a Go library and command line utility for reading values from a Sutron data logger
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
package sutron
import ( "fmt" )
type SutronB struct { Block byte Group byte Delta byte Data []byte Voltage byte }
func (s SutronB) GroupString() string { switch s.Group { case '1': return "Scheduled Transmission" case '2': return "Alarm Transmission" case '3': return "Forced Transmission" default: return "" } }
func ParseSutronB(raw []byte) (*SutronB, error) { raw_len := len(raw) if raw_len < 5 { return nil, fmt.Errorf("message structure too short: %d bytes", len(raw)) }
if raw[0] != 'B' { return nil, fmt.Errorf("wrong sutron format: %s", raw[0]) }
data := SutronB{} data.Block = raw[0] data.Group = raw[1] data.Delta = raw[2] data.Data = raw[3 : raw_len-1] data.Voltage = raw[raw_len-1] return &data, nil }
|