CAC_smartcushion / Mbed OS AdiSense1000_V21_Smartcushion

Fork of Sean_AdiSense1000_V21 by Rohan Gurav

Committer:
nfathurr
Date:
Thu Oct 25 08:59:30 2018 +0000
Revision:
36:4aded4b4f060
Parent:
35:853be4d80ff3
modified output into one line

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