Skip to content

Commit 8db245a

Browse files
committed
fox
1 parent 8b92697 commit 8db245a

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

MIDAS/src/hilsim/kal.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,21 @@ DECLARE_THREAD(hilsim, void*arg) {
119119
// ---- ENTRY FUNCS ----
120120
void k_run() {
121121
Serial.begin(115200);
122+
while(!Serial);
123+
124+
k_push_event(K_START_E);
125+
k_push_event(k_get_checksum_evt());
126+
127+
// Wait until start signal (newline written to serial)
128+
k_wait_until('\n');
129+
k_clear_inbuf();
130+
131+
// Set up MIDAS
122132
k_midas_setup();
123133
k_init_sensordata();
124134
k_push_event(K_SETUP_DONE);
135+
136+
// Start systems
125137
k_start();
126138
}
127139

MIDAS/src/hilsim/kal.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ inline bool k_handle_reading(uint32_t ts, uint8_t disc, uint8_t* data, size_t da
4848
enum sys_instr_t {
4949
RESERVED = 0,
5050
REPORT_EN = 1,
51+
VERIFY_CHECKSUM = 2,
5152
};
5253

5354
// System message: instruct the Kamaji driver to do something
@@ -67,6 +68,15 @@ inline void k_handle_sys_msg(uint8_t* data, uint16_t crc) {
6768
k_enable_data_report(disc, report_intv);
6869
}
6970
break;
71+
case (sys_instr_t::VERIFY_CHECKSUM):
72+
{
73+
uint32_t checksum;
74+
memcpy(&checksum, data + 1, sizeof(uint32_t));
75+
if(checksum != LOG_CHECKSUM) {
76+
k_INVALIDCHECKSUM();
77+
}
78+
}
79+
break;
7080
default:
7181
k_INVALIDINSTR();
7282
return;
@@ -75,6 +85,19 @@ inline void k_handle_sys_msg(uint8_t* data, uint16_t crc) {
7585
Serial.write("%OK");
7686
}
7787

88+
void k_wait_until(char sig) {
89+
char a;
90+
do {
91+
a = Serial.read();
92+
} while (a != sig);
93+
}
94+
95+
void k_clear_inbuf() {
96+
while(Serial.available() > 0) {
97+
char tb = Serial.read();
98+
}
99+
}
100+
78101
// ---- Kamaji Thread ----
79102
void hilsim_thread(void* arg);
80103

MIDAS/src/hilsim/kamaji/kal_error.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,8 @@ inline void k_INVALIDINSTR() {
1717
Serial.write("!II\n");
1818
}
1919

20+
inline void k_INVALIDCHECKSUM() {
21+
// Invalid checksum test
22+
Serial.write("!IC\n");
23+
}
24+

MIDAS/src/hilsim/kamaji/kal_events.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22
#include <cstdint>
33
#include "kal_error.h"
4+
#include "log_checksum.h"
45

56
// ---- CONFIGURATION ----
67
#define EVENT_STACK_SIZE 8
@@ -62,6 +63,14 @@ inline void k_log(char* log_message, size_t len) {
6263
k_push_event(evt);
6364
}
6465

66+
inline k_event_t k_get_checksum_evt() {
67+
k_event_t evt;
68+
uint32_t checksum = LOG_CHECKSUM;
69+
memcpy(evt.buf + 1, &checksum, sizeof(uint32_t));
70+
evt.buf[0] = 'C';
71+
return evt;
72+
}
6573

6674
// ---- PRE-DEFINED EVENTS ----
67-
constexpr k_event_t K_SETUP_DONE {0, K_EVENT_TYPE::SYSTEM_MESSAGE, 3, {'H', 'I', 'L'}};
75+
constexpr k_event_t K_START_E {0, K_EVENT_TYPE::SYSTEM_MESSAGE, 3, {'H', 'I', 'L'}};
76+
constexpr k_event_t K_SETUP_DONE {0, K_EVENT_TYPE::SYSTEM_MESSAGE, 3, {'H', 'S', 'D'}};

0 commit comments

Comments
 (0)