45 lines
1.1 KiB
C++
45 lines
1.1 KiB
C++
#include "usart.h"
|
|
#include <cstdio>
|
|
#include <cstring>
|
|
#include <signal.h>
|
|
|
|
class Top : public BaseLayer {
|
|
static constexpr int max = 1024;
|
|
volatile unsigned index;
|
|
int passcnt;
|
|
char buffer [max];
|
|
public:
|
|
explicit Top () : BaseLayer(), index(0u), passcnt(0) {}
|
|
void puts (const char * str) {
|
|
const unsigned l = strlen(str);
|
|
Down(str, l);
|
|
}
|
|
uint32_t Up(const char * data, const uint32_t len) override {
|
|
for (unsigned n=0; n<len; n++) {
|
|
const char c = data [n];
|
|
buffer [index++] = c;
|
|
if (c == '\n') {
|
|
buffer [index - 2] = '\0';
|
|
printf("Rx (%d) %s\n", passcnt++, buffer);
|
|
index = 0u;
|
|
}
|
|
}
|
|
return len;
|
|
}
|
|
};
|
|
static const char * TestString = "THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG'S BACK 1234567890\r\n";
|
|
static volatile bool loop = false;
|
|
static void Handler (int) {
|
|
loop = false;
|
|
}
|
|
int main (void) {
|
|
loop = true;
|
|
signal (SIGINT, Handler);
|
|
UsartClass usart ("/dev/serial/by-id/usb-Kizarm_Labs._USB__=__USART_0002-if00", 1'000'000);
|
|
Top top;
|
|
top += usart;
|
|
while (loop) {
|
|
top.puts(TestString);
|
|
}
|
|
return 0;
|
|
}
|