public static MeiligaoPacket GetMeiligaoPacket(byte[] bytes)
        {
            UInt16 validChecksum;
            if (!IsChecksumValid(bytes, out validChecksum)) return null;

            var packet = new MeiligaoPacket();
            //1.Header
            packet.Header = Encoding.ASCII.GetString(bytes, 0, 2);

            //2.Length of the packet
            packet.Length = getLengthFromBytes(bytes);

            //3.ID
            packet.ID = getIDFromBytes(bytes);

            //4.Command
            packet.Command = getCommandFromPacketBytes(bytes);


            var dataCount = bytes.Length - 13 - 2 - 2;
            if (dataCount == 1)
            {
                //Flag
                packet.Flag = getCommandFlagFromBytes(bytes);
            }
            else
            {
                //Data
                packet.GpsData = getGPSData(bytes);
            }


            packet.CheckSum = validChecksum;
            return packet;
        }
        public void TestGetMeiligaoPacket()
        {
            var trackOnDemandresponsePacket = new MeiligaoPacket();
            trackOnDemandresponsePacket.Header = "$$";
            trackOnDemandresponsePacket.ID = "123456";
            trackOnDemandresponsePacket.Length = 96;
            trackOnDemandresponsePacket.GpsData = new GPSData() { Altitude = 0.0, HDOP = "11.5", GPRMC = new GPRMC("035644.000,A,2232.6083,N,11404.8137,E,0.00,,010809,,*1C") };
            trackOnDemandresponsePacket.Command = CommandTypes.TrackOnDemandResponse;
            var trackOnDemandresponseBytes = new byte[]
                                        {
                                            0x24, 0x24, 0x00, 0x60, 0x12, 0x34, 0x56, 0xFF, 0xFF, 0xFF, 0xFF, 0x99, 0x55
                                            , 0x30, 0x33, 0x35, 0x36, 0x34, 0x34, 0x2E, 0x30
                                            , 0x30, 0x30, 0x2C, 0x41, 0x2C, 0x32, 0x32, 0x33, 0x32, 0x2E, 0x36, 0x30,
                                            0x38, 0x33, 0x2C, 0x4E, 0x2C, 0x31, 0x31, 0x34, 0x30, 0x34
                                            , 0x2E, 0x38, 0x31, 0x33, 0x37, 0x2C, 0x45, 0x2C, 0x30, 0x2E, 0x30, 0x30,
                                            0x2C, 0x2C, 0x30, 0x31, 0x30, 0x38, 0x30, 0x39, 0x2C, 0x2C, 0x2A, 0x31
                                            , 0x43, 0x7C, 0x31, 0x31, 0x2E, 0x35, 0x7C, 0x31, 0x39, 0x34, 0x7C, 0x30,
                                            0x30, 0x30, 0x30, 0x7C, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x30, 0x30, 0x30
                                            , 0x30, 0x69, 0x62, 0x0D, 0x0A
                                        };

            var testPacket1 = MeiligaoProcessor.GetMeiligaoPacket(trackOnDemandresponseBytes);

            Assert.AreEqual(testPacket1.Header, trackOnDemandresponsePacket.Header,"Header convension test failed");
            Assert.AreEqual(testPacket1.Length, trackOnDemandresponsePacket.Length,"Length convension test failed");
            Assert.AreEqual(testPacket1.Command, trackOnDemandresponsePacket.Command,"Command convension test failed");
            Assert.AreEqual(testPacket1.GpsData.Altitude, trackOnDemandresponsePacket.GpsData.Altitude, "Command convension test failed");
            Assert.AreEqual(testPacket1.GpsData.HDOP, trackOnDemandresponsePacket.GpsData.HDOP, "HDOP convension test failed");
            Assert.AreEqual(testPacket1.GpsData.GPRMC.GPRMCSentenceString, trackOnDemandresponsePacket.GpsData.GPRMC.GPRMCSentenceString, "GPRMC convension test failed");

            Assert.AreEqual(testPacket1.GpsData.GPRMC.CheckSum, trackOnDemandresponsePacket.GpsData.GPRMC.CheckSum, "GPRMC-CheckSum convension test failed");
            Assert.AreEqual(testPacket1.GpsData.GPRMC.D, trackOnDemandresponsePacket.GpsData.GPRMC.D, "GPRMC-D convension test failed");
            Assert.AreEqual(testPacket1.GpsData.GPRMC.DateTimeUTC, trackOnDemandresponsePacket.GpsData.GPRMC.DateTimeUTC, "GPRMC-DateTimeUTC convension test failed");
            Assert.AreEqual(testPacket1.GpsData.GPRMC.Direction, trackOnDemandresponsePacket.GpsData.GPRMC.Direction, "GPRMC-Direction convension test failed");
            Assert.AreEqual(testPacket1.GpsData.GPRMC.Latitude, trackOnDemandresponsePacket.GpsData.GPRMC.Latitude, "GPRMC-Latitude convension test failed");
            Assert.AreEqual(testPacket1.GpsData.GPRMC.Longitude, trackOnDemandresponsePacket.GpsData.GPRMC.Longitude, "GPRMC-Longitude convension test failed");
            Assert.AreEqual(testPacket1.GpsData.GPRMC.Speed, trackOnDemandresponsePacket.GpsData.GPRMC.Speed, "GPRMC-Speed convension test failed");
            Assert.AreEqual(testPacket1.GpsData.GPRMC.Status, trackOnDemandresponsePacket.GpsData.GPRMC.Status, "GPRMC-Status convension test failed");
        }
        public static byte[] GetBytes(MeiligaoPacket Packet)
        {
            var bytesList = new List<byte>();
            //1.header
            var headerBytes = Encoding.ASCII.GetBytes(Packet.Header);
            bytesList.AddRange(headerBytes);

            //2.Length
            var intBytes = BitConverter.GetBytes(Packet.Length);
            if (BitConverter.IsLittleEndian)
                Array.Reverse(intBytes);
            bytesList.AddRange(intBytes);

            //3.ID
            var id = getIDBytes(Packet.ID);
            bytesList.AddRange(id);

            //4.Command
            var commandByte = BitConverter.GetBytes((ushort) Packet.Command);
            if (BitConverter.IsLittleEndian)
                Array.Reverse(commandByte);
            bytesList.AddRange(commandByte);

            //5.Parameter/Data?


            //6.Checksum
            var checksumBytes = getCheckSumforBytes(bytesList);
            bytesList.AddRange(checksumBytes);


            //Ending
            bytesList.AddRange(new byte[] {0x0d, 0x0a});

            return bytesList.ToArray();
        }
 public static byte[] GetBytes(MeiligaoPacket Packet)
 {
     throw new NotImplementedException();
 }