Fumiya Fujisawa
/
program_BlockPIL
program_BlockPIL //{Ping,Ir,Lines} Sensor
Diff: usart.cpp
- Revision:
- 1:3ecb80796a7f
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usart.cpp Mon Feb 24 05:20:20 2014 +0000 @@ -0,0 +1,70 @@ +#include "mbed.h" + +#define KEYCODE 0xAA +#define TX_CHECKCODE (tx_data[1]^tx_data[2]^tx_data[3]^tx_data[4]^tx_data[5]^tx_data[6]^tx_data[7]^tx_data[8]^tx_data[9]^tx_data[10]) +#define RX_CHECKCODE (rx_data[1]^rx_data[2]^rx_data[3]^rx_data[4]^rx_data[5]^rx_data[6]^rx_data[7]^rx_data[8]^rx_data[9]^rx_data[10]) +#define DATA_NUM 13 +#define CHECK (DATA_NUM - 1) +#define ALL_IR 10 +#define ALL_PING 4 +#define ALL_LINE 4 + + + +extern Serial sensor; +extern Serial pc; +extern unsigned int value_ping[ALL_PING]; +extern unsigned int value_ir[ALL_IR]; +extern unsigned int value_ir_min; +extern unsigned int ir_min_num; +extern unsigned int value_line[ALL_LINE]; +extern unsigned int value_compass; +void micon_rx(){ + + static uint8_t rx; + static uint8_t rx_data[DATA_NUM]; + + rx_data[rx] = sensor.getc(); + + if(rx_data[0] == KEYCODE){ + rx++; + } + + if(rx >= DATA_NUM){ + if(rx_data[CHECK] == RX_CHECKCODE){ + pc.printf("%d %d %d %d %d\n", rx_data[1], rx_data[2], rx_data[3], rx_data[4], rx_data[5]); + } + rx = 0; + } + +} + +void micon_tx(){ + + static uint8_t tx; + static uint8_t tx_data[DATA_NUM]; + + if(tx >= DATA_NUM){ + tx_data[0] = KEYCODE; + tx_data[1] = value_ir_min; + tx_data[2] = ir_min_num; + tx_data[3] = value_ping[0]; + tx_data[4] = value_ping[1]; + tx_data[5] = value_ping[2]; + tx_data[6] = value_ping[3]; + tx_data[7] = value_line[0]; + tx_data[8] = value_line[1]; + tx_data[9] = value_line[2]; + tx_data[10] = value_line[3]; + tx_data[11] = value_compass; + tx_data[12] = TX_CHECKCODE; + + tx = 0; + } + + + sensor.putc(tx_data[tx]); + //pc.printf("%d\n", tx_data[tx]); + tx++; + //wait(0.1); +} \ No newline at end of file