public void EncodeDecodeTest() { SanSensNetProtocol a = new SanSensNetProtocol(); var comm = a.Encode_SendCommand(5, 45, 2645); FrameType fr; FrCommand decodedComm = a.DecodeData(comm, out fr) as FrCommand; Assert.AreEqual(FrameType.FRCommand, fr); Assert.AreEqual(5, decodedComm.cmd); Assert.AreEqual(45, decodedComm.v1); Assert.AreEqual(2645, decodedComm.v2); }
public void EncodeDecodePayloadRawTest() { byte[] inpl = new byte[3]; inpl[0] = 7; inpl[1] = 8; inpl[2] = 9; SanSensNetProtocol a = new SanSensNetProtocol(); byte[] encoded = a.EncodePayload(inpl, FrameType.FRCommand); Assert.AreEqual(8, encoded.Length); int ft; var data = a.DecodeRawData(encoded, out ft); for (int i = 0; i < inpl.Length; i++) { Assert.AreEqual(inpl[i], data[i]); } }
private void sendCommandToolStripMenuItem_Click(object sender, EventArgs e) { SendCommand scf = new SendCommand(); if (scf.ShowDialog(this) == DialogResult.OK) { SanSensNetProtocol a = new SanSensNetProtocol(); byte[] buff = a.Encode_SendCommand(scf.CommandId, scf.V1, scf.V2); string publishtopic = ConfigurationManager.AppSettings["publishCommands_topic"]; Console.WriteLine("send commande"); MqttMessage mess = new MqttMessage(publishtopic, buff, 1, false); mqtt.publish(mess); } }
public void SendMessages(object state) { Console.WriteLine("send commande"); SanSensNetProtocol a = new SanSensNetProtocol(); byte[] buff = a.Encode_SendCommand(7, 54, 215); string publishtopic = ConfigurationManager.AppSettings["publishCommands_topic"]; MqttMessage mess = new MqttMessage(publishtopic, buff, 1, false); mqtt.publish(mess); }