Esempio n. 1
0
        public void StatusMessageVsIndex()
        {
            StatusMessage testStatusMessageSize  = new StatusMessage();
            StatusMessage testStatusMessageIndex = new StatusMessage();

            MessageInitializers.StatusMessageFieldSizeInitializer(out testStatusMessageSize);
            MessageInitializers.StatusMessageFieldIndexInitializer(out testStatusMessageIndex);


            int statusMessageSize = (int)(testStatusMessageSize.OpCode + testStatusMessageSize.MessageCounter
                                          + testStatusMessageSize.IDPart1
                                          + testStatusMessageSize.IDPart2
                                          + testStatusMessageSize.IDPart3
                                          + testStatusMessageSize.TimeSource
                                          + testStatusMessageSize.GPSYear
                                          + testStatusMessageSize.GPSMonth
                                          + testStatusMessageSize.GPSDay
                                          + testStatusMessageSize.GPSHour
                                          + testStatusMessageSize.GPSMinute
                                          + testStatusMessageSize.GPSSecond
                                          + testStatusMessageSize.GPSMiliSec
                                          + testStatusMessageSize.Mode
                                          + testStatusMessageSize.RTA
                                          + testStatusMessageSize.BCS
                                          + testStatusMessageSize.IMUStatus
                                          + testStatusMessageSize.FDS
                                          + testStatusMessageSize.RCChannels);

            Assert.AreEqual(testStatusMessageIndex.RCChannels, statusMessageSize - testStatusMessageSize.RCChannels);
        }
Esempio n. 2
0
        public void StatusMessageEncodingTests()
        {
            StatusMessage testStatusMessageSize  = new StatusMessage();
            StatusMessage testStatusMessageIndex = new StatusMessage();

            MessageInitializers.StatusMessageFieldSizeInitializer(out testStatusMessageSize);
            MessageInitializers.StatusMessageFieldIndexInitializer(out testStatusMessageIndex);

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

            messageValuesList = ManualSerializer.EncodeValuesAsBytesInList(testStatusMessageSize.OpCode, (uint)2,
                                                                           messageValuesList);
            messageValuesList = ManualSerializer.EncodeValuesAsBytesInList(testStatusMessageSize.MessageCounter,
                                                                           (uint)0, messageValuesList);
            messageValuesList = ManualSerializer.EncodeValuesAsBytesInList((int)testStatusMessageSize.IDPart1,
                                                                           600, messageValuesList);
            messageValuesList = ManualSerializer.EncodeValuesAsBytesInList((int)testStatusMessageSize.IDPart2,
                                                                           700, messageValuesList);
            messageValuesList = ManualSerializer.EncodeValuesAsBytesInList((int)testStatusMessageSize.IDPart3,
                                                                           800, messageValuesList);
            messageValuesList = ManualSerializer.EncodeValuesAsBytesInList(testStatusMessageSize.TimeSource,
                                                                           (uint)2, messageValuesList);   //Accurate
            messageValuesList = ManualSerializer.EncodeValuesAsBytesInList(testStatusMessageSize.GPSYear,
                                                                           (uint)0, messageValuesList);   //Year
            messageValuesList = ManualSerializer.EncodeValuesAsBytesInList(testStatusMessageSize.GPSMonth,
                                                                           (uint)0, messageValuesList);   //Month
            messageValuesList = ManualSerializer.EncodeValuesAsBytesInList(testStatusMessageSize.GPSDay,
                                                                           (uint)0, messageValuesList);   //Day
            messageValuesList = ManualSerializer.EncodeValuesAsBytesInList(testStatusMessageSize.GPSHour,
                                                                           (uint)0, messageValuesList);   //Hour
            messageValuesList = ManualSerializer.EncodeValuesAsBytesInList(testStatusMessageSize.GPSMinute,
                                                                           (uint)0, messageValuesList);   //Min
            messageValuesList = ManualSerializer.EncodeValuesAsBytesInList(testStatusMessageSize.GPSSecond,
                                                                           (uint)0, messageValuesList);   //Sec
            messageValuesList = ManualSerializer.EncodeValuesAsBytesInList(testStatusMessageSize.GPSMiliSec,
                                                                           (uint)0, messageValuesList);   //Mili
            messageValuesList = ManualSerializer.EncodeValuesAsBytesInList(testStatusMessageSize.Mode,
                                                                           (uint)4, messageValuesList);   //Mode
            messageValuesList = ManualSerializer.EncodeValuesAsBytesInList(testStatusMessageSize.RTA,
                                                                           (uint)1, messageValuesList);   //Ready To Arm
            messageValuesList = ManualSerializer.EncodeValuesAsBytesInList(testStatusMessageSize.BCS,
                                                                           (uint)160, messageValuesList); //Battery LSB=0.1
            messageValuesList = ManualSerializer.EncodeValuesAsBytesInList(testStatusMessageSize.IMUStatus,
                                                                           (uint)1, messageValuesList);   //IMU
            messageValuesList = ManualSerializer.EncodeValuesAsBytesInList(testStatusMessageSize.FDS,
                                                                           (uint)3, messageValuesList);   //Flash
            messageValuesList = ManualSerializer.EncodeValuesAsBytesInList(testStatusMessageSize.RCChannels,
                                                                           (uint)1, messageValuesList);   //RC
            //Convert list to Array
            Byte[] messageinValues = messageValuesList.ToArray();
            Byte[] ExpectedArray   = { 2, 0, 0, 88, 2, 0, 0, 188, 2, 0, 0, 32, 3, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 1, 160, 0, 1, 3, 1 };
            Assert.AreEqual(Convert.ToBase64String(ExpectedArray), Convert.ToBase64String(messageinValues));
        }
Esempio n. 3
0
        public void dataPlayerStatusMessageParseFromByteArray()
        {
            StatusMessage statusMessagetoParse   = new StatusMessage();
            StatusMessage statusMessagetoCompare = new StatusMessage();

            StatusMessage StatusMessageFieldsSize = new StatusMessage();

            MessageInitializers.StatusMessageFieldSizeInitializer(out StatusMessageFieldsSize);

            StatusMessage StatusMessageFieldsIndex = new StatusMessage();

            MessageInitializers.StatusMessageFieldIndexInitializer(out StatusMessageFieldsIndex);

            Byte[] statusbyteArray = Encoding.UTF8.GetBytes("023f00470020001751353235363633020000000000002700000602a100020000");

            MessageParser.StatusMessageParserFromByteArray(out statusMessagetoParse, StatusMessageFieldsIndex, StatusMessageFieldsSize, statusbyteArray);

            statusMessagetoCompare.OpCode         = 2;
            statusMessagetoCompare.MessageCounter = 63;
            statusMessagetoCompare.IDPart1        = 2097223;
            statusMessagetoCompare.IDPart2        = 842354967;
            statusMessagetoCompare.IDPart3        = 859190837;
            statusMessagetoCompare.TimeSource     = 2;
            statusMessagetoCompare.GPSYear        = 0;
            statusMessagetoCompare.GPSMonth       = 0;
            statusMessagetoCompare.GPSDay         = 0;
            statusMessagetoCompare.GPSHour        = 0;
            statusMessagetoCompare.GPSMinute      = 0;
            statusMessagetoCompare.GPSSecond      = 39;
            statusMessagetoCompare.GPSMiliSec     = 0;
            statusMessagetoCompare.Mode           = 6;
            statusMessagetoCompare.RTA            = 2;
            statusMessagetoCompare.BCS            = 161;
            statusMessagetoCompare.IMUStatus      = 2;
            statusMessagetoCompare.FDS            = 0;
            statusMessagetoCompare.RCChannels     = 0;
            Assert.AreEqual(statusMessagetoCompare, statusMessagetoParse);
        }
Esempio n. 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);
                        }
                    }
                }
            }
        }
Esempio n. 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!");
        }