Beispiel #1
0
        public void parseRecievedPacket(OnDataRecievedListener listener, byte[] data)
        {
            try
            {
                if (Encoding.Default.GetString(data).Contains("Ready to Send SMS"))
                {
                    listener.onConnectionStarted();
                    return;
                }

                if (Encoding.Default.GetString(data).Contains(AbstractPacket.GSM_Sending_Error_text))
                {
                    listener.onGSMSendingError();
                    return;
                }


                RecievedPacket recPacket = new RecievedPacket(data);
                if (recPacket.AbsPacket != null)
                {
                    switch (recPacket.type)
                    {
                    case AbstractPacket.StructType.Registeration:
                        if (recPacket.AbsPacket.Cmd == AbstractPacket.WRITE_CMD)
                        {
                            listener.onWriteNumberRegister((RegisterationPacket)recPacket.AbsPacket);
                        }
                        else
                        {
                            listener.onReadNumberRegister((RegisterationPacket)recPacket.AbsPacket);
                        }
                        break;

                    case AbstractPacket.StructType.Activation:
                        if (recPacket.AbsPacket.Cmd == AbstractPacket.WRITE_CMD)
                        {
                            listener.onWriteActivate();
                        }
                        else
                        {
                            listener.onReadActivate((ActivationPacket)recPacket.AbsPacket);
                        }
                        break;

                    case AbstractPacket.StructType.Send:
                        listener.onSend();
                        break;

                    case AbstractPacket.StructType.AutoId:
                        listener.onAutoId((RegisterationPacket)recPacket.AbsPacket);
                        break;

                    case AbstractPacket.StructType.Delivery:
                        listener.onDelivery((DeliveryPacket)recPacket.AbsPacket);
                        break;

                    case AbstractPacket.StructType.AutoDelivery:
                        listener.onAutoDelivery((DeliveryPacket)recPacket.AbsPacket);
                        break;

                    case AbstractPacket.StructType.USSDWrite:
                        listener.onUSSDWrite();
                        break;

                    case AbstractPacket.StructType.USSDExecute:
                        listener.onUSSDExecute();
                        break;

                    case AbstractPacket.StructType.USSDRead:
                        listener.onUSSDRead((USSDPacket)recPacket.AbsPacket);
                        break;

                    case AbstractPacket.StructType.SMSText:
                        if (recPacket.AbsPacket.Cmd == AbstractPacket.WRITE_CMD)
                        {
                            listener.onMessageTextWrite();
                        }
                        else
                        {
                            listener.onMessageTextRead((SMSTextPacket)recPacket.AbsPacket);
                        }
                        break;

                    case AbstractPacket.StructType.Inbox:

                        listener.onReadInbox((InboxPacket)recPacket.AbsPacket);
                        break;

                    case AbstractPacket.StructType.AutoInbox:
                        listener.onAutoInbox((InboxPacket)recPacket.AbsPacket);
                        break;
                    }
                }

                return;
            }
            catch (Exception e)
            {
                Console.WriteLine(string.Format("Parse Packet Error => {0}", e.Message));
            }
        }