Exemple #1
0
        /// <summary>
        /// Processes the strike received for version 1 receiver (EIDSS 2.0)
        /// </summary>
        /// <param name="e">The <see cref="LaJust.PowerMeter.Communications.Hardware.DataPacketReceivedEventArgs"/> instance containing the event data.</param>
        #if EIDSS2
        private DeviceEventData Process_HoguDataReceivedV1(DataPacketReceivedEventArgs e)
        {
            // Generate acknowledgement packet and send to receiver
            _recvrComm.SendDataPacket(new byte[3] {
                e.DataPacket[(byte)HoguDataFieldsV1.GameNumber], 
                (byte)OpCodeCmds.Acknowledgement, 
                e.DataPacket[(byte)HoguDataFieldsV1.SequenceNumber] });

            // Parse data packet
            DeviceEventData deviceData = new DeviceEventData()
            {
                Receiver = this,
                GameNumber = e.DataPacket[(byte)HoguDataFieldsV1.GameNumber],
                OpCode = (OpCodes)e.DataPacket[(byte)HoguDataFieldsV1.OpCode],
                RegSequence = e.DataPacket[(byte)HoguDataFieldsV1.RegSequence],
                VestHitValue = e.DataPacket[(byte)HoguDataFieldsV1.VestHitValue],
                HeadHitValue = e.DataPacket[(byte)HoguDataFieldsV1.HeadHitValue],
                TouchStatus = (TouchSensorStatusEnum)e.DataPacket[(byte)HoguDataFieldsV1.TouchStatus],
                DeviceStatus = (DeviceStatusEnum)e.DataPacket[(byte)HoguDataFieldsV1.HoguStatus],
                SequenceNumber = e.DataPacket[(byte)HoguDataFieldsV1.SequenceNumber]
            };

            // Insert device Id information we stored during registration as V1 data packet does not include it
            switch (deviceData.OpCode)
            {
                case OpCodes.ChungDataV1: deviceData.DeviceId = _ChungDeviceId; break;
                case OpCodes.HongDataV1: deviceData.DeviceId = _HongDeviceId; break;
            }

            return deviceData;
        }
Exemple #2
0
        /// <summary>
        /// Processes the strike received for V2 receiver (EIDSS 3.0)
        /// </summary>
        /// <param name="e">The <see cref="LaJust.PowerMeter.Communications.Hardware.DataPacketReceivedEventArgs"/> instance containing the event data.</param>
        private DeviceEventData Process_HoguDataReceivedV2(DataPacketReceivedEventArgs e)
        {
            // Generate acknowledgement packet and send to receiver
            _recvrComm.SendDataPacket(new byte[3] {
                e.DataPacket[(byte)HoguDataFieldsV2.GameNumber], 
                (byte)OpCodeCmds.Acknowledgement, 
                e.DataPacket[(byte)HoguDataFieldsV2.SequenceNumber] });

            // Parse data packet
            DeviceEventData deviceData = new DeviceEventData()
            {
                Receiver = this,
                GameNumber = e.DataPacket[(byte)HoguDataFieldsV2.GameNumber],
                OpCode = (OpCodes)e.DataPacket[(byte)HoguDataFieldsV2.OpCode],
                RegSequence = e.DataPacket[(byte)HoguDataFieldsV2.RegSequence],
                VestHitValue = e.DataPacket[(byte)HoguDataFieldsV2.VestHitValue],
                HeadHitValue = e.DataPacket[(byte)HoguDataFieldsV2.HeadHitValue],
                TouchStatus = (TouchSensorStatusEnum)e.DataPacket[(byte)HoguDataFieldsV2.TouchStatus],
                DeviceStatus = (DeviceStatusEnum)e.DataPacket[(byte)HoguDataFieldsV2.HoguStatus],
                DeviceId = new DeviceId(
                    e.DataPacket[(byte)HoguDataFieldsV2.ID1],
                    e.DataPacket[(byte)HoguDataFieldsV2.ID2],
                    e.DataPacket[(byte)HoguDataFieldsV2.ID3]
                ),
                SequenceNumber = e.DataPacket[(byte)HoguDataFieldsV2.SequenceNumber]
            };

            return deviceData;
        }
Exemple #3
0
 /// <summary>
 /// Notifies the specified data.
 /// </summary>
 /// <param name="data">The data.</param>
 public void Notify(DeviceEventData data)
 {
     DeviceEventObservers.ForEach(o =>
     {
         o.NotifyAsync(data);
     });
 }
Exemple #4
0
 public static DeviceEventModel Map(DeviceEventData deviceEvent)
 {
     return(new DeviceEventModel
     {
         Id = deviceEvent.Id,
         DeviceId = deviceEvent.DeviceId,
         Time = deviceEvent.Time,
         Type = deviceEvent.Type,
         Message = deviceEvent.Message
     });
 }
