diff --git a/SensorHub.Config/ConfigBuild.cs b/SensorHub.Config/ConfigBuild.cs index a9c1185..7dda940 100644 --- a/SensorHub.Config/ConfigBuild.cs +++ b/SensorHub.Config/ConfigBuild.cs @@ -104,7 +104,7 @@ } //获取配置tag - private static byte[] getConfigTag(String configItem) + public static byte[] getConfigTag(String configItem) { byte[] result = new byte[256]; int flag = 0; diff --git a/SensorHub.Config/ConfigBuild.cs b/SensorHub.Config/ConfigBuild.cs index a9c1185..7dda940 100644 --- a/SensorHub.Config/ConfigBuild.cs +++ b/SensorHub.Config/ConfigBuild.cs @@ -104,7 +104,7 @@ } //获取配置tag - private static byte[] getConfigTag(String configItem) + public static byte[] getConfigTag(String configItem) { byte[] result = new byte[256]; int flag = 0; diff --git a/SensorHub.Noise/Noise.cs b/SensorHub.Noise/Noise.cs index ed689fe..638db21 100644 --- a/SensorHub.Noise/Noise.cs +++ b/SensorHub.Noise/Noise.cs @@ -347,7 +347,7 @@ { session.Logger.Info("进入远程升级流程[" + devName + " " + devCode + " " + softwareVersion + "]"); Common.remoteUpgrade(session, operType, devName, devCode, btPdu, softwareVersion, size, offset, source); - return; + // return; } // 回复校时信息 @@ -412,6 +412,21 @@ value.CopyTo(frame, 34); } + // 查询是否有需要下发的配置项 + byte[] configBytes = Common.BuildConfigBytes(devCode); + if (configBytes.Length > 0) + { + Array.Resize(ref frame, frame.Length + configBytes.Length); // 扩展长度 + configBytes.CopyTo(frame, 42); // 在后面加上其他配置项 + + int length = frame.Length - 4; + byte[] btLens = new byte[2]; //数据帧长度 + byte[] btlens0 = BitConverter.GetBytes(length); + btLens[0] = btlens0[1]; + btLens[1] = btlens0[0]; + btLens.CopyTo(frame, 2); + } + // SM4加密 byte[] tag = new byte[frame.Length - 16]; Array.Copy(frame, 16, tag, 0, tag.Length); // 需要加密的内容 diff --git a/SensorHub.Config/ConfigBuild.cs b/SensorHub.Config/ConfigBuild.cs index a9c1185..7dda940 100644 --- a/SensorHub.Config/ConfigBuild.cs +++ b/SensorHub.Config/ConfigBuild.cs @@ -104,7 +104,7 @@ } //获取配置tag - private static byte[] getConfigTag(String configItem) + public static byte[] getConfigTag(String configItem) { byte[] result = new byte[256]; int flag = 0; diff --git a/SensorHub.Noise/Noise.cs b/SensorHub.Noise/Noise.cs index ed689fe..638db21 100644 --- a/SensorHub.Noise/Noise.cs +++ b/SensorHub.Noise/Noise.cs @@ -347,7 +347,7 @@ { session.Logger.Info("进入远程升级流程[" + devName + " " + devCode + " " + softwareVersion + "]"); Common.remoteUpgrade(session, operType, devName, devCode, btPdu, softwareVersion, size, offset, source); - return; + // return; } // 回复校时信息 @@ -412,6 +412,21 @@ value.CopyTo(frame, 34); } + // 查询是否有需要下发的配置项 + byte[] configBytes = Common.BuildConfigBytes(devCode); + if (configBytes.Length > 0) + { + Array.Resize(ref frame, frame.Length + configBytes.Length); // 扩展长度 + configBytes.CopyTo(frame, 42); // 在后面加上其他配置项 + + int length = frame.Length - 4; + byte[] btLens = new byte[2]; //数据帧长度 + byte[] btlens0 = BitConverter.GetBytes(length); + btLens[0] = btlens0[1]; + btLens[1] = btlens0[0]; + btLens.CopyTo(frame, 2); + } + // SM4加密 byte[] tag = new byte[frame.Length - 16]; Array.Copy(frame, 16, tag, 0, tag.Length); // 需要加密的内容 diff --git a/SensorHub.Servers/Common.cs b/SensorHub.Servers/Common.cs index 0c55ab3..c8609e9 100644 --- a/SensorHub.Servers/Common.cs +++ b/SensorHub.Servers/Common.cs @@ -100,6 +100,19 @@ sendGPRSConfig(session, devCode, btPdu, source, "SM4"); } + public static byte[] BuildConfigBytes(string devCode) + { + RedisHelper redis = new RedisHelper(0); + + string configItem = null; + if (redis.Conn != null) + { + configItem = redis.StringGet(devCode); + } + + return ConfigBuild.getConfigTag(configItem); + } + public static void sendGPRSConfig(CasicSession session, string devCode, byte[] btPdu, string source, string mode) { RedisHelper redis = new RedisHelper(0); @@ -110,6 +123,8 @@ configItem = redis.StringGet(devCode); } + session.Logger.Info("收到Redis中的待下发配置:" + configItem); + byte[] config = ConfigBuild.buildConfigFrame(devCode, configItem); config[10] = 0x03; config[13] = btPdu[0]; @@ -305,7 +320,7 @@ string ret = AepDeviceCommand.CreateCommandLwm2mProfile(JsonConvert.SerializeObject(body)); session.Logger.Info(ret); - return Int16.Parse(JObject.Parse(ret)["code"].ToString()); + return Int32.Parse(JObject.Parse(ret)["code"].ToString()); } public static void sender433Config(CasicSession session, string devCode, byte[] btPdu, byte routeflag)