#include "BusSerial.h"

Timer timer;
BusSerial BS(PB_6, PB_7, &timer);// (TX,RX,&timer)

int main()
{
    BS.baud(9600);
    const int header = 251, footer = 250;
    
    while(1) {
        uint8_t data[10] = {0}; // 10を使ってるのはテキトー．必要な数に合わせて下さい．
        
        int timeout_ms = 100;

        
        // ~~~戻り値でちゃんと受信できたらtrueを返す．~~~
        // 変数作らずにif(BS.getBusSerial(data, header, 7))でも動くと思う．
        // headerの後ろの引数の値が受け取るデータ数
        // 送信側が{255,1,2,3,254,1,2,3,4,253,1,2,3,4,5,,252,~}って感じ送信する時は
        // 自分のIDが254の場合は『4』にする
        //bool correct = BS.getBusSerial(data, header, 7);                       // ヘッダー照合ver
        //bool correct = BS.getTimedBusSerial(data, header, 7, timeout_ms);         // ヘッダー照合とタイムアウトver
        //bool correct = BS.getBusSerial(data, header, 7, footer);               // ヘッダーとフッター照合ver
        bool correct = BS.getTimedBusSerial(data, header, 7, footer, timeout_ms); // ヘッダーとフッター照合とタイムアウトver

        if(correct) {
            for(int i = 0; i<10; i++) printf("%d ",data[i]);
            printf("\n");
        } else
            printf("miss\n");


        // 自らのTxRxを接続して動作確認する．いらない
        //uint8_t send_data[9] = {251,11,22,33,44,55,66,77,250};
        //BS.sendBusSerial(send_data, 9); // 絶対この関数の中身を書いた方が楽．
        
        //BS.GetBusSerial(data,header,3,timeout); // 旧式の通信．いらない
    }
}