修改解析
This commit is contained in:
parent
50a66a813d
commit
089c1d6fc5
|
|
@ -150,6 +150,15 @@ namespace Waste.Application
|
|||
{
|
||||
//记录日志
|
||||
_loggerService.AddLogger($"设备未找到,参数:{data.ToJson()}", 3);
|
||||
return;
|
||||
}
|
||||
//计算净重,毛重-皮重=净重,如果净重小于等于0则不上报保存
|
||||
decimal weight = (data.Weight.ToDecimal() - device.Tare).ToDecimal(2);
|
||||
if (weight <= 0)
|
||||
{
|
||||
//记录日志
|
||||
_loggerService.AddLogger($"净重为0不上报,参数:{data.ToJson()}", 3);
|
||||
return;
|
||||
}
|
||||
var devicedata = await dbClient.Queryable<W_DeviceData>().FirstAsync(x => x.DeviceId == device.Id);
|
||||
var resultid = IDGen.NextID();
|
||||
|
|
@ -176,7 +185,7 @@ namespace Waste.Application
|
|||
city = "",
|
||||
area = data.trashcode,
|
||||
wastetype = data.WasteType,
|
||||
weigth = data.Weight,
|
||||
weigth = weight,
|
||||
isheart = data.IsHeart,
|
||||
tare = device.Tare,
|
||||
isfrist = isfrist
|
||||
|
|
|
|||
|
|
@ -416,27 +416,17 @@ namespace Waste.Application.ThirdApiInfo
|
|||
byte[] newval = new byte[databytes.Length + result.databyte.Length];
|
||||
databytes.CopyTo(newval, 0);
|
||||
result.databyte.CopyTo(newval, databytes.Length);
|
||||
var datastr = Encoding.GetEncoding("gb2312").GetString(newval);
|
||||
datastr.Replace(@"\r\n", "");
|
||||
var arr = datastr.Split('@');
|
||||
string wastetype = arr[2];//垃圾类型
|
||||
string weight = arr[3];//重量,kg
|
||||
string trashno = string.Empty; //垃圾桶编号
|
||||
string size = string.Empty;//桶大小
|
||||
var sizebytes = Encoding.Default.GetBytes(arr[0]);
|
||||
size = Convert.ToHexString(sizebytes);
|
||||
var trashbytes = Encoding.Default.GetBytes(arr[1]);
|
||||
//长度为5个字节,后三位为垃圾桶编号(16进制)
|
||||
if (trashbytes.Length == 5)
|
||||
{
|
||||
var typeBytes = new byte[3];
|
||||
for (var i = 0; i < 3; i++)
|
||||
{
|
||||
typeBytes[i] = trashbytes[i + 2];
|
||||
}
|
||||
var typeHex = Convert.ToHexString(typeBytes);
|
||||
trashno = Convert.ToInt32(typeHex, 16).ToString();
|
||||
}
|
||||
//解析协议,IC卡数据@垃圾桶编号@厨余垃圾@7.91
|
||||
var datahex = BytesToHexStr(databytes);
|
||||
datahex = datahex.Replace(" ", "");
|
||||
//收到的为16进制,对数据进行解析,0-4预留,5-垃圾种类,6-垃圾桶大小,7-@,8-12垃圾桶编号,13@,14-21垃圾种类汉字,22@,23-结束重量
|
||||
var trashhex = datahex.Substring(16, 10); //垃圾桶编号
|
||||
var typehex = datahex.Substring(28, 16); //垃圾种类
|
||||
var size = datahex.Substring(12, 2);//桶大小,30-小桶,31-大桶
|
||||
var weighthex = datahex.Substring(46, datahex.Length - 46);
|
||||
string trashno = HextToDec(trashhex).ToString(); //垃圾桶编号使用10进制
|
||||
var wastetype = GetChsFromHex(typehex);
|
||||
var weight = GetChsFromHex(weighthex);
|
||||
await _resultService.InsertResultByWifiAsync(new WifiPackage
|
||||
{
|
||||
sn = result.sn,
|
||||
|
|
@ -451,7 +441,7 @@ namespace Waste.Application.ThirdApiInfo
|
|||
else
|
||||
{
|
||||
var val = await _cahce.GetAsync(result.sn);
|
||||
var time = new DistributedCacheEntryOptions().SetSlidingExpiration(TimeSpan.FromSeconds(60));
|
||||
var time = new DistributedCacheEntryOptions().SetSlidingExpiration(TimeSpan.FromSeconds(5));
|
||||
if (val != null && val.Length > 0)
|
||||
{
|
||||
byte[] newval = new byte[val.Length + result.databyte.Length];
|
||||
|
|
|
|||
|
|
@ -1782,6 +1782,11 @@
|
|||
重量,KG
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Waste.Application.WifiPackage.IsHeart">
|
||||
<summary>
|
||||
是否为心跳包
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:Waste.Application.IResultService">
|
||||
<summary>
|
||||
投放记录
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue