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
|
Horodate *time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
func treatFrames(frames chan []byte, writer TICWriter) {
|
func treatFrames(frames chan []byte, writer TICWriter, legacyMode bool) {
|
||||||
first := true
|
first := true
|
||||||
fframe:
|
fframe:
|
||||||
for {
|
for {
|
||||||
@ -65,13 +65,19 @@ fframe:
|
|||||||
var defaultHorodate time.Time
|
var defaultHorodate time.Time
|
||||||
|
|
||||||
for _, line := range bytes.Split(frame, []byte("\r\n")) {
|
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 {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Replace legacy keys
|
||||||
|
if legacyMode {
|
||||||
|
if nkey, ok := Legacy2Std[key]; ok {
|
||||||
|
key = nkey
|
||||||
|
}
|
||||||
|
}
|
||||||
// Skip ADCO, this is the Linky address, confidential and unrelevant
|
// Skip ADCO, this is the Linky address, confidential and unrelevant
|
||||||
if key == "ADCO" {
|
if key == "ADCO" {
|
||||||
continue
|
continue
|
||||||
@ -131,7 +137,7 @@ func getHorodate(fields *[][]byte) (*time.Time, error) {
|
|||||||
return nil, nil
|
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)
|
line = bytes.TrimSpace(line)
|
||||||
|
|
||||||
if len(line) <= 1 {
|
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] {
|
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]))
|
// Try checksum mode 1
|
||||||
return
|
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)
|
fields := bytes.Fields(line)
|
||||||
@ -203,7 +212,7 @@ func main() {
|
|||||||
|
|
||||||
frames := make(chan []byte)
|
frames := make(chan []byte)
|
||||||
go readSerial(s, frames)
|
go readSerial(s, frames)
|
||||||
go treatFrames(frames, writer)
|
go treatFrames(frames, writer, *legacyMode)
|
||||||
|
|
||||||
interrupt := make(chan os.Signal, 1)
|
interrupt := make(chan os.Signal, 1)
|
||||||
signal.Notify(interrupt, os.Interrupt, syscall.SIGTERM)
|
signal.Notify(interrupt, os.Interrupt, syscall.SIGTERM)
|
||||||
|
@ -1,6 +1,25 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
var (
|
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{
|
MeasurementGroups = map[string][]string{
|
||||||
"EAS": []string{"EAST", "EASF01", "EASF02", "EASF03", "EASF04", "EASF05", "EASF06", "EASF07", "EASF08", "EASF09", "EASF10", "EASD01", "EASD02", "EASD03", "EASD04"},
|
"EAS": []string{"EAST", "EASF01", "EASF02", "EASF03", "EASF04", "EASF05", "EASF06", "EASF07", "EASF08", "EASF09", "EASF10", "EASD01", "EASD02", "EASD03", "EASD04"},
|
||||||
"ERQ": []string{"ERQ1", "ERQ2", "ERQ3", "ERQ4"},
|
"ERQ": []string{"ERQ1", "ERQ2", "ERQ3", "ERQ4"},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user