|
|
|
|
@@ -13,6 +13,30 @@ public struct Message : MessageP{
|
|
|
|
|
public let location: Location
|
|
|
|
|
public let fields: [Field]
|
|
|
|
|
|
|
|
|
|
public init(
|
|
|
|
|
|
|
|
|
|
version: UInt8,
|
|
|
|
|
messageType: MessageType,
|
|
|
|
|
devType: DeviceType,
|
|
|
|
|
RESERVED: UInt8,
|
|
|
|
|
signType: SignType,
|
|
|
|
|
timestamp: Date,
|
|
|
|
|
devID: UInt128,
|
|
|
|
|
location: Location,
|
|
|
|
|
fields: [Field]
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
|
|
self.version = version
|
|
|
|
|
self.messageType = messageType
|
|
|
|
|
self.devType = devType
|
|
|
|
|
self.RESERVED = RESERVED
|
|
|
|
|
self.signType = signType
|
|
|
|
|
self.timestamp = timestamp
|
|
|
|
|
self.devID = devID
|
|
|
|
|
self.location = location
|
|
|
|
|
self.fields = fields
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public func toString() -> String {
|
|
|
|
|
var description = ""
|
|
|
|
|
@@ -24,16 +48,17 @@ public struct Message : MessageP{
|
|
|
|
|
description += "Signature Type: \t\(self.signType.rawValue)\n"
|
|
|
|
|
description += "Timestamp: \t\(self.timestamp)\n"
|
|
|
|
|
description += "Device ID: \t\(self.devID)\n"
|
|
|
|
|
description += "Location: \tX: \(self.location.x)\tY: \(self.location.y)\tZ: \(self.location.z)\n"
|
|
|
|
|
description +=
|
|
|
|
|
"Location: \tX: \(self.location.x)\tY: \(self.location.y)\tZ: \(self.location.z)\n"
|
|
|
|
|
description += "Fields: \n"
|
|
|
|
|
for field in self.fields {
|
|
|
|
|
description += "\t\(String(data: Data(field.key), encoding: .ascii) ?? "UNABLE TO DECODE"): \(String(data: Data(field.value), encoding: .ascii) ?? "UNABLE TO DECODE")\n"
|
|
|
|
|
description +=
|
|
|
|
|
"\t\(String(data: Data(field.key), encoding: .ascii) ?? "UNABLE TO DECODE"): \(String(data: Data(field.value), encoding: .ascii) ?? "UNABLE TO DECODE")\n"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return description
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public struct SignedMessage: MessageP {
|
|
|
|
|
|
|
|
|
|
public let version: UInt8
|
|
|
|
|
@@ -48,7 +73,6 @@ public struct SignedMessage : MessageP {
|
|
|
|
|
public let fields: [Field]
|
|
|
|
|
public let signature: [UInt8]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public func toString() -> String {
|
|
|
|
|
var description = ""
|
|
|
|
|
description += "MESSAGE -------\n"
|
|
|
|
|
@@ -59,10 +83,12 @@ public struct SignedMessage : MessageP {
|
|
|
|
|
description += "Signature Type: \t\(self.signType.rawValue)\n"
|
|
|
|
|
description += "Timestamp: \t\(self.timestamp)\n"
|
|
|
|
|
description += "Device ID: \t\(self.devID)\n"
|
|
|
|
|
description += "Location: \tX: \(self.location.x)\tY: \(self.location.y)\tZ: \(self.location.z)\n"
|
|
|
|
|
description +=
|
|
|
|
|
"Location: \tX: \(self.location.x)\tY: \(self.location.y)\tZ: \(self.location.z)\n"
|
|
|
|
|
description += "Fields: \n"
|
|
|
|
|
for field in self.fields {
|
|
|
|
|
description += "\t\(String(data: Data(field.key), encoding: .ascii) ?? "UNABLE TO DECODE"): \(String(data: Data(field.value), encoding: .ascii) ?? "UNABLE TO DECODE")\n"
|
|
|
|
|
description +=
|
|
|
|
|
"\t\(String(data: Data(field.key), encoding: .ascii) ?? "UNABLE TO DECODE"): \(String(data: Data(field.value), encoding: .ascii) ?? "UNABLE TO DECODE")\n"
|
|
|
|
|
}
|
|
|
|
|
description += "Signature: \t\(self.signature)\n"
|
|
|
|
|
|
|
|
|
|
|