Skip to content

Commit

Permalink
re-structured everything, and sensor data discovery now works on HWL
Browse files Browse the repository at this point in the history
  • Loading branch information
Skjelsbek committed Mar 4, 2019
1 parent 11f4b16 commit 029a393
Show file tree
Hide file tree
Showing 27 changed files with 795 additions and 715 deletions.
151 changes: 95 additions & 56 deletions SatStat_HWLayer/SatStat_HWLayer.ino
Original file line number Diff line number Diff line change
@@ -1,96 +1,135 @@
#pragma once
#include "./handlers/Input_handler.h"
#include "./handlers/Output_handler.h"
#include "./handlers/Serial_handler.h"
#include "./other/Sensor_container.h"

// Init input and output handler
Input_handler* input_handler;
Output_handler* output_handler;
Serial_handler* serial_handler;
Instruction_handler* instruction_handler;
Sensor_container* sensor_container;

// Timing constrains
unsigned long start_time = millis();
const int duration = 1000;

void setup()
void handshake()
{
// Temp and hum sensor gnd and 5V
pinMode(7, OUTPUT);
digitalWrite(7, LOW);
pinMode(5, OUTPUT);
digitalWrite(5, HIGH);

// Initialize the serial port
Serial.begin(9600);

// Instantiate input and output handler
input_handler = new Input_handler();
output_handler = new Output_handler();

// Loop until handshake received
bool connection_established = false;
while (!connection_established)
{
while (true)
{
// Send ack if approved, nack if not
if (input_handler->handshake_approved())
{
output_handler->send_handshake_response();
connection_established = true;
}
else
if (serial_handler->handshake_approved())
{
output_handler->send_nack();
break;
}
}
}
}

