Added some implementations from Schema in BluePrints
This commit is contained in:
parent
bb0472911b
commit
b21f633bb4
@ -1,41 +1,41 @@
|
|||||||
{
|
{
|
||||||
// Displayed name
|
// Displayed name
|
||||||
"name": "IoT-Simulator-Core",
|
"name": "IoT-Simulator-Core",
|
||||||
|
|
||||||
// Image to be used
|
// Image to be used
|
||||||
"image": "swift",
|
"image": "swift",
|
||||||
|
|
||||||
// Customization
|
// Customization
|
||||||
"customizations": {
|
"customizations": {
|
||||||
"vscode": {
|
"vscode": {
|
||||||
"extensions": [
|
"extensions": [
|
||||||
"sswg.swift-lang"
|
"sswg.swift-lang"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// Env in container
|
// Env in container
|
||||||
"containerEnv": {
|
"containerEnv": {
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Mounts in container
|
// Mounts in container
|
||||||
"mounts": [
|
"mounts": [
|
||||||
{
|
{
|
||||||
"source": "${localWorkspaceFolder}",
|
"source": "${localWorkspaceFolder}",
|
||||||
"target": "/workspace",
|
"target": "/workspace",
|
||||||
"type": "bind"
|
"type": "bind"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
||||||
// The WorkspaceFolder inside container
|
// The WorkspaceFolder inside container
|
||||||
"workspaceFolder": "/workspace",
|
"workspaceFolder": "/workspace",
|
||||||
|
|
||||||
// RunArgs
|
// RunArgs
|
||||||
"runArgs": [
|
"runArgs": [
|
||||||
"--name",
|
"--name",
|
||||||
"IoT-Simulator-Core"
|
"IoT-Simulator-Core"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1,26 +1,26 @@
|
|||||||
// swift-tools-version: 6.0
|
// swift-tools-version: 6.0
|
||||||
// The swift-tools-version declares the minimum version of Swift required to build this package.
|
// The swift-tools-version declares the minimum version of Swift required to build this package.
|
||||||
|
|
||||||
import PackageDescription
|
import PackageDescription
|
||||||
|
|
||||||
let package = Package(
|
let package = Package(
|
||||||
name: "IoT-Simulator-Core",
|
name: "IoT-Simulator-Core",
|
||||||
defaultLocalization: LanguageTag(stringLiteral: "en-US"),
|
defaultLocalization: LanguageTag(stringLiteral: "en-US"),
|
||||||
products: [
|
products: [
|
||||||
// Products define the executables and libraries a package produces, making them visible to other packages.
|
// Products define the executables and libraries a package produces, making them visible to other packages.
|
||||||
.library(
|
.library(
|
||||||
name: "IoT-Simulator-Core",
|
name: "IoT-Simulator-Core",
|
||||||
targets: ["IoT-Simulator-Core"])
|
targets: ["IoT-Simulator-Core"])
|
||||||
],
|
],
|
||||||
dependencies: [],
|
dependencies: [],
|
||||||
targets: [
|
targets: [
|
||||||
// Targets are the basic building blocks of a package, defining a module or a test suite.
|
// Targets are the basic building blocks of a package, defining a module or a test suite.
|
||||||
// Targets can depend on other targets in this package and products from dependencies.
|
// Targets can depend on other targets in this package and products from dependencies.
|
||||||
.target(
|
.target(
|
||||||
name: "IoT-Simulator-Core"),
|
name: "IoT-Simulator-Core"),
|
||||||
.testTarget(
|
.testTarget(
|
||||||
name: "IoT-Simulator-CoreTests",
|
name: "IoT-Simulator-CoreTests",
|
||||||
dependencies: ["IoT-Simulator-Core"]
|
dependencies: ["IoT-Simulator-Core"]
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|||||||
@ -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)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
3
Sources/IoT-Simulator-Core/Classes/Utils/Message.swift
Normal file
3
Sources/IoT-Simulator-Core/Classes/Utils/Message.swift
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
public class Message {
|
||||||
|
|
||||||
|
}
|
||||||
13
Sources/IoT-Simulator-Core/Classes/Utils/PhysicalData.swift
Normal file
13
Sources/IoT-Simulator-Core/Classes/Utils/PhysicalData.swift
Normal 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
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
6
Sources/IoT-Simulator-Core/Enums/DataType.swift
Normal file
6
Sources/IoT-Simulator-Core/Enums/DataType.swift
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
public enum DataType {
|
||||||
|
case Temperature
|
||||||
|
case Humidity
|
||||||
|
case Scan
|
||||||
|
case Weight
|
||||||
|
}
|
||||||
4
Sources/IoT-Simulator-Core/Enums/DeviceType.swift
Normal file
4
Sources/IoT-Simulator-Core/Enums/DeviceType.swift
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
public enum DeviceType {
|
||||||
|
case AsyncEdgeDevice
|
||||||
|
case EdgeDevice
|
||||||
|
}
|
||||||
3
Sources/IoT-Simulator-Core/Errors/CoreErrors.swift
Normal file
3
Sources/IoT-Simulator-Core/Errors/CoreErrors.swift
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
public enum CoreError : Error {
|
||||||
|
case NoPhysicalDataAvailable( dataType: String)
|
||||||
|
}
|
||||||
@ -1,3 +0,0 @@
|
|||||||
public func sleepAndPrint() async {
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,2 +1,2 @@
|
|||||||
// The Swift Programming Language
|
// The Swift Programming Language
|
||||||
// https://docs.swift.org/swift-book
|
// https://docs.swift.org/swift-book
|
||||||
|
|||||||
11
Sources/IoT-Simulator-Core/Protocols/EdgeDevice.swift
Normal file
11
Sources/IoT-Simulator-Core/Protocols/EdgeDevice.swift
Normal 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
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,6 +1,6 @@
|
|||||||
import Testing
|
import Testing
|
||||||
@testable import IoT_Simulator_Core
|
@testable import IoT_Simulator_Core
|
||||||
|
|
||||||
@Test func example() async throws {
|
@Test func example() async throws {
|
||||||
// Write your test here and use APIs like `#expect(...)` to check expected conditions.
|
// Write your test here and use APIs like `#expect(...)` to check expected conditions.
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user