private void DataReceivedHandler(object sender, SerialDataArgs e) { if (e.ToString().StartsWith("#")) { try { byte[] msgIn = Convert.FromBase64String(e.ToString().TrimEnd(new char[] { '\n', '\r' }).TrimStart(new char[] { '#' })); UInt32 Subscriber = (UInt32)( ((msgIn[0] << 24)) | ((msgIn[1] << 16)) | ((msgIn[2] << 8)) | ((msgIn[3])) ); byte[] Payload = msgIn.GetRange(5, msgIn.Length - 5); if (!Settings.Background.Exist) { ConsoleEx.Info($"[timestamp] [yellow]MQTT <- MSG64:[reset] (#{Subscriber.ToString("X8")}) {Payload.ToHexString()}:{e.ToString().TrimEnd(new char[] { '\n', '\r' })}"); } client.Publish($"{Settings.ServerTopic}/rx", msgIn); } catch (FormatException Fe) { ConsoleEx.Error("[timestamp] Malformed BC Message, possible collision"); } } }
private void DataReceivedHandler(object sender, SerialDataArgs e) { if (e.ToString().StartsWith("#")) { try { byte[] msgIn = Convert.FromBase64String(e.ToString().TrimEnd(new char[] { '\n', '\r' }).TrimStart(new char[] { '#' })); UInt16 Subscriber = (UInt16)((msgIn[0] << 8) | (msgIn[1])); byte Operator = msgIn[2]; byte[] Payload = msgIn.GetRange(3, msgIn.Length - 3); Console.WriteLine($"req {Subscriber.ToString("X4")}"); if (NodeBySubscriptionHash.ContainsKey(Subscriber)) { NodeBySubscriptionHash[Subscriber].Operator = Operator; NodeBySubscriptionHash[Subscriber].Build(Payload); NodeBySubscriptionHash[Subscriber].EventGenerator(); //NodeBySubscriptionHash[Subscriber].Dump(); NodeBySubscriptionHash[Subscriber].msgUid = rand.Next(); Console.WriteLine($"mqtt pub -> substr: {NodeBySubscriptionHash[Subscriber].GetSubscription(),40} ({Subscriber.ToString("X4")}-{Operator.ToString("X2")}) uid:{NodeBySubscriptionHash[Subscriber].msgUid.ToString("X8")} : {NodeBySubscriptionHash[Subscriber].GetStringPayload()} "); BCMsg.WebInterfaceClass web = new BCMsg.WebInterfaceClass(NodeBySubscriptionHash[Subscriber]); client.Publish($"{web.subscriber}", web.Export().ToByteArr()); } } catch (FormatException Fe) { ConsoleEx.Error("Malformed BC Message, possible collision"); } } }
void SerialIo_LogData(CommunicationState communicationState, SerialDataArgs evenArgs) { }