CAC_smartcushion / Mbed OS AdiSense1000_V21_Smartcushion

Fork of Sean_AdiSense1000_V21 by Rohan Gurav

Committer:
nfathurr
Date:
Mon Sep 24 11:39:35 2018 +0000
Revision:
34:029fc3b83f78
Child:
35:853be4d80ff3
v21

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nfathurr 34:029fc3b83f78 1
nfathurr 34:029fc3b83f78 2 #include "myproswift_eval.h"
nfathurr 34:029fc3b83f78 3
nfathurr 34:029fc3b83f78 4
nfathurr 34:029fc3b83f78 5 #include "mbed.h"
nfathurr 34:029fc3b83f78 6 #include "pc_interface.h"
nfathurr 34:029fc3b83f78 7 #include "ble_interface.h"
nfathurr 34:029fc3b83f78 8 #include "myproswift_periph.h"
nfathurr 34:029fc3b83f78 9
nfathurr 34:029fc3b83f78 10
nfathurr 34:029fc3b83f78 11 /***************************************************************
nfathurr 34:029fc3b83f78 12 * Function Name: MyProSwift_Command
nfathurr 34:029fc3b83f78 13 * Description : read a command from either PC or BLE interfaces
nfathurr 34:029fc3b83f78 14 * and handle accordingly
nfathurr 34:029fc3b83f78 15 ****************************************************************/
nfathurr 34:029fc3b83f78 16 int32_t MyProSwift_Command( bool bleActive )
nfathurr 34:029fc3b83f78 17 {
nfathurr 34:029fc3b83f78 18 uint32_t ret = 0;
nfathurr 34:029fc3b83f78 19 //init buffers to 0x00
nfathurr 34:029fc3b83f78 20 char msgBuffer[MSG_BUFFER_MAX_SIZE] = {0x00};
nfathurr 34:029fc3b83f78 21 char bleBuffer[BLE_BUFFER_MAX_SIZE] = {0x00};
nfathurr 34:029fc3b83f78 22
nfathurr 34:029fc3b83f78 23 //setup callback routine for pc
nfathurr 34:029fc3b83f78 24 volatile bool bPcMessageFlag = 0;
nfathurr 34:029fc3b83f78 25 ret = Pc_SetupReadLineCb( msgBuffer, MSG_BUFFER_MAX_SIZE, &bPcMessageFlag );
nfathurr 34:029fc3b83f78 26 if( ret != 0 ) {
nfathurr 34:029fc3b83f78 27 return ret;
nfathurr 34:029fc3b83f78 28 }
nfathurr 34:029fc3b83f78 29
nfathurr 34:029fc3b83f78 30 //setup callback routine for ble
nfathurr 34:029fc3b83f78 31 volatile bool bBleMessageReceived = 0;
nfathurr 34:029fc3b83f78 32 if( bleActive ) {
nfathurr 34:029fc3b83f78 33 //read first byte
nfathurr 34:029fc3b83f78 34 ret = Bl652_SetupReadCb( bleBuffer, 1, &bBleMessageReceived );
nfathurr 34:029fc3b83f78 35 if( ret != 0 ) {
nfathurr 34:029fc3b83f78 36 ADI_SENSE_LOG_INFO("Ble Message Read Unsuccesful!");
nfathurr 34:029fc3b83f78 37 return ret;
nfathurr 34:029fc3b83f78 38 }
nfathurr 34:029fc3b83f78 39 }
nfathurr 34:029fc3b83f78 40
nfathurr 34:029fc3b83f78 41 //poll ble and pc flag
nfathurr 34:029fc3b83f78 42 while( !bBleMessageReceived /*&& !bPcMessageFlag */ )
nfathurr 34:029fc3b83f78 43 ;//add mbed abstracted sleep function
nfathurr 34:029fc3b83f78 44
nfathurr 34:029fc3b83f78 45 //clear ble callbacks if needed
nfathurr 34:029fc3b83f78 46 if( bleActive ) {
nfathurr 34:029fc3b83f78 47 ret = Bl652_ClearCb();
nfathurr 34:029fc3b83f78 48 if( ret != 0 ) {
nfathurr 34:029fc3b83f78 49 return ret;
nfathurr 34:029fc3b83f78 50 }
nfathurr 34:029fc3b83f78 51 }
nfathurr 34:029fc3b83f78 52
nfathurr 34:029fc3b83f78 53 //clear pc callbacks always
nfathurr 34:029fc3b83f78 54 ret = Pc_ClearReadLineCb();
nfathurr 34:029fc3b83f78 55 if( ret != 0 ) {
nfathurr 34:029fc3b83f78 56 return ret;
nfathurr 34:029fc3b83f78 57 }
nfathurr 34:029fc3b83f78 58
nfathurr 34:029fc3b83f78 59 //handle message based on which interface it was received from
nfathurr 34:029fc3b83f78 60 if( bBleMessageReceived ) {
nfathurr 34:029fc3b83f78 61 //parse and handle command
nfathurr 34:029fc3b83f78 62 ADI_SENSE_LOG_INFO("Ble Message Received!");
nfathurr 34:029fc3b83f78 63 ret = Ble_ParseCommand( bleBuffer );
nfathurr 34:029fc3b83f78 64 ADI_SENSE_LOG_INFO("Command Parsed!");
nfathurr 34:029fc3b83f78 65 if(ret != 0) {
nfathurr 34:029fc3b83f78 66 //all ble side error handled within function as responses
nfathurr 34:029fc3b83f78 67 return ret;
nfathurr 34:029fc3b83f78 68 }
nfathurr 34:029fc3b83f78 69 }
nfathurr 34:029fc3b83f78 70
nfathurr 34:029fc3b83f78 71 else if(bPcMessageFlag) {
nfathurr 34:029fc3b83f78 72 //parse and handle command
nfathurr 34:029fc3b83f78 73 ret = Pc_ParseCommand( msgBuffer );
nfathurr 34:029fc3b83f78 74 if( ret != 0 ) {
nfathurr 34:029fc3b83f78 75 //all pc side error handled within function as responses
nfathurr 34:029fc3b83f78 76 return ret;
nfathurr 34:029fc3b83f78 77 }
nfathurr 34:029fc3b83f78 78 }
nfathurr 34:029fc3b83f78 79
nfathurr 34:029fc3b83f78 80 return 0;
nfathurr 34:029fc3b83f78 81 }