bool ParseAndProcessReceivedPacket(byte[] receivedMsg, int receivedMsgLen) { try { IReceivedMessage processor = _recvFactoryManager.CreateProcessor(receivedMsg, receivedMsgLen); if (processor == null) { return(false); } if (processor.Execute(receivedMsg, receivedMsgLen)) { switch (processor.RequestType) { case (ushort)HcomHostRequestType.HCOM_HOST_REQUEST_UNDEFINED_REQUEST: ConsoleOut("Request Undefined"); // TESTING break; // This set are responses to request issued by this application case (ushort)HcomHostRequestType.HCOM_HOST_REQUEST_TEXT_REJECTED: ConsoleOut("Request Rejected"); // TESTING if (!string.IsNullOrEmpty(processor.ToString())) { OnReceiveData?.Invoke(this, new MeadowMessageEventArgs(MeadowMessageType.Data, processor.ToString())); } break; case (ushort)HcomHostRequestType.HCOM_HOST_REQUEST_TEXT_ACCEPTED: //ConsoleOut($"protocol-Request Accepted"); // TESTING OnReceiveData?.Invoke(this, new MeadowMessageEventArgs(MeadowMessageType.Accepted)); break; case (ushort)HcomHostRequestType.HCOM_HOST_REQUEST_TEXT_CONCLUDED: //ConsoleOut($"protocol-Request Concluded"); // TESTING OnReceiveData?.Invoke(this, new MeadowMessageEventArgs(MeadowMessageType.Concluded)); break; case (ushort)HcomHostRequestType.HCOM_HOST_REQUEST_TEXT_ERROR: ConsoleOut("Request Error"); // TESTING if (!string.IsNullOrEmpty(processor.ToString())) { OnReceiveData?.Invoke(this, new MeadowMessageEventArgs(MeadowMessageType.Data, processor.ToString())); } break; case (ushort)HcomHostRequestType.HCOM_HOST_REQUEST_TEXT_INFORMATION: //ConsoleOut("protocol-Request Information"); // TESTING if (!string.IsNullOrEmpty(processor.ToString())) { OnReceiveData?.Invoke(this, new MeadowMessageEventArgs(MeadowMessageType.Data, processor.ToString())); } break; case (ushort)HcomHostRequestType.HCOM_HOST_REQUEST_TEXT_LIST_HEADER: //ConsoleOut("protocol-Request File List Header received"); // TESTING OnReceiveData?.Invoke(this, new MeadowMessageEventArgs(MeadowMessageType.FileListTitle, processor.ToString())); break; case (ushort)HcomHostRequestType.HCOM_HOST_REQUEST_TEXT_LIST_MEMBER: OnReceiveData?.Invoke(this, new MeadowMessageEventArgs(MeadowMessageType.FileListMember, processor.ToString())); break; case (ushort)HcomHostRequestType.HCOM_HOST_REQUEST_TEXT_CRC_MEMBER: OnReceiveData?.Invoke(this, new MeadowMessageEventArgs(MeadowMessageType.FileListCrcMember, processor.ToString())); break; case (ushort)HcomHostRequestType.HCOM_HOST_REQUEST_TEXT_MONO_STDOUT: OnReceiveData?.Invoke(this, new MeadowMessageEventArgs(MeadowMessageType.AppOutput, processor.ToString())); break; case (ushort)HcomHostRequestType.HCOM_HOST_REQUEST_TEXT_MONO_STDERR: OnReceiveData?.Invoke(this, new MeadowMessageEventArgs(MeadowMessageType.ErrOutput, processor.ToString())); break; case (ushort)HcomHostRequestType.HCOM_HOST_REQUEST_TEXT_DEVICE_INFO: OnReceiveData?.Invoke(this, new MeadowMessageEventArgs(MeadowMessageType.DeviceInfo, processor.ToString())); break; case (ushort)HcomHostRequestType.HCOM_HOST_REQUEST_TEXT_TRACE_MSG: if (!string.IsNullOrEmpty(processor.ToString())) { OnReceiveData?.Invoke(this, new MeadowMessageEventArgs(MeadowMessageType.MeadowTrace, processor.ToString())); } break; case (ushort)HcomHostRequestType.HCOM_HOST_REQUEST_TEXT_RECONNECT: ConsoleOut($"Host Serial Reconnect"); // TESTING OnReceiveData?.Invoke(this, new MeadowMessageEventArgs(MeadowMessageType.SerialReconnect, null)); break; // Debug message from Meadow for Visual Studio case (ushort)HcomHostRequestType.HCOM_HOST_REQUEST_MONO_DEBUGGER_MSG: ConsoleOut($"Debugging message from Meadow for Visual Studio"); // TESTING MeadowDeviceManager.ForwardMonoDataToVisualStudio(processor.MessageData); break; } return(true); } else { return(false); } } catch (Exception ex) { ConsoleOut($"Exception: {ex}"); return(false); } }