Interplan IM920 library, 920MHz module
Dependents: IM920_sample IM920_SDlog IM920_sample IM920_sample3 ... more
IM920 ライブラリ
データモード、低速、長距離 の設定で通信するライブラリです。
920MHz無線モジュール
- mbedとモジュールとは、シリアル(TX,RX)、BUSY、RESET端子を接続します。
- モジュールはあらかじめ、コマンドでノード番号などを設定しておきます。
Diff: IM920.h
- Revision:
- 0:d3ab05ed8142
- Child:
- 1:81b2fd407327
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/IM920.h Fri Dec 26 15:35:20 2014 +0000 @@ -0,0 +1,126 @@ +#ifndef _IM920_h_ +#define _IM920_h_ + +#include "IM920_conf.h" + +#include "mbed.h" +#include "CBuffer.h" +#include <ctype.h> +#include <stdlib.h> +#include <string.h> + +//Debug is disabled by default +#if defined(DEBUG) and (!defined(TARGET_LPC11U24)) +#define DBG(x, ...) std::printf("[DBG]" x "\r\n", ##__VA_ARGS__); +#define WARN(x, ...) std::printf("[WARN]" x "\r\n", ##__VA_ARGS__); +#define ERR(x, ...) std::printf("[ERR]" x "\r\n", ##__VA_ARGS__); +#define INFO(x, ...) std::printf("[INFO]" x "\r\n", ##__VA_ARGS__); +#else +#define DBG(x, ...) +#define WARN(x, ...) +#define ERR(x, ...) +#define INFO(x, ...) +#endif + +class IM920 { +public: + enum Response { + RES_NULL, + RES_RDID, + RES_RDNN, + RES_RDRS, + }; + + enum Mode { + MODE_COMMAND, + MODE_DATA_RX, + }; + + enum Status { + STAT_NONE, + STAT_SLEEP, + }; + + IM920 (PinName tx, PinName rx, PinName busy = NC, PinName reset = NC, int baud = IM920_BAUD); + + int init (int node, void(*func)() = NULL); + + void poll (); + + int send (char *buf, int len); + int recv (char *buf, int len); + + int setCh (int ch); + int getRssi (); + int sleep (); + int wakeup (); + + // ----- GSwifi_cmd.cpp ----- + int sendCommand(const char * cmd, Response res = RES_NULL, int timeout = DEFAULT_WAIT_RESP_TIMEOUT); + int sendData(const char * data, int len, int timeout = CFG_TIMEOUT); + +private: + RawSerial _im; + DigitalIn *_busy; + DigitalOut *_reset; + int _baud; + + struct STATE { + int id, node, rssi; + + time_t time; + bool initialized; + volatile Mode mode; + volatile Status status; + volatile bool ok, failure; + volatile Response res; + int n; + char buf[CFG_BUF_SIZE]; + + CircBuffer<char> *data; + volatile bool received; + void(*func)(); + } _state; + + // ----- GSwifi_util.cpp ----- + int x2i (char c); + char i2x (int i); + + // ----- GSwifi_msg.cpp ----- + void recvData (char c); + int parseMessage (); + void msgOk (const char*); + void msgError (const char*); + void msgConnect (const char*); + void resRDID (const char *buf); + void resRDNN (const char *buf); + void resRDRS (const char *buf); + + // ----- GSwifi_cmd.cpp ----- + void clearFlags (); + int cmdENWR (); + int cmdDSWR (); + int cmdRDID (); + int cmdSTNN (int n); + int cmdRDNN (); + int cmdSRID (int n); + int cmdERID (); + int cmdSTCH (int n); + int cmdRDRS (); + int cmdSTPO (int n); + int cmdSTRT (int n); + int cmdSBRT (int n); + int cmdDSRX (); + int cmdENRX (); + + // ----- GSwifi_hal.cpp ----- + void setReset (bool flg); + void isrUart (); + int getUart (); + void putUart (char c); + int lockUart (int ms); + void unlockUart (); + void initUart (PinName busy, PinName reset, int baud); + }; + +#endif