IZU2020 / PQES920LR

Dependents:   IZU2020_GROUND_STATION IZU2020_AVIONICS IZU2020_AVIONICS

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers PQES920LR.h Source File

PQES920LR.h

00001 #ifndef PQES920LR_H
00002 #define PQES920LR_H
00003 
00004 /**
00005  * ES920LRのライブラリ
00006  * @note 内部でシリアル受信割り込みを使用しています
00007  * @note 適切な送信時間間隔を取ること
00008  * @note attachで受信イベントハンドラを設定すること
00009  * @code
00010 #include "mbed.h"
00011 #include "PQES920LR.h"
00012 
00013 Serial pc(USBTX, USBRX, 115200);
00014 Serial es_serial(p9, p10, 115200);
00015 
00016 ES920LR es(es_serial);
00017 
00018 char data[50];
00019 
00020 void on_receive(char *buff)
00021 {
00022     for(int i = 0; i < 50; i++) {
00023         pc.printf("%x ", buff[i]);
00024     }
00025 }
00026 
00027 int main()
00028 {
00029     es.attach(&on_receive);
00030     for(int i = 0; i < 50; i++) {
00031         data[i] = 0xFF;
00032     }
00033     while(1) {
00034         es.send(data, 50);
00035         wait(1);
00036     }
00037 }
00038  * @endcode
00039  */
00040 
00041 class ES920LR
00042 {
00043 private:
00044     Serial *_serial;
00045     char tx_buf[52];
00046     char rx_buf[52];
00047     char rx_size;
00048     int index;
00049     int flag;
00050     bool response;
00051 
00052     void (*func)(char*);
00053 
00054 public:
00055     /**
00056      * @param es_serial Serialのインスタンスへの参照
00057      */
00058     ES920LR (Serial &es_serial);
00059 
00060     /**
00061      * @param data 送信するバイナリデータの配列(最大50バイト)
00062      * @param size 送信するバイナリデータのサイズ
00063      */
00064     void send (char *data, int size);
00065 
00066     /**
00067      * @param func_ptr 受信時に呼ばれる関数へのポインタ、引数に受信データを受け取る
00068      */
00069     void attach (void(*func_ptr)(char*));
00070 
00071 private:
00072     void receive();
00073 };
00074 
00075 #endif