1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- // Copyright 2019 github.com. All rights reserved.
- // Use of this source code is governed by github.com.
- package v1
- import (
- "github.com/jaryhe/gopkgs/database"
- "github.com/jinzhu/gorm"
- "time"
- "lift-monitor/model"
- )
- func LiftFrameAlarmConfWrite(record *model.LiftAlarmConf) error {
- p := &model.LiftAlarmConf{}
- where := map[string]interface{}{
- "SN": record.SN,
- "LiftNo": record.LiftNo,
- "ProjectID": record.ProjectID,
- }
- err := p.Find(database.DB(), where)
- if err != nil && err != gorm.ErrRecordNotFound {
- return err
- }
- if p.ID == 0 {
- record.CreatedAt = time.Now()
- record.UpdatedAt = record.CreatedAt
- return record.Insert(database.DB())
- }
- values := map[string]interface{}{
- "MaxWeightWarning":record.MaxWeightWarning,
- "MaxWeightAlarm":record.MaxWeightAlarm,
- "MaxHigh":record.MaxHigh,
- "MaxSpeedWarning":record.MaxSpeedWarning,
- "MaxSpeedAlarm":record.MaxSpeedAlarm,
- "MaxPeople":record.MaxPeople,
- "TiltWarning":record.TiltWarning ,
- "TiltAlarm":record.TiltAlarm,
- "WindSpeedWarning":record.WindSpeedWarning,
- "WindSpeedAlarm":record.WindSpeedAlarm,
- "UpdatedAt": time.Now(),
- }
- where = map[string]interface{}{
- "ID": p.ID,
- }
- return p.Update(database.DB(), where, values)
- }
- func LiftFrameAlarmConfRequestHandle(sn string, liftNo byte, version byte, data []byte) (res []byte, err error) {
- projectId,_ := checkAuth(sn)
- if projectId <= 0 {
- // 未认证或需重新认证
- return makeResponse(sn, liftNo, LiftFrameAlarmConfResponse, version, []byte{0xfe}), nil
- }
- if len(data) < 20 {
- return makeResponse(sn, liftNo, LiftFrameAlarmConfResponse, version, []byte{0xff}), nil
- }
- record := &model.LiftAlarmConf{}
- // 最大起重量预警
- record.MaxWeightWarning = int64(data[0])<<8 + int64(data[1])
- // 最大起重量报警
- record.MaxWeightAlarm = int64(data[2])<<8 + int64(data[3])
- // 最大起升高度
- record.MaxHigh = (float64(int16(data[4])<<8) + float64(data[5])) * 0.1
- // 最大速度预警
- record.MaxSpeedWarning = (float64(int16(data[6])<<8) + float64(data[7])) * 0.1
- // 最大速度报警
- record.MaxSpeedAlarm = (float64(int16(data[8])<<8) + float64(data[9])) * 0.1
- // 最大承载人数
- record.MaxPeople = int64(data[10])<<8 + int64(data[11])
- // 倾斜预警
- record.TiltWarning =(float64(int16(data[12])<<8) + float64(data[13])) * 0.1
- // 倾斜报警
- record.TiltAlarm = (float64(int16(data[14])<<8) + float64(data[15])) * 0.1
- // 风速预警
- record.WindSpeedWarning = (float64(int16(data[16])<<8) + float64(data[17])) * 0.1
- // 风速报警
- record.WindSpeedAlarm = (float64(int16(data[18])<<8) + float64(data[19])) * 0.1
- record.ProjectID = projectId
- record.SN = sn
- record.LiftNo = int(liftNo) >> 1
- record.LiftDirect = int(liftNo) & 1
- if LiftFrameAlarmConfWrite(record) != nil {
- return makeResponse(sn, liftNo, LiftFrameAlarmConfResponse, version, []byte{0xfd}), nil
- }
- return makeResponse(sn, liftNo, LiftFrameAlarmConfResponse, version, []byte{0x00}), nil
- }
|