修改新版协议主机 协议触发的机制,新增 缓存机制

This commit is contained in:
2026-04-09 13:37:09 +08:00
parent c13ab0cb56
commit 36c2fa4061
22 changed files with 484 additions and 1897 deletions

View File

@@ -21,6 +21,7 @@ using System.Threading;
using System.Collections;
using Newtonsoft.Json;
using Microsoft.IO;
using System.Reflection;
namespace RCUHost.Implement
{
@@ -649,14 +650,15 @@ namespace RCUHost.Implement
//如果不存在就处理
else
{
//GaiXie g = new GaiXie();
//g.Data = receiveBuffer111;
//g.IPEndPoint = remoteEP111.ToString();
//var data = Newtonsoft.Json.JsonConvert.SerializeObject(g);
string s1 = Tools.ByteToString(receiveBuffer111);
string data = s1 + "#" + remoteEP111.ToString();
if (VVV.CmdType == 0x0E || VVV.CmdType == 0x01 || VVV.CmdType == 0x36)
{
ushort MyFrameNO = context.SystemHeader.Value.FrameNo;
byte[] framenolist = BitConverter.GetBytes(MyFrameNO);
Reply(context, framenolist);
}
//ProcessData(data);
CSRedisCacheHelper.StreamAdd(1, UDPAllDataKey, data);
@@ -676,15 +678,15 @@ namespace RCUHost.Implement
}
else
{
//GaiXie g = new GaiXie();
//g.Data = receiveBuffer111;
//g.IPEndPoint = remoteEP111.ToString();
//var data = Newtonsoft.Json.JsonConvert.SerializeObject(g);
string s1 = Tools.ByteToString_NoWhiteSpace(receiveBuffer111);
string data = s1 + "#" + remoteEP111.ToString();
//ProcessData(data);
if (VVV.CmdType == 0x0E || VVV.CmdType == 0x01 || VVV.CmdType == 0x36)
{
ushort MyFrameNO = context.SystemHeader.Value.FrameNo;
byte[] framenolist = BitConverter.GetBytes(MyFrameNO);
Reply(context, framenolist);
}
CSRedisCacheHelper.StreamAdd(1, UDPAllDataKey, data);
}
}
@@ -1221,8 +1223,6 @@ namespace RCUHost.Implement
/// 处理数据
/// </summary>
/// <param name="context"></param>
//private void ProcessData(ReceiverContext context111, string hotelCode)
//private void ProcessData(GaiXie gga)
private void ProcessData(string gga)
{
//GaiXie gga = new GaiXie();
@@ -1337,12 +1337,13 @@ namespace RCUHost.Implement
#region 0E 01
//36 就是新版本的0E
if (cmdType == 0x0E || cmdType == 0x01 || cmdType == 0x36)
{
StepTongJi.SendInfo(1.1, "0E 01指令回复开始", context111.MessageID, context111.IsMonitor);
Reply(context111, framenolist);
StepTongJi.SendInfo(1.2, "0E 01指令回复结束", context111.MessageID, context111.IsMonitor);
}
//回复放到上面
//if (cmdType == 0x0E || cmdType == 0x01 || cmdType == 0x36)
//{
//StepTongJi.SendInfo(1.1, "0E 01指令回复开始", context111.MessageID, context111.IsMonitor);
//Reply(context111, framenolist);
//StepTongJi.SendInfo(1.2, "0E 01指令回复结束", context111.MessageID, context111.IsMonitor);
//}
#endregion
///注册指令 也要推送
@@ -1743,7 +1744,8 @@ namespace RCUHost.Implement
}
}
public IDeviceControlReceiver DeviceControlReceiver { get; set; }
public static System.Reflection.PropertyInfo[] properties = typeof(HotelSeason).GetProperties();//获取所有属性
public static byte[] nocard_enum = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
public static object oo = new object();
private void NewXieYi(ReceiverContext context_1, string hotelCode_1, string HostNNN_1, byte[] framenolist_1, byte cmdType_1, string EndPoint_1, ushort MyFrameNO)
@@ -1836,6 +1838,8 @@ namespace RCUHost.Implement
if (qudian == 0x01)
{
VoiceRobotTrigger(1, hotelCode, HostNNN);
}
else if (qudian == 0x02)
{
@@ -1846,6 +1850,18 @@ namespace RCUHost.Implement
}
#region
try
{
JiJieChuLi(hotelCode, HostNNN, EndPoint, qudian);
}
catch (Exception ex)
{
logger.Error("季节出错了:"+ex.Message);
}
#endregion
NewVersionHexData ns = new NewVersionHexData();
ns.CmdType = 0x35;
ns.HotelCode = hotelCode;
@@ -2029,7 +2045,7 @@ namespace RCUHost.Implement
//给宝镜发送完整的数据
string hexdata = Tools.ByteToString(context111.Data);
CSRedisCacheHelper.Publish("redis-baojing-powerdata", hexdata);
//CSRedisCacheHelper.Publish("redis-baojing-powerdata", hexdata);
try
@@ -2762,6 +2778,73 @@ namespace RCUHost.Implement
}, tuple);
}
/// <summary>
/// 季节处理
/// </summary>
/// <param name="hotelCode"></param>
/// <param name="HostNNN"></param>
/// <param name="EndPoint"></param>
/// <param name="qudian"></param>
private void JiJieChuLi(string hotelCode, string HostNNN, string EndPoint, byte qudian)
{
//3、取电或断电时季节空调处理
HotelSeason hotelSeason = QuanJuVar.HotelSeaon.FirstOrDefault(A => A.SysHotel.Code.Equals(hotelCode));
if (hotelSeason != null)
{
int conditonType = (qudian == 1 ? 2 : 3);
List<HotelAirControl> list = QuanJuVar.HotelAirControl.Where(A => A.SysHotel!=null&&!string.IsNullOrEmpty(A.SysHotel.Code)&& A.SysHotel.Code.Equals(hotelCode) && A.ConditionType == conditonType && A.ActiveIndicator).ToList();
string ttt = CSRedisCacheHelper.HMGet<string>(5, CacheKey.HostId_HostNumber, HostNNN)[0];
if (string.IsNullOrEmpty(ttt))
{
return;
}
string[] NNN111 = ttt.Split('#');
string HostID = NNN111[0];
string RoomTypeID = NNN111[1];
int room_type_id = int.Parse(RoomTypeID);
var hostModals = QuanJuVar.RoomTypeDeviceModal.Where(A => A.RoomType.ID == room_type_id && A.Type == DeviceType.AirConditioner && A.ActiveIndicator).ToList();
if (list.Count > 0 && hostModals.Count > 0)
{
//System.Reflection.PropertyInfo[] properties = typeof(HotelSeason).GetProperties();//获取所有属性
foreach (HotelAirControl item in list)
{
foreach (PropertyInfo prop in properties)//遍历属性
{
if (prop.Name == "Month" + DateTime.Now.Month.ToString() && Convert.ToInt16(prop.GetValue(hotelSeason, null)) == item.Season)//当前月份所属该季节则发送命令给rcu设置空调
{
var D2 = item;
Task.Factory.StartNew(() =>
{
System.Threading.Thread.Sleep(item.DelayTime * 1000);//延迟执行
foreach (RoomTypeModal hostModal1 in hostModals)
{
Device device1 = new Device();
device1.Address = hostModal1.ModalAddress;
device1.AddressType = AddressType.DeviceAddress;
device1.Type = DeviceType.AirConditioner;
device1.Status = (byte)D2.Status;
device1.Brightness = 0;
device1.Temperature = (byte)D2.SettingTemp;
device1.FanSpeed = (byte)D2.FanSpeed;
device1.Mode = (byte)D2.Mode;
device1.Valve = 0;
device1.AirExecMode = (D2.Status << 14) + (D2.Mode << 12) + (D2.FanSpeed << 10) + (0 << 8) + D2.SettingTemp;//空调执行方式和内容
var span = EndPoint.Split(':');
string ip = span[0];
string port = span[1];
IPEndPoint eee = new IPEndPoint(IPAddress.Parse(ip), int.Parse(port));
DeviceControlReceiver.SendWithEndPoint(device1, eee);
}
});
break;
}
}
}
}
}
}
/// <summary>
/// 碳达人上报
/// </summary>