-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
112 lines (86 loc) · 2.16 KB
/
main.cpp
File metadata and controls
112 lines (86 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include <iostream>
#include <vector>
#include <cstdint>
// Communications
#include "Communications/LoRa.h"
#include "Communications/Serial.h"
// Guards init
#include "Guards/GuardsInit.h"
// Settings
#include "Storage.h"
// Commands
#include "Commands/Directory.h"
// Example lora data in the format it is received
uint8_t loraRaw[] = { 'a', 0x31, 0x00, 100, 200, 5 };
// Example serial data in the format it is received in
std::string seriaData = "FREQ=822109384,5";
// Tasks
void loRaTask();
void serialTask();
/**
* Main event loop
*/
int main()
{
// Welcome message
std::cout << "Method Architecture Demo" << std::endl;
std::cout << "=========================" << std::endl<< std::endl;
// Setup the setting class
Storage storage;
// Setup guard classes so they have access to the settings class
Guards::GuardsInit::init(storage);
loRaTask();
std::cout <<std::endl<<std::endl;
serialTask();
return 0;
}
/**
* Demo lora task
*/
void loRaTask()
{
// Create interface
Communications::LoRa lora;
// Convert raw lora data to string
std::string data((char *)loraRaw, sizeof(loraRaw) + 1);
// Get command contract
auto contract = lora.handle(data);
// Demo
if(contract.validExecution())
{
std::cout << "LORA = ";
std::cout << "Received: ";
for(int i = 0; i < data.size(); i++)
{
std::cout << unsigned((uint8_t)data.at(i)) << " ";
}
std::cout << "Sent: ";
for(int i = 0; i < contract.communicationsOutput.size(); i++)
{
std::cout << unsigned((uint8_t)contract.communicationsOutput.at(i)) << " ";
}
}
else
{
std::cout << "Invalid data" << std::endl;
}
}
/**
* Demo serial task
*/
void serialTask()
{
// Create interface
Communications::Serial serial;
// Get command contract
auto contract = serial.handle(seriaData);
// Demo
if(contract.validExecution())
{
std::cout << "SERIAL = " << "Received: " << seriaData << " Sent: " << contract.communicationsOutput << std::endl;
}
else
{
std::cout << "Invalid data" << std::endl;
}
}