API to interface sensor with host PC
Dependencies: LidarSpi USBDevice mbed
tests.cpp@0:10bd8964965a, 2016-04-05 (annotated)
- Committer:
- TNU
- Date:
- Tue Apr 05 08:16:30 2016 +0000
- Revision:
- 0:10bd8964965a
Fixed tests.cpp;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
TNU | 0:10bd8964965a | 1 | |
TNU | 0:10bd8964965a | 2 | #include "tests.h" |
TNU | 0:10bd8964965a | 3 | int traceTest(LidarSpi* lidar, Serial * pc, USBSerial * serial) |
TNU | 0:10bd8964965a | 4 | { |
TNU | 0:10bd8964965a | 5 | int res=0; |
TNU | 0:10bd8964965a | 6 | uint16_t buf[9473]; |
TNU | 0:10bd8964965a | 7 | uint32_t nBytes; |
TNU | 0:10bd8964965a | 8 | res=lidar->setTrace(); |
TNU | 0:10bd8964965a | 9 | pc->printf("Set trace result: %d\n\r"); |
TNU | 0:10bd8964965a | 10 | memset(buf, 0, sizeof(buf[0])*9472); |
TNU | 0:10bd8964965a | 11 | //for(int i=0;i<64;i++) res=lidar.GetTraceOne( buf, 9472*2, 0, 0, i, &pc); |
TNU | 0:10bd8964965a | 12 | //res=lidar.GetTraceOne( buf, 9472*2, 0, 0, 0, &pc); |
TNU | 0:10bd8964965a | 13 | res=lidar->GetTrace( buf, 9472*2, 0, 0, pc); |
TNU | 0:10bd8964965a | 14 | pc->printf("============\n\r============\n\r==================\n\r"); |
TNU | 0:10bd8964965a | 15 | pc->printf("Result: %d \tTrace values after Patch:\n\r", res); |
TNU | 0:10bd8964965a | 16 | |
TNU | 0:10bd8964965a | 17 | //"%d \n", ((buf[i] & 0x00ff) << 8) | ((buf[i] & 0xff00) >> 8) |
TNU | 0:10bd8964965a | 18 | //for (int i =0; i<(74*8*16);i++) pc->printf("%d ",((buf[i] & 0x00ff) << 8) | ((buf[i] & 0xff00) >> 8)); |
TNU | 0:10bd8964965a | 19 | /* |
TNU | 0:10bd8964965a | 20 | for(int i =0;i<16;i++) serial->printf("CH%d;",i); |
TNU | 0:10bd8964965a | 21 | serial->printf("\n"); |
TNU | 0:10bd8964965a | 22 | for (int i =0; i<(592);i++) { |
TNU | 0:10bd8964965a | 23 | for(int j=0;j<16;j++) serial->printf("%d;",((buf[i+(j*74*8)] & 0x00ff) << 8) | ((buf[i+(j*74*8)] & 0xff00) >> 8)); |
TNU | 0:10bd8964965a | 24 | serial->printf("\n"); |
TNU | 0:10bd8964965a | 25 | } |
TNU | 0:10bd8964965a | 26 | |
TNU | 0:10bd8964965a | 27 | serial->printf("\n");*/ |
TNU | 0:10bd8964965a | 28 | |
TNU | 0:10bd8964965a | 29 | if(res<0) { |
TNU | 0:10bd8964965a | 30 | serial->putc(1); |
TNU | 0:10bd8964965a | 31 | for(int i=0;i<4;i++) serial->putc(0); |
TNU | 0:10bd8964965a | 32 | return 0; |
TNU | 0:10bd8964965a | 33 | } |
TNU | 0:10bd8964965a | 34 | else nBytes=res*2; |
TNU | 0:10bd8964965a | 35 | |
TNU | 0:10bd8964965a | 36 | uint8_t * pntrS=(uint8_t *) &nBytes; |
TNU | 0:10bd8964965a | 37 | pc->printf("size: %d\n\r", *pntrS); |
TNU | 0:10bd8964965a | 38 | serial->putc(0); |
TNU | 0:10bd8964965a | 39 | for(int i=0;i<sizeof(nBytes);i++) serial->putc(*(pntrS+i)); |
TNU | 0:10bd8964965a | 40 | uint8_t * pnt; |
TNU | 0:10bd8964965a | 41 | pnt=(uint8_t *)buf; |
TNU | 0:10bd8964965a | 42 | pc->printf("Shows some values of trace, nBytes: %d\n\r", nBytes*2); |
TNU | 0:10bd8964965a | 43 | |
TNU | 0:10bd8964965a | 44 | for(int i=0;i<(nBytes);i=i+100) pc->printf("Value= %d\n\r", pnt[i]); |
TNU | 0:10bd8964965a | 45 | pc->printf("Transmit trace\n\r"); |
TNU | 0:10bd8964965a | 46 | for(int i=0;i<(nBytes);i++) { |
TNU | 0:10bd8964965a | 47 | serial->putc(pnt[i]); |
TNU | 0:10bd8964965a | 48 | if(i<50)pc->printf("Char [%d] -> %x \n\r", i, pnt[i]); |
TNU | 0:10bd8964965a | 49 | if(((i % 2)==0)&&i<50 )pc->printf("Transmit [%d] -> %x \n\r",i, ((pnt[i])<<8)|(pnt[i+1])); |
TNU | 0:10bd8964965a | 50 | } |
TNU | 0:10bd8964965a | 51 | pc->printf("Trace transmitted\n\r"); |
TNU | 0:10bd8964965a | 52 | //delete buf; |
TNU | 0:10bd8964965a | 53 | wait_us(4); |
TNU | 0:10bd8964965a | 54 | return res; |
TNU | 0:10bd8964965a | 55 | } |