インタープラン製無線モジュールIM920と通信を行うライブラリです

Files at this revision

API Documentation at this revision

Comitter:
kim1212
Date:
Sat Mar 11 03:30:34 2017 +0000
Commit message:
???????????????IM920?????????????

Changed in this revision

IM920.cpp Show annotated file Show diff for this revision Revisions of this file
IM920.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 4d4bdea0e93d IM920.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/IM920.cpp	Sat Mar 11 03:30:34 2017 +0000
@@ -0,0 +1,63 @@
+#include "IM920.h"
+#include "mbed.h"
+
+IM920::IM920(PinName RadioTx,PinName RadioRx,PinName Busy): _Radio(RadioTx,RadioRx),_Busy(Busy){
+    
+RadioInit();
+
+}
+
+
+void IM920::RadioInit(){
+    char commandbuf[50];
+
+    _Radio.baud(19200);//初期状態のボーレートは19200
+    
+    while(_Busy!=0);
+    sprintf(commandbuf,"%s,%d","SBRT",BAUD_LATE);
+    SendCommand(commandbuf);//ボーレートは38400
+    wait_ms(5);
+    
+    _Radio.baud(BAUD_LATE);//マイコン側ボーレート変更
+    
+    SendBufClear(commandbuf);//送信バッファクリア
+    sprintf(commandbuf,"%s,%s","STCH",FREQ);//データ作成
+    SendCommand(commandbuf);//ch2
+    
+    SendBufClear(commandbuf);//送信バッファクリア
+    sprintf(commandbuf,"%s,%d","STPO",POWER);//データ作成 送信出力
+    SendCommand(commandbuf);//ch2
+    
+    SendBufClear(commandbuf);//送信バッファクリア
+    sprintf(commandbuf,"%s,%d","STRT",SPEED);//データ作成 高速通信モード
+    SendCommand(commandbuf);//ch2
+    
+    SendBufClear(commandbuf);//送信バッファクリア
+    sprintf(commandbuf,"%s,%s","SRID",ID);//データ作成
+    SendCommand(commandbuf);//相手方IDを設定
+    
+}
+
+void IM920::SendCommand(char* data){
+    while(_Busy!=0);
+    _Radio.printf("%s",data);
+    _Radio.putc(0x0d);
+    _Radio.putc(0x0a);
+    wait_ms(5);
+}
+
+void IM920::SendBufClear(char* buf){
+    int i=0;
+    for(;i<50;i++) buf[i]=0;
+}
+
+bool IM920::SendData(char* data){
+    if(_Busy!=1){
+        char sdata[70];
+        sprintf(sdata,"%s,%s","TXDA ",data);
+        _Radio.printf(sdata);
+        _Radio.putc(0x0d);
+        _Radio.putc(0x0a);
+        return true;
+    }else return false;
+}
\ No newline at end of file
diff -r 000000000000 -r 4d4bdea0e93d IM920.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/IM920.h	Sat Mar 11 03:30:34 2017 +0000
@@ -0,0 +1,43 @@
+#ifndef IM920_H
+#define IM920_H
+
+#include "mbed.h"
+
+#define BAUD_1200 0
+#define BAUD_2400 1
+#define BAUD_4800 2
+#define BAUD_9600 3
+#define BAUD_19200 4
+#define BAUD_38400 5
+
+#define POWER_0_1MW 1
+#define POWER_1MW 2
+#define POWER_10MW 3
+
+#define HSPEED 1 //50kbps 高速通信モード
+#define LSPEED 2//1.25kbps 長距離通信モード
+
+#define BAUD_LATE BAUD_38400//通信時ボーレート
+#define POWER POWER_10MW //送信出力
+#define ID "0DCB"//相手方の固有ID
+#define FREQ "02"//通信チャンネル(01~15)
+#define SPEED HSPEED //通信モード
+
+
+class IM920{
+    public:
+        IM920(PinName RadioTx,PinName RadioRx,PinName Busy);
+        void RadioInit();//初期設定 不揮発メモリは書き込み禁止で行う
+        void SendCommand(char* data);//データ送信
+        void SendBufClear(char* buf);
+        bool SendData(char* data);
+        
+    private:
+        
+        Serial _Radio;
+        DigitalIn _Busy;
+};
+
+
+
+#endif