1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- package main
- import "errors"
- var ErrCfgVerifyFailed = errors.New("config verify failed")
- type ConfigDefClass struct {
- Serial struct {
- ComPort string `toml:"port"`
- Baudrate int `toml:"baud"`
- DataBits int `toml:"data_bits"`
- StopBits float32 `toml:"stop_bits"`
- Parity string `toml:"parity"`
- } `toml:"serial"`
- Performance struct {
- TxBufferSize int `toml:"tx_buf_size"`
- RxBufferSize int `toml:"rx_buf_size"`
- } `toml:"perf"`
- Server struct {
- Mode string `toml:"mode"`
- TCPConfig struct {
- Bind string `toml:"bind"`
- } `toml:"tcp"`
- } `toml:"server"`
- }
- func ConfigVerifyAndFillDefault() error {
- // TODO: process default config
- if Config.Serial.ComPort == "" {
- App.Error("no serial port specified.")
- return ErrCfgVerifyFailed
- }
- if Config.Serial.Baudrate <= 0 {
- App.Error("baudrate should more than 0.")
- return ErrCfgVerifyFailed
- }
- if Config.Serial.DataBits == 0 {
- Config.Serial.DataBits = 8
- }
- if Config.Serial.StopBits == 0 {
- Config.Serial.StopBits = 1
- }
- if Config.Serial.Parity == "" {
- Config.Serial.Parity = "N"
- }
- if Config.Performance.TxBufferSize <= 0 {
- Config.Performance.TxBufferSize = 2048
- }
- if Config.Performance.RxBufferSize <= 0 {
- Config.Performance.RxBufferSize = 2048
- }
- return nil
- }
|