-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.cpp
48 lines (38 loc) · 1.36 KB
/
test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <iostream>
#include "cheerinos.h"
using namespace std;
// instantiate receive handler
void buf_received(char* buffer, uint8_t size);
// instatiate cheerinos object with its node address
cheerinos ch(1);
int main() {
// set up data to send
uint8_t to_addr = 2;
char data_to_send[] = "hello world";
// register receive handler
ch.register_handler(&buf_received);
std::cout<<"main: registered receive handler"<<std::endl;
// send data!
// NB. + 1 after strlen is because ascii strings are nul terminated
ch.send(to_addr, data_to_send, strlen(data_to_send) + 1);
std::cout<<"main: sent packed with payload - "<<data_to_send<<std::endl;
std::cout<<std::endl<<"main: -----------------------" <<std::endl;
// set up simulation for serial receive simulator
std::cout<<"main: starting receive simulator" <<std::endl;
std::cout<<"main: -----------------------" <<std::endl;
char wire_delay[200];
unsigned int wire_length;
// loop 50 times
for (int i=0; i<50; i++) {
ch.serial.tx_out(wire_delay, wire_length);
ch.serial.rx_in(wire_delay, wire_length);
ch.update();
};
return 0;
}
// implement receive handler
void buf_received(char* buffer, uint8_t size) {
std::cout<<"RECEIVE HANDLER: Packet Received! "<<std::endl;
std::cout<<"RECEIVE HANDLER: printing below... "<<std::endl<<std::endl;
ch.sm_debug_packet(buffer, size);
}