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