Beispiel #1
0
        void UpdateDisplay(OBDIIReader.OBDIIData obdiiData)
        {
            if (_showAlertUntil < DateTime.UtcNow)
            {
                string time = obdiiData.Time.ToString("hh:mm:ss");
#if !MF_EMULATOR
                _text1.TextContent  = " " + time + " Speed: " + obdiiData.VehicleSpeed;
                _text2.TextContent  = " RPM: " + obdiiData.RPM;
                _text3.TextContent  = " Temp: " + obdiiData.AmbientAirTemp;
                _text4.TextContent  = " Fuel: " + obdiiData.FuelLevel; // 01 2F
                _text5.TextContent  = " Fuel Type: " + obdiiData.VehicleFuelType;
                _text6.TextContent  = " VIN: " + obdiiData.VIN;
                _text7.TextContent  = " Battery Voltage: " + obdiiData.BatteryVoltage;
                _text8.TextContent  = " Protocol Type: " + obdiiData.OBDProtocolType;
                _text9.TextContent  = " Intake Air Temp: " + obdiiData.IntakeAirTemp;
                _text10.TextContent = " Throttle position: " + obdiiData.ThrottlePosition;
#endif
            }
            else
            {
                this._text1.TextContent  = "";
                this._text2.TextContent  = "";
                this._text3.TextContent  = "";
                this._text4.TextContent  = "";
                this._text5.TextContent  = "  " + _alertText;
                this._text6.TextContent  = "";
                this._text7.TextContent  = "";
                this._text8.TextContent  = "";
                this._text9.TextContent  = "";
                this._text10.TextContent = "";

                this._timer.Interval = _targetTelemetryInterval;
            }
        }
Beispiel #2
0
        void timer_Tick(GT.Timer timer)
        {
            timer.Stop();
            timer.Interval = _targetTelemetryInterval;

            OBDIIReader.OBDIIData obdiiData = null;
            if (this.OBDReader.InitializeObd())
            {
                obdiiData = this.OBDReader.ReadObdIIData();
                UpdateDisplay(obdiiData);
            }

#if !MF_EMULATOR
            this.temperatureHumidity.RequestMeasurement();
#endif

#if SB
            if (this.TimeHelper.UpdateTime())
            {
                GetDeviceProvisioningInfo();
                if (this.SBSender == null)
                {
                    // TODO: Provision SB credentials properly
                    this.SBSender = new AmqpSender(this, this.deviceInfo.baseUri, this.deviceInfo.keyName, this.deviceInfo.keyValue, this.deviceInfo.OutboxEntity);
                    this.SBSender.StartSender();
#if !OrderedMessagingDemo
                    if (this.SBReceiver == null)
                    {
                        // TODO Use the AMQP session and connection of the sender to minimize socket usage/SSL overhead on both client and service
                        this.SBReceiver = new AmqpReceiver(this, this.deviceInfo.baseUri, this.deviceInfo.keyName, this.deviceInfo.keyValue, this.deviceInfo.InboxEntity, OnMessageCallback);
                        //this.SBReceiver = new AmqpReceiver(this, this.SBSender, this.deviceInfo.InboxEntity, OnMessageCallback);

                        this.SBReceiver.SenderForLatencies   = this.SBSender;
                        this.SBReceiver.DeviceIdForLatencies = this.deviceInfo.DeviceId.ToString();
                        this.SBReceiver.Start();
                    }
#endif
                }
                else
                {
                    SendOBDToSB(obdiiData);

                    if (this._lastDeviceTemperatureHumidityTimestamp > DateTime.MinValue)
                    {
                        SendTemperatureToDB(this.deviceInfo.DeviceId, this._lastDeviceTemperatureHumidityTimestamp, this._lastDeviceTemperature, this._lastDeviceHumidity);
                    }
                }
            }
#endif
            timer.Start();
        }
