Logs port from gruvin9x

JETI ok on simu
Sticks mode problem in Trims2Offsets function
PXX bug fix pulled from er9x
Optimizations
This commit is contained in:
bsongis
2012-02-21 16:36:57 +00:00
parent 97723c5732
commit 6f1f234b40
11 changed files with 155 additions and 52 deletions
+4 -3
View File
@@ -139,10 +139,11 @@ inline void getGpsDistance()
inline int8_t parseTelemHubIndex(uint8_t index)
{
if (index > 0x3b)
index = 255; // invalid index
if (index > 0x39)
if (index > 0x39) {
if (index > 0x3b)
return -1; // invalid index
index -= 17;
}
return index*2;
}
+5 -3
View File
@@ -37,7 +37,7 @@ uint16_t jeti_keys = JETI_KEY_NOCHANGE;
uint8_t JetiBuffer[32]; // 32 characters
uint8_t JetiBufferReady;
#ifndef SIMU
ISR (USART0_RX_vect)
{
uint8_t stat;
@@ -76,8 +76,7 @@ ISR (USART0_RX_vect)
}
}
#endif
void JETI_Init (void)
{
@@ -87,6 +86,8 @@ void JETI_Init (void)
DDRE &= ~(1 << DDE0); // set RXD0 pin as input
PORTE &= ~(1 << PORTE0); // disable pullup on RXD0 pin
#ifndef SIMU
#undef BAUD
#define BAUD 9600
#include <util/setbaud.h>
@@ -102,6 +103,7 @@ void JETI_Init (void)
// flush receive buffer
while ( UCSR0A & (1 << RXC0) ) UDR0;
#endif
}
+64 -22
View File
@@ -33,15 +33,13 @@
#include "open9x.h"
#include "ff.h"
// "/G9XLOGS/M00_000.TXT\0" max required length = 21
char g_logFilename[22];
// These global so we can close any open file from anywhere
FATFS FATFS_Obj;
char g_logFilename[21]; // "/O9XLOGS/M00_000.CSV\0" max required length = 21
FATFS g_FATFS_Obj;
FIL g_oLogFile;
int8_t g_logState = 0; // 0=closed, >0=opened, <0=error
const pm_char * g_logError = NULL;
void startLogs()
void initLogs()
{
// Determine and set log file filename
FRESULT result;
@@ -50,22 +48,23 @@ void startLogs()
if (g_oLogFile.fs) f_close(&g_oLogFile);
g_logState = 0;
strcpy_P(g_logFilename, PSTR("/G9XLOGS/M00_000.TXT"));
strcpy_P(g_logFilename, PSTR(LOG_PATH "M00_000.CSV"));
// Set log file model number
uint8_t num = g_eeGeneral.currModel + 1;
char *n = &g_logFilename[11];
char *n = &g_logFilename[11]; // TODO constant
*n = (char)((num % 10) + '0');
*(--n) = (char)((num / 10) + '0');
result = f_mount(0, &FATFS_Obj);
result = f_mount(0, &g_FATFS_Obj);
if (result!=FR_OK)
{
strcpy_P(g_logFilename, PSTR("FILE SYSTEM ERROR"));
g_logState = -result;
g_logError = PSTR("SDCARD F/S ERROR");
return;
}
// Skip over any existing log files ... _000, _001, etc. (or find first gap in numbering)
// 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);
@@ -97,10 +96,10 @@ void startLogs()
}
else if (result == FR_NO_PATH)
{
if (f_mkdir("/G9XLOGS") != FR_OK)
if (f_mkdir(LOG_PATH) != FR_OK)
{
strcpy_P(g_logFilename, PSTR("Check /G9XLOGS folder"));
g_logState = -result;
g_logError = PSTR("Check " LOG_PATH " folder");
return;
}
}
@@ -108,9 +107,9 @@ void startLogs()
{
g_logState = -result;
if (result == FR_NOT_READY)
strcpy_P(g_logFilename, PSTR("DATA CARD NOT PRESENT"));
g_logError = PSTR("NO SDCARD");
else
strcpy_P(g_logFilename, PSTR("DATA CARD ERROR"));
g_logError = PSTR("SDCARD ERROR");
return;
}
}
@@ -118,8 +117,7 @@ void startLogs()
// g_logFilename should now be set appropriately.
}
// TODO FORCEINLINE this function
void doLogs()
void writeLogs()
{
FRESULT result;
@@ -127,25 +125,32 @@ void doLogs()
{
if (g_logState==0)
{
result = f_mount(0, &FATFS_Obj);
result = f_mount(0, &g_FATFS_Obj);
if (result != FR_OK)
{
g_logState = -result;
// TODO beepAgain = result - 1;
AUDIO_KEYPAD_UP();
AUDIO_WARNING1();
}
else
{
// create new log file using filename set up in startLogs()
// 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 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("Buffer,RX,TX,A1,A2,Date,Time,Long,Lat,Course,Speed,Alt,BarAlt,"
"Temp1,Temp2,RPM,Fuel,Volts,AccelX,AccelY,AccelZ,THR,RUD,ELE,IDL0,IDL1,IDL2,AIL,GEA,TRN\n",
&g_oLogFile);
}
f_lseek(&g_oLogFile, g_oLogFile.fsize); // append
g_logState = 1;
AUDIO_WARNING2();
@@ -155,7 +160,44 @@ void doLogs()
if (g_logState>0)
{
// TODO here we write logs
// For now, append 'anything' as a test
// if data type == Hub
f_printf(&g_oLogFile, "%d,", frskyStreaming);
f_printf(&g_oLogFile, "%d,", frskyRSSI[0].value);
f_printf(&g_oLogFile, "%d,", frskyRSSI[1].value);
f_printf(&g_oLogFile, "%d,", frskyTelemetry[0].value);
f_printf(&g_oLogFile, "%d,", frskyTelemetry[1].value);
f_printf(&g_oLogFile, "%4d-%02d-%02d,", frskyHubData.year+2000, frskyHubData.month, frskyHubData.day);
f_printf(&g_oLogFile, "%02d:%02d:%02d,", frskyHubData.hour, frskyHubData.min, frskyHubData.sec);
f_printf(&g_oLogFile, "%03d.%04d%c,", frskyHubData.gpsLongitude_bp, frskyHubData.gpsLongitude_ap,
frskyHubData.gpsLongitudeEW ? frskyHubData.gpsLongitudeEW : '-');
f_printf(&g_oLogFile, "%03d.%04d%c,", frskyHubData.gpsLatitude_bp, frskyHubData.gpsLatitude_ap,
frskyHubData.gpsLatitudeNS ? frskyHubData.gpsLatitudeNS : '-');
f_printf(&g_oLogFile, "%03d.%d,", frskyHubData.gpsCourse_bp, frskyHubData.gpsCourse_ap);
f_printf(&g_oLogFile, "%d.%d,", frskyHubData.gpsSpeed_bp, frskyHubData.gpsSpeed_ap);
f_printf(&g_oLogFile, "%03d.%d,", frskyHubData.gpsAltitude_bp, frskyHubData.gpsAltitude_ap);
f_printf(&g_oLogFile, "%d.%d,", frskyHubData.baroAltitude_bp + frskyHubData.baroAltitudeOffset, frskyHubData.baroAltitude_ap);
f_printf(&g_oLogFile, "%d,", frskyHubData.temperature1);
f_printf(&g_oLogFile, "%d,", frskyHubData.temperature2);
f_printf(&g_oLogFile, "%d,", frskyHubData.rpm);
f_printf(&g_oLogFile, "%d,", frskyHubData.fuelLevel);
f_printf(&g_oLogFile, "%d,", frskyHubData.volts);
f_printf(&g_oLogFile, "%d,", frskyHubData.accelX);
f_printf(&g_oLogFile, "%d,", frskyHubData.accelY);
f_printf(&g_oLogFile, "%d,", frskyHubData.accelZ);
f_printf(&g_oLogFile, "%d,", keyState(SW_ThrCt));
f_printf(&g_oLogFile, "%d,", keyState(SW_RuddDR));
f_printf(&g_oLogFile, "%d,", keyState(SW_ElevDR));
f_printf(&g_oLogFile, "%d,", keyState(SW_ID0));
f_printf(&g_oLogFile, "%d,", keyState(SW_ID1));
f_printf(&g_oLogFile, "%d,", keyState(SW_ID2));
f_printf(&g_oLogFile, "%d,", keyState(SW_AileDR));
f_printf(&g_oLogFile, "%d,", keyState(SW_Gear));
f_printf(&g_oLogFile, "%d\n", keyState(SW_Trainer));
// 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)
+47
View File
@@ -0,0 +1,47 @@
/*
* Authors (alphabetical order)
* - Bertrand Songis <bsongis@gmail.com>
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
* - Cameron Weeks <th9xer@gmail.com>
* - Erez Raviv
* - Jean-Pierre Parisy
* - Karl Szmutny <shadow@privy.de>
* - Michael Blandford
* - Michal Hlavinka
* - Philip Moss
* - Rob Thomson
* - Romolo Manfredini <romolo.manfredini@gmail.com>
* - Thomas Husterer
*
* open9x is based on code named
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/,
* er9x by Erez Raviv: http://code.google.com/p/er9x/,
* and the original (and ongoing) project by
* Thomas Husterer, th9x: http://code.google.com/p/th9x/
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#ifndef LOGS_H
#define LOGS_H
#define LOG_PATH "/O9XLOGS" // no trailing slash = important
extern char g_logFilename[21]; // "/O9XLOGS/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 void writeLogs();
#endif
+3 -2
View File
@@ -36,8 +36,6 @@
#include <inttypes.h>
#include "open9x.h"
#define IS_THROTTLE(x) (((2-(g_eeGeneral.stickMode&1)) == x) && (x<4))
#define NO_HI_LEN 25
#define RESX 1024
@@ -110,6 +108,9 @@ int8_t checkIncDecGen(uint8_t event, int8_t i_val, int8_t i_min, int8_t i_max);
#ifdef NAVIGATION_RE1
extern int8_t *s_inflight_value;
extern const pm_char *s_inflight_label;
extern int16_t s_inflight_min;
extern int16_t s_inflight_max;
extern int16_t s_inflight_shift;
#define INFLIGHT(val) (s_inflight_value==&val ? SURROUNDED : 0)
void checkInFlightIncDecModel(uint8_t event, int8_t *value, int16_t i_min, int16_t i_max, int8_t i_shift, const pm_char *label);
#define CHECK_INFLIGHT_INCDEC_MODELVAR(event, var, imin, imax, ishift, label) \
+1 -1
View File
@@ -891,7 +891,7 @@ void menuProcCurveOne(uint8_t event)
break;
case EVT_KEY_REPT(KEY_RIGHT):
case EVT_KEY_FIRST(KEY_RIGHT):
if (!autoThrStep && m_posHorz<((s_editMode>0) ? points-1 : ((g_menuStack[g_menuStackPtr-1] == menuProcExpoOne && IS_THROTTLE(expoaddress(s_currIdx)->chn)) ? 2 : 1))) m_posHorz++;
if (!autoThrStep && m_posHorz<((s_editMode>0) ? points-1 : ((g_menuStack[g_menuStackPtr-1] == menuProcExpoOne && expoaddress(s_currIdx)->chn == THR_STICK) ? 2 : 1))) m_posHorz++;
break;
}
+5 -5
View File
@@ -1178,8 +1178,8 @@ void perOut(int16_t *chanOut, uint8_t phase)
if (s_noStickInputs) {
for (uint8_t i=0; i<NUM_STICKS; i++) {
if (!IS_THROTTLE(i)) {
anas[i] = 0;
if (i!=THR_STICK) {
anas[i] = 0;
}
}
for (uint8_t i=0; i<NUM_PPM; i++) anas[i+PPM_BASE] = 0;
@@ -1662,7 +1662,7 @@ void perMain()
trimsCheckTimer -= 1;
#if defined (LOGS)
doLogs();
writeLogs();
#endif
#if defined(FRSKY) && defined(DISPLAY_USER_DATA)
@@ -2048,8 +2048,8 @@ void moveTrimsToOffsets() // copy state of 3 primary to subtrim
g_model.limitData[i].offset = limit((int16_t)-1000, zero_chans512[i], (int16_t)1000); // make sure the offset doesn't go haywire
// reset all trims, except throttle
for (uint8_t i=0; i<4; i++) {
if (!IS_THROTTLE(i)) {
for (uint8_t i=0; i<NUM_STICKS; i++) {
if (i!=THR_STICK) {
for (uint8_t phase=0; phase<MAX_PHASES; phase++) {
int16_t trim = getTrimValue(phase, i);
if (trim <= TRIM_EXTENDED_MAX)
+4 -11
View File
@@ -608,11 +608,6 @@ void DSM2_Init();
void DSM2_Done();
void resetProto();
#ifdef LOGS
extern void startLogs();
extern void doLogs();
#endif
extern uint8_t *pulses2MHzRPtr;
extern uint8_t *pulses2MHzWPtr;
@@ -685,12 +680,6 @@ inline bool isFunctionActive(uint8_t func)
extern char userDataDisplayBuf[TELEM_SCREEN_BUFFER_SIZE]; // text buffer for frsky telem. user data experiments
#endif
#if defined (PCBV4)
extern char g_logFilename[22]; // pers.cpp::resetTelemetry()
extern FATFS FATFS_Obj; // pers.cpp::resetTelemetry()
extern FIL g_oLogFile; // pers.cpp::resetTelemetry()
#endif
#if defined (PCBV4)
// Global rotary encoder registers -- 8-bit, 0-255
extern volatile uint8_t g_rotenc[2];
@@ -704,6 +693,10 @@ extern volatile uint8_t g_rotenc[2];
#include "beeper.h"
#endif
#ifdef LOGS
#include "logs.h"
#endif
#if defined(SOMO)
#include "somo14d.h"
#endif
+1 -1
View File
@@ -133,7 +133,7 @@ void eeLoadModel(uint8_t id)
resetTimer(1);
resetProto();
#ifdef LOGS
startLogs();
initLogs();
#endif
}
}
+19 -4
View File
@@ -326,6 +326,21 @@ void putPcmByte( uint8_t byte )
}
}
void putPcmHead()
{
// send 7E, do not CRC
// 01111110
putPcmPart( 0xC0 ) ;
putPcmPart( 0x80 ) ;
putPcmPart( 0x80 ) ;
putPcmPart( 0x80 ) ;
putPcmPart( 0x80 ) ;
putPcmPart( 0x80 ) ;
putPcmPart( 0x80 ) ;
putPcmPart( 0xC0 ) ;
}
void setupPulsesPXX()
{
uint8_t i ;
@@ -338,7 +353,7 @@ void setupPulsesPXX()
PcmCrc = 0 ;
PcmBitCount = PcmByte = 0 ;
PcmOnesCount = 0 ;
putPcmByte( 0x7E ) ; // sync byte
putPcmHead() ;
putPcmByte( g_model.modelId ) ; // putPcmByte( g_model.rxnum ) ; //
putPcmByte( pxxFlag ) ; // First byte of flags
putPcmByte( 0 ) ; // Second byte of flags
@@ -362,7 +377,7 @@ void setupPulsesPXX()
chan = PcmCrc ; // get the crc
putPcmByte( chan ) ; // Checksum lo
putPcmByte( chan >> 8 ) ; // Checksum hi
putPcmByte( 0x7E ) ; // sync byte
putPcmHead( ) ;
putPcmFlush() ;
OCR1C += 40000 ; // 20mS on
PORTB |= (1<<OUT_B_PPM);
@@ -433,7 +448,7 @@ void DSM2_Init(void)
#ifndef SIMU
DDRE &= ~(1 << DDE0); // set RXD0 pin as input
PORTE &= ~(1 << PORTE0); // disable pullup on RXD0 pin
PORTE |= (1 << PORTE0); // enable pullup on RXD0 pin
#undef BAUD
#define BAUD 125000
@@ -453,7 +468,7 @@ void DSM2_Init(void)
setupPulsesDsm2();
// These should be running right from power up on a FrSky enabled '9X.
DSM2_EnableTXD(); // enable FrSky-Telemetry reception
DSM2_EnableTXD(); // enable DSM2 UART transmitter
#endif // SIMU
}
+2
View File
@@ -104,6 +104,7 @@ extern sem_t eeprom_write_sem;
#define pgm_read_stringP(adr) ((adr))
#define PSTR(adr) adr
#define _delay_us(a)
#define _delay_ms(a)
#define cli()
#define sei()
#define strcpy_P strcpy
@@ -136,6 +137,7 @@ extern sem_t eeprom_write_sem;
#define UCSR0B dummyport
#define UDRIE0 dummyport
#define TXB80 dummyport
#define TXEN0 dummyport
#define RXEN0 dummyport
#define DDE0 dummyport