using SafeMobileLib; using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace MotoTRBO_XNL_Cmd { class RadioMessage { //set DEBUG=true to print data in console private bool DEBUG = false; private byte[] data; private int recvLength; public bool connectionStatus; private bool messageStatus;//decide if we need to send another message or not public bool speakerStatus = false; public int zoneNr,channelNr; public bool channelNrRecived; public static byte xnlFlag; private bool valid; private ushort length; private ushort opcode; private byte protocolId; private byte XNLflags; private ushort destAddr; private ushort sourceAddr; private ushort transID_low=0; private ushort transId; public byte transId_high = 0; private ushort payloadLength; private byte[] payload; // intern private ushort xnlAdress; private byte[] tempAuthKey; private byte[] majXNLVers = { 0x00, 0x00, 0x00, 0x00 }; #region constructor //constructor public RadioMessage() { } #endregion #region main process function //process message public bool processMessage(byte[] recvData, int recv) { data = recvData; recvLength = recv; //xnlFlag = 0x09; channelNrRecived = false; try { valid = false; //compute length length = bytes2ushort(data[0], data[1]); length += 2;// first to bytes are the curent length //validet message if (length == recvLength) { valid = true; } else { Utils.WriteLine("-------------- INValid messsage-------------", ConsoleType.XNL); } if (valid) { /* Console.WriteLine("-------------------------------------------------------- " + length); Console.WriteLine("-------------- processing message ----------------------"); Console.Write("Data: "); for (int i = 0; i < recvLength; i++) Console.Write(" 0x" + data[i].ToString("X")); Console.WriteLine(""); */ //set opcode opcode = bytes2ushort(data[2], data[3]); switch (opcode) { case (ushort)OPCODE_ENUM.XNL_MASTER_STATUS_BRDCST: //set transaction id transId = bytes2ushort(data[10], data[11]); messageStatus = true; Utils.WriteLine("RX : XNL_MASTER_STATUS_BRDCST", ConsoleType.XNL); break; case (ushort)OPCODE_ENUM.DEVICE_AUTH_KEY_REPLY: messageStatus = true; Utils.WriteLine("RX : DEVICE_AUTH_KEY_REPLY", ConsoleType.XNL); break; case (ushort)OPCODE_ENUM.DEVICE_CONN_REPLY: messageStatus = true; Utils.WriteLine("RX : DEVICE_CONN_REPLY", ConsoleType.XNL); break; case (ushort)OPCODE_ENUM.DATA_MSG: messageStatus = true; //Console.WriteLine("RX : DATA_MSG"); break; case (ushort)OPCODE_ENUM.DATA_MSG_ACK: messageStatus = false; /* Console.WriteLine("######### ACK MESSAGE RECEIVED ######### " + length); Console.Write("Data: "); for (int i = 2; i < length; i++) Console.Write(" 0x" + data[i].ToString("X")); Console.WriteLine(""); Console.WriteLine("#############################################"); */ break; default: messageStatus = false; break; } //set protocol id protocolId = data[4]; //set XNL flags XNLflags = data[5]; //set destination address destAddr = bytes2ushort(data[6], data[7]); //set source address sourceAddr = bytes2ushort(data[8], data[9]); //set paylaod length payloadLength = bytes2ushort(data[12], data[13]); //if any payload set it if (payloadLength > 0) { //Console.WriteLine("payload lenth=" + payloadLength); payload = new byte[payloadLength]; for (int i = 14; i < length; i++) { payload[i - 14] = data[i]; } //process payload switch (opcode) { case (ushort)OPCODE_ENUM.XNL_MASTER_STATUS_BRDCST: break; case (ushort)OPCODE_ENUM.DEVICE_AUTH_KEY_REPLY: processPayloadForAuth(); break; case (ushort)OPCODE_ENUM.DEVICE_CONN_REPLY: if (processConnection() == true) { } else { Utils.WriteLine("====ERROR processConnection OPCODE_ENUM.DEVICE_CONN_REPLY==== \nprocessConnection() == false", ConsoleType.XNL); } break; case (ushort)OPCODE_ENUM.DATA_MSG: ushort pOpcode = bytes2ushort(payload[0], payload[1]); if (pOpcode == (ushort)OPCODE_ENUM.DEVINITSTS) { if (payload[6] == 0x00) { byte temp_transID = data[10]; Utils.WriteLine("TransId_high:" + transId_high + " temp_transID:" + temp_transID + " transID:" + transId, ConsoleType.XNL); connectionStatus = true; if (this.OnAuthDone != null) { this.OnAuthDone(this); } } } else { //regular data message continue processPayload(); } break; default: { //Console.WriteLine("Opcode: " + opcode); } break; } byte temp_transID2 = data[10]; //Console.WriteLine("TransId_high:" + transId_high + " temp_transID:" + temp_transID2 + " transID:" + transId); } } else { //Console.WriteLine("Invalid message ::Length=" + length + " || actual length=" + recvLength); //Console.Write("Data: "); //for (int i = 2; i < length; i++) //Console.Write(" 0x" + data[i].ToString("X")); //Console.WriteLine("--------------------------------------------------------------------------- "); }//if valid end }//try end :D catch (Exception ex) { Utils.WriteLine("MotoTrbo_XNL_CMD/RadioMessage.cs/processMessage ", ConsoleType.XNL); Utils.WriteLine(ex.ToString(), ConsoleType.XNL); throw ex; } //Console.WriteLine("-------------------------------------------------------- "); return messageStatus; }// process message end #endregion #region aux function //convert 2 bytes to 1 ushort public static ushort bytes2ushort(byte first, byte second) { ushort us; us = (ushort)first; us <<= 8; us |= (ushort)second; return us; } #endregion //process payload #region process payload functions //process auth key private void processPayloadForAuth() { try { xnlAdress = bytes2ushort(payload[0], payload[1]); Utils.WriteLine("Temp XNL address:" + xnlAdress, ConsoleType.XNL); if (payloadLength > 0) { //Console.WriteLine("payload lenth=" + payloadLength); tempAuthKey = new byte[payload.Length - 2]; for (int i = 2; i < payloadLength; i++) { tempAuthKey[i - 2] = payload[i]; } } ///new code MTteaEncoder mtCsharp = new MTteaEncoder(); uint[] tempKey = mtCsharp.ConvertTea(tempAuthKey[0], tempAuthKey[1], tempAuthKey[2], tempAuthKey[3], tempAuthKey[4], tempAuthKey[5], tempAuthKey[6], tempAuthKey[7]); byte[] temp1 = BitConverter.GetBytes(tempKey[0]); byte[] temp2 = BitConverter.GetBytes(tempKey[1]); byte[] output = new byte[8]; for (int i = 0; i < 4; i++) { output[i] = temp1[i]; output[i + 4] = temp2[i]; } tempAuthKey = output; } catch (Exception ex) { Utils.WriteLine(ex.ToString(), ConsoleType.XNL); } } //get data from auth reply private bool processConnection() { try { Utils.WriteLine(" Init processConnection()", ConsoleType.XNL); Utils.WriteLine("Length:" + payloadLength + " payload[0]:" + payload[0], ConsoleType.XNL); if (payloadLength > 0) { //test if auth has been successfuly if (payload[0] == 1) { //Console.WriteLine("data1=" + payload[1].ToString("X")); transId = bytes2ushort(payload[1], 0x01); transId_high = payload[1]; Utils.WriteLine("TransId_high:" + transId_high, ConsoleType.XNL); //Console.WriteLine("+++++++++++++CONNECTED++++++++++++++"); xnlAdress = bytes2ushort(payload[2], payload[3]); //connectionStatus = true; return true; } else { Utils.WriteLine("processConnection : payload[0] != 1 ... auth failed!!!", ConsoleType.XNL); return false; } } else { return false; } } catch (Exception ex) { Utils.WriteLine(ex.ToString(), ConsoleType.XNL); return false; } } //process payload (test if an ACK for any of the messages sent is receied) private void processPayload() { if (DEBUG) { Utils.WriteLine("--------------------------------------------------------------------------- " + length, ConsoleType.XNL); Utils.WriteLine("Data: ", ConsoleType.XNL); for (int i = 2; i < length; i++) Utils.Write(" 0x" + data[i].ToString("X2"), ConsoleType.XNL); Utils.WriteLine("", ConsoleType.XNL); Utils.WriteLine("--------------------------------------------------------------------------- ", ConsoleType.XNL); } ushort pOpcode = bytes2ushort(payload[0], payload[1]); switch (pOpcode) { case (ushort)OPCODE_ENUM.SPKRSTAT: ushort function = bytes2ushort(payload[4], payload[5]); if (function == 0x0001) { speakerStatus = true; //Console.WriteLine("Speakers ON (reciving data from another radio)"); if (this.OnSpeakersEvent != null) { this.OnSpeakersEvent(true); } } else { speakerStatus = false; if (this.OnSpeakersEvent != null) { this.OnSpeakersEvent(false); } //Console.WriteLine("Speakers OFF (reciving data from another radio)"); } break; case (ushort)OPCODE_ENUM.CHANNEL_Broadcast: zoneNr = (int)bytes2ushort(payload[2], payload[3]); //Console.WriteLine("CHANNEL_Broadcas Zone nr recived =" + zoneNr.ToString()); channelNr = (int)bytes2ushort(payload[4], payload[5]); //Console.WriteLine("CHANNEL_Broadcas Channel nr recived =" + channelNr.ToString()); channelNrRecived = true; if (this.OnChannelEvent != null) { this.OnChannelEvent(zoneNr, channelNr); } break; case (ushort)OPCODE_ENUM.CHANNEL: if (payload[2] == 0x00 && payload[3] == 0x80)//success { zoneNr = (int)bytes2ushort(payload[4], payload[5]); //Console.WriteLine("CHANNEL reply Zone nr recived =" + zoneNr.ToString()); channelNr = (int)bytes2ushort(payload[6], payload[7]); //Console.WriteLine("CHANNEL reply Channel nr recived =" + channelNr.ToString()); channelNrRecived = true; if (this.OnChannelEvent != null) { this.OnChannelEvent(zoneNr,channelNr); } } else { if (payload[3] != 0x05) Utils.WriteLine("Channel nr recived ERROR!!!!", ConsoleType.XNL); } break; case (ushort)OPCODE_ENUM.INCOMINGCALL: if (payload[3] == 0x01 || payload[3] == 0x02) { byte[] temp = { payload[6], payload[7], payload[8] }; int i = payload[8] + payload[7] * 256 + payload[6] * 256 * 256; //Console.WriteLine("Incomming call from " + i + " calltype:"+payload[2]);// + payload[].ToString()); int callType = payload[2]; int groupId = 0; if (payloadLength > 14) { groupId = payload[14] + payload[13] * 256 + payload[12] * 256 * 256; } CALL_STATUS cStatus = (payload[3] ==1)?CALL_STATUS.INIT:CALL_STATUS.INCALL; if (this.OnCallEvent != null) { this.OnCallEvent(cStatus, i, callType, groupId); } } else { if (payload[3] == 0x03 || payload[3] == 0x07) { byte[] temp = { payload[6], payload[7], payload[8] }; int i = payload[8] + payload[7] * 256 + payload[6] * 256 * 256; //Console.WriteLine("Call end from " + i + " calltype:" + payload[2]);// + payload[].ToString()); int callType = payload[2]; int groupId = 0; if (payloadLength > 14) { groupId = payload[14] + payload[13] * 256 + payload[12] * 256 * 256; } CALL_STATUS cStatus = (payload[3] == 3) ? CALL_STATUS.CALLEND : CALL_STATUS.HANGTIMER; if (this.OnCallEvent != null) { this.OnCallEvent(cStatus, i, callType, groupId); } } } break; case (ushort)OPCODE_ENUM.TRANSMITCONTROL: bool onoff = (payload[3] == 1); if (this.OnTransmitEvent != null) { this.OnTransmitEvent(onoff); } break; case (ushort)OPCODE_ENUM.REMOTE_CONTROL_BROADCAST: if (payload[3] != 0x20 && payload[3] != 0x21) { bool status = (payload[3] == 0x10); REMOTE_RADIO_FUNCS func = (REMOTE_RADIO_FUNCS)payload[2]; int radioID = payload[8] + payload[7] * 256 + payload[6] * 256 * 256; if (this.OnRemoteControlEvent != null) { this.OnRemoteControlEvent(status, func, radioID); } } break; case (ushort)OPCODE_ENUM.EMERGENCY_BROADCAST: if (payload[2] == 0x3) { int rID = payload[7] + payload[6] * 256 + payload[5] * 256 * 256; if (this.OnEmergencyEvent != null) { this.OnEmergencyEvent(rID,true); } } else if (payload[2] == 0x00) { //int rID = payload[7] + payload[6] * 256 + payload[5] * 256 * 256; if (this.OnEmergencyEvent != null) { this.OnEmergencyEvent(0, false); } } break; case (ushort)OPCODE_ENUM.EMGREP: { int status = payload[2]; int func = payload[3]; if (this.OnSendEmergencyEvent != null) { this.OnSendEmergencyEvent(func, status); } break; } case (ushort) OPCODE_ENUM.SHUTDOWN_BROADCAST: if (payload[2] == 0x00) { if (this.OnRestartEvent != null) { this.OnRestartEvent(); } } break; case (ushort)OPCODE_ENUM.VERSION_REPLY: if (payload[2] == 0x00) { //get vesrsion from payload //skip first 3 bytes (2 are opcode, 1 is the result 0-ok 4-invalid parameter) //skip the last byte that is NULL, ascii code 0x00 string str = System.Text.Encoding.ASCII.GetString(payload, 3, payloadLength-4); if (this.OnVersionEvent != null) { this.OnVersionEvent(str); } } break; case (ushort) OPCODE_ENUM.INUPDAT: break; case (ushort)OPCODE_ENUM.DISPTEXT: break; //case (ushort)OPCODE_ENUM.NAVBRDCST: case (ushort)OPCODE_ENUM.NAVREP: if (this.OnNavRepEvent != null) { this.OnNavRepEvent(payload[2], payload[3]); } break; default: Utils.WriteLine("", ConsoleType.XNL); Utils.WriteLine("******************UNPROCESS********************", ConsoleType.XNL); Utils.WriteLine("OPCODE :0x"+ payload[0].ToString("X")+ payload[1].ToString("X2"), ConsoleType.XNL); Utils.WriteLine("payload: ", ConsoleType.XNL); for (int i = 0; i < payload.Length; i++) Utils.Write(" 0x" + payload[i].ToString("X2"), ConsoleType.XNL); Utils.WriteLine("", ConsoleType.XNL); Utils.WriteLine("***********************************************", ConsoleType.XNL); Utils.WriteLine("", ConsoleType.XNL); break; }//swith end }//processPayload end #endregion #region EVENTS public delegate void AuthDone(RadioMessage rm); public event AuthDone OnAuthDone; public delegate void SpeakersEvent(bool onOFF); public event SpeakersEvent OnSpeakersEvent; public delegate void CallEvent(CALL_STATUS status, int callerID, int callType, int groupID); public event CallEvent OnCallEvent; public delegate void TransmitEvent(bool onOFF); public event TransmitEvent OnTransmitEvent; public delegate void ChannelEvent(int zoneNR,int channelNr); public event ChannelEvent OnChannelEvent; public delegate void RemoteControlEvent(bool status, REMOTE_RADIO_FUNCS func, int radioId); public event RemoteControlEvent OnRemoteControlEvent; public delegate void EmergencyEvent(int radioId, bool status); public event EmergencyEvent OnEmergencyEvent; public delegate void SendEmergencyEvent(int function, int status); public event SendEmergencyEvent OnSendEmergencyEvent; public delegate void RestartEvent(); public event RestartEvent OnRestartEvent; public delegate void VersionEvent(string version); public event VersionEvent OnVersionEvent; public delegate void NavRepEvent(int function, int status); public event NavRepEvent OnNavRepEvent; #endregion //create stepicfic messages ptt,channel request,set cal type ..... #region create specific messages //ptt 0x0415 – KEYREQ – Transmit Control Request; public byte[] pttONOFF(bool state) { byte[] temp = new byte[2]; //Console.WriteLine(" "); //Console.WriteLine("--------------------------------------------------------------------------- "); transID_low++; if (transID_low > 255) transID_low = 0; byte[] br_off = new byte[18]; //add message length br_off[0] = 0x00; br_off[1] = 0x10; //add opcode temp = BitConverter.GetBytes((ushort)OPCODE_ENUM.DATA_MSG); br_off[2] = temp[1]; br_off[3] = temp[0]; //add protocol id br_off[4] = protocolId; //add XNL flags br_off[5] = 0x01; //add destination addres (previous message source address) temp = BitConverter.GetBytes(sourceAddr); br_off[6] = temp[1]; br_off[7] = temp[0]; //add source addres () temp = BitConverter.GetBytes(xnlAdress); br_off[8] = temp[1]; br_off[9] = temp[0]; //add transaction ID temp = BitConverter.GetBytes(transID_low); byte[] temp1 = BitConverter.GetBytes(transId); br_off[10] = temp1[1]; br_off[11] = temp[0]; //add payload length temp = BitConverter.GetBytes(0x0004); br_off[12] = temp[1]; br_off[13] = temp[0]; temp = BitConverter.GetBytes(0x0415); br_off[14] = temp[1]; br_off[15] = temp[0]; //function if (state) { //Console.WriteLine("Creating message for ptt on"); br_off[16] = 0x01; br_off[5] = 0x01; } else { //Console.WriteLine("Creating message for ptt off"); br_off[16] = 0x02; br_off[5] = 0x02; } //call type br_off[17] = 0x00; //for (int i = 0; i < 18; i++) ///Console.Write(" 0x" + br_off[i].ToString("X") + " "); //Console.WriteLine(" "); return br_off; } //ptt 0xb405 – user Inputs public byte[] pttWithPUI(bool onOF) { byte[] temp = new byte[2]; //Console.WriteLine(" "); //Console.WriteLine("--------------PUI------------------------------------------------------------- "); transID_low++; if (transID_low > 255) transID_low = 0; byte[] br_off = new byte[23]; //add message length br_off[0] = 0x00; br_off[1] = 0x15; //add opcode temp = BitConverter.GetBytes((ushort)OPCODE_ENUM.DATA_MSG); br_off[2] = temp[1]; br_off[3] = temp[0]; //add protocol id br_off[4] = protocolId; //add XNL flags br_off[5] = 0x01; //add destination addres (previous message source address) temp = BitConverter.GetBytes(sourceAddr); br_off[6] = temp[1]; br_off[7] = temp[0]; //add source addres () temp = BitConverter.GetBytes(xnlAdress); br_off[8] = temp[1]; br_off[9] = temp[0]; //add transaction ID temp = BitConverter.GetBytes(transID_low); byte[] temp1 = BitConverter.GetBytes(transId); br_off[10] = temp1[1]; br_off[11] = temp[0]; //add payload length temp = BitConverter.GetBytes(0x0009); br_off[12] = temp[1]; br_off[13] = temp[0]; //opcode temp = BitConverter.GetBytes(0xb405); br_off[14] = temp[1]; br_off[15] = temp[0]; //PUI source br_off[16] = 0x03; //PUI TYPE br_off[17] = 0x00; //PUI ID temp = BitConverter.GetBytes(0x0001); br_off[18] = temp[1]; br_off[19] = temp[0]; //pui state if (onOF) { br_off[20] = 0x01; br_off[5] = 0x01; } else { br_off[20] = 0x00; br_off[5] = 0x02; } //pui min/max br_off[21] = 0x00; br_off[22] = 0x03; Utils.WriteLine(" PUI code start", ConsoleType.XNL); for (int i = 0; i < 18; i++) Utils.Write(" 0x" + br_off[i].ToString("X2") + " ", ConsoleType.XNL); Utils.WriteLine(" PUI code end", ConsoleType.XNL); return br_off; } //back button 0xb405 – user Inputs ( button code 0x0081) public byte[] backBtnShortPress(bool status) { byte[] temp = new byte[2]; //Console.WriteLine(" "); //Console.WriteLine("--------------BACK BUtton PUI------------------------------------------- "); transID_low++; if (transID_low > 255) transID_low = 0; byte[] br_off = new byte[23]; //add message length br_off[0] = 0x00; br_off[1] = 0x15; //add opcode temp = BitConverter.GetBytes((ushort)OPCODE_ENUM.DATA_MSG); br_off[2] = temp[1]; br_off[3] = temp[0]; //add protocol id br_off[4] = protocolId; //add XNL flags br_off[5] = 0x01; //add destination addres (previous message source address) temp = BitConverter.GetBytes(sourceAddr); br_off[6] = temp[1]; br_off[7] = temp[0]; //add source addres () temp = BitConverter.GetBytes(xnlAdress); br_off[8] = temp[1]; br_off[9] = temp[0]; //add transaction ID temp = BitConverter.GetBytes(transID_low); byte[] temp1 = BitConverter.GetBytes(transId); br_off[10] = temp1[1]; br_off[11] = temp[0]; //add payload length temp = BitConverter.GetBytes(0x0009); br_off[12] = temp[1]; br_off[13] = temp[0]; //opcode temp = BitConverter.GetBytes(0xb405); br_off[14] = temp[1]; br_off[15] = temp[0]; //PUI source br_off[16] = 0x00; //PUI TYPE br_off[17] = 0x00; //PUI ID temp = BitConverter.GetBytes(0x0081); br_off[18] = temp[1]; br_off[19] = temp[0]; //pui state if (status) { br_off[20] = 0x01; br_off[5] = 0x01; } else { br_off[20] = 0x00; br_off[5] = 0x02; } //pui min/max br_off[21] = 0x00; br_off[22] = 0x03; //for (int i = 0; i < 18; i++) ///Console.Write(" 0x" + br_off[i].ToString("X") + " "); //Console.WriteLine(" "); return br_off; } //P4 button 0xb405 – user Inputs ( button code 0x00A3) public byte[] btnP4longPress(bool status) { byte[] temp = new byte[2]; //Console.WriteLine(" "); //Console.WriteLine("--------------P4 BUtton PUI------------------------------------------- "); transID_low++; if (transID_low > 255) transID_low = 0; byte[] br_off = new byte[23]; //add message length br_off[0] = 0x00; br_off[1] = 0x15; //add opcode temp = BitConverter.GetBytes((ushort)OPCODE_ENUM.DATA_MSG); br_off[2] = temp[1]; br_off[3] = temp[0]; //add protocol id br_off[4] = protocolId; //add XNL flags br_off[5] = 0x01; //add destination addres (previous message source address) temp = BitConverter.GetBytes(sourceAddr); br_off[6] = temp[1]; br_off[7] = temp[0]; //add source addres () temp = BitConverter.GetBytes(xnlAdress); br_off[8] = temp[1]; br_off[9] = temp[0]; //add transaction ID temp = BitConverter.GetBytes(transID_low); byte[] temp1 = BitConverter.GetBytes(transId); br_off[10] = temp1[1]; br_off[11] = temp[0]; //add payload length temp = BitConverter.GetBytes(0x0009); br_off[12] = temp[1]; br_off[13] = temp[0]; //opcode temp = BitConverter.GetBytes(0xb405); br_off[14] = temp[1]; br_off[15] = temp[0]; //PUI source br_off[16] = 0x00; //PUI TYPE br_off[17] = 0x00; //PUI ID temp = BitConverter.GetBytes(0x00A3); br_off[18] = temp[1]; br_off[19] = temp[0]; //pui state if (status) { br_off[20] = 0x01; br_off[5] = 0x01; } else { br_off[20] = 0x00; br_off[5] = 0x02; } //pui min/max br_off[21] = 0x00; br_off[22] = 0x03; return br_off; } //0x040E – MICCTRLREQ – Microphone Control Request(this doesnt work) - for future use public byte[] micONoff(bool state) { transID_low++; if (transID_low > 255) transID_low = 0; byte[] temp = new byte[2]; byte[] br_off = new byte[20]; //add message length br_off[0] = 0x00; br_off[1] = 0x12; //add opcode temp = BitConverter.GetBytes((ushort)OPCODE_ENUM.DATA_MSG); br_off[2] = temp[1]; br_off[3] = temp[0]; //add protocol id br_off[4] = protocolId; //add XNL flags br_off[5] = 0x01; //add destination addres (previous message source address) temp = BitConverter.GetBytes(sourceAddr); br_off[6] = temp[1]; br_off[7] = temp[0]; //add source addres () temp = BitConverter.GetBytes(xnlAdress); br_off[8] = temp[1]; br_off[9] = temp[0]; //add transaction ID temp = BitConverter.GetBytes(transID_low); byte[] temp1 = BitConverter.GetBytes(transId); br_off[10] = temp1[1]; br_off[11] = temp[0]; //add payload length temp = BitConverter.GetBytes(0x0006); br_off[12] = temp[1]; br_off[13] = temp[0]; //opcode temp = BitConverter.GetBytes(0x040e); br_off[14] = temp[1]; br_off[15] = temp[0]; //function if (state) { br_off[16] = 0x01; br_off[5] = 0x02; } else { br_off[16] = 0x02; br_off[5] = 0x02; } //mic type br_off[17] = 0x01; //signal type br_off[18] = 0x01; //mic gain br_off[19] = 0x00; return br_off; } //0x041E – CALLCTRLREQ – Call Control Request; //int type ====GROUP=0/Private=1/allCall=2 //int groupOrSubscriberId(passed from SD) or 0 if it is an all call /// /// 0x041E – CALLCTRLREQ – Call Control Request; /// int type ====GROUP=0/Private=1/allCall=2 /// int groupOrSubscriberId(passed from SD) or 0 if it is an all call /// /// /// /// public byte[] callType(int type, int groupOrSubscriberId) { transID_low++; if (transID_low > 255) transID_low = 0; byte[] temp = new byte[2]; byte[] br_off = new byte[29]; //add message length br_off[0] = 0x00; br_off[1] = 0x1b; //add opcode temp = BitConverter.GetBytes((ushort)OPCODE_ENUM.DATA_MSG); br_off[2] = temp[1]; br_off[3] = temp[0]; //add protocol id br_off[4] = protocolId; //add XNL flags br_off[5] = 0x01; //add destination addres (previous message source address) temp = BitConverter.GetBytes(sourceAddr); br_off[6] = temp[1]; br_off[7] = temp[0]; //add source addres () temp = BitConverter.GetBytes(xnlAdress); br_off[8] = temp[1]; br_off[9] = temp[0]; //add transaction ID temp = BitConverter.GetBytes(transID_low); byte[] temp1 = BitConverter.GetBytes(transId); br_off[10] = temp1[1]; br_off[11] = temp[0]; //add payload length temp = BitConverter.GetBytes(0x000f); br_off[12] = temp[1]; br_off[13] = temp[0]; //opcode temp = BitConverter.GetBytes(0x041e); br_off[14] = temp[1]; br_off[15] = temp[0]; //function br_off[16] = 0x01; //call type br_off[17] = 0x06; //remote address br_off[18] = 0x01; br_off[19] = 0x03; br_off[20] = 0x00; br_off[21] = 0x00; br_off[22] = 0x00; //rezerved nr br_off[23] = 0x00; br_off[24] = 0x00; //group id size br_off[25] = 0x03; //group id number br_off[26] = 0xff; br_off[27] = 0xff; br_off[28] = 0xff; // modifie parameters to create group or private call (!!!! default is all call!!!!!) switch (type) { case 0: //call type br_off[17] = 0x06; //transaction id br_off[5] = 0x03; //group id number temp = BitConverter.GetBytes(groupOrSubscriberId); br_off[26] = temp[2]; br_off[27] = temp[1]; br_off[28] = temp[0]; break; case 1: //call type br_off[17] = 0x04; //transaction id br_off[5] = 0x04; //remote address temp = BitConverter.GetBytes(groupOrSubscriberId); br_off[20] = temp[2]; br_off[21] = temp[1]; br_off[22] = temp[0]; break; case 2: //transaction id br_off[5] = 0x05; break; default: //call type //Console.WriteLine("Creating message for all call"); //transaction id br_off[5] = 0x05; break; } /* Console.Write("TX :"); for (int i = 0; i < br_off.Length; i++) Console.Write(" 0x" + br_off[i].ToString("X") + " "); Console.WriteLine(" "); */ return br_off; } //0x040D – CHZNSELREQ – Channel Zone Selection Request //channelnr -- channel number; if 0 the query for current channel nr public byte[] channelSelect(int channelNR, int zoneNr) { transID_low++; if (transID_low > 255) transID_low = 0; byte[] temp = new byte[2]; byte[] br_off = new byte[21]; //add message length br_off[0] = 0x00; br_off[1] = 0x13; //add opcode temp = BitConverter.GetBytes((ushort)OPCODE_ENUM.DATA_MSG); br_off[2] = temp[1]; br_off[3] = temp[0]; //add protocol id br_off[4] = protocolId; //add XNL flags br_off[5] = 0x01; //add destination addres (previous message source address) temp = BitConverter.GetBytes(sourceAddr); br_off[6] = temp[1]; br_off[7] = temp[0]; //add source addres () temp = BitConverter.GetBytes(xnlAdress); br_off[8] = temp[1]; br_off[9] = temp[0]; //add transaction ID temp = BitConverter.GetBytes(transID_low); byte[] temp1 = BitConverter.GetBytes(transId); br_off[10] = temp1[1]; br_off[11] = temp[0]; //add payload length temp = BitConverter.GetBytes(0x0007); br_off[12] = temp[1]; br_off[13] = temp[0]; //opcode temp = BitConverter.GetBytes(0x040D); br_off[14] = temp[1]; br_off[15] = temp[0]; //function br_off[16] = 0x80; //zone number temp = BitConverter.GetBytes(0x0000); br_off[17] = temp[1]; br_off[18] = temp[0]; //channel number temp = BitConverter.GetBytes(channelNR); br_off[19] = temp[1]; br_off[20] = temp[0]; if (xnlFlag > 0x40) { xnlFlag = 0x09; } if (channelNR == 0 && zoneNr ==0) { //Console.WriteLine("Creating message for CHANNel querry"); br_off[16] = 0x80; br_off[5] = xnlFlag++; //Console.WriteLine("xnlFlag=" + xnlFlag.ToString()); } else { //Console.WriteLine("Creating message for CHANNel selection"); br_off[16] = 0x05; br_off[5] = xnlFlag++; //zone number temp = BitConverter.GetBytes(zoneNr); br_off[17] = temp[1]; br_off[18] = temp[0]; //channel number temp = BitConverter.GetBytes(channelNR); br_off[19] = temp[1]; br_off[20] = temp[0]; } return br_off; } //0x041C – RRCTRLREQ – Remote Radio Control Request public byte[] remoteRadioControl(int radioID, REMOTE_RADIO_FUNCS remoteFunction) { transID_low++; if (transID_low > 255) transID_low = 0; byte[] temp = new byte[2]; byte[] br_off = new byte[29]; //add message length br_off[0] = 0x00; br_off[1] = 0x1b; //add opcode temp = BitConverter.GetBytes((ushort)OPCODE_ENUM.DATA_MSG); br_off[2] = temp[1]; br_off[3] = temp[0]; //add protocol id br_off[4] = protocolId; //add XNL flags br_off[5] = xnlFlag++; //add destination addres (previous message source address) temp = BitConverter.GetBytes(sourceAddr); br_off[6] = temp[1]; br_off[7] = temp[0]; //add source addres () temp = BitConverter.GetBytes(xnlAdress); br_off[8] = temp[1]; br_off[9] = temp[0]; //add transaction ID temp = BitConverter.GetBytes(transID_low); byte[] temp1 = BitConverter.GetBytes(transId); br_off[10] = temp1[1]; br_off[11] = temp[0]; //add payload length temp = BitConverter.GetBytes(0x000f); br_off[12] = temp[1]; br_off[13] = temp[0]; //opcode temp = BitConverter.GetBytes(0x041C); br_off[14] = temp[1]; br_off[15] = temp[0]; //Feature br_off[16] = (byte)remoteFunction; //Operation br_off[17] = 0x01; //Remote Address Structure br_off[18] = 0x01; br_off[19] = 0x03; //remote address temp = BitConverter.GetBytes(radioID); br_off[20] = temp[2]; br_off[21] = temp[1]; br_off[22] = temp[0]; //rezerved nr br_off[23] = 0x00; br_off[24] = 0x00; //group id size br_off[25] = 0x03; //group id number br_off[26] = 0xff; br_off[27] = 0xff; br_off[28] = 0xff; return br_off; } //0x0413 – SHUTDWNREQ – Shut Down Request public byte[] SendEmergencyAck() { transID_low++; if (transID_low > 255) transID_low = 0; byte[] temp = new byte[2]; byte[] br_off = new byte[19]; //add message length br_off[0] = 0x00; br_off[1] = 0x11; //add opcode temp = BitConverter.GetBytes((ushort)OPCODE_ENUM.DATA_MSG); br_off[2] = temp[1]; br_off[3] = temp[0]; //add protocol id br_off[4] = protocolId; //add XNL flags br_off[5] = xnlFlag++; //add destination addres (previous message source address) temp = BitConverter.GetBytes(sourceAddr); br_off[6] = temp[1]; br_off[7] = temp[0]; //add source addres () temp = BitConverter.GetBytes(xnlAdress); br_off[8] = temp[1]; br_off[9] = temp[0]; //add transaction ID temp = BitConverter.GetBytes(transID_low); byte[] temp1 = BitConverter.GetBytes(transId); br_off[10] = temp1[1]; br_off[11] = temp[0]; //add payload length temp = BitConverter.GetBytes(0x0005); br_off[12] = temp[1]; br_off[13] = temp[0]; //opcode temp = BitConverter.GetBytes(0x0413); br_off[14] = temp[1]; br_off[15] = temp[0]; //function br_off[16] = (byte)(0x03); //Option temp = BitConverter.GetBytes(0x0000); br_off[17] = temp[1]; br_off[18] = temp[0]; /* //remote address br_off[19] = 0x01; br_off[20] = 0x03; temp = new byte[3]; temp = BitConverter.GetBytes(radioID); br_off[21] = temp[2]; br_off[22] = temp[1]; br_off[23] = temp[0];*/ /* Console.WriteLine("%%%%%%%%%%% SendEmergency %%%%%%%%%%%%%%%%%%%%%%% " + br_off.Length); Console.Write("SendEmergency: "); for (int i = 0; i < br_off.Length; i++) Console.Write(" 0x" + br_off[i].ToString("X")); Console.WriteLine(""); Console.WriteLine("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "); */ return br_off; } //0x0413 – SHUTDWNREQ – Shut Down Request public byte[] SendEmergency(bool isOn) { transID_low++; if (transID_low > 255) transID_low = 0; byte[] temp = new byte[2]; byte[] br_off = new byte[19]; //add message length br_off[0] = 0x00; br_off[1] = 0x11; //add opcode temp = BitConverter.GetBytes((ushort)OPCODE_ENUM.DATA_MSG); br_off[2] = temp[1]; br_off[3] = temp[0]; //add protocol id br_off[4] = protocolId; //add XNL flags br_off[5] = xnlFlag++; //add destination addres (previous message source address) temp = BitConverter.GetBytes(sourceAddr); br_off[6] = temp[1]; br_off[7] = temp[0]; //add source addres () temp = BitConverter.GetBytes(xnlAdress); br_off[8] = temp[1]; br_off[9] = temp[0]; //add transaction ID temp = BitConverter.GetBytes(transID_low); byte[] temp1 = BitConverter.GetBytes(transId); br_off[10] = temp1[1]; br_off[11] = temp[0]; //add payload length temp = BitConverter.GetBytes(0x0005); br_off[12] = temp[1]; br_off[13] = temp[0]; //opcode temp = BitConverter.GetBytes(0x0413); br_off[14] = temp[1]; br_off[15] = temp[0]; //function br_off[16] = (byte)((isOn) ? 1 : 3); //Option br_off[17] = 0x00; br_off[18] = 0x00; /* Console.WriteLine("%%%%%%%%%%% SendEmergency %%%%%%%%%%%%%%%%%%%%%%% " + br_off.Length); Console.Write("SendEmergency: "); for (int i = 0; i < br_off.Length; i++) Console.Write(" 0x" + br_off[i].ToString("X")); Console.WriteLine(""); Console.WriteLine("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "); */ return br_off; } //0x0401 – DISPTXTRQ – Display Text Request public byte[] DisplayText(string txt) { //byte[] b_txt = txt.ge transID_low++; if (transID_low > 255) transID_low = 0; byte[] temp = new byte[2]; byte[] br_off = new byte[27 + txt.Length*2]; //add message length temp = BitConverter.GetBytes(0x19 + txt.Length * 2); br_off[0] = temp[1]; br_off[1] = temp[0]; //add opcode temp = BitConverter.GetBytes((ushort)OPCODE_ENUM.DATA_MSG); br_off[2] = temp[1]; br_off[3] = temp[0]; //add protocol id br_off[4] = protocolId; //add XNL flags br_off[5] = xnlFlag++; //add destination addres (previous message source address) temp = BitConverter.GetBytes(sourceAddr); br_off[6] = temp[1]; br_off[7] = temp[0]; //add source addres () temp = BitConverter.GetBytes(xnlAdress); br_off[8] = temp[1]; br_off[9] = temp[0]; //add transaction ID temp = BitConverter.GetBytes(transID_low); byte[] temp1 = BitConverter.GetBytes(transId); br_off[10] = temp1[1]; br_off[11] = temp[0]; //add payload length temp = BitConverter.GetBytes(13 + txt.Length * 2 ); br_off[12] = temp[1]; br_off[13] = temp[0]; //opcode temp = BitConverter.GetBytes(0x0401); br_off[14] = temp[1]; br_off[15] = temp[0]; //function br_off[16] = 0x00; //Token br_off[17] = 0xff; //region br_off[18] = 0x01; //timed br_off[19] = 0x00; br_off[20] = 0x0a; //class br_off[21] = 0x04; //encode br_off[22] = 0x01; //num bytes temp = BitConverter.GetBytes(txt.Length*2+2); br_off[23] = temp[1]; br_off[24] = temp[0]; //System.Text.ASCIIEncoding.ASCII. System.Text.Encoding enc2 = System.Text.Encoding.ASCII; byte[] buf2 = enc2.GetBytes(txt); //actual bytes for (int i = 0; i < buf2.Length; i++) { br_off[25 + i * 2] = 0x00; br_off[25 + i * 2 + 1] = buf2[i]; } /* //c1 br_off[25] = 0x00; br_off[26] = 0x4c; //c2 br_off[27] = 0x00; br_off[28] = 0x49; */ //end c br_off[25 + txt.Length * 2] = 0x00; br_off[26 + txt.Length * 2] = 0x00; Utils.WriteLine("%%%%%%%%%%% DisplayText %%%%%%%%%%%%%%%%%%%%%%% " + br_off.Length, ConsoleType.XNL); Utils.WriteLine("DisplayText: ", ConsoleType.XNL); for (int i = 0; i < br_off.Length; i++) Utils.Write(" 0x" + br_off[i].ToString("X"), ConsoleType.XNL); Utils.WriteLine("", ConsoleType.XNL); Utils.WriteLine("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ", ConsoleType.XNL); return br_off; } //0x040A – SHUTDWNREQ – Shut Down Request public byte[] RestartRequest() { transID_low++; if (transID_low > 255) transID_low = 0; byte[] temp = new byte[2]; byte[] br_off = new byte[17]; //add message length br_off[0] = 0x00; br_off[1] = 0x0f; //add opcode temp = BitConverter.GetBytes((ushort)OPCODE_ENUM.DATA_MSG); br_off[2] = temp[1]; br_off[3] = temp[0]; //add protocol id br_off[4] = protocolId; //add XNL flags br_off[5] = xnlFlag++; //add destination addres (previous message source address) temp = BitConverter.GetBytes(sourceAddr); br_off[6] = temp[1]; br_off[7] = temp[0]; //add source addres () temp = BitConverter.GetBytes(xnlAdress); br_off[8] = temp[1]; br_off[9] = temp[0]; //add transaction ID temp = BitConverter.GetBytes(transID_low); byte[] temp1 = BitConverter.GetBytes(transId); br_off[10] = temp1[1]; br_off[11] = temp[0]; //add payload length temp = BitConverter.GetBytes(0x0003); br_off[12] = temp[1]; br_off[13] = temp[0]; //opcode temp = BitConverter.GetBytes(0x040A); br_off[14] = temp[1]; br_off[15] = temp[0]; //Operation br_off[16] = 0x02; return br_off; } //0x000F – VERINFO – Version Information Request public byte[] VersionRequest() { transID_low++; if (transID_low > 255) transID_low = 0; byte[] temp = new byte[2]; byte[] br_off = new byte[17]; //add message length br_off[0] = 0x00; br_off[1] = 0x0f; //add opcode temp = BitConverter.GetBytes((ushort)OPCODE_ENUM.DATA_MSG); br_off[2] = temp[1]; br_off[3] = temp[0]; //add protocol id br_off[4] = protocolId; //add XNL flags br_off[5] = xnlFlag++; //add destination addres (previous message source address) temp = BitConverter.GetBytes(sourceAddr); br_off[6] = temp[1]; br_off[7] = temp[0]; //add source addres () temp = BitConverter.GetBytes(xnlAdress); br_off[8] = temp[1]; br_off[9] = temp[0]; //add transaction ID temp = BitConverter.GetBytes(transID_low); byte[] temp1 = BitConverter.GetBytes(transId); br_off[10] = temp1[1]; br_off[11] = temp[0]; //add payload length temp = BitConverter.GetBytes(0x0003); br_off[12] = temp[1]; br_off[13] = temp[0]; //opcode temp = BitConverter.GetBytes(0x000F); br_off[14] = temp[1]; br_off[15] = temp[0]; //Operation br_off[16] = 0x00; return br_off; } //0x000F – VERINFO – Version Information Request public byte[] disableDisplayBcstRequest() { transID_low++; if (transID_low > 255) transID_low = 0; byte[] temp = new byte[2]; byte[] br_off = new byte[27]; /* Length = 25 = 0x0019*/ br_off[0] = (byte)(0x0019 >> 8); br_off[1] = (byte)(0x0019); /* OpCode */ br_off[2] = (byte)(0x00); br_off[3] = (byte)(0x0B); /* ProtocolID and XNLFlags */ br_off[4] = protocolId; /* XNLFlag */ br_off[5] = xnlFlag++; /* Destination Address = MasterAddress */ temp = BitConverter.GetBytes(sourceAddr); br_off[6] = temp[1]; br_off[7] = temp[0]; /* Source Address = TempXNLAddress */ temp = BitConverter.GetBytes(xnlAdress); br_off[8] = temp[1]; br_off[9] = temp[0]; /* TransactionID */ temp = BitConverter.GetBytes(transID_low); byte[] temp1 = BitConverter.GetBytes(transId); br_off[10] = temp1[1]; br_off[11] = temp[0]; /* PayLoad Length = 0x000D*/ br_off[12] = (byte)(0x000D >> 8); br_off[13] = (byte)(0x000D); /* OpCode */ br_off[14] = (byte)(0x00B4); br_off[15] = (byte)(0x0000); /* XCMP Version */ br_off[16] = majXNLVers[3]; br_off[17] = majXNLVers[2]; br_off[18] = majXNLVers[1]; br_off[19] = majXNLVers[0]; /* Device init Type */ br_off[20] = 0x02; // Device Status Update - 0x02 /* ### Start Device Status Info Region ### */ /* Device Type [Size 1 byte] */ br_off[21] = 0x01; /* Device Status [Size 2 byte] */ br_off[22] = 0x00; br_off[23] = 0x00; /* Device Descriptor Size [Size 1 byte] */ br_off[24] = 0x02; // 2 bytes for the pair /* Device Descriptor [Size 0+] */ br_off[25] = 0x02; br_off[26] = 0x00; /* ### End Device Status Info Region ### */ return br_off; } //respond message public byte[] genResponseMessage() { //Console.WriteLine("!!!!!!Generating response!!!"); byte[] temp = new byte[2]; byte[] toReturn; switch (opcode) { //case we got XNL_MASTER_STATUS_BRDCST create DEVICE_AUTH_KEY_REQUEST case (ushort)OPCODE_ENUM.XNL_MASTER_STATUS_BRDCST: //Console.WriteLine("Creating message for DEVICE_AUTH_KEY_REQUEST"); byte[] device_auth_key_request = new byte[14]; //add message length device_auth_key_request[0] = 0x00; device_auth_key_request[1] = 0x0C; //add opcode temp = BitConverter.GetBytes((ushort)OPCODE_ENUM.DEVICE_AUTH_KEY_REQUEST); device_auth_key_request[2] = temp[1]; device_auth_key_request[3] = temp[0]; //add protocol id device_auth_key_request[4] = protocolId; //add XNL flags device_auth_key_request[5] = XNLflags; //add destination addres (previus message source addres) temp = BitConverter.GetBytes(sourceAddr); device_auth_key_request[6] = temp[1]; device_auth_key_request[7] = temp[0]; //add source addres (null) temp = BitConverter.GetBytes(0x0000); device_auth_key_request[8] = temp[0]; device_auth_key_request[9] = temp[1]; //add transaction ID temp = BitConverter.GetBytes(0x0000); device_auth_key_request[10] = temp[0]; device_auth_key_request[11] = temp[1]; //add payload length temp = BitConverter.GetBytes(0x0000); device_auth_key_request[12] = temp[0]; device_auth_key_request[13] = temp[1]; toReturn = device_auth_key_request; break; //case we got DEVICE_AUTH_KEY_REPLY create DEVICE_CONN_REQUEST case (ushort)OPCODE_ENUM.DEVICE_AUTH_KEY_REPLY: byte[] device_conn_request = new byte[26]; //add message length device_conn_request[0] = 0x00; device_conn_request[1] = 0x18; //add opcode temp = BitConverter.GetBytes((ushort)OPCODE_ENUM.DEVICE_CONN_REQUEST); device_conn_request[2] = temp[1]; device_conn_request[3] = temp[0]; //add protocol id device_conn_request[4] = protocolId; //add XNL flags device_conn_request[5] = XNLflags; //add destination addres (previous message source address) temp = BitConverter.GetBytes(sourceAddr); device_conn_request[6] = temp[1]; device_conn_request[7] = temp[0]; //add source addres (null) Utils.WriteLine("source addres:" + xnlAdress, ConsoleType.XNL); temp = BitConverter.GetBytes(xnlAdress); device_conn_request[8] = temp[1]; device_conn_request[9] = temp[0]; //add transaction ID temp = BitConverter.GetBytes(0x0000); device_conn_request[10] = temp[1]; device_conn_request[11] = temp[0]; //add payload length temp = BitConverter.GetBytes(0x000C); device_conn_request[12] = temp[1]; device_conn_request[13] = temp[0]; //add preferred xnl address temp = BitConverter.GetBytes(0x0000); device_conn_request[14] = temp[1]; device_conn_request[15] = temp[0]; //add device type device_conn_request[16] = 0x0A; //add authentification index device_conn_request[17] = 0x01; for (int i = 18; i < 26; i++) { device_conn_request[i] = tempAuthKey[i - 18]; } /* Console.WriteLine("Sent device_conn_request:"); for (int i = 0; i < 26; i++) Console.Write("0x" + device_conn_request[i].ToString("X") + " "); Console.WriteLine(); */ toReturn = device_conn_request; break; //case we got DATA_MSG create DATA_MSG_ACK case (ushort)OPCODE_ENUM.DATA_MSG: byte[] data_msg_ack = new byte[14]; //add message length data_msg_ack[0] = 0x00; data_msg_ack[1] = 0x0C; //add opcode temp = BitConverter.GetBytes((ushort)OPCODE_ENUM.DATA_MSG_ACK); data_msg_ack[2] = temp[1]; data_msg_ack[3] = temp[0]; //add protocol id data_msg_ack[4] = protocolId; //add XNL flags data_msg_ack[5] = XNLflags; //add destination addres (previous message source address) temp = BitConverter.GetBytes(sourceAddr); data_msg_ack[6] = temp[1]; data_msg_ack[7] = temp[0]; //add source addres (null) temp = BitConverter.GetBytes(xnlAdress); data_msg_ack[8] = temp[1]; data_msg_ack[9] = temp[0]; //add transaction ID temp = BitConverter.GetBytes(transID_low); byte[] temp1 = BitConverter.GetBytes(transId); data_msg_ack[10] = temp1[1]; data_msg_ack[11] = temp[0]; //add payload length temp = BitConverter.GetBytes(0x0000); data_msg_ack[12] = temp[1]; data_msg_ack[13] = temp[0]; toReturn = data_msg_ack; /* Console.WriteLine("%%%%%%%%%%% ACK SENT %%%%%%%%%%%%%%%%%%%%%%% " + data_msg_ack.Length); Console.Write("ACK: "); for (int i = 2; i < data_msg_ack.Length; i++) Console.Write(" 0x" + data_msg_ack[i].ToString("X")); Console.WriteLine(""); Console.WriteLine("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "); */ break; case (ushort)OPCODE_ENUM.DATA_MSG_ACK: default: byte[] zero2 = { 0, 0 }; toReturn = zero2; break; }//switch return toReturn; }//responde message //send Nav Request public byte[] sendNavReq() { byte[] temp = new byte[2]; //Console.WriteLine(" "); //Console.WriteLine("--------------BACK BUtton PUI------------------------------------------- "); transID_low++; if (transID_low > 255) transID_low = 0; byte[] br_off = new byte[22]; //add message length br_off[0] = 0x00; br_off[1] = 0x14; //add opcode temp = BitConverter.GetBytes((ushort)OPCODE_ENUM.DATA_MSG); br_off[2] = temp[1]; br_off[3] = temp[0]; //add protocol id br_off[4] = protocolId; //add XNL flags br_off[5] = 0x01; //add destination addres (previous message source address) temp = BitConverter.GetBytes(sourceAddr); br_off[6] = temp[1]; br_off[7] = temp[0]; //add source addres () temp = BitConverter.GetBytes(xnlAdress); br_off[8] = temp[1]; br_off[9] = temp[0]; //add transaction ID temp = BitConverter.GetBytes(transID_low); byte[] temp1 = BitConverter.GetBytes(transId); br_off[10] = temp1[1]; br_off[11] = temp[0]; //add payload length temp = BitConverter.GetBytes(0x0008); br_off[12] = temp[1]; br_off[13] = temp[0]; //opcode temp = BitConverter.GetBytes(0x041F); br_off[14] = temp[1]; br_off[15] = temp[0]; //Function br_off[16] = 0x01; //br_off[16] = 0x80; //Display Mode br_off[17] = 0x00; //br_off[17] = 0x02; //Menu or List ID temp = BitConverter.GetBytes(0x0001); //temp = BitConverter.GetBytes(0x0002); br_off[18] = temp[1]; br_off[19] = temp[0]; //Count temp = BitConverter.GetBytes(0x0002); br_off[20] = temp[1]; br_off[21] = temp[0]; //br_off[20] = 0x00; //br_off[21] = 0xFF; //for (int i = 0; i < 18; i++) ///Console.Write(" 0x" + br_off[i].ToString("X") + " "); //Console.WriteLine(" "); return br_off; } //send Nav Request public byte[] sendNavReqQueryList() { byte[] temp = new byte[2]; //Console.WriteLine(" "); //Console.WriteLine("--------------BACK BUtton PUI------------------------------------------- "); transID_low++; if (transID_low > 255) transID_low = 0; byte[] br_off = new byte[22]; //add message length br_off[0] = 0x00; br_off[1] = 0x14; //add opcode temp = BitConverter.GetBytes((ushort)OPCODE_ENUM.DATA_MSG); br_off[2] = temp[1]; br_off[3] = temp[0]; //add protocol id br_off[4] = protocolId; //add XNL flags br_off[5] = 0x01; //add destination addres (previous message source address) temp = BitConverter.GetBytes(sourceAddr); br_off[6] = temp[1]; br_off[7] = temp[0]; //add source addres () temp = BitConverter.GetBytes(xnlAdress); br_off[8] = temp[1]; br_off[9] = temp[0]; //add transaction ID temp = BitConverter.GetBytes(transID_low); byte[] temp1 = BitConverter.GetBytes(transId); br_off[10] = temp1[1]; br_off[11] = temp[0]; //add payload length temp = BitConverter.GetBytes(0x0008); br_off[12] = temp[1]; br_off[13] = temp[0]; //opcode temp = BitConverter.GetBytes(0x041F); br_off[14] = temp[1]; br_off[15] = temp[0]; //Function //br_off[16] = 0x01; br_off[16] = 0x80; //Display Mode //br_off[17] = 0x00; br_off[17] = 0x00; //Menu or List ID temp = BitConverter.GetBytes(0x0001); //temp = BitConverter.GetBytes(0x0002); br_off[18] = temp[1]; br_off[19] = temp[0]; //Count temp = BitConverter.GetBytes(0x0002); br_off[20] = temp[1]; br_off[21] = temp[0]; //br_off[20] = 0x00; //br_off[21] = 0xFF; //for (int i = 0; i < 18; i++) ///Console.Write(" 0x" + br_off[i].ToString("X") + " "); //Console.WriteLine(" "); return br_off; } #endregion private void printHex(string dir, byte[] data) { int length = 0; length += data[0] << 8; length += data[1]; string hexed = ""; for (int i = 0; i < length + 2; i++) hexed += "0x" + data[i].ToString("x2") + " "; Utils.WriteLine("" + dir + hexed, ConsoleType.XNL); } }// radio message class end }