| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- package dataStruct
- import (
- "log"
- "time"
- "unicode/utf8"
- )
- // DTU管理命令
- const (
- CmdRegister = iota // 注册
- CmdHeartBeat // 心跳
- CmdCollect // 采集
- )
- type DTUManageCmd struct {
- SN string `json:"sn"`
- Cmd int `json:"cmd"`
- Data []byte `json:"data"`
- }
- // DmcUnmarshal 解析DTU上报
- // 注册和心跳格式:注册包@202402200322 心跳包 $202402200322
- // SN长度为8-16个字符
- func (dmc *DTUManageCmd) DmcUnmarshal(data []byte) {
- size := utf8.RuneCount(data)
- log.Println("DTU采集:", data)
- // SN 长度在 8-16个字符 (注册包在9-17个字符)
- if size > 8 && size < 18 {
- if data[0] == '@' {
- dmc.Cmd = CmdRegister
- dmc.SN = string(data[1:])
- return
- } else if data[0] == '$' {
- dmc.Cmd = CmdHeartBeat
- dmc.SN = string(data[1:])
- return
- }
- }
- dmc.Data = data
- dmc.Cmd = CmdCollect
- }
- type DtuRegisterChanMsg struct {
- Sn string
- Value *ClientState
- }
- type DateTime struct {
- Year int
- Month time.Month
- Day int
- Hour int
- Minute int
- Second int
- }
- // DataToTimeStamp 日期转时间戳
- func (dt *DateTime) DataToTimeStamp() int64 {
- return time.Date(dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, dt.Second, 0, time.Local).Unix()
- }
- // TimeStampToData 时间戳转日期
- func (dt *DateTime) TimeStampToData(t int64) *DateTime {
- v := time.Unix(t, 0)
- m := &DateTime{}
- m.Year = v.Year()
- m.Month = v.Month()
- m.Day = v.Day()
- m.Hour = v.Hour()
- m.Minute = v.Minute()
- m.Second = v.Second()
- return m
- }
- type MeterRef struct {
- PvRef float32
- LvRef float32
- }
- type MeterRatio struct {
- Ct int `json:"ct"`
- Pt int `json:"pt"`
- }
- type MeterPMC350BParam struct {
- PrimaryVolt int `json:"primary_volt"`
- SecondVolt int `json:"second_volt"`
- PrimaryCurrent int `json:"primary_current"`
- SecondCurrent int `json:"second_current"`
- CType int `json:"ct_type"`
- }
|