Msg ordering tests
This commit is contained in:
41
experiments/can/can_receive_counter.cpp
Normal file
41
experiments/can/can_receive_counter.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
//
|
||||
// Created by zuma on 12.10.2020.
|
||||
//
|
||||
|
||||
#include <asyncdevice.h>
|
||||
#include <picandevice.h>
|
||||
#include <future>
|
||||
|
||||
int main() {
|
||||
AsyncDevice device;
|
||||
auto canDevice = new PICANDevice("can1");
|
||||
|
||||
int counter = 1;
|
||||
std::promise<bool> is_success_promise;
|
||||
auto is_success = is_success_promise.get_future();
|
||||
auto closure = [&is_success_promise, &counter, canDevice](CAN_Raw msg){
|
||||
if (msg.Id != 0x20) return;
|
||||
if (msg.Size != sizeof(int)) {
|
||||
is_success_promise.set_value(false);
|
||||
throw can::error(canDevice, can::error::closed, "");
|
||||
}
|
||||
int recv_counter = reinterpret_cast<int&>(msg.Data);
|
||||
if (counter != recv_counter) {
|
||||
piCout << recv_counter << "<- miss ordering";
|
||||
// is_success_promise.set_value(false);
|
||||
// throw can::error(canDevice, can::error::closed, "");
|
||||
} else {
|
||||
piCout << recv_counter;
|
||||
}
|
||||
counter = recv_counter + 1;
|
||||
if (counter - 1 == 1000) {
|
||||
is_success_promise.set_value(true);
|
||||
throw can::error(canDevice, can::error::closed, "");
|
||||
}
|
||||
};
|
||||
CONNECTL(&device, readEvent, closure);
|
||||
|
||||
device.replace(canDevice);
|
||||
bool result = is_success.get();
|
||||
piCout << (result ? "success" : "failure");
|
||||
}
|
||||
22
experiments/can/can_send_counter.cpp
Normal file
22
experiments/can/can_send_counter.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
//
|
||||
// Created by zuma on 12.10.2020.
|
||||
//
|
||||
|
||||
#include <asyncdevice.h>
|
||||
#include <picandevice.h>
|
||||
|
||||
int main() {
|
||||
AsyncDevice device;
|
||||
device.replace(new PICANDevice("can0"));
|
||||
|
||||
CAN_Raw msg = { .Id = 0x20, .Size = sizeof(int) };
|
||||
int& counter = reinterpret_cast<int&>(msg.Data);
|
||||
|
||||
counter = 0;
|
||||
while (counter++ < 1000) {
|
||||
device.send(msg);
|
||||
piMSleep(1);
|
||||
}
|
||||
|
||||
piSleep(5);
|
||||
}
|
||||
Reference in New Issue
Block a user