NEC Near Field Communication RF module library for mbed H001-000003-001 (950MHz), H001-000013-001 (920MHz), TY24FM-E2024 (2.4GHz)
Dependents: NECnfc_sample Drone_air Drone_ground
NEC Near Field Communication RF module library
NEC製の近距離無線モジュール用のライブラリです。
Revision 6:2e1fc47e5bca, committed 2016-04-07
- Comitter:
- okini3939
- Date:
- Thu Apr 07 00:53:53 2016 +0000
- Parent:
- 5:e5a358e9ed94
- Child:
- 7:9c963cb53ef7
- Commit message:
- bug fix;
Changed in this revision
--- a/NECnfc.cpp Mon Oct 19 01:36:35 2015 +0000 +++ b/NECnfc.cpp Thu Apr 07 00:53:53 2016 +0000 @@ -21,6 +21,7 @@ _msgno = 0; _id = NEC_DUMMYID; _received = 0; + _rxcount = 0; initUart(reset, NC, NC, baud); setReset(true); @@ -37,6 +38,7 @@ _msgno = 0; _id = NEC_DUMMYID; _received = 0; + _rxcount = 0; initUart(reset, wakeup, mode, baud); setReset(true);
--- a/NECnfc.h Mon Oct 19 01:36:35 2015 +0000 +++ b/NECnfc.h Thu Apr 07 00:53:53 2016 +0000 @@ -147,6 +147,8 @@ enum Mode _mode; struct ifMessage _rxmsg; char *_rxbuf; + int _rxlen; + int _rxcount; int _msgno; volatile int _ack, _noack, _resend; int _txmsg;
--- a/NECnfc_msg.cpp Mon Oct 19 01:36:35 2015 +0000 +++ b/NECnfc_msg.cpp Thu Apr 07 00:53:53 2016 +0000 @@ -1,7 +1,6 @@ #include "NECnfc.h" void NECnfc::recvData (char c) { - static int len = 0, count = 0; #ifdef DEBUG_DUMP if (c < 0x20 || c >= 0x7f) { @@ -12,35 +11,35 @@ #endif switch (_mode) { case MODE_READY: - switch (count) { + switch (_rxcount) { case 0: if (c == 0x0f) { - _rxbuf[count] = c; - count ++; + _rxbuf[_rxcount] = c; + _rxcount ++; _received = 0; } break; case 1: if (c == 0x5a) { - _rxbuf[count] = c; - count ++; + _rxbuf[_rxcount] = c; + _rxcount ++; } else { - count = 0; + _rxcount = 0; } break; case 2: - _rxbuf[count] = c; - count ++; - len = (int)((unsigned char)c); + _rxbuf[_rxcount] = c; + _rxcount ++; + _rxlen = (int)((unsigned char)c); _mode = MODE_DATA; break; } break; case MODE_DATA: - _rxbuf[count] = c; - count ++; - if (count >= len) { - count = 0; + _rxbuf[_rxcount] = c; + _rxcount ++; + if (_rxcount >= _rxlen) { + _rxcount = 0; _mode = MODE_READY; parseMessage(); } @@ -83,6 +82,20 @@ unsigned char *buf = (unsigned char *)&ifmsg; Timer t; + if (_mode != MODE_READY) { + t.start(); + t.stop(); + while (_mode != MODE_READY) { + poll(); + if (t.read() > NEC_TIMEOUT) { + DBG("timeout\r\n"); + t.stop(); + return -1; + } + } + t.reset(); + } + if (len > NEC_MAXLENGTH) len = NEC_MAXLENGTH; _msgno = (_msgno + 1) & 0xff; ifmsg.start = htons(0x0f5a);