auto-sync

This commit is contained in:
rusEfi 2014-11-14 14:03:04 -06:00
parent e7b34357cd
commit 9e79c4859c
5 changed files with 40 additions and 29 deletions

View File

@ -46,12 +46,12 @@ extern SerialUSBDriver SDU1;
#define CONSOLE_DEVICE &SDU1
#define TS_SERIAL_UART_DEVICE &SD3
//#define TS_SERIAL_SPEED 115200
#define TS_SERIAL_SPEED 38400
static SerialConfig tsSerialConfig = { TS_SERIAL_SPEED, 0, USART_CR2_STOP1_BITS | USART_CR2_LINEN, 0 };
static SerialConfig tsSerialConfig = { 0, 0, USART_CR2_STOP1_BITS | USART_CR2_LINEN, 0 };
#endif /* EFI_PROD_CODE */
EXTERN_ENGINE;
#define MAX_PAGE_ID 0
// in MS, that's 10 seconds
@ -104,15 +104,11 @@ extern TunerStudioOutputChannels tsOutputChannels;
extern TunerStudioState tsState;
extern engine_configuration_s *engineConfiguration;
extern board_configuration_s *boardConfiguration;
static void printStats(void) {
#if EFI_PROD_CODE
if (!isSerialOverUart()) {
scheduleMsg(&logger, "TS RX on %s%d/TX on %s%d @%d", portname(TS_SERIAL_RX_PORT), TS_SERIAL_RX_PIN,
portname(TS_SERIAL_TX_PORT), TS_SERIAL_TX_PIN, TS_SERIAL_SPEED);
portname(TS_SERIAL_TX_PORT), TS_SERIAL_TX_PIN, boardConfiguration->tunerStudioSerialSpeed);
}
#endif /* EFI_PROD_CODE */
scheduleMsg(&logger, "TunerStudio total/error counter=%d/%d H=%d / O counter=%d size=%d / P=%d / B=%d", tsCounter, tsState.errorCounter, tsState.queryCommandCounter, tsState.outputChannelsCommandCounter,
@ -137,6 +133,11 @@ static void printStats(void) {
scheduleMsg(&logger, "engineCycle %d", offset);
}
static void setTsSpeed(int value) {
boardConfiguration->tunerStudioSerialSpeed = value;
printStats();
}
void tunerStudioWriteData(const uint8_t * buffer, int size) {
chSequentialStreamWrite(getTsSerialDevice(), buffer, size);
}
@ -476,6 +477,24 @@ void syncTunerStudioCopy(void) {
memcpy(&configWorkingCopy, &persistentState.persistentConfiguration, sizeof(persistent_config_s));
}
/**
* Adds size to the beginning of a packet and a crc32 at the end. Then send the packet.
*/
void tunerStudioWriteCrcPacket(const uint8_t command, const void *buf, const uint16_t size) {
// todo: max size validation
*(uint16_t *) crcIoBuffer = SWAP_UINT16(size + 1); // packet size including command
*(uint8_t *) (crcIoBuffer + 2) = command;
if (size != 0)
memcpy(crcIoBuffer + 3, buf, size);
// CRC on whole packet
uint32_t crc = crc32((void *) (crcIoBuffer + 2), (uint32_t) (size + 1));
*(uint32_t *) (crcIoBuffer + 2 + 1 + size) = SWAP_UINT32(crc);
// scheduleMsg(&logger, "TunerStudio: CRC command %x size %d", command, size);
tunerStudioWriteData(crcIoBuffer, size + 2 + 1 + 4); // with size, command and CRC
}
void startTunerStudioConnectivity(void) {
initLogging(&logger, "tuner studio");
@ -496,32 +515,17 @@ void startTunerStudioConnectivity(void) {
mySetPadMode("tunerstudio rx", TS_SERIAL_RX_PORT, TS_SERIAL_RX_PIN, PAL_MODE_ALTERNATE(TS_SERIAL_AF));
mySetPadMode("tunerstudio tx", TS_SERIAL_TX_PORT, TS_SERIAL_TX_PIN, PAL_MODE_ALTERNATE(TS_SERIAL_AF));
tsSerialConfig.speed = boardConfiguration->tunerStudioSerialSpeed;
sdStart(TS_SERIAL_UART_DEVICE, &tsSerialConfig);
}
#endif /* EFI_PROD_CODE */
syncTunerStudioCopy();
addConsoleAction("tsinfo", printStats);
addConsoleActionI("set_ts_speed", setTsSpeed);
chThdCreateStatic(TS_WORKING_AREA, sizeof(TS_WORKING_AREA), NORMALPRIO, tsThreadEntryPoint, NULL);
}
/**
* Adds size to the beginning of a packet and a crc32 at the end. Then send the packet.
*/
void tunerStudioWriteCrcPacket(const uint8_t command, const void *buf, const uint16_t size) {
// todo: max size validation
*(uint16_t *) crcIoBuffer = SWAP_UINT16(size + 1); // packet size including command
*(uint8_t *) (crcIoBuffer + 2) = command;
if (size != 0)
memcpy(crcIoBuffer + 3, buf, size);
// CRC on whole packet
uint32_t crc = crc32((void *) (crcIoBuffer + 2), (uint32_t) (size + 1));
*(uint32_t *) (crcIoBuffer + 2 + 1 + size) = SWAP_UINT32(crc);
// scheduleMsg(&logger, "TunerStudio: CRC command %x size %d", command, size);
tunerStudioWriteData(crcIoBuffer, size + 2 + 1 + 4); // with size, command and CRC
}
#endif /* EFI_TUNER_STUDIO */

View File

@ -52,6 +52,9 @@
#include "mitsubishi.h"
#include "subaru.h"
//#define TS_DEFAULT_SPEED 115200
#define TS_DEFAULT_SPEED 38400
static volatile int globalConfigurationVersion = 0;
int getGlobalConfigurationVersion(void) {
@ -442,6 +445,8 @@ void setDefaultConfiguration(engine_configuration_s *engineConfiguration, board_
boardConfiguration->isSdCardEnabled = false;
boardConfiguration->isFastAdcEnabled = false;
boardConfiguration->isEngineControlEnabled = true;
boardConfiguration->tunerStudioSerialSpeed = TS_DEFAULT_SPEED;
}
void resetConfigurationExt(Logging * logger, engine_type_e engineType, Engine *engine) {

View File

@ -12,7 +12,7 @@
#include "engine_configuration.h"
#include "engine.h"
#define FLASH_DATA_VERSION 5056
#define FLASH_DATA_VERSION 5343
void readFromFlash(void);
void initFlash(Engine *engine);

View File

@ -70,7 +70,8 @@ typedef Thread thread_t;
*/
#define EXTERN_ENGINE extern Engine *engine; \
extern engine_configuration_s *engineConfiguration;
extern engine_configuration_s *engineConfiguration; \
extern board_configuration_s *boardConfiguration;
#define DECLARE_ENGINE_PARAMETER_F void
#define DECLARE_ENGINE_PARAMETER_S

View File

@ -89,7 +89,8 @@ typedef EventListener event_listener_t;
#define THD_WORKING_AREA WORKING_AREA
#define EXTERN_ENGINE extern Engine *engine; \
extern engine_configuration_s *engineConfiguration;
extern engine_configuration_s *engineConfiguration; \
extern board_configuration_s *boardConfiguration;
#define DECLARE_ENGINE_PARAMETER_F void
#define DECLARE_ENGINE_PARAMETER_S