|
|
@ -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) { |
|
|
|