auto-sync

This commit is contained in:
rusEfi 2015-01-28 11:04:30 -06:00
parent 8eaf54339b
commit 5a85a07c4c
3 changed files with 41 additions and 32 deletions

View File

@ -72,7 +72,7 @@ BaseChannel * getTsSerialDevice(void) {
#endif #endif
} }
static Logging *logger; Logging *tsLogger;
extern persistent_config_s configWorkingCopy; extern persistent_config_s configWorkingCopy;
extern persistent_config_container_s persistentState; extern persistent_config_container_s persistentState;
@ -105,18 +105,18 @@ extern TunerStudioOutputChannels tsOutputChannels;
extern TunerStudioState tsState; extern TunerStudioState tsState;
static void printStats(void) { void printTsStats(void) {
#if EFI_PROD_CODE #if EFI_PROD_CODE
if (!isSerialOverUart()) { if (!isSerialOverUart()) {
scheduleMsg(logger, "TS RX on %s%d/TX on %s%d @%d", portname(TS_SERIAL_RX_PORT), TS_SERIAL_RX_PIN, scheduleMsg(tsLogger, "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, boardConfiguration->tunerStudioSerialSpeed); portname(TS_SERIAL_TX_PORT), TS_SERIAL_TX_PIN, boardConfiguration->tunerStudioSerialSpeed);
} }
#endif /* EFI_PROD_CODE */ #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, scheduleMsg(tsLogger, "TunerStudio total/error counter=%d/%d H=%d / O counter=%d size=%d / P=%d / B=%d", tsCounter, tsState.errorCounter, tsState.queryCommandCounter, tsState.outputChannelsCommandCounter,
sizeof(tsOutputChannels), tsState.readPageCommandsCounter, tsState.burnCommandCounter); sizeof(tsOutputChannels), tsState.readPageCommandsCounter, tsState.burnCommandCounter);
scheduleMsg(logger, "TunerStudio W counter=%d / C = %d / P = %d / current page %d", tsState.writeValueCommandCounter, tsState.writeChunkCommandCounter, scheduleMsg(tsLogger, "TunerStudio W counter=%d / C = %d / P = %d / current page %d", tsState.writeValueCommandCounter, tsState.writeChunkCommandCounter,
tsState.pageCommandCounter, tsState.currentPageId); tsState.pageCommandCounter, tsState.currentPageId);
scheduleMsg(logger, "page size=%d", sizeof(engine_configuration_s)); scheduleMsg(tsLogger, "page size=%d", sizeof(engine_configuration_s));
// scheduleMsg(logger, "analogChartFrequency %d", // scheduleMsg(logger, "analogChartFrequency %d",
// (int) (&engineConfiguration->analogChartFrequency) - (int) engineConfiguration); // (int) (&engineConfiguration->analogChartFrequency) - (int) engineConfiguration);
@ -125,18 +125,18 @@ static void printStats(void) {
// scheduleMsg(logger, "fuelTable %d", fuelMapOffset); // scheduleMsg(logger, "fuelTable %d", fuelMapOffset);
// //
int offset = (int) (&boardConfiguration->hip9011Gain) - (int) engineConfiguration; int offset = (int) (&boardConfiguration->hip9011Gain) - (int) engineConfiguration;
scheduleMsg(logger, "hip9011Gain %d", offset); scheduleMsg(tsLogger, "hip9011Gain %d", offset);
// //
offset = (int) (&engineConfiguration->crankingCycleBins) - (int) engineConfiguration; offset = (int) (&engineConfiguration->crankingCycleBins) - (int) engineConfiguration;
scheduleMsg(logger, "crankingCycleBins %d", offset); scheduleMsg(tsLogger, "crankingCycleBins %d", offset);
offset = (int) (&engineConfiguration->engineCycle) - (int) engineConfiguration; offset = (int) (&engineConfiguration->engineCycle) - (int) engineConfiguration;
scheduleMsg(logger, "engineCycle %d", offset); scheduleMsg(tsLogger, "engineCycle %d", offset);
} }
static void setTsSpeed(int value) { static void setTsSpeed(int value) {
boardConfiguration->tunerStudioSerialSpeed = value; boardConfiguration->tunerStudioSerialSpeed = value;
printStats(); printTsStats();
} }
void tunerStudioWriteData(const uint8_t * buffer, int size) { void tunerStudioWriteData(const uint8_t * buffer, int size) {
@ -145,8 +145,8 @@ void tunerStudioWriteData(const uint8_t * buffer, int size) {
void tunerStudioDebug(const char *msg) { void tunerStudioDebug(const char *msg) {
#if EFI_TUNER_STUDIO_VERBOSE #if EFI_TUNER_STUDIO_VERBOSE
scheduleMsg(logger, "%s", msg); scheduleMsg(tsLogger, "%s", msg);
printStats(); printTsStats();
#endif #endif
} }
@ -183,7 +183,7 @@ void handlePageSelectCommand(ts_response_format_e mode, uint16_t pageId) {
tsState.pageCommandCounter++; tsState.pageCommandCounter++;
tsState.currentPageId = pageId; tsState.currentPageId = pageId;
scheduleMsg(logger, "page %d selected", tsState.currentPageId); scheduleMsg(tsLogger, "page %d selected", tsState.currentPageId);
tsSendResponse(mode, NULL, 0); tsSendResponse(mode, NULL, 0);
} }
@ -194,17 +194,17 @@ void handlePageSelectCommand(ts_response_format_e mode, uint16_t pageId) {
void handleWriteChunkCommand(ts_response_format_e mode, short offset, short count, void *content) { void handleWriteChunkCommand(ts_response_format_e mode, short offset, short count, void *content) {
tsState.writeChunkCommandCounter++; tsState.writeChunkCommandCounter++;
scheduleMsg(logger, "receiving page %d chunk offset %d size %d", tsState.currentPageId, offset, count); scheduleMsg(tsLogger, "receiving page %d chunk offset %d size %d", tsState.currentPageId, offset, count);
if (offset > getTunerStudioPageSize(tsState.currentPageId)) { if (offset > getTunerStudioPageSize(tsState.currentPageId)) {
scheduleMsg(logger, "ERROR offset %d", offset); scheduleMsg(tsLogger, "ERROR offset %d", offset);
tunerStudioError("ERROR: out of range"); tunerStudioError("ERROR: out of range");
offset = 0; offset = 0;
} }
if (count > getTunerStudioPageSize(tsState.currentPageId)) { if (count > getTunerStudioPageSize(tsState.currentPageId)) {
tunerStudioError("ERROR: unexpected count"); tunerStudioError("ERROR: unexpected count");
scheduleMsg(logger, "ERROR count %d", count); scheduleMsg(tsLogger, "ERROR count %d", count);
count = 0; count = 0;
} }
@ -234,7 +234,7 @@ void handleWriteValueCommand(ts_response_format_e mode, uint16_t page, uint16_t
if (offset > getTunerStudioPageSize(tsState.currentPageId)) { if (offset > getTunerStudioPageSize(tsState.currentPageId)) {
tunerStudioError("ERROR: out of range2"); tunerStudioError("ERROR: out of range2");
scheduleMsg(logger, "ERROR offset %d", offset); scheduleMsg(tsLogger, "ERROR offset %d", offset);
offset = 0; offset = 0;
return; return;
} }
@ -242,7 +242,7 @@ void handleWriteValueCommand(ts_response_format_e mode, uint16_t page, uint16_t
efitimems_t nowMs = currentTimeMillis(); efitimems_t nowMs = currentTimeMillis();
if (nowMs - previousWriteReportMs > 5) { if (nowMs - previousWriteReportMs > 5) {
previousWriteReportMs = nowMs; previousWriteReportMs = nowMs;
scheduleMsg(logger, "page %d offset %d: value=%d", tsState.currentPageId, offset, value); scheduleMsg(tsLogger, "page %d offset %d: value=%d", tsState.currentPageId, offset, value);
} }
getWorkingPageAddr(tsState.currentPageId)[offset] = value; getWorkingPageAddr(tsState.currentPageId)[offset] = value;
@ -260,11 +260,11 @@ void handlePageReadCommand(ts_response_format_e mode, uint16_t pageId, uint16_t
tsState.currentPageId = pageId; tsState.currentPageId = pageId;
#if EFI_TUNER_STUDIO_VERBOSE #if EFI_TUNER_STUDIO_VERBOSE
scheduleMsg(logger, "Page requested: page %d offset=%d count=%d", (int)tsState.currentPageId, offset, count); scheduleMsg(tsLogger, "Page requested: page %d offset=%d count=%d", (int)tsState.currentPageId, offset, count);
#endif #endif
if (tsState.currentPageId > MAX_PAGE_ID) { if (tsState.currentPageId > MAX_PAGE_ID) {
scheduleMsg(logger, "invalid Page number %x", tsState.currentPageId); scheduleMsg(tsLogger, "invalid Page number %x", tsState.currentPageId);
// something is not right here // something is not right here
tsState.currentPageId = 0; tsState.currentPageId = 0;
@ -275,7 +275,7 @@ void handlePageReadCommand(ts_response_format_e mode, uint16_t pageId, uint16_t
int size = getTunerStudioPageSize(tsState.currentPageId); int size = getTunerStudioPageSize(tsState.currentPageId);
if (size < offset + count) { if (size < offset + count) {
scheduleMsg(logger, "invalid offset/count %d/%d", offset, count); scheduleMsg(tsLogger, "invalid offset/count %d/%d", offset, count);
sendErrorCode(); sendErrorCode();
return; return;
} }
@ -283,7 +283,7 @@ void handlePageReadCommand(ts_response_format_e mode, uint16_t pageId, uint16_t
const uint8_t *addr = (const uint8_t *) (getWorkingPageAddr(tsState.currentPageId) + offset); const uint8_t *addr = (const uint8_t *) (getWorkingPageAddr(tsState.currentPageId) + offset);
tsSendResponse(mode, addr, count); tsSendResponse(mode, addr, count);
#if EFI_TUNER_STUDIO_VERBOSE #if EFI_TUNER_STUDIO_VERBOSE
scheduleMsg(logger, "Sending %d done", count); scheduleMsg(tsLogger, "Sending %d done", count);
#endif #endif
} }
@ -311,7 +311,7 @@ void handleBurnCommand(ts_response_format_e mode, uint16_t page) {
#endif #endif
incrementGlobalConfigurationVersion(); incrementGlobalConfigurationVersion();
tunerStudioWriteCrcPacket(TS_RESPONSE_BURN_OK, NULL, 0); tunerStudioWriteCrcPacket(TS_RESPONSE_BURN_OK, NULL, 0);
scheduleMsg(logger, "burned in (ms): %d", currentTimeMillis() - nowMs); scheduleMsg(tsLogger, "burned in (ms): %d", currentTimeMillis() - nowMs);
} }
static TunerStudioReadRequest readRequest; static TunerStudioReadRequest readRequest;
@ -319,7 +319,7 @@ static short int pageIn;
static bool handlePlainCommand(uint8_t command) { static bool handlePlainCommand(uint8_t command) {
if (command == TS_HELLO_COMMAND || command == TS_HELLO_COMMAND_DEPRECATED) { if (command == TS_HELLO_COMMAND || command == TS_HELLO_COMMAND_DEPRECATED) {
scheduleMsg(logger, "Got naked Query command"); scheduleMsg(tsLogger, "Got naked Query command");
handleQueryCommand(TS_PLAIN); handleQueryCommand(TS_PLAIN);
return true; return true;
} else if (command == 't' || command == 'T') { } else if (command == 't' || command == 'T') {
@ -430,7 +430,7 @@ static msg_t tsThreadEntryPoint(void *arg) {
uint32_t incomingPacketSize = firstByte * 256 + secondByte; uint32_t incomingPacketSize = firstByte * 256 + secondByte;
if (incomingPacketSize == 0 || incomingPacketSize > (sizeof(crcIoBuffer) - CRC_WRAPPING_SIZE)) { if (incomingPacketSize == 0 || incomingPacketSize > (sizeof(crcIoBuffer) - CRC_WRAPPING_SIZE)) {
scheduleMsg(logger, "TunerStudio: invalid size: %d", incomingPacketSize); scheduleMsg(tsLogger, "TunerStudio: invalid size: %d", incomingPacketSize);
tunerStudioError("ERROR: size"); tunerStudioError("ERROR: size");
sendErrorCode(); sendErrorCode();
continue; continue;
@ -444,7 +444,7 @@ static msg_t tsThreadEntryPoint(void *arg) {
char command = crcIoBuffer[0]; char command = crcIoBuffer[0];
if (!isKnownCommand(command)) { if (!isKnownCommand(command)) {
scheduleMsg(logger, "unexpected command %x", command); scheduleMsg(tsLogger, "unexpected command %x", command);
sendErrorCode(); sendErrorCode();
continue; continue;
} }
@ -455,7 +455,7 @@ static msg_t tsThreadEntryPoint(void *arg) {
MS2ST(TS_READ_TIMEOUT)); MS2ST(TS_READ_TIMEOUT));
int expectedSize = incomingPacketSize + CRC_VALUE_SIZE - 1; int expectedSize = incomingPacketSize + CRC_VALUE_SIZE - 1;
if (recieved != expectedSize) { if (recieved != expectedSize) {
scheduleMsg(logger, "got ONLY %d for packet size %d/%d for command %c", recieved, incomingPacketSize, scheduleMsg(tsLogger, "got ONLY %d for packet size %d/%d for command %c", recieved, incomingPacketSize,
expectedSize, command); expectedSize, command);
tunerStudioError("ERROR: not enough"); tunerStudioError("ERROR: not enough");
continue; continue;
@ -467,11 +467,11 @@ static msg_t tsThreadEntryPoint(void *arg) {
uint32_t actualCrc = crc32(crcIoBuffer, incomingPacketSize); uint32_t actualCrc = crc32(crcIoBuffer, incomingPacketSize);
if (actualCrc != expectedCrc) { if (actualCrc != expectedCrc) {
scheduleMsg(logger, "TunerStudio: CRC %x %x %x %x", crcIoBuffer[incomingPacketSize + 0], scheduleMsg(tsLogger, "TunerStudio: CRC %x %x %x %x", crcIoBuffer[incomingPacketSize + 0],
crcIoBuffer[incomingPacketSize + 1], crcIoBuffer[incomingPacketSize + 2], crcIoBuffer[incomingPacketSize + 1], crcIoBuffer[incomingPacketSize + 2],
crcIoBuffer[incomingPacketSize + 3]); crcIoBuffer[incomingPacketSize + 3]);
scheduleMsg(logger, "TunerStudio: command %c actual CRC %x/expected %x", crcIoBuffer[0], actualCrc, scheduleMsg(tsLogger, "TunerStudio: command %c actual CRC %x/expected %x", crcIoBuffer[0], actualCrc,
expectedCrc); expectedCrc);
tunerStudioError("ERROR: CRC issue"); tunerStudioError("ERROR: CRC issue");
continue; continue;
@ -513,7 +513,7 @@ void tunerStudioWriteCrcPacket(const uint8_t command, const void *buf, const uin
} }
void startTunerStudioConnectivity(Logging *sharedLogger) { void startTunerStudioConnectivity(Logging *sharedLogger) {
logger = sharedLogger; tsLogger = sharedLogger;
if (sizeof(engine_configuration_s) != getTunerStudioPageSize(0)) if (sizeof(engine_configuration_s) != getTunerStudioPageSize(0))
firmwareError("TS page size mismatch: %d/%d", sizeof(engine_configuration_s), getTunerStudioPageSize(0)); firmwareError("TS page size mismatch: %d/%d", sizeof(engine_configuration_s), getTunerStudioPageSize(0));
@ -524,7 +524,7 @@ void startTunerStudioConnectivity(Logging *sharedLogger) {
memset(&tsState, 0, sizeof(tsState)); memset(&tsState, 0, sizeof(tsState));
syncTunerStudioCopy(); syncTunerStudioCopy();
addConsoleAction("tsinfo", printStats); addConsoleAction("tsinfo", printTsStats);
addConsoleActionI("set_ts_speed", setTsSpeed); addConsoleActionI("set_ts_speed", setTsSpeed);
chThdCreateStatic(tsThreadStack, sizeof(tsThreadStack), NORMALPRIO, tsThreadEntryPoint, NULL); chThdCreateStatic(tsThreadStack, sizeof(tsThreadStack), NORMALPRIO, tsThreadEntryPoint, NULL);

View File

@ -15,6 +15,7 @@
#include "engine.h" #include "engine.h"
void updateTunerStudioState(Engine *engine, TunerStudioOutputChannels *tsOutputChannels); void updateTunerStudioState(Engine *engine, TunerStudioOutputChannels *tsOutputChannels);
void printTsStats(void);
void startTunerStudioConnectivity(Logging *sharedLogger); void startTunerStudioConnectivity(Logging *sharedLogger);
void syncTunerStudioCopy(void); void syncTunerStudioCopy(void);

View File

@ -60,6 +60,11 @@
#if EFI_TUNER_STUDIO #if EFI_TUNER_STUDIO
#if EFI_TUNER_STUDIO_VERBOSE
extern Logging *tsLogger;
#include "tunerstudio.h"
#endif
TunerStudioState tsState; TunerStudioState tsState;
TunerStudioOutputChannels tsOutputChannels; TunerStudioOutputChannels tsOutputChannels;
/** /**
@ -139,7 +144,10 @@ void tsSendResponse(ts_response_format_e mode, const uint8_t * buffer, int size)
*/ */
void handleQueryCommand(ts_response_format_e mode) { void handleQueryCommand(ts_response_format_e mode) {
tsState.queryCommandCounter++; tsState.queryCommandCounter++;
tunerStudioDebug("got S/H (queryCommand) mode=%d", mode); #if EFI_TUNER_STUDIO_VERBOSE
scheduleMsg(tsLogger, "got S/H (queryCommand) mode=%d", mode);
printTsStats();
#endif
tsSendResponse(mode, (const uint8_t *) TS_SIGNATURE, strlen(TS_SIGNATURE) + 1); tsSendResponse(mode, (const uint8_t *) TS_SIGNATURE, strlen(TS_SIGNATURE) + 1);
} }