Esempio n. 1
0
        public void StartTransmission()
        {
            RunPyScript();
            while (!terminate)
            {
                try
                {
                    Byte[] receiveBytes = RemoteUdpClient.Receive(ref RemoteIpEndPoint);
                    string returnData   = Encoding.UTF8.GetString(receiveBytes);

                    var information = JsonSerializer.Deserialize <float[]>(returnData);

                    vmx.ReCount(information[0], information[3]);
                    vmy.ReCount(information[1], information[3]);
                    vmz.ReCount(information[2], information[3]);

                    //~ if (information[0] > deadline || information[1] > deadline || information[2] > deadline)
                    //~ {
                    //~ WebSocketContext.TriggerEmergency(OwnWsc);
                    //~ }

                    if (counter % snm == 0)
                    {
                        float[] clientData = new float[]
                        {
                            information[0], information[1], information[2],
                            vmx.Velocity, vmy.Velocity, vmz.Velocity
                        };
                        MessageBlock sendMsg    = new MessageBlock(clientData);
                        string       clientJson = JsonSerializer.Serialize(sendMsg);

                        try
                        {
                            WS.Send(clientJson);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("WS send error!\n\n" + ex.Message);
                        }

                        if (counter > 4294967000)
                        {
                            counter = 1;
                        }
                    }
                    ++counter;
                }
                catch
                {
                    Console.WriteLine("\n\n SENSORCONTROLLER CLASS \n\n");
                    throw;
                }
            }
        }
        public void StartTransmission()
        {
            RunPyScript();
            while (!terminate)
            {
                try
                {
                    Byte[] receiveBytes = RemoteUdpClient.Receive(ref RemoteIpEndPoint);
                    string returnData   = Encoding.UTF8.GetString(receiveBytes);

                    var information = JsonSerializer.Deserialize <float[]>(returnData);

                    vmx.ReCount(information[0], information[3]);
                    vmy.ReCount(information[1], information[3]);
                    vmz.ReCount(information[2], information[3]);

                    float[] clientData = new float[]
                    {
                        information[0], information[1], information[2],
                        vmx.Velocity, vmy.Velocity, vmz.Velocity
                    };

                    MessageBlock sendMsg = new MessageBlock(clientData);

                    if (counter % sf == 0)
                    {
                        string clientJson = JsonSerializer.Serialize(sendMsg);
                        try
                        {
                            WS.Send(clientJson);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.Message);
                        }
                        if (counter > 4294967000)
                        {
                            counter = 0;
                        }
                    }
                    ++counter;
                }
                catch
                {
                    Console.WriteLine("\n\n SENSORCONTROLLER CLASS \n\n");
                    throw;
                }
            }
        }