diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index d27878f..341fe88 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,41 +1,41 @@ -{ - // Displayed name - "name": "IoT-Simulator-Core", - - // Image to be used - "image": "swift", - - // Customization - "customizations": { - "vscode": { - "extensions": [ - "sswg.swift-lang" - ] - } - }, - - // Env in container - "containerEnv": { - - }, - - // Mounts in container - "mounts": [ - { - "source": "${localWorkspaceFolder}", - "target": "/workspace", - "type": "bind" - } - ], - - // The WorkspaceFolder inside container - "workspaceFolder": "/workspace", - - // RunArgs - "runArgs": [ - "--name", - "IoT-Simulator-Core" - ] - - +{ + // Displayed name + "name": "IoT-Simulator-Core", + + // Image to be used + "image": "swift", + + // Customization + "customizations": { + "vscode": { + "extensions": [ + "sswg.swift-lang" + ] + } + }, + + // Env in container + "containerEnv": { + + }, + + // Mounts in container + "mounts": [ + { + "source": "${localWorkspaceFolder}", + "target": "/workspace", + "type": "bind" + } + ], + + // The WorkspaceFolder inside container + "workspaceFolder": "/workspace", + + // RunArgs + "runArgs": [ + "--name", + "IoT-Simulator-Core" + ] + + } \ No newline at end of file diff --git a/Package.swift b/Package.swift index 9165aa5..022c369 100644 --- a/Package.swift +++ b/Package.swift @@ -1,26 +1,26 @@ -// swift-tools-version: 6.0 -// The swift-tools-version declares the minimum version of Swift required to build this package. - -import PackageDescription - -let package = Package( - name: "IoT-Simulator-Core", - defaultLocalization: LanguageTag(stringLiteral: "en-US"), - products: [ - // Products define the executables and libraries a package produces, making them visible to other packages. - .library( - name: "IoT-Simulator-Core", - targets: ["IoT-Simulator-Core"]) - ], - dependencies: [], - targets: [ - // 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. - .target( - name: "IoT-Simulator-Core"), - .testTarget( - name: "IoT-Simulator-CoreTests", - dependencies: ["IoT-Simulator-Core"] - ), - ] -) +// swift-tools-version: 6.0 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "IoT-Simulator-Core", + defaultLocalization: LanguageTag(stringLiteral: "en-US"), + products: [ + // Products define the executables and libraries a package produces, making them visible to other packages. + .library( + name: "IoT-Simulator-Core", + targets: ["IoT-Simulator-Core"]) + ], + dependencies: [], + targets: [ + // 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. + .target( + name: "IoT-Simulator-Core"), + .testTarget( + name: "IoT-Simulator-CoreTests", + dependencies: ["IoT-Simulator-Core"] + ), + ] +) diff --git a/README.md b/README.md index b863740..979a7d8 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ -# IoT-Simulator-Core - +# IoT-Simulator-Core + diff --git a/Sources/IoT-Simulator-Core/Classes/Environment/PhysicalEnvironment.swift b/Sources/IoT-Simulator-Core/Classes/Environment/PhysicalEnvironment.swift new file mode 100644 index 0000000..14d7b8d --- /dev/null +++ b/Sources/IoT-Simulator-Core/Classes/Environment/PhysicalEnvironment.swift @@ -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) + } + +} diff --git a/Sources/IoT-Simulator-Core/Classes/Utils/Message.swift b/Sources/IoT-Simulator-Core/Classes/Utils/Message.swift new file mode 100644 index 0000000..e31a0a8 --- /dev/null +++ b/Sources/IoT-Simulator-Core/Classes/Utils/Message.swift @@ -0,0 +1,3 @@ +public class Message { + +} \ No newline at end of file diff --git a/Sources/IoT-Simulator-Core/Classes/Utils/PhysicalData.swift b/Sources/IoT-Simulator-Core/Classes/Utils/PhysicalData.swift new file mode 100644 index 0000000..9782b82 --- /dev/null +++ b/Sources/IoT-Simulator-Core/Classes/Utils/PhysicalData.swift @@ -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 + } + +} \ No newline at end of file diff --git a/Sources/IoT-Simulator-Core/Enums/DataType.swift b/Sources/IoT-Simulator-Core/Enums/DataType.swift new file mode 100644 index 0000000..b4429b7 --- /dev/null +++ b/Sources/IoT-Simulator-Core/Enums/DataType.swift @@ -0,0 +1,6 @@ +public enum DataType { + case Temperature + case Humidity + case Scan + case Weight +} \ No newline at end of file diff --git a/Sources/IoT-Simulator-Core/Enums/DeviceType.swift b/Sources/IoT-Simulator-Core/Enums/DeviceType.swift new file mode 100644 index 0000000..c39e4b4 --- /dev/null +++ b/Sources/IoT-Simulator-Core/Enums/DeviceType.swift @@ -0,0 +1,4 @@ +public enum DeviceType { + case AsyncEdgeDevice + case EdgeDevice +} \ No newline at end of file diff --git a/Sources/IoT-Simulator-Core/Errors/CoreErrors.swift b/Sources/IoT-Simulator-Core/Errors/CoreErrors.swift new file mode 100644 index 0000000..16b0fc4 --- /dev/null +++ b/Sources/IoT-Simulator-Core/Errors/CoreErrors.swift @@ -0,0 +1,3 @@ +public enum CoreError : Error { + case NoPhysicalDataAvailable( dataType: String) +} \ No newline at end of file diff --git a/Sources/IoT-Simulator-Core/Interfaces/Environment.swift b/Sources/IoT-Simulator-Core/Interfaces/Environment.swift deleted file mode 100644 index b04b5c0..0000000 --- a/Sources/IoT-Simulator-Core/Interfaces/Environment.swift +++ /dev/null @@ -1,3 +0,0 @@ -public func sleepAndPrint() async { - -} \ No newline at end of file diff --git a/Sources/IoT-Simulator-Core/IoT_Simulator_Core.swift b/Sources/IoT-Simulator-Core/IoT_Simulator_Core.swift index 08b22b8..fe2ab92 100644 --- a/Sources/IoT-Simulator-Core/IoT_Simulator_Core.swift +++ b/Sources/IoT-Simulator-Core/IoT_Simulator_Core.swift @@ -1,2 +1,2 @@ -// The Swift Programming Language -// https://docs.swift.org/swift-book +// The Swift Programming Language +// https://docs.swift.org/swift-book diff --git a/Sources/IoT-Simulator-Core/Protocols/EdgeDevice.swift b/Sources/IoT-Simulator-Core/Protocols/EdgeDevice.swift new file mode 100644 index 0000000..1435070 --- /dev/null +++ b/Sources/IoT-Simulator-Core/Protocols/EdgeDevice.swift @@ -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 + +} \ No newline at end of file diff --git a/Sources/IoT-Simulator-Core/Protocols/Environment.swift b/Sources/IoT-Simulator-Core/Protocols/Environment.swift new file mode 100644 index 0000000..e69de29 diff --git a/Tests/IoT-Simulator-CoreTests/IoT_Simulator_CoreTests.swift b/Tests/IoT-Simulator-CoreTests/IoT_Simulator_CoreTests.swift index 4b14fdb..dc70750 100644 --- a/Tests/IoT-Simulator-CoreTests/IoT_Simulator_CoreTests.swift +++ b/Tests/IoT-Simulator-CoreTests/IoT_Simulator_CoreTests.swift @@ -1,6 +1,6 @@ -import Testing -@testable import IoT_Simulator_Core - -@Test func example() async throws { - // Write your test here and use APIs like `#expect(...)` to check expected conditions. -} +import Testing +@testable import IoT_Simulator_Core + +@Test func example() async throws { + // Write your test here and use APIs like `#expect(...)` to check expected conditions. +}