71 lines
2.7 KiB
Swift
71 lines
2.7 KiB
Swift
import Foundation
|
|
|
|
public struct Message : MessageP{
|
|
|
|
public let version: UInt8
|
|
public let messageType: MessageType
|
|
public let devType: DeviceType
|
|
public let RESERVED: UInt8
|
|
public let signType: SignType
|
|
|
|
public let timestamp : Date
|
|
public let devID : UInt128
|
|
public let location: Location
|
|
public let fields: [Field]
|
|
|
|
|
|
public func toString() -> String{
|
|
var description = ""
|
|
description += "MESSAGE -------\n"
|
|
description += "V: \t\(self.version)\n"
|
|
description += "Message Type: \t\(self.messageType.rawValue)\n"
|
|
description += "Device Type: \t\(self.devType.rawValue)\n"
|
|
description += "RESERVED: \t\(self.RESERVED)\n"
|
|
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 += "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"
|
|
}
|
|
|
|
return description
|
|
}
|
|
}
|
|
|
|
public struct SignedMessage : MessageP {
|
|
|
|
public let version: UInt8
|
|
public let messageType: MessageType
|
|
public let devType: DeviceType
|
|
public let RESERVED: UInt8
|
|
public let signType: SignType
|
|
|
|
public let timestamp : Date
|
|
public let devID : UInt128
|
|
public let location: Location
|
|
public let fields: [Field]
|
|
public let signature: [UInt8]
|
|
|
|
|
|
public func toString() -> String{
|
|
var description = ""
|
|
description += "MESSAGE -------\n"
|
|
description += "V: \t\(self.version)\n"
|
|
description += "Message Type: \t\(self.messageType.rawValue)\n"
|
|
description += "Device Type: \t\(self.devType.rawValue)\n"
|
|
description += "RESERVED: \t\(self.RESERVED)\n"
|
|
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 += "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 += "Signature: \t\(self.signature)\n"
|
|
|
|
return description
|
|
}
|
|
} |