数据上报
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

78 lines
1.9 KiB

package adaptors
import (
"crypto/rc4"
"encoding/json"
"goUpload/consumers/CQZG/protoFiles"
"goUpload/models"
"goUpload/utils"
"google.golang.org/protobuf/proto"
"log"
)
// Adaptor_ZD_CQZG 振动数据转换器
type Adaptor_ZD_CQZG struct {
IdMap map[string]int64
RC4Key string
}
func (the Adaptor_ZD_CQZG) Transform(rawMsg string) []byte {
zd := models.ZD{}
json.Unmarshal([]byte(rawMsg), &zd)
return the.ZDtoCQZG(zd)
}
func (the Adaptor_ZD_CQZG) ZDtoCQZG(zd models.ZD) (result []byte) {
var transBytes []byte
ComplexData_HSD := &protoFiles.ComplexData{
SensorData: make([]*protoFiles.SensorData, 0),
}
sensorData := &protoFiles.SensorData{
MonitorType: protoFiles.MonitoryType_VIB, //监测类型 转换
SensorID: the.getSensorId(zd.Module), //id转换
EventTime: zd.Ticks / 1000 * 1000, //由于振动时间问题,去掉毫秒
ChannelCode: "",
DataBody: &protoFiles.SensorData_Vib{
Vib: &protoFiles.VIBRealTime{
MonitorValues: zd.AccValues,
},
},
}
//无匹配 提前返回
if sensorData.SensorID == 0 {
log.Printf("振动测点[%s] 数据无匹配的资管平台id,请检查配置文件", zd.Module)
return
}
ComplexData_HSD.SensorData = append(ComplexData_HSD.SensorData, sensorData)
transBytes, _ = proto.Marshal(ComplexData_HSD)
resultByCrc16 := utils.NewCRC16CCITT().GetWCRCin(transBytes)
needRC4 := append(transBytes, resultByCrc16...)
rc4Key := []byte(the.RC4Key)
// 加密操作
dest1 := make([]byte, len(needRC4))
rc4.NewCipher(rc4Key)
cipher1, _ := rc4.NewCipher(rc4Key)
cipher1.XORKeyStream(dest1, needRC4)
//log.Printf("rc4加密结果=> %s \n", hex.EncodeToString(dest1))
return dest1
}
func (the Adaptor_ZD_CQZG) getSensorId(rawSensorName string) int64 {
v, isValid := the.IdMap[rawSensorName]
if !isValid {
v = 0
}
return v
}
// DAAS软件 振动对方平台id对于关系
//var idMapZD = map[string]int64{
// "1": 5000200017,
// "2": 5000200018,
//}