emu
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed

This commit is contained in:
2023-12-11 16:50:28 +01:00
parent 668fc20be9
commit b3de6182b3
4 changed files with 87 additions and 73 deletions

View File

@ -1,11 +0,0 @@
package emuProfIILoRa
import (
"fmt"
"udi/database"
)
func Parse(decodedPayload interface{}) ([]database.VariableType, error) {
return nil, fmt.Errorf("Nothing works so far")
}

View File

@ -0,0 +1,53 @@
package emuProfIILoRaCfg1
// provisioning device with
// f_port=1: 01 00 0A 0B 0C 0D 0E 17 18 19 F0 4C
// f_port=2: 01 00 0A 24 26 28 2A 7A
import (
"log"
"fmt"
//"encoding/json"
"udi/database"
)
/*
const nameMapping = map[string]string {
"Active Energy Export T1 64bit": "ActiveEnergyExport",
"Reactive Energy Export T1 64bit": "ReactiveEnergyExport",
"Active Energy Import T1 64bit": "ActiveEnergyImport",
"Reactive Energy Import T1 64bit": "ReactiveEnergyImport",
}
*/
type emuVariable struct {
Value interface{} `json:"value"`
Unit string `json:"unit"`
}
func i2m(i interface{}) (map[string]interface{}, error) {
o, ok := i.(map[string]interface{})
if ! ok {
return nil, fmt.Errorf("Unable to transform payload, outer stage")
}
return o, nil
}
func Parse(fPort int, decodedPayload interface{}) (map[string]database.VariableType, error) {
dp, err := i2m(decodedPayload)
if err != nil {
return nil, err
}
variables := make(map[string]database.VariableType)
for key, item := range dp {
log.Printf("Key: %s, Item: %s", key, item)
variables[key] = database.VariableType{ Variable: key, Unit: item.(map[string]interface{})["unit"], Value: item.(map[string]interface{})["value"] }
}
return variables, nil
}