Skip to content

Commit fef0f52

Browse files
committed
feat: create OctoberSkyInterface
1 parent 4d01681 commit fef0f52

File tree

5 files changed

+94
-227
lines changed

5 files changed

+94
-227
lines changed

projects/OctoberSky1/config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// clang-format off
44

55
#define STATEMACHINE OctoberSkyStateMachine
6+
#define INTERFACE OctoberSkyInterface
67

78
#ifndef TESTING
89
#define TESTING 0

src/init/MainLoop.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "chrono"
99
#include "data/UOSMData.h"
1010
#include "interface/HotFire/HotFireInterface.h"
11+
#include "interface/OctoberSky/OctoberSkyInterface.h"
1112
#include "spdlog/sinks/basic_file_sink.h"
1213
#include "spdlog/sinks/dup_filter_sink.h"
1314
#include "spdlog/sinks/stdout_color_sinks.h"

src/interface/InterfaceImpl.cpp

Lines changed: 0 additions & 188 deletions
This file was deleted.
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#include "config.h"
2+
#if TESTING != 1
3+
4+
#include "OctoberSkyInterface.h"
5+
#include "common/pch.h"
6+
#include <chrono>
7+
#include <spdlog/spdlog.h>
8+
9+
OctoberSkyInterface::OctoberSkyInterface() : eventQueue(), radio(eventQueue)
10+
{
11+
logger = spdlog::default_logger();
12+
}
13+
14+
OctoberSkyInterface::~OctoberSkyInterface() = default;
15+
16+
void OctoberSkyInterface::initialize()
17+
{
18+
initializeInputs();
19+
initializeOutputs();
20+
}
21+
22+
void OctoberSkyInterface::initializeInputs()
23+
{
24+
SPDLOG_LOGGER_INFO(logger, "Initializing SBG...");
25+
sbgSensor.initialize();
26+
}
27+
28+
void OctoberSkyInterface::initializeOutputs()
29+
{
30+
SPDLOG_LOGGER_INFO(logger, "Initializing SENSOR_LOGGER...");
31+
sensorLogger.initialize();
32+
33+
SPDLOG_LOGGER_INFO(logger, "Initializing RADIO...");
34+
radio.initialize();
35+
}
36+
37+
bool OctoberSkyInterface::updateInputs()
38+
{
39+
latestState = std::make_shared<StateData>();
40+
41+
latestState->timeStamp =
42+
std::chrono::duration_cast<time_point::duration>(std::chrono::steady_clock::now().time_since_epoch()).count();
43+
44+
latestState->sbg = sbgSensor.getData();
45+
latestState->sbgIsInitialized = sbgSensor.isInitialized();
46+
47+
latestState->eventNumber = eventQueue.pop();
48+
49+
latestState->loggerIsInitialized = sensorLogger.isInitialized();
50+
51+
latestState->radioIsInitialized = radio.isInitialized();
52+
53+
return true;
54+
}
55+
56+
bool OctoberSkyInterface::updateOutputs(std::shared_ptr<StateData> data)
57+
{
58+
sensorLogger.enqueueSensorData(*data);
59+
60+
radio.enqueueSensorData(*data);
61+
62+
return true;
63+
}
64+
65+
void OctoberSkyInterface::calibrateTelemetry()
66+
{
67+
sbgSensor.setZeroBarometricAltitude();
68+
}
69+
70+
std::shared_ptr<StateData> OctoberSkyInterface::getLatest()
71+
{
72+
73+
latestState->loggerWorking = SensorLogger::working;
74+
75+
return latestState;
76+
}
77+
78+
time_point OctoberSkyInterface::getCurrentTime()
79+
{
80+
return std::chrono::steady_clock::now();
81+
}
82+
83+
#endif

src/interface/InterfaceImpl.h renamed to src/interface/OctoberSky/OctoberSkyInterface.h

Lines changed: 9 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@
1010
#include "IO/SensorLogger.h"
1111
#include "IO/gpio/Gpio.h"
1212
#include "IO/tcp/SocketServer.h"
13-
#include "Interface.h"
1413
#include <IO/Sensors.h>
14+
#include <interface/Interface.h>
1515
#include <memory>
1616
#include <spdlog/logger.h>
1717
#include <string>
1818

19-
class InterfaceImpl : public Interface
19+
class OctoberSkyInterface : public Interface
2020
{
2121
public:
22-
InterfaceImpl();
23-
~InterfaceImpl();
22+
OctoberSkyInterface();
23+
~OctoberSkyInterface();
2424

2525
void initialize() override;
2626

27-
void calibrateTelemetry();
27+
void calibrateTelemetry() override;
2828

2929
// to get the latest rocket state. return a pointer to latestState
3030
std::shared_ptr<StateData> getLatest() override;
@@ -33,11 +33,6 @@ class InterfaceImpl : public Interface
3333
bool updateInputs() override;
3434
bool updateOutputs(std::shared_ptr<StateData> data) override;
3535

36-
#if USE_GPIO == 1
37-
void createNewGpioOutput(std::string name, int pinNbr) override;
38-
void createNewGpioPwmOutput(std::string name, int pinNbr, int safePosition, bool softpwm) override;
39-
#endif
40-
4136
time_point getCurrentTime() override;
4237

4338
private:
@@ -49,37 +44,12 @@ class InterfaceImpl : public Interface
4944
std::shared_ptr<StateData> latestState;
5045
EventQueue eventQueue;
5146

52-
#if USE_SBG == 1
53-
SBGSensor mySbgSensor;
54-
#endif
55-
56-
#if USE_INPUT == 1
57-
Input input;
58-
#endif
59-
60-
#if USE_SOCKET_CLIENT == 1
61-
SocketServer client;
62-
#endif
63-
64-
#if USE_RADIO == 1
47+
/**
48+
* IO instances
49+
*/
50+
SBGSensor sbgSensor;
6551
Radio radio;
66-
#endif
67-
68-
#if USE_LOGGER == 1
6952
SensorLogger sensorLogger;
70-
#endif
71-
72-
#if USE_GPIO == 1
73-
Gpio gpio;
74-
#endif
75-
76-
#if USE_ARDUINO_PROXY == 1
77-
ArduinoProxy *arduinoProxy;
78-
#endif
79-
80-
#if USE_SENSORS == 1
81-
Sensors sensors;
82-
#endif
8353
};
8454

8555
#endif

0 commit comments

Comments
 (0)