using HighWayIot.Log4net;
using HighWayIot.Repository.domain;
using HighWayIot.Repository.service.Impl;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.AxHost;
namespace HighWayIot.TouchSocket
{
public class BufferAnalysis
{
private static LogHelper logHelper = LogHelper.Instance;
///
/// 心跳报文分析
///
///
public static void HeartbeatSocket(string ip)
{
BaseHeartbeatServiceImpl sql = new BaseHeartbeatServiceImpl();
if (sql.UpdateHeartbeatInfo(ip) == 0)
{
RFIDHeartbeat heartbeat = new RFIDHeartbeat()
{
IP = ip,
BeatTime = DateTime.Now,
};
sql.AddHeartbeatInfo(heartbeat);
}
}
///
/// RFID发送设备状态
///
///
public static void RFIDStatusSocket(string ip)
{
BaseStateServiceImpl sql = new BaseStateServiceImpl();
RFIDState rFIDState = new RFIDState()
{
IP = ip,
LogTime = DateTime.Now,
};
sql.AddStateInfo(rFIDState);
}
///
/// RFID发送条码
///
///
public static void RFIDCodeSocket(JObject obj, string ip)
{
BaseContentServiceImpl sql = new BaseContentServiceImpl();
RFIDContent content;
if (obj["status"].Value() == "GR")
{
JArray jArray = obj["epc"] as JArray;
List list = new List();
foreach(var item in jArray)
{
list.Add(item.Value());
}
string epc = "";
for (int i = 0; i < list.Count; i++)
{
if (i == 0)
{
epc = list[i];
}
else
{
epc += "_" + list[i];
}
}
content = new RFIDContent()
{
IP = ip,
SN = obj["sn"].Value(),
Length = obj["length"].Value(),
Interval = obj["interval"].Value(),
Status = obj["status"].Value(),
EPC = epc,
Tips = obj["tips"].Value(),
LogTime = DateTime.Now,
};
}
else
{
content = new RFIDContent()
{
IP = ip,
SN = obj["sn"].Value(),
Length = obj["length"].Value(),
Interval = obj["interval"].Value(),
Status = obj["status"].Value(),
EPC = "",
Tips = obj["tips"].Value(),
LogTime = DateTime.Now,
};
}
sql.AddContentInfo(content);
}
///
/// 将一个数组拆成另外一个数组
///
/// 原始数组,被拆分的数组
/// 从原始数组第几个元素开始
/// 目标数组的长度
/// 目标数组开始的元素序号,默认为0
///
public static byte[] SplitByteArray(byte[] originbyte, int oringinstartindex, int destbytelength, int destbytestartindex = 0)
{
byte[] result = new byte[destbytelength];
System.Array.Copy(originbyte, oringinstartindex, result, destbytestartindex, destbytelength);
return result;
}
}
}