Пример #1
0
        public void dataPlayerKinematicMessageParseFromByteArray()
        {
            KinematicMessage kinematicMessagetoParse   = new KinematicMessage();
            KinematicMessage kinematicMessagetoCompare = new KinematicMessage();

            KinematicMessage KinematicMessageFieldsSize = new KinematicMessage();

            MessageInitializers.KinematicMessageFieldSizeInitializer(out KinematicMessageFieldsSize);

            KinematicMessage KinematicMessageFieldsIndex = new KinematicMessage();

            MessageInitializers.KinematicMessageFieldIndexInitializer(out KinematicMessageFieldsIndex);

            Byte[] statusbyteArray = Encoding.UTF8.GetBytes("04500826003f00175135323536363302000000000023049d030000ff4800007600b703f469800900cd0100f6ff02005605710000000000000000000000000000000000000000000000");

            MessageParser.KinematicMessageParserFromByteArray(out kinematicMessagetoParse, KinematicMessageFieldsIndex, KinematicMessageFieldsSize, statusbyteArray);

            kinematicMessagetoCompare.OpCode         = 4;
            kinematicMessagetoCompare.MessageCounter = 2128;
            kinematicMessagetoCompare.IDPart1        = 4128806;
            kinematicMessagetoCompare.IDPart2        = 842354967;
            kinematicMessagetoCompare.IDPart3        = 859190837;
            kinematicMessagetoCompare.TimeSource     = 2;
            kinematicMessagetoCompare.GPSYear        = 0;
            kinematicMessagetoCompare.GPSMonth       = 0;
            kinematicMessagetoCompare.GPSDay         = 0;
            kinematicMessagetoCompare.GPSHour        = 0;
            kinematicMessagetoCompare.GPSMinute      = 35;
            kinematicMessagetoCompare.GPSSecond      = 4;
            kinematicMessagetoCompare.GPSMiliSec     = 925;
            kinematicMessagetoCompare.BaroHeight     = 0;
            kinematicMessagetoCompare.Pressure       = 18687;
            kinematicMessagetoCompare.AccX           = 0;
            kinematicMessagetoCompare.AccY           = 118;
            kinematicMessagetoCompare.AccZ           = 951;
            kinematicMessagetoCompare.MagX           = 27124;
            kinematicMessagetoCompare.MagY           = 2432;
            kinematicMessagetoCompare.MagZ           = -13056;
            kinematicMessagetoCompare.GyroX          = 1;
            kinematicMessagetoCompare.GyroY          = -10;
            kinematicMessagetoCompare.GyroZ          = 2;
            kinematicMessagetoCompare.Heading        = 1366;
            kinematicMessagetoCompare.Roll           = 113;
            kinematicMessagetoCompare.Pitch          = 0;
            kinematicMessagetoCompare.OrientationX   = 0;
            kinematicMessagetoCompare.OrientationY   = 0;
            kinematicMessagetoCompare.OrientationZ   = 0;
            kinematicMessagetoCompare.OrientationW   = 0;
            kinematicMessagetoCompare.LinearAccX     = 0;
            kinematicMessagetoCompare.LinearAccY     = 0;
            kinematicMessagetoCompare.LinearAccZ     = 0;
            kinematicMessagetoCompare.GravX          = 0;
            kinematicMessagetoCompare.GravY          = 0;
            kinematicMessagetoCompare.GravZ          = 0;

            Assert.AreEqual(kinematicMessagetoCompare, kinematicMessagetoParse);
        }
