From 02a7c77d0a5584d288c4779d6e989cf59cb3b863 Mon Sep 17 00:00:00 2001 From: rusEfi Date: Tue, 9 Aug 2016 00:03:08 -0400 Subject: [PATCH] auto-sync --- firmware/hw_layer/mmc_card.cpp | 24 +++++- firmware/hw_layer/rtc_helper.cpp | 82 ++++++++++---------- firmware/hw_layer/rtc_helper.h | 1 + java_console/ui/src/com/rusefi/Launcher.java | 4 +- 4 files changed, 64 insertions(+), 47 deletions(-) diff --git a/firmware/hw_layer/mmc_card.cpp b/firmware/hw_layer/mmc_card.cpp index acf378cca5..e5429a02a4 100644 --- a/firmware/hw_layer/mmc_card.cpp +++ b/firmware/hw_layer/mmc_card.cpp @@ -27,11 +27,16 @@ #include "usb_msd.h" #include "usb_msd_cfg.h" +#include "rtc_helper.h" EXTERN_ENGINE; #define LOG_INDEX_FILENAME "index.txt" + #define RUSEFI_LOG_PREFIX "rus" +#define PREFIX_LEN 3 +#define SHORT_TIME_LEN 11 + #define LS_RESPONSE "ls_result" #define FILE_LIST_MAX_COUNT 20 @@ -80,7 +85,7 @@ static void printError(const char *str, FRESULT f_error) { static FIL FDLogFile; static FIL FDCurrFile; static int logFileIndex = 1; -static char logName[15]; +static char logName[20]; static int totalLoggedBytes = 0; @@ -135,6 +140,19 @@ static void incLogFileName(void) { unlockSpi(); } +static void prepareLogFileName(void) { + strcpy(logName, RUSEFI_LOG_PREFIX); +// bool result = dateToStringShort(&logName[PREFIX_LEN]); + char *ptr; +// if (result) { +// ptr = &logName[PREFIX_LEN + SHORT_TIME_LEN]; +// } else { + ptr = itoa10(&logName[PREFIX_LEN], logFileIndex); +// } + strcat(ptr, ".msl"); + +} + /** * @brief Create a new file with the specified name * @@ -144,9 +162,7 @@ static void incLogFileName(void) { static void createLogFile(void) { lockSpi(SPI_NONE); memset(&FDLogFile, 0, sizeof(FIL)); // clear the memory - strcpy(logName, RUSEFI_LOG_PREFIX); - char *ptr = itoa10(&logName[3], logFileIndex); - strcat(ptr, ".msl"); + prepareLogFileName(); FRESULT err = f_open(&FDLogFile, logName, FA_OPEN_ALWAYS | FA_WRITE); // Create new file if (err != FR_OK && err != FR_EXIST) { diff --git a/firmware/hw_layer/rtc_helper.cpp b/firmware/hw_layer/rtc_helper.cpp index ff72426293..74b8923fff 100644 --- a/firmware/hw_layer/rtc_helper.cpp +++ b/firmware/hw_layer/rtc_helper.cpp @@ -32,6 +32,41 @@ void date_get_tm(struct tm *timp) { #endif /* EFI_RTC */ } +static void put2(int offset, char *lcd_str, int value) { + static char buff[4]; + itoa10(buff, value); + if (value < 10) { + lcd_str[offset] = '0'; + lcd_str[offset + 1] = buff[0]; + } else { + lcd_str[offset] = buff[0]; + lcd_str[offset + 1] = buff[1]; + } +} + +bool dateToStringShort(char *lcd_str) { +#if EFI_RTC || defined(__DOXYGEN__) + strcpy(lcd_str, "0000_000000\0"); + struct tm timp; + rtcGetTimeTm(&RTCD1, &timp); + if (timp.tm_year < 116 || timp.tm_year > 130) { + // 2016 to 2030 is the valid range + lcd_str[0] = 0; + return false; + } + put2(0, lcd_str, timp.tm_mon + 1); + put2(2, lcd_str, timp.tm_mday); + put2(5, lcd_str, timp.tm_hour); + put2(7, lcd_str, timp.tm_min); + put2(9, lcd_str, timp.tm_sec); + + return true; +#else + lcd_str[0] = 0; + return false; +#endif +} + void dateToString(char *lcd_str) { #if EFI_RTC || defined(__DOXYGEN__) // todo: @@ -40,50 +75,15 @@ void dateToString(char *lcd_str) { // this would require a temporary mem stream - see datalogging and other existing usages strcpy(lcd_str, "00/00 00:00:00\0"); - static char buff[4]; struct tm timp; rtcGetTimeTm(&RTCD1, &timp); // get RTC date/time - itoa10(buff, timp.tm_mon + 1); - if(timp.tm_mon < 9) { - lcd_str[0] = '0'; - lcd_str[1] = buff[0]; - } else { - lcd_str[0] = buff[0]; - lcd_str[1] = buff[1]; - } - itoa10(buff, timp.tm_mday); - if(timp.tm_mday < 10) { - lcd_str[3] = '0'; - lcd_str[4] = buff[0]; - } else { - lcd_str[3] = buff[0]; - lcd_str[4] = buff[1]; - } - itoa10(buff, timp.tm_hour); - if(timp.tm_hour < 10) { - lcd_str[6] = '0'; - lcd_str[7] = buff[0]; - } else { - lcd_str[6] = buff[0]; - lcd_str[7] = buff[1]; - } - itoa10(buff, timp.tm_min); - if(timp.tm_min < 10) { - lcd_str[9] = '0'; - lcd_str[10] = buff[0]; - } else { - lcd_str[9] = buff[0]; - lcd_str[10] = buff[1]; - } - itoa10(buff, timp.tm_sec); - if(timp.tm_sec < 10) { - lcd_str[12] = '0'; - lcd_str[13] = buff[0]; - } else { - lcd_str[12] = buff[0]; - lcd_str[13] = buff[1]; - } + put2(0, lcd_str, timp.tm_mon + 1); + put2(3, lcd_str, timp.tm_mday); + put2(6, lcd_str, timp.tm_hour); + put2(9, lcd_str, timp.tm_min); + put2(12, lcd_str, timp.tm_sec); + #else lcd_str[0] = 0; #endif /* EFI_RTC */ diff --git a/firmware/hw_layer/rtc_helper.h b/firmware/hw_layer/rtc_helper.h index adfaaf2513..b95bd10b11 100644 --- a/firmware/hw_layer/rtc_helper.h +++ b/firmware/hw_layer/rtc_helper.h @@ -15,5 +15,6 @@ void initRtc(void); void date_set_tm(struct tm *); void date_get_tm(struct tm *); void dateToString(char *buffer); +bool dateToStringShort(char *lcd_str); #endif /* RTC_HELPER_H_ */ diff --git a/java_console/ui/src/com/rusefi/Launcher.java b/java_console/ui/src/com/rusefi/Launcher.java index 559ceee486..12268a0745 100644 --- a/java_console/ui/src/com/rusefi/Launcher.java +++ b/java_console/ui/src/com/rusefi/Launcher.java @@ -38,7 +38,7 @@ import static com.rusefi.ui.storage.PersistentConfiguration.getConfig; * @see EngineSnifferPanel */ public class Launcher { - public static final int CONSOLE_VERSION = 20160807; + public static final int CONSOLE_VERSION = 20160808; public static final boolean SHOW_STIMULATOR = false; private static final String TAB_INDEX = "main_tab"; protected static final String PORT_KEY = "port"; @@ -192,7 +192,7 @@ public class Launcher { UiUtils.trueRepaint(tabbedPane); // this would repaint status label if (ConnectionStatus.INSTANCE.getValue() == ConnectionStatus.Value.CONNECTED) { long unixTime = System.currentTimeMillis() / 1000L; - long withOffset = unixTime + TimeZone.getDefault().getOffset(System.currentTimeMillis()); + long withOffset = unixTime + TimeZone.getDefault().getOffset(System.currentTimeMillis()) / 1000; CommandQueue.getInstance().write("set date " + withOffset, CommandQueue.DEFAULT_TIMEOUT, InvocationConfirmationListener.VOID, false); }