bool connection()
{
// Loop until connection request received
connection_established = false;
while (!connection_established)
{
unsigned long start_time = millis();
unsigned long timeout = 10000;

while (millis() - start_time < timeout)
{
// Send nack if not approved
if (input_handler->connection_request_approved())
{
connection_established = true;
if (serial_handler->connection_request_approved())
{
return true;
}
else
}

return false;
}

bool connection_init()
{
// Init connection on new config
unsigned long start_time = millis();
unsigned long timeout = 10000;

while (millis() - start_time < timeout)
{
if (serial_handler->connection_init_approved())
{
output_handler->send_nack();
return true;
}
}
}

// Apply new config
input_handler->serial_init();
output_handler->set_newline_format(input_handler->get_newline_format());
return false;
}

connection_established = false;
while (!connection_established)
{
output_handler->send_ack();
bool provide_sensor_data()
{
// Init connection on new config
unsigned long start_time = millis();
unsigned long timeout = 10000;

if (input_handler->init_connection())
while (millis() - start_time < timeout)
{
// Send nack if not approved
if (serial_handler->available_data_request_approved())
{
connection_established = true;
return true;
}
}

return false;
}

void setup()
{
// Temp and hum sensor gnd and 5V
pinMode(7, OUTPUT);
digitalWrite(7, LOW);
pinMode(5, OUTPUT);
digitalWrite(5, HIGH);

serial_handler = new Serial_handler();
instruction_handler = new Instruction_handler();
sensor_container = new Sensor_container();

Serial.begin(9600);

while (true)
{
handshake();

if (connection())
{
if (connection_init())
{
if (provide_sensor_data())
{
break;
}
}
}
serial_handler->send_nack();
delay(30);
Serial.begin(9600);
}
}

void loop()
{
input_handler->serial_listener();
serial_handler->serial_listener();

if (input_handler->instruction_available())
{
output_handler->interpret_instruction(input_handler->get_instruction());
if (!instruction_handler->queue_is_empty())
{
instruction_handler->interpret_instruction();
}

if (output_handler->get_auto_rotate_en())
if (instruction_handler->sadm_auto_rotate_en())
{
output_handler->auto_rotate_sadm();
instruction_handler->sadm_auto_rotate();
}

// Runs with an interval equal to the duration
if (!(millis() - start_time < duration))
{
// Prints sensor data
output_handler->print_to_serial(input_handler->read_sensors());
serial_handler->print_to_serial(sensor_container->read_sensors());

// Update start time to current time
start_time = millis();
Expand Down
14 changes: 9 additions & 5 deletions SatStat_HWLayer/SatStat_HWLayer.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@
</None>
</ItemGroup>
<ItemGroup>
<ClInclude Include="handlers\Input_handler.h" />
<ClInclude Include="handlers\Instruction_handler.h" />
<ClInclude Include="handlers\Json_handler.h" />
<ClInclude Include="handlers\Output_handler.h" />
<ClInclude Include="handlers\Serial_handler.h" />
<ClInclude Include="libraries\ArduinoJson.h" />
<ClInclude Include="libraries\ArduinoJson.hpp" />
<ClInclude Include="libraries\ArduinoJson\Configuration.hpp" />
Expand Down Expand Up @@ -204,20 +204,24 @@
<ClInclude Include="other\Json_array_container.h" />
<ClInclude Include="other\Json_container.h" />
<ClInclude Include="other\Json_object_container.h" />
<ClInclude Include="other\SADM_functions.h" />
<ClInclude Include="other\Sensor_container.h" />
<ClInclude Include="sensors\Result.h" />
<ClInclude Include="sensors\Sensor.h" />
<ClInclude Include="sensors\Temp_hum_sensor.h" />
<ClInclude Include="__vm\.SatStat_HWLayer.vsarduino.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="handlers\Input_handler.cpp" />
<ClCompile Include="handlers\Instruction_handler.cpp" />
<ClCompile Include="handlers\Json_handler.cpp" />
<ClCompile Include="handlers\Output_handler.cpp" />
<ClCompile Include="handlers\Serial_handler.cpp" />
<ClCompile Include="libraries\dht.cpp" />
<ClCompile Include="libraries\DS1302.cpp" />
<ClCompile Include="libraries\Stepper.cpp" />
<ClCompile Include="other\Json_array_container.cpp" />
<ClCompile Include="other\Json_object_container.cpp" />
<ClCompile Include="other\SADM_functions.cpp" />
<ClCompile Include="other\Sensor_container.cpp" />
<ClCompile Include="sensors\Sensor.cpp" />
<ClCompile Include="sensors\Temp_hum_sensor.cpp" />
</ItemGroup>
Expand All @@ -226,7 +230,7 @@
</ImportGroup>
<ProjectExtensions>
<VisualStudio>
<UserProperties arduino.upload.port="COM9" />
<UserProperties arduino.upload.port="COM11" />
</VisualStudio>
</ProjectExtensions>
</Project>
36 changes: 24 additions & 12 deletions SatStat_HWLayer/SatStat_HWLayer.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@
<ClInclude Include="handlers\Json_handler.h">
<Filter>Header Files\handlers</Filter>
</ClInclude>
<ClInclude Include="handlers\Output_handler.h">
<Filter>Header Files\handlers</Filter>
</ClInclude>
<ClInclude Include="sensors\Sensor.h">
<Filter>Header Files\sensors</Filter>
</ClInclude>
Expand Down Expand Up @@ -324,26 +321,29 @@
<ClInclude Include="other\Json_object_container.h">
<Filter>Header Files\other</Filter>
</ClInclude>
<ClInclude Include="handlers\Input_handler.h">
<Filter>Header Files\handlers</Filter>
</ClInclude>
<ClInclude Include="other\Json_array_container.h">
<Filter>Header Files\other</Filter>
</ClInclude>
<ClInclude Include="other\Json_container.h">
<Filter>Header Files\other</Filter>
</ClInclude>
<ClInclude Include="handlers\Instruction_handler.h">
<Filter>Header Files\handlers</Filter>
</ClInclude>
<ClInclude Include="handlers\Serial_handler.h">
<Filter>Header Files\handlers</Filter>
</ClInclude>
<ClInclude Include="other\Sensor_container.h">
<Filter>Header Files\other</Filter>
</ClInclude>
<ClInclude Include="other\SADM_functions.h">
<Filter>Header Files\other</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="handlers\Input_handler.cpp">
<Filter>Source Files\handlers</Filter>
</ClCompile>
<ClCompile Include="handlers\Json_handler.cpp">
<Filter>Source Files\handlers</Filter>
</ClCompile>
<ClCompile Include="handlers\Output_handler.cpp">
<Filter>Source Files\handlers</Filter>
</ClCompile>
<ClCompile Include="sensors\Sensor.cpp">
<Filter>Source Files\sensors</Filter>
</ClCompile>
Expand All @@ -365,5 +365,17 @@
<ClCompile Include="other\Json_array_container.cpp">
<Filter>Source Files\other</Filter>
</ClCompile>
<ClCompile Include="handlers\Instruction_handler.cpp">
<Filter>Source Files\handlers</Filter>
</ClCompile>
<ClCompile Include="handlers\Serial_handler.cpp">
<Filter>Source Files\handlers</Filter>
</ClCompile>
<ClCompile Include="other\Sensor_container.cpp">
<Filter>Source Files\other</Filter>
</ClCompile>
<ClCompile Include="other\SADM_functions.cpp">
<Filter>Source Files\other</Filter>
</ClCompile>
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion SatStat_HWLayer/__vm/Compile.vmps.xml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion SatStat_HWLayer/__vm/Configuration.Debug.vmps.xml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion SatStat_HWLayer/__vm/Upload.vmps.xml

Large diffs are not rendered by default.

Loading

0 comments on commit 029a393

Please sign in to comment.