示例#1
0
文件: Parser.cs 项目: jesumarquez/lt
        public override IMessage Decode(IFrame frame)
        {
            /*
             * Format 0 Default=SORPZAB27GHKLMN*U!
             *
             * S	IMEI
             * O	Operation mode: 1=Sleeping, 2=Periodic, 3=On-line, 4=Motion
             * R	Report type
             * P	Alarm status
             * Z	Geo-fence statu
             * A	1=not fix, 2=2D fix, 3=3D fix
             * B	UTC Date, Time  ddmmyy,hhmmss
             * 2	Longitude  (E or W)dddmm.mmm
             * 7	Latitude  (N or S)ddmm.mmmm
             * G	Altitude  xxxxx.x Unit: meter
             * H	Speed  xxx.xx unit: knots (1.852km/hr)
             * K	Heading  xxx unit: degree
             * L	Number of satellite in use xx
             * M	HDOP  xx.x
             * N	Battery capacity  xx unit: percent capacity
             * U!	Checksum
             *
             * GSr,IMEI,[T,S,]Device_Mode,Report_Type,Alarm_Status,Geofence_status,GPS_Fix,UTC_Date,UTC_Time,Longitude,Latitude,Altitude,Speed,Heading,Number_of_Satellites,HDOP,Battery_capacity*checksum!
             * GSr,011412000845531,2,2,00,,1,020109,022556,+0,+0,135,0.00,0,0,0.0,94#68!
             */

            var buffer = AsString(frame);

            ParserUtils.CheckChecksumOk(buffer, "*", null, ParserUtils.GetCheckSumNmea);
            IMessage result;

            var data = buffer.Split(',');

            switch (data[0])
            {
            case Reporte.DevInfPositionAndStatusReportFormat0:
                result = PositionParse(data).ToPosition(Id, 0).AddStringToSend(Reporte.SrvCmdAck);
                break;

            default:
                result = null;
                if (data[1] != Reporte.DevInfAck)
                {
                    result = new UserMessage(Id, Convert.ToUInt64(data[3]))
                             .AddStringToSend(Reporte.SrvCmdAck);
                }
                break;
            }
            return(result);
        }