KIM HyoengJun / Mbed 2 deprecated mbed_fota_robot_control

Dependencies:   mbed-rtos mbed mbed_fota_fan_control

Fork of mbed_fota_lamp_control by KIM HyoengJun

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

Go to the documentation of this file.
00001 /**
00002  * @file main.cpp
00003  * @brief interface configuration & main loop start
00004  * Copyright 2015 SEVENCORE Co., Ltd.
00005  *
00006  * @author HyeongJun Kim 
00007  * @version 1.0.0  
00008  * @since 2015-08-17
00009 */
00010 
00011 
00012 #include "mbed.h"
00013 #include "cmsis_os.h"
00014 #include "BleMsgHandler.h"
00015 #include "fan_control_task.h"
00016 #include "dialog_fota_config.h"
00017 #include "app.h"
00018 
00019 Serial hostpc(USBTX,USBRX);
00020 Serial device(p13,p14);
00021 LocalFileSystem local("local");               // Create the local filesystem
00022 DigitalOut myled(LED1);
00023 DigitalOut myled2(LED2);
00024 DigitalOut myled3(LED3);
00025 DigitalOut myled4(LED4);
00026 
00027 DigitalOut port18(p18);//mid
00028 DigitalOut port19(p19);//low
00029 DigitalOut port20(p20);//high
00030 
00031 DigitalOut port21(p21);//low
00032 DigitalOut port22(p22);//high
00033 
00034 uint8_t Timer_flag;
00035 uint32_t Residual_Time;
00036 
00037 using namespace sevencore_fota;
00038 
00039 
00040 void FanTimer(void const *threadarg)
00041 {
00042     Timer_flag = 0;
00043     Residual_Time = 0;
00044     BleMsgHandler *BMH;
00045     BMH = (struct BleMsgHandler *) threadarg;
00046     while(true)
00047     {
00048         if( Timer_flag == 1 && Residual_Time == 0 )
00049         {
00050             hostpc.printf("Power off!!\n");
00051             if( port21 == 1 || port22 == 1  )
00052                 port21 = port22 = 0;
00053             Timer_flag = 0;
00054             /*{
00055                 uint8_t fota_normal = 0;
00056                 uint8_t *msg;
00057                 struct fan_control_set_char_val_req char_set_req;
00058                 unsigned short msg_size = 1+sizeof(ble_hdr)+ sizeof(fan_control_set_char_val_req)-(4-FAN_CONTROL_MIN_SIZE);
00059                 // Fill in the parameter structure
00060                 char_set_req.char_code     = FAN_CONTROL_POWER_STATE_CHAR;
00061                 char_set_req.val_len       = FAN_CONTROL_MIN_SIZE;
00062                 memcpy(&char_set_req.val[0], &fota_normal, sizeof(fota_normal));
00063                 
00064                 msg = new uint8_t[msg_size];
00065                 
00066                 BMH->BleMsgAlloc(FAN_CONTROL_SET_CHAR_VAL_REQ
00067                     ,TASK_FAN_CONTROL, TASK_GTL
00068                     ,sizeof(struct fan_control_set_char_val_req)-(4-FAN_CONTROL_MIN_SIZE)
00069                     ,&char_set_req,msg );
00070                 // Send the message
00071                 BMH->BleSendMsg(msg,msg_size);                
00072                 free(msg);
00073             }
00074             */
00075             
00076         }
00077     
00078         if( Timer_flag == 1 )
00079         {
00080             osDelay(1000);
00081             if(Residual_Time > 0){
00082                 hostpc.printf("Residual Time = %d, minus 1 second!!\n",Residual_Time );
00083                 Residual_Time--;
00084             }
00085         }
00086     }
00087 }
00088 
00089 void t0(void const *argument) {FanTimer(argument);}
00090 osThreadDef(t0, osPriorityNormal, DEFAULT_STACK_SIZE);
00091 
00092 void led_setting_one(void){
00093     myled = 1;
00094     myled2 = 1;
00095     myled3 = 1;
00096     myled4 = 1;
00097 }
00098 
00099 void led_setting_zero(void){
00100     myled = 1;
00101     myled2 = 0;
00102     myled3 = 0;
00103     myled4 = 0;
00104 }
00105 
00106 int main() {
00107     wait(0.5);
00108     myled = 1;
00109     wait(0.5);
00110     myled = 0;
00111     wait(0.5);
00112     myled = 1;
00113     wait(0.5);
00114     myled = 0;
00115     wait(0.5);
00116     led_setting_zero(); 
00117     wait(0.5);
00118     hostpc.baud(9600);
00119     wait(0.5);
00120     device.baud(115200);
00121     device.set_flow_control(device.RTSCTS,P2_7,p12);
00122     wait(0.5);
00123     
00124     BleMsgHandler myfota(&device,&hostpc);   
00125     osThreadCreate( osThread(t0), (void *)&myfota );
00126     
00127     myfota.PrintTitle();
00128     app_rst_gap(&myfota);
00129     
00130     for(int i = 0; i < 200; i++) {
00131         myfota.BleReceiveMsg();
00132         myfota.BleMsgHandle();
00133     }
00134     
00135     while(1) {
00136         myled = 1;
00137         wait(0.5);
00138         myled = 0;
00139         wait(0.5);
00140     }
00141     
00142 }