MPUとHMCでうごくかもver
Dependencies: ConfigFile SDFileSystem mbed
Fork of LAURUS_program by
Revision 28:d993f3bbe302, committed 2015-07-01
- Comitter:
- onaka
- Date:
- Wed Jul 01 14:57:24 2015 +0000
- Parent:
- 27:a26ff85bba23
- Child:
- 29:59f4808e2eb6
- Commit message:
- xbee communication fix
Changed in this revision
--- a/BufferedSerial/BufferedSerial.cpp Sun Jun 28 15:42:26 2015 +0000 +++ b/BufferedSerial/BufferedSerial.cpp Wed Jul 01 14:57:24 2015 +0000 @@ -132,7 +132,7 @@ void BufferedSerial::txIrq(void) { // see if there is room in the hardware fifo and if something is in the software fifo - while(serial_writable(&_serial) && !_cts) { + while(serial_writable(&_serial) && checkCTS()) { if(_txbuf.available()) { serial_putc(&_serial, (int)_txbuf.get()); } else { @@ -148,7 +148,7 @@ void BufferedSerial::prime(void) { // if already busy then the irq will pick this up - if(serial_writable(&_serial) && !_cts) { + if(serial_writable(&_serial) && checkCTS()) { SERIAL_BASE::attach(NULL, SERIAL_BASE::TxIrq); // make sure not to cause contention in the irq BufferedSerial::txIrq(); // only write to hardware in one place SERIAL_BASE::attach(this, &BufferedSerial::txIrq, SERIAL_BASE::TxIrq); @@ -157,8 +157,28 @@ return; } +bool BufferedSerial::checkCTS(void) +{ + static bool _send_flg=true; + if(_send_flg) { + _send_flg=!_cts; + } else { + if(_cts) { + _cts_timer.reset(); + } else { + if(_cts_timer.read_ms()>XBEE_WAIT_TIME) { + _cts_timer.stop(); + _send_flg=true; + } + } + } + return _send_flg; +} + void BufferedSerial::ctsInterrupt(void) { + _cts_timer.reset(); + _cts_timer.start(); BufferedSerial::prime(); return; }
--- a/BufferedSerial/BufferedSerial.h Sun Jun 28 15:42:26 2015 +0000 +++ b/BufferedSerial/BufferedSerial.h Wed Jul 01 14:57:24 2015 +0000 @@ -30,6 +30,8 @@ // Base Class #define SERIAL_BASE RawSerial +#define XBEE_WAIT_TIME 3800 + /** A serial port (UART) for communication with other serial devices * * Can be used for Full Duplex communication, or Simplex by specifying @@ -75,6 +77,7 @@ { private: InterruptIn _cts; + Timer _cts_timer; Buffer <char> _rxbuf; Buffer <char> _txbuf; uint32_t _buf_size; @@ -84,6 +87,7 @@ void txIrq(void); void prime(void); + bool checkCTS(void); void ctsInterrupt(void); public:
--- a/LAURUS_program.lib Sun Jun 28 15:42:26 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://developer.mbed.org/teams/LAURUS/code/LAURUS_program/#4c72d7420d8a
--- a/main.cpp Sun Jun 28 15:42:26 2015 +0000 +++ b/main.cpp Wed Jul 01 14:57:24 2015 +0000 @@ -50,7 +50,7 @@ GMS6_CR6 gms(&gps, &pc); // GPS SDFileSystem sd(PB_5, PB_4, PB_3, PB_10, "sd"); // microSD FILE * fp; // ログファイルのポインタ -BufferedSerial xbee(PA_9, PA_10, PC_1); // Xbee +BufferedSerial xbee(PA_9, PA_10, PC_1, 256, 16); // Xbee ConfigFile cfg; // ConfigFile PwmOut servoL(PB_6), servoR(PC_7); // サーボ用PWM出力 AnalogIn optSensor(PC_0); // 照度センサ用アナログ入力 @@ -86,7 +86,7 @@ Vector pre_p(2); // 過去の位置情報(経度, 緯度)(rad) int UTC_t = 0; // UTC時刻 int pre_UTC_t = 0; // 前のUTC時刻 -int ss = 0.0f; // 時刻の秒数の小数部分 +int ss = 0; // 時刻の秒数の小数部分 Vector b_f(3); // 機体座標に固定された、機体前方向きのベクトル(x軸) Vector b_u(3); // 機体座標に固定された、機体上方向きのベクトル(z軸)