電動バイク制御基板プログラム

Dependencies:   BufferedSerial SDFileSystem mbed

main.cpp

Committer:
NT32
Date:
2016-10-16
Revision:
1:f61fbb8e4352
Parent:
0:7210cdf801f9
Child:
2:1a62df057057

File content as of revision 1:f61fbb8e4352:

#include "mbed.h"
#include "SDFileSystem.h"
#define SEL_GPS 0
#define SEL_BMS 1
#define SEL_HNDL 2
#define SEL_FELICA 3
#define CELL_NUM 24
DigitalOut led1(P1_1);
DigitalOut led2(P0_9);
BusOut selUart(P1_5, P1_4);
Serial uart_cpld(P1_0, P0_31);
//Serial uart_v850(P0_28, P0_29);
//Serial uart_gps(P0_26, P0_27);
//Serial uart_handle(P0_0, P0_30);
//Serial uart_felica(P0_4, P0_2);
Serial uart_moni(P0_0,P0_30);
//SDFileSystem sd(P0_7, P0_5, P0_6, P0_8, "sd");

int main() {
    int cellVol[CELL_NUM] = {0,0,0,0,0,0,0,0,0,0,0,0,
                             0,0,0,0,0,0,0,0,0,0,0,0};
    int cellMinVol, cellMaxVol, cellAvgVol;
    while(1) {
        //=================================================
        // バッテリ管理基板との通信
        //=================================================
        led1 = 0;
        selUart = SEL_BMS;
        uart_cpld.putc('s');
        for (int i = 0; i < CELL_NUM; ++i)
        {
            // 個別セル電圧取得
            uart_cpld.scanf("%d\n", &cellVol[i]); 
        }
        //最低->最高->平均で取得
        uart_cpld.scanf("%d\n", &cellMinVol); 
        uart_cpld.scanf("%d\n", &cellMaxVol); 
        uart_cpld.scanf("%d\n", &cellAvgVol); 
        led1 = 1;

        //=================================================
        // 表示装置との通信
        //=================================================
        led2 = 0;
        selUart = SEL_HNDL;
        uart_cpld.putc('m');
        uart_cpld.printf("\033[2J"); //デバッグ用Tera Term出力
        uart_cpld.printf("\033[%d;%dH" ,0,0); //デバッグ用Tera Term出力
        
        wait(0.01);
        for (int i = 0; i < CELL_NUM; ++i)
        {
            // 個別セル電圧取得
            uart_cpld.printf("%d\n",cellVol[i]); 
        }
        //最低->最高->平均で取得
        uart_cpld.printf("%d\n",cellMinVol); 
        uart_cpld.printf("%d\n",cellMaxVol); 
        uart_cpld.printf("%d\n",cellAvgVol); 

        led2 = 1;

    }
}