Interplan IM920 library, 920MHz module
Dependents: IM920_sample IM920_SDlog IM920_sample IM920_sample3 ... more
IM920 ライブラリ
データモード、低速、長距離 の設定で通信するライブラリです。
920MHz無線モジュール
- mbedとモジュールとは、シリアル(TX,RX)、BUSY、RESET端子を接続します。
- モジュールはあらかじめ、コマンドでノード番号などを設定しておきます。
IM920_hal.cpp@5:2fd9b1725283, 2015-04-24 (annotated)
- Committer:
- idealtechlab
- Date:
- Fri Apr 24 03:59:13 2015 +0000
- Revision:
- 5:2fd9b1725283
- Parent:
- 3:db269462ad1c
fix buffer over run
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
okini3939 | 0:d3ab05ed8142 | 1 | #include "IM920.h" |
okini3939 | 0:d3ab05ed8142 | 2 | |
okini3939 | 0:d3ab05ed8142 | 3 | void IM920::setReset (bool flg) { |
okini3939 | 0:d3ab05ed8142 | 4 | if (_reset) { |
okini3939 | 0:d3ab05ed8142 | 5 | if (flg) { |
okini3939 | 3:db269462ad1c | 6 | _reset->output(); |
okini3939 | 0:d3ab05ed8142 | 7 | _reset->write(0); |
okini3939 | 0:d3ab05ed8142 | 8 | } else { |
okini3939 | 3:db269462ad1c | 9 | _reset->input(); |
okini3939 | 3:db269462ad1c | 10 | _reset->mode(PullNone); |
okini3939 | 0:d3ab05ed8142 | 11 | } |
okini3939 | 0:d3ab05ed8142 | 12 | } |
okini3939 | 0:d3ab05ed8142 | 13 | } |
okini3939 | 0:d3ab05ed8142 | 14 | |
okini3939 | 0:d3ab05ed8142 | 15 | void IM920::isrUart () { |
okini3939 | 0:d3ab05ed8142 | 16 | recvData(getUart()); |
okini3939 | 0:d3ab05ed8142 | 17 | } |
okini3939 | 0:d3ab05ed8142 | 18 | |
okini3939 | 0:d3ab05ed8142 | 19 | int IM920::getUart () { |
okini3939 | 0:d3ab05ed8142 | 20 | return _im.getc(); |
okini3939 | 0:d3ab05ed8142 | 21 | } |
okini3939 | 0:d3ab05ed8142 | 22 | |
okini3939 | 0:d3ab05ed8142 | 23 | void IM920::putUart (char c) { |
okini3939 | 0:d3ab05ed8142 | 24 | _im.putc(c); |
okini3939 | 0:d3ab05ed8142 | 25 | } |
okini3939 | 0:d3ab05ed8142 | 26 | |
okini3939 | 0:d3ab05ed8142 | 27 | int IM920::lockUart (int ms) { |
okini3939 | 0:d3ab05ed8142 | 28 | Timer t; |
okini3939 | 0:d3ab05ed8142 | 29 | |
okini3939 | 0:d3ab05ed8142 | 30 | if (_busy && _busy->read()) { |
okini3939 | 0:d3ab05ed8142 | 31 | // CTS check |
okini3939 | 0:d3ab05ed8142 | 32 | t.start(); |
okini3939 | 0:d3ab05ed8142 | 33 | while (_busy->read()) { |
okini3939 | 0:d3ab05ed8142 | 34 | if (t.read_ms() >= ms) { |
okini3939 | 0:d3ab05ed8142 | 35 | DBG("cts timeout\r\n"); |
okini3939 | 0:d3ab05ed8142 | 36 | return -1; |
okini3939 | 0:d3ab05ed8142 | 37 | } |
okini3939 | 0:d3ab05ed8142 | 38 | } |
okini3939 | 0:d3ab05ed8142 | 39 | } |
okini3939 | 0:d3ab05ed8142 | 40 | return 0; |
okini3939 | 0:d3ab05ed8142 | 41 | } |
okini3939 | 0:d3ab05ed8142 | 42 | |
okini3939 | 0:d3ab05ed8142 | 43 | void IM920::unlockUart () { |
okini3939 | 0:d3ab05ed8142 | 44 | } |
okini3939 | 0:d3ab05ed8142 | 45 | |
okini3939 | 0:d3ab05ed8142 | 46 | void IM920::initUart (PinName busy, PinName reset, int baud) { |
okini3939 | 0:d3ab05ed8142 | 47 | _baud = baud; |
okini3939 | 0:d3ab05ed8142 | 48 | if (_baud) _im.baud(_baud); |
okini3939 | 0:d3ab05ed8142 | 49 | _im.attach(this, &IM920::isrUart, Serial::RxIrq); |
okini3939 | 0:d3ab05ed8142 | 50 | |
okini3939 | 0:d3ab05ed8142 | 51 | _busy = NULL; |
okini3939 | 0:d3ab05ed8142 | 52 | _reset = NULL; |
okini3939 | 0:d3ab05ed8142 | 53 | if (busy != NC) { |
okini3939 | 0:d3ab05ed8142 | 54 | _busy = new DigitalIn(busy); |
okini3939 | 0:d3ab05ed8142 | 55 | } |
okini3939 | 0:d3ab05ed8142 | 56 | if (reset != NC) { |
okini3939 | 3:db269462ad1c | 57 | _reset = new DigitalInOut(reset); |
okini3939 | 0:d3ab05ed8142 | 58 | } |
okini3939 | 0:d3ab05ed8142 | 59 | } |