예제 #1
0
 /// <summary>
 /// Raises the <see cref="E:DeviceRegistered"/> event.
 /// </summary>
 /// <param name="e">The <see cref="LaJust.PowerMeter.Communications.DeviceRegistrationEventArgs"/> instance containing the event data.</param>
 protected virtual void OnDeviceRegistered(DeviceRegistrationEventData e)
 {
     EventHandler<DeviceRegistrationEventData> handler = DeviceRegistered;
     try
     {
         handler(this, e);
     }
     catch (Exception ex)
     {
         Trace.TraceError("{0}.OnDeviceRegistered: {1}", CLASSNAME, ex.GetBaseException());
     }
 }
예제 #2
0
 /// <summary>
 /// Processes the device registration.
 /// </summary>
 /// <param name="e">The <see cref="LaJust.PowerMeter.Communications.Hardware.DataPacketReceivedEventArgs"/> instance containing the event data.</param>
 private DeviceRegistrationEventData Process_DeviceRegistration(DataPacketReceivedEventArgs e)
 {
     // Parse data packet into registration data structure
     DeviceRegistrationEventData registrationData = new DeviceRegistrationEventData()
     {
         Receiver = this,
         GameNumber = e.DataPacket[(byte)RegistrationDataFields.GameNumber],
         OpCode = (OpCodes)e.DataPacket[(byte)RegistrationDataFields.OpCode],
         CourtNumber = e.DataPacket[(byte)RegistrationDataFields.CourtNumber],
         RegistrationSequence = e.DataPacket[(byte)RegistrationDataFields.RegSequence],
         MinimumPressure = e.DataPacket[(byte)RegistrationDataFields.MinimumPressure],
         TouchSensorMode = (TouchSensorStatusEnum)e.DataPacket[(byte)RegistrationDataFields.TouchSensorMode],
         Id = new DeviceId(
             e.DataPacket[(byte)RegistrationDataFields.Id1],
             e.DataPacket[(byte)RegistrationDataFields.Id2],
             e.DataPacket[(byte)RegistrationDataFields.Id3]
         )
     };
     return registrationData;
 }
예제 #3
0
        /// <summary>
        /// Publishes the device registration.
        /// </summary>
        /// <param name="registrationData">The registration data.</param>
        private void Publish_DeviceRegistration(DeviceRegistrationEventData registrationData)
        {
            Trace.TraceInformation("{0}.Process_DeviceRegistration: OpCode={1} Match={2} Court={3} RegSeq={4} MinPressure={5} Touch={6} Id={7}",
                CLASSNAME, registrationData.OpCode, registrationData.GameNumber, registrationData.CourtNumber,
                registrationData.RegistrationSequence, registrationData.MinimumPressure, registrationData.TouchSensorMode,
                registrationData.Id);

            // Record registration sequence information for later verification
            lock (_deviceRegistrations)
            {
                if (_deviceRegistrations.ContainsKey(registrationData.Id))
                    _deviceRegistrations[registrationData.Id] = registrationData;
                else
                    _deviceRegistrations.Add(registrationData.Id, registrationData);
            }

            // Publish device registration event
            ThreadPool.QueueUserWorkItem(delegate
            {
                OnDeviceRegistered(registrationData);
            });

            #if EIDSS2
            // Keep track of Chung and Hong device Id as V1 (EIDSS 2.0) receiver does not provide them 
            // on data events unlike EIDSS 3.0 which does.
            switch (registrationData.OpCode)
            {
                case OpCodes.ChungRegistered:
                case OpCodes.ChungPreRegistered:
                    if (_HongDeviceId.Equals(registrationData.Id)) _HongDeviceId = new DeviceId();
                    _ChungDeviceId = registrationData.Id;
                    break;

                case OpCodes.HongRegistered:
                case OpCodes.HongPreRegistered:
                    if (_ChungDeviceId.Equals(registrationData.Id)) _ChungDeviceId = new DeviceId();
                    _HongDeviceId = registrationData.Id;
                    break;
            }
            #endif
        }
예제 #4
0
        /// <summary>
        /// Handles the DeviceRegistered event of the Receiver control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="LaJust.PowerMeter.Communications.DeviceRegisteredEventArgs"/> instance containing the event data.</param>
        private void Receiver_DeviceRegistered(object sender, DeviceRegistrationEventData e)
        {
            // Used to keep monitor from going into suspend when we have receiver activity
            Helpers.ActivitySimulator.MoveMouse();

            _logger.Log("Publishing device registration received event to EventAggregator", Category.Info, Priority.Low);
            ReceiverEvents.SensorDeviceType sensorType = ReceiverEvents.SensorDeviceType.Unknown;
            switch (e.OpCode)
            {
                case OpCodes.ChungRegistered: sensorType = ReceiverEvents.SensorDeviceType.Chung; break;
                case OpCodes.HongRegistered: sensorType = ReceiverEvents.SensorDeviceType.Hong; break;
                case OpCodes.TargetRegistered: sensorType = ReceiverEvents.SensorDeviceType.Target; break;
            }
            _eventAggregator.GetEvent<ReceiverEvents.DeviceRegistered>().Publish(new ReceiverEvents.DeviceRegistered()
            { 
                SensorId = e.Id.ToString(),
                SensorType = sensorType
            });
        }