12345678910111213141516171819202122232425262728293031323334 |
- // Copyright 2019 github.com. All rights reserved.
- // Use of this source code is governed by github.com.
- package v1
- import (
- "fmt"
- "strings"
- "tower-monitor/util"
- )
- func TowerFramAuthRequestHandle(sn string, towerNo byte, version byte, data []byte) (res []byte, err error) {
- deviceInfo, err := util.GetDeviceInfo(sn)
- if err != nil {
- fmt.Printf("get device info err:%v\n", err)
- if strings.Contains(err.Error(), "20001") {
- res := makeResponse(sn, towerNo, TowerFrameAuthResponse, version, []byte{0x01})
- return res, nil
- } else {
- res := makeResponse(sn, towerNo, TowerFrameAuthResponse, version, []byte{0xfd})
- return res, nil
- }
- }
- if deviceInfo.Key != strings.TrimSpace(string(data)) {
- res := makeResponse(sn, towerNo, TowerFrameAuthResponse, version, []byte{0x02})
- return res, nil
- }
- authCache(sn, deviceInfo.ProjectId, deviceInfo.Name)
- return makeResponse(sn, towerNo, TowerFrameAuthResponse, version, []byte{0x00}), nil
- }
|