engineerper 1 éve
szülő
commit
6001a2e33c
1 módosított fájl, 24 hozzáadás és 25 törlés
  1. 24 25
      gatewayServer/c2s.go

+ 24 - 25
gatewayServer/c2s.go

@@ -14,7 +14,6 @@ import (
 	"strings"
 )
 
-// ParseAndResponse 分析和响应
 func ParseAndResponse(adu AppDataUnit, c net.Conn) {
 	switch adu.CmdCode {
 	case CmdCodeHeartbeatC2S:
@@ -25,31 +24,32 @@ func ParseAndResponse(adu AppDataUnit, c net.Conn) {
 		c2s4004(adu)
 	case CmdCodeRegisterC2S:
 		c2s4001(adu, c)
+	case CmdCodeServerC2S:
+		c2s4000(adu, c)
 	case CmdCodeUpdateC2S:
 		//更新固件
 	default:
 		fmt.Println(adu.String())
 	}
-
 }
 
-// c2s4000 请求管理服务器响应
+// 请求管理服务器响应
 func c2s4000(adu AppDataUnit, c net.Conn) {
-	unit := AppDataUnit{
+	a := AppDataUnit{
 		CmdCode: CmdCodeServerS2C,
 		SubCode: 0,
 		DevId:   adu.DevId,
 		Data:    ipAddress,
 	}
-	unit.Debug()
-	_, err := c.Write(Pack(unit))
+	a.Debug()
+	_, err := c.Write(Pack(a))
 	if err != nil {
 		logrus.Errorf("写入数据错误 %e\n", err)
 	}
-	logrus.Info(adu.DevId, "请求管理服务器成功")
+	logrus.Info(adu.DevId, "向登录服务器请求管理服务器")
 }
 
-// c2s4001 注册登录响应
+// 注册登录响应
 func c2s4001(adu AppDataUnit, c net.Conn) {
 	a := AppDataUnit{
 		CmdCode: CmdCodeRegisterS2C,
@@ -67,6 +67,7 @@ func c2s4001(adu AppDataUnit, c net.Conn) {
 	gs := service.ServiceGroupApp.AppServiceGroup.GatewayService
 	gw, err := gs.CreateIfNotExist(adu.DevId)
 	if err != nil {
+		//if errors.Is(err, appService.ExistError) {
 		if err == appService.ExistError {
 			logrus.Infof("网关[%s]登录成功", adu.DevId)
 		} else {
@@ -83,8 +84,7 @@ func c2s4001(adu AppDataUnit, c net.Conn) {
 		logrus.Error(err)
 		return
 	}
-	var info isapi.DeviceInfo
-	xml.Unmarshal(resp, &info)
+	var info = resp.(isapi.DeviceInfo)
 	//创建camera记录并绑定gateway_id
 	err = cs.CreateIfNotExist(info, gw.ID)
 	if err != nil {
@@ -106,7 +106,7 @@ func c2s4001(adu AppDataUnit, c net.Conn) {
 	setSIP(baseUrl, camera.ID, cs)
 }
 
-// c2s4002 心跳响应
+// 心跳响应
 func c2s4002(adu AppDataUnit, c net.Conn) {
 	//todo 心跳处理
 	a := AppDataUnit{
@@ -119,14 +119,15 @@ func c2s4002(adu AppDataUnit, c net.Conn) {
 	if err != nil {
 		logrus.Errorf("写入数据错误 %e\n", err)
 	}
+	//todo 网关注册后,网关再接入摄像头如何注册摄像头--
 }
 
-// c2s4003 查询参数响应
+// 查询参数响应
 func c2s4003(adu AppDataUnit) {
 	logrus.Infof("参数响应%s,devId:%s,CmdCode=%X,SubCode=%X\n", adu.Data, adu.DevId, adu.CmdCode, adu.SubCode)
 }
 
-// c2s4004 设置参数响应
+// 设置参数响应
 func c2s4004(adu AppDataUnit) {
 	logrus.Infof("配置参数-响应码%s,devId:%s,CmdCode=%X,SubCode=%X\n", adu.Data, adu.DevId, adu.CmdCode, adu.SubCode)
 }
@@ -139,17 +140,17 @@ func setServer(host string) uint {
 		logrus.Errorf("事件主机配置文件解析错误: %e\n", err)
 		return 0
 	}
-	bytes, err := isapi.Com(host, isapi.SetHosts, marshal)
+	data, err := isapi.Com(host, isapi.SetHosts, marshal)
 	if err != nil {
 		logrus.Error("配置监听主机错误", err)
 	}
-	var resp isapi.ResponseStatus
-	err = xml.Unmarshal(bytes, &resp)
+	var resp = data.(isapi.ResponseStatus)
+	//err = xml.Unmarshal(bytes, &resp)
 	if err != nil || (resp.StatusCode != 0 && resp.StatusCode != 1) {
 		logrus.Errorf("配置监听服务器响应 err:%s,StatusCode:%d,StatusString:%s", err.Error(), resp.StatusCode, resp.StatusString)
 		return 0
 	}
-	logrus.Info("配置监听主机响应", string(bytes))
+	//logrus.Info("配置监听主机响应", string(bytes))
 	return 1
 }
 
@@ -225,13 +226,12 @@ func setSIP(host string, cid uint, cs appService.CameraService) uint {
 	}
 	//2. 配置SIP
 	s := fmt.Sprintf(sipstr, id, id)
-	bytes, err := isapi.Com(host, isapi.SetSIP, []byte(s))
+	data, err := isapi.Com(host, isapi.SetSIP, []byte(s))
 	if err != nil {
 		logrus.Error("配置SIP错误", err)
 		return 0
 	}
-	var resp isapi.ResponseStatus
-	err = xml.Unmarshal(bytes, &resp)
+	var resp = data.(isapi.ResponseStatus)
 	if err != nil {
 		logrus.Errorf("配置SIP服务器err:%s", err.Error())
 		return 0
@@ -242,20 +242,19 @@ func setSIP(host string, cid uint, cs appService.CameraService) uint {
 		return 0
 	}
 	//3. 配置SIPInfo
-	com, err := isapi.Com(host, isapi.SetSIPInfo, []byte(sipInfo))
+	data, err = isapi.Com(host, isapi.SetSIPInfo, []byte(sipInfo))
 	if err != nil {
 		logrus.Error("配置SIPInfo错误", err)
 		return 0
 	}
-	var resp1 isapi.ResponseStatus
-	err = xml.Unmarshal(com, &resp1)
+	var resp1 = data.(isapi.ResponseStatus)
 	if err != nil {
 		logrus.Errorf("配置配置SIPInfo err:%s", err.Error())
 		return 0
 	}
 	//记录失败原因
-	if resp.StatusCode != 0 && resp.StatusCode != 1 {
-		logrus.Infof("配置SIPInfo-响应 StatusCode:%d,StatusString:%s", resp.StatusCode, resp.StatusString)
+	if resp1.StatusCode != 0 && resp1.StatusCode != 1 {
+		logrus.Infof("配置SIPInfo-响应 StatusCode:%d,StatusString:%s", resp1.StatusCode, resp1.StatusString)
 		return 0
 	}
 	//成功保存数据库