Hand in place of the asterisk

Work on SD-card logs. No more f_open and f_close in flight (could take up to 400ms!)
SD-card logs now closed on shutdown
This commit is contained in:
bsongis
2012-05-30 11:28:14 +00:00
parent 68d8fa7794
commit ed8379c44b
11 changed files with 110 additions and 148 deletions
+5 -5
View File
@@ -1,5 +1,5 @@
27,32,
0xe0,0xf8,0xfc,0xfc,0xfc,0x7c,0x78,0x78,0x70,0x70,0x60,0xe0,0xc0,0xc0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xff,0xff,0xff,0xff,0xff,0xfc,0xf0,0xc0,0x00,0x00,0x80,0x87,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xfe,0xfc,0xfc,0xf8,0xf8,0xf0,0xf0,0xe0,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf3,0xe1,0xe1,0xe1,0xe1,0xf3,0xff,0x7f,0x3f,0x3f,0x1f,0x0f,0x0f,0x07,0x03,0x03,0x01,0x00,
0x07,0x1f,0x3f,0x3f,0x3f,0x3f,0x1f,0x1f,0x0f,0x07,0x07,0x03,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
27,32,
0xfc,0x04,0x04,0x04,0x04,0x04,0x04,0x84,0xc4,0x84,0x04,0xe4,0xf4,0xe4,0x04,0x84,0xc4,0xc4,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0xfc,
0xff,0x00,0x00,0x00,0xfc,0xfe,0x00,0xff,0xff,0xff,0x80,0xff,0xff,0xff,0x80,0xff,0xff,0xff,0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0xff,
0xff,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf8,0xfc,0xff,0x3f,0x0f,0x03,0x00,0x00,0xff,
0x3f,0x20,0x20,0x20,0x21,0x27,0x27,0x2f,0x2f,0x2f,0x2b,0x27,0x2f,0x2f,0x2f,0x2f,0x2f,0x2f,0x27,0x23,0x20,0x20,0x20,0x20,0x20,0x20,0x3f,
+14 -14
View File
@@ -1,14 +1,14 @@
#define asterisk_width 27
#define asterisk_height 32
static unsigned char asterisk_bits[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00,
0xfe, 0x00, 0x00, 0x00, 0xfe, 0x03, 0x00, 0x00, 0xff, 0x0f, 0x00, 0x00,
0xff, 0x3f, 0x00, 0x00, 0x1f, 0xf8, 0x00, 0x00, 0x1f, 0xf8, 0x03, 0x00,
0x1f, 0xf8, 0x0f, 0x00, 0x3f, 0xf8, 0x3f, 0x00, 0x3f, 0xf0, 0xff, 0x00,
0x7f, 0xf0, 0xff, 0x03, 0x7f, 0xf0, 0xff, 0x07, 0xff, 0xf0, 0xff, 0x07,
0xff, 0xfc, 0xff, 0x07, 0xff, 0xff, 0xff, 0x03, 0xff, 0xc3, 0xff, 0x01,
0xff, 0x81, 0x7f, 0x00, 0xff, 0x81, 0x3f, 0x00, 0xff, 0xc3, 0x0f, 0x00,
0xff, 0xff, 0x07, 0x00, 0xff, 0xff, 0x01, 0x00, 0xff, 0xff, 0x00, 0x00,
0xff, 0x3f, 0x00, 0x00, 0xff, 0x0f, 0x00, 0x00, 0xff, 0x07, 0x00, 0x00,
0xfe, 0x01, 0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
#define asterisk_width 27
#define asterisk_height 32
static unsigned char asterisk_bits[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x07,
0x01, 0x00, 0x00, 0x04, 0x01, 0x10, 0x00, 0x04, 0x01, 0x38, 0x00, 0x04,
0x01, 0x39, 0x03, 0x04, 0x81, 0xbb, 0x03, 0x04, 0x81, 0xbb, 0x03, 0x04,
0xa1, 0xbb, 0x03, 0x04, 0xb1, 0xbb, 0x03, 0x04, 0xb1, 0xbb, 0x03, 0x04,
0xb1, 0xbb, 0x03, 0x04, 0xb1, 0xbb, 0x03, 0x04, 0xb1, 0xbb, 0x03, 0x04,
0xb1, 0xff, 0xe3, 0x04, 0xf1, 0xff, 0xf3, 0x04, 0xf1, 0xff, 0xf3, 0x04,
0xf1, 0xff, 0x7b, 0x04, 0xf1, 0xff, 0x7f, 0x04, 0xf1, 0xff, 0x3f, 0x04,
0xf1, 0xff, 0x3f, 0x04, 0xf1, 0xff, 0x1f, 0x04, 0xf1, 0xff, 0x1f, 0x04,
0xf1, 0xff, 0x0f, 0x04, 0xe1, 0xff, 0x0f, 0x04, 0xe1, 0xfb, 0x07, 0x04,
0x81, 0xf7, 0x03, 0x04, 0x01, 0x00, 0x00, 0x04, 0xff, 0xff, 0xff, 0x07,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
-4
View File
@@ -506,10 +506,6 @@ void eeLoadModel(uint8_t id)
resetProto();
resetAll();
#if 0
initLogs();
#endif
}
}
+17 -2
View File
@@ -546,17 +546,22 @@ const pm_char * eeBackupModel(uint8_t i_fileSrc)
}
#endif
wdt_reset();
// check and create folder here
strcpy_P(buf, STR_MODELS_PATH);
#ifndef SIMU
result = f_opendir(&archiveFolder, buf);
if (result != FR_OK) {
result = f_mkdir(buf);
if (result == FR_NO_PATH)
result = f_mkdir(buf);
if (result != FR_OK)
return SDCARD_ERROR(result);
}
#endif
wdt_reset();
buf[sizeof(MODELS_PATH)-1] = '/';
eeLoadModelName(i_fileSrc, &buf[sizeof(MODELS_PATH)]);
buf[sizeof(MODELS_PATH)+FILENAME_MAXLEN] = '\0';
@@ -595,6 +600,8 @@ const pm_char * eeBackupModel(uint8_t i_fileSrc)
return SDCARD_ERROR(result);
}
wdt_reset();
result = f_write(&archiveFile, &g_eeGeneral.myVers, 1, &written);
if (result != FR_OK) {
return SDCARD_ERROR(result);
@@ -608,6 +615,7 @@ const pm_char * eeBackupModel(uint8_t i_fileSrc)
if (result != FR_OK) {
return SDCARD_ERROR(result);
}
wdt_reset();
}
f_close(&archiveFile);
@@ -625,6 +633,8 @@ const pm_char * eeRestoreModel(uint8_t i_fileDst, char *model_name)
return SDCARD_ERROR(result);
}
wdt_reset();
strcpy_P(buf, STR_MODELS_PATH);
buf[sizeof(MODELS_PATH)-1] = '/';
strcpy(&buf[sizeof(MODELS_PATH)], model_name);
@@ -662,6 +672,7 @@ const pm_char * eeRestoreModel(uint8_t i_fileDst, char *model_name)
s_sync_write = false;
return STR_EEPROMOVERFLOW;
}
wdt_reset();
}
} while (read == 15);
@@ -853,6 +864,10 @@ void eeLoadModel(uint8_t id)
{
if (id<MAX_MODELS) {
#ifdef SDCARD
closeLogs();
#endif
if (pulsesStarted()) {
pausePulses();
}
@@ -882,7 +897,7 @@ void eeLoadModel(uint8_t id)
resetAll();
#ifdef SDCARD
initLogs();
openLogs();
#endif
}
}
+1 -1
View File
@@ -181,7 +181,7 @@ void audioQueue::event(uint8_t e, uint8_t f)
if (g_eeGeneral.flashBeep && (e <= AU_ERROR || e >= AU_WARNING1)) {
if (g_LightOffCounter < FLASH_DURATION)
g_LightOffCounter = FLASH_DURATION;
g_LightOffCounter = FLASH_DURATION;
}
if (g_eeGeneral.beeperMode>0 || (g_eeGeneral.beeperMode==0 && e>=AU_TRIM_MOVE) || (g_eeGeneral.beeperMode>=-1 && e<=AU_ERROR)) {
+63 -117
View File
@@ -37,141 +37,94 @@
char g_logFilename[21]; // "/O9XLOGS/M00_000.CSV\0" max required length = 21
FATFS g_FATFS_Obj; // TODO not here
FIL g_oLogFile;
int8_t g_logState = 0; // 0=closed, >0=opened, <0=error
const pm_char * g_logError = NULL;
// TODO initSDCard()
void initLogs()
const pm_char * openLogs()
{
// Determine and set log file filename
FRESULT result;
DIR folder;
char *buf = g_logFilename;
// close any file left open. E.G. Changing models with log switch still on.
if (g_oLogFile.fs) f_close(&g_oLogFile);
g_logState = 0;
strcpy_P(g_logFilename, PSTR(LOGS_PATH "/M00_000.CSV"));
// Set log file model number
uint8_t num = g_eeGeneral.currModel + 1;
char *n = &g_logFilename[sizeof(LOGS_PATH) + 2];
*n = (char)((num % 10) + '0');
*(--n) = (char)((num / 10) + '0');
result = f_mount(0, &g_FATFS_Obj);
if (result!=FR_OK)
{
g_logState = -result;
g_logError = PSTR("SDCARD F/S ERROR");
return;
if (result != FR_OK) {
return SDCARD_ERROR(result);
}
DIR dir;
result = f_opendir(&dir, MODELS_PATH);
wdt_reset();
strcpy_P(buf, STR_LOGS_PATH);
result = f_opendir(&folder, buf);
if (result != FR_OK) {
if (result == FR_NO_PATH)
result = f_mkdir(MODELS_PATH);
if (result != FR_OK) {
g_logState = -result;
g_logError = PSTR("Check " MODELS_PATH " folder");
return;
}
result = f_mkdir(buf);
if (result != FR_OK)
return SDCARD_ERROR(result);
}
// Loop, skipping over any existing log files ... _000, _001, etc. until we have a unique file name
while (1)
{
result = f_open(&g_oLogFile, g_logFilename, FA_OPEN_EXISTING | FA_READ);
if (result == FR_OK)
{
f_close(&g_oLogFile);
wdt_reset();
// bump log file counter (file extension)
n = &g_logFilename[sizeof(LOGS_PATH) + 6];
if (++*n > '9')
{
*n='0';
n--;
if (++*n > '9')
{
*n='0';
n--;
if (++*n > '9')
{
*n='0';
break; // Wow. We looped back around past 999 to 000! abort loop
}
}
}
}
else if (result == FR_NO_FILE /*TODO check this code*/)
{
break;
}
else if (result == FR_NO_PATH)
{
if (f_mkdir(LOGS_PATH) != FR_OK)
{
g_logState = -result;
g_logError = PSTR("Check " LOGS_PATH " folder");
return;
}
}
else
{
g_logState = -result;
g_logError = SDCARD_ERROR(result);
return;
buf[sizeof(LOGS_PATH)-1] = '/';
memcpy(&buf[sizeof(LOGS_PATH)], g_model.name, sizeof(g_model.name));
buf[sizeof(LOGS_PATH)+FILENAME_MAXLEN] = '\0';
uint8_t i = sizeof(LOGS_PATH)+FILENAME_MAXLEN-1;
uint8_t len = 0;
while (i>sizeof(LOGS_PATH)-1) {
if (!len && buf[i])
len = i+1;
if (len) {
if (buf[i])
buf[i] = idx2char(buf[i]);
else
buf[i] = '_';
}
i--;
}
// g_logFilename should now be set appropriately.
if (len == 0) {
uint8_t num = g_eeGeneral.currModel + 1;
strcpy_P(&buf[sizeof(LOGS_PATH)], STR_MODEL);
buf[sizeof(LOGS_PATH) + PSIZE(TR_MODEL)] = (char)((num / 10) + '0');
buf[sizeof(LOGS_PATH) + PSIZE(TR_MODEL) + 1] = (char)((num % 10) + '0');
len = sizeof(LOGS_PATH) + PSIZE(TR_MODEL) + 2;
}
strcpy_P(&buf[len], STR_LOGS_EXT);
result = f_open(&g_oLogFile, buf, FA_OPEN_ALWAYS | FA_WRITE);
if (result != FR_OK) {
return SDCARD_ERROR(result);
}
if (g_oLogFile.fsize == 0) {
f_puts("Date,Time,Buffer,RX,TX,A1,A2,", &g_oLogFile);
if (g_model.frsky.usrProto == USR_PROTO_FRSKY_HUB)
f_puts("GPS Date,GPS Time,Long,Lat,Course,GPS Speed,GPS Alt,Baro Alt,Temp1,Temp2,RPM,Fuel,Volts,AccelX,AccelY,AccelZ,", &g_oLogFile);
f_puts("Rud,Ele,Thr,Ail,P1,P2,P3,THR,RUD,ELE,ID0,ID1,ID2,AIL,GEA,TRN\n", &g_oLogFile);
}
result = f_lseek(&g_oLogFile, g_oLogFile.fsize); // append
if (result != FR_OK) {
return SDCARD_ERROR(result);
}
return NULL;
}
void closeLogs()
{
f_close(&g_oLogFile);
}
void writeLogs()
{
FRESULT result;
if (isFunctionActive(FUNC_LOGS))
if (g_oLogFile.fs && isFunctionActive(FUNC_LOGS))
{
if (g_logState==0)
{
result = f_mount(0, &g_FATFS_Obj);
if (result != FR_OK)
{
g_logState = -result;
// TODO beepAgain = result - 1;
AUDIO_WARNING2();
}
else
{
// create new log file using filename set up in initLogs()
result = f_open(&g_oLogFile, g_logFilename, FA_OPEN_ALWAYS | FA_WRITE);
if (result != FR_OK)
{
g_logState = -result;
// TODO beepAgain = result - 1; // TODO FOR DEBUG -- count out error_number beeps
AUDIO_KEYPAD_UP();
}
else
{
if (g_oLogFile.fsize == 0) {
// if data type == Hub TODO
f_puts("Date,Time,Buffer,RX,TX,A1,A2,", &g_oLogFile);
if (g_model.frsky.usrProto == USR_PROTO_FRSKY_HUB)
f_puts("GPS Date,GPS Time,Long,Lat,Course,GPS Speed,GPS Alt,Baro Alt,Temp1,Temp2,RPM,Fuel,Volts,AccelX,AccelY,AccelZ,", &g_oLogFile);
f_puts("Rud,Ele,Thr,Ail,P1,P2,P3,THR,RUD,ELE,ID0,ID1,ID2,AIL,GEA,TRN\n", &g_oLogFile);
}
f_lseek(&g_oLogFile, g_oLogFile.fsize); // append
g_logState = 1;
AUDIO_WARNING2();
}
}
}
if (g_logState>0)
{
static struct gtm t;
struct gtm *at = &t;
filltm(&g_unixTime, &t);
@@ -223,13 +176,6 @@ void writeLogs()
// TODO Don't close the log file here. We have 'soft off' available on the v4.1 board. Once
// that is implemented, it can take care of closing the file, should the radio be
// powered off before the FUNC SWITCH is turned off.
}
}
else if (g_logState > 0)
{
f_close(&g_oLogFile);
AUDIO_WARNING2();
g_logState = 0;
}
}
+4 -3
View File
@@ -42,15 +42,16 @@
#include "gtime.h"
#define LOGS_PATH "/9XLOGS" // no trailing slash = important
#define LOGS_EXT ".CSV"
#define MODELS_PATH "/9XMODELS"
#define MODELS_EXT ".bin"
#define MODELS_EXT ".BIN"
extern char g_logFilename[21]; // "/9XLOGS/M00_000.CSV\0" max required length = 21
extern int8_t g_logState; // 0=closed, >0 = opened, <0 is error
extern FATFS g_FATFS_Obj;
extern FIL g_oLogFile;
extern void initLogs();
extern const pm_char * openLogs();
extern void closeLogs();
extern void writeLogs();
inline const pm_char *SDCARD_ERROR(FRESULT result)
+1
View File
@@ -145,6 +145,7 @@ bool listSDcardModels()
FRESULT res = f_opendir(&dir, MODELS_PATH); /* Open the directory */
if (res == FR_OK) {
for (;;) {
wdt_reset();
res = f_readdir(&dir, &fno); /* Read a directory item */
if (res != FR_OK || fno.fname[0] == 0) break; /* Break on error or end of dir */
if (fno.fname[0] == '.') continue; /* Ignore dot entry */
+1
View File
@@ -314,6 +314,7 @@ const pm_char STR_RESTORE_MODEL[] PROGMEM = TR_RESTORE_MODEL;
const pm_char STR_SDCARD_ERROR[] PROGMEM = TR_SDCARD_ERROR;
const pm_char STR_NO_SDCARD[] PROGMEM = TR_NO_SDCARD;
const pm_char STR_LOGS_PATH[] PROGMEM = LOGS_PATH;
const pm_char STR_LOGS_EXT[] PROGMEM = LOGS_EXT;
const pm_char STR_MODELS_PATH[] PROGMEM = MODELS_PATH;
const pm_char STR_MODELS_EXT[] PROGMEM = MODELS_EXT;
#endif
+1
View File
@@ -389,6 +389,7 @@ extern const pm_char STR_RESTORE_MODEL[];
extern const pm_char STR_SDCARD_ERROR[];
extern const pm_char STR_NO_SDCARD[];
extern const pm_char STR_LOGS_PATH[];
extern const pm_char STR_LOGS_EXT[];
extern const pm_char STR_MODELS_PATH[];
extern const pm_char STR_MODELS_EXT[];
#define STR_UPDATE_LIST STR_DELAYDOWN
+3 -2
View File
@@ -2370,8 +2370,6 @@ ISR(TIMER3_CAPT_vect) // G: High frequency noise can cause stack overflo with IS
#endif
}
extern uint16_t g_timeMain;
/*
// gruvin: Fuse declarations work if we use the .elf file for AVR Studio (v4)
// instead of the Intel .hex files. They should also work with AVRDUDE v5.10
@@ -2765,6 +2763,9 @@ int main(void)
g_eeGeneral.unexpectedShutdown=0;
eeDirty(EE_GENERAL);
eeCheck(true);
#if defined(SDCARD)
closeLogs();
#endif
lcd_clear() ;
refreshDisplay() ;
soft_power_off(); // Only turn power off if necessary