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 }
/** * '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); }
/** * 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(); }
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 }
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); }
/** * 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); }