void LogToFile(DataBuffer* myBuf,char annotation, char* fileName) { int16_t currentBuf = myBuf->currentReadBuffer; //uint8_t write_buf[48]; UINT bw; /* open file */ if (FAT1_open(&fp, fileName, FA_OPEN_ALWAYS|FA_WRITE)!=FR_OK) { Err(/*OPEN_FILE_ERROR*/); } /* move to the end of the file */ if (FAT1_lseek(&fp, fp.fsize) != FR_OK || fp.fptr != fp.fsize) { Err(/*END_OF_FILE_ERROR*/); } /* write data */ write_buf[0] = '\0'; //time_t run_time; for(int cur_buf_index=0;cur_buf_index<BUFFER_SIZE;++cur_buf_index) { /** Time Components */ UTIL1_strcatNum8u(write_buf, sizeof(write_buf), myBuf->dataBuffer[currentBuf][cur_buf_index].time.hour); UTIL1_chcat(write_buf, sizeof(write_buf), ':'); UTIL1_strcatNum8u(write_buf, sizeof(write_buf), myBuf->dataBuffer[currentBuf][cur_buf_index].time.minute); UTIL1_chcat(write_buf, sizeof(write_buf), ':'); UTIL1_strcatNum8u(write_buf, sizeof(write_buf), myBuf->dataBuffer[currentBuf][cur_buf_index].time.second); UTIL1_chcat(write_buf, sizeof(write_buf), ':'); UTIL1_strcatNum8u(write_buf, sizeof(write_buf), myBuf->dataBuffer[currentBuf][cur_buf_index].time.milliBig); UTIL1_strcatNum8u(write_buf, sizeof(write_buf), myBuf->dataBuffer[currentBuf][cur_buf_index].time.milliSmall); UTIL1_chcat(write_buf, sizeof(write_buf), ','); ; /** Accelerometer Components */ UTIL1_strcatNum16s(write_buf, sizeof(write_buf), myBuf->dataBuffer[currentBuf][cur_buf_index].x); UTIL1_chcat(write_buf, sizeof(write_buf), ','); UTIL1_strcatNum16s(write_buf, sizeof(write_buf), myBuf->dataBuffer[currentBuf][cur_buf_index].y); UTIL1_chcat(write_buf, sizeof(write_buf), ','); UTIL1_strcatNum16s(write_buf, sizeof(write_buf), myBuf->dataBuffer[currentBuf][cur_buf_index].z); UTIL1_chcat(write_buf, sizeof(write_buf), ','); /** Annotation mode **/ UTIL1_chcat(write_buf, sizeof(write_buf), annotation); UTIL1_strcat(write_buf, sizeof(write_buf), (unsigned char*)"\n"); /** Write to file **/ if (FAT1_write(&fp, write_buf, UTIL1_strlen((char*)write_buf), &bw)!=FR_OK) { (void)FAT1_close(&fp); Err(/*WRITE_ERROR*/); } memset(write_buf,'\0',48); } if(myBuf->currentReadBuffer == currentBuf) myBuf->currentReadBuffer=-1; /* closing file */ (void)FAT1_close(&fp); }
static void LogToFile(int16_t x, int16_t y, int16_t z) { uint8_t write_buf[48]; UINT bw; TIMEREC time; /* open file */ if (FAT1_open(&fp, "./log.txt", FA_OPEN_ALWAYS|FA_WRITE)!=FR_OK) { Err(); } /* move to the end of the file */ if (FAT1_lseek(&fp, fp.fsize) != FR_OK || fp.fptr != fp.fsize) { Err(); } /* get time */ if (TmDt1_GetTime(&time)!=ERR_OK) { Err(); } /* write data */ write_buf[0] = '\0'; UTIL1_strcatNum8u(write_buf, sizeof(write_buf), time.Hour); UTIL1_chcat(write_buf, sizeof(write_buf), ':'); UTIL1_strcatNum8u(write_buf, sizeof(write_buf), time.Min); UTIL1_chcat(write_buf, sizeof(write_buf), ':'); UTIL1_strcatNum8u(write_buf, sizeof(write_buf), time.Sec); UTIL1_chcat(write_buf, sizeof(write_buf), '\t'); UTIL1_strcatNum16s(write_buf, sizeof(write_buf), x); UTIL1_chcat(write_buf, sizeof(write_buf), '\t'); UTIL1_strcatNum16s(write_buf, sizeof(write_buf), y); UTIL1_chcat(write_buf, sizeof(write_buf), '\t'); UTIL1_strcatNum16s(write_buf, sizeof(write_buf), z); UTIL1_strcat(write_buf, sizeof(write_buf), (unsigned char*)"\r\n"); if (FAT1_write(&fp, write_buf, UTIL1_strlen((char*)write_buf), &bw)!=FR_OK) { (void)FAT1_close(&fp); Err(); } /* closing file */ (void)FAT1_close(&fp); }