V0.7.2 Arroyo Toad
Revised the creation of devices a bit
This commit is contained in:
parent
569b29c815
commit
d8df743c58
@ -4,14 +4,17 @@ import MessageUtils
|
||||
public actor DeviceFactory {
|
||||
|
||||
private static var setted: Bool = false
|
||||
// TODO: Make it possible to set this
|
||||
private static var availableIDs: Set<UInt128> = Set(0..<999)
|
||||
|
||||
|
||||
public static func createEdgeDevice(
|
||||
deviceID: UInt128,
|
||||
dataType: DataType,
|
||||
privateKey: P256.Signing.PrivateKey
|
||||
) throws -> EdgeDevice{
|
||||
return try DeviceFactory.createEdgeDevice(
|
||||
deviceID: deviceID
|
||||
dataType: dataType,
|
||||
privateKey: privateKey,
|
||||
realSensor: false
|
||||
@ -19,11 +22,11 @@ public actor DeviceFactory {
|
||||
}
|
||||
|
||||
public static func createEdgeDevice(
|
||||
deviceID: UInt128,
|
||||
dataType: DataType,
|
||||
privateKey: P256.Signing.PrivateKey,
|
||||
realSensor: Bool
|
||||
) throws -> EdgeDevice{
|
||||
let deviceID = try DeviceFactory.getUnusedID()
|
||||
|
||||
return try DeviceFactory.createEdgeDevice(
|
||||
deviceID: deviceID,
|
||||
@ -81,7 +84,9 @@ public actor DeviceFactory {
|
||||
privateKey: privateKey)
|
||||
}
|
||||
|
||||
private static func getUnusedID() throws -> UInt128 {
|
||||
public static func getUnusedID() throws -> UInt128 {
|
||||
|
||||
DeviceFactory.setted = true
|
||||
|
||||
if DeviceFactory.availableIDs.count < 1 {
|
||||
throw CoreError.FinishedIDs
|
||||
|
||||
@ -5,10 +5,10 @@ import Foundation
|
||||
|
||||
public actor IoTSimulatorCore {
|
||||
|
||||
private static var enviroments: [String: PhysicalEnvironment] = Dictionary()
|
||||
private static var devices: [String: EdgeDeviceP] = Dictionary()
|
||||
private static var env_dev: [String: Set<UInt128>] = Dictionary()
|
||||
private static var dev_tasks: [String: Task<(), Never>] = Dictionary()
|
||||
internal static var enviroments: [String: PhysicalEnvironment] = Dictionary()
|
||||
internal static var devices: [String: EdgeDeviceP] = Dictionary()
|
||||
internal static var env_dev: [String: Set<String>] = Dictionary()
|
||||
internal static var dev_tasks: [String: Task<(), Never>] = Dictionary()
|
||||
|
||||
public static func addEnv(environment: PhysicalEnvironment) {
|
||||
IoTSimulatorCore.enviroments[environment.location] = environment
|
||||
@ -27,7 +27,7 @@ public actor IoTSimulatorCore {
|
||||
IoTSimulatorCore.env_dev[location] = Set()
|
||||
}
|
||||
|
||||
IoTSimulatorCore.env_dev[location]!.insert(device.deviceID)
|
||||
IoTSimulatorCore.env_dev[location]!.insert("\(device.deviceID)")
|
||||
|
||||
// schedule work
|
||||
let task = IoTSimulatorCore.schedule(
|
||||
@ -102,14 +102,14 @@ public actor IoTSimulatorCore {
|
||||
deviceID: UInt128,
|
||||
success: sending @escaping (_ msg: Data) throws -> Void,
|
||||
failure: sending @escaping () -> Void
|
||||
) -> Task<(), Never> {
|
||||
) -> Task<(), Never>{
|
||||
let _devID: String = "\(deviceID)"
|
||||
return Task {
|
||||
|
||||
var notCancelled: Bool = true
|
||||
|
||||
let dev = IoTSimulatorCore.getDev(devID: _devID)!
|
||||
let env = IoTSimulatorCore.getEnv(name: envID)!
|
||||
let dev = IoTSimulatorCore.devices["\(_devID)"]!
|
||||
let env = IoTSimulatorCore.enviroments[envID]!
|
||||
|
||||
while notCancelled {
|
||||
print("Device: \(dev.deviceID)")
|
||||
@ -125,13 +125,12 @@ public actor IoTSimulatorCore {
|
||||
try await Task.sleep(nanoseconds: UInt64(dev.dutyCicle) * UInt64(1E6))
|
||||
} catch {
|
||||
notCancelled = false
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
print("Bye, Bye, \(dev.deviceID)\n\n")
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -81,7 +81,7 @@ import MessageUtils
|
||||
|
||||
@Test func stressLoop1() async throws {
|
||||
|
||||
let devices: UInt128 = 500
|
||||
let devices: UInt128 = 5000
|
||||
|
||||
let env = PhysicalEnvironment("Delta")
|
||||
let truth = PhysicalData(.Temperature, 22)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user