private void SendButton_Click(object sender, RoutedEventArgs e)
        {
            string message;

            switch (MessageType)
            {
            case MessageTestType.J1708:
                message = BuildJ1708Message();
                break;

            case MessageTestType.J1939:
                message = BuildJ1939Message();
                break;

            case MessageTestType.Raw:
            default:
                message = CurrentMessage.Text;
                break;
            }
            if (!string.IsNullOrEmpty(message))
            {
                RaiseVMSEvent?.Invoke(this, new VMSCommDataEventArgs(message, DateTime.Now));
                MessageBox.Show($"Message sent as {message}");
            }
            else
            {
                MessageBox.Show($"Invalid message");
            }
        }
Exemple #2
0
 protected void OnDataReceived(string data)
 {
     RaiseVMSEvent?.Invoke(
         this,
         new VMSCommDataEventArgs(data, DateTime.Now)
         );
 }
Exemple #3
0
 private void Calculate()
 {
     if (!double.IsNaN(LastSpeed))
     {
         double acceleration       = (NewSpeed - LastSpeed);
         double metricAcceleration = (acceleration * 1.60934);
         RaiseVMSEvent?.Invoke(this, new VMSPidValueEventArgs((EventIDs.PID_BASE | 10), acceleration));
     }
     LastSpeed = NewSpeed;
 }
 private void PublishTireEvents()
 {
     for (int i = 0; i < MAX_TIRE_POSITIONS; i++)
     {
         if (Tires[i] != null)
         {
             var e = new TireEventArgs(Tires[i]);
             RaiseVMSEvent?.Invoke(this, e);
         }
     }
 }
Exemple #5
0
 private void PublishNewDataEvent(CanMessage message)
 {
     foreach (var segment in message.CanMessageSegments)
     {
         if (segment.ParseStatus == ParseStatus.Parsed)
         {
             segment.TimeParsed = DateTime.Now;
             var e = new VMSParsedDataEventArgs(segment.Pid, segment);
             RaiseVMSEvent?.Invoke(this, e);
         }
         else
         {
             PublishUnparsedData(segment);
         }
     }
 }
Exemple #6
0
        public void PublishUnparsedData(CanMessageSegment segment)
        {
            VMSRawDataEventArgs e;

            switch (segment.DataSource)
            {
            case VMSDataSource.J1708:
                e = new VMSJ1708RawDataEventArgs(segment as J1708MessageSegment);
                RaiseVMSEvent?.Invoke(this, e);
                break;

            case VMSDataSource.J1939:
                e = new VMSJ1939RawDataEventArgs(segment as J1939MessageSegment);
                RaiseVMSEvent?.Invoke(this, e);
                break;
            }
        }
Exemple #7
0
 /// <summary>
 /// Instantiates a J1939 can message from the raw message, then passes the message to the J1939 parser,
 /// which handles both extraction and parsing
 /// </summary>
 /// <param name="rawMessage"></param>
 /// <param name="e"></param>
 private void ProcessJ1939Data(string rawMessage, VMSCommDataEventArgs e)
 {
     try
     {
         var canMessage = new J1939Message(rawMessage, e.timeStamp);
         if (canMessage.IsValidMessage())
         {
             canMessage.ExtractMessage();
             _J1939Parser.Parse(canMessage);
             PublishNewDataEvent(canMessage);
         }
     }
     catch (Exception ex)
     {
         RaiseVMSEvent?.Invoke(this, new VMSCommDataErrorEventArgs(e, MessageError.UnrecognizedMessage, ex));
         ErrorLogger.GenerateErrorRecord(ex);
     }
 }
