public override void Send(string text) { base.Send(text); //_sp.Write(text); var buffer = Conversions.AsciiToBytes(text); _sp.Write(buffer, 0, buffer.Length); base.Send(Conversions.BytesToAscii(buffer)); }
public void AsciiToHexForLeadingZeroTests() { var d = "026219057B0F11FF"; var r1 = Conversions.HexToAscii(d); var r4 = Conversions.HexToBytes(d); var r5 = Conversions.BytesToAscii(r4); var r3 = Conversions.AsciiToBytes(r1); var r2 = Conversions.AsciiToHex(r1); Assert.AreEqual(d, r2); }
protected override List <Command> _DataToCommands(string data) { var commands = new List <Command>(); var dataB = Conversions.AsciiToBytes(data); var command = new Command(); if (dataB[0] == 0x02) { //Incoming Standard Message if (dataB[1] == 0x50) { command.Source = Conversions.BytesToHex(dataB[2]) + "." + Conversions.BytesToHex(dataB[3]) + "." + Conversions.BytesToHex(dataB[4]); command.Destination = Conversions.BytesToHex(dataB[5]) + "." + Conversions.BytesToHex(dataB[6]) + "." + Conversions.BytesToHex(dataB[7]); var messageType = _MessageType(dataB[8]); command.Primary = _CommandType(dataB[9]); command.Secondary = Conversions.BytesToInt(dataB[10]).ToString(); command.SourceObject = this; if (command.Primary != null && (messageType == InsteonMessageType.Broadcast || messageType == InsteonMessageType.Direct || messageType == InsteonMessageType.BroadCastLinkAll )) { commands.Add(command); Log(Core.Logger.Level.Info, String.Format("Received Command: {0} -> {1}: {2}", command.Source, command.Destination, command.Primary )); } } } return(commands); }
public override void Send(string data) { try { base.Send(data); if (IsOpen && _stream != null) { // Process the data sent by the client. //byte[] msg = System.Text.Encoding.ASCII.GetBytes(data); var msg = Conversions.AsciiToBytes(data); // Send back a response. _stream.Write(msg, 0, msg.Length); Log(message: String.Format("Sent: {0}", data)); } } catch (Exception ex) { Log(ex); } }
public override void Send(string data) { lock (connectingLock) { if (IsOpen && _stream != null) { // Process the data sent by the client. //byte[] msg = System.Text.Encoding.ASCII.GetBytes(data); var msg = Conversions.AsciiToBytes(data); // Send back a response. _stream.Write(msg, 0, msg.Length); Log(Core.Logger.Level.Debug, String.Format("Sent: {0}", data)); } else { Log(String.Format( "Client not connected to send: {0}", data)); } } }
protected override List <Command> _DataToCommands(string data) { var dBytes = Conversions.AsciiToBytes(data); var rBytes = Conversions.BytesReverse(dBytes); // If this is a corrupt packet, discard and exit if (rBytes[0] + rBytes[1] != 255 || rBytes[2] + rBytes[3] != 255) { Log("Corrupt Packet Received"); return(new List <Command>()); } var sBytes = new byte[4] { rBytes[2], rBytes[3], rBytes[0], rBytes[1], }; string houseCode = _HouseCodes[sBytes[2] & 0x0f]; int unitCode = ((sBytes[0] & 0x18) >> 3) + ((sBytes[0] & 0x02) << 1) + ((sBytes[2] & 0x20) >> 2) + 1; CommandType commandPrimary = null; switch (sBytes[0] & 0x05) { case 4: commandPrimary = CommandType.Off; break; case 0: commandPrimary = CommandType.On; break; default: commandPrimary = CommandType.Unknown; break; } var commands = new List <Command>() { new Command() { Primary = commandPrimary, Source = String.Format("{0}{1}", houseCode, unitCode), Destination = String.Format("{0}{1}", houseCode, unitCode), SourceObject = this, } }; if (commands[0] != null) { Log(Core.Logger.Level.Info, String.Format("Received Command: {0} -> {1}: {2}", commands[0].Source, commands[0].Destination, commands[0].Primary.ToString() )); } return(commands); }