Browse Source

update

master
zhaohe 4 years ago
parent
commit
25a448f1a0
  1. 5
      .clang-format
  2. 6
      .vscode/settings.json
  3. 1
      README.md
  4. BIN
      release/aarch64/uart_read_test_main.out
  5. BIN
      release/aarch64/uart_write_test.out
  6. 52
      uart_read_test_main.cpp
  7. BIN
      uart_read_test_main.out
  8. BIN
      uart_write_test.out
  9. 39
      uart_write_test_main.cpp

5
.clang-format

@ -0,0 +1,5 @@
# Defines the Chromium style for automatic reformatting.
# http://clang.llvm.org/docs/ClangFormatStyleOptions.html
Language: Cpp
BasedOnStyle: Google
ColumnLimit: 300

6
.vscode/settings.json

@ -0,0 +1,6 @@
{
"files.associations": {
"*.tcc": "cpp",
"ostream": "cpp"
}
}

1
README.md

@ -2,5 +2,6 @@
```
uart_read_test_main.out
```

BIN
release/aarch64/uart_read_test_main.out

BIN
release/aarch64/uart_write_test.out

52
uart_read_test_main.cpp

@ -14,10 +14,25 @@
#include <string.h>
#include <termios.h>
#include <unistd.h>
//
#include <map>
#include <set>
#include <string>
#include "uart.h"
#define MAX_RECV_SIZE 235
using namespace std;
map<string, uint32_t> g_baundmap = {
{"0", 0000000}, {"50", 0000001}, {"75", 0000002}, {"110", 0000003}, //
{"134", 0000004}, {"150", 0000005}, {"200", 0000006}, {"300", 0000007}, //
{"600", 0000010}, {"1200", 0000011}, {"1800", 0000012}, {"2400", 0000013}, //
{"4800", 0000014}, {"9600", 0000015}, {"19200", 0000016}, {"38400", 0000017}, //
{"57600", 0010001}, {"115200", 0010002}, {"230400", 0010003}, {"460800", 0010004}, //
{"500000", 0010005}, {"576000", 0010006}, {"921600", 0010007}, {"1000000", 0010010}, //
{"1152000", 0010011}, {"1500000", 0010012}, {"2000000", 0010013}, {"2500000", 0010014}, //
{"3000000", 0010015}, {"3500000", 0010016}, {"4000000", 0010017},
};
void openuart(struct UartDevice *device, char *devname, int rate) {
device->name = devname;
@ -33,33 +48,32 @@ void openuart(struct UartDevice *device, char *devname, int rate) {
int main(int argc, char *argv[]) {
struct UartDevice dev = {0};
// struct UartDevice dev2 = {0};
if (argc != 2) {
printf("Usage:%s dev1\n", argv[0]);
// printf("Demo:%s /dev/ttyUSB0 /dev/ttyUSB1\n", argv[0]);
exit(-1);
if (argc != 3) {
printf("Usage: %s /dev/ttyUSB0 115200\n", argv[0]);
return -1;
}
printf("device name:%s\n", argv[1]);
printf("baundrate :%s\n", argv[2]);
auto baundrate_find_result = g_baundmap.find(argv[2]);
if (baundrate_find_result == g_baundmap.end()) {
printf("unsupport baundrate\n");
return -1;
};
openuart(&dev, argv[1], B9600);
// openuart(&dev, argv[1], B115200);
// openuart(&dev2, argv[2], B9600);
openuart(&dev, argv[1], baundrate_find_result->second);
char buf[1024] = {0};
memset(buf, 0x55, 1024);
for (size_t i = 0;; i++) {
int ret1, ret2;
ret1 = uartReceive(&dev, buf, 2/*接收的字节数2-1*/); // send the received text over UART
ret1 = uartReceive(&dev, buf, 2 /*接收的字节数2-1*/); // send the received text over UART
if (ret1 != 0) {
// printf("receive %d %x characters %d\n", ret1, buf[0], i);
printf("%x\n", buf[0]);
if (buf[0] != 0x12 && buf[0] != 0x34 && buf[0] != 0x56 &&
buf[0] != 0x78 && buf[0] != 0x9a) {
printf("....................................................%x\n", buf[0]);
}
printf("%x", buf[0]);
}
fflush(stdout);
if (i % 20 == 0) {
printf("\n");
}
// ret2 = uartSend(&dev2, buf, 1); // send the received text over UART
// usleep(1*1000);
}
while (1) {

BIN
uart_read_test_main.out

BIN
uart_write_test.out

39
uart_write_test_main.cpp

@ -16,8 +16,23 @@
#include <unistd.h>
#include "uart.h"
//
#include <map>
#include <set>
#include <string>
#define MAX_RECV_SIZE 235
using namespace std;
map<string, uint32_t> g_baundmap = {
{"0", 0000000}, {"50", 0000001}, {"75", 0000002}, {"110", 0000003}, //
{"134", 0000004}, {"150", 0000005}, {"200", 0000006}, {"300", 0000007}, //
{"600", 0000010}, {"1200", 0000011}, {"1800", 0000012}, {"2400", 0000013}, //
{"4800", 0000014}, {"9600", 0000015}, {"19200", 0000016}, {"38400", 0000017}, //
{"57600", 0010001}, {"115200", 0010002}, {"230400", 0010003}, {"460800", 0010004}, //
{"500000", 0010005}, {"576000", 0010006}, {"921600", 0010007}, {"1000000", 0010010}, //
{"1152000", 0010011}, {"1500000", 0010012}, {"2000000", 0010013}, {"2500000", 0010014}, //
{"3000000", 0010015}, {"3500000", 0010016}, {"4000000", 0010017},
};
void openuart(struct UartDevice *device, char *devname, int rate) {
device->name = devname;
@ -33,24 +48,28 @@ void openuart(struct UartDevice *device, char *devname, int rate) {
int main(int argc, char *argv[]) {
struct UartDevice dev = {0};
// struct UartDevice dev2 = {0};
if (argc != 2) {
printf("Usage:%s dev1\n", argv[0]);
// printf("Demo:%s /dev/ttyUSB0 /dev/ttyUSB1\n", argv[0]);
exit(-1);
if (argc != 3) {
printf("Usage: %s /dev/ttyUSB0 115200\n", argv[0]);
return -1;
}
printf("device name:%s\n", argv[1]);
printf("baundrate :%s\n", argv[2]);
auto baundrate_find_result = g_baundmap.find(argv[2]);
if (baundrate_find_result == g_baundmap.end()) {
printf("unsupport baundrate\n");
return -1;
};
openuart(&dev, argv[1], B9600);
// openuart(&dev2, argv[2], B9600);
char buf[1024] = {0x55};
memset(buf, 0x55, 1024);
for (size_t i = 0;; i++) {
int ret1, ret2;
int ret1;
ret1 = uartSend(&dev, buf, 1); // send the received text over UART
// ret2 = uartSend(&dev2, buf, 1); // send the received text over UART
printf("send %d %d characters %d\n", ret1, ret2, i);
usleep(1*1000);
printf("send %d characters %d\n", ret1, i);
usleep(1 * 1000);
}
while (1) {

Loading…
Cancel
Save