STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
actuator_nc.cpp
Go to the documentation of this file.
1#include <iostream>
2
4
5static bool serverHeartbeat = true;
6static bool configPacket = true;
7int boardID = 1234; // Example board ID
8static const std::string SERVER_ADDRESS = "SERVER_ADDRESS";
9static const std::string ACTUATOR_CONTROLLER_ADDRESS =
10 "ACTUATOR_CONTROLLER_ADDRESS";
11const int IPAddress = 0; // Example IP address (recieve during packet config)
12const bool necessaryForAbort = true; // example condition for abort
13const std::string ABORT = "ABORT"; // example server packet indicating abort
16
18 std::string destination) {
19 (void)boardID; // Mock implementation of sending heartbeat w/ ID
20}
25 return configPacket; // Mock implementation
26}
28 // stores server address in server heartbeat
29}
30void delay(int ms) {
31 // Mock implementation of delay
32}
33bool heartbeatTimedOut(int currTime, int lastHeartbeatTime) {
34 return (currTime - lastHeartbeatTime) > HEARTBEAT_TIMEOUT_MS;
35}
37 // mock connection test function
38 return false; // assume connection failed for example
39}
41 // mock implementation of streaming packets to server
42}
44 std::string destination) {
45 // mock implementation of providing abort data to actuator controller
46}
50 SERVER_ADDRESS); // send heartbeat to server with abort state
51 mainloop(myBoardState, boardID); // example of looping mainloop after abort
52}
54 // mock implementation of broadcasting connection loss to server and
55 // actuator controller
56}
57void ping() {
58 // mock implementation of pinging server and actuator controller
59}
61 // mock implementation of checking for response from server and actuator
62 // controller
63 return false; // assume no response received for example
64}
66 // mock implementation of checking for abort done packet from controller
67 // board
68
69 return false; // assume no abort done packet received for example
70}
72 // mock implementation of executing commands from controller board
73}
75 // mock implementation of checking if connection is resumed
76 return false; // assume connection not resumed for example
77}
78std::string serverPacket() {
79 // mock implementation of checking for server packet
80 return ABORT; // assume ABORT packet received for example
81}
82
83int main(int argc, char** argv) {
84 (void)argc;
85 (void)argv;
86
87 setup(); // setup once
88
89 while (true) { // loop mainloop until fail
91 }
92
93 return 0;
94}
95
96void setup() {
97 // Power on
99
100 // Waiting for Server
101 // send heartbeats including board ID until it recieves server's heartbeat
102 // response or timeout
103 while (serverHeartbeatReceived() == false) {
106 }
107
108 storeAddress(); // store server address in server heartbeat
109 // Waiting for Config
110 while (configPacketReceived() == false) {
112 }
113
114 // everything is set up, board is active
116}
117
118void mainloop(BoardState myBoardState, int boardID) { // ACTIVE STATE
120 SERVER_ADDRESS); // send heartbeat to server
121 storeAddress(); // store server address in server heartbeat
122 streamPackets(); // stream packets to server
123
124 if (heartbeatTimedOut(6000, 0)) { // example time values
126 }
127 if (serverPacket() == ABORT) {
129 }
130}
131
133 (void)boardID;
134 // handle connection loss
136 int currentTime = 0;
137 while (currentTime < CONNECTION_LOSS_GRACE_MS) {
138 broadcastConnectionLoss(); // broadcast connection loss to server and
139 // actuator controller
140 ping();
141 currentTime += MAINLOOP_POLL_INTERVAL_MS;
142 }
143 if (connectionResume() == true) {
145 boardID); // resume mainloop if connection is resumed
146 }
147 if (responseReceived() == true) {
149 boardID); // abort if connection not resumed
150 }
151
152 else { // STANDALONE ABORT
153 myBoardState = BoardState::abort; // abort if necessary
155 ACTUATOR_CONTROLLER_ADDRESS); // provide abort data to
156 // actuator controller
158 }
159
160 // nothing here
161}
162
164 while (true) {
167 SERVER_ADDRESS); // send heartbeat to server with abort state
169 if (abortDonePacketReceived() == true) {
171 boardID); // finish abort if abort done packet received
172 // from controller board
173 break;
174 } else if (heartbeatTimedOut(6000, 0)) { // example time values
176 break;
177 }
178 }
179}
180
182 if (responseReceived()) { // NO CONNECTION ABORT
184
185 while (abortDonePacketReceived() == false) {
186 executeCommands(); // execute commands from controller board as
187 // they come
189 }
190
192 }
193}
#define CONNECTION_LOSS_GRACE_MS
#define HEARTBEAT_TIMEOUT_MS
static const std::string SERVER_ADDRESS
bool responseReceived()
void abortFinish(BoardState myBoardState, int boardID)
bool serverHeartbeatReceived()
void provideAbortData(BoardState boardState, int boardID, int IPAddress, std::string destination)
static const std::string ACTUATOR_CONTROLLER_ADDRESS
void noConnectionAbort(BoardState myBoardState, int boardID)
void broadcastConnectionLoss()
static bool serverHeartbeat
static bool configPacket
void setup()
bool testConnection()
void standardAbort(BoardState myBoardState, int boardID)
bool configPacketReceived()
void streamPackets()
bool connectionResume()
BoardState myBoardState
void executeCommands()
bool abortDonePacketReceived()
void mainloop(BoardState myBoardState, int boardID)
BoardState
std::string serverPacket()
const bool necessaryForAbort
void storeAddress()
void delay(int ms)
int boardID
const std::string ABORT
void connectionLoss(BoardState myBoardState, int boardID)
void ping()
#define HEARTBEAT_SEND_INTERVAL_MS
#define MAINLOOP_POLL_INTERVAL_MS
static bool heartbeatTimedOut()
Definition main.cpp:366
static void sendHeartbeat()
Definition main.cpp:241
static State boardState
Definition main.cpp:73
int main()