Пример #1
0
        static void Main(string[] args)
        {
            Phantom.Instance.start(new Phantom.ProcessPhantomMessages(processMessages), true);

            while (true)
            {
                object[] parameters;
                if (messagesQueue.TryDequeue(out parameters))
                {
                    Phantom.Messages    message      = (Phantom.Messages)parameters[0];
                    Phantom.MessageData generic_data = (Phantom.MessageData)parameters[1];
                    DateTime            message_time = (DateTime)parameters[2];

                    switch (message)
                    {
                    case Phantom.Messages.RECEIVED_ID_INFO:
                    {
                        Phantom.MessageDataIDInfo data = (Phantom.MessageDataIDInfo)generic_data;

                        phantom_to_ip[data.phantom_code] = data.ip_address;

                        Console.WriteLine("Id from " + data.phantom_code + " " + data.ip_address);

                        break;
                    }

                    case Phantom.Messages.RECEIVED_EIMOINFO:
                    {
                        Phantom.MessageDataEIMO data = (Phantom.MessageDataEIMO)generic_data;

                        phantom_to_ip[data.phantom_code] = data.ip_address;

                        break;
                    }

                    case Phantom.Messages.RECEIVED_PHANTOM_ACCEL_DATA:
                    {
                        Phantom.MessageDataEIMONanoAccel data = (Phantom.MessageDataEIMONanoAccel)generic_data;

                        Console.WriteLine("Data from " + data.phantom_code);

                        break;
                    }

                    case Phantom.Messages.RECEIVED_PHANTOM_TEMP_DATA:
                    {
                        Phantom.MessageDataEIMONanoTemp data = (Phantom.MessageDataEIMONanoTemp)generic_data;

                        if (data.type == Phantom.TemperatureType.INFRARED)
                        {
                            Console.WriteLine("TEmperature from infrarred " + data.phantom_code + " Object Temp " + data.temperature.ToString() +
                                              " Ambient Temp " + data.ambient_temperature.ToString() +
                                              "C Battery " + data.battery.ToString() + " Module Temperature: " + data.module_temperature.ToString() + " (" + System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture) + ")\n");
                        }
                        else
                        {
                            Console.WriteLine("TEmperature from termocopule " + data.phantom_code + " " + data.temperature.ToString() +
                                              "C Battery " + data.battery.ToString() + " Module Temperature: " + data.module_temperature.ToString() + " (" + System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture) + ")\n");
                        }

                        break;
                    }

                    case Phantom.Messages.RECEIVED_PHANTOM_ACCEL_SETTINGS:
                    {
                        Phantom.MessageEIMONanoAccelSettings data = (Phantom.MessageEIMONanoAccelSettings)generic_data;

                        Console.WriteLine("Settings from " + data.phantom_code + " send interval: " + data.send_interval.ToString()
                                          + " Sample Rate: " + data.sample_rate.ToString()
                                          + " Samples to Get: " + data.samples_to_get.ToString()
                                          + " Range: " + data.range.ToString() + "g"
                                          + " AlarmX: " + data.alarm1.ToString() + "mm/s"
                                          + " AlarmY: " + data.alarm2.ToString() + "mm/s"
                                          + " AlarmZ: " + data.alarm3.ToString() + "mm/s"
                                          + "Alarm Check Interval " + data.alarmcheck_interval.ToString() + "s"
                                          + " (" + System.DateTime.Now.ToString() + ")"
                                          + "\r\n");


                        break;
                    }

                    case Phantom.Messages.RECEIVED_PHANTOM_ACCEL_STATE:
                    {
                        Phantom.MessageEIMONanoAccelState data = (Phantom.MessageEIMONanoAccelState)generic_data;

                        Console.WriteLine("State from " + data.phantom_code + " RMS Channel1: " + data.rms1.ToString()
                                          + " RMS Channel2: " + data.rms2.ToString()
                                          + " RMS Channel13: " + data.rms3.ToString()
                                          + " Battery voltage: " + data.battery.ToString() + "v"
                                          + " Temperature: " + data.temperature.ToString() + "C"
                                          + "\n");

                        break;
                    }
                    }
                }
                else
                {
                    System.Threading.Thread.Sleep(500);
                }
            }
        }
