123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- package v1
- import (
- "context"
- "encoding/json"
- "github.com/jaryhe/gopkgs/logger"
- "go.uber.org/zap"
- "lift-monitor/consts"
- "lift-monitor/pb"
- "lift-monitor/pb/v1"
- "time"
- )
- const (
- LiftAlarmHigh = "L01"
- LiftAlarmWeight = "L02"
- LiftAlarmPeople = "L03"
- LiftAlarmSpeed = "L04"
- LiftAlarmWind = "L05"
- LiftAlarmTilt = "L06"
- LiftWarningHigh = "L07"
- LiftWarningWeight = "L08"
- LiftWarningPeople = "L09"
- LiftWarningSpeed = "L10"
- LiftWarningWind = "L11"
- LiftWarningTilt = "L12"
- LiftAlarmFrontDoor = "L13"
- LiftAlarmBackDoor = "L14"
- )
- var LiftAlarmCodeReasonMap = map[string]string{
- "L01":"高度报警",
- "L02":"重量报警",
- "L03":"人数报警",
- "L04":"速度报警",
- "L05":"风速报警",
- "L06":"倾角报警",
- "L07":"高度预警",
- "L08":"重量预警",
- "L09":"人数预警",
- "L10":"速度预警",
- "L11":"风速预警",
- "L12":"倾角预警",
- "L13":"前门异常",
- "L14":"后门异常",
- }
- func judgeAlarmCode(value int, codes ...string) string {
- if value == 0 {
- return ""
- }
- if value == 1 && len(codes) > 0 {
- return codes[0]
- }
- if value == 2 && len(codes) > 1 {
- return codes[1]
- }
- return ""
- }
- func getAlarmCodes(record *LiftRealtimeData) []string {
- ret := []string{}
- if code := judgeAlarmCode(record.HighAlarmState, LiftWarningHigh, LiftAlarmHigh); code != "" {
- ret = append(ret, code)
- }
- if code := judgeAlarmCode(record.PeopleAlarmState, LiftWarningPeople, LiftAlarmPeople); code != "" {
- ret = append(ret, code)
- }
- if code := judgeAlarmCode(record.WeightAlarmState, LiftWarningWeight, LiftAlarmWeight); code != "" {
- ret = append(ret, code)
- }
- if code := judgeAlarmCode(record.WindSpeedAlarmState, LiftWarningWind, LiftAlarmWind); code != "" {
- ret = append(ret, code)
- }
- if code := judgeAlarmCode(record.TiltAlarmState, LiftWarningTilt, LiftAlarmTilt); code != "" {
- ret = append(ret, code)
- }
- if code := judgeAlarmCode(record.SpeedAlarmState, LiftWarningSpeed, LiftAlarmSpeed); code != "" {
- ret = append(ret, code)
- }
- if code := judgeAlarmCode(record.FrontDoorAlarmState, LiftAlarmFrontDoor); code != "" {
- ret = append(ret, code)
- }
- if code := judgeAlarmCode(record.BackDoorAlarmState, LiftAlarmBackDoor); code != "" {
- ret = append(ret, code)
- }
- return ret
- }
- func handleAlarms(record *LiftRealtimeData, sn string, liftno int64, timestamp int64, projectId int64, deviceName string) bool {
- codes := getAlarmCodes(record)
- for _, code := range codes {
- handleAlarm(code, sn, liftno, timestamp, projectId, deviceName)
- }
- if len(codes) > 0 {
- return true
- }
- return false
- }
- func handleAlarm(code string, sn string, liftno int64, timestamp int64, projectId int64, deviceName string) {
- timeStr := time.Unix(timestamp, 0).Format("2006-01-02 15:04:05")
- //reason := fmt.Sprintf("%d号%s", sn, liftno, timeStr, LiftAlarmValueReasonMap[alarmValue])
- alarmData := &v1.AlarmAddRequest{
- AlarmReason: LiftAlarmCodeReasonMap[code],
- AlarmCode: code,
- Date: timeStr,
- Sn: sn,
- ProjectId: projectId,
- DeviceCode: consts.LiftDeviceCode,
- DeviceType: consts.LiftDeviceName,
- DeviceName: deviceName,
- }
- // 添加告警
- _, err := pb.SmartAlarm.AlarmAdd(context.Background(), alarmData)
- if err != nil {
- reqByte, _ := json.Marshal(alarmData)
- logger.Error("rpc",
- zap.String("call", "pb.SmartAlarm.AlarmAdd"),
- zap.String("args", string(reqByte)),
- zap.String("error", err.Error()))
- }
- }
- func LiftFrameAlarmRequestHandle(sn string, liftNo byte, version byte, data []byte) (res []byte, err error) {
- // 不管,因为实时包里包含了报警数据
- return makeResponse(sn, liftNo, LiftFrameAlarmResponse, version, []byte{0x00}), nil
- }
|