2022-01-24 17:17:06 +01:00
|
|
|
import Foundation
|
|
|
|
|
|
|
|
/**
|
|
|
|
A result from sending a key to the device.
|
|
|
|
*/
|
2022-04-07 23:53:25 +02:00
|
|
|
enum MessageResult: UInt8 {
|
2022-01-24 17:17:06 +01:00
|
|
|
|
|
|
|
/// Text content was received, although binary data was expected
|
|
|
|
case textReceived = 1
|
|
|
|
|
|
|
|
/// A socket event on the device was unexpected (not binary data)
|
|
|
|
case unexpectedSocketEvent = 2
|
|
|
|
|
2022-04-07 23:53:25 +02:00
|
|
|
/// The size of the payload (i.e. message) was invalid, or the data could not be read
|
|
|
|
case invalidMessageData = 3
|
|
|
|
|
|
|
|
/// The transmitted message could not be authenticated using the key
|
|
|
|
case messageAuthenticationFailed = 4
|
2022-01-24 17:17:06 +01:00
|
|
|
|
2022-04-07 23:53:25 +02:00
|
|
|
/// The message time was not within the acceptable bounds
|
|
|
|
case messageTimeMismatch = 5
|
2022-01-24 17:17:06 +01:00
|
|
|
|
|
|
|
/// A later key has been used, invalidating this key (to prevent replay attacks after blocked communication)
|
2022-04-07 23:53:25 +02:00
|
|
|
case messageCounterInvalid = 6
|
2022-01-24 17:17:06 +01:00
|
|
|
|
|
|
|
/// The key was accepted by the device, and the door will be opened
|
2022-04-07 23:53:25 +02:00
|
|
|
case messageAccepted = 7
|
|
|
|
|
|
|
|
|
2022-01-24 17:17:06 +01:00
|
|
|
/// The device produced an unknown error
|
2022-01-29 10:36:49 +01:00
|
|
|
case unknownDeviceError = 9
|
2022-01-24 17:17:06 +01:00
|
|
|
|
|
|
|
/// The request did not contain body data with the key
|
2022-01-29 10:36:49 +01:00
|
|
|
case noBodyData = 10
|
2022-01-24 17:17:06 +01:00
|
|
|
|
|
|
|
/// The body data could not be read
|
2022-01-29 10:36:49 +01:00
|
|
|
case corruptkeyData = 11
|
2022-01-24 17:17:06 +01:00
|
|
|
|
|
|
|
/// The device is not connected
|
2022-01-29 10:36:49 +01:00
|
|
|
case deviceNotConnected = 12
|
2022-01-29 10:26:30 +01:00
|
|
|
|
|
|
|
/// The device did not respond within the timeout
|
2022-01-29 10:36:49 +01:00
|
|
|
case deviceTimedOut = 13
|
2022-04-07 23:53:25 +02:00
|
|
|
|
|
|
|
/// Another message is being processed by the device
|
|
|
|
case operationInProgress = 14
|
2022-01-29 10:36:49 +01:00
|
|
|
}
|
|
|
|
|
2022-04-07 23:53:25 +02:00
|
|
|
extension MessageResult: CustomStringConvertible {
|
2022-01-29 10:36:49 +01:00
|
|
|
|
|
|
|
var description: String {
|
|
|
|
switch self {
|
|
|
|
case .textReceived:
|
|
|
|
return "The device received unexpected text"
|
|
|
|
case .unexpectedSocketEvent:
|
|
|
|
return "Unexpected socket event for the device"
|
2022-04-07 23:53:25 +02:00
|
|
|
case .invalidMessageData:
|
|
|
|
return "Invalid message data"
|
|
|
|
case .messageAuthenticationFailed:
|
|
|
|
return "Message authentication failed"
|
|
|
|
case .messageTimeMismatch:
|
|
|
|
return "Message time invalid"
|
|
|
|
case .messageCounterInvalid:
|
|
|
|
return "Message counter invalid"
|
|
|
|
case .messageAccepted:
|
|
|
|
return "Message accepted"
|
2022-01-29 10:36:49 +01:00
|
|
|
case .unknownDeviceError:
|
|
|
|
return "The device experienced an unknown error"
|
2022-04-07 23:53:25 +02:00
|
|
|
case .noBodyData:
|
|
|
|
return "No body data included in the request"
|
|
|
|
case .corruptkeyData:
|
|
|
|
return "Key data corrupted"
|
|
|
|
case .deviceNotConnected:
|
|
|
|
return "Device not connected"
|
2022-01-29 10:36:49 +01:00
|
|
|
case .deviceTimedOut:
|
|
|
|
return "The device did not respond"
|
2022-04-07 23:53:25 +02:00
|
|
|
case .operationInProgress:
|
|
|
|
return "Another operation is in progress"
|
2022-01-29 10:36:49 +01:00
|
|
|
}
|
|
|
|
}
|
2022-01-24 17:17:06 +01:00
|
|
|
}
|