Interplan IM920 library, 920MHz module

Dependents:   IM920_sample IM920_SDlog IM920_sample IM920_sample3 ... more

IM920 ライブラリ

データモード、低速、長距離 の設定で通信するライブラリです。

920MHz無線モジュール

http://www.interplan.co.jp/images/contents/solution/im920.png IM920 (インタープラン製)

  • mbedとモジュールとは、シリアル(TX,RX)、BUSY、RESET端子を接続します。
  • モジュールはあらかじめ、コマンドでノード番号などを設定しておきます。

NECの920MHz近距離無線モジュールもおすすめ

Committer:
idealtechlab
Date:
Mon Jan 05 03:47:08 2015 +0000
Revision:
2:0b47f6b25cc4
Parent:
1:81b2fd407327
Child:
3:db269462ad1c
support attach

Who changed what in which revision?

UserRevisionLine numberNew contents of line
okini3939 1:81b2fd407327 1 /* Copyright (C) 2014 Suga, MIT License
okini3939 1:81b2fd407327 2 *
okini3939 1:81b2fd407327 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
okini3939 1:81b2fd407327 4 * and associated documentation files (the "Software"), to deal in the Software without restriction,
okini3939 1:81b2fd407327 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
okini3939 1:81b2fd407327 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
okini3939 1:81b2fd407327 7 * furnished to do so, subject to the following conditions:
okini3939 1:81b2fd407327 8 *
okini3939 1:81b2fd407327 9 * The above copyright notice and this permission notice shall be included in all copies or
okini3939 1:81b2fd407327 10 * substantial portions of the Software.
okini3939 1:81b2fd407327 11 *
okini3939 1:81b2fd407327 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
okini3939 1:81b2fd407327 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
okini3939 1:81b2fd407327 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
okini3939 1:81b2fd407327 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
okini3939 1:81b2fd407327 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
okini3939 1:81b2fd407327 17 */
okini3939 0:d3ab05ed8142 18 #include "IM920.h"
okini3939 0:d3ab05ed8142 19
okini3939 0:d3ab05ed8142 20 IM920::IM920 (PinName tx, PinName rx, PinName busy, PinName reset, int baud) : _im(tx, rx) {
okini3939 0:d3ab05ed8142 21
okini3939 0:d3ab05ed8142 22 memset(&_state, 0, sizeof(_state));
okini3939 0:d3ab05ed8142 23 _state.data = new CircBuffer<char>(CFG_DATA_SIZE);
okini3939 0:d3ab05ed8142 24
okini3939 0:d3ab05ed8142 25 initUart(busy, reset, baud);
okini3939 0:d3ab05ed8142 26 setReset(true);
okini3939 0:d3ab05ed8142 27 wait_ms(100);
okini3939 0:d3ab05ed8142 28 setReset(false);
okini3939 0:d3ab05ed8142 29 }
okini3939 0:d3ab05ed8142 30
idealtechlab 2:0b47f6b25cc4 31 int IM920::init (int node) {
okini3939 0:d3ab05ed8142 32
okini3939 0:d3ab05ed8142 33 _state.node = node;
okini3939 0:d3ab05ed8142 34
okini3939 0:d3ab05ed8142 35 cmdRDID();
okini3939 0:d3ab05ed8142 36 cmdSTNN(_state.node);
okini3939 0:d3ab05ed8142 37 cmdSTPO(3); // 10dBm
okini3939 0:d3ab05ed8142 38 cmdSTRT(2); // 1.25kbps
okini3939 0:d3ab05ed8142 39 return 0;
okini3939 0:d3ab05ed8142 40 }
okini3939 0:d3ab05ed8142 41
okini3939 0:d3ab05ed8142 42 void IM920::poll () {
okini3939 0:d3ab05ed8142 43
okini3939 0:d3ab05ed8142 44 if (_state.received && _state.buf != NULL)
idealtechlab 2:0b47f6b25cc4 45 if (!_state.data->isEmpty()) {
idealtechlab 2:0b47f6b25cc4 46 _func.call();
okini3939 0:d3ab05ed8142 47 if (_state.data->isEmpty()) {
okini3939 0:d3ab05ed8142 48 _state.received = false;
okini3939 0:d3ab05ed8142 49 }
okini3939 0:d3ab05ed8142 50 }
okini3939 0:d3ab05ed8142 51 }
okini3939 0:d3ab05ed8142 52
okini3939 0:d3ab05ed8142 53 int IM920::send (char *buf, int len) {
okini3939 0:d3ab05ed8142 54
okini3939 0:d3ab05ed8142 55 if (len > 64) len = 64;
okini3939 0:d3ab05ed8142 56
okini3939 0:d3ab05ed8142 57 return sendData(buf, len);
okini3939 0:d3ab05ed8142 58 }
okini3939 0:d3ab05ed8142 59
okini3939 0:d3ab05ed8142 60 int IM920::recv (char *buf, int len) {
okini3939 0:d3ab05ed8142 61 int i;
okini3939 0:d3ab05ed8142 62
okini3939 0:d3ab05ed8142 63 if (_state.data == NULL) return 0;
okini3939 0:d3ab05ed8142 64 while (!_state.received && _state.mode != MODE_COMMAND);
okini3939 0:d3ab05ed8142 65 _state.received = false;
okini3939 0:d3ab05ed8142 66 for (i = 0; i < len; i ++) {
okini3939 0:d3ab05ed8142 67 if (_state.data->dequeue(&buf[i]) == false) break;
okini3939 0:d3ab05ed8142 68 }
okini3939 0:d3ab05ed8142 69 return i;
okini3939 0:d3ab05ed8142 70 }