void sonic_SDsave(int sonicx, const char *f_name, int ndata) { FRESULT res; u8 _sonicx = 0; char *_f_name = f_namecrt(f_name); extern struct rt_thread *rt_current_thread; /* enable the sonic */ _sonicx = 0x01<<(sonicx-1); SONICx_ENABLE(_sonicx); res = f_open (&sonic_file[sonicx-1], _f_name, FA_OPEN_ALWAYS | FA_READ | FA_WRITE); f_lseek(&sonic_file[sonicx-1], sonic_file[sonicx-1].fsize); if(res != FR_OK) {LCD_ERROR(); anyKey(0, "file open err:%d", res); return;} SD_Printf2(&sonic_file[sonicx-1], "-------------------------------------------"); SD_Printf2(&sonic_file[sonicx-1], "-->date:%s", __DATE__); SD_Printf2(&sonic_file[sonicx-1], "-->time:%s", __TIME__); SD_Printf2(&sonic_file[sonicx-1], "-->thread:%s", rt_current_thread->name); SD_Printf2(&sonic_file[sonicx-1], "sonic%d data", sonicx); while(ndata-- >0) { SD_Printf2(&sonic_file[sonicx-1], "%d,", sonic_data[sonicx-1].data); Delay_ms(5*6); LCD_Clear(); LCD_SetXY(0, 0); LCD_Printf("sonic data saving : %d", sonic_data[sonicx-1].data); } SD_Printf2(&sonic_file[sonicx-1], "-------------------------------------------"); SD_Printf2(&sonic_file[sonicx-1], ""); SD_Printf2(&sonic_file[sonicx-1], ""); f_close(&sonic_file[sonicx-1]); f_timestamp(_f_name); SONICx_DISABLE(_sonicx); }
static void _can_senddata(CAN_TypeDef *canx, CanTxMsg *tx) { u8 wait_time = 0; while(CAN_Transmit(canx, tx)==CAN_NO_MB && wait_time<6) { wait_time ++; Delay_ms(5); } /* delay 30ms */ if(wait_time>=6) { extern struct rt_thread *rt_current_thread; int i; LCD_Clear(); LCD_SetXY(2, 3); LCD_Printf("can send timeout!"); f_open (&can_send_file, "can_errInfo.txt", FA_OPEN_ALWAYS | FA_READ | FA_WRITE); f_lseek(&can_send_file, can_send_file.fsize); SD_Printf2(&can_send_file, ""); SD_Printf2(&can_send_file, "-----------------------------------------------"); SD_Printf2(&can_send_file, "-->date:%s", __DATE__); SD_Printf2(&can_send_file, "-->time:%s", __TIME__); SD_Printf2(&can_send_file, "-->tick:%d", rt_tick_get()); SD_Printf2(&can_send_file, "-->thread:%s", rt_current_thread->name); SD_Printf2(&can_send_file, "-->GPS:"); SD_Printf2(&can_send_file, " >x:%f", GPS.position.x); SD_Printf2(&can_send_file, " >y:%f", GPS.position.y); SD_Printf2(&can_send_file, " >a:%f", GPS.radian); SD_Printf2(&can_send_file, "-->txMsg:"); SD_Printf2(&can_send_file, " >ID :%d", tx->StdId); SD_Printf2(&can_send_file, " >len :%d", tx->DLC); SD_Printf2(&can_send_file, " >data", tx->DLC); for(i=0; i<tx->DLC; i++) SD_Printf(&can_send_file, " %x", tx->Data[i]); SD_Printf2(&can_send_file, ""); SD_Printf2(&can_send_file, "-----------------------------------------------"); SD_Printf2(&can_send_file, ""); f_close(&can_send_file); Delay_ms(500); } }