private HardwareConfiguration(string data) { var subcode = data.Substring(0, 2); if (subcode != "HG") { throw new InvalidDataException( string.Format("Expected sub-code of \"{0}\" but got \"{1}\".", "HG", subcode)); } if (!int.TryParse(data.Substring(2, 5), NumberStyles.None, CultureInfo.InvariantCulture, out _firmwareVersion)) { throw new InvalidDataException("Couldn't parse firmware version from hardware configuration data."); } if (!DateTime.TryParseExact(data.Substring(8, 10), "dd.MM.yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out _firmwareDate)) { throw new InvalidDataException("Couldn't parse firmware date from hardware configuration data."); } // TODO: what does 18 represent? _terminalType = (TerminalTypes)data[19]; _keyboardType = (KeyboardTypes)data[20]; _displayType = (DisplayTypes)data[21]; _hostSerialParameters = data.Substring(22, 3); byte b; if (!byte.TryParse(data.Substring(25, 1), NumberStyles.None, CultureInfo.InvariantCulture, out b)) { throw new InvalidDataException("Couldn't parse host serial baud rate from hardware configuration data."); } _hostSerialBaudRate = BaudRates.Get(b); _terminalId = Util.CharToTerminalId(data[26]); // TODO: what does 27 represent? Maybe the network card type? if (!byte.TryParse(data.Substring(28, 1), NumberStyles.None, CultureInfo.InvariantCulture, out _fingerprintUnitType)) { throw new InvalidDataException("Couldn't parse fingerprint unit type from hardware configuration data."); } _fingerprintUnitMode = (FingerprintUnitModes)data[29]; if (!int.TryParse(data.Substring(30, 4), NumberStyles.None, CultureInfo.InvariantCulture, out _userDefinedField)) { throw new InvalidDataException("Couldn't parse user defined field from hardware configuration data."); } }
private FingerprintUnitStatus(string data) { var subcode = data.Substring(0, 2); if (subcode != "M0") { throw new InvalidDataException( string.Format("Expected sub-code of \"{0}\" but got \"{1}\".", "MO", subcode)); } _comparisonMode = (FingerprintComparisonModes)data[2]; _kernelVersion = data.Substring(3, 12); if (!int.TryParse(data.Substring(15, 5), NumberStyles.None, CultureInfo.InvariantCulture, out _loadedTemplates)) { throw new InvalidDataException("Couldn't parse number of templates loaded from fingerprint status data."); } // character 20 is a hardcoded slash that we can ignore if (!int.TryParse(data.Substring(21, 5), NumberStyles.None, CultureInfo.InvariantCulture, out _maximumTemplates)) { throw new InvalidDataException("Couldn't parse maximum number of templates from fingerprint status data."); } _fingerprintUnitMode = (FingerprintUnitModes)data[26]; byte b; if (!byte.TryParse(data.Substring(27, 1), NumberStyles.None, CultureInfo.InvariantCulture, out b)) { throw new InvalidDataException("Couldn't parse global threshold from fingerprint status data."); } if (b < 1 || b > 5) { throw new InvalidDataException("Fingerprint Global Threshold should be between 1 and 5."); } _globalThreshold = (FingerprintThreshold)b; _enrollMode = (FingerprintEnrollModes)data[28]; }
/// <summary> /// Returns an awaitable task that sets the fingerprint unit mode on the terminal. /// </summary> /// <param name="mode">The fingerprint unit mode.</param> public async Task SetUnitModeAsync(FingerprintUnitModes mode) { string val; switch (mode) { case FingerprintUnitModes.Master: val = "MASTERMODE"; break; case FingerprintUnitModes.Slave: val = "SLAVE-MODE"; break; default: throw new ArgumentException("Invalid FPU mode.", "mode"); } var data = string.Format("H0F{0}", val); await _client.SendAndReceiveAsync(RequestCommand.Fingerprint, data, ACK); }
private HardwareConfiguration(string data) { var subcode = data.Substring(0, 2); if (subcode != "HG") throw new InvalidDataException( string.Format("Expected sub-code of \"{0}\" but got \"{1}\".", "HG", subcode)); if (!int.TryParse(data.Substring(2, 5), NumberStyles.None, CultureInfo.InvariantCulture, out _firmwareVersion)) throw new InvalidDataException("Couldn't parse firmware version from hardware configuration data."); if (!DateTime.TryParseExact(data.Substring(8, 10), "dd.MM.yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out _firmwareDate)) throw new InvalidDataException("Couldn't parse firmware date from hardware configuration data."); // TODO: what does 18 represent? _terminalType = (TerminalTypes)data[19]; _keyboardType = (KeyboardTypes)data[20]; _displayType = (DisplayTypes)data[21]; _hostSerialParameters = data.Substring(22, 3); byte b; if (!byte.TryParse(data.Substring(25, 1), NumberStyles.None, CultureInfo.InvariantCulture, out b)) throw new InvalidDataException("Couldn't parse host serial baud rate from hardware configuration data."); _hostSerialBaudRate = BaudRates.Get(b); _terminalId = Util.CharToTerminalId(data[26]); // TODO: what does 27 represent? Maybe the network card type? if (!byte.TryParse(data.Substring(28, 1), NumberStyles.None, CultureInfo.InvariantCulture, out _fingerprintUnitType)) throw new InvalidDataException("Couldn't parse fingerprint unit type from hardware configuration data."); _fingerprintUnitMode = (FingerprintUnitModes)data[29]; if (!int.TryParse(data.Substring(30, 4), NumberStyles.None, CultureInfo.InvariantCulture, out _userDefinedField)) throw new InvalidDataException("Couldn't parse user defined field from hardware configuration data."); }
private TerminalStatus(string data) { if (!byte.TryParse(data.Substring(0, 1), NumberStyles.None, CultureInfo.InvariantCulture, out _hardwareModel)) throw new InvalidDataException("Couldn't parse hardware model from terminal status data."); if (!byte.TryParse(data.Substring(1, 1), NumberStyles.None, CultureInfo.InvariantCulture, out _hardwareRevision)) throw new InvalidDataException("Couldn't parse hardware revision from terminal status data."); if (!int.TryParse(data.Substring(2, 5), NumberStyles.None, CultureInfo.InvariantCulture, out _firmwareVersion)) throw new InvalidDataException("Couldn't parse firmware version from terminal status data."); if (!DateTime.TryParseExact(data.Substring(7, 10), "yyMMddHHmm", CultureInfo.InvariantCulture, DateTimeStyles.None, out _timestamp)) throw new InvalidDataException("Couldn't parse timestamp from terminal status data."); _activeFunction = data[17]; _buffersFull = SynelNumericFormat.Convert(data.Substring(18, 3)); _buffersFaulty = SynelNumericFormat.Convert(data.Substring(21, 3)); _buffersTransmitted = SynelNumericFormat.Convert(data.Substring(24, 3)); _buffersEmpty = SynelNumericFormat.Convert(data.Substring(27, 3)); if (data[34] == 'K') { int mem; if (!int.TryParse(data.Substring(30, 4), NumberStyles.None, CultureInfo.InvariantCulture, out mem)) throw new InvalidDataException("Couldn't parse memory used from terminal status data."); _memoryUsed = mem * 1024; // assuming 'K' means KiB rather than KB } else { if (!int.TryParse(data.Substring(30, 4), NumberStyles.None, CultureInfo.InvariantCulture, out _memoryUsed)) throw new InvalidDataException("Couldn't parse memory used from terminal status data."); } _terminalType = (TerminalTypes)data[35]; _poweredOn = data[36] == '1'; // TODO: what does 37-38 represent? _userDefinedField = data.Substring(39, 4); _transportType = data[43] == 'T' ? TransportType.Tcp : data[43] == 'U' ? TransportType.Udp : 0; int i; if (!int.TryParse(data.Substring(44, 2), NumberStyles.None, CultureInfo.InvariantCulture, out i)) throw new InvalidDataException("Couldn't parse the polling interval from terminal status data."); _pollingInterval = TimeSpan.FromSeconds(i); _fingerprintUnitMode = (FingerprintUnitModes)data[46]; }
/// <summary> /// Returns an awaitable task that sets the fingerprint unit mode on the terminal. /// </summary> /// <param name="mode">The fingerprint unit mode.</param> public async Task SetUnitModeAsync(FingerprintUnitModes mode) { string val; switch (mode) { case FingerprintUnitModes.Master: val = "MASTERMODE"; break; case FingerprintUnitModes.Slave: val = "SLAVE-MODE"; break; default: throw new ArgumentException("Invalid FPU mode.", "mode"); } var data = string.Format("H0F{0}", val); await _client.SendAndReceiveAsync(RequestCommand.Fingerprint, data, ACK); }
private TerminalStatus(string data) { if (!byte.TryParse(data.Substring(0, 1), NumberStyles.None, CultureInfo.InvariantCulture, out _hardwareModel)) { throw new InvalidDataException("Couldn't parse hardware model from terminal status data."); } if (!byte.TryParse(data.Substring(1, 1), NumberStyles.None, CultureInfo.InvariantCulture, out _hardwareRevision)) { throw new InvalidDataException("Couldn't parse hardware revision from terminal status data."); } if (!int.TryParse(data.Substring(2, 5), NumberStyles.None, CultureInfo.InvariantCulture, out _firmwareVersion)) { throw new InvalidDataException("Couldn't parse firmware version from terminal status data."); } if (!DateTime.TryParseExact(data.Substring(7, 10), "yyMMddHHmm", CultureInfo.InvariantCulture, DateTimeStyles.None, out _timestamp)) { throw new InvalidDataException("Couldn't parse timestamp from terminal status data."); } _activeFunction = data[17]; _buffersFull = SynelNumericFormat.Convert(data.Substring(18, 3)); _buffersFaulty = SynelNumericFormat.Convert(data.Substring(21, 3)); _buffersTransmitted = SynelNumericFormat.Convert(data.Substring(24, 3)); _buffersEmpty = SynelNumericFormat.Convert(data.Substring(27, 3)); if (data[34] == 'K') { int mem; if (!int.TryParse(data.Substring(30, 4), NumberStyles.None, CultureInfo.InvariantCulture, out mem)) { throw new InvalidDataException("Couldn't parse memory used from terminal status data."); } _memoryUsed = mem * 1024; // assuming 'K' means KiB rather than KB } else { if (!int.TryParse(data.Substring(30, 4), NumberStyles.None, CultureInfo.InvariantCulture, out _memoryUsed)) { throw new InvalidDataException("Couldn't parse memory used from terminal status data."); } } _terminalType = (TerminalTypes)data[35]; _poweredOn = data[36] == '1'; // TODO: what does 37-38 represent? _userDefinedField = data.Substring(39, 4); _transportType = data[43] == 'T' ? TransportType.Tcp : data[43] == 'U' ? TransportType.Udp : 0; int i; if (!int.TryParse(data.Substring(44, 2), NumberStyles.None, CultureInfo.InvariantCulture, out i)) { throw new InvalidDataException("Couldn't parse the polling interval from terminal status data."); } _pollingInterval = TimeSpan.FromSeconds(i); _fingerprintUnitMode = (FingerprintUnitModes)data[46]; }
private FingerprintUnitStatus(string data) { var subcode = data.Substring(0, 2); if (subcode != "M0") throw new InvalidDataException( string.Format("Expected sub-code of \"{0}\" but got \"{1}\".", "MO", subcode)); _comparisonMode = (FingerprintComparisonModes)data[2]; _kernelVersion = data.Substring(3, 12); if (!int.TryParse(data.Substring(15, 5), NumberStyles.None, CultureInfo.InvariantCulture, out _loadedTemplates)) throw new InvalidDataException("Couldn't parse number of templates loaded from fingerprint status data."); // character 20 is a hardcoded slash that we can ignore if (!int.TryParse(data.Substring(21, 5), NumberStyles.None, CultureInfo.InvariantCulture, out _maximumTemplates)) throw new InvalidDataException("Couldn't parse maximum number of templates from fingerprint status data."); _fingerprintUnitMode = (FingerprintUnitModes)data[26]; byte b; if (!byte.TryParse(data.Substring(27, 1), NumberStyles.None, CultureInfo.InvariantCulture, out b)) throw new InvalidDataException("Couldn't parse global threshold from fingerprint status data."); if (b < 1 || b > 5) throw new InvalidDataException("Fingerprint Global Threshold should be between 1 and 5."); _globalThreshold = (FingerprintThreshold)b; _enrollMode = (FingerprintEnrollModes) data[28]; }