Exemple #8
0
            public void UpdateAndPublish(PidValue pidValue, CanMessageSegment segment)
            {
                if (pidValue == null)
                {
                    pidValue = new PidValue();
                }
                pidValue.RawValue         = segment.RawValue;
                pidValue.StandardValue    = segment.StandardValue * Parameter.Multiplier + Parameter.Offset;
                pidValue.MetricValue      = segment.MetricValue * Parameter.Multiplier + Parameter.Offset;
                pidValue.TimeReceived     = segment.TimeReceived;
                Parameter.LastValue       = pidValue.StandardValue;
                Parameter.LastMetricValue = pidValue.MetricValue;
                Parameter.Seen            = true;
                var e = new VMSPidValueEventArgs(EventIDs.PID_BASE | Parameter.Pid, Parameter.LastValue)
                {
                    segment = segment,
                };

                RaiseVMSEvent?.Invoke(this, e);
                //VMSConsole.PrintLine("Time to parse: " + (segment.TimeParsed - segment.TimeReceived));
            }
Exemple #9
0
 /// <summary>
 /// Istantiates a J1708 can message from the raw message. The J1708 Can Message handles it's own
 /// raw value extraction, which is then passed onto the J1708Parser to get standard and metric values
 /// </summary>
 /// <param name="rawMessage"></param>
 /// <param name="e"></param>
 private void ProcessJ1708Data(string rawMessage, VMSCommDataEventArgs e)
 {
     try
     {
         var canMessage = new J1708Message(rawMessage, e.timeStamp);
         if (canMessage.IsValidMessage())
         {
             canMessage.ExtractMessage();
             _J1708Parser.Parse(canMessage);
             PublishNewDataEvent(canMessage);
         }
         else
         {
         }
     }
     catch (Exception ex)
     {   //Todo - trim this down to only invoke CommDataErrorEvent on specific exceptions (ie, from CanMesssage or parser)
         RaiseVMSEvent?.Invoke(this, new VMSCommDataErrorEventArgs(e, MessageError.UnrecognizedMessage, ex));
         ErrorLogger.GenerateErrorRecord(ex);
     }
 }
        public void ConsumeEvent(VMSEventArgs e)
        {
            var message = (e as VMSPidValueEventArgs);

            switch (message.segment.Pid)
            {
            case 190:
                CurrentRPMs = message.segment.RawValue;
                break;

            case 92:
                CurrentLoadPercent = message.segment.StandardValue;
                break;
            }
            if (!double.IsNaN(CurrentRPMs) && !double.IsNaN(CurrentLoadPercent))
            {
                var HP            = EngineSpec.CalculateHorsepower(CurrentRPMs, CurrentLoadPercent);
                var Torque        = EngineSpec.CalculateTorque(CurrentRPMs, CurrentLoadPercent);
                var torqueSegment = message.segment.DeepCopy();
                torqueSegment.Pid           = 510;
                torqueSegment.StandardValue = Torque;
                var hpSegment = message.segment.DeepCopy();
                hpSegment.Pid           = 509;
                hpSegment.StandardValue = HP;
                RaiseVMSEvent?.Invoke(this, new VMSParsedDataEventArgs(510, torqueSegment));
                RaiseVMSEvent?.Invoke(this, new VMSParsedDataEventArgs(509, hpSegment));

                /*
                 * RaiseVMSEvent?.Invoke(this, new VMSPidValueEventArgs(
                 *  (EventIDs.PID_BASE | 510),
                 *  Torque
                 *  ));
                 * RaiseVMSEvent?.Invoke(this, new VMSPidValueEventArgs(
                 *  (EventIDs.PID_BASE | 509),
                 *  HP
                 *  ));
                 */
            }
        }
 private void PublishResetEvent()
 {
     RaiseVMSEvent?.Invoke(this, new VMSEventArgs(EventIDs.GUI_RESET_EVENT));
 }
Exemple #12
0
 protected void PublishEvent(VMSEventArgs e)
 {
     RaiseVMSEvent?.Invoke(this, e);
 }
Exemple #13
0
 protected virtual void OnRaiseCustomEvent(AlarmEventArgs e)
 {
     RaiseVMSEvent?.Invoke(this, e);
 }
 public void PublishEvent(DiagnosticMessage message)
 {
     RaiseVMSEvent?.Invoke(this, new DiagnosticEventArgs(message));
 }