![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
BLE fota Robot Demo
Dependencies: mbed-rtos mbed mbed_fota_fan_control
Fork of mbed_fota_lamp_control by
main.cpp@13:e714e2971c49, 2015-10-13 (annotated)
- Committer:
- dudnwjs
- Date:
- Tue Oct 13 06:35:19 2015 +0000
- Revision:
- 13:e714e2971c49
- Parent:
- 12:e3d3676753cc
lamp demo;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dudnwjs | 8:9eec2c246a85 | 1 | /** |
dudnwjs | 8:9eec2c246a85 | 2 | * @file main.cpp |
dudnwjs | 8:9eec2c246a85 | 3 | * @brief interface configuration & main loop start |
dudnwjs | 8:9eec2c246a85 | 4 | * Copyright 2015 SEVENCORE Co., Ltd. |
dudnwjs | 8:9eec2c246a85 | 5 | * |
dudnwjs | 8:9eec2c246a85 | 6 | * @author HyeongJun Kim |
dudnwjs | 8:9eec2c246a85 | 7 | * @version 1.0.0 |
dudnwjs | 8:9eec2c246a85 | 8 | * @since 2015-08-17 |
dudnwjs | 8:9eec2c246a85 | 9 | */ |
dudnwjs | 8:9eec2c246a85 | 10 | |
dudnwjs | 8:9eec2c246a85 | 11 | |
dudnwjs | 0:a1f6b1ba8a1e | 12 | #include "mbed.h" |
dudnwjs | 12:e3d3676753cc | 13 | #include "cmsis_os.h" |
dudnwjs | 1:5cf3a6c969be | 14 | #include "BleMsgHandler.h" |
dudnwjs | 12:e3d3676753cc | 15 | #include "fan_control_task.h" |
dudnwjs | 12:e3d3676753cc | 16 | #include "dialog_fota_config.h" |
dudnwjs | 3:1e70387e1337 | 17 | #include "app.h" |
dudnwjs | 0:a1f6b1ba8a1e | 18 | |
dudnwjs | 0:a1f6b1ba8a1e | 19 | Serial hostpc(USBTX,USBRX); |
dudnwjs | 0:a1f6b1ba8a1e | 20 | Serial device(p13,p14); |
dudnwjs | 6:8dd20294b2aa | 21 | LocalFileSystem local("local"); // Create the local filesystem |
dudnwjs | 0:a1f6b1ba8a1e | 22 | DigitalOut myled(LED1); |
dudnwjs | 6:8dd20294b2aa | 23 | DigitalOut myled2(LED2); |
dudnwjs | 6:8dd20294b2aa | 24 | DigitalOut myled3(LED3); |
dudnwjs | 6:8dd20294b2aa | 25 | DigitalOut myled4(LED4); |
dudnwjs | 0:a1f6b1ba8a1e | 26 | |
dudnwjs | 12:e3d3676753cc | 27 | DigitalOut port18(p18);//mid |
dudnwjs | 12:e3d3676753cc | 28 | DigitalOut port19(p19);//low |
dudnwjs | 12:e3d3676753cc | 29 | DigitalOut port20(p20);//high |
dudnwjs | 12:e3d3676753cc | 30 | |
dudnwjs | 13:e714e2971c49 | 31 | DigitalOut port21(p21);//low |
dudnwjs | 13:e714e2971c49 | 32 | DigitalOut port22(p22);//high |
dudnwjs | 13:e714e2971c49 | 33 | |
dudnwjs | 12:e3d3676753cc | 34 | uint8_t Timer_flag; |
dudnwjs | 12:e3d3676753cc | 35 | uint32_t Residual_Time; |
dudnwjs | 12:e3d3676753cc | 36 | |
dudnwjs | 1:5cf3a6c969be | 37 | using namespace sevencore_fota; |
dudnwjs | 1:5cf3a6c969be | 38 | |
dudnwjs | 12:e3d3676753cc | 39 | |
dudnwjs | 12:e3d3676753cc | 40 | void FanTimer(void const *threadarg) |
dudnwjs | 12:e3d3676753cc | 41 | { |
dudnwjs | 12:e3d3676753cc | 42 | Timer_flag = 0; |
dudnwjs | 12:e3d3676753cc | 43 | Residual_Time = 0; |
dudnwjs | 12:e3d3676753cc | 44 | BleMsgHandler *BMH; |
dudnwjs | 12:e3d3676753cc | 45 | BMH = (struct BleMsgHandler *) threadarg; |
dudnwjs | 12:e3d3676753cc | 46 | while(true) |
dudnwjs | 12:e3d3676753cc | 47 | { |
dudnwjs | 12:e3d3676753cc | 48 | if( Timer_flag == 1 && Residual_Time == 0 ) |
dudnwjs | 12:e3d3676753cc | 49 | { |
dudnwjs | 12:e3d3676753cc | 50 | hostpc.printf("Power off!!\n"); |
dudnwjs | 13:e714e2971c49 | 51 | if( port21 == 1 || port22 == 1 ) |
dudnwjs | 13:e714e2971c49 | 52 | port21 = port22 = 0; |
dudnwjs | 12:e3d3676753cc | 53 | Timer_flag = 0; |
dudnwjs | 12:e3d3676753cc | 54 | /*{ |
dudnwjs | 12:e3d3676753cc | 55 | uint8_t fota_normal = 0; |
dudnwjs | 12:e3d3676753cc | 56 | uint8_t *msg; |
dudnwjs | 12:e3d3676753cc | 57 | struct fan_control_set_char_val_req char_set_req; |
dudnwjs | 12:e3d3676753cc | 58 | unsigned short msg_size = 1+sizeof(ble_hdr)+ sizeof(fan_control_set_char_val_req)-(4-FAN_CONTROL_MIN_SIZE); |
dudnwjs | 12:e3d3676753cc | 59 | // Fill in the parameter structure |
dudnwjs | 12:e3d3676753cc | 60 | char_set_req.char_code = FAN_CONTROL_POWER_STATE_CHAR; |
dudnwjs | 12:e3d3676753cc | 61 | char_set_req.val_len = FAN_CONTROL_MIN_SIZE; |
dudnwjs | 12:e3d3676753cc | 62 | memcpy(&char_set_req.val[0], &fota_normal, sizeof(fota_normal)); |
dudnwjs | 12:e3d3676753cc | 63 | |
dudnwjs | 12:e3d3676753cc | 64 | msg = new uint8_t[msg_size]; |
dudnwjs | 12:e3d3676753cc | 65 | |
dudnwjs | 12:e3d3676753cc | 66 | BMH->BleMsgAlloc(FAN_CONTROL_SET_CHAR_VAL_REQ |
dudnwjs | 12:e3d3676753cc | 67 | ,TASK_FAN_CONTROL, TASK_GTL |
dudnwjs | 12:e3d3676753cc | 68 | ,sizeof(struct fan_control_set_char_val_req)-(4-FAN_CONTROL_MIN_SIZE) |
dudnwjs | 12:e3d3676753cc | 69 | ,&char_set_req,msg ); |
dudnwjs | 12:e3d3676753cc | 70 | // Send the message |
dudnwjs | 12:e3d3676753cc | 71 | BMH->BleSendMsg(msg,msg_size); |
dudnwjs | 12:e3d3676753cc | 72 | free(msg); |
dudnwjs | 12:e3d3676753cc | 73 | } |
dudnwjs | 12:e3d3676753cc | 74 | */ |
dudnwjs | 12:e3d3676753cc | 75 | |
dudnwjs | 12:e3d3676753cc | 76 | } |
dudnwjs | 12:e3d3676753cc | 77 | |
dudnwjs | 12:e3d3676753cc | 78 | if( Timer_flag == 1 ) |
dudnwjs | 12:e3d3676753cc | 79 | { |
dudnwjs | 12:e3d3676753cc | 80 | osDelay(1000); |
dudnwjs | 12:e3d3676753cc | 81 | if(Residual_Time > 0){ |
dudnwjs | 12:e3d3676753cc | 82 | hostpc.printf("Residual Time = %d, minus 1 second!!\n",Residual_Time ); |
dudnwjs | 12:e3d3676753cc | 83 | Residual_Time--; |
dudnwjs | 12:e3d3676753cc | 84 | } |
dudnwjs | 12:e3d3676753cc | 85 | } |
dudnwjs | 12:e3d3676753cc | 86 | } |
dudnwjs | 12:e3d3676753cc | 87 | } |
dudnwjs | 12:e3d3676753cc | 88 | |
dudnwjs | 12:e3d3676753cc | 89 | void t0(void const *argument) {FanTimer(argument);} |
dudnwjs | 12:e3d3676753cc | 90 | osThreadDef(t0, osPriorityNormal, DEFAULT_STACK_SIZE); |
dudnwjs | 12:e3d3676753cc | 91 | |
dudnwjs | 7:3478c46cceef | 92 | void led_setting_one(void){ |
dudnwjs | 6:8dd20294b2aa | 93 | myled = 1; |
dudnwjs | 6:8dd20294b2aa | 94 | myled2 = 1; |
dudnwjs | 6:8dd20294b2aa | 95 | myled3 = 1; |
dudnwjs | 6:8dd20294b2aa | 96 | myled4 = 1; |
dudnwjs | 6:8dd20294b2aa | 97 | } |
dudnwjs | 6:8dd20294b2aa | 98 | |
dudnwjs | 7:3478c46cceef | 99 | void led_setting_zero(void){ |
dudnwjs | 12:e3d3676753cc | 100 | myled = 1; |
dudnwjs | 6:8dd20294b2aa | 101 | myled2 = 0; |
dudnwjs | 6:8dd20294b2aa | 102 | myled3 = 0; |
dudnwjs | 6:8dd20294b2aa | 103 | myled4 = 0; |
dudnwjs | 6:8dd20294b2aa | 104 | } |
dudnwjs | 6:8dd20294b2aa | 105 | |
dudnwjs | 6:8dd20294b2aa | 106 | int main() { |
dudnwjs | 8:9eec2c246a85 | 107 | wait(0.5); |
dudnwjs | 8:9eec2c246a85 | 108 | myled = 1; |
dudnwjs | 8:9eec2c246a85 | 109 | wait(0.5); |
dudnwjs | 8:9eec2c246a85 | 110 | myled = 0; |
dudnwjs | 8:9eec2c246a85 | 111 | wait(0.5); |
dudnwjs | 8:9eec2c246a85 | 112 | myled = 1; |
dudnwjs | 8:9eec2c246a85 | 113 | wait(0.5); |
dudnwjs | 8:9eec2c246a85 | 114 | myled = 0; |
dudnwjs | 8:9eec2c246a85 | 115 | wait(0.5); |
dudnwjs | 12:e3d3676753cc | 116 | led_setting_zero(); |
dudnwjs | 8:9eec2c246a85 | 117 | wait(0.5); |
dudnwjs | 5:e11b23f9aacc | 118 | hostpc.baud(9600); |
dudnwjs | 8:9eec2c246a85 | 119 | wait(0.5); |
dudnwjs | 3:1e70387e1337 | 120 | device.baud(115200); |
dudnwjs | 6:8dd20294b2aa | 121 | device.set_flow_control(device.RTSCTS,P2_7,p12); |
dudnwjs | 8:9eec2c246a85 | 122 | wait(0.5); |
dudnwjs | 3:1e70387e1337 | 123 | |
dudnwjs | 5:e11b23f9aacc | 124 | BleMsgHandler myfota(&device,&hostpc); |
dudnwjs | 12:e3d3676753cc | 125 | osThreadCreate( osThread(t0), (void *)&myfota ); |
dudnwjs | 6:8dd20294b2aa | 126 | |
dudnwjs | 1:5cf3a6c969be | 127 | myfota.PrintTitle(); |
dudnwjs | 3:1e70387e1337 | 128 | app_rst_gap(&myfota); |
dudnwjs | 3:1e70387e1337 | 129 | |
dudnwjs | 8:9eec2c246a85 | 130 | for(int i = 0; i < 200; i++) { |
dudnwjs | 4:60be78a172c2 | 131 | myfota.BleReceiveMsg(); |
dudnwjs | 4:60be78a172c2 | 132 | myfota.BleMsgHandle(); |
dudnwjs | 4:60be78a172c2 | 133 | } |
dudnwjs | 3:1e70387e1337 | 134 | |
dudnwjs | 0:a1f6b1ba8a1e | 135 | while(1) { |
dudnwjs | 0:a1f6b1ba8a1e | 136 | myled = 1; |
dudnwjs | 0:a1f6b1ba8a1e | 137 | wait(0.5); |
dudnwjs | 0:a1f6b1ba8a1e | 138 | myled = 0; |
dudnwjs | 0:a1f6b1ba8a1e | 139 | wait(0.5); |
dudnwjs | 0:a1f6b1ba8a1e | 140 | } |
dudnwjs | 5:e11b23f9aacc | 141 | |
dudnwjs | 0:a1f6b1ba8a1e | 142 | } |