Пример #2
0
        public void processMessagesMainThread(Phantom.Messages message, Phantom.MessageData generic_data)
        {
            switch (message)
            {
            case Phantom.Messages.RECEIVED_ID_INFO:
            {
                Phantom.MessageDataIDInfo data = (Phantom.MessageDataIDInfo)generic_data;

                //phantom_to_ip[data.phantom_code] = data.ip_address;

                Console.WriteLine("Id from " + data.phantom_code + " " + data.ip_address);

                break;
            }

            case Phantom.Messages.RECEIVED_EIMOINFO:
            {
                Phantom.MessageDataEIMO data = (Phantom.MessageDataEIMO)generic_data;

                //phantom_to_ip[data.phantom_code] = data.ip_address;

                break;
            }

            case Phantom.Messages.RECEIVED_PHANTOM_ACCEL_DATA:
            {
                Phantom.MessageDataEIMONanoAccel data = (Phantom.MessageDataEIMONanoAccel)generic_data;
                AccelModuleData mem_data = null;

                try
                {
                    mem_data = (AccelModuleData)phantom_to_data[data.phantom_code];
                }
                catch (Exception)
                {
                    mem_data = new AccelModuleData();
                    phantom_to_data[data.phantom_code] = mem_data;

                    phantomListBox.Items.Add(data.phantom_code);
                }

                mem_data.module_type      = data.device;
                mem_data.channel1         = data.channel1;
                mem_data.channel2         = data.channel2;
                mem_data.channel3         = data.channel3;
                mem_data.last_update_data = DateTime.Now;
                updateui_if_selected(data.phantom_code);

                Console.WriteLine("Data from " + data.phantom_code);


                break;
            }

            case Phantom.Messages.RECEIVED_PHANTOM_TEMP_DATA:
            {
                Phantom.MessageDataEIMONanoTemp data = (Phantom.MessageDataEIMONanoTemp)generic_data;

                if (data.type == Phantom.TemperatureType.INFRARED)
                {
                    Console.WriteLine("TEmperature from infrarred " + data.phantom_code + " Object Temp " + data.temperature.ToString() +
                                      " Ambient Temp " + data.ambient_temperature.ToString() +
                                      "C Battery " + data.battery.ToString() + " Module Temperature: " + data.module_temperature.ToString() + " (" + System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ")\n");
                }
                else
                {
                    Console.WriteLine("TEmperature from termocopule " + data.phantom_code + " " + data.temperature.ToString() +
                                      "C Battery " + data.battery.ToString() + " Module Temperature: " + data.module_temperature.ToString() + " (" + System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ")\n");
                }

                break;
            }

            case Phantom.Messages.RECEIVED_PHANTOM_ACCEL_SETTINGS:
            {
                Phantom.MessageEIMONanoAccelSettings data = (Phantom.MessageEIMONanoAccelSettings)generic_data;

                Console.WriteLine("Settings from " + data.phantom_code + " send interval: " + data.send_interval.ToString()
                                  + " Sample Rate: " + data.sample_rate.ToString()
                                  + " Samples to Get: " + data.samples_to_get.ToString()
                                  + " Range: " + data.range.ToString() + "g"
                                  + " AlarmX: " + data.alarm1.ToString() + "mm/s"
                                  + " AlarmY: " + data.alarm2.ToString() + "mm/s"
                                  + " AlarmZ: " + data.alarm3.ToString() + "mm/s"
                                  + "Alarm Check Interval " + data.alarmcheck_interval.ToString() + "s"
                                  + " (" + System.DateTime.Now.ToString() + ")"
                                  + "\r\n");


                break;
            }

            case Phantom.Messages.RECEIVED_PHANTOM_ACCEL_STATE:
            {
                Phantom.MessageEIMONanoAccelState data = (Phantom.MessageEIMONanoAccelState)generic_data;

                AccelModuleData mem_data = null;

                try
                {
                    mem_data = (AccelModuleData)phantom_to_data[data.phantom_code];
                }
                catch (Exception)
                {
                    mem_data = new AccelModuleData();
                    phantom_to_data[data.phantom_code] = mem_data;

                    phantomListBox.Items.Add(data.phantom_code);
                }

                mem_data.module_type        = data.device;
                mem_data.module_battery     = data.battery;
                mem_data.module_temperature = data.temperature;
                mem_data.rms_channel1       = data.rms1;
                mem_data.rms_channel2       = data.rms2;
                mem_data.rms_channel3       = data.rms3;

                mem_data.last_update_rms = DateTime.Now;
                updateui_if_selected(data.phantom_code);

                Console.WriteLine("State from " + data.phantom_code + " RMS Channel1: " + data.rms1.ToString()
                                  + " RMS Channel2: " + data.rms2.ToString()
                                  + " RMS Channel13: " + data.rms3.ToString()
                                  + " Battery voltage: " + data.battery.ToString() + "v"
                                  + " Temperature: " + data.temperature.ToString() + "C"
                                  + "\n");

                break;
            }
            }
        }