| | |
| | | {
|
| | | var reResult = new ReceiptGatewayResult();
|
| | | reResult.listReceiptData = new string[listReceiptTopic.Count];
|
| | | reResult.JsonData = new string[listReceiptTopic.Count];
|
| | |
|
| | | var myGateway = device.Gateway;
|
| | | if (myGateway == null) |
| | | { |
| | |
| | | listReceiptTopic[i] = gatewayID + "/" + listReceiptTopic[i];
|
| | | }
|
| | |
|
| | | //接收数
|
| | | int receiptCount = 0;
|
| | | //蓝才刚整了个同一个主题可能会推送多个过来的机能
|
| | | var listCheckTopic = new HashSet<string>();
|
| | | Action<string, string> receiptAction = (topic, message) =>
|
| | | {
|
| | | var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
| | |
| | | {
|
| | | if (topic == listReceiptTopic[i])
|
| | | {
|
| | | if (listCheckTopic.Contains(topic) == true)
|
| | | {
|
| | | //这里写这个东西是有点用处的
|
| | | continue;
|
| | | }
|
| | | string deviceMac = jobject["DeviceAddr"].ToString();
|
| | | int deviceEpoint = 200;
|
| | | if (jobject.Property("Epoint") != null)
|
| | |
| | | return;
|
| | | }
|
| | | reResult.listReceiptData[i] = jobject["Data"].ToString();
|
| | | receiptCount++;
|
| | | if (jobject.Property("Time") != null)
|
| | | {
|
| | | //需要移除time这个字段
|
| | | jobject.Remove("Time");
|
| | | }
|
| | | reResult.JsonData[i] = jobject.ToString();
|
| | | if (listCheckTopic.Contains(topic) == false)
|
| | | {
|
| | | //加到检测主题对象中
|
| | | listCheckTopic.Add(topic);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | //超时时间
|
| | | int TimeOut = 0;
|
| | | waitTime = 20 * waitTime;
|
| | | while (receiptCount != listReceiptTopic.Count && TimeOut < waitTime)
|
| | | while (listCheckTopic.Count != listReceiptTopic.Count && TimeOut < waitTime)
|
| | | {
|
| | | //全部接收才退出
|
| | | System.Threading.Thread.Sleep(50);
|
| | |
| | | }
|
| | | myGateway.Actions -= receiptAction;
|
| | | receiptAction = null;
|
| | | if (receiptCount != listReceiptTopic.Count)
|
| | | if (listCheckTopic.Count != listReceiptTopic.Count)
|
| | | {
|
| | | reResult.ErrorMsgDiv = 0;
|
| | | }
|
| | |
| | | {
|
| | | //如果只有一个主题,则替换变量
|
| | | reResult.ReceiptData = reResult.listReceiptData[0];
|
| | | reResult.listReceiptData = null;
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | /// <param name="receiptCommand">指定接收命令符</param>
|
| | | /// <param name="receiptDataLength">指定接收数据的长度</param>
|
| | | /// <param name="waitTime">超时时间(秒)</param>
|
| | | /// <param name="listReceiptLength">附加检测数据接收长度,当接收的长度在这列表里面时,代表接收成功(旨在对应新旧设备,透传回复的长度可能不同)</param>
|
| | | /// <returns>网关返回的数据</returns>
|
| | | public ReceiptGatewayResult SendJobjectDataToGateway2(CommonDevice device, string sendData, string receiptCommand, int receiptDataLength, int waitTime = 5)
|
| | | public ReceiptGatewayResult SendJobjectDataToGateway2(CommonDevice device, string sendData, string receiptCommand, int receiptDataLength,
|
| | | int waitTime = 5, List<int> listReceiptLength = null)
|
| | | {
|
| | | var reResult = new ReceiptGatewayResult();
|
| | | var myGateway = device.Gateway;
|
| | |
| | | }
|
| | |
|
| | | var responseData = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ClientDataPassthroughResponseData>(jobject["Data"].ToString());
|
| | | //长度一致
|
| | | if (responseData.PassData.Length == receiptDataLength)
|
| | | //长度不一致
|
| | | if (responseData.PassData.Length != receiptDataLength)
|
| | | {
|
| | | var command = responseData.PassData[4].ToString() |
| | | + responseData.PassData[5].ToString()
|
| | | + responseData.PassData[2].ToString() |
| | | + responseData.PassData[3].ToString();
|
| | | //并且是这个命令
|
| | | if (command == receiptCommand)
|
| | | if (listReceiptLength == null)
|
| | | {
|
| | | reResult.ReceiptData = responseData.PassData;
|
| | | //如果没有附加检测长度,则直接返回
|
| | | return;
|
| | | }
|
| | | if (listReceiptLength.Contains(responseData.PassData.Length) == false)
|
| | | {
|
| | | //如果附加的检测长度里面,还不存在的话,直接返回
|
| | | return;
|
| | | }
|
| | | }
|
| | |
|
| | | var command = responseData.PassData[4].ToString()
|
| | | + responseData.PassData[5].ToString()
|
| | | + responseData.PassData[2].ToString()
|
| | | + responseData.PassData[3].ToString();
|
| | | //并且是这个命令
|
| | | if (command == receiptCommand)
|
| | | {
|
| | | reResult.ReceiptData = responseData.PassData;
|
| | | reResult.JsonData = new string[1];
|
| | | if (jobject.Property("Time") != null)
|
| | | {
|
| | | //需要移除time这个字段
|
| | | jobject.Remove("Time");
|
| | | }
|
| | | reResult.JsonData[0] = jobject.ToString();
|
| | | }
|
| | | }
|
| | | };
|