Beispiel #3
0
        public void SendOBDToSB(OBDIIReader.OBDIIData obdiiData)
        {
            if (bSBViaHttp && this.messagingClient != null)
            {
                try
                {
                    this.TraceLog("Sending OBDData to SB via HTTP");

                    SimpleMessage message = new SimpleMessage()
                    {
                        BrokerProperties = { { "SessionId", obdiiData.VIN }, { "Label", "OBDData" } },
                        Properties       =
                        {
                            { AmqpSendReceiveBase.strPropertyDeviceGatewayDeviceId, this.deviceInfo.DeviceId    },
                            { AmqpSendReceiveBase.strPropertyEventTimestamp,        obdiiData.Time              },

                            { "VIN",                                                obdiiData.VIN               },
                            { "Speed",                                              obdiiData.VehicleSpeed      },
                            { "RPM",                                                obdiiData.RPM               },
                            { "ThrottlePosition",                                   obdiiData.ThrottlePosition  },
                            { "AmbientAirTemp",                                     obdiiData.AmbientAirTemp    },
                            { "IntakeAirTemp",                                      obdiiData.IntakeAirTemp     },
                            { "DistancePerGallon",                                  obdiiData.DistancePerGallon },
#if MyMode01
                            { "EngineFuelRate",                                     obdiiData.EngineFuelRate    },
#endif
                        },
                    };
                    this.messagingClient.Send(message);

                    this.TraceLog("Sent OBDData to SB via HTTP");
                }
                catch (Exception e)
                {
                    this.TraceLog("Failure sending OBDData to SB via HTTP: " + e.Message);
                }
            }
            if (bSBViaAmqp && this.SBSender != null)
            {
                try
                {
#if !OrderedMessagingDemo
                    this.TraceLog("Sending OBDData to SB via AMQP");

                    Message message = new Message();

                    message.Properties         = new Amqp.Framing.Properties();
                    message.Properties.Subject = "OBDData";
                    message.Properties.GroupId = obdiiData.VIN;

                    message.ApplicationProperties = new Amqp.Framing.ApplicationProperties();
                    message.ApplicationProperties[AmqpSendReceiveBase.strPropertyDeviceGatewayDeviceId] = this.deviceInfo.DeviceId;
                    message.ApplicationProperties[AmqpSendReceiveBase.strPropertyEventTimestamp]        = obdiiData.Time;
                    message.ApplicationProperties[AmqpSendReceiveBase.strPropertySendTimestamp]         = DateTime.UtcNow;

                    message.ApplicationProperties["VIN"]               = obdiiData.VIN;
                    message.ApplicationProperties["Speed"]             = obdiiData.VehicleSpeed;
                    message.ApplicationProperties["RPM"]               = obdiiData.RPM;
                    message.ApplicationProperties["ThrottlePosition"]  = obdiiData.ThrottlePosition;
                    message.ApplicationProperties["AmbientAirTemp"]    = obdiiData.AmbientAirTemp;
                    message.ApplicationProperties["IntakeAirTemp"]     = obdiiData.IntakeAirTemp;
                    message.ApplicationProperties["DistancePerGallon"] = obdiiData.DistancePerGallon;
                    message.ApplicationProperties["BatteryVoltage"]    = obdiiData.BatteryVoltage;
#if MyMode01
                    message.ApplicationProperties["EngineFuelRate"] = obdiiData.EngineFuelRate;
#endif

                    this.SBSender.SendOrEnqueueMessage(message);
#else //if OrderedMessagingDemo // Use in demos to if ordering of messages from the same sender/partition are preserved
                    this.TraceLog("Sending Sentence to SB via AMQP");
                    string text = "Vehicle " + obdiiData.VIN + " going at " + obdiiData.VehicleSpeed + " mph with " + obdiiData.RPM + " RPM at " + obdiiData.Time.ToString();
                    foreach (var word in text.Split(' '))
                    {
                        var tmessage = new Message(word);
                        tmessage.Properties            = new Amqp.Framing.Properties();
                        tmessage.Properties.Subject    = "Sentences";
                        tmessage.ApplicationProperties = new Amqp.Framing.ApplicationProperties();
                        tmessage.ApplicationProperties["PartitionKey"] = obdiiData.VIN;

                        this.SBSender.SendOrEnqueueMessage(tmessage);
                    }
#endif
                }
                catch (Exception e)
                {
                    this.TraceLog("Failure sending OBDData to SB via AMQP: " + e.Message);
                }
            }
        }