public static ReonParsedPacket SecondLevelParser(ReceivedPacket receivedPacket)
        {
            try
            {
                if (receivedPacket != null)
                {
                    PacketParser parser = new PacketParser(receivedPacket);

                    //#if DEBUG
                    return(ParsePacket(parser));
                    //#else
                    //                    if (parser != null)
                    //                        (new Thread(() => ParsePacket(parser))).Start();
                    //#endif
                }
            }
            catch (Exception ex)
            {
                LoggingManager.Log(ex);
            }

            return(null);
        }
 public static ReonParsedPacket ParsePacket(PacketParser parser)
 {
     return(parser.Parse());
 }
        private static void ParsePacket(string packet)
        {
            try
            {
                //DeviceParser parser = null;
                PacketParser parser     = null;
                int          index      = 0;
                string       terminalId = string.Empty;
                string       pkt        = string.Empty;

                index = packet.IndexOf('<');
                if (index != -1)
                {
                    terminalId = packet.Substring(0, index);
                    pkt        = packet.Substring(index, packet.Length - index).TrimStart('<').TrimEnd('>');

                    string protocolHeader = string.Empty;
                    string data           = string.Empty;
                    index = pkt.IndexOf('(');
                    if (index != -1)
                    {
                        protocolHeader = pkt.Substring(0, index);
                        if (protocolHeader.StartsWith("M") || protocolHeader.StartsWith("3P"))
                        {
                            StringBuilder sb        = new StringBuilder();
                            byte[]        dataBytes = Encoding.Default.GetBytes(pkt.Substring(index, pkt.Length - index).TrimStart('(').TrimEnd(')'));

                            foreach (byte b in dataBytes)
                            {
                                int value = b;
                                sb.Append(value.ToString());
                                sb.Append(",");
                            }

                            data = sb.ToString().TrimEnd(',');

                            parser = new PacketParser(new ReceivedPacket()
                            {
                                Data           = data,
                                ProtocolHeader = protocolHeader,
                                TerminalId     = terminalId
                            });
                        }
                        else
                        {
                            data = pkt.Substring(index, pkt.Length - index).Replace('(', ',').Replace(')', ',').TrimStart(',').TrimEnd(',');

                            parser = new PacketParser(new ReceivedPacket()
                            {
                                Data           = data,
                                ProtocolHeader = protocolHeader,
                                TerminalId     = terminalId
                            });
                        }

                        if (parser != null)
                        {
                            new Thread(() => ParsePacket(parser)).Start();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LoggingManager.Log(ex);
            }
        }