Exemple #5
0
 /// <summary>
 /// Raises the <see cref="E:HitReceived"/> event.
 /// </summary>
 /// <param name="e">The <see cref="LaJust.PowerMeter.Communications.HitReceivedEventArgs"/> instance containing the event data.</param>
 protected virtual void OnStrikeDetected(DeviceEventData e)
 {
     EventHandler<DeviceEventData> handler = StrikeDetected;
     try
     {
         handler(this, e);
     }
     catch (Exception ex)
     {
         Trace.TraceError("{0}.OnStrikeDetected: {1}", CLASSNAME, ex.GetBaseException());
     }
 }
Exemple #6
0
        /// <summary>
        /// Map to DeviceLog object.
        /// </summary>
        /// <param name="deviceLogSerializer">device event data</param>
        /// <returns>Device log</returns>
        public static DeviceEvent Map(DeviceEventData deviceLogSerializer)
        {
            var deviceLog = new DeviceEvent
            {
                Changes         = deviceLogSerializer.Changes,
                Data            = deviceLogSerializer.Data,
                EventDate       = deviceLogSerializer.DateTime.ToNullableUniversalTime(),
                Description     = deviceLogSerializer.Description,
                DeviceId        = deviceLogSerializer.DeviceId,
                Id              = deviceLogSerializer.Id,
                TypeDescription = deviceLogSerializer.EventTypeDescription,
                StateChanged    = deviceLogSerializer.StateChange,
                Type            = deviceLogSerializer.EventType,
            };

            return(deviceLog);
        }
Exemple #7
0
        /// <summary>
        /// Publish the event data.
        /// </summary>
        /// <param name="eventData">The event data.</param>
        private void Publish_EventData(DeviceEventData deviceData)
        {
            // Check for duplicate packet
            if (deviceData.SequenceNumber == _lastSeqNumber)
                return;
            else
                _lastSeqNumber = deviceData.SequenceNumber;

            // Validate known device Id
            if ( !deviceData.DeviceId.IsValid() ||  !_deviceRegistrations.ContainsKey(deviceData.DeviceId) )
            {
                Trace.TraceWarning("{0}.Process_EventData: Unknown device id. ID={1}", CLASSNAME, deviceData.DeviceId);
                return;
            }

            // Validate registration sequence
            if (_deviceRegistrations[deviceData.DeviceId].RegistrationSequence != deviceData.RegSequence)
            {
                Trace.TraceWarning("{0}.Process_EventData: Incorrect registration sequence. ID={1} Expected={2} Actual={3}", CLASSNAME, deviceData.DeviceId, _deviceRegistrations[deviceData.DeviceId], deviceData.RegSequence);
                return;
            }

            // Trace/Debug Information
            if (Trace.Listeners.Count > 0) // Optimization for no listeners
                Trace.TraceInformation("{0}.Process_EventData: OpCode={1} Match={2} RegSeq={3} VestHit={4} HeadHit={5} Touch={6} Status={7} Id={8} TgtNum={9} TgtTot={10} Panel={11} Seq={12}", CLASSNAME,
                    deviceData.OpCode, deviceData.GameNumber, deviceData.RegSequence, deviceData.VestHitValue, 
                    deviceData.HeadHitValue, deviceData.TouchStatus, deviceData.DeviceStatus, deviceData.DeviceId, 
                    deviceData.TargetNumber, deviceData.TargetTotal, deviceData.WetBagPanel, deviceData.SequenceNumber);

            // Send device status update event
            ThreadPool.QueueUserWorkItem(delegate
            {
                OnDeviceStatusUpdate(new DeviceStatusEventData() { Receiver = this, DeviceId = deviceData.DeviceId, DeviceStatus = deviceData.DeviceStatus });
            });

            // If the pressure of head or vest is greater than zero send a strike impact event
            if (deviceData.HeadHitValue > 0 || deviceData.VestHitValue > 0)
            {
                ThreadPool.QueueUserWorkItem(delegate
                {
                    OnStrikeDetected(deviceData);
                });
            }
        }
