/// <summary> /// Handle a 'Remove allowed device' response. /// </summary> /// <param name="packet">The packet to check.</param> private void HandleRemoveAllowedResponse(CommandData packet) { try { Beacon receivedBeacon = RiderIDCommandDataParser.ParseAllowedDeviceOperationResponse(packet.Status, packet.Data); if (packet.Status == 0) { this.knownRiders.RemoveAll(rid => rid.Beacon.Equals(receivedBeacon)); } else { Log.Warn("Failure while removing rider"); } } catch (Exception ex) { Log.Error($"Received bad response for {packet.CommandType} command", ex); } }
/// <summary> /// Handle a 'Add allowed device' response. /// </summary> /// <param name="packet">The packet to check.</param> private void HandleAddAllowedResponse(CommandData packet) { try { Beacon receivedBeacon = RiderIDCommandDataParser.ParseAllowedDeviceOperationResponse(packet.Status, packet.Data); if (packet.Status == 0) { if (this.knownRiders.Any(rid => rid.Beacon.Equals(receivedBeacon))) { Log.Info($"Successfully added rider {this.knownRiders.First(rid => rid.Beacon.Equals(receivedBeacon)).Name} with beacon {receivedBeacon}"); } } else { Log.Warn("Failure while adding rider"); } } catch (Exception ex) { Log.Error($"Received bad response for {packet.CommandType} command", ex); } }
/// <summary> /// Handle a 'List all allowed devices' response. /// </summary> /// <param name="packet">The packet to check.</param> private void HandleListAllowedDevices(CommandData packet) { try { if ((packet.Status == 1) && (packet.Data.Length > 2)) { byte[] beaconData = new byte[packet.Data.Length - 2]; packet.Data.CopyTo(beaconData, 2); this.foundBeacons.AddRange(RiderIDCommandDataParser.ParseClosestDeviceResponse(0, beaconData)); if (packet.Data[0] == (packet.Data[1] - 1)) { foreach (Beacon b in this.foundBeacons) { this.commandQueue.Enqueue(this.GenerateRemoveRiderCommand(b)); } } } } catch (Exception ex) { Log.Error($"Received bad response for {packet.CommandType} command", ex); } }