Sync parser
sync parser implementation
This commit is contained in:
1 parent
96cc366595
commit
d2318b6903
4 files changed
+64
-3
No files matched your search
@@ -27,6 +27,15 @@ typedef struct {
|
||||
} data_packet;
|
||||
#pragma pack(pop)
|
||||
|
||||
#pragma pack(push, 1)
|
||||
typedef struct {
|
||||
uint16_t sync;
|
||||
uint8_t type;
|
||||
uint32_t r_t;
|
||||
uint32_t s_t;
|
||||
} sync_packet;
|
||||
#pragma pack(pop)
|
||||
|
||||
uint16_t crc16_ccitt(const uint8_t *data, size_t length)
|
||||
{
|
||||
uint16_t crc = 0xFFFF;
|
||||
@@ -71,6 +80,35 @@ void setup() {
|
||||
pinMode(interruptPin, INPUT);
|
||||
pinMode(lambdaPin, INPUT);
|
||||
attachInterrupt(digitalPinToInterrupt(interruptPin),interrupt,FALLING);
|
||||
bool first_packet = false;
|
||||
bool parser_finished = false;
|
||||
unsigned long ts_lp = 0;
|
||||
while(true){
|
||||
uint8_t previous = 0;
|
||||
sync_packet packet{0xBEEF,3,0,0};
|
||||
while (true) {
|
||||
if (first_packet && micros() > ts_lp + 100000){parser_finished = true; break;}
|
||||
|
||||
if (Serial.available()) {
|
||||
uint8_t byte;
|
||||
Serial.readBytes(&byte, 1);
|
||||
if (previous == 0xEF && byte == 0xBE) {
|
||||
break;
|
||||
}
|
||||
previous = byte;
|
||||
}
|
||||
}
|
||||
if(parser_finished){break;}
|
||||
uint32_t r_t = micros();
|
||||
Serial.readBytes(&packet.type, 9);
|
||||
if (packet.type == 3) {
|
||||
packet.r_t = r_t;
|
||||
packet.s_t = micros();
|
||||
Serial.write((uint8_t*)&packet, sizeof(packet));
|
||||
first_packet = true;
|
||||
ts_lp = r_t;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
Reference in new issue
Block a user