/*=========================================================================== * ReadContinuousLogData *--------------------------------------------------------------------------- * Description: Puts the node in continuous mode, reads the sensor data and * prints to the screen and logs data to user file until the user * interrupts. * * Return: HANDLE - handle to the opened comport *===========================================================================*/ void ReadContinuousLogData(int portNum) { int iCount = 0; BOOL bStopContinuous = FALSE; DWORD dwcharsRead = 0; I3dmgx3Set Record; BYTE cmd_return; int Curs_posY = 0; int Curs_posX = 0; int status = 0; int error_record = 0; int valid_check = 0; int valid_count = 0; char consoleBuff[60] = {0}; long valid_rec = 0; unsigned char error_cmd; char ComLogFile[256]; FILE *m_logFile; int LogFlag = 0; int error_count = 0; int errorCode =0, i=0; char fw[20] = {0}; char sn[20] = {0}; char mListSep[4]; char mDecSep[4]; LANGID langId; char szLanguage[256]; /*MAX_PATH]; */ char idchar[] = {'\x02', '\x00', '\x01', '\x03', '\x04'}; int m_timerconst = 62500; unsigned long AA_Time_Stamp=0; unsigned long AA_s_prev =0; float AA_convert = 0.0; float AA_prev = 0.0; struct __timeb64 timebuffer; char *timeline; _ftime64( &timebuffer ); timeline = _ctime64( & ( timebuffer.time ) ); while (LogFlag != 1){ printf("Enter Name of LogFile to use:"); scanf("%s", &ComLogFile); // 255); printf("logFile %s\n", ComLogFile); if ( ( m_logFile= fopen( ComLogFile, "w")) == NULL){ printf("File: %s not opened\n", ComLogFile); if(++error_count > 2) return; }else LogFlag = 1; } fprintf(m_logFile, "[SESSION START TAG]\n"); fprintf(m_logFile, "Session Start Time:%.19s.%hu \n", timeline, timebuffer.millitm ); fprintf(m_logFile, "Time Source: HOST\n"); GetLocaleInfo(LOCALE_SYSTEM_DEFAULT,LOCALE_SLIST,mListSep,4); fprintf(m_logFile, "List Separator: %s\n", mListSep); GetLocaleInfo(LOCALE_SYSTEM_DEFAULT,LOCALE_SDECIMAL,mDecSep,4); fprintf(m_logFile, "Decimal Separator: %s\n", mDecSep); langId = GetSystemDefaultLangID (); i = VerLanguageName (langId, szLanguage, 256); //dwSize = MAX_PATH; fprintf(m_logFile, "Language: %s\n", szLanguage); while(valid_check == 0) { errorCode = i3dmgx3_getFirmwareVersion(portNum, &fw[0]); if (errorCode < 0){ purge_port(portNum); printf("Firmware Error %d\n",errorCode); if (valid_count++ > 6) { printf("Please Halt Current Data Display and Retry, count %d\n", valid_count); return; } }else if (errorCode >= 0){ valid_check = 1; } } /*------------------------------------------------------------------ * 0xEA get serial information number, model and options (as string) *-----------------------------------------------------------------*/ valid_count =0; for ( i=0; i<4; i++){ //cycles through the valid device options errorCode = i3dmgx3_getDeviceIdentiy(portNum, idchar[i], &sn[0]); if (errorCode < 0){ purge_port(portNum); i--; if (valid_count++ >6){ printf("Error Read Device Identity: %s\n", explainError(errorCode)); } } else{ switch( i ) { case 0: fprintf(m_logFile, "Device Name: %s\n",sn); break; case 1: fprintf(m_logFile, "Device Model: %s\n",sn); break; case 2: fprintf(m_logFile, "Device FirmWare Version: %s\n", fw); fprintf(m_logFile, "Device Serial Number: %s\n", sn); break; case 3: fprintf(m_logFile, "Device Options: %s\n", sn); break; case 4: default: break; } } } fprintf(m_logFile, "Command C2\n[DATA START TAG]\n\t Time%s Accel X%s Accel Y%s Accel Z%s AngRate X%s AngRate Y%s AngRate Z%s Ticks\n", mListSep, mListSep, mListSep, mListSep, mListSep, mListSep, mListSep); //put the node in continuous mode status =SetContinuousMode(portNum, 0xC2); printf("setcontinuous is %d", status); //set up the output for the data printf("\n\n"); printf("Reading streaming data (hit s to Stop streaming).\n"); printf("C2___________________________Acceleration_______________________________\n"); printf(" X Y Z \n"); /* acceleration values go here */ printf("\n\n\n"); printf("C2____________________________Angular_Rate______________________________\n"); printf(" X Y Z \n"); /* angle rate values go here */ getConXY(&Curs_posX, &Curs_posY); printf("\n\n\n\n"); //continue until the user hits the <s>top key while(!bStopContinuous) { if(ReadNextRecord(portNum, &Record, &cmd_return) != SUCCESS) error_record++; if (cmd_return == 0xC2){ if (AA_s_prev == 0){ fprintf(m_logFile, "\t 0.00"); AA_s_prev = Record.timer; //AA_Time_Stamp; } else { AA_convert = ((float)(Record.timer - AA_s_prev)/m_timerconst); //19660800); AA_s_prev = Record.timer; //AA_Time_Stamp; AA_prev = AA_prev + AA_convert; fprintf(m_logFile, "\t%6.2f", AA_prev); } //move to the acceleration position and print the data sprintf(consoleBuff, "\t%2.6f\t\t%2.6f\t\t%2.6f", Record.setA[0], Record.setA[1], Record.setA[2]); fprintf(m_logFile, "%s %2.6f%s %2.6f%s %2.6f%s ", mListSep, Record.setA[0],mListSep, Record.setA[1], mListSep, Record.setA[2], mListSep); setConXY(Curs_posX, Curs_posY -5, &consoleBuff[0]); sprintf(consoleBuff, "\t%2.6f\t\t%2.6f\t\t%2.6f", Record.setB[0], Record.setB[1], Record.setB[2]); fprintf(m_logFile, "%2.6f%s %2.6f%s %2.6f%s %u\n", Record.setB[0], mListSep, Record.setB[1], mListSep, Record.setB[2], mListSep, Record.timer); setConXY(Curs_posX, Curs_posY, &consoleBuff[0]); valid_rec++; }else if (cmd_return != 0xc4){ if((cmd_return == 0xCB || cmd_return == 0xD3) && error_record == 0) error_cmd = cmd_return; else error_record++; } //check for a key every 50 iterations if(iCount++ > 50) { int ch = 0; if(ReadCharNoReturn(&ch)){ bStopContinuous = (ch == 's' || ch == 'S'); } //reset the counter iCount = 0; } } printf("\n\n\nStopping Continuous Mode..."); StopContinuousMode(portNum); printf("stopped.\n"); fclose(m_logFile); if (error_record > 0) printf("Number of records received in error were %d and received successfully %d\n", error_record, valid_rec); else printf("All %d records read successfully.\n", valid_rec); }
int main() { CyGlobalIntEnable; /* Uncomment this line to enable global interrupts. */ XBee_UART_Start(); I2C_Start(); LCD_Start(); // INITIALIZE VALUES Command_Received = 0; MAG_DataRdy_Flag = 0; ReadyForCommand_Flag = 1; IncomingData_Flag = 0; StatusError_Flag = 0; //WaitForDataRead_Flag = 0; Command_Buffer = 0; // INITIALIZE ISRs InitXBee_Isr(); //InitINT1_Isr(); // IF INT1 TRIGGERS WHEN NOT IN ACTIVE MODE, MOVE INITIATION CODE FOR SETTING ACTIVE. //INT1_isr_Start(); XBee_UART_ClearRxBuffer(); XBee_UART_ClearTxBuffer(); CyDelay(2000); LCD_ClearDisplay(); LCD_Position(0,0); LCD_PrintString("MAG DRIVER:"); LCD_Position(1,0); LCD_PrintString("[ERR]"); LCD_Position(1,7); LCD_PrintString("[I2C]"); uint8 status = 0; status = SetCtrlReg1Default(); status |= SetCtrlReg2Default(); if(status !=0) { LCD_ClearDisplay(); LCD_Position(0,0); LCD_PrintInt8(status); status = 0; } uint8 pin_status = 0; for(;;) { pin_status = INT1_Pin_Read(); pin_status |= MAG_DataRdy_Flag; if(pin_status) { MAG_DataRdy_Flag = pin_status; if(ReadyForCommand_Flag!=0) { Command_Received = CMD_I_RM_MAGDATA; ReadyForCommand_Flag = 0; } } if(Command_Received != 0) { LCD_ClearDisplay(); //XBee_UART_ClearTxBuffer(); //XBee_UART_ClearRxBuffer(); switch (Command_Received){ case CMD_I_RM_MAGDATA: // CMD_I_RM_MAGDATA = 34 { status = ReadMagData(Global_ReadPtr); if(status == 0) { CyDelay(500); XBee_UART_PutChar(Command_Received); //LED_out_Write(0); CyDelay(500); XBee_UART_PutArray(Global_ReadPtr,ARRAY_SIZE_MAG_DATA); CyDelay(1000); //WaitForDataRead_Flag = 0; MAG_DataRdy_Flag = 0; if(Command_Buffer!=0) { Command_Received = Command_Buffer; Command_Buffer = 0; //ReadyForCommand_Flag = 0; //Dont toggle flag } else { Command_Received = 0; ReadyForCommand_Flag = 1; LED_out_Write(0); } } else { // will result is a halt of CMD processing and leaves LED lit (visual error signal) LCD_Position(1,0); LCD_PrintString("E:STA"); CyDelay(1000); StatusError_Flag = 1; } } break; case CMD_I_WM_OFFSET_ALL:// CMD_I_WM_OFFSET_ALL = 1 { if(IncomingData_Flag == 0) // IF THE OFFSET DATA TO WRITE HAS BEEN RECEIVED... { status = WriteOffsetCorrection(DataInPtr_Global); if(status == 0) { CyDelay(500); XBee_UART_PutChar(Command_Received); //Sends confirmation TWICE. Once after receiving CMD, and again after finishing WRITE LED_out_Write(0); Command_Received = 0; IncomingData_Flag = 0; ReadyForCommand_Flag = 1; } else { // will result is a halt of CMD processing and leaves LED lit (visual error signal) LCD_Position(1,0); LCD_PrintString("E:STA"); CyDelay(1000); StatusError_Flag = 1; } } } break; case CMD_I_RS_CTRL1://CMD_I_RS_CTRL1=35 { status = ReadCtrlReg1(Global_ReadPtr); if(status == 0) { CyDelay(500); XBee_UART_PutChar(Command_Received); LED_out_Write(0); CyDelay(500); XBee_UART_PutChar(Global_ReadBuffer[0]); // Send Read Value Command_Received = 0; IncomingData_Flag = 0; ReadyForCommand_Flag = 1; } else { // will result is a halt of CMD processing and leaves LED lit (visual error signal) LCD_Position(1,0); LCD_PrintString("E:STA"); CyDelay(1000); StatusError_Flag = 1; } } break; case CMD_I_RS_CTRL2://CMD_I_RS_CTRL2 = 36 { status = ReadCtrlReg2(Global_ReadPtr); if(status == 0) { CyDelay(500); XBee_UART_PutChar(Command_Received); LED_out_Write(0); CyDelay(500); XBee_UART_PutChar(Global_ReadBuffer[0]); // Send Read Value Command_Received = 0; IncomingData_Flag = 0; ReadyForCommand_Flag = 1; } else { // will result is a halt of CMD processing and leaves LED lit (visual error signal) LCD_Position(1,0); LCD_PrintString("E:STA"); CyDelay(1000); StatusError_Flag = 1; } } break; case CMD_I_RS_DRSTATUS://CMD_I_RS_DRSTATUS = 37 { status = ReadDrStatus(Global_ReadPtr); if(status == 0) { CyDelay(500); XBee_UART_PutChar(Command_Received); LED_out_Write(0); CyDelay(500); XBee_UART_PutChar(Global_ReadBuffer[0]); // Send Read Value Command_Received = 0; IncomingData_Flag = 0; ReadyForCommand_Flag = 1; } else { // will result is a halt of CMD processing and leaves LED lit (visual error signal) LCD_Position(1,0); LCD_PrintString("E:STA"); CyDelay(1000); StatusError_Flag = 1; } } break; case CMD_I_RS_SYSMOD:// CMD_I_RS_SYSMOD = 38 { status = ReadSysMod(Global_ReadPtr); if(status == 0) { CyDelay(500); XBee_UART_PutChar(Command_Received); LED_out_Write(0); CyDelay(500); XBee_UART_PutChar(Global_ReadBuffer[0]); Command_Received = 0; IncomingData_Flag = 0; ReadyForCommand_Flag = 1; } else { // will result is a halt of CMD processing and leaves LED lit (visual error signal) LCD_Position(1,0); LCD_PrintString("E:STA"); CyDelay(1000); StatusError_Flag = 1; } } break; case CMD_I_RS_DIETEMP: // CMD_I_RS_DIETEMP = 39 { status = ReadDieTemp(Global_ReadPtr); if(status == 0) { CyDelay(500); XBee_UART_PutChar(Command_Received); LED_out_Write(0); CyDelay(500); XBee_UART_PutChar(Global_ReadBuffer[0]); Command_Received = 0; IncomingData_Flag = 0; ReadyForCommand_Flag = 1; } else { // will result is a halt of CMD processing and leaves LED lit (visual error signal) LCD_Position(1,0); LCD_PrintString("E:STA"); CyDelay(1000); StatusError_Flag = 1; } } break; case CMD_I_RS_WHOAMI: // CMD_I_RS_WHOAMI = 40 { status = ReadWhoAmI(Global_ReadPtr); if(status == 0) { CyDelay(500); XBee_UART_PutChar(Command_Received); LED_out_Write(0); CyDelay(500); XBee_UART_PutChar(Global_ReadBuffer[0]); Command_Received = 0; IncomingData_Flag = 0; ReadyForCommand_Flag = 1; } else { // will result is a halt of CMD processing and leaves LED lit (visual error signal) LCD_Position(1,0); LCD_PrintString("E:STA"); CyDelay(1000); StatusError_Flag = 1; } } break; case CMD_I_WS_CTRL1_DEFAULT: // CMD_I_WS_CTRL1_DEFAULT = 41 { status = SetCtrlReg1Default(); if(status == 0) //if the write was a success { CyDelay(500); XBee_UART_PutChar(Command_Received);//Returns command received from MATLAB as confirmation LED_out_Write(0); //Turns off LED Command_Received = 0; //Clears the Command IncomingData_Flag = 0; ReadyForCommand_Flag = 1; // Sets state as READY for next command } else { // will result is a halt of CMD processing and leaves LED lit (visual error signal) LCD_Position(1,0); LCD_PrintString("E:STA"); CyDelay(1000); StatusError_Flag = 1; } } break; case CMD_I_WS_CTRL1_MODSTANDBY: // CMD_I_WS_CTRL1_MODSTANDBY = 42 { status = SetStandbyMode(); if(status == 0) //if the write was a success { CyDelay(500); XBee_UART_PutChar(Command_Received);//Returns command received from MATLAB as confirmation LED_out_Write(0); //Turns off LED Command_Received = 0; //Clears the Command IncomingData_Flag = 0; ReadyForCommand_Flag = 1; // Sets state as READY for next command } else { // will result is a halt of CMD processing and leaves LED lit (visual error signal) LCD_Position(1,0); LCD_PrintString("E:STA"); CyDelay(1000); StatusError_Flag = 1; } } break; case CMD_I_WS_CTRL1_MODSINGLE: // CMD_I_WS_CTRL1_MODSINGLE = 43 { status = SetSingleMeasurmentMode(); if(status == 0) //if the write was a success { CyDelay(500); XBee_UART_PutChar(Command_Received);//Returns command received from MATLAB as confirmation LED_out_Write(0); //Turns off LED Command_Received = 0; //Clears the Command IncomingData_Flag = 0; ReadyForCommand_Flag = 1; // Sets state as READY for next command } else { // will result is a halt of CMD processing and leaves LED lit (visual error signal) LCD_Position(1,0); LCD_PrintString("E:STA"); CyDelay(1000); StatusError_Flag = 1; } } break; //IF INT1 CONTINUES TO TRIGGER WHEN NOT IT ACTIVE MODE, DEACTIVATE/ACTIVATE ISR WHEN CHANGING MODES case CMD_I_WS_CTRL1_MODACTIVE: // CMD_I_WS_CTRL1_MODACTIVE = 44 { status = SetContinuousMode(); if(status == 0) //if the write was a success { CyDelay(500); XBee_UART_PutChar(Command_Received);//Returns command received from MATLAB as confirmation LED_out_Write(0); //Turns off LED Command_Received = 0; //Clears the Command IncomingData_Flag = 0; ReadyForCommand_Flag = 1; // Sets state as READY for next command } else { // will result is a halt of CMD processing and leaves LED lit (visual error signal) LCD_Position(1,0); LCD_PrintString("E:STA"); CyDelay(1000); StatusError_Flag = 1; } } break; case CMD_I_WS_CTRL1_MODTRIGGER: // CMD_I_WS_CTRL1_MODTRIGGER = 45 { status = SetTriggerMeasurmentMode(); if(status == 0) //if the write was a success { CyDelay(500); XBee_UART_PutChar(Command_Received);//Returns command received from MATLAB as confirmation LED_out_Write(0); //Turns off LED Command_Received = 0; //Clears the Command IncomingData_Flag = 0; ReadyForCommand_Flag = 1; // Sets state as READY for next command } else { // will result is a halt of CMD processing and leaves LED lit (visual error signal) LCD_Position(1,0); LCD_PrintString("E:STA"); CyDelay(1000); StatusError_Flag = 1; } } break; case CMD_I_WS_CTRL1_ENFAST: // CMD_I_WS_CTRL1_ENFAST = 46 { status = SetFastReadOn(); if(status == 0) //if the write was a success { CyDelay(500); XBee_UART_PutChar(Command_Received);//Returns command received from MATLAB as confirmation LED_out_Write(0); //Turns off LED Command_Received = 0; //Clears the Command IncomingData_Flag = 0; ReadyForCommand_Flag = 1; // Sets state as READY for next command } else { // will result is a halt of CMD processing and leaves LED lit (visual error signal) LCD_Position(1,0); LCD_PrintString("E:STA"); CyDelay(1000); StatusError_Flag = 1; } } break; case CMD_I_WS_CTRL1_NENFAST: //CMD_I_WS_CTRL1_NENFAST = 47 { status = SetFastReadOff(); if(status == 0) //if the write was a success { CyDelay(500); XBee_UART_PutChar(Command_Received);//Returns command received from MATLAB as confirmation LED_out_Write(0); //Turns off LED Command_Received = 0; //Clears the Command IncomingData_Flag = 0; ReadyForCommand_Flag = 1; // Sets state as READY for next command } else { // will result is a halt of CMD processing and leaves LED lit (visual error signal) LCD_Position(1,0); LCD_PrintString("E:STA"); CyDelay(1000); StatusError_Flag = 1; } } break; case CMD_I_WS_CTRL2_DEFAULT: //CMD_I_WS_CTRL2_DEFAULT = 48 { status = SetCtrlReg2Default(); if(status == 0) //if the write was a success { CyDelay(500); XBee_UART_PutChar(Command_Received);//Returns command received from MATLAB as confirmation LED_out_Write(0); //Turns off LED Command_Received = 0; //Clears the Command IncomingData_Flag = 0; ReadyForCommand_Flag = 1; // Sets state as READY for next command } else { // will result is a halt of CMD processing and leaves LED lit (visual error signal) LCD_Position(1,0); LCD_PrintString("E:STA"); CyDelay(1000); StatusError_Flag = 1; } } break; case CMD_I_WS_CTRL2_ENAUTORESET: // CMD_I_WS_CTRL2_ENAUTORESET = 49 { status = SetAutoResetOn(); if(status == 0) //if the write was a success { CyDelay(500); XBee_UART_PutChar(Command_Received);//Returns command received from MATLAB as confirmation LED_out_Write(0); //Turns off LED Command_Received = 0; //Clears the Command IncomingData_Flag = 0; ReadyForCommand_Flag = 1; // Sets state as READY for next command } else { // will result is a halt of CMD processing and leaves LED lit (visual error signal) LCD_Position(1,0); LCD_PrintString("E:STA"); CyDelay(1000); StatusError_Flag = 1; } } break; case CMD_I_WS_CTRL2_NENAUTORESET: // CMD_I_WS_CTRL2_NENAUTORESET = 50 { status = SetAutoResetOff(); if(status == 0) //if the write was a success { CyDelay(500); XBee_UART_PutChar(Command_Received);//Returns command received from MATLAB as confirmation LED_out_Write(0); //Turns off LED Command_Received = 0; //Clears the Command IncomingData_Flag = 0; ReadyForCommand_Flag = 1; // Sets state as READY for next command } else { // will result is a halt of CMD processing and leaves LED lit (visual error signal) LCD_Position(1,0); LCD_PrintString("E:STA"); CyDelay(1000); StatusError_Flag = 1; } } break; case CMD_I_WS_CTRL2_ENUSEROFFSET: // CMD_I_WS_CTRL2_ENUSEROFFSET = 51 { status = SetUserCorrectedData(); if(status == 0) //if the write was a success { CyDelay(500); XBee_UART_PutChar(Command_Received);//Returns command received from MATLAB as confirmation LED_out_Write(0); //Turns off LED Command_Received = 0; //Clears the Command IncomingData_Flag = 0; ReadyForCommand_Flag = 1; // Sets state as READY for next command } else { // will result is a halt of CMD processing and leaves LED lit (visual error signal) LCD_Position(1,0); LCD_PrintString("E:STA"); CyDelay(1000); StatusError_Flag = 1; } } break; case CMD_I_WS_CTRL2_NENUSEROFFSET: // CMD_I_WS_CTRL2_NENUSEROFFSET = 52 { status = SetRawData(); if(status == 0) //if the write was a success { CyDelay(500); XBee_UART_PutChar(Command_Received);//Returns command received from MATLAB as confirmation LED_out_Write(0); //Turns off LED Command_Received = 0; //Clears the Command IncomingData_Flag = 0; ReadyForCommand_Flag = 1; // Sets state as READY for next command } else { // will result is a halt of CMD processing and leaves LED lit (visual error signal) StatusError_Flag = 1; LCD_Position(1,0); LCD_PrintString("E:STA"); CyDelay(1000); StatusError_Flag = 1; } } break; case CMD_I_WS_CTRL2_RESETMAG: // CMD_I_WS_CTRL2_RESETMAG = 53 { status = ResetMag(); if(status == 0) //if the write was a success { CyDelay(1000); //LET MAGNETOMETER RESET PROCEDURE FINISH XBee_UART_PutChar(Command_Received);//Returns command received from MATLAB as confirmation LED_out_Write(0); //Turns off LED Command_Received = 0; //Clears the Command IncomingData_Flag = 0; ReadyForCommand_Flag = 1; // Sets state as READY for next command } else { // will result is a halt of CMD processing and leaves LED lit (visual error signal) //LCD_ClearDisplay(); LCD_Position(1,0); LCD_PrintString("E:STA"); CyDelay(1000); StatusError_Flag = 1; } } break; case CMD_I_RESET_ALL://54 { // RESET I2C uint8 i2c_status = I2C_MasterClearStatus(); //LCD_ClearDisplay(); LCD_Position(1,7); LCD_PrintInt8(i2c_status); I2C_MasterClearReadBuf(); I2C_MasterClearWriteBuf(); // Reset MAG CTRL REGISTERS status = SetCtrlReg1Default(); status |= SetCtrlReg2Default(); if(status == 0) //if the write was a success { CyDelay(500); XBee_UART_PutChar(Command_Received);//Returns command received from MATLAB as confirmation LED_out_Write(0); //Turns off LED Command_Received = 0; //Clears the Command IncomingData_Flag = 0; ReadyForCommand_Flag = 1; // Sets state as READY for next command } else { // will result is a halt of CMD processing and leaves LED lit (visual error signal) //LCD_ClearDisplay(); LCD_Position(1,0); LCD_PrintString("E:STA"); CyDelay(1000); StatusError_Flag = 1; } } break; default: //handles Set Sampling/Data rate CMDs, and Out of range errors { if((Command_Received >= (STARTOFRANGE_SET_SAMPLING_AND_RATE))&&(Command_Received < (STARTOFRANGE_SET_SAMPLING_AND_RATE + RANGESIZE_SET_SAMPLING_AND_RATE))) { uint8 offset = Command_Received-STARTOFRANGE_SET_SAMPLING_AND_RATE; offset *=DELTAVALS_SET_SAMP_AND_RATE; status = SetOverSampleAndDataRate(offset); if(status == 0) //if the write was a success { CyDelay(500); XBee_UART_PutChar(Command_Received);//Returns command received from MATLAB as confirmation LED_out_Write(0); //Turns off LED Command_Received = 0; //Clears the Command IncomingData_Flag = 0; ReadyForCommand_Flag = 1; // Sets state as READY for next command } else { // will result is a halt of CMD processing and leaves LED lit (visual error signal) StatusError_Flag = 1; //LCD_ClearDisplay(); LCD_Position(1,0); LCD_PrintString("E:STA"); CyDelay(1000); } } else // ERROR: CMD VALUE OUT OF RANGE (executed if not a CMD to set sampling/data rate) { //CLEAR EVERYTHING XBee_UART_ClearTxBuffer(); XBee_UART_ClearRxBuffer(); I2C_MasterClearReadBuf(); I2C_MasterClearWriteBuf(); Command_Received = 0; //Clears the Command IncomingData_Flag = 0; ReadyForCommand_Flag = 1; // Sets state as READY for next command XBee_UART_PutChar(CMD_O_CMDVALUEOUTOFRANGE); //Send error msg //LCD_ClearDisplay(); LCD_Position(1,0); LCD_PrintString("E:RAN"); CyDelay(1000); LED_out_Write(0); //Turns off LED } } } //END OF SWITCH-CASE }//end of IF statement encasing switch-case /*else // if(Command_Received == 0) { if((MAG_DataRdy_Flag==1) && (WaitForDataRead_Flag==0)) { //May change CMD_O_MAGDATARDY to simply be the same as CMD_I_RM_MAGDATA. //XBee_UART_ClearTxBuffer(); //LCD_ClearDisplay(); LCD_Position(1,0); LCD_PrintString("DRDY2"); XBee_UART_PutChar(CMD_O_MAGDATARDY);// CMD_O_MAGDATARDY = 55 WaitForDataRead_Flag = 1; //Prevents constant resending of notification to MATLAB INT1_isr_Disable(); } }*/ }//END OF FOR LOOP }//END OF MAIN
/*=========================================================================== * ReadContinuousData *--------------------------------------------------------------------------- * Description: Puts the node in continuous mode, reads the sensor data and * prints to the screen until the user interrupts. * * Return: HANDLE - handle to the opened comport *===========================================================================*/ void ReadContinuousData(int portNum) { int iCount = 0; BOOL bStopContinuous = FALSE; DWORD dwcharsRead = 0; I3dmgx3Set Record; BYTE cmd_return; int Curs_posY = 0; int Curs_posX = 0; int status = 0; int error_record = 0; char consoleBuff[60] = {0}; long valid_rec = 0; unsigned char error_cmd; //put the node in continuous mode status =SetContinuousMode(portNum, 0xC2); printf("setcontinuous is %d", status); //set up the output for the data printf("\n\n"); printf("Reading streaming data (hit s to Stop streaming).\n"); printf("C2___________________________Acceleration_______________________________\n"); printf(" X Y Z \n"); /* acceleration values go here, save the position */ printf("\n\n\n"); printf("C2____________________________Angular_Rate______________________________\n"); printf(" X Y Z \n"); /* angle rate values go here, save the position */ getConXY(&Curs_posX, &Curs_posY); printf("\n\n\n\n"); //continue until the user hits the s key while(!bStopContinuous) { if(ReadNextRecord(portNum, &Record, &cmd_return) != SUCCESS) error_record++; if (cmd_return == 0xC2){ //move to the acceleration position and print the data sprintf(consoleBuff, "\t%2.6f\t\t%2.6f\t\t%2.6f", Record.setA[0], Record.setA[1], Record.setA[2]); setConXY(Curs_posX, Curs_posY -5, &consoleBuff[0]); sprintf(consoleBuff, "\t%2.6f\t\t%2.6f\t\t%2.6f", Record.setB[0], Record.setB[1], Record.setB[2]); setConXY(Curs_posX, Curs_posY, &consoleBuff[0]); valid_rec++; }else if (cmd_return != 0xC4){ if((cmd_return == 0xCB || cmd_return == 0xD3) && error_record == 0) error_cmd = cmd_return; else error_record++; } //check for a key every 50 iterations if(iCount++ > 50) { int ch = 0; if(ReadCharNoReturn(&ch)){ bStopContinuous = (ch == 's' || ch == 'S'); } //reset the counter iCount = 0; } } printf("\n\n\nStopping Continuous Mode..."); StopContinuousMode(portNum); printf("stopped.\n"); if (error_record > 0) printf("Number of records received in error were %d and received successfully %d\n", error_record, valid_rec); else printf("All %d records read successfully.\n", valid_rec); }