Exemple #8
0
        /// <summary>
        /// Handles the StrikeDetected event of the Receiver control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="LaJust.PowerMeter.Communications.StrikeDetectedEventArgs"/> instance containing the event data.</param>
        private void Receiver_StrikeDetected(object sender, DeviceEventData e)
        {
            // Used to keep monitor from going into suspend when we have receiver activity
            Helpers.ActivitySimulator.MoveMouse();

            _logger.Log("Publishing strike received event #" + e.SequenceNumber + " to EventAggregator", Category.Info, Priority.Low);

            byte impactLevel = Math.Max(e.VestHitValue, e.HeadHitValue);

            // FIXME: Temporary code to software patch sensor issue 12/19/09
            //if (e.WetBagPanel == WetBagPanelEnum.BottomMiddle) impactLevel = (byte)((double)impactLevel * 1.20);

            _eventAggregator.GetEvent <ReceiverEvents.SensorHit>().Publish(new ReceiverEvents.SensorHit()
            {
                SensorId    = e.DeviceId.ToString(),
                OpCode      = e.OpCode.ToString(),
                ImpactLevel = impactLevel,
                Panel       = (ReceiverEvents.SensorPanel)Enum.Parse(typeof(ReceiverEvents.SensorPanel), e.WetBagPanel.ToString(), true)
            });
        }
        public async Task AddEvent(DeviceEventData deviceEvent, CancellationToken token)
        {
            var url = $"{_endpoints.Host}{_endpoints.AddEvent}";

            var bearer = await GetBearerToken();

            var messageResponse = await NetHelper.PostAsync(_client, url, bearer, deviceEvent, token);

            if (!messageResponse.IsSuccessStatusCode)
            {
                if (messageResponse.StatusCode == HttpStatusCode.Unauthorized)
                {
                    throw new ControlApiException(await messageResponse.ContentAsStringAsync(), ErrorCode.Unauthorized);
                }

                throw await messageResponse.ReadErrorAsync();
            }

            var addedEvent = await messageResponse.ContentAsAsync <DeviceEventData>();

            deviceEvent.Id = addedEvent.Id;
        }
 private static void updateClient(Object stateinfo)
 {
     try
     {
         if (theClient != null)
         {
             Console.WriteLine("Updating Client {0}", clientId);
             DeviceEventData eventData = new DeviceEventData();
             eventData.message = "Test Data";
             eventData.timestamp = DateTime.Now;
             theClient.SendDeviceEventData(eventData);
         }
     }
     catch (CommunicationException ex)
     {
         //client error so dispose of client
         Console.WriteLine("Client Error: {0}", ex.Message);
         Console.WriteLine("Closing connection to client {0}", clientId);
         theClient = null;
         clientId = String.Empty;
     }
 }
Exemple #11
0
        /// <summary>
        /// Processes the strike received for V2 receiver (EIDSS 3.0)
        /// </summary>
        /// <param name="e">The <see cref="LaJust.PowerMeter.Communications.Hardware.DataPacketReceivedEventArgs"/> instance containing the event data.</param>
        private DeviceEventData Process_TargetDataReceivedV2(DataPacketReceivedEventArgs e)
        {
            // Generate acknowledgement packet and send to receiver
            _recvrComm.SendDataPacket(new byte[3] {
                e.DataPacket[(int)TargetDataFieldsV2.GameNumber], 
                (byte)OpCodeCmds.Acknowledgement, 
                e.DataPacket[(int)TargetDataFieldsV2.SequenceNumber] });

            // Parse data packet
            DeviceEventData deviceData = new DeviceEventData()
            {
                Receiver = this,
                GameNumber = e.DataPacket[(byte)TargetDataFieldsV2.GameNumber],
                OpCode = (OpCodes)e.DataPacket[(byte)TargetDataFieldsV2.OpCode],
                RegSequence = e.DataPacket[(byte)TargetDataFieldsV2.RegSequence],
                VestHitValue = e.DataPacket[(byte)TargetDataFieldsV2.VestHitValue],
                HeadHitValue = e.DataPacket[(byte)TargetDataFieldsV2.HeadHitValue],
                // Remove "touch sensor" bit from wet bag panel byte by AND with 0x77 (0111 0111)
                WetBagPanel = (WetBagPanelEnum)(e.DataPacket[(byte)TargetDataFieldsV2.PanelValue] & 0x77),
                // Determine "touch sensor" bit from wet bag panel byte by checking 0x08 or 0x80 bits
                TouchStatus = (((e.DataPacket[(byte)TargetDataFieldsV2.PanelValue] & 0x08) == 0x08) || 
                               ((e.DataPacket[(byte)TargetDataFieldsV2.PanelValue] & 0x80) == 0x80)) ? 
                               TouchSensorStatusEnum.Required : TouchSensorStatusEnum.NotRequired,
                DeviceStatus = (DeviceStatusEnum)e.DataPacket[(byte)TargetDataFieldsV2.HoguStatus],
                DeviceId = new DeviceId(
                    e.DataPacket[(byte)TargetDataFieldsV2.ID1],
                    e.DataPacket[(byte)TargetDataFieldsV2.ID2],
                    e.DataPacket[(byte)TargetDataFieldsV2.ID3]
                ),
                SequenceNumber = e.DataPacket[(byte)TargetDataFieldsV2.SequenceNumber],
                TargetNumber = e.DataPacket[(byte)TargetDataFieldsV2.TargetNumber],
                TargetTotal = e.DataPacket[(byte)TargetDataFieldsV2.TargetTotal]
            };

            return deviceData;
        }