Пример #2
0
        public void KinematicMessageEncodingTests()
        {
            KinematicMessage testKinematicMessageSize  = new KinematicMessage();
            KinematicMessage testKinematicMessageIndex = new KinematicMessage();

            MessageInitializers.KinematicMessageFieldSizeInitializer(out testKinematicMessageSize);
            MessageInitializers.KinematicMessageFieldIndexInitializer(out testKinematicMessageIndex);

            List <Byte> messageValuesList = new List <Byte>();

            messageValuesList = ManualSerializer.EncodeValuesAsBytesInList(testKinematicMessageSize.OpCode, 4, messageValuesList);
            messageValuesList = ManualSerializer.EncodeValuesAsBytesInList(testKinematicMessageSize.MessageCounter, 0, messageValuesList);
            messageValuesList = ManualSerializer.EncodeValuesAsBytesInList((int)testKinematicMessageSize.IDPart1, 600, messageValuesList);
            messageValuesList = ManualSerializer.EncodeValuesAsBytesInList((int)testKinematicMessageSize.IDPart2, 700, messageValuesList);
            messageValuesList = ManualSerializer.EncodeValuesAsBytesInList((int)testKinematicMessageSize.IDPart3, 800, messageValuesList);
            messageValuesList = ManualSerializer.EncodeValuesAsBytesInList(testKinematicMessageSize.TimeSource, 2, messageValuesList);
            messageValuesList = ManualSerializer.EncodeValuesAsBytesInList(testKinematicMessageSize.GPSYear, 0, messageValuesList);
            messageValuesList = ManualSerializer.EncodeValuesAsBytesInList(testKinematicMessageSize.GPSMonth, 0, messageValuesList);
            messageValuesList = ManualSerializer.EncodeValuesAsBytesInList(testKinematicMessageSize.GPSDay, 0, messageValuesList);
            messageValuesList = ManualSerializer.EncodeValuesAsBytesInList(testKinematicMessageSize.GPSHour, 0, messageValuesList);
            messageValuesList = ManualSerializer.EncodeValuesAsBytesInList(testKinematicMessageSize.GPSMinute, 0, messageValuesList);
            messageValuesList = ManualSerializer.EncodeValuesAsBytesInList(testKinematicMessageSize.GPSSecond, 0, messageValuesList);
            messageValuesList = ManualSerializer.EncodeValuesAsBytesInList(testKinematicMessageSize.GPSMiliSec, 0, messageValuesList);
            messageValuesList = ManualSerializer.EncodeValuesAsBytesInList(testKinematicMessageSize.BaroHeight, 17, messageValuesList);
            messageValuesList = ManualSerializer.EncodeValuesAsBytesInList(testKinematicMessageSize.Pressure, 3200, messageValuesList);
            messageValuesList = ManualSerializer.EncodeValuesAsBytesInList(testKinematicMessageSize.AccX, 3500, messageValuesList);
            messageValuesList = ManualSerializer.EncodeValuesAsBytesInList(testKinematicMessageSize.AccY, 3000, messageValuesList);
            messageValuesList = ManualSerializer.EncodeValuesAsBytesInList(testKinematicMessageSize.AccZ, 3, messageValuesList);
            messageValuesList = ManualSerializer.EncodeValuesAsBytesInList(testKinematicMessageSize.MagX, 5, messageValuesList);
            messageValuesList = ManualSerializer.EncodeValuesAsBytesInList(testKinematicMessageSize.MagY, 15, messageValuesList);
            messageValuesList = ManualSerializer.EncodeValuesAsBytesInList(testKinematicMessageSize.MagZ, 32, messageValuesList);
            messageValuesList = ManualSerializer.EncodeValuesAsBytesInList(testKinematicMessageSize.GyroX, 3000, messageValuesList);
            messageValuesList = ManualSerializer.EncodeValuesAsBytesInList(testKinematicMessageSize.GyroY, 0, messageValuesList);
            messageValuesList = ManualSerializer.EncodeValuesAsBytesInList(testKinematicMessageSize.GyroZ, 0, messageValuesList);
            messageValuesList = ManualSerializer.EncodeValuesAsBytesInList(testKinematicMessageSize.Heading, 10, messageValuesList);
            messageValuesList = ManualSerializer.EncodeValuesAsBytesInList(testKinematicMessageSize.Roll, 20, messageValuesList);
            messageValuesList = ManualSerializer.EncodeValuesAsBytesInList(testKinematicMessageSize.Pitch, 40, messageValuesList);
            messageValuesList = ManualSerializer.EncodeValuesAsBytesInList(testKinematicMessageSize.OrientationX, 0, messageValuesList);
            messageValuesList = ManualSerializer.EncodeValuesAsBytesInList(testKinematicMessageSize.OrientationY, 0, messageValuesList);
            messageValuesList = ManualSerializer.EncodeValuesAsBytesInList(testKinematicMessageSize.OrientationZ, 0, messageValuesList);
            messageValuesList = ManualSerializer.EncodeValuesAsBytesInList(testKinematicMessageSize.OrientationW, 0, messageValuesList);
            messageValuesList = ManualSerializer.EncodeValuesAsBytesInList(testKinematicMessageSize.LinearAccX, 0, messageValuesList);
            messageValuesList = ManualSerializer.EncodeValuesAsBytesInList(testKinematicMessageSize.LinearAccY, 0, messageValuesList);
            messageValuesList = ManualSerializer.EncodeValuesAsBytesInList(testKinematicMessageSize.LinearAccZ, 0, messageValuesList);
            messageValuesList = ManualSerializer.EncodeValuesAsBytesInList(testKinematicMessageSize.GravX, 0, messageValuesList);
            messageValuesList = ManualSerializer.EncodeValuesAsBytesInList(testKinematicMessageSize.GravY, 0, messageValuesList);
            messageValuesList = ManualSerializer.EncodeValuesAsBytesInList(testKinematicMessageSize.GravZ, 0, messageValuesList);
            //Convert list to Array
            Byte[] messageinValues = messageValuesList.ToArray();
            Byte[] ExpectedArray   = { 4, 0, 0, 88, 2, 0, 0, 188, 2, 0, 0, 32, 3, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 0, 128, 12, 172, 13, 184, 11, 3, 0, 5, 0, 15, 0, 32, 0, 184, 11, 0, 0, 0, 0, 10, 0, 20, 0, 40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
            Assert.AreEqual(Convert.ToBase64String(ExpectedArray), Convert.ToBase64String(messageinValues));
        }
Пример #3
0
        public void KinematiclMessageSizeVsIndex()
        {
            KinematicMessage testKinematicMessageSize = new KinematicMessage();

            MessageInitializers.KinematicMessageFieldSizeInitializer(out testKinematicMessageSize);

            KinematicMessage testKinematicMessageIndex = new KinematicMessage();

            MessageInitializers.KinematicMessageFieldIndexInitializer(out testKinematicMessageIndex);

            int kinematicMessageSize = (int)(testKinematicMessageSize.OpCode + testKinematicMessageSize.MessageCounter
                                             + testKinematicMessageSize.IDPart1
                                             + testKinematicMessageSize.IDPart2
                                             + testKinematicMessageSize.IDPart3
                                             + testKinematicMessageSize.TimeSource
                                             + testKinematicMessageSize.GPSYear
                                             + testKinematicMessageSize.GPSMonth
                                             + testKinematicMessageSize.GPSDay
                                             + testKinematicMessageSize.GPSHour
                                             + testKinematicMessageSize.GPSMinute
                                             + testKinematicMessageSize.GPSSecond
                                             + testKinematicMessageSize.GPSMiliSec
                                             + testKinematicMessageSize.BaroHeight
                                             + testKinematicMessageSize.Pressure
                                             + testKinematicMessageSize.AccX
                                             + testKinematicMessageSize.AccY
                                             + testKinematicMessageSize.AccZ
                                             + testKinematicMessageSize.MagX
                                             + testKinematicMessageSize.MagY
                                             + testKinematicMessageSize.MagZ
                                             + testKinematicMessageSize.GyroX
                                             + testKinematicMessageSize.GyroY
                                             + testKinematicMessageSize.GyroZ
                                             + testKinematicMessageSize.Heading
                                             + testKinematicMessageSize.Roll
                                             + testKinematicMessageSize.Pitch
                                             + testKinematicMessageSize.OrientationX
                                             + testKinematicMessageSize.OrientationY
                                             + testKinematicMessageSize.OrientationZ
                                             + testKinematicMessageSize.OrientationW
                                             + testKinematicMessageSize.LinearAccX
                                             + testKinematicMessageSize.LinearAccY
                                             + testKinematicMessageSize.LinearAccZ
                                             + testKinematicMessageSize.GravX
                                             + testKinematicMessageSize.GravY
                                             + testKinematicMessageSize.GravZ);

            Assert.AreEqual(testKinematicMessageIndex.GravZ, kinematicMessageSize - testKinematicMessageSize.GravZ);
        }
Пример #4
0
        static public void playerFromIoTCapture(string fileToPlay, MqttClient client)
        {
            Stopwatch stopWatch   = new Stopwatch();
            TimeSpan  startTime   = new TimeSpan();
            TimeSpan  currentTime = new TimeSpan();

            //StreamReader reader = new StreamReader(@"/Users/nadavguy/Downloads/subscription.csv");
            StreamReader reader = new StreamReader(fileToPlay);

            StatusMessage statusMessagetoParse = new StatusMessage();

            KinematicMessage kinematicMessagetoParse = new KinematicMessage();

            PhysicalMessage physicalMessagetoParse = new PhysicalMessage();

            StatusMessage StatusMessageFieldsSize = new StatusMessage();

            MessageInitializers.StatusMessageFieldSizeInitializer(out StatusMessageFieldsSize);

            StatusMessage StatusMessageFieldsIndex = new StatusMessage();

            MessageInitializers.StatusMessageFieldIndexInitializer(out StatusMessageFieldsIndex);

            //Kinematic message
            KinematicMessage KinematicMessageFieldsSize = new KinematicMessage();

            MessageInitializers.KinematicMessageFieldSizeInitializer(out KinematicMessageFieldsSize);

            KinematicMessage KinematicMessageFieldsIndex = new KinematicMessage();

            MessageInitializers.KinematicMessageFieldIndexInitializer(out KinematicMessageFieldsIndex);

            //Physical message
            PhysicalMessage PhysicalMessageFieldsSize = new PhysicalMessage();

            MessageInitializers.PhysicalMessageFieldSizeInitializer(out PhysicalMessageFieldsSize);

            PhysicalMessage PhysicalMessageFieldsIndex = new PhysicalMessage();

            MessageInitializers.PhysicalMessageFieldIndexInitializer(out PhysicalMessageFieldsIndex);

            List <string> listHex       = new List <string>();
            List <string> listPayload   = new List <string>();
            List <string> listQoS       = new List <string>();
            List <string> listTimestamp = new List <string>();
            List <string> listTopic     = new List <string>();

            while (!reader.EndOfStream)
            {
                var line   = reader.ReadLine();
                var values = line.Split(',');

                listHex.Add(values[0]);
                listPayload.Add(values[1]);
                listQoS.Add(values[2]);
                listTimestamp.Add(values[3]);
                listTopic.Add(values[4]);
            }
            double baseTimestamp = Convert.ToDouble(listTimestamp[0]);

            startTime = DateTime.Now.TimeOfDay;
            //stopWatch.Start();
            int i = 0;

            while (i < listHex.Count)
            {
                currentTime = DateTime.Now.TimeOfDay;
                //stopWatch.Stop();
                // Get the elapsed time as a TimeSpan value.
                //ts = stopWatch.Elapsed;
                // Using ID 600-700-800 for the data playerso it hard coded
                for (int j = i; j < listHex.Count; j++)
                {
                    if ((double)(currentTime - startTime).TotalMilliseconds > (Convert.ToDouble(listTimestamp[j]) - baseTimestamp))
                    {
                        i++;
                        if (listTopic[j].Equals(DeviceStatusTopic))
                        {
                            byte[] statusbyteArray = Encoding.UTF8.GetBytes(listPayload[j]);
                            MessageParser.StatusMessageParserFromByteArray(out statusMessagetoParse, StatusMessageFieldsIndex, StatusMessageFieldsSize, statusbyteArray);

                            List <Byte> termsList = new List <Byte>();

                            termsList = ManualSerializer.EncodeValuesAsBytesInList(StatusMessageFieldsSize.OpCode, (uint)statusMessagetoParse.OpCode, termsList);
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(StatusMessageFieldsSize.MessageCounter, (uint)statusMessagetoParse.MessageCounter, termsList);
                            termsList = ManualSerializer.EncodeValuesAsBytesInList((int)StatusMessageFieldsSize.IDPart1, 600, termsList);
                            termsList = ManualSerializer.EncodeValuesAsBytesInList((int)StatusMessageFieldsSize.IDPart2, 700, termsList);
                            termsList = ManualSerializer.EncodeValuesAsBytesInList((int)StatusMessageFieldsSize.IDPart3, 800, termsList);
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(StatusMessageFieldsSize.TimeSource, (uint)statusMessagetoParse.TimeSource, termsList); //Accurate
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(StatusMessageFieldsSize.GPSYear, (uint)0, termsList);                                  //Year
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(StatusMessageFieldsSize.GPSMonth, (uint)0, termsList);                                 //Month
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(StatusMessageFieldsSize.GPSDay, (uint)0, termsList);                                   //Day
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(StatusMessageFieldsSize.GPSHour, (uint)0, termsList);                                  //Hour
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(StatusMessageFieldsSize.GPSMinute, (uint)0, termsList);                                //Min
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(StatusMessageFieldsSize.GPSSecond, (uint)0, termsList);                                //Sec
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(StatusMessageFieldsSize.GPSMiliSec, (uint)0, termsList);                               //Mili
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(StatusMessageFieldsSize.Mode, (uint)statusMessagetoParse.Mode, termsList);             //Mode
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(StatusMessageFieldsSize.RTA, (uint)statusMessagetoParse.RTA, termsList);               //Ready To Arm
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(StatusMessageFieldsSize.BCS, (uint)statusMessagetoParse.BCS, termsList);               //Battery LSB=0.1
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(StatusMessageFieldsSize.IMUStatus, (uint)statusMessagetoParse.IMUStatus, termsList);   //IMU
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(StatusMessageFieldsSize.FDS, (uint)statusMessagetoParse.FDS, termsList);               //Flash
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(StatusMessageFieldsSize.RCChannels, (uint)statusMessagetoParse.RCChannels, termsList); //RC
                            Byte[] terms = termsList.ToArray();
                            client.Publish(DeviceStatusTopic, terms, 0, false);
                        }

                        if (listTopic[j].Equals(KinematicDataTopic))
                        {
                            byte[] statusbyteArray = Encoding.UTF8.GetBytes(listPayload[j]);
                            MessageParser.KinematicMessageParserFromByteArray(out kinematicMessagetoParse, KinematicMessageFieldsIndex, KinematicMessageFieldsSize, statusbyteArray);

                            List <Byte> termsList = new List <Byte>();

                            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.OpCode, (uint)kinematicMessagetoParse.OpCode, termsList);
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.MessageCounter, (uint)kinematicMessagetoParse.MessageCounter, termsList);
                            termsList = ManualSerializer.EncodeValuesAsBytesInList((int)KinematicMessageFieldsSize.IDPart1, 600, termsList);
                            termsList = ManualSerializer.EncodeValuesAsBytesInList((int)KinematicMessageFieldsSize.IDPart2, 700, termsList);
                            termsList = ManualSerializer.EncodeValuesAsBytesInList((int)KinematicMessageFieldsSize.IDPart3, 800, termsList);
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.TimeSource, (uint)statusMessagetoParse.TimeSource, termsList); //Accurate
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.GPSYear, (uint)0, termsList);                                  //Year
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.GPSMonth, (uint)0, termsList);                                 //Month
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.GPSDay, (uint)0, termsList);                                   //Day
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.GPSHour, (uint)0, termsList);                                  //Hour
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.GPSMinute, (uint)0, termsList);                                //Min
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.GPSSecond, (uint)0, termsList);                                //Sec
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.GPSMiliSec, (uint)0, termsList);                               //Mili
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.BaroHeight, (uint)kinematicMessagetoParse.BaroHeight, termsList);
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.Pressure, (uint)kinematicMessagetoParse.Pressure, termsList);
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.AccX, (uint)kinematicMessagetoParse.AccX, termsList);
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.AccY, (uint)kinematicMessagetoParse.AccY, termsList);
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.AccZ, (uint)kinematicMessagetoParse.AccZ, termsList);
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.MagX, (uint)kinematicMessagetoParse.MagX, termsList);
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.MagY, (uint)kinematicMessagetoParse.MagY, termsList);
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.MagZ, (uint)kinematicMessagetoParse.MagZ, termsList);
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.GyroX, (uint)kinematicMessagetoParse.GyroX, termsList);
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.GyroY, (uint)kinematicMessagetoParse.GyroY, termsList);
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.GyroZ, (uint)kinematicMessagetoParse.GyroZ, termsList);
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.Heading, (uint)kinematicMessagetoParse.Heading, termsList);
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.Roll, (uint)kinematicMessagetoParse.Roll, termsList);
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.Pitch, (uint)kinematicMessagetoParse.Pitch, termsList);
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.OrientationX, (uint)kinematicMessagetoParse.OrientationX, termsList);
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.OrientationY, (uint)kinematicMessagetoParse.OrientationY, termsList);
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.OrientationZ, (uint)kinematicMessagetoParse.OrientationZ, termsList);
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.OrientationW, (uint)kinematicMessagetoParse.OrientationW, termsList);
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.LinearAccX, (uint)kinematicMessagetoParse.LinearAccX, termsList);
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.LinearAccY, (uint)kinematicMessagetoParse.LinearAccY, termsList);
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.LinearAccZ, (uint)kinematicMessagetoParse.LinearAccZ, termsList);
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.GravX, (uint)kinematicMessagetoParse.GravX, termsList);
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.GravY, (uint)kinematicMessagetoParse.GravY, termsList);
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.GravZ, (uint)kinematicMessagetoParse.GravZ, termsList);
                            Byte[] terms = termsList.ToArray();
                            client.Publish(KinematicDataTopic, terms, 0, false);
                        }

                        if (listTopic[j].Equals(PhysicalDataTopic))
                        {
                            byte[] statusbyteArray = Encoding.UTF8.GetBytes(listPayload[j]);
                            MessageParser.PhysicalMessageParserFromByteArray(out physicalMessagetoParse, PhysicalMessageFieldsIndex, PhysicalMessageFieldsSize, statusbyteArray);

                            List <Byte> termsList = new List <Byte>();

                            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.OpCode, (uint)physicalMessagetoParse.OpCode, termsList);
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.MessageCounter, (uint)physicalMessagetoParse.MessageCounter, termsList);
                            termsList = ManualSerializer.EncodeValuesAsBytesInList((int)PhysicalMessageFieldsSize.IDPart1, 600, termsList);
                            termsList = ManualSerializer.EncodeValuesAsBytesInList((int)PhysicalMessageFieldsSize.IDPart2, 700, termsList);
                            termsList = ManualSerializer.EncodeValuesAsBytesInList((int)PhysicalMessageFieldsSize.IDPart3, 800, termsList);
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.TimeSource, (uint)physicalMessagetoParse.TimeSource, termsList); //Accurate
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.GPSYear, (uint)0, termsList);                                    //Year
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.GPSMonth, (uint)0, termsList);                                   //Month
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.GPSDay, (uint)0, termsList);                                     //Day
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.GPSHour, (uint)0, termsList);                                    //Hour
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.GPSMinute, (uint)0, termsList);                                  //Min
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.GPSSecond, (uint)0, termsList);                                  //Sec
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.GPSMiliSec, (uint)0, termsList);                                 //Mili
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.NumberOfSatellites, (uint)physicalMessagetoParse.NumberOfSatellites, termsList);
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.Latitude, (uint)physicalMessagetoParse.Latitude, termsList);
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.Longitude, (uint)physicalMessagetoParse.Longitude, termsList);
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.GPSAltitude, (uint)physicalMessagetoParse.GPSAltitude, termsList);
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.GPSVelocity, (uint)physicalMessagetoParse.GPSVelocity, termsList);
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.GPSAngle, (uint)physicalMessagetoParse.GPSAngle, termsList);
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.GPSGroundSpeed, (uint)physicalMessagetoParse.GPSGroundSpeed, termsList);
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.Temperature, (uint)physicalMessagetoParse.Temperature, termsList);
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.Humidity, (uint)physicalMessagetoParse.Humidity, termsList);
                            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.UVAUVB, (uint)physicalMessagetoParse.UVAUVB, termsList);
                            Byte[] terms = termsList.ToArray();
                            client.Publish(PhysicalDataTopic, terms, 0, false);
                        }
                    }
                }
            }
        }
Пример #5
0
        static void Main(string[] args)
        {
            /*Some Hack to Make MQTT messaging Work, Otherwise next messages are not sent*/
            //Publ publisher = new Publ();
            //publisher.Publish();
            const string     IotEndpoint             = "a28g8imipibhcw.iot.us-east-1.amazonaws.com";
            const int        BrokerPort              = 8883;
            const string     DeviceStatusTopic       = "DeviceStatus";
            const string     PhysicalDataTopic       = "PhysicalData";
            const string     KinematicDataTopic      = "KinematicData";
            const string     InitializationDataTopic = "InitData";
            X509Certificate2 clientCert              = new X509Certificate2("YOURPFXFILE.pfx", "1");
            X509Certificate  caCert = X509Certificate.CreateFromSignedFile("rootCA.pem");

            // create the client
            MqttClient client = new MqttClient(IotEndpoint, BrokerPort, true, caCert, clientCert, MqttSslProtocols.TLSv1_2);

            //message to publish - could be anything
            //client naming has to be unique if there was more than one publisher
            client.Connect("clientid1");

            //publish to the topic
            Byte[] A = { 2 };
            client.Publish("hello", A, 0, false);

            //string Message = "";
            Console.WriteLine("Hello World!");

            //For Future use when Export form DB will have millisecond

            /* StreamReader reader = new StreamReader(@"/Users/nadavguy/Downloads/physical-data-messages-2018-04-08.csv");
             * while (!reader.EndOfStream)
             * {
             *   var line = reader.ReadLine();
             *   var values = line.Split(',');
             *   Convert.ToDateTime(values[6].Substring(0,19))
             * }*/

            //Play old data capured from IoT (not DB export)
            //DataPlayer.playerFromIoTCapture(@"/Users/nadavguy/Downloads/subscription2.csv", client);

//Initialize messages
            //Status message
            StatusMessage StatusMessageFieldsSize = new StatusMessage();

            MessageInitializers.StatusMessageFieldSizeInitializer(out StatusMessageFieldsSize);

            StatusMessage StatusMessageFieldsIndex = new StatusMessage();

            MessageInitializers.StatusMessageFieldIndexInitializer(out StatusMessageFieldsIndex);

            //Physical message
            PhysicalMessage PhysicalMessageFieldsSize = new PhysicalMessage();

            MessageInitializers.PhysicalMessageFieldSizeInitializer(out PhysicalMessageFieldsSize);

            PhysicalMessage PhysicalMessageFieldsIndex = new PhysicalMessage();

            MessageInitializers.PhysicalMessageFieldIndexInitializer(out PhysicalMessageFieldsIndex);

            //Kinematic message
            KinematicMessage KinematicMessageFieldsSize = new KinematicMessage();

            MessageInitializers.KinematicMessageFieldSizeInitializer(out KinematicMessageFieldsSize);

            KinematicMessage KinematicMessageFieldsIndex = new KinematicMessage();

            MessageInitializers.KinematicMessageFieldIndexInitializer(out KinematicMessageFieldsIndex);

            //Initialization message
            InitializtionMessage InitMessageFieldsSize = new InitializtionMessage();

            MessageInitializers.InitMessageFieldSizeInitializer(out InitMessageFieldsSize);

            InitializtionMessage InitMessageFieldsIndex = new InitializtionMessage();

            MessageInitializers.InitMessageFieldIndexInitializer(out InitMessageFieldsIndex);
            //Start Application part

            WriteDefaultValues(fileName);
            //Parse old string message form IoT Core export to actual vlaues
            //will be used later for testing I guess

            /*
             * SByte OpCode = ManualSerializer.ReturnSByteValue(0, 1);
             * Int16 MessageCounter = ManualSerializer.ReturnInt16Value(1, 2, false);
             * UInt32 IDPart1 = ManualSerializer.ReturnUint32Value(3, 4, false);
             * UInt32 IDPart2 = ManualSerializer.ReturnUint32Value(7, 4, false);
             * UInt32 IDPart3 = ManualSerializer.ReturnUint32Value(11, 4, false);
             * SByte TimeSource = ManualSerializer.ReturnSByteValue(15, 1);
             * Int16 GPSYear = ManualSerializer.ReturnInt16Value(16, 2,false);
             * SByte GPSMonth = ManualSerializer.ReturnSByteValue(18, 1);
             * SByte GPSDay = ManualSerializer.ReturnSByteValue(19, 1);
             * SByte GPSHour = ManualSerializer.ReturnSByteValue(20, 1);
             * SByte GPSMinute = ManualSerializer.ReturnSByteValue(21, 1);
             * SByte GPSSecond = ManualSerializer.ReturnSByteValue(22, 1);
             * Int16 GPSMiliSecond = ManualSerializer.ReturnInt16Value(23, 2, false);
             * SByte Mode = ManualSerializer.ReturnSByteValue(25, 1);
             * SByte RTA = ManualSerializer.ReturnSByteValue(26, 1);
             * Int16 BCS = ManualSerializer.ReturnInt16Value(27, 2, false);
             * SByte IMUStatus = ManualSerializer.ReturnSByteValue(29, 1);
             * SByte FDS = ManualSerializer.ReturnSByteValue(30, 1);
             * SByte RCChannels = ManualSerializer.ReturnSByteValue(31, 1);
             */

            /*
             * StatusMessage ParsedStatusMessage = new StatusMessage();
             * MessageParser.StatusMessageParser(out ParsedStatusMessage, StatusMessageFieldsIndex, StatusMessageFieldsSize);
             */
            /* Part of the try to create a Byte array manuall and sending it using external MQTT applicaiton
             * it did not work. apperantly MQTT does so weird stuff to the payload.
             * added MQTT library.
             * Code is obsolete
             * Message += ManualSerializer.EncodeValuesAsBytes(1, (uint)2) + ",";
             * Message += ManualSerializer.EncodeValuesAsBytes(2, (uint)0) + ",";
             * Message += ManualSerializer.EncodeValuesAsBytes(4, 300) + ",";
             * Message += ManualSerializer.EncodeValuesAsBytes(4, 400) + ",";
             * Message += ManualSerializer.EncodeValuesAsBytes(4, 500) + ",";
             * Message += ManualSerializer.EncodeValuesAsBytes(1, (uint)2) + ",";//Accurate
             * Message += ManualSerializer.EncodeValuesAsBytes(2, (uint)0) + ",";//Year
             * Message += ManualSerializer.EncodeValuesAsBytes(1, (uint)0) + ",";//Month
             * Message += ManualSerializer.EncodeValuesAsBytes(1, (uint)0) + ",";//Day
             * Message += ManualSerializer.EncodeValuesAsBytes(1, (uint)0) + ",";//Hour
             * Message += ManualSerializer.EncodeValuesAsBytes(1, (uint)0) + ",";//Min
             * Message += ManualSerializer.EncodeValuesAsBytes(1, (uint)0) + ",";//Sec
             * Message += ManualSerializer.EncodeValuesAsBytes(2, (uint)0) + ",";//Mili
             * Message += ManualSerializer.EncodeValuesAsBytes(1, (uint)6) + ",";//Mode
             * Message += ManualSerializer.EncodeValuesAsBytes(1, (uint)1) + ",";//Ready To Arm
             * Message += ManualSerializer.EncodeValuesAsBytes(2, (uint)10) + ",";//Battery LSB=0.1
             * Message += ManualSerializer.EncodeValuesAsBytes(1, (uint)1) + ",";//IMU
             * Message += ManualSerializer.EncodeValuesAsBytes(1, (uint)3) + ",";//Flash
             * Message += ManualSerializer.EncodeValuesAsBytes(1, (uint)1);//RC*/

            //Encode Byte Array using list.
            List <Byte> termsList = new List <Byte>();

            //termsList = EncodeValuesAsBytesInList(4, 400, termsList);

            //Generate Status message
            termsList = ManualSerializer.EncodeValuesAsBytesInList(StatusMessageFieldsSize.OpCode, (uint)2,
                                                                   termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(StatusMessageFieldsSize.MessageCounter,
                                                                   (uint)0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList((int)StatusMessageFieldsSize.IDPart1,
                                                                   600, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList((int)StatusMessageFieldsSize.IDPart2,
                                                                   700, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList((int)StatusMessageFieldsSize.IDPart3,
                                                                   800, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(StatusMessageFieldsSize.TimeSource,
                                                                   (uint)2, termsList);   //Accurate
            termsList = ManualSerializer.EncodeValuesAsBytesInList(StatusMessageFieldsSize.GPSYear,
                                                                   (uint)0, termsList);   //Year
            termsList = ManualSerializer.EncodeValuesAsBytesInList(StatusMessageFieldsSize.GPSMonth,
                                                                   (uint)0, termsList);   //Month
            termsList = ManualSerializer.EncodeValuesAsBytesInList(StatusMessageFieldsSize.GPSDay,
                                                                   (uint)0, termsList);   //Day
            termsList = ManualSerializer.EncodeValuesAsBytesInList(StatusMessageFieldsSize.GPSHour,
                                                                   (uint)0, termsList);   //Hour
            termsList = ManualSerializer.EncodeValuesAsBytesInList(StatusMessageFieldsSize.GPSMinute,
                                                                   (uint)0, termsList);   //Min
            termsList = ManualSerializer.EncodeValuesAsBytesInList(StatusMessageFieldsSize.GPSSecond,
                                                                   (uint)0, termsList);   //Sec
            termsList = ManualSerializer.EncodeValuesAsBytesInList(StatusMessageFieldsSize.GPSMiliSec,
                                                                   (uint)0, termsList);   //Mili
            termsList = ManualSerializer.EncodeValuesAsBytesInList(StatusMessageFieldsSize.Mode,
                                                                   (uint)2, termsList);   //Mode
            termsList = ManualSerializer.EncodeValuesAsBytesInList(StatusMessageFieldsSize.RTA,
                                                                   (uint)2, termsList);   //Ready To Arm
            termsList = ManualSerializer.EncodeValuesAsBytesInList(StatusMessageFieldsSize.BCS,
                                                                   (uint)160, termsList); //Battery LSB=0.1
            termsList = ManualSerializer.EncodeValuesAsBytesInList(StatusMessageFieldsSize.IMUStatus,
                                                                   (uint)2, termsList);   //IMU
            termsList = ManualSerializer.EncodeValuesAsBytesInList(StatusMessageFieldsSize.FDS,
                                                                   (uint)3, termsList);   //Flash
            termsList = ManualSerializer.EncodeValuesAsBytesInList(StatusMessageFieldsSize.RCChannels,
                                                                   (uint)0, termsList);   //RC
            //2,0,0,3,0,0,0,4,0,0,0,5,0,0,0,0  ,0    ,0    ,0   ,0  ,0   ,0  ,0  ,0    ,0    ,0   ,0  ,255 ,0   ,1  ,1  ,3
            //2,0,0,3,0,0,0,4,0,0,0,5,0,0,0,Acc,YearL,YearH,Mnth,Day,Hour,Min,Sec,MiliL,MiliH,Mode,RTA,BCSL,BCSH,IMU,FSD,RC
            //2,0,0,3,0,0,0,4,0,0,0,5,0,0,0,1  ,0    ,0    ,0   ,0  ,0   ,0  ,0  ,0    ,0    ,6   ,1  ,10  ,0   ,1  ,3  ,1
            //Convert list to Array
            Byte[] terms = termsList.ToArray();
            //client.Connect("clientid1");
            //Publish message
            client.Publish(DeviceStatusTopic, terms, 0, false);

            termsList.Clear();
            //Generate Physical data message
            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.OpCode, 3, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.MessageCounter, 0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList((int)PhysicalMessageFieldsSize.IDPart1, 600, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList((int)PhysicalMessageFieldsSize.IDPart2, 700, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList((int)PhysicalMessageFieldsSize.IDPart3, 800, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.TimeSource, 2, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.GPSYear, 0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.GPSMonth, 0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.GPSDay, 0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.GPSHour, 0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.GPSMinute, 0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.GPSSecond, 0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.GPSMiliSec, 0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.NumberOfSatellites, 17, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.Latitude, 32100000, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.Longitude, 35200000, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.GPSAltitude, 3000, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.GPSVelocity, 3, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.GPSAngle, 5, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.GPSGroundSpeed, 15, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.Temperature, 32, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.Humidity, 3000, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.UVAUVB, 0, termsList);
            Byte[] terms2 = termsList.ToArray();
            //client.Connect("clientid1");
            client.Publish(PhysicalDataTopic, terms2, 0, false);

            //Generate Kinematic message
            termsList.Clear();
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.OpCode, 4, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.MessageCounter, 0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList((int)KinematicMessageFieldsSize.IDPart1, 600, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList((int)KinematicMessageFieldsSize.IDPart2, 700, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList((int)KinematicMessageFieldsSize.IDPart3, 800, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.TimeSource, 2, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.GPSYear, 0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.GPSMonth, 0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.GPSDay, 0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.GPSHour, 0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.GPSMinute, 0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.GPSSecond, 0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.GPSMiliSec, 0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.BaroHeight, 17, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.Pressure, 3200, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.AccX, 3500, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.AccY, 3000, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.AccZ, 3, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.MagX, 5, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.MagY, 15, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.MagZ, 32, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.GyroX, 3000, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.GyroY, 0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.GyroZ, 0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.Heading, 10, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.Roll, 20, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.Pitch, 40, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.OrientationX, 0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.OrientationY, 0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.OrientationZ, 0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.OrientationW, 0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.LinearAccX, 0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.LinearAccY, 0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.LinearAccZ, 0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.GravX, 0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.GravY, 0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.GravZ, 0, termsList);

            Byte[] terms3 = termsList.ToArray();
            //client.Connect("clientid1");
            client.Publish(KinematicDataTopic, terms3, 0, false);

            //Generate Initialization message
            termsList.Clear();
            termsList = ManualSerializer.EncodeValuesAsBytesInList(InitMessageFieldsSize.OpCode, (uint)1, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(InitMessageFieldsSize.MessageCounter, (uint)0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList((int)InitMessageFieldsSize.IDPart1, (uint)600, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList((int)InitMessageFieldsSize.IDPart2, (uint)700, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList((int)InitMessageFieldsSize.IDPart3, (uint)800, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(InitMessageFieldsSize.TimeSource, (uint)1, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(InitMessageFieldsSize.GPSYear, (uint)0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(InitMessageFieldsSize.GPSMonth, (uint)0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(InitMessageFieldsSize.GPSDay, (uint)0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(InitMessageFieldsSize.GPSHour, (uint)0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(InitMessageFieldsSize.GPSMinute, (uint)0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(InitMessageFieldsSize.GPSSecond, (uint)0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(InitMessageFieldsSize.GPSMiliSec, (uint)0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(InitMessageFieldsSize.SWVersionID, (uint)1000, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(InitMessageFieldsSize.HWVersionID, (uint)1000, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(InitMessageFieldsSize.ArmHeight, (uint)5, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(InitMessageFieldsSize.DisarmHeight, (uint)3, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(InitMessageFieldsSize.VibrationsValue, (uint)2, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(InitMessageFieldsSize.NoVibrationTime, (uint)250, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(InitMessageFieldsSize.VibrationFrequency, (uint)5, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(InitMessageFieldsSize.RollCalibration, (uint)0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(InitMessageFieldsSize.PitchCalibration, (uint)0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(InitMessageFieldsSize.RollInitMargin, (uint)5, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(InitMessageFieldsSize.PitchInitMargin, (uint)5, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(InitMessageFieldsSize.IMUConfiguration, (uint)15, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(InitMessageFieldsSize.RCConfiguration, (uint)3, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(InitMessageFieldsSize.BatteryCells, (uint)4, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(InitMessageFieldsSize.MotorDelay, (uint)50, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(InitMessageFieldsSize.RollAttitudeLimit, (uint)65, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(InitMessageFieldsSize.PitchAttitudeLimit, (uint)65, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(InitMessageFieldsSize.FreefallDuration, (uint)250, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(InitMessageFieldsSize.FreefallLimit, (uint)3, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(InitMessageFieldsSize.AngularSpeedRateLimit, (uint)150, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(InitMessageFieldsSize.AngularSpeedLimit, (uint)65, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(InitMessageFieldsSize.YawRateLimit, (uint)150, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(InitMessageFieldsSize.ActiveHeightSource, (uint)1, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(InitMessageFieldsSize.MaximumHeight, (uint)1, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(InitMessageFieldsSize.LandingGear, (uint)0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(InitMessageFieldsSize.ArmMode, (uint)1, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(InitMessageFieldsSize.PyroSensorCalib, (uint)35, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(InitMessageFieldsSize.PyroSensorMeasurement, (uint)19, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(InitMessageFieldsSize.PyroTestRate, (uint)15, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(InitMessageFieldsSize.EmergencyBattery, (uint)0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(InitMessageFieldsSize.Destination, (uint)1, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(InitMessageFieldsSize.SDCard, (uint)1, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(InitMessageFieldsSize.TriggeringMode, (uint)1, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(InitMessageFieldsSize.FiveVoltIndication, (uint)0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(InitMessageFieldsSize.EmergencyBatteryVoltageIndication, (uint)0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(InitMessageFieldsSize.TwelveVoltageIndication, (uint)0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(InitMessageFieldsSize.CapacitorVoltageIndication, (uint)0, termsList);

            //Convert list to Array
            Byte[] terms7 = termsList.ToArray();
            //client.Connect("clientid1");
            //Publish message
            client.Publish(InitializationDataTopic, terms7, 0, false);


            termsList.Clear();
            termsList = ManualSerializer.EncodeValuesAsBytesInList(StatusMessageFieldsSize.OpCode, (uint)2,
                                                                   termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(StatusMessageFieldsSize.MessageCounter,
                                                                   (uint)0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList((int)StatusMessageFieldsSize.IDPart1,
                                                                   600, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList((int)StatusMessageFieldsSize.IDPart2,
                                                                   700, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList((int)StatusMessageFieldsSize.IDPart3,
                                                                   900, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(StatusMessageFieldsSize.TimeSource,
                                                                   (uint)2, termsList);   //Accurate
            termsList = ManualSerializer.EncodeValuesAsBytesInList(StatusMessageFieldsSize.GPSYear,
                                                                   (uint)0, termsList);   //Year
            termsList = ManualSerializer.EncodeValuesAsBytesInList(StatusMessageFieldsSize.GPSMonth,
                                                                   (uint)0, termsList);   //Month
            termsList = ManualSerializer.EncodeValuesAsBytesInList(StatusMessageFieldsSize.GPSDay,
                                                                   (uint)0, termsList);   //Day
            termsList = ManualSerializer.EncodeValuesAsBytesInList(StatusMessageFieldsSize.GPSHour,
                                                                   (uint)0, termsList);   //Hour
            termsList = ManualSerializer.EncodeValuesAsBytesInList(StatusMessageFieldsSize.GPSMinute,
                                                                   (uint)0, termsList);   //Min
            termsList = ManualSerializer.EncodeValuesAsBytesInList(StatusMessageFieldsSize.GPSSecond,
                                                                   (uint)0, termsList);   //Sec
            termsList = ManualSerializer.EncodeValuesAsBytesInList(StatusMessageFieldsSize.GPSMiliSec,
                                                                   (uint)0, termsList);   //Mili
            termsList = ManualSerializer.EncodeValuesAsBytesInList(StatusMessageFieldsSize.Mode,
                                                                   (uint)6, termsList);   //Mode
            termsList = ManualSerializer.EncodeValuesAsBytesInList(StatusMessageFieldsSize.RTA,
                                                                   (uint)1, termsList);   //Ready To Arm
            termsList = ManualSerializer.EncodeValuesAsBytesInList(StatusMessageFieldsSize.BCS,
                                                                   (uint)160, termsList); //Battery LSB=0.1
            termsList = ManualSerializer.EncodeValuesAsBytesInList(StatusMessageFieldsSize.IMUStatus,
                                                                   (uint)1, termsList);   //IMU
            termsList = ManualSerializer.EncodeValuesAsBytesInList(StatusMessageFieldsSize.FDS,
                                                                   (uint)3, termsList);   //Flash
            termsList = ManualSerializer.EncodeValuesAsBytesInList(StatusMessageFieldsSize.RCChannels,
                                                                   (uint)0, termsList);   //RC
            //2,0,0,3,0,0,0,4,0,0,0,5,0,0,0,0  ,0    ,0    ,0   ,0  ,0   ,0  ,0  ,0    ,0    ,0   ,0  ,255 ,0   ,1  ,1  ,3
            //2,0,0,3,0,0,0,4,0,0,0,5,0,0,0,Acc,YearL,YearH,Mnth,Day,Hour,Min,Sec,MiliL,MiliH,Mode,RTA,BCSL,BCSH,IMU,FSD,RC
            //2,0,0,3,0,0,0,4,0,0,0,5,0,0,0,1  ,0    ,0    ,0   ,0  ,0   ,0  ,0  ,0    ,0    ,6   ,1  ,10  ,0   ,1  ,3  ,1
            //Convert list to Array
            Byte[] terms6 = termsList.ToArray();
            //client.Connect("clientid1");
            //Publish message
            client.Publish(DeviceStatusTopic, terms6, 0, false);

            termsList.Clear();
            //Generate Physical data message
            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.OpCode, 3, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.MessageCounter, 0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList((int)PhysicalMessageFieldsSize.IDPart1, 600, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList((int)PhysicalMessageFieldsSize.IDPart2, 700, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList((int)PhysicalMessageFieldsSize.IDPart3, 900, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.TimeSource, 2, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.GPSYear, 0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.GPSMonth, 0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.GPSDay, 0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.GPSHour, 0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.GPSMinute, 0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.GPSSecond, 0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.GPSMiliSec, 0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.NumberOfSatellites, 17, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.Latitude, 32000000, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.Longitude, 35000000, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.GPSAltitude, 3000, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.GPSVelocity, 3, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.GPSAngle, 5, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.GPSGroundSpeed, 15, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.Temperature, 32, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.Humidity, 3000, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(PhysicalMessageFieldsSize.UVAUVB, 0, termsList);
            Byte[] terms5 = termsList.ToArray();
            //client.Connect("clientid1");
            client.Publish(PhysicalDataTopic, terms5, 0, false);

            //Generate Kinematic message
            termsList.Clear();
            //Generate Physical data message
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.OpCode, 4, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.MessageCounter, 0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList((int)KinematicMessageFieldsSize.IDPart1, 600, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList((int)KinematicMessageFieldsSize.IDPart2, 700, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList((int)KinematicMessageFieldsSize.IDPart3, 900, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.TimeSource, 2, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.GPSYear, 0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.GPSMonth, 0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.GPSDay, 0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.GPSHour, 0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.GPSMinute, 0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.GPSSecond, 0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.GPSMiliSec, 0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.BaroHeight, 17, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.Pressure, 3200, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.AccX, 3500, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.AccY, 3000, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.AccZ, 3, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.MagX, 5, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.MagY, 15, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.MagZ, 32, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.GyroX, 3000, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.GyroY, 0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.GyroZ, 0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.Heading, 10, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.Roll, 20, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.Pitch, 40, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.OrientationX, 0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.OrientationY, 0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.OrientationZ, 0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.OrientationW, 0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.LinearAccX, 0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.LinearAccY, 0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.LinearAccZ, 0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.GravX, 0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.GravY, 0, termsList);
            termsList = ManualSerializer.EncodeValuesAsBytesInList(KinematicMessageFieldsSize.GravZ, 0, termsList);

            Byte[] terms4 = termsList.ToArray();
            //client.Connect("clientid1");
            client.Publish(KinematicDataTopic, terms4, 0, false);


            //client.Disconnect();

            /*
             * StatusMessage NewMessage = new StatusMessage();
             * NewMessage.OpCode = OpCode;
             * NewMessage.MessageCounter = MessageCounter;
             * NewMessage.IDPart1 = IDPart1;
             * NewMessage.IDPart2 = IDPart2;
             * NewMessage.IDPart3 = IDPart3;
             * NewMessage.TimeSource = TimeSource;
             * NewMessage.GPSYear = 2018;
             * NewMessage.GPSMonth = 4;
             * NewMessage.GPSDay = 4;
             * NewMessage.GPSHour = 14;
             * NewMessage.GPSMinute = 5;
             * NewMessage.GPSSecond = 0;
             * NewMessage.GPSMiliSec = 0;
             * NewMessage.Mode = Mode;
             * NewMessage.RTA = RTA;
             * NewMessage.BCS = BCS;
             * NewMessage.IMUStatus = IMUStatus;
             * NewMessage.FDS = FDS;
             * NewMessage.RCChannels = RCChannels;
             *
             * string Message2 = Encoders.MessageEncoder.StatusMessageEncoder(NewMessage, StatusMessageFieldsSize);
             */
//            client.Disconnect();
            Console.WriteLine("Its the End of the world as we know it!");
        }