36 #include "xcp_terminal.h" 45 #include <sys/select.h> 51 struct termios orig_termios;
53 static void reset_terminal_mode(
void);
54 static void set_options(
void);
55 static void set_raw_terminal_mode(
void);
56 static int kbhit(
void);
57 static int getch(
void);
60 static void SystemInformation(
void);
61 static void DisplayHelp(
void);
62 void FlsEmu_Info(
void);
63 void Xcp_DisplayInfo(
void);
64 void XcpDaq_PrintDAQDetails(
void);
65 void XcpDaq_Info(
void);
68 void *XcpTerm_Thread(
void *param) {
73 INPUT_RECORD irInBuf[128];
76 XCP_UNREFERENCED_PARAMETER(param);
78 hStdin = GetStdHandle(STD_INPUT_HANDLE);
79 if (hStdin == INVALID_HANDLE_VALUE) {
80 XcpHw_ErrorMsg(
"GetStdHandle", GetLastError());
83 fdwMode = ENABLE_WINDOW_INPUT | ENABLE_MOUSE_INPUT;
84 if (!SetConsoleMode(hStdin, fdwMode)) {
85 XcpHw_ErrorMsg(
"SetConsoleMode", GetLastError());
89 WaitForSingleObject(hStdin, 1000);
91 if (!GetNumberOfConsoleInputEvents(hStdin, &cNumRead)) {
92 XcpHw_ErrorMsg(
"PeekConsoleInput", GetLastError());
95 if (!ReadConsoleInput(hStdin, irInBuf, 128, &cNumRead)) {
96 XcpHw_ErrorMsg(
"ReadConsoleInput", GetLastError());
98 for (idx = 0; idx < cNumRead; ++idx) {
99 switch (irInBuf[idx].EventType) {
101 key = irInBuf[idx].Event.KeyEvent;
103 if (key.wVirtualKeyCode == VK_ESCAPE) {
106 switch (tolower(key.uChar.AsciiChar)) {
109 #if !defined(_MSC_VER) 119 XcpDaq_PrintDAQDetails();
135 static void reset_terminal_mode(
void) { tcsetattr(0, TCSANOW, &orig_termios); }
137 static void set_options(
void) {
140 tcgetattr(STDIN_FILENO, &term);
141 term.c_lflag &= ~(ECHO | ISIG | IEXTEN);
142 term.c_iflag &= ~(IXON | ICRNL | ISTRIP | BRKINT | INPCK);
144 term.c_oflag |= OPOST;
145 tcsetattr(STDIN_FILENO, TCSAFLUSH, &term);
148 static void set_raw_terminal_mode(
void) {
149 struct termios new_termios;
151 tcgetattr(0, &orig_termios);
152 memcpy(&new_termios, &orig_termios,
sizeof(new_termios));
154 atexit(reset_terminal_mode);
155 cfmakeraw(&new_termios);
157 tcsetattr(0, TCSANOW, &new_termios);
160 static int kbhit(
void) {
161 struct timeval tv = {0L, 0L};
166 return select(1, &fds, NULL, NULL, &tv);
169 static int getch(
void) {
171 unsigned char buf[256];
173 if ((len = read(0, &buf,
sizeof(buf))) < 0) {
186 void *XcpTerm_Thread(
void *param) {
189 set_raw_terminal_mode();
195 switch (tolower(key)) {
206 XcpDaq_PrintDAQDetails();
214 static void SystemInformation(
void) {
215 #if XCP_ENABLE_STATISTICS == XCP_ON 216 Xcp_StateType
const *state = Xcp_GetState();
219 printf(
"\n\rSystem-Information\n\r");
220 printf(
"------------------\n\r");
221 XcpTl_PrintConnectionInformation();
222 printf(
"MAX_CTO : %d MAX_DTO: %d\n\r", XCP_MAX_CTO, XCP_MAX_DTO);
223 printf(
"Slave-Blockmode : %s\n\r",
224 (XCP_ENABLE_SLAVE_BLOCKMODE == XCP_ON) ?
"Yes" :
"No");
225 printf(
"Master-Blockmode: %s\n\r",
226 (XCP_ENABLE_MASTER_BLOCKMODE == XCP_ON) ?
"Yes" :
"No");
228 #if XCP_ENABLE_CAL_COMMANDS == XCP_ON 229 printf(
"Calibration : Yes Protected: %s\n\r",
230 (XCP_PROTECT_CAL == XCP_ON) ?
"Yes" :
"No");
232 printf(
"Calibration : No\n\r");
235 #if XCP_ENABLE_PAG_COMMANDS == XCP_ON 236 printf(
"Paging : Yes Protected: %s\n\r",
237 (XCP_PROTECT_PAG == XCP_ON) ?
"Yes" :
"No");
239 printf(
"Paging : No\n\r");
242 #if XCP_ENABLE_DAQ_COMMANDS == XCP_ON 243 printf(
"DAQ : Yes Protected: [DAQ: %s STIM: %s]\n\r",
244 (XCP_PROTECT_DAQ == XCP_ON) ?
"Yes" :
"No",
245 (XCP_PROTECT_STIM == XCP_ON) ?
"Yes" :
"No");
247 printf(
"DAQ : No\n\r");
250 #if XCP_ENABLE_PGM_COMMANDS 251 printf(
"Programming : Yes Protected: %s\n\r",
252 (XCP_PROTECT_PGM == XCP_ON) ?
"Yes" :
"No");
254 printf(
"Programming : No\n\r");
258 if (FlsEmu_Initialized()) {
261 #if XCP_ENABLE_STATISTICS == XCP_ON 262 printf(
"\n\rStatistics\n\r");
263 printf(
"----------\n\r");
264 printf(
"CTOs rec'd : %d\n\r", state->statistics.ctosReceived);
265 printf(
"CROs busy : %d\n\r", state->statistics.crosBusy);
266 printf(
"CROs send : %d\n\r", state->statistics.crosSend);
268 printf(
"---------------------------------------------------------------------" 272 static void DisplayHelp(
void) {
273 printf(
"\n\rh\t\tshow this help message\n\r");
274 printf(
"<ESC> or q\texit\n\r");
275 printf(
"i\t\tsystem information\n\r");
276 printf(
"d\t\tDAQ configuration\n\r");
279 void FlsEmu_Info(
void) {
282 FlsEmu_SegmentType *segment;
284 printf(
"\n\rFlash-Emulator\n\r");
285 printf(
"--------------\n\r");
286 printf(
"Segment Mapped Virtual Size(KB) Pagesize(KB) " 288 for (idx = 0; idx < FlsEmu_GetConfig()->numSegments; ++idx) {
289 ptr = FlsEmu_BasePointer(idx);
290 segment = FlsEmu_GetConfig()->segments[idx];
291 printf(
"%-20.20s %p %p %8d %4d %6d\n\r", segment->name,
292 (
void *)segment->baseAddress, ptr, segment->memSize / 1024,
293 segment->pageSize / 1024, FlsEmu_NumPages(idx));
298 void Xcp_DisplayInfo(
void) {
299 XcpTl_PrintConnectionInformation();
300 printf(
"Press h for help.\n\r");
304 #if XCP_ENABLE_DAQ_COMMANDS == XCP_ON 305 void XcpDaq_PrintDAQDetails(
void) {
306 XcpDaq_ListIntegerType listIdx;
307 XcpDaq_ODTIntegerType odtIdx;
308 XcpDaq_ODTEntryIntegerType odtEntriyIdx;
309 XcpDaq_ListConfigurationType
const *listConf;
310 XcpDaq_ListStateType *listState;
311 XcpDaq_ODTType
const *odt;
312 XcpDaq_ODTEntryType
const *entry;
315 XcpDaq_ODTIntegerType firstPid;
317 printf(
"\n\rDAQ configuration\n\r");
318 printf(
"-----------------\n\r");
319 for (listIdx = (XcpDaq_ListIntegerType)0; listIdx < XcpDaq_GetListCount();
321 listState = XcpDaq_GetListState(listIdx);
322 listConf = XcpDaq_GetListConfiguration(listIdx);
323 mode = listState->mode;
325 XcpDaq_GetFirstPid(listIdx, &firstPid);
326 #if XCP_DAQ_CONFIG_TYPE == XCP_DAQ_CONFIG_TYPE_DYNAMIC 327 printf(
"DAQ-List #%d [%s] firstPid: %d mode: ", listIdx,
328 (listIdx < XCP_MIN_DAQ) ?
"predefined" :
"dynamic", firstPid);
329 #elif XCP_DAQ_CONFIG_TYPE == XCP_DAQ_CONFIG_TYPE_STATIC 330 printf(
"DAQ-List #%d [%s] firstPid: %d mode: ", listIdx,
331 (listIdx < XCP_MIN_DAQ) ?
"predefined" :
"static", firstPid);
332 #elif XCP_DAQ_CONFIG_TYPE == XCP_DAQ_CONFIG_TYPE_NONE 333 printf(
"DAQ-List #%d [predefined] firstPid: %d mode: ", listIdx, firstPid);
336 if (mode & XCP_DAQ_LIST_MODE_DIRECTION) {
341 if (mode & XCP_DAQ_LIST_MODE_SELECTED) {
344 if (mode & XCP_DAQ_LIST_MODE_STARTED) {
347 if (mode & XCP_DAQ_LIST_MODE_ALTERNATING) {
348 printf(
"ALTERNATING ");
350 if (mode & XCP_DAQ_LIST_MODE_PID_OFF) {
353 if (mode & XCP_DAQ_LIST_MODE_TIMESTAMP) {
354 printf(
"TIMESTAMP ");
357 for (odtIdx = (XcpDaq_ODTIntegerType)0; odtIdx < listConf->numOdts;
359 odt = XcpDaq_GetOdt(listIdx, odtIdx);
360 printf(
" ODT #%d\n\r", odtIdx);
361 for (odtEntriyIdx = (XcpDaq_ODTEntryIntegerType)0;
362 odtEntriyIdx < odt->numOdtEntries; ++odtEntriyIdx) {
363 entry = XcpDaq_GetOdtEntry(listIdx, odtIdx, odtEntriyIdx);
364 printf(
" Entry #%d [0x%08x] %d Byte(s)\n\r", odtEntriyIdx,
365 entry->mta.address, entry->length);
366 total += entry->length;
369 printf(
" -------------\n\r");
370 printf(
" %-5d Byte(s)\n\r", total);
372 printf(
"---------------------------------------------------------------------" 376 void XcpDaq_Info(
void) {
377 Xcp_StateType
const *Xcp_State;
379 Xcp_State = Xcp_GetState();
381 printf(
"DAQ\n\r---\n\r");
382 #if XCP_ENABLE_DAQ_COMMANDS == XCP_ON 383 printf(
"Processor state : ");
384 switch (Xcp_State->daqProcessor.state) {
385 case XCP_DAQ_STATE_UNINIT:
386 printf(
"Uninitialized");
388 case XCP_DAQ_STATE_CONFIG_INVALID:
389 printf(
"Configuration invalid");
391 case XCP_DAQ_STATE_CONFIG_VALID:
392 printf(
"Configuration valid");
394 case XCP_DAQ_STATE_STOPPED:
397 case XCP_DAQ_STATE_RUNNING:
402 #if XCP_DAQ_ENABLE_DYNAMIC_LISTS == XCP_ON 403 printf(
"Allocated DAQ entities: %d of %d\n\r",
404 XcpDaq_GetDynamicDaqEntityCount(), XCP_DAQ_MAX_DYNAMIC_ENTITIES);
408 printf(
"\tfunctionality not supported.\n\r");