void ProcessSendCommand(object o) { if (o is string) { var s = (string)o; Logger.Info(s, "> BT"); port.WriteLine(s); } else { var cmd = (MuxCommand)o; var bytes = cmd.GetBytes(); var len = bytes.Length; if (len > 1023) { throw new Exception("WT32 command length limit is 10 bytes. Can't send: " + cmd.Command); } var buf = new byte[len + 5]; int pos = 0; buf[pos++] = 0xBF; // SOF buf[pos++] = (byte)cmd.Link; buf[pos++] = (byte)(len >> 8); // Flags (reserved) 6 bits + len 2 bits (256-1023) buf[pos++] = (byte)len; // + len 8 bits (0-255) Array.Copy(bytes, 0, buf, pos, len); pos += len; buf[pos++] = (byte)(((byte)cmd.Link) ^ 0xFF); // nlink Logger.Info("MUX " + (cmd.Link == Link.Control ? "CTRL" : cmd.Link.ToString()) + ": " + cmd.Command, "> BT"); port.Write(buf); } }
void ProcessSendCommand(object o) { var s = (string)o; port.WriteLine(s); Logger.Info(s, "> BT"); }