Beispiel #1
0
 public static void EncodeHeaders(ref byte[] buffer, ref int pos, PDU pdu)
 {
     EncodeShort(ref buffer, ref pos, pdu.DeviceId);
     EncodeByte(ref buffer, ref pos, pdu.Seq);
     EncodeByte(ref buffer, ref pos, pdu.CH);
     EncodeByte(ref buffer, ref pos, pdu.CL);
 }
Beispiel #2
0
        public LoginAcepted(byte[] buffer, int pos)
        {
            PDU this_pdu = this;

            Decoder.DecodeHeaders(buffer, ref this_pdu, ref pos);
            idAsignado = Decoder.DecodeShort(buffer, ref pos);
        }
Beispiel #3
0
 public static void DecodeHeaders(byte[] buffer, ref PDU pdu, ref int pos)
 {
     pdu.Incomming = true;
     pdu.DeviceId  = DecodeShort(buffer, ref pos);
     pdu.Seq       = DecodeByte(buffer, ref pos);
     pdu.CH        = DecodeByte(buffer, ref pos);
     pdu.CL        = DecodeByte(buffer, ref pos);
 }
Beispiel #4
0
        public LoginRequest(byte[] buffer, int pos)
        {
            PDU this_pdu = this;

            Decoder.DecodeHeaders(buffer, ref this_pdu, ref pos);
            iMEI         = Decoder.DecodeString(buffer, ref pos);
            password     = Decoder.DecodeString(buffer, ref pos);
            firmware     = Decoder.DecodeString(buffer, ref pos);
            tableVersion = Decoder.DecodeShort(buffer, ref pos);
        }
Beispiel #5
0
        public static PDU Decode(byte[] buffer, ref DecodeErrors outcode)
        {
            /*int chkpos = buffer.GetLength(0) - 2;
             * short chk = DecodeShort(buffer, ref chkpos);
             * if (Checksum8(buffer, buffer.GetLength(0) - 2) != chk)
             * {   // CRC ERROR
             *  crc_errors++;
             *  outcode = DecodeErrors.ChecksumError; // crcerror
             *  return null;
             * }*/
            int   pos     = 0;
            short pdusize = DecodeShort(buffer, ref pos);

            if (pdusize != buffer.GetLength(0) - 2)
            {
                badlength_error++;
                outcode = DecodeErrors.BadLength;
                return(null);
            }
            byte options = DecodeByte(buffer, ref pos);

            if (options > 0x01)
            {
                badoptions_error++;
                outcode = DecodeErrors.BadOptions;
                return(null);
            }
            PDU headers = new PDU();

            DecodeHeaders(buffer, ref headers, ref pos);
            pos = 3;
            switch ((ComandoH)headers.CH)
            {
            case ComandoH.LoginRequest:
                return(new LoginRequest(buffer, pos));

            case ComandoH.LoginAcepted:
                return(new LoginAcepted(buffer, pos));

            case ComandoH.LoginReject:
                return(new LoginReject(buffer, pos));

            case ComandoH.MsgPosicion:
                return(new Posicion(buffer, pos));

            case ComandoH.MsgEvento:
                return(DecodeEventos(headers, buffer, pos));

            default:
                return(headers);
            }
        }
Beispiel #6
0
        public Posicion(byte[] buffer, int pos)
        {
            PDU this_pdu = this;

            Decoder.DecodeHeaders(buffer, ref this_pdu, ref pos);
            byte items = Decoder.DecodeByte(buffer, ref pos);

            puntos.Clear();
            while (items-- > 0)
            {
                puntos.Add(DecodeGPSPoint(buffer, ref pos));
            }
        }
Beispiel #7
0
        public static void Encode(ref byte[] buffer, ref int size, PDU pdu)
        {
            int start   = 0;
            int payload = 3; // salteo

            EncodeHeaders(ref buffer, ref payload, pdu);
            pdu.FinalEncode(ref buffer, ref payload);
            short pdu_size = Convert.ToInt16(payload & 0xFFFF);

            // PDU Size.
            EncodeShort(ref buffer, ref start, pdu_size);
            // Options = 0x00
            EncodeByte(ref buffer, ref start, pdu.Options);
            short sum = Checksum8(buffer, pdu_size);

            EncodeShort(ref buffer, ref payload, sum);
            size = pdu_size + 2; // del sum
        }
Beispiel #8
0
 internal static PDU DecodeEventos(PDU headers, byte[] buffer, int pos)
 {
     return(null);
 }
Beispiel #9
0
        public LoginReject(byte[] buffer, int pos)
        {
            PDU this_pdu = this;

            Decoder.DecodeHeaders(buffer, ref this_pdu, ref pos);
        }