Added some implementations from Schema in BluePrints

This commit is contained in:
Christian Risi 2024-11-29 15:22:26 +00:00
parent bb0472911b
commit b21f633bb4
14 changed files with 147 additions and 79 deletions

View File

@ -0,0 +1,31 @@
public class PhysicalEnvironment {
private var physicalEnvironment: [DataType: PhysicalData]
public let location: String
public init(_ location: String) {
self.physicalEnvironment = Dictionary()
self.location = location
}
/// Gets speficied datum from environment
/// - Parameter dataType: Type of data you want to retrieve
/// - Throws: NoPhysicalDataAvailable
/// - Returns: The datum asked for
public func getPhysicalData(_ dataType: DataType) throws -> PhysicalData {
guard let result: PhysicalData = self.physicalEnvironment[dataType] else {
throw CoreError.NoPhysicalDataAvailable(dataType: "\(dataType)")
}
return result
}
public func setPhysicalData(_ dataType: DataType, _ value: PhysicalData) {
self.physicalEnvironment[dataType] = value
}
public func removePhysicalData(_ dataType: DataType) -> PhysicalData? {
return self.physicalEnvironment.removeValue(forKey: dataType)
}
}

View File

@ -0,0 +1,3 @@
public class Message {
}

View File

@ -0,0 +1,13 @@
public class PhysicalData {
public let type: DataType
public let value: Float
public init(_ dataType: DataType, _ value: Float) {
self.type = dataType
self.value = value
}
}

View File

@ -0,0 +1,6 @@
public enum DataType {
case Temperature
case Humidity
case Scan
case Weight
}

View File

@ -0,0 +1,4 @@
public enum DeviceType {
case AsyncEdgeDevice
case EdgeDevice
}

View File

@ -0,0 +1,3 @@
public enum CoreError : Error {
case NoPhysicalDataAvailable( dataType: String)
}

View File

@ -1,3 +0,0 @@
public func sleepAndPrint() async {
}

View File

@ -0,0 +1,11 @@
public protocol EdgeDevice {
var deviceID : String {get}
var deviceType : DeviceType {get}
var dataType : DataType {get}
var disconnected : Bool {get set}
var compromised : Bool {get set}
var dutyCicle : UInt {get set}
func work() -> Message
}