/* Package config provides configuration types and JSON handling for rs2322tcp. This file contains the distinction between the server-internal physical device configuration and the public device information made available to clients. Project: rs2322tcp Module: git.lang-dieter.de/rs2322tcp */ package config /////////////////////////////////////////////////////////////////////////////// // Remote device /////////////////////////////////////////////////////////////////////////////// // RemoteDevice describes a physical RS232 device that is made available // to a client by the rs2322tcp server. // // Server-internal information such as the physical serial device path // is deliberately not included. type RemoteDevice struct { ID string `json:"id"` Name string `json:"name"` BaudRate int `json:"baud_rate"` DataBits int `json:"data_bits"` Parity string `json:"parity"` StopBits int `json:"stop_bits"` } /////////////////////////////////////////////////////////////////////////////// // Remote device list /////////////////////////////////////////////////////////////////////////////// // DeviceList contains the remote devices made available by the server. type DeviceList struct { Devices []RemoteDevice `json:"devices"` } /////////////////////////////////////////////////////////////////////////////// // Public device information /////////////////////////////////////////////////////////////////////////////// // RemoteDevice returns the public description of a configured physical // device. // // The physical serial port remains server-internal and is not exposed // to the client. func (cfg DeviceConfig) RemoteDevice() RemoteDevice { return RemoteDevice{ ID: cfg.ID, Name: cfg.Name, BaudRate: cfg.BaudRate, DataBits: cfg.DataBits, Parity: cfg.Parity, StopBits: cfg.StopBits, } } /////////////////////////////////////////////////////////////////////////////// // Remote device list /////////////////////////////////////////////////////////////////////////////// // RemoteDevices returns the public device list for all configured // physical devices. // // Server-internal information such as the physical serial port is // deliberately omitted. func (cfg *ServerConfig) RemoteDevices() DeviceList { if cfg == nil { return DeviceList{} } devices := make([]RemoteDevice, 0, len(cfg.Devices)) for _, device := range cfg.Devices { devices = append(devices, device.RemoteDevice()) } return DeviceList{ Devices: devices, } }