-
-
Save fluke9/697f264618ec5929cabd6211fc25b673 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Windows.h> | |
#include <WinBase.h> | |
#include <consoleapi.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string> | |
#include <iostream> | |
#include "messylogger.h" | |
#include "measurement.h" | |
#include "getopt.h" | |
#include "log.h" | |
#include "serial.h" | |
#include "KWP2000.h" | |
#include "MCmess.h" | |
#include "KWPmain.h" | |
#include "logfile.h" | |
#include "iniparser/INIReader.h" | |
#include <iostream> | |
#define RAM_TABLE 0x382a2e | |
#define DEFAULT_SAMPLERATE 20 | |
std::map<int, Measurement*> g_measurementTable; | |
int g_onemeasurementonly = 0; | |
char g_ecuDefinitionFile[MAX_PATH]; | |
int g_realtimeoutput = 0; | |
int g_realtimeflush = 0; | |
char* g_logfilename = NULL; | |
int g_syncreading = 0; | |
char* g_logdeffile = NULL; | |
int g_verbose = 0; | |
int g_hertz = 0; | |
int g_ctrlc = 0; | |
// have to handle this more intelligent in the future, | |
// looks like the handler is threaded so all sorts of shit can happen | |
// for now the 95% solution (tm) will work | |
BOOL WINAPI CtrlHandler(DWORD fdwCtrlType) | |
{ | |
switch (fdwCtrlType) | |
{ | |
case CTRL_C_EVENT: | |
g_ctrlc = 1; | |
LogfileFlushToDisk(); | |
//LogfileClose(); // can generate an execption if we are still writing | |
if (g_syncreading) | |
{ | |
printf("\n"); | |
LOG("<CTRL-C>: received, exiting sync-reading..."); | |
McMessExitReadSyncTable(); | |
Sleep(100); | |
exit(0); | |
} | |
else | |
{ | |
printf("\n"); | |
LOG("<CTRL-C>: received, exiting..."); | |
exit(0); | |
} | |
return TRUE; | |
case CTRL_CLOSE_EVENT: | |
// crude but we dont have time for the loop to finish its thing | |
Serial_SendAndConsumeByte(0xAA); | |
return TRUE; | |
default: | |
return FALSE; | |
} | |
} | |
int McMessMain(); | |
void usage(); | |
void ParseME7LoggerCfgFile(const char* filename); | |
void usage() | |
{ | |
printf("%s %s (C) 2019 %s\n", PROGNAME, PROGVERSION, PROGAUTHOR); | |
printf("Usage: %s [-p <comport>] [-s <rate>] [-a|-m] [-1] [-R] [-o <logfile>]", PROGNAME); | |
printf(" [-P <ecubin> -M 0x38XXXX] <logconfig>\n"); | |
printf("\n"); | |
printf("Options:\n"); | |
printf(" -l : list available serial ports\n"); | |
printf(" -p <comport> : interface is connected to <comport> (default = COM6)\n"); | |
printf(" -s <sps> : samplerate(in hertz), overrides rate from log config file\n"); | |
printf(" -a : print absolute timestamps(default: seconds.milliseconds since start)\n"); | |
printf(" -m : print millisecond timestamps(default: seconds.milliseconds since start)\n"); | |
printf(" -1 : just read one measurement and then stop\n"); | |
printf(" -r : write logged data to file immediately(for realtime postproc),\n"); | |
printf(" default is to flush only every full second to disk\n"); | |
printf(" -R : show logged data on screen(realtime display), this turns off\n"); | |
printf(" writing to logfile if not requested explicitly via - o <logfile>\n"); | |
printf(" -o <logfile> : write log to file <logfile>, output is appended if logfile already exists\n"); | |
printf(" default logfile is '<logconfig>_<date>_<time>.csv' in logs - directory\n"); | |
printf(" -P <ecubin> : patches McMess in ecu binary <ecubin> to relocate the memory table and\n"); | |
printf(" allow more than 6 bytes of data to be logged.\n"); | |
printf(" Always correct the checksums of <ecubin_patched> before flashing!\n"); | |
printf(" -M <address> : address in ram which should be used if it can not be automatically\n"); | |
printf(" detected while patching the ecu binary <ecubin> also used for logging.\n"); | |
printf(" Always correct the checksums of <ecubin_patched> before flashing!\n"); | |
printf(" <logconfig> : use log configuration file <logconfig>(from logs - directory)\n"); | |
printf("\n"); | |
} | |
int main(int argc, char** argv) | |
{ | |
memset(g_ecuDefinitionFile, 0, sizeof(g_ecuDefinitionFile)); | |
int c; | |
int listports = 0; | |
char* port = NULL; | |
char* patchfile = NULL; | |
unsigned long memoryaddress = 0x0; | |
while ((c = getopt(argc, argv, "vp:s:o:rlP:M:1R")) != -1) | |
{ | |
switch (c) | |
{ | |
case 'v': | |
g_verbose++; | |
break; | |
case 'p': | |
port = optarg; | |
break; | |
case 's': | |
g_hertz = atoi(optarg); | |
if (g_hertz < 5) | |
g_hertz = 5; | |
break; | |
case 'o': | |
g_logfilename = optarg; | |
break; | |
case 'r': | |
g_realtimeflush = 1; | |
break; | |
case 'l': | |
listports = 1; | |
break; | |
case 'P': | |
patchfile = optarg; | |
break; | |
case 'M': | |
memoryaddress = strtol (optarg, NULL, 16); | |
break; | |
case '1': | |
g_onemeasurementonly = 1; | |
break; | |
case 'R': | |
g_realtimeoutput = 1; | |
break; | |
default: | |
LOG("unknown option given, ignoring...", c); | |
break; | |
} | |
} | |
g_logdeffile = argv[optind]; | |
if (!patchfile && g_logdeffile == NULL) | |
{ | |
usage(); | |
exit(0); | |
} | |
printf("%s %s\n\n", PROGNAME, PROGVERSION); | |
if (patchfile) | |
{ | |
printf("patching file %s memorytable @ 0x%X\n", patchfile, memoryaddress); | |
//PatchFile(g_patchfile); | |
exit(0); | |
} | |
if (listports) | |
{ | |
Serial_EnumeratePorts(); | |
Serial_QueryPorts(); | |
exit(0); | |
} | |
ParseME7LoggerCfgFile(g_logdeffile); | |
std::string comport = "COM6"; | |
if (port != NULL) | |
{ | |
comport = "COM" + std::string(port); | |
} | |
Serial_OpenPort(comport); | |
SetConsoleCtrlHandler(CtrlHandler, TRUE); | |
McMessMain(); | |
} | |
std::wstring GetCurrentWorkingDirectory() | |
{ | |
wchar_t infoBuf[MAX_PATH]; | |
if (!GetCurrentDirectory(_countof(infoBuf), infoBuf)) | |
{ | |
printf("could not get current directory!\n"); | |
exit(0); | |
} | |
return infoBuf; | |
} | |
void ParseME7LoggerCfgFile(const char* filename) | |
{ | |
char directory[MAX_PATH]; | |
size_t charsConverted; | |
std::wstring currentDirectory = GetCurrentWorkingDirectory(); | |
memset(directory, 0, sizeof(directory)); | |
wcstombs_s(&charsConverted, directory, currentDirectory.c_str(), sizeof(directory)-1); | |
std::string cfgFile = filename; | |
if (!(cfgFile.length() >= 2 && cfgFile.c_str()[1] == ':')) // not full path X:\... | |
cfgFile = std::string(directory) + "\\..\\logs\\" + std::string(filename); | |
printf("Loading log config file: %s\n", cfgFile.c_str()); | |
INIReader readerCfg(cfgFile); | |
if (readerCfg.ParseError() < 0) | |
{ | |
fprintf(stderr, "Can't load '%s'\n", cfgFile.c_str()); | |
exit(0); | |
} | |
std::string ecuCharacteristicsFile = readerCfg.Get("Configuration", "ECUCharacteristics", "UNDEFINED"); | |
if (ecuCharacteristicsFile == "UNDEFINED") | |
{ | |
printf("ECUCharacteristics undefined, please fix...\n"); | |
exit(0); | |
} | |
sprintf_s(g_ecuDefinitionFile, "%s", ecuCharacteristicsFile.c_str()); | |
//printf("SamplesPerSecond %d\n", readerCfg.GetInteger("Configuration", "SamplesPerSecond", 50)); | |
//printf("ECUCharacteristics %s\n", ECUCharacteristicsFile.c_str()); | |
//printf("\n"); | |
if (g_hertz == 0) | |
g_hertz = readerCfg.GetInteger("Configuration", "SamplesPerSecond", DEFAULT_SAMPLERATE); | |
std::string ecuFilePath = std::string(directory) + "\\..\\ecus\\" + ecuCharacteristicsFile; | |
printf("Loading ecu characteristics file: %s\n", ecuFilePath.c_str()); | |
INIReader readerEcu(ecuFilePath); | |
if (readerEcu.ParseError() < 0) | |
{ | |
fprintf(stderr, "Can't load ECUCharacteristics '%s'\n", ecuFilePath.c_str()); | |
exit(0); | |
} | |
/*printf("Version %1.2f\n", readerEcu.GetReal("Version", "Version", 1.0));*/ | |
printf("\n"); | |
printf("[Communication]\n"); | |
printf("Connect %-15s (IGNORED)\n", readerEcu.Get("Communication", "Connect", "HIGHSPEED").c_str()); | |
printf("Communicate %-15s (IGNORED)\n", readerEcu.Get("Communication", "Communicate", "HM0").c_str()); | |
printf("Speed %-15d (IGNORED)\n", readerEcu.GetInteger("Communication", "Speed", 10400)); | |
/*printf("HWNumber %s\n", readerEcu.Get("Identification", "HWNumber", "0261999999").c_str()); | |
printf("SWNumber %s\n", readerEcu.Get("Identification", "SWNumber", "0123456789").c_str()); | |
printf("Partnumber %s\n", readerEcu.Get("Identification", "PartNumber", "1111111111").c_str()); | |
printf("SWVersion %s\n", readerEcu.Get("Identification", "SWVersion", "1").c_str()); | |
printf("EngineId %s\n", readerEcu.Get("Identification", "EngineId", "V6").c_str()); | |
*/ | |
printf("\n"); | |
printf("Logged variables are:\n"); | |
printf("#no.: name , alias , addr ,sz, bitm, S, I, A, B, unit\n"); | |
printf("#------------------------------------------------------------------------------------------------------------\n"); | |
int index = 0; | |
while (1) | |
{ | |
std::string result = readerCfg.Get("LogVariables", std::to_string(index), "UNDEFINED").c_str(); | |
if (result == "UNDEFINED") | |
{ | |
// we did not find any more items in the [LogVariables] section | |
break; | |
} | |
std::string value = readerCfg.Get("LogVariables", result, "UNDEFINED").c_str(); | |
if (result == "UNDEFINED") | |
{ | |
printf("error finding cfg item %s\n", result.c_str()); | |
exit(0); | |
} | |
std::string mess = readerEcu.Get("Measurements", result, "UNDEFINED"); | |
if (result == "UNDEFINED") | |
{ | |
printf("error finding variable %s in ecu definition, fix your .cfg or .ecu\n", result.c_str()); | |
exit(0); | |
} | |
Measurement* measItem = new Measurement(); | |
int idx = 0; | |
size_t pos = 0; | |
std::string token; | |
measItem->name = result; | |
int itemidx = 0; | |
while ((pos = mess.find(",")) != std::string::npos) | |
{ | |
token = mess.substr(0, pos); | |
token.erase(0, token.find_first_not_of("{ \t")); // ltrim whitespace + curlybrace | |
token.erase(token.find_last_not_of("} \t") + 1); // rtrim whitespace + curlybrace | |
// Name, { Alias }, Address, Size, Bitmask, { Unit }, S, I, A, B, Comment | |
// blah, {IgnitionRetardCyl1}, 0x380AAB, 1, 0x0000, { ^KW }, 1, 0, 0.75, 0, { zyl.ind.ZW - Spõtverstellung inkl.Dyn.vorhalt } | |
switch (itemidx++) | |
{ | |
case 0: measItem->alias = token; break; | |
case 1: measItem->addr = std::stoul(token, nullptr, 16); break; | |
case 2: measItem->size = std::stoi(token); break; | |
case 3: measItem->bitmask = std::stoul(token, nullptr, 16); break; | |
case 4: measItem->unit = token; break; | |
case 5: measItem->signedness = std::stoi(token); break; | |
case 6: measItem->inverse = std::stoi(token); break; | |
case 7: measItem->factor = std::stod(token); break; | |
case 8: measItem->offset = std::stod(token); break; | |
//case 9: comment; | |
} | |
mess.erase(0, pos + 1); | |
} | |
g_measurementTable[index] = measItem; | |
index++; | |
} | |
int no = 1; | |
for (std::map<int, Measurement*>::iterator it = g_measurementTable.begin(); it != g_measurementTable.end(); it++) | |
{ | |
Measurement* measItem = it->second; | |
std::string factorStr = std::to_string(measItem->factor); | |
factorStr.erase(factorStr.find_last_not_of("0") + 1); // knock trailing zeros off | |
factorStr.erase(factorStr.find_last_not_of(".") + 1); // and maybe the lonely dot | |
printf("#%03d: %-20s, %-32s, %06X , %1d, %04X, %1d, %1d, %10s, %3d, '%s'\n", | |
no++, | |
measItem->name.c_str(), | |
measItem->alias.c_str(), | |
measItem->addr, | |
measItem->size, | |
measItem->bitmask, | |
measItem->signedness, | |
measItem->inverse, | |
factorStr.c_str(), | |
(int)measItem->offset, | |
measItem->unit.c_str()); | |
} | |
printf("\n"); | |
} | |
void ParseDataFromCrank(uint8_t* buf, uint8_t len) | |
{ | |
uint16_t numberOfMeasurements = 0; | |
uint32_t wantedLen = 0; | |
uint32_t bufidx = 0; | |
for (std::map<int, Measurement*>::iterator it = g_measurementTable.begin(); it != g_measurementTable.end(); it++) | |
{ | |
Measurement* measItem = it->second; | |
if ( measItem->size == 1 | |
|| measItem->size == 2) | |
wantedLen += measItem->size; | |
} | |
if (len != wantedLen) | |
{ | |
LOG("ERROR: len does not match wantedLen %d != %d", len, wantedLen); | |
return; | |
} | |
LogfileLogItemsBegin(); | |
for (std::map<int, Measurement*>::iterator it = g_measurementTable.begin(); it != g_measurementTable.end(); it++) | |
{ | |
Measurement* measItem = it->second; | |
if ( measItem->size == 1 | |
|| measItem->size == 2) | |
{ | |
double value; | |
uint16_t valueraw; | |
if (measItem->size == 1) | |
value = valueraw = *((uint8_t*)(buf + bufidx)); | |
if (measItem->size == 2) | |
value = valueraw = *((uint16_t*)(buf + bufidx)); | |
value = value * measItem->factor; | |
value -= measItem->offset; | |
std::string strvalue = std::to_string(value); | |
strvalue.erase(strvalue.find_last_not_of("0") + 1); // knock trailing zeros off | |
strvalue.erase(strvalue.find_last_not_of(".") + 1); // and maybe the lonely dot | |
//LOG("%s = %s %s", measItem->name.c_str(), strvalue.c_str(), measItem->unit.c_str()); | |
LogfileLogOneItem(strvalue); | |
bufidx += measItem->size; | |
} | |
} | |
LogfileItemsFinished(); | |
} | |
int McMessMain() | |
{ | |
bool highspeed = true; | |
//McMessTryRevive(); | |
McMessStandAloneInit(Serial_GetHandle(), highspeed); | |
Sleep(500); | |
if (highspeed == false) | |
Serial_ChangeBaudRate(10400, SPACEPARITY, ONESTOPBIT); | |
else | |
Serial_ChangeBaudRate(125000, SPACEPARITY, TWOSTOPBITS); | |
int numBytes = 0; | |
LOG("writing to measurement table in ram at 0x%6x", RAM_TABLE + 2); | |
McMessSetupWrite((RAM_TABLE+2) & 0xFFFF); | |
unsigned int numberOfMeasurements = 0; | |
for (std::map<int, Measurement*>::iterator it = g_measurementTable.begin(); it != g_measurementTable.end(); it++) | |
{ | |
Measurement* measItem = it->second; | |
LOG_REWIND("setting up %-12s %-20s @ 0x%X size=%d ", measItem->name.c_str(), measItem->alias.c_str(), measItem->addr, measItem->size); | |
if (measItem->size == 1) | |
{ | |
McMessWriteByteAddressToTable(measItem->addr); | |
numBytes += measItem->size; | |
numberOfMeasurements++; | |
} | |
else if (measItem->size == 2) | |
{ | |
McMessWriteWordAddressToTable(measItem->addr); | |
numBytes += measItem->size; | |
numberOfMeasurements++; | |
} | |
else | |
{ | |
LOG_REWIND("setting up %-12s -> unsupported size %d, ignoring! ", measItem->name.c_str(), measItem->size); | |
} | |
} | |
LOG_REWIND("writing %d items to memory table finished... \n", numberOfMeasurements); | |
LOG("writing size %d of measurement table to ram at 0x%6x", numBytes, RAM_TABLE); | |
McMessSetupWrite(RAM_TABLE & 0xFFFF); | |
McMessWriteByte(numBytes, true); | |
McMessWriteByte(0x00, true); | |
LOG("finished setting up %d measurements with total of %d bytes", numberOfMeasurements, numBytes); | |
// TODO: verify table is correct | |
LOG("switching to sync reading... use <CTRL-C> to end, otherwise your session might get stuck!"); | |
g_syncreading = 1; // for the CTRL-C handler | |
McMessSwitchToSyncReading(); | |
if (!LogfileOutputHeader(numberOfMeasurements, numBytes)) | |
{ | |
LOG("creating logfile failed!"); | |
McMessExitReadSyncTable(); | |
exit(0); | |
} | |
int mess = 0; | |
int totalmess = 0; | |
int lasthertz = 0; | |
ULONGLONG wantedduration = 1000 / g_hertz; | |
ULONGLONG msstart = GetTickCount64(); | |
ULONGLONG duration = GetTickCount64(); | |
// first answer does not need to be requested as 0x13D is still in receive buffer | |
while (1) | |
{ | |
uint8_t buf[255]; | |
Serial_ConsumeBytes("DATA", buf, numBytes + 1); | |
if (!g_realtimeoutput) | |
LOG_REWIND("Current rate %dhz total blocks %d total measured bytes %d", lasthertz, totalmess, totalmess * numBytes); | |
ParseDataFromCrank(buf, numBytes); | |
if (g_onemeasurementonly) | |
{ | |
McMessExitReadSyncTable(); | |
printf("\n"); | |
LOG("exiting after one measurement as requested with -1\n"); | |
break; | |
} | |
mess++; | |
totalmess++; | |
if (GetTickCount64() - msstart >= 1000) | |
{ | |
msstart = GetTickCount64(); | |
lasthertz = mess; | |
mess = 0; | |
if (!g_realtimeflush) | |
LogfileFlushToDisk(); | |
} | |
// delay to reach the wanted speed, needs to be improved as windows does not have sub-ms delays | |
ULONGLONG diff = GetTickCount64() - duration; | |
if (diff < wantedduration) | |
{ | |
Sleep((DWORD)(wantedduration - diff)); | |
} | |
duration = GetTickCount64(); | |
if (g_ctrlc) | |
break; | |
McMessReadSyncTable(); | |
} | |
Sleep(100); | |
LOG("exiting..."); | |
return 0; | |
} | |
#if 0 | |
unsigned short startaddr = 0x383AA0 & 0xFFFF; | |
unsigned short addr = startaddr; | |
unsigned short index = 0; | |
unsigned char buffer[1024]; | |
while (addr < (startaddr + 1024)) | |
{ | |
uint8_t tempbytes[2]; | |
memcpy(tempbytes, McMessReadBytes(addr), 2); | |
buffer[index] = tempbytes[1]; | |
buffer[index + 1] = tempbytes[0]; | |
index += 2; | |
addr += 2; | |
} | |
FILE* fd; | |
fopen_s(&fd, "eepromdump.bin", "wb"); | |
fwrite(buffer, 1, sizeof(buffer), fd); | |
fclose(fd); | |
for (int i = 0; i < (1024 / 16); i++) | |
{ | |
LOG("i=%d", i); | |
Serial_LogBytes("EEPROM", buffer + (i * 16), 16); | |
} | |
exit(0); | |
while (1) | |
{ | |
McMessSetupWrite(0x0ec0); | |
McMessWriteByte(0xff); | |
McMessWriteByte(0xff); | |
McMessSetupWrite(0x0ec2); | |
McMessWriteByte(0xff); | |
McMessWriteByte(0xff); | |
McMessSetupWrite(0x0ec4); | |
McMessWriteByte(0xff); | |
McMessWriteByte(0xff); | |
McMessSetupWrite(0x0ec6); | |
McMessWriteByte(0xff); | |
McMessWriteByte(0xff); | |
} | |
while (1) | |
{ | |
/*McMessSetupWrite(0xf7a4); | |
McMessWriteByte(0xff); | |
McMessWriteByte(0xff); | |
*/ | |
LOG("read...."); | |
Sleep(400); | |
McMessReadBytes(0x0ec0); | |
} | |
while (1) | |
McMessReadBytes(0xf7a4); | |
/* | |
LOG("reading back log address table"); | |
unsigned long address = 0x2a2e; | |
uint8_t logbytes[512]; | |
unsigned int idx = 0; | |
for (int i = 0; i < numbytes+1; i++) | |
{ | |
uint8_t bytes[2]; | |
memcpy(bytes, McMessReadBytes(address), 2); | |
logbytes[idx] = bytes[0]; | |
logbytes[idx+1] = bytes[1]; | |
memcpy(bytes, McMessReadBytes(address+2), 2); | |
logbytes[idx+2] = bytes[0]; | |
logbytes[idx+3] = bytes[1]; | |
address += 4; | |
idx += 4; | |
} | |
LogBytes("LOGTABLE", logbytes, idx); | |
printf("\n"); | |
*/ | |
_____________________________CODE DUMP HERE________________________________ | |
#if 0 | |
KWP2000_SetTargetSource(0x10, 0xF1); | |
/*while (GetTickCount() - hertzdelay < (1000 / maxhertz)) | |
Sleep(1); | |
hertzdelay = GetTickCount();*/ | |
//Sleep(5); | |
//revive | |
/*Serial_ChangeBaudRate(125000, MARKPARITY, ONESTOPBIT); | |
Serial_SendByte(0xAA); Consume1Byte('X'); | |
Serial_SendByte(0xAA); Consume1Byte('X'); | |
Serial_SendByte(0xAA); Consume1Byte('X'); | |
Serial_ChangeBaudRate(10400, NOPARITY, ONESTOPBIT); | |
Serial_SendByte(0xAA); Consume1Byte('X'); | |
Serial_SendByte(0xAA); Consume1Byte('X'); | |
Serial_SendByte(0xAA); Consume1Byte('X'); | |
Sleep(1000); | |
*/ | |
/*BIT9_OFF; | |
McMessReadBytes(0xe0a5); | |
McMessReadBytes(0xe0a7); | |
McMessReadBytes(0xe0a9); | |
McMessReadBytes(0xe0ab); | |
McMessReadBytes(0xe0ad); | |
McMessReadBytes(0xe0af); | |
BIT9_ON;*/ | |
//Sleep(5000); | |
//exit(1); | |
g_exit_receiver_thread = 1; | |
LOG("receiver disabled"); | |
unsigned short address = 0x0000; | |
//Sleep(5000); | |
// nmot_w f87c | |
// tmot 0c2e | |
// tans 0c26 | |
// zwout f9f0 | |
// zwist f9ee | |
/* | |
McMessSetupSetLowAddress(0x00); | |
//McMessSetupSetLowAddress(0x00); | |
McMessWriteSyncTable(0xf8); McMessWriteSyncTable(0x7a); | |
McMessWriteSyncTable(0xf8); McMessWriteSyncTable(0x7a); | |
McMessWriteSyncTable(0xf8); McMessWriteSyncTable(0x7a); | |
McMessWriteSyncTable(0xf8); McMessWriteSyncTable(0x7a); | |
McMessWriteSyncTable(0xf8); McMessWriteSyncTable(0x7a); | |
McMessWriteSyncTable(0xf8); McMessWriteSyncTable(0x7a); | |
McMessWriteSyncTable(0xf8); McMessWriteSyncTable(0x7a); | |
*/ | |
/*McMessSetupSetLowAddress(0x00); | |
for (int i = 0; i < 12; i++) | |
McMessReadSyncTable(); | |
*/ | |
//Sleep(5000); | |
//exit(0); | |
McMessReadBytes(0x310c); | |
Sleep(500); | |
McMessSetupWrite(0x310c); | |
McMessWriteByte(0xcc); | |
McMessWriteByte(0xcc); | |
McMessReadBytes(0x310c); | |
DWORD ticks = GetTickCount(); | |
McMessSetupWrite(0x3b12); | |
for (int i = 0; i <= strlen("BOANIGGER!"); i++) | |
{ | |
McMessWriteByte("BOANIGGER!"[i]); | |
} | |
McMessSetupWrite(0x3b22); | |
for (int i = 0; i <= strlen("ZIRBNSTUBN1"); i++) | |
{ | |
McMessWriteByte("ZIRBNSTUBN1"[i]); | |
} | |
Serial_ChangeBaudRate(125000, SPACEPARITY, TWOSTOPBITS); | |
address = 0x3aa0; | |
while (address <= 0x3aa0 + 0x200) | |
{ | |
unsigned char bytes[2]; | |
bytes[0] = (address & 0xFF00) >> 8; | |
bytes[1] = address & 0xFF; | |
printf("requesting: %04x\n", address); | |
Serial_SendBytes(bytes, 2); | |
address += 2; | |
Sleep(40); | |
//Serial_SendByte(0x31); Sleep(20); | |
//Serial_SendByte(0x14); Sleep(20); | |
} | |
//Sleep(20); | |
//Serial_SendByte(0x38); | |
Sleep(20); | |
for (int i = 0; i < 0x2f; i++) | |
{ | |
Serial_SendByte(0x19); | |
Sleep(30); | |
} | |
Serial_ChangeBaudRate(125000, SPACEPARITY, TWOSTOPBITS); | |
Sleep(500); | |
exit(0); | |
unsigned short addresstable[] = { 0x0b35, 0xf87c, 0x0c2e, 0x0c26, 0xf9f0, 0xe1cb }; | |
int idx = 0; | |
int set = 0; | |
while (1) | |
{ | |
address = 0x00; // addresstable[idx]; | |
McMessReadBytes(address); | |
Sleep(3); | |
idx++; | |
if (idx == 6) | |
{ | |
idx = 0; | |
LOG_KWP2000_MSG("set done %d timedelta %d", set++, ticks - GetTickCount()); | |
ticks = GetTickCount(); | |
} | |
//printf("%d\n", i++); | |
} | |
Sleep(30000); | |
#endif | |
#endif | |
#ifdef OLD | |
#define WAIT_FOR_SYNC 0 | |
#define WAIT_FOR_KB1 1 | |
#define WAIT_FOR_KB2 2 | |
#define WAIT_FOR_INVADR 3 | |
#define DUMMY 4 | |
void SerialStateMachine(HANDLE serialHandle, unsigned char c) | |
{ | |
switch (g_serial_state) | |
{ | |
case WAIT_FOR_SYNC: | |
printf("\t waiting for sync byte 0x55 (got 0x%02X)\n", c); | |
if (c == 0x55) | |
g_serial_state++; | |
break; | |
case WAIT_FOR_KB1: | |
printf("\t got KB1 0x%02X\n", c); | |
g_kb1 = c; | |
g_serial_state++; | |
break; | |
case WAIT_FOR_KB2: | |
printf("\t got KB2 0x%02X\n", c); | |
g_kb2 = c; | |
Sleep(30); | |
Serial_SendByte(serialHandle, ~g_kb2); | |
g_serial_state++; | |
break; | |
case WAIT_FOR_INVADR: | |
printf("\t got inv addr 0x%02X\n", ~c & 0xFF); | |
if ((~c & 0xFF) == 0x10) | |
{ | |
printf("\t ADDRESS OK\n"); | |
DWORD bytesRead; | |
Serial_SendByte(serialHandle, 0x02); | |
Serial_SendByte(serialHandle, 0x1A); | |
Serial_SendByte(serialHandle, 0x80); | |
Serial_SendByte(serialHandle, 0x9C); // 86 | |
ReadFile(serialHandle, &c, 1, &bytesRead, 0); | |
ReadFile(serialHandle, &c, 1, &bytesRead, 0); | |
ReadFile(serialHandle, &c, 1, &bytesRead, 0); | |
ReadFile(serialHandle, &c, 1, &bytesRead, 0); | |
//Sleep(200); | |
/* | |
// 03 10 86 14 ad | |
Serial_SendByte(serialHandle, 0x03); | |
Serial_SendByte(serialHandle, 0x10); | |
Serial_SendByte(serialHandle, 0x85); // 86 | |
Serial_SendByte(serialHandle, 0x14); | |
Serial_SendByte(serialHandle, 0xac); // ad | |
*/ | |
// 03 10 86 14 ad | |
/*Serial_SendByte(serialHandle, 0x03); | |
ReadFile(serialHandle, &c, 1, &bytesRead, 0); | |
Serial_SendByte(serialHandle, 0x10); | |
ReadFile(serialHandle, &c, 1, &bytesRead, 0); | |
Serial_SendByte(serialHandle, 0x85); // 86 | |
ReadFile(serialHandle, &c, 1, &bytesRead, 0); | |
Serial_SendByte(serialHandle, 0x14); | |
ReadFile(serialHandle, &c, 1, &bytesRead, 0); | |
Serial_SendByte(serialHandle, 0xac); // ad | |
ReadFile(serialHandle, &c, 1, &bytesRead, 0); | |
*/ | |
/* Sleep(500); | |
*/ | |
g_serial_state++; | |
break; | |
} | |
else | |
LOG("\t ADDRESS NOT OK\n"); | |
break; | |
case DUMMY: | |
//printf("\t got 0x%02X\n", c); | |
break; | |
} | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment