|
@@ -0,0 +1,97 @@
|
|
|
|
|
+// fault record 故障录波请求
|
|
|
|
|
+package fwh_mqtt
|
|
|
|
|
+
|
|
|
|
|
+import (
|
|
|
|
|
+ "context"
|
|
|
|
|
+ "encoding/json"
|
|
|
|
|
+ "fmt"
|
|
|
|
|
+ "hash/crc32"
|
|
|
|
|
+ "strings"
|
|
|
|
|
+ "time"
|
|
|
|
|
+)
|
|
|
|
|
+
|
|
|
|
|
+type FaultRecordParaListItem struct {
|
|
|
|
|
+ Id int `json:"id"`
|
|
|
|
|
+ SetVal string `json:"setVal"`
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+type FaultRecordInfoItem struct {
|
|
|
|
|
+ Sn string `json:"sn"` // aPower SN
|
|
|
|
|
+ ParaList []FaultRecordParaListItem `json:"paraList"`
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+type FaultRecordListItem struct {
|
|
|
|
|
+ Type string `json:"type"`
|
|
|
|
|
+ Info []FaultRecordInfoItem `json:"info"`
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+type FaultRecordData struct {
|
|
|
|
|
+ List []FaultRecordListItem `json:"list"`
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+type FaultRecordDataArea struct {
|
|
|
|
|
+ Cmd int `json:"cmd"`
|
|
|
|
|
+ Data FaultRecordData `json:"data"`
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+type FaultRecordChannelConfig struct {
|
|
|
|
|
+ Sn string `json:"sn"` // aPower SN
|
|
|
|
|
+ ParaList []FaultRecordParaListItem `json:"paraList"`
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func ChargeChannel(ctx context.Context, sn string) error {
|
|
|
|
|
+ dataArea := map[string]interface{}{
|
|
|
|
|
+ "cmd": 1,
|
|
|
|
|
+ "data": map[string]interface{}{
|
|
|
|
|
+ "list": []interface{}{
|
|
|
|
|
+ map[string]interface{}{
|
|
|
|
|
+ "type": "pe",
|
|
|
|
|
+ "info": []interface{}{
|
|
|
|
|
+ map[string]interface{}{
|
|
|
|
|
+ "sn": "10050015A00X25070634",
|
|
|
|
|
+ "paraList": []interface{}{
|
|
|
|
|
+ map[string]interface{}{
|
|
|
|
|
+ "id": 6,
|
|
|
|
|
+ "setVal": "010300014252",
|
|
|
|
|
+ },
|
|
|
|
|
+ map[string]interface{}{
|
|
|
|
|
+ "id": 6,
|
|
|
|
|
+ "setVal": "020100014C14",
|
|
|
|
|
+ },
|
|
|
|
|
+ map[string]interface{}{
|
|
|
|
|
+ "id": 6,
|
|
|
|
|
+ "setVal": "030100013102",
|
|
|
|
|
+ },
|
|
|
|
|
+ map[string]interface{}{
|
|
|
|
|
+ "id": 6,
|
|
|
|
|
+ "setVal": "040100013103",
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ dataStr, err := json.Marshal(dataArea)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return err
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ err = fwhMqttClient.sendMessageOnce(ctx, "fwh/s2c/mng/"+sn, FwhMqttMsg{
|
|
|
|
|
+ CmdType: 377, // 故障录波请求
|
|
|
|
|
+ Type: 0, // IBG
|
|
|
|
|
+ Snno: 123,
|
|
|
|
|
+ TimeStamp: time.Now().Unix(),
|
|
|
|
|
+ EquipNo: sn,
|
|
|
|
|
+ DataArea: dataArea,
|
|
|
|
|
+ Len: len(dataStr),
|
|
|
|
|
+ Crc: strings.ToUpper(fmt.Sprintf("%08X", crc32.ChecksumIEEE(dataStr))),
|
|
|
|
|
+ })
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return err
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return nil
|
|
|
|
|
+}
|