In legacy mode, try to map to standard mode key
This commit is contained in:
parent
ba5c097cf0
commit
fe9538c817
21
main.go
21
main.go
@ -48,7 +48,7 @@ type Point struct {
|
||||
Horodate *time.Time
|
||||
}
|
||||
|
||||
func treatFrames(frames chan []byte, writer TICWriter) {
|
||||
func treatFrames(frames chan []byte, writer TICWriter, legacyMode bool) {
|
||||
first := true
|
||||
fframe:
|
||||
for {
|
||||
@ -65,13 +65,19 @@ fframe:
|
||||
var defaultHorodate time.Time
|
||||
|
||||
for _, line := range bytes.Split(frame, []byte("\r\n")) {
|
||||
key, horodate, data, err := treatLine(line)
|
||||
key, horodate, data, err := treatLine(line, legacyMode)
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
continue
|
||||
}
|
||||
|
||||
// Replace legacy keys
|
||||
if legacyMode {
|
||||
if nkey, ok := Legacy2Std[key]; ok {
|
||||
key = nkey
|
||||
}
|
||||
}
|
||||
// Skip ADCO, this is the Linky address, confidential and unrelevant
|
||||
if key == "ADCO" {
|
||||
continue
|
||||
@ -131,7 +137,7 @@ func getHorodate(fields *[][]byte) (*time.Time, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func treatLine(line []byte) (key string, horodate *time.Time, data []byte, err error) {
|
||||
func treatLine(line []byte, legacyMode bool) (key string, horodate *time.Time, data []byte, err error) {
|
||||
line = bytes.TrimSpace(line)
|
||||
|
||||
if len(line) <= 1 {
|
||||
@ -139,8 +145,11 @@ func treatLine(line []byte) (key string, horodate *time.Time, data []byte, err e
|
||||
}
|
||||
|
||||
if computeChecksum(line[:len(line)-1]) != line[len(line)-1] {
|
||||
log.Printf("BAD checksum on %s: calculated: %c\n", line, computeChecksum(line[:len(line)-1]))
|
||||
return
|
||||
// Try checksum mode 1
|
||||
if !legacyMode || computeChecksum(line[:len(line)-2]) != line[len(line)-1] {
|
||||
log.Printf("BAD checksum on %s: calculated: %c\n", line, computeChecksum(line[:len(line)-1]))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
fields := bytes.Fields(line)
|
||||
@ -203,7 +212,7 @@ func main() {
|
||||
|
||||
frames := make(chan []byte)
|
||||
go readSerial(s, frames)
|
||||
go treatFrames(frames, writer)
|
||||
go treatFrames(frames, writer, *legacyMode)
|
||||
|
||||
interrupt := make(chan os.Signal, 1)
|
||||
signal.Notify(interrupt, os.Interrupt, syscall.SIGTERM)
|
||||
|
@ -1,6 +1,25 @@
|
||||
package main
|
||||
|
||||
var (
|
||||
Legacy2Std = map[string]string{
|
||||
"BASE": "EAST",
|
||||
"HCHC": "EASF01",
|
||||
"HCHP": "EASF02",
|
||||
"EJPHN": "EASF01",
|
||||
"EJPHPM": "EASF02",
|
||||
"BBRHCJB": "EASF01",
|
||||
"BBRHPJB": "EASF02",
|
||||
"BBRHCJW": "EASF03",
|
||||
"BBRHPJW": "EASF04",
|
||||
"BBRHCJR": "EASF05",
|
||||
"BBRHPJR": "EASF06",
|
||||
"IINST": "IRMS1",
|
||||
"IINST1": "IRMS1",
|
||||
"IINST2": "IRMS2",
|
||||
"IINST3": "IRMS3",
|
||||
"PAPP": "SINSTS",
|
||||
}
|
||||
|
||||
MeasurementGroups = map[string][]string{
|
||||
"EAS": []string{"EAST", "EASF01", "EASF02", "EASF03", "EASF04", "EASF05", "EASF06", "EASF07", "EASF08", "EASF09", "EASF10", "EASD01", "EASD02", "EASD03", "EASD04"},
|
||||
"ERQ": []string{"ERQ1", "ERQ2", "ERQ3", "ERQ4"},
|
||||
|
Loading…
Reference in New Issue
Block a user