Beispiel #1
0
/**
 * This command is needed to make the whole transfer a bit faster
 * @note See also handleWriteValueCommand
 */
void handleWriteChunkCommand(ts_channel_s *tsChannel, ts_response_format_e mode, short offset, short count,
		void *content) {
	tsState.writeChunkCommandCounter++;

	scheduleMsg(&tsLogger, "WRITE CHUNK m=%d p=%d o=%d s=%d", mode, currentPageId, offset, count);

	if (offset > getTunerStudioPageSize(currentPageId)) {
		scheduleMsg(&tsLogger, "ERROR invalid offset %d", offset);
		tunerStudioError("ERROR: out of range");
		offset = 0;
	}

	if (count > getTunerStudioPageSize(currentPageId)) {
		tunerStudioError("ERROR: unexpected count");
		scheduleMsg(&tsLogger, "ERROR unexpected count %d", count);
		count = 0;
	}

	uint8_t * addr = (uint8_t *) (getWorkingPageAddr(currentPageId) + offset);
	memcpy(addr, content, count);
	yellowMagic(currentPageId, offset, count);

	tsSendResponse(tsChannel, mode, NULL, 0);
	printTsStats();
}
Beispiel #2
0
void startTunerStudioConnectivity(void) {
	initLogging(&logger, "tuner studio");

	if (sizeof(engine_configuration_s) != getTunerStudioPageSize(0))
		firmwareError("TS page size mismatch: %d/%d", sizeof(engine_configuration_s), getTunerStudioPageSize(0));

	if (sizeof(TunerStudioOutputChannels) != TS_OUTPUT_SIZE)
		firmwareError("TS outputs size mismatch: %d/%d", sizeof(TunerStudioOutputChannels), TS_OUTPUT_SIZE);

	memset(&tsState, 0, sizeof(tsState));
#if EFI_PROD_CODE
	if (isSerialOverUart()) {
		print("TunerStudio over USB serial");
		usb_serial_start();
	} else {

		print("TunerStudio over USART");
		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));

		sdStart(TS_SERIAL_UART_DEVICE, &tsSerialConfig);
	}
#endif /* EFI_PROD_CODE */
	syncTunerStudioCopy();

	addConsoleAction("tsinfo", printStats);

	chThdCreateStatic(TS_WORKING_AREA, sizeof(TS_WORKING_AREA), NORMALPRIO, tsThreadEntryPoint, NULL);
}
Beispiel #3
0
void handlePageReadCommand(ts_channel_s *tsChannel, ts_response_format_e mode, uint16_t pageId, uint16_t offset,
		uint16_t count) {
	tsState.readPageCommandsCounter++;
	currentPageId = pageId;

#if EFI_TUNER_STUDIO_VERBOSE
	scheduleMsg(&tsLogger, "READ m=%d p=%d o=%d c=%d", mode, (int) currentPageId, offset, count);
	printTsStats();
#endif

	if (currentPageId >= PAGE_COUNT) {
		// something is not right here
		currentPageId = 0;
		tunerStudioError("ERROR: invalid page number");
		return;
	}

	int size = getTunerStudioPageSize(currentPageId);

	if (size < offset + count) {
		scheduleMsg(&tsLogger, "invalid offset/count %d/%d", offset, count);
		sendErrorCode(tsChannel);
		return;
	}

	const uint8_t *addr = (const uint8_t *) (getWorkingPageAddr(currentPageId) + offset);
	tsSendResponse(tsChannel, mode, addr, count);
#if EFI_TUNER_STUDIO_VERBOSE
	scheduleMsg(&tsLogger, "Sending %d done", count);
#endif
}
Beispiel #4
0
/**
 * 'Write' command receives a single value at a given offset
 * @note Writing values one by one is pretty slow
 */
void handleWriteValueCommand(ts_channel_s *tsChannel, ts_response_format_e mode, uint16_t page, uint16_t offset,
		uint8_t value) {
	tsState.writeValueCommandCounter++;

	currentPageId = page;

	tunerStudioDebug("got W (Write)"); // we can get a lot of these

#if EFI_TUNER_STUDIO_VERBOSE
//	scheduleMsg(logger, "Page number %d\r\n", pageId); // we can get a lot of these
#endif

//	int size = sizeof(TunerStudioWriteValueRequest);
//	scheduleMsg(logger, "Reading %d\r\n", size);

	if (offset > getTunerStudioPageSize(currentPageId)) {
		tunerStudioError("ERROR: out of range2");
		scheduleMsg(&tsLogger, "ERROR offset %d", offset);
		offset = 0;
		return;
	}

	efitimems_t nowMs = currentTimeMillis();
	if (nowMs - previousWriteReportMs > 5) {
		previousWriteReportMs = nowMs;
		scheduleMsg(&tsLogger, "page %d offset %d: value=%d", currentPageId, offset, value);
	}

	getWorkingPageAddr(currentPageId)[offset] = value;

	yellowMagic(currentPageId, offset, 1);

//	scheduleMsg(logger, "va=%d", configWorkingCopy.boardConfiguration.idleValvePin);
}
Beispiel #5
0
void printTsStats(void) {
#if EFI_PROD_CODE
	if (!isSerialOverUart()) {
		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);
	}
#endif /* EFI_PROD_CODE */
	scheduleMsg(&tsLogger, "TunerStudio size=%d / total=%d / errors=%d / H=%d / O=%d / P=%d / B=%d",
			sizeof(tsOutputChannels), tsState.tsCounter, tsState.errorCounter, tsState.queryCommandCounter,
			tsState.outputChannelsCommandCounter, tsState.readPageCommandsCounter, tsState.burnCommandCounter);
	scheduleMsg(&tsLogger, "TunerStudio W=%d / C=%d / P=%d / page=%d", tsState.writeValueCommandCounter,
			tsState.writeChunkCommandCounter, tsState.pageCommandCounter, currentPageId);
	scheduleMsg(&tsLogger, "page size=%d", getTunerStudioPageSize(currentPageId));

//	scheduleMsg(logger, "analogChartFrequency %d",
//			(int) (&engineConfiguration->analogChartFrequency) - (int) engineConfiguration);
//
//	int fuelMapOffset = (int) (&engineConfiguration->fuelTable) - (int) engineConfiguration;
//	scheduleMsg(logger, "fuelTable %d", fuelMapOffset);
//
//	int offset = (int) (&boardConfiguration->hip9011Gain) - (int) engineConfiguration;
//	scheduleMsg(&tsLogger, "hip9011Gain %d", offset);
//
//	offset = (int) (&engineConfiguration->crankingCycleBins) - (int) engineConfiguration;
//	scheduleMsg(&tsLogger, "crankingCycleBins %d", offset);
//
//	offset = (int) (&engineConfiguration->engineCycle) - (int) engineConfiguration;
//	scheduleMsg(&tsLogger, "engineCycle %d", offset);
}
Beispiel #6
0
void handlePageReadCommand(ts_response_format_e mode, uint16_t pageId, uint16_t offset, uint16_t count) {
	tsState.readPageCommandsCounter++;
	tunerStudioDebug("got R (Read page)");
	tsState.currentPageId = pageId;

#if EFI_TUNER_STUDIO_VERBOSE
	scheduleMsg(&logger, "Page requested: page %d offset=%d count=%d", (int)tsState.currentPageId, offset, count);
#endif

	if (tsState.currentPageId > MAX_PAGE_ID) {
		scheduleMsg(&logger, "invalid Page number %x", tsState.currentPageId);

		// something is not right here
		tsState.currentPageId = 0;
		tunerStudioError("ERROR: invalid page");
		return;
	}

	int size = getTunerStudioPageSize(tsState.currentPageId);

	if (size < offset + count) {
		scheduleMsg(&logger, "invalid offset/count %d/%d", offset, count);
		sendErrorCode();
		return;
	}

	const uint8_t *addr = (const uint8_t *) (getWorkingPageAddr(tsState.currentPageId) + offset);
	tsSendResponse(mode, addr, count);
#if EFI_TUNER_STUDIO_VERBOSE
	scheduleMsg(&logger, "Sending %d done", count);
#endif
}
Beispiel #7
0
void startTunerStudioConnectivity(void) {
	if (sizeof(persistent_config_s) != getTunerStudioPageSize(0))
		firmwareError("TS page size mismatch: %d/%d", sizeof(persistent_config_s), getTunerStudioPageSize(0));

	if (sizeof(TunerStudioOutputChannels) != TS_OUTPUT_SIZE)
		firmwareError("TS outputs size mismatch: %d/%d", sizeof(TunerStudioOutputChannels), TS_OUTPUT_SIZE);

	memset(&tsState, 0, sizeof(tsState));
	syncTunerStudioCopy();

	addConsoleAction("tsinfo", printTsStats);
	addConsoleAction("reset_ts", resetTs);
	addConsoleActionI("set_ts_speed", setTsSpeed);

	tsChannel.channel = getTsSerialDevice();
	tsChannel.writeBuffer = tsCrcWriteBuffer;

	chThdCreateStatic(tsThreadStack, sizeof(tsThreadStack), NORMALPRIO, tsThreadEntryPoint, NULL);
}
Beispiel #8
0
/**
 * This command is needed to make the whole transfer a bit faster
 * @note See also handleWriteValueCommand
 */
void handleWriteChunkCommand(ts_response_format_e mode, short offset, short count, void *content) {
	tsState.writeChunkCommandCounter++;

	scheduleMsg(&logger, "receiving page %d chunk offset %d size %d", tsState.currentPageId, offset, count);

	if (offset > getTunerStudioPageSize(tsState.currentPageId)) {
		scheduleMsg(&logger, "ERROR offset %d", offset);
		tunerStudioError("ERROR: out of range");
		offset = 0;
	}

	if (count > getTunerStudioPageSize(tsState.currentPageId)) {
		tunerStudioError("ERROR: unexpected count");
		scheduleMsg(&logger, "ERROR count %d", count);
		count = 0;
	}

	uint8_t * addr = (uint8_t *) (getWorkingPageAddr(tsState.currentPageId) + offset);
	memcpy(addr, content, count);

	tsSendResponse(mode, NULL, 0);
}
Beispiel #9
0
void handleCrc32Check(ts_channel_s *tsChannel, ts_response_format_e mode, uint16_t pageId, uint16_t offset,
		uint16_t count) {
	tsState.crc32CheckCommandCounter++;

	count = SWAP_UINT16(count);

	count = getTunerStudioPageSize(pageId);

	scheduleMsg(&tsLogger, "CRC32 request: pageId %d offset %d size %d", pageId, offset, count);

	uint32_t crc = SWAP_UINT32(crc32((void * ) getWorkingPageAddr(0), count));

	scheduleMsg(&tsLogger, "CRC32 response: %x", crc);

	tsSendResponse(tsChannel, mode, (const uint8_t *) &crc, 4);
}