protected virtual void OnResponseRunGet(CommandInterfaceResponseRunGetEventArgs e) { var handler = ResponseRunGet; if (handler != null) { handler(this, e); } }
private void ParseMessage(byte[] Message) { int offset, strLen; if (Message == null) { return; } if (Message.Count() == 0) { return; } //Log.WriteLog(Log.LogLevelType.Comm, "CommandInterface::ParseMessage(): " + // "[" + m_Connection.Address + ":" + m_Connection.Port + "] " + // "Found Message of " + Message.Length.ToString() + " bytes"); // Log.HexDump(Log.LogLevelType.Comm, Message); offset = 0; while (offset < Message.Length) { CommandCodes Command = (CommandCodes)Message[0]; offset++; //skip past Command if (offset == Message.Length) { break; } switch (Command) { case CommandCodes.COMMAND_FAILURE: var ResponseErrorArgs = new CommandInterfaceResponseErrorEventArgs(); strLen = BitConverter.ToInt16(Message, offset); offset += sizeof(Int16); ResponseErrorArgs.ErrorText = System.Text.Encoding.ASCII.GetString(Message, offset, strLen); offset += strLen; //Log.WriteLog(Log.LogLevelType.Error, "CommandInterface::ParseMessage(): " + // "[" + m_Connection.Address + ":" + m_Connection.Port + "] " + // "COMMAND_FAILURE: " + ResponseErrorArgs.ErrorText); OnResponseError(ResponseErrorArgs); break; case CommandCodes.GET_ID: case CommandCodes.V2_GET_ID: var ResponseGetIDArgs = new CommandInterfaceResponseGetIDEventArgs(); strLen = BitConverter.ToInt16(Message, offset); offset += sizeof(Int16); ResponseGetIDArgs.Name = System.Text.Encoding.ASCII.GetString(Message, offset, strLen); offset += strLen; ResponseGetIDArgs.ID = BitConverter.ToInt16(Message, offset); offset += sizeof(Int16); ResponseGetIDArgs.Format = BitConverter.ToInt16(Message, offset); offset += sizeof(Int16); ResponseGetIDArgs.Use = 0; ResponseGetIDArgs.ParamCount = 0; if (Command == CommandCodes.V2_GET_ID) { ResponseGetIDArgs.Use = BitConverter.ToInt16(Message, offset); offset += sizeof(Int16); ResponseGetIDArgs.ParamCount = BitConverter.ToInt16(Message, offset); offset += sizeof(Int16); } //Log.WriteLog(Log.LogLevelType.Comm, "CommandInterface::ParseMessage(): " + // "[" + m_Connection.Address + ":" + m_Connection.Port + "] " + // "GET_ID: " + ResponseGetIDArgs.Name + // " = " + ResponseGetIDArgs.ID + " (0x" + ResponseGetIDArgs.ID.ToString("X2") + ")" + // " Format: " + ResponseGetIDArgs.Format + // " Use: " + ResponseGetIDArgs.Use + // " ParamCount: " + ResponseGetIDArgs.ParamCount); OnResponseGetID(ResponseGetIDArgs); break; case CommandCodes.RUN_GET: case CommandCodes.V2_RUN_GET: var ResponseRunGetArgs = new CommandInterfaceResponseRunGetEventArgs(); ResponseRunGetArgs.TransactionID = 0; if (Command == CommandCodes.V2_RUN_GET) { ResponseRunGetArgs.TransactionID = BitConverter.ToInt16(Message, offset); offset += sizeof(Int16); } ResponseRunGetArgs.ID = BitConverter.ToInt16(Message, offset); offset += sizeof(Int16); ResponseRunGetArgs.Param = BitConverter.ToInt16(Message, offset); offset += sizeof(Int16); ResponseRunGetArgs.Length = BitConverter.ToInt16(Message, offset); offset += sizeof(Int16); ResponseRunGetArgs.Value = Message.Skip(offset).Take(ResponseRunGetArgs.Length).ToArray(); offset += ResponseRunGetArgs.Length; //Log.WriteLog(Log.LogLevelType.Comm, "CommandInterface::ParseMessage(): " + // "[" + m_Connection.Address + ":" + m_Connection.Port + "] " + // "RUN_GET: ID: " + ResponseRunGetArgs.ID + " (0x" + ResponseRunGetArgs.ID.ToString("X2") + ")" + // " Param: " + ResponseRunGetArgs.Param + // " Length: " + ResponseRunGetArgs.Length + // " Transaction: " + ResponseRunGetArgs.TransactionID); OnResponseRunGet(ResponseRunGetArgs); break; case CommandCodes.RUN_SET: case CommandCodes.V2_RUN_SET: var ResponseRunSetArgs = new CommandInterfaceResponseRunSetEventArgs(); ResponseRunSetArgs.TransactionID = 0; if (Command == CommandCodes.V2_RUN_SET) { ResponseRunSetArgs.TransactionID = BitConverter.ToInt16(Message, offset); offset += sizeof(Int16); } ResponseRunSetArgs.ID = BitConverter.ToInt16(Message, offset); offset += sizeof(Int16); ResponseRunSetArgs.Param = BitConverter.ToInt16(Message, offset); offset += sizeof(Int16); ResponseRunSetArgs.Length = BitConverter.ToInt16(Message, offset); offset += sizeof(Int16); //Log.WriteLog(Log.LogLevelType.Comm, "CommandInterface::ParseMessage(): " + // "[" + m_Connection.Address + ":" + m_Connection.Port + "] " + // "RUN_SET: ID: " + ResponseRunSetArgs.ID + " (0x" + ResponseRunSetArgs.ID.ToString("X2") + ")" + // " Param: " + ResponseRunSetArgs.Param + // " Length: " + ResponseRunSetArgs.Length + // " Transaction: " + ResponseRunSetArgs.TransactionID); OnResponseRunSet(ResponseRunSetArgs); break; default: var InvalidCommandErrorArgs = new CommandInterfaceResponseErrorEventArgs(); InvalidCommandErrorArgs.ErrorText = "Unimplemented Command: " + Command.ToString("X2"); //Log.WriteLog(Log.LogLevelType.Error, "CommandInterface::ParseMessage(): " + // "[" + m_Connection.Address + ":" + m_Connection.Port + "] " + // "INVALID_COMMAND: " + InvalidCommandErrorArgs.ErrorText); OnResponseError(InvalidCommandErrorArgs); break; } } }