PageRenderTime 34ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/src/plugins/mscommon/interrogate.c

https://gitlab.com/libreems-suite/megatunix
C | 1717 lines | 1466 code | 94 blank | 157 comment | 333 complexity | 5578e4c3df61416046e513eeb598e3c6 MD5 | raw file
Possible License(s): GPL-2.0
  1. /*
  2. * Copyright (C) 2002-2012 by Dave J. Andruczyk <djandruczyk at yahoo dot com>
  3. *
  4. * Linux Megasquirt tuning software
  5. *
  6. * Most of this file contributed by Perry Harrington
  7. * slight changes applied (naming, addition ofbspot 1-3 vars)
  8. *
  9. * This software comes under the GPL (GNU Public License)
  10. * You may freely copy,distribute etc. this as long as the source code
  11. * is made available for FREE.
  12. *
  13. * No warranty is made or implied. You use this program at your own risk.
  14. */
  15. /*!
  16. \file src/plugins/mscommon/interrogate.c
  17. \ingroup MSCommonPlugin,Plugins
  18. \brief MS Specific device interrogation/detection routines
  19. \author David Andruczyk
  20. */
  21. #include <api-versions.h>
  22. #include <dep_loader.h>
  23. #include <getfiles.h>
  24. #include <interrogate.h>
  25. #include <libgen.h>
  26. #include <mscommon_comms.h>
  27. #include <mscommon_plugin.h>
  28. #include <multi_expr_loader.h>
  29. #include <serialio.h>
  30. #include <stdlib.h>
  31. #include <stdio.h>
  32. #include <string.h>
  33. extern GtkWidget *interr_view;
  34. extern gconstpointer *global_data;
  35. #define BUFSIZE 4096
  36. /*!
  37. \brief Iinterrogates the target ECU to determine what
  38. firmware it is running. It does this by reading a list of tests, sending
  39. those tests in turn, reading the responses and them comparing the group of
  40. responses against a list of interrogation profiles until it finds a match.
  41. \returns TRUE on a success, FALSE otherwise
  42. */
  43. G_MODULE_EXPORT gboolean interrogate_ecu(void)
  44. {
  45. static GMutex mutex;
  46. gboolean interrogated = FALSE;
  47. GArray *tests = NULL;
  48. GHashTable *tests_hash = NULL;
  49. Detection_Test *test = NULL;
  50. guchar uint8 = 0;
  51. gchar sint8 = 0;
  52. guint16 uint16 = 0;
  53. gint16 sint16 = 0;
  54. gboolean res = 0;
  55. gint count = 0;
  56. gint i = 0;
  57. gint j = 0;
  58. gint len = 0;
  59. gint tests_to_run = 0;
  60. gint total_read = 0;
  61. gint total_wanted = 0;
  62. gint zerocount = 0;
  63. gint adder = 0;
  64. gint base_offset = 0;
  65. unsigned long crc32 = 0;
  66. gint crc_pass = 0;
  67. gint crc_fail = 0;
  68. gchar *string = NULL;
  69. guchar buf[BUFSIZE];
  70. guchar *ptr = NULL;
  71. gchar * message = NULL;
  72. Serial_Params *serial_params = NULL;
  73. ENTER();
  74. serial_params = (Serial_Params *)DATA_GET(global_data,"serial_params");
  75. if (DATA_GET(global_data,"offline"))
  76. {
  77. EXIT();
  78. return FALSE;
  79. }
  80. /* prevent multiple runs of interrogator simultaneously */
  81. g_mutex_lock(&mutex);
  82. MTXDBG(INTERROGATOR,_("Entered\n"));
  83. if (!DATA_GET(global_data,"connected"))
  84. {
  85. MTXDBG(INTERROGATOR,_("NOT connected to ECU!!!!\n"));
  86. g_mutex_unlock(&mutex);
  87. EXIT();
  88. return FALSE;
  89. }
  90. thread_update_widget_f("titlebar",MTX_TITLE,g_strdup(_("Interrogating ECU...")));
  91. /* Load tests from config files */
  92. tests = validate_and_load_tests(&tests_hash);
  93. if ((!tests) || (tests->len < 1))
  94. {
  95. MTXDBG(INTERROGATOR|CRITICAL,_("validate_and_load_tests() didn't return a valid list of commands\n\t MegaTunix was NOT installed correctly, Aborting Interrogation\n"));
  96. update_logbar_f("interr_view",NULL,g_strdup(__FILE__": interrogate_ecu()\n\t validate_and_load_tests() didn't return a valid list of commands\n\t MegaTunix was NOT installed correctly, Aborting Interrogation\n"),FALSE,FALSE,TRUE);
  97. g_mutex_unlock(&mutex);
  98. EXIT();
  99. return FALSE;
  100. }
  101. thread_widget_set_sensitive_f("offline_button",FALSE);
  102. thread_widget_set_sensitive_f("interrogate_button",FALSE);
  103. /* how many tests.... */
  104. tests_to_run = tests->len;
  105. for (i=0;i<tests_to_run;i++)
  106. {
  107. flush_serial_f(serial_params->fd,BOTH);
  108. count = 0;
  109. test = g_array_index(tests,Detection_Test *, i);
  110. /* flush buffer to known state.. */
  111. memset (buf,0,BUFSIZE);
  112. ptr = buf;
  113. string = g_strdup(test->actual_test);
  114. res = write_wrapper_f(serial_params->fd,test->send_buf,test->send_len,&len);
  115. if (!res)
  116. MTXDBG(INTERROGATOR|CRITICAL,_("Interrogation error: Unable to send data: \"%s\"n"),(gchar *)g_strndup((const gchar *)test->send_buf,test->send_len));
  117. MTXDBG(INTERROGATOR,_("Sent command \"%s\"\n"),string);
  118. g_free(string);
  119. total_read = 0;
  120. total_wanted = BUFSIZE;
  121. zerocount = 0;
  122. while ((total_read < total_wanted ) && (total_wanted-total_read) > 0 )
  123. {
  124. MTXDBG(INTERROGATOR,_("Interrogation for command %s requesting %i bytes\n"),test->test_name,total_wanted-total_read);
  125. res = read_wrapper_f(serial_params->fd,
  126. ptr+total_read,
  127. total_wanted-total_read,&len);
  128. total_read += len;
  129. MTXDBG(INTERROGATOR,_("Interrogation for command %s read %i bytes, running total %i\n"),test->test_name,len,total_read);
  130. /* If we get nothing back (i.e. timeout, inc counter)*/
  131. if ((!res) || (len == 0))
  132. zerocount++;
  133. if (zerocount > 1)
  134. break;
  135. }
  136. MTXDBG(INTERROGATOR,_("Received %i bytes\n"),total_read);
  137. ptr = buf;
  138. test->recv_len = total_read;
  139. /* copy data from tmp buffer to struct pointer */
  140. if (test->ms3_crc32)
  141. {
  142. adder = 7;
  143. base_offset = 3;
  144. len = buf[0]*256 + buf[1];
  145. if ((len == 0 ) || (len > 2054))
  146. printf("packet length INVALID\n");
  147. if ((len + 6) != test->recv_len)
  148. printf("data length received DOES NOT MATCH packet length header\n");
  149. crc32 = crc32_computebuf(0,&buf[2],len);
  150. if ( (((crc32 >> 24) & 0xff) != buf[2 + len])
  151. || (((crc32 >> 16) & 0xff) != buf[3 + len])
  152. || (((crc32 >> 8) & 0xff) != buf[4 + len])
  153. || ((crc32 & 0xff) != buf[5 + len])) {
  154. printf("CRC32 validation FAILED\n");
  155. crc_fail++;
  156. }
  157. else
  158. {
  159. printf("CRC32 validation SUCCEEDED\n");
  160. crc_pass++;
  161. }
  162. if (buf[2] & 0x80)
  163. printf("Packet contains error code 0x%x\n",buf[2] & 0xff);
  164. else
  165. printf("Packet contains status code 0x%x\n",buf[2] & 0xff);
  166. }
  167. if (total_read <= (0 + adder))
  168. test->result_str = g_strdup("");
  169. else
  170. test->result_str = g_strndup((gchar *)ptr+base_offset, total_read-adder);
  171. if (total_read > (0 + adder))
  172. {
  173. if (test->result_type == RESULT_TEXT)
  174. update_logbar_f("interr_view",NULL,g_strdup_printf(_("Command \"%s\" (%s), returned %i bytes \"%s\"\n"),test->actual_test, test->test_desc,total_read,test->result_str),FALSE,FALSE,TRUE);
  175. else if (test->result_type == RESULT_DATA)
  176. update_logbar_f("interr_view",NULL,g_strdup_printf(_("Command \"%s\" (%s), returned %i bytes\n"),test->actual_test, test->test_desc,total_read),FALSE,FALSE,TRUE);
  177. ptr = buf;
  178. MTXDBG(SERIAL_RD|INTERROGATOR,_("Read the following from the %s command\n"),test->test_name);
  179. message = g_strndup(((gchar *)buf),total_read);
  180. MTXDBG(SERIAL_RD|INTERROGATOR,_("Dumping Output string: \"%s\"\n"),message);
  181. g_free(message);
  182. QUIET_MTXDBG(SERIAL_RD|INTERROGATOR,_("Data is in HEX!!\n"));
  183. for (j=0;j<total_read;j++)
  184. {
  185. QUIET_MTXDBG(SERIAL_RD|INTERROGATOR,"%.2x ", ptr[j]);
  186. if (!((j+1)%8)) /* every 8 bytes give a CR */
  187. QUIET_MTXDBG(SERIAL_RD|INTERROGATOR,"\n");
  188. }
  189. QUIET_MTXDBG(SERIAL_RD|INTERROGATOR,"\n\n");
  190. }
  191. }
  192. interrogated = determine_ecu(tests,tests_hash);
  193. DATA_SET(global_data,"interrogated",GINT_TO_POINTER(interrogated));
  194. if (interrogated)
  195. {
  196. thread_widget_set_sensitive_f("interrogate_button",FALSE);
  197. thread_widget_set_sensitive_f("offline_button",FALSE);
  198. }
  199. free_tests_array(tests);
  200. g_hash_table_destroy(tests_hash);
  201. if (!interrogated)
  202. {
  203. thread_widget_set_sensitive_f("interrogate_button",TRUE);
  204. thread_widget_set_sensitive_f("offline_button",TRUE);
  205. }
  206. g_mutex_unlock(&mutex);
  207. MTXDBG(INTERROGATOR,_("Leaving\n"));
  208. thread_update_widget_f("titlebar",MTX_TITLE,g_strdup("Interrogation Complete..."));
  209. EXIT();
  210. return interrogated;
  211. }
  212. /*!
  213. \brief Tries to match to determine the target firmware by
  214. loading the interrogation profiles in turn and comparing the data from our
  215. test ECU and a profile until a match is found,
  216. \param tests is a pointer to the Array of tests
  217. \param tests_hash is a pointer to the hashtable of tests
  218. \returns TRUE on successfull match, FALSE on no match
  219. */
  220. G_MODULE_EXPORT gboolean determine_ecu(GArray *tests,GHashTable *tests_hash)
  221. {
  222. gboolean retval = TRUE;
  223. gint i = 0;
  224. Detection_Test *test = NULL;
  225. gint num_tests = tests->len;
  226. gboolean match = FALSE;
  227. gchar * filename = NULL;
  228. gchar ** filenames = NULL;
  229. GArray *classes = NULL;
  230. Firmware_Details *firmware = NULL;
  231. gchar *pathstub = NULL;
  232. ENTER();
  233. pathstub = g_build_filename(INTERROGATOR_DATA_DIR,"Profiles",DATA_GET(global_data,"ecu_family"),NULL);
  234. filenames = get_files((const gchar *)DATA_GET(global_data,"project_name"),pathstub,"prof",&classes);
  235. g_free(pathstub);
  236. if (!filenames)
  237. {
  238. MTXDBG(INTERROGATOR|CRITICAL,_("NO Interrogation profiles found, was MegaTunix installed properly?\n"));
  239. EXIT();
  240. return FALSE;
  241. }
  242. i = 0;
  243. while (filenames[i])
  244. {
  245. if (check_for_match(tests_hash,filenames[i]))
  246. {
  247. match = TRUE;
  248. filename = g_strdup(filenames[i]);
  249. break;
  250. }
  251. i++;
  252. }
  253. g_strfreev(filenames);
  254. g_array_free(classes,TRUE);
  255. /* Update the screen with the data... */
  256. for (i=0;i<num_tests;i++)
  257. {
  258. test = g_array_index(tests,Detection_Test *,i);
  259. if (test->result_type == RESULT_TEXT)
  260. MTXDBG(INTERROGATOR,_("Command \"%s\" (%s), returned %i bytes \"%s\"\n"),
  261. test->actual_test,
  262. test->test_desc,
  263. test->recv_len,
  264. test->result_str);
  265. else if (test->result_type == RESULT_DATA)
  266. MTXDBG(INTERROGATOR,_("Command \"%s\" (%s), returned %i bytes\n"),
  267. test->actual_test,
  268. test->test_desc,
  269. test->recv_len);
  270. }
  271. if (match == FALSE) /* (we DID NOT find one) */
  272. {
  273. MTXDBG(INTERROGATOR,_("Firmware NOT DETECTED, Enable Interrogation debugging, retry interrogation,\nclose megatunix, and send ~/mtx/%s/debug.log to the author for analysis with a note\ndescribing which firmware you are attempting to talk to.\n"),(gchar *)DATA_GET(global_data,"project_name"));
  274. update_logbar_f("interr_view","warning",g_strdup_printf("Firmware NOT DETECTED, Enable Interrogation debugging, retry interrogation,\nclose megatunix, and send ~/mtx/%s/debug.log to the author for analysis with a note\ndescribing which firmware you are attempting to talk to.\n",(gchar *)DATA_GET(global_data,"project_name")),FALSE,FALSE,TRUE);
  275. retval = FALSE;
  276. }
  277. else
  278. {
  279. if (!firmware)
  280. {
  281. firmware = g_new0(Firmware_Details,1);
  282. DATA_SET(global_data,"firmware",firmware);
  283. }
  284. if (!load_firmware_details(firmware,filename))
  285. retval = FALSE;
  286. }
  287. g_free(filename);
  288. EXIT();
  289. return(retval);
  290. }
  291. /*!
  292. \brief loads up all firmware details allocating the required resrouces
  293. \param firmware is the pointer to the firmware datastructure
  294. \param filename is the pointer to the filename to parse
  295. \returns TRUE on success, FALSE otherwise
  296. */
  297. G_MODULE_EXPORT gboolean load_firmware_details(Firmware_Details *firmware, const gchar * filename)
  298. {
  299. ConfigFile *cfgfile;
  300. gchar * tmpbuf = NULL;
  301. gchar * section = NULL;
  302. gchar ** list = NULL;
  303. gint i = 0;
  304. MultiSource * multi = NULL;
  305. gchar **sources = NULL;
  306. gchar **suffixes = NULL;
  307. gchar **fromecu_mults = NULL;
  308. gchar **fromecu_adds = NULL;
  309. gchar **precisions = NULL;
  310. gchar **expr_keys = NULL;
  311. gchar **tables = NULL;
  312. gfloat tmpf = 0.0;
  313. gint major = 0;
  314. gint minor = 0;
  315. gint len1 = 0;
  316. gint len2 = 0;
  317. gint len3 = 0;
  318. gint len4 = 0;
  319. gint len5 = 0;
  320. gint len6 = 0;
  321. gint j = 0;
  322. ENTER();
  323. g_return_val_if_fail(firmware,FALSE);
  324. g_return_val_if_fail(filename,FALSE);
  325. cfgfile = cfg_open_file((gchar *)filename);
  326. if (!cfgfile)
  327. {
  328. MTXDBG(INTERROGATOR|CRITICAL,_("File \"%s\" NOT OPENED successfully\n"),filename);
  329. EXIT();
  330. return FALSE;
  331. }
  332. get_file_api_f(cfgfile,&major,&minor);
  333. if ((major != INTERROGATE_MAJOR_API) || (minor != INTERROGATE_MINOR_API))
  334. {
  335. thread_update_logbar_f("interr_view","warning",g_strdup_printf(_("Interrogation profile API mismatch (%i.%i != %i.%i):\n\tFile %s will be skipped\n"),major,minor,INTERROGATE_MAJOR_API,INTERROGATE_MINOR_API,filename),FALSE,FALSE);
  336. cfg_free(cfgfile);
  337. EXIT();
  338. return FALSE;
  339. }
  340. firmware->profile_filename = g_strdup(filename);
  341. cfg_read_string(cfgfile,"interrogation_profile","name",&firmware->name);
  342. cfg_read_string(cfgfile,"parameters","TextVerVia",&firmware->TextVerVia);
  343. cfg_read_string(cfgfile,"parameters","NumVerVia",&firmware->NumVerVia);
  344. cfg_read_string(cfgfile,"parameters","SignatureVia",&firmware->SignatureVia);
  345. if(cfg_read_string(cfgfile,"parameters","EcuTempUnits",&tmpbuf))
  346. {
  347. firmware->ecu_temp_units = (TempUnits)translate_string_f(tmpbuf);
  348. g_free(tmpbuf);
  349. }
  350. else
  351. MTXDBG(INTERROGATOR,_("Failed to find EcuTempUnits key in interrogation profile\n"));
  352. MTXDBG(INTERROGATOR,_("File:%s opened successfully\n"),filename);
  353. if(!cfg_read_boolean(cfgfile,"parameters","BigEndian",&firmware->bigendian))
  354. {
  355. MTXDBG(INTERROGATOR|CRITICAL,_("\"BigEndian\" key not found in interrogation profile, assuming ECU firmware byte order is big endian, ERROR in interrogation profile\n"));
  356. firmware->bigendian = TRUE;
  357. }
  358. if(!cfg_read_string(cfgfile,"parameters","Capabilities",
  359. &tmpbuf))
  360. MTXDBG(INTERROGATOR|CRITICAL,_("\"Capabilities\" enumeration list not found in interrogation profile, ERROR\n"));
  361. else
  362. {
  363. /*printf("Capabilities %s\n",tmpbuf);*/
  364. firmware->capabilities = translate_capabilities(tmpbuf);
  365. g_free(tmpbuf);
  366. /*
  367. printf("CAP #'s MS1 %i MS1_STD %i MS1_E %i MS1_DT %i MS2 %i MS2_STD %i, MS2_E %i, MS2_E_COMPMON %i, PIS %i, JIMSTIM %i\n",MS1,MS1_STD,MS1_E,MS1_DT,MS2,MS2_STD,MS2_E,MS2_E_COMPMON,PIS,JIMSTIM);
  368. if (firmware->capabilities & MS1)
  369. printf("MS1\n");
  370. if (firmware->capabilities & MS1_STD)
  371. printf("MS1_STD\n");
  372. if (firmware->capabilities & MS1_E)
  373. printf("MS1_E\n");
  374. if (firmware->capabilities & MS1_DT)
  375. printf("MS1_DT\n");
  376. if (firmware->capabilities & MS2)
  377. printf("MS2\n");
  378. if (firmware->capabilities & MS2_STD)
  379. printf("MS2_STD\n");
  380. if (firmware->capabilities & MS2_E)
  381. printf("MS2_E\n");
  382. if (firmware->capabilities & MS2_E_COMPMON)
  383. printf("MS2_E_COMPMON\n");
  384. if (firmware->capabilities & PIS)
  385. printf("PIS\n");
  386. if (firmware->capabilities & JIMSTIM)
  387. printf("JIMSTIM\n");
  388. */
  389. }
  390. if(!cfg_read_string(cfgfile,"parameters","RT_Command",
  391. &firmware->rt_command))
  392. MTXDBG(INTERROGATOR|CRITICAL,_("\"RT_Command\" variable not found in interrogation profile, ERROR\n"));
  393. if (firmware->capabilities & PIS)
  394. {
  395. if(!cfg_read_int(cfgfile,"parameters","CLT_Table_Page",
  396. &firmware->clt_table_page))
  397. MTXDBG(INTERROGATOR|CRITICAL,_("\"CLT_Table_Page\" variable not found in interrogation profile, ERROR\n"));
  398. if(!cfg_read_int(cfgfile,"parameters","MAT_Table_Page",
  399. &firmware->mat_table_page))
  400. MTXDBG(INTERROGATOR|CRITICAL,_("\"MAT_Table_Page\" variable not found in interrogation profile, ERROR\n"));
  401. }
  402. if (firmware->capabilities & MS2)
  403. {
  404. if(!cfg_read_int(cfgfile,"parameters","MS2_RT_Page",
  405. &firmware->ms2_rt_page))
  406. MTXDBG(INTERROGATOR|CRITICAL,_("\"MS2_RT_Page\" variable not found in interrogation profile, ERROR\n"));
  407. if(!cfg_read_int(cfgfile,"parameters","InterCharDelay",
  408. &firmware->interchardelay))
  409. MTXDBG(INTERROGATOR|CRITICAL,_("\"InterCharDelay\" variable not found in interrogation profile, ERROR\n"));
  410. if(!cfg_read_int(cfgfile,"parameters","CLT_Table_Page",
  411. &firmware->clt_table_page))
  412. MTXDBG(INTERROGATOR|CRITICAL,_("\"CLT_Table_Page\" variable not found in interrogation profile, ERROR\n"));
  413. if(!cfg_read_int(cfgfile,"parameters","MAT_Table_Page",
  414. &firmware->mat_table_page))
  415. MTXDBG(INTERROGATOR|CRITICAL,_("\"MAT_Table_Page\" variable not found in interrogation profile, ERROR\n"));
  416. if(!cfg_read_int(cfgfile,"parameters","EGO_Table_Page",
  417. &firmware->ego_table_page))
  418. MTXDBG(INTERROGATOR|CRITICAL,_("\"EGO_Table_Page\" variable not found in interrogation profile, ERROR\n"));
  419. if(!cfg_read_int(cfgfile,"parameters","MAF_Table_Page",
  420. &firmware->maf_table_page))
  421. MTXDBG(INTERROGATOR|CRITICAL,_("\"MAF_Table_Page\" variable not found in interrogation profile, ERROR\n"));
  422. }
  423. if(!cfg_read_int(cfgfile,"parameters","RT_total_bytes",
  424. &firmware->rtvars_size))
  425. MTXDBG(INTERROGATOR|CRITICAL,_("\"RT_total_bytes\" variable not found in interrogation profile, ERROR\n"));
  426. if(!cfg_read_string(cfgfile,"parameters","Get_All_Command",
  427. &firmware->get_all_command))
  428. MTXDBG(INTERROGATOR|CRITICAL,_("\"Get_All_Command\" variable not found in interrogation profile, ERROR\n"));
  429. if(!cfg_read_string(cfgfile,"parameters","Read_Command",
  430. &firmware->read_command))
  431. MTXDBG(INTERROGATOR|CRITICAL,_("\"Read_Command\" variable not found in interrogation profile, ERROR\n"));
  432. if(!cfg_read_string(cfgfile,"parameters","Write_Command",
  433. &firmware->write_command))
  434. MTXDBG(INTERROGATOR|CRITICAL,_("\"Write_Command\" variable not found in interrogation profile, ERROR\n"));
  435. if(!cfg_read_string(cfgfile,"parameters","Burn_Command",
  436. &firmware->burn_command))
  437. MTXDBG(INTERROGATOR|CRITICAL,_("\"Burn_Command\" variable not found in interrogation profile, ERROR\n"));
  438. if(!cfg_read_string(cfgfile,"parameters","Burn_All_Command",
  439. &firmware->burn_all_command))
  440. MTXDBG(INTERROGATOR|CRITICAL,_("\"Burn_All_Command\" variable not found in interrogation profile, ERROR\n"));
  441. if(!cfg_read_boolean(cfgfile,"parameters","MultiPage",
  442. &firmware->multi_page))
  443. MTXDBG(INTERROGATOR|CRITICAL,_("\"MultiPage\" flag not found in parameters section in interrogation profile, ERROR\n"));
  444. if ((firmware->multi_page) && (!(firmware->capabilities & MS2)))
  445. {
  446. if(!cfg_read_string(cfgfile,"parameters","Page_Command",
  447. &firmware->page_command))
  448. MTXDBG(INTERROGATOR|CRITICAL,_("\"Page_Command\" flag not found in parameters section in interrogation profile, ERROR\n"));
  449. }
  450. if(!cfg_read_boolean(cfgfile,"parameters","ChunkWriteSupport",
  451. &firmware->chunk_support))
  452. MTXDBG(INTERROGATOR|CRITICAL,_("\"ChunkWriteSupport\" flag not found in parameters section in interrogation profile, ERROR\n"));
  453. if (firmware->chunk_support)
  454. {
  455. if(!cfg_read_string(cfgfile,"parameters","Chunk_Write_Command",
  456. &firmware->chunk_write_command))
  457. MTXDBG(INTERROGATOR|CRITICAL,_("\"Chunk_Write_Command\" flag not found in parameters section in interrogation profile, ERROR\n"));
  458. }
  459. if (firmware->capabilities & MS2)
  460. {
  461. if(!cfg_read_string(cfgfile,"parameters","Table_Write_Command",
  462. &firmware->table_write_command))
  463. MTXDBG(INTERROGATOR|CRITICAL,_("\"Table_Write_Command\" flag not found in parameters section in interrogation profile, ERROR\n"));
  464. }
  465. if(!cfg_read_int(cfgfile,"parameters","TotalPages",
  466. &firmware->total_pages))
  467. MTXDBG(INTERROGATOR|CRITICAL,_("\"TotalPages\" value not found in interrogation profile, ERROR\n"));
  468. cfg_read_int(cfgfile,"parameters","ReadOnlyAbove",&firmware->ro_above);
  469. if(!cfg_read_int(cfgfile,"parameters","TotalTables",
  470. &firmware->total_tables))
  471. MTXDBG(INTERROGATOR|CRITICAL,_("\"TotalTables\" value not found in interrogation profile, ERROR\n"));
  472. cfg_read_int(cfgfile,"parameters","TotalTETables",
  473. &firmware->total_te_tables);
  474. if ((firmware->capabilities & MS2_E) || (firmware->capabilities & MS1_E))
  475. {
  476. if(!cfg_read_int(cfgfile,"parameters","TrigmonPage",&firmware->trigmon_page))
  477. MTXDBG(INTERROGATOR|CRITICAL,_("\"TrigmonPage\" value not found in interrogation profile, ERROR\n"));
  478. if(!cfg_read_int(cfgfile,"parameters","ToothmonPage",&firmware->toothmon_page))
  479. MTXDBG(INTERROGATOR|CRITICAL,_("\"ToothmonPage\" value not found in interrogation profile, ERROR\n"));
  480. if (firmware->capabilities & MS2_E_COMPMON)
  481. {
  482. if(!cfg_read_int(cfgfile,"parameters","CompositemonPage",&firmware->compositemon_page))
  483. MTXDBG(INTERROGATOR|CRITICAL,_("\"CompositemonPage\" value not found in interrogation profile, ERROR\n"));
  484. }
  485. }
  486. if(!cfg_read_string(cfgfile,"gui","LoadTabs",
  487. &tmpbuf))
  488. MTXDBG(INTERROGATOR|CRITICAL,_("\"LoadTabs\" list not found in interrogation profile, ERROR\n"));
  489. else
  490. {
  491. firmware->tab_list = g_strsplit(tmpbuf,",",0);
  492. g_free(tmpbuf);
  493. }
  494. if(!cfg_read_string(cfgfile,"gui","TabConfs",
  495. &tmpbuf))
  496. MTXDBG(INTERROGATOR|CRITICAL,_("\"TabConfs\" list not found in interrogation profile, ERROR\n"));
  497. else
  498. {
  499. firmware->tab_confs = g_strsplit(tmpbuf,",",0);
  500. g_free(tmpbuf);
  501. }
  502. if(!cfg_read_string(cfgfile,"gui","RealtimeMapFile",
  503. &firmware->rtv_map_file))
  504. MTXDBG(INTERROGATOR|CRITICAL,_("\"RealtimeMapFile\" variable not found in interrogation profile, ERROR\n"));
  505. if(!cfg_read_string(cfgfile,"gui","SliderMapFile",
  506. &firmware->sliders_map_file))
  507. MTXDBG(INTERROGATOR|CRITICAL,_("\"SliderMapFile\" variable not found in interrogation profile, ERROR\n"));
  508. cfg_read_string(cfgfile,"gui","RuntimeTextMapFile",
  509. &firmware->rtt_map_file);
  510. /* MTXDBG(INTERROGATOR|CRITICAL,_("\"RuntimeTextMapFile\" variable not found in interrogation profile, ERROR\n"));*/
  511. cfg_read_string(cfgfile,"gui","StatusMapFile",
  512. &firmware->status_map_file);
  513. /* MTXDBG(INTERROGATOR|CRITICAL,_("\"StatusMapFile\" variable not found in interrogation profile, ERROR\n"));*/
  514. if (!cfg_read_string(cfgfile,"lookuptables","tables",
  515. &tmpbuf))
  516. MTXDBG(INTERROGATOR|CRITICAL,_("\"tables\" lookuptable name not found in interrogation profile, ERROR\n"));
  517. else
  518. {
  519. list = g_strsplit(tmpbuf,",",0);
  520. g_free(tmpbuf);
  521. i = 0;
  522. while (list[i] != NULL)
  523. {
  524. if (!cfg_read_string(cfgfile,"lookuptables",list[i],&tmpbuf))
  525. MTXDBG(INTERROGATOR|CRITICAL,_("\"%s\" key name not found in \"[lookuptables]\"\n\t section of interrogation profile, ERROR\n"),list[i]);
  526. else
  527. {
  528. MTXDBG(INTERROGATOR,_("\"[lookuptables]\"\n\t section loading table %s, file %s\n"),list[i],tmpbuf);
  529. get_table_f(list[i],tmpbuf,NULL);
  530. g_free(tmpbuf);
  531. }
  532. i++;
  533. }
  534. g_strfreev(list);
  535. }
  536. /* Allocate space for Page Params structures.... */
  537. firmware->page_params = g_new0(Page_Params *,firmware->total_pages);
  538. for (i=0;i<firmware->total_pages;i++)
  539. {
  540. firmware->page_params[i] = initialize_page_params();
  541. section = g_strdup_printf("page_%i",i);
  542. if (firmware->multi_page)
  543. if(!cfg_read_int(cfgfile,section,"phys_ecu_page",&firmware->page_params[i]->phys_ecu_page))
  544. MTXDBG(INTERROGATOR|CRITICAL,_("\"phys_ecu_page\" flag not found in \"%s\" section in interrogation profile, ERROR\n"),section);
  545. if(!cfg_read_boolean(cfgfile,section,"dl_by_default",&firmware->page_params[i]->dl_by_default))
  546. {
  547. MTXDBG(INTERROGATOR|CRITICAL,_("\"dl_by_default\" flag not found in \"%s\" section in interrogation profile, assuming TRUE\n"),section);
  548. firmware->page_params[i]->dl_by_default = TRUE;
  549. }
  550. if(!cfg_read_int(cfgfile,section,"length",&firmware->page_params[i]->length))
  551. MTXDBG(INTERROGATOR|CRITICAL,_("\"length\" flag not found in \"%s\" section in interrogation profile, ERROR\n"),section);
  552. g_free(section);
  553. }
  554. /* Allocate space for Table Offsets structures.... */
  555. firmware->table_params = g_new0(Table_Params *,firmware->total_tables);
  556. for (i=0;i<firmware->total_tables;i++)
  557. {
  558. firmware->table_params[i] = initialize_table_params();
  559. section = g_strdup_printf("table_%i",i);
  560. cfg_read_string(cfgfile,section,"bind_to_list",&firmware->table_params[i]->bind_to_list);
  561. if(cfg_read_string(cfgfile,section,"match_type",&tmpbuf))
  562. {
  563. firmware->table_params[i]->match_type = (MatchType)translate_string_f(tmpbuf);
  564. g_free(tmpbuf);
  565. }
  566. cfg_read_boolean(cfgfile,section,"is_spark",&firmware->table_params[i]->is_spark);
  567. cfg_read_boolean(cfgfile,section,"is_fuel",&firmware->table_params[i]->is_fuel);
  568. if ((firmware->table_params[i]->is_fuel) && !(firmware->capabilities & PIS))
  569. {
  570. if(!cfg_read_int(cfgfile,section,"divider_page",&firmware->table_params[i]->divider_page))
  571. MTXDBG(INTERROGATOR|CRITICAL,_("\"divider_page\" flag not found in \"%s\" section in interrogation profile, ERROR\n"),section);
  572. if(!cfg_read_int(cfgfile,section,"divider_offset",&firmware->table_params[i]->divider_offset))
  573. MTXDBG(INTERROGATOR|CRITICAL,_("\"divider_offset\" flag not found in \"%s\" section in interrogation profile, ERROR\n"),section);
  574. if(!cfg_read_int(cfgfile,section,"reqfuel_page",&firmware->table_params[i]->reqfuel_page))
  575. MTXDBG(INTERROGATOR|CRITICAL,_("\"reqfuel_page\" flag not found in \"%s\" section in interrogation profile, ERROR\n"),section);
  576. if(!cfg_read_int(cfgfile,section,"reqfuel_offset",&firmware->table_params[i]->reqfuel_offset))
  577. MTXDBG(INTERROGATOR|CRITICAL,_("\"reqfuel_offset\" flag not found in \"%s\" section in interrogation profile, ERROR\n"),section);
  578. if(!cfg_read_string(cfgfile,section,"reqfuel_size",&tmpbuf))
  579. firmware->table_params[i]->reqfuel_size = MTX_U08;
  580. else
  581. {
  582. firmware->table_params[i]->reqfuel_size = (DataSize)translate_string_f(tmpbuf);
  583. g_free(tmpbuf);
  584. }
  585. if(!cfg_read_int(cfgfile,section,"stroke_page",&firmware->table_params[i]->stroke_page))
  586. MTXDBG(INTERROGATOR|CRITICAL,_("\"stroke_page\" flag not found in \"%s\" section in interrogation profile, ERROR\n"),section);
  587. if(!cfg_read_int(cfgfile,section,"stroke_offset",&firmware->table_params[i]->stroke_offset))
  588. MTXDBG(INTERROGATOR|CRITICAL,_("\"stroke_offset\" flag not found in \"%s\" section in interrogation profile, ERROR\n"),section);
  589. if(!cfg_read_int(cfgfile,section,"stroke_mask",&firmware->table_params[i]->stroke_mask))
  590. MTXDBG(INTERROGATOR|CRITICAL,_("\"stroke_mask\" flag not found in \"%s\" section in interrogation profile, ERROR\n"),section);
  591. if(!cfg_read_int(cfgfile,section,"num_cyl_page",&firmware->table_params[i]->num_cyl_page))
  592. MTXDBG(INTERROGATOR|CRITICAL,_("\"num_cyl_page\" flag not found in \"%s\" section in interrogation profile, ERROR\n"),section);
  593. if(!cfg_read_int(cfgfile,section,"num_cyl_offset",&firmware->table_params[i]->num_cyl_offset))
  594. MTXDBG(INTERROGATOR|CRITICAL,_("\"num_cyl_offset\" flag not found in \"%s\" section in interrogation profile, ERROR\n"),section);
  595. if(!cfg_read_int(cfgfile,section,"num_cyl_mask",&firmware->table_params[i]->num_cyl_mask))
  596. MTXDBG(INTERROGATOR|CRITICAL,_("\"num_cyl_mask\" flag not found in \"%s\" section in interrogation profile, ERROR\n"),section);
  597. if(!cfg_read_int(cfgfile,section,"num_inj_page",&firmware->table_params[i]->num_inj_page))
  598. MTXDBG(INTERROGATOR|CRITICAL,_("\"num_inj_page\" flag not found in \"%s\" section in interrogation profile, ERROR\n"),section);
  599. if(!cfg_read_int(cfgfile,section,"num_inj_offset",&firmware->table_params[i]->num_inj_offset))
  600. MTXDBG(INTERROGATOR|CRITICAL,_("\"num_inj_offset\" flag not found in \"%s\" section in interrogation profile, ERROR\n"),section);
  601. if(!cfg_read_int(cfgfile,section,"num_inj_mask",&firmware->table_params[i]->num_inj_mask))
  602. MTXDBG(INTERROGATOR|CRITICAL,_("\"num_inj_mask\" flag not found in \"%s\" section in interrogation profile, ERROR\n"),section);
  603. if (!(firmware->capabilities & MS2))
  604. {
  605. if(!cfg_read_int(cfgfile,section,"rpmk_page",&firmware->table_params[i]->rpmk_page))
  606. MTXDBG(INTERROGATOR|CRITICAL,_("\"rpmk_page\" flag not found in \"%s\" section in interrogation profile, ERROR\n"),section);
  607. if(!cfg_read_int(cfgfile,section,"rpmk_offset",&firmware->table_params[i]->rpmk_offset))
  608. MTXDBG(INTERROGATOR|CRITICAL,_("\"rpmk_offset\" flag not found in \"%s\" section in interrogation profile, ERROR\n"),section);
  609. }
  610. if (!(firmware->capabilities & MS1_DT))
  611. {
  612. if(!cfg_read_int(cfgfile,section,"alternate_page",&firmware->table_params[i]->alternate_page))
  613. MTXDBG(INTERROGATOR|CRITICAL,_("\"alternate_page\" flag not found in \"%s\" section in interrogation profile, ERROR\n"),section);
  614. if(!cfg_read_int(cfgfile,section,"alternate_offset",&firmware->table_params[i]->alternate_offset))
  615. MTXDBG(INTERROGATOR|CRITICAL,_("\"alternate_offset\" flag not found in \"%s\" section in interrogation profile, ERROR\n"),section);
  616. }
  617. if (firmware->capabilities & MS1_E)
  618. {
  619. if(!cfg_read_int(cfgfile,section,"dtmode_offset",&firmware->table_params[i]->dtmode_offset))
  620. MTXDBG(INTERROGATOR|CRITICAL,_("\"dtmode_offset\" flag not found in \"%s\" section in interrogation profile, ERROR\n"),section);
  621. if(!cfg_read_int(cfgfile,section,"dtmode_page",&firmware->table_params[i]->dtmode_page))
  622. MTXDBG(INTERROGATOR|CRITICAL,_("\"dtmode_page\" flag not found in \"%s\" section in interrogation profile, ERROR\n"),section);
  623. if(!cfg_read_int(cfgfile,section,"dtmode_mask",&firmware->table_params[i]->dtmode_mask))
  624. MTXDBG(INTERROGATOR|CRITICAL,_("\"dtmode_mask\" flag not found in \"%s\" section in interrogation profile, ERROR\n"),section);
  625. }
  626. }
  627. if(!cfg_read_int(cfgfile,section,"x_page",&firmware->table_params[i]->x_page))
  628. MTXDBG(INTERROGATOR|CRITICAL,_("\"x_page\" flag not found in \"%s\" section in interrogation profile, ERROR\n"),section);
  629. if(!cfg_read_int(cfgfile,section,"y_page",&firmware->table_params[i]->y_page))
  630. MTXDBG(INTERROGATOR|CRITICAL,_("\"y_page\" flag not found in \"%s\" section in interrogation profile, ERROR\n"),section);
  631. if(!cfg_read_int(cfgfile,section,"z_page",&firmware->table_params[i]->z_page))
  632. MTXDBG(INTERROGATOR|CRITICAL,_("\"z_page\" flag not found in \"%s\" section in interrogation profile, ERROR\n"),section);
  633. if(!cfg_read_int(cfgfile,section,"x_base_offset",&firmware->table_params[i]->x_base))
  634. MTXDBG(INTERROGATOR|CRITICAL,_("\"x_base_offset\" variable not found in interrogation profile, ERROR\n"));
  635. if(!cfg_read_int(cfgfile,section,"y_base_offset",&firmware->table_params[i]->y_base))
  636. MTXDBG(INTERROGATOR|CRITICAL,_("\"y_base_offset\" variable not found in interrogation profile, ERROR\n"));
  637. if(!cfg_read_int(cfgfile,section,"z_base_offset",&firmware->table_params[i]->z_base))
  638. MTXDBG(INTERROGATOR|CRITICAL,_("\"z_base_offset\" variable not found in interrogation profile, ERROR\n"));
  639. if(!cfg_read_int(cfgfile,section,"x_bincount",&firmware->table_params[i]->x_bincount))
  640. MTXDBG(INTERROGATOR|CRITICAL,_("\"x_bincount\" variable not found in interrogation profile, ERROR\n"));
  641. if(!cfg_read_int(cfgfile,section,"y_bincount",&firmware->table_params[i]->y_bincount))
  642. MTXDBG(INTERROGATOR|CRITICAL,_("\"y_bincount\" variable not found in interrogation profile, ERROR\n"));
  643. if(!cfg_read_string(cfgfile,section,"x_size",&tmpbuf))
  644. MTXDBG(INTERROGATOR|CRITICAL,_("\"x_size\" enumeration not found in interrogation profile, ERROR\n"));
  645. else
  646. {
  647. firmware->table_params[i]->x_size = (DataSize)translate_string_f(tmpbuf);
  648. g_free(tmpbuf);
  649. }
  650. if(!cfg_read_string(cfgfile,section,"y_size",&tmpbuf))
  651. MTXDBG(INTERROGATOR|CRITICAL,_("\"y_size\" enumeration not found in interrogation profile, ERROR\n"));
  652. else
  653. {
  654. firmware->table_params[i]->y_size = (DataSize)translate_string_f(tmpbuf);
  655. g_free(tmpbuf);
  656. }
  657. if(!cfg_read_string(cfgfile,section,"z_size",&tmpbuf))
  658. MTXDBG(INTERROGATOR|CRITICAL,_("\"z_size\" enumeration not found in interrogation profile, ERROR\n"));
  659. else
  660. {
  661. firmware->table_params[i]->z_size = (DataSize)translate_string_f(tmpbuf);
  662. g_free(tmpbuf);
  663. }
  664. if(!cfg_read_int(cfgfile,section,"z_raw_lower",&firmware->table_params[i]->z_raw_lower))
  665. {
  666. firmware->table_params[i]->z_raw_lower = get_extreme_from_size_f(firmware->table_params[i]->z_size,LOWER);
  667. }
  668. if(!cfg_read_int(cfgfile,section,"z_raw_upper",&firmware->table_params[i]->z_raw_upper))
  669. {
  670. firmware->table_params[i]->z_raw_upper = get_extreme_from_size_f(firmware->table_params[i]->z_size,UPPER);
  671. }
  672. if(cfg_read_boolean(cfgfile,section,"x_multi_source",&firmware->table_params[i]->x_multi_source))
  673. {
  674. /* READ multi-source stuff, but do NOT create
  675. * evaluators, we do that in the final copy
  676. * over to the firmware struct
  677. */
  678. if(!cfg_read_string(cfgfile,section,"x_multi_expr_keys",&firmware->table_params[i]->x_multi_expr_keys))
  679. MTXDBG(INTERROGATOR|CRITICAL,_("\"x_multi_expr_keys\" variable not found in interrogation profile, ERROR\n"));
  680. if(!cfg_read_string(cfgfile,section,"x_source_key",&firmware->table_params[i]->x_source_key))
  681. MTXDBG(INTERROGATOR|CRITICAL,_("\"x_source_key\" variable not found in interrogation profile, ERROR\n"));
  682. if(!cfg_read_string(cfgfile,section,"x_sources",&firmware->table_params[i]->x_sources))
  683. MTXDBG(INTERROGATOR|CRITICAL,_("\"x_sources\" variable not found in interrogation profile, ERROR\n"));
  684. if(!cfg_read_string(cfgfile,section,"x_suffixes",&firmware->table_params[i]->x_suffixes))
  685. MTXDBG(INTERROGATOR|CRITICAL,_("\"x_suffixes\" variable not found in interrogation profile, ERROR\n"));
  686. if(!cfg_read_string(cfgfile,section,"x_fromecu_mults",&firmware->table_params[i]->x_fromecu_mults))
  687. MTXDBG(INTERROGATOR|CRITICAL,_("\"x_fromecu_mults\" variable not found in interrogation profile, table %i, ERROR\n"),i);
  688. if(!cfg_read_string(cfgfile,section,"x_fromecu_adds",&firmware->table_params[i]->x_fromecu_adds))
  689. MTXDBG(INTERROGATOR|CRITICAL,_("\"x_fromecu_adds\" variable not found in interrogation profile, table %i, ERROR\n"),i);
  690. if(!cfg_read_string(cfgfile,section,"x_precisions",&firmware->table_params[i]->x_precisions))
  691. MTXDBG(INTERROGATOR|CRITICAL,_("\"x_precisions\" variable not found in interrogation profile, ERROR\n"));
  692. cfg_read_string(cfgfile,section,"x_lookuptables",&firmware->table_params[i]->x_lookuptables);
  693. cfg_read_boolean(cfgfile,section,"x_ignore_algorithm",&firmware->table_params[i]->x_ignore_algorithm);
  694. }
  695. else
  696. {
  697. if(!cfg_read_string(cfgfile,section,"x_source",&firmware->table_params[i]->x_source))
  698. MTXDBG(INTERROGATOR|CRITICAL,_("\"x_source\" variable not found in interrogation profile, ERROR\n"));
  699. if(!cfg_read_string(cfgfile,section,"x_suffix",&firmware->table_params[i]->x_suffix))
  700. MTXDBG(INTERROGATOR|CRITICAL,_("\"x_suffix\" variable not found in interrogation profile, ERROR\n"));
  701. if(cfg_read_boolean(cfgfile,section,"x_complex",&firmware->table_params[i]->x_complex))
  702. {
  703. cfg_read_string(cfgfile,section,"x_fromecu_conv_expr",&firmware->table_params[i]->x_fromecu_conv_expr);
  704. cfg_read_string(cfgfile,section,"x_toecu_conv_expr",&firmware->table_params[i]->x_toecu_conv_expr);
  705. }
  706. else
  707. {
  708. if(cfg_read_float(cfgfile,section,"x_fromecu_mult",&tmpf))
  709. {
  710. firmware->table_params[i]->x_fromecu_mult = g_new0(gfloat, 1);
  711. *(firmware->table_params[i]->x_fromecu_mult) = tmpf;
  712. }
  713. if(cfg_read_float(cfgfile,section,"x_fromecu_add",&tmpf))
  714. {
  715. firmware->table_params[i]->x_fromecu_add = g_new0(gfloat, 1);
  716. *(firmware->table_params[i]->x_fromecu_add) = tmpf;
  717. }
  718. }
  719. if(!cfg_read_int(cfgfile,section,"x_precision",&firmware->table_params[i]->x_precision))
  720. MTXDBG(INTERROGATOR|CRITICAL,_("\"x_precision\" variable not found in interrogation profile for table %i, ERROR\n"),i);
  721. }
  722. if(cfg_read_boolean(cfgfile,section,"y_multi_source",&firmware->table_params[i]->y_multi_source))
  723. {
  724. /* READ multi-source stuff, but do NOT create
  725. * evaluators, we do that in the final copy
  726. * over to the firmware struct
  727. */
  728. if(!cfg_read_string(cfgfile,section,"y_multi_expr_keys",&firmware->table_params[i]->y_multi_expr_keys))
  729. MTXDBG(INTERROGATOR|CRITICAL,_("\"y_multi_expr_keys\" variable not found in interrogation profile, ERROR\n"));
  730. if(!cfg_read_string(cfgfile,section,"y_source_key",&firmware->table_params[i]->y_source_key))
  731. MTXDBG(INTERROGATOR|CRITICAL,_("\"y_source_key\" variable not found in interrogation profile, ERROR\n"));
  732. if(!cfg_read_string(cfgfile,section,"y_sources",&firmware->table_params[i]->y_sources))
  733. MTXDBG(INTERROGATOR|CRITICAL,_("\"y_sources\" variable not found in interrogation profile, ERROR\n"));
  734. if(!cfg_read_string(cfgfile,section,"y_suffixes",&firmware->table_params[i]->y_suffixes))
  735. MTXDBG(INTERROGATOR|CRITICAL,_("\"y_suffixes\" variable not found in interrogation profile, ERROR\n"));
  736. if(!cfg_read_string(cfgfile,section,"y_fromecu_mults",&firmware->table_params[i]->y_fromecu_mults))
  737. MTXDBG(INTERROGATOR|CRITICAL,_("\"y_fromecu_mults\" variable not found in interrogation profile, table %i, ERROR\n"),i);
  738. if(!cfg_read_string(cfgfile,section,"y_fromecu_adds",&firmware->table_params[i]->y_fromecu_adds))
  739. MTXDBG(INTERROGATOR|CRITICAL,_("\"y_fromecu_adds\" variable not found in interrogation profile, table %i, ERROR\n"),i);
  740. if(!cfg_read_string(cfgfile,section,"y_precisions",&firmware->table_params[i]->y_precisions))
  741. MTXDBG(INTERROGATOR|CRITICAL,_("\"y_precisions\" variable not found in interrogation profile, ERROR\n"));
  742. cfg_read_string(cfgfile,section,"y_lookuptables",&firmware->table_params[i]->y_lookuptables);
  743. cfg_read_boolean(cfgfile,section,"y_ignore_algorithm",&firmware->table_params[i]->y_ignore_algorithm);
  744. }
  745. else
  746. {
  747. if(!cfg_read_string(cfgfile,section,"y_source",&firmware->table_params[i]->y_source))
  748. MTXDBG(INTERROGATOR|CRITICAL,_("\"y_source\" variable not found in interrogation profile, ERROR\n"));
  749. if(!cfg_read_string(cfgfile,section,"y_suffix",&firmware->table_params[i]->y_suffix))
  750. MTXDBG(INTERROGATOR|CRITICAL,_("\"y_suffix\" variable not found in interrogation profile, ERROR\n"));
  751. if(cfg_read_boolean(cfgfile,section,"y_complex",&firmware->table_params[i]->y_complex))
  752. {
  753. cfg_read_string(cfgfile,section,"y_fromecu_conv_expr",&firmware->table_params[i]->y_fromecu_conv_expr);
  754. cfg_read_string(cfgfile,section,"y_toecu_conv_expr",&firmware->table_params[i]->y_toecu_conv_expr);
  755. }
  756. else
  757. {
  758. if(cfg_read_float(cfgfile,section,"y_fromecu_mult",&tmpf))
  759. {
  760. firmware->table_params[i]->y_fromecu_mult = g_new0(gfloat, 1);
  761. *(firmware->table_params[i]->y_fromecu_mult) = tmpf;
  762. }
  763. if(cfg_read_float(cfgfile,section,"y_fromecu_add",&tmpf))
  764. {
  765. firmware->table_params[i]->y_fromecu_add = g_new0(gfloat, 1);
  766. *(firmware->table_params[i]->y_fromecu_add) = tmpf;
  767. }
  768. }
  769. if(!cfg_read_int(cfgfile,section,"y_precision",&firmware->table_params[i]->y_precision))
  770. MTXDBG(INTERROGATOR|CRITICAL,_("\"y_precision\" variable not found in interrogation profile for table %i, ERROR\n"),i);
  771. }
  772. if(cfg_read_boolean(cfgfile,section,"z_multi_source",&firmware->table_params[i]->z_multi_source))
  773. {
  774. /* READ multi-source stuff, but do NOT create
  775. * evaluators, we do that in the final copy
  776. * over to the firmware struct
  777. */
  778. if(!cfg_read_string(cfgfile,section,"z_multi_expr_keys",&firmware->table_params[i]->z_multi_expr_keys))
  779. MTXDBG(INTERROGATOR|CRITICAL,_("\"z_multi_expr_keys\" variable not found in interrogation profile, ERROR\n"));
  780. if(!cfg_read_string(cfgfile,section,"z_source_key",&firmware->table_params[i]->z_source_key))
  781. MTXDBG(INTERROGATOR|CRITICAL,_("\"z_source_key\" variable not found in interrogation profile, ERROR\n"));
  782. if(!cfg_read_string(cfgfile,section,"z_sources",&firmware->table_params[i]->z_sources))
  783. MTXDBG(INTERROGATOR|CRITICAL,_("\"z_sources\" variable not found in interrogation profile, ERROR\n"));
  784. if(!cfg_read_string(cfgfile,section,"z_suffixes",&firmware->table_params[i]->z_suffixes))
  785. MTXDBG(INTERROGATOR|CRITICAL,_("\"z_suffixes\" variable not found in interrogation profile, ERROR\n"));
  786. if(!cfg_read_string(cfgfile,section,"z_fromecu_mults",&firmware->table_params[i]->z_fromecu_mults))
  787. MTXDBG(INTERROGATOR|CRITICAL,_("\"z_fromecu_mults\" variable not found in interrogation profile, table %i, ERROR\n"),i);
  788. if(!cfg_read_string(cfgfile,section,"z_fromecu_adds",&firmware->table_params[i]->z_fromecu_adds))
  789. MTXDBG(INTERROGATOR|CRITICAL,_("\"z_fromecu_adds\" variable not found in interrogation profile, table %i, ERROR\n"),i);
  790. if(!cfg_read_string(cfgfile,section,"z_precisions",&firmware->table_params[i]->z_precisions))
  791. MTXDBG(INTERROGATOR|CRITICAL,_("\"z_precisions\" variable not found in interrogation profile, ERROR\n"));
  792. cfg_read_string(cfgfile,section,"z_lookuptables",&firmware->table_params[i]->z_lookuptables);
  793. cfg_read_boolean(cfgfile,section,"z_ignore_algorithm",&firmware->table_params[i]->z_ignore_algorithm);
  794. }
  795. else
  796. {
  797. if(!cfg_read_string(cfgfile,section,"z_source",&firmware->table_params[i]->z_source))
  798. MTXDBG(INTERROGATOR|CRITICAL,_("\"z_source\" variable not found in interrogation profile, ERROR\n"));
  799. if(!cfg_read_string(cfgfile,section,"z_suffix",&firmware->table_params[i]->z_suffix))
  800. MTXDBG(INTERROGATOR|CRITICAL,_("\"z_suffix\" variable not found in interrogation profile, ERROR\n"));
  801. if(cfg_read_boolean(cfgfile,section,"z_complex",&firmware->table_params[i]->z_complex))
  802. {
  803. cfg_read_string(cfgfile,section,"z_fromecu_conv_expr",&firmware->table_params[i]->z_fromecu_conv_expr);
  804. cfg_read_string(cfgfile,section,"z_toecu_conv_expr",&firmware->table_params[i]->z_toecu_conv_expr);
  805. }
  806. else
  807. {
  808. if(cfg_read_float(cfgfile,section,"z_fromecu_mult",&tmpf))
  809. {
  810. firmware->table_params[i]->z_fromecu_mult = g_new0(gfloat, 1);
  811. *(firmware->table_params[i]->z_fromecu_mult) = tmpf;
  812. }
  813. if(cfg_read_float(cfgfile,section,"z_fromecu_add",&tmpf))
  814. {
  815. firmware->table_params[i]->z_fromecu_add = g_new0(gfloat, 1);
  816. *(firmware->table_params[i]->z_fromecu_add) = tmpf;
  817. }
  818. }
  819. if(!cfg_read_int(cfgfile,section,"z_precision",&firmware->table_params[i]->z_precision))
  820. MTXDBG(INTERROGATOR|CRITICAL,_("\"z_precision\" variable not found in interrogation profile for table %i, ERROR\n"),i);
  821. if(cfg_read_string(cfgfile,section,"z_depend_on",&firmware->table_params[i]->z_depend_on))
  822. {
  823. firmware->table_params[i]->z_object = (GObject *)g_object_new(GTK_TYPE_INVISIBLE,NULL);
  824. g_object_ref_sink(GTK_OBJECT(firmware->table_params[i]->z_object));
  825. load_dependencies_obj(firmware->table_params[i]->z_object,cfgfile,section,"z_depend_on");
  826. if(!cfg_read_string(cfgfile,section,"z_alt_lookuptable",&tmpbuf))
  827. MTXDBG(INTERROGATOR|CRITICAL,_("\"z_alt_lookuptable\" variable not found in interrogation profile, NOT NECESSARILY AN ERROR\n"));
  828. else
  829. {
  830. OBJ_SET_FULL(firmware->table_params[i]->z_object,"alt_lookuptable",g_strdup(tmpbuf),g_free);
  831. g_free(tmpbuf);
  832. }
  833. if(!cfg_read_string(cfgfile,section,"z_lookuptable",&tmpbuf))
  834. MTXDBG(INTERROGATOR|CRITICAL,_("\"z_lookuptable\" variable not found in interrogation profile, NOT NECESSARILY AN ERROR\n"));
  835. else
  836. {
  837. OBJ_SET_FULL(firmware->table_params[i]->z_object,"lookuptable",g_strdup(tmpbuf),g_free);
  838. g_free(tmpbuf);
  839. }
  840. }
  841. }
  842. cfg_read_boolean(cfgfile,section,"x_use_color",&firmware->table_params[i]->x_use_color);
  843. cfg_read_boolean(cfgfile,section,"y_use_color",&firmware->table_params[i]->y_use_color);
  844. cfg_read_boolean(cfgfile,section,"z_use_color",&firmware->table_params[i]->z_use_color);
  845. if(!cfg_read_string(cfgfile,section,"table_name",&firmware->table_params[i]->table_name))
  846. MTXDBG(INTERROGATOR|CRITICAL,_("\"table_name\" variable not found in interrogation profile, ERROR\n"));
  847. g_free(section);
  848. }
  849. /* Allocate space for Table Editor structures.... */
  850. firmware->te_params = g_new0(TE_Params *,firmware->total_te_tables);
  851. for (i=0;i<firmware->total_te_tables;i++)
  852. {
  853. firmware->te_params[i] = initialize_te_params();
  854. section = g_strdup_printf("te_table_%i",i);
  855. cfg_read_boolean(cfgfile,section,"x_lock",&firmware->te_params[i]->x_lock);
  856. cfg_read_boolean(cfgfile,section,"y_lock",&firmware->te_params[i]->y_lock);
  857. cfg_read_boolean(cfgfile,section,"reversed",&firmware->te_params[i]->reversed);
  858. cfg_read_string(cfgfile,section,"bind_to_list",&firmware->te_params[i]->bind_to_list);
  859. if(cfg_read_string(cfgfile,section,"match_type",&tmpbuf))
  860. {
  861. firmware->te_params[i]->match_type = (MatchType)translate_string_f(tmpbuf);
  862. g_free(tmpbuf);
  863. }
  864. cfg_read_boolean(cfgfile,section,"gauge_temp_dep",&firmware->te_params[i]->gauge_temp_dep);
  865. cfg_read_string(cfgfile,section,"gauge",&firmware->te_params[i]->gauge);
  866. cfg_read_string(cfgfile,section,"c_gauge",&firmware->te_params[i]->c_gauge);
  867. cfg_read_string(cfgfile,section,"f_gauge",&firmware->te_params[i]->f_gauge);
  868. if (firmware->te_params[i]->f_gauge || firmware->te_params[i]->c_gauge || firmware->te_params[i]->gauge)
  869. cfg_read_string(cfgfile,section,"gauge_datasource",&firmware->te_params[i]->gauge_datasource);
  870. cfg_read_boolean(cfgfile,section,"x_use_color",&firmware->te_params[i]->x_use_color);
  871. cfg_read_boolean(cfgfile,section,"y_use_color",&firmware->te_params[i]->y_use_color);
  872. cfg_read_boolean(cfgfile,section,"x_temp_dep",&firmware->te_params[i]->x_temp_dep);
  873. cfg_read_boolean(cfgfile,section,"y_temp_dep",&firmware->te_params[i]->y_temp_dep);
  874. if(!cfg_read_string(cfgfile,section,"x_axis_label",&firmware->te_params[i]->x_axis_label))
  875. MTXDBG(INTERROGATOR|CRITICAL,_("\"x_axis_label\" flag not found in \"%s\" section in interrogation profile, ERROR\n"),section);
  876. if(!cfg_read_string(cfgfile,section,"y_axis_label",&firmware->te_params[i]->y_axis_label))
  877. MTXDBG(INTERROGATOR|CRITICAL,_("\"y_axis_label\" flag not found in \"%s\" section in interrogation profile, ERROR\n"),section);
  878. if(!cfg_read_int(cfgfile,section,"x_page",&firmware->te_params[i]->x_page))
  879. MTXDBG(INTERROGATOR|CRITICAL,_("\"x_page\" flag not found in \"%s\" section in interrogation profile, ERROR\n"),section);
  880. if(!cfg_read_int(cfgfile,section,"y_page",&firmware->te_params[i]->y_page))
  881. MTXDBG(INTERROGATOR|CRITICAL,_("\"y_page\" flag not found in \"%s\" section in interrogation profile, ERROR\n"),section);
  882. if(!cfg_read_int(cfgfile,section,"x_base_offset",&firmware->te_params[i]->x_base))
  883. MTXDBG(INTERROGATOR|CRITICAL,_("\"x_base_offset\" variable not found in interrogation profile, ERROR\n"));
  884. if(!cfg_read_int(cfgfile,section,"y_base_offset",&firmware->te_params[i]->y_base))
  885. MTXDBG(INTERROGATOR|CRITICAL,_("\"y_base_offset\" variable not found in interrogation profile, ERROR\n"));
  886. if(!cfg_read_int(cfgfile,section,"bincount",&firmware->te_params[i]->bincount))
  887. MTXDBG(INTERROGATOR|CRITICAL,_("\"x_bincount\" variable not found in interrogation profile, ERROR\n"));
  888. if(!cfg_read_string(cfgfile,section,"x_size",&tmpbuf))
  889. MTXDBG(INTERROGATOR|CRITICAL,_("\"x_size\" enumeration not found in interrogation profile, ERROR\n"));
  890. else
  891. {
  892. firmware->te_params[i]->x_size = (DataSize)translate_string_f(tmpbuf);
  893. g_free(tmpbuf);
  894. }
  895. if(!cfg_read_string(cfgfile,section,"y_size",&tmpbuf))
  896. MTXDBG(INTERROGATOR|CRITICAL,_("\"y_size\" enumeration not found in interrogation profile, ERROR\n"));
  897. else
  898. {
  899. firmware->te_params[i]->y_size = (DataSize)translate_string_f(tmpbuf);
  900. g_free(tmpbuf);
  901. }
  902. if(!cfg_read_string(cfgfile,section,"x_source",&firmware->te_params[i]->x_source))
  903. MTXDBG(INTERROGATOR|CRITICAL,_("\"x_source\" variable not found in interrogation profile, ERROR\n"));
  904. if(!cfg_read_string(cfgfile,section,"x_units",&firmware->te_params[i]->x_units))
  905. MTXDBG(INTERROGATOR|CRITICAL,_("\"x_units\" variable not found in interrogation profile, ERROR\n"));
  906. if(!cfg_read_string(cfgfile,section,"x_name",&firmware->te_params[i]->x_name))
  907. MTXDBG(INTERROGATOR|CRITICAL,_("\"x_name\" variable not found in interrogation profile, ERROR\n"));
  908. if(cfg_read_float(cfgfile,section,"x_fromecu_mult",&tmpf))
  909. {
  910. firmware->te_params[i]->x_fromecu_mult = g_new0(gfloat,1 );
  911. *(firmware->te_params[i]->x_fromecu_mult) = tmpf;
  912. }
  913. if(cfg_read_float(cfgfile,section,"x_fromecu_add",&tmpf))
  914. {
  915. firmware->te_params[i]->x_fromecu_add = g_new0(gfloat,1 );
  916. *(firmware->te_params[i]->x_fromecu_add) = tmpf;
  917. }
  918. if(!cfg_read_int(cfgfile,section,"x_raw_lower",&firmware->te_params[i]->x_raw_lower))
  919. MTXDBG(INTERROGATOR|CRITICAL,_("\"x_raw_lower\" variable not found in interrogation profile for table %i, ERROR\n"),i);
  920. if(!cfg_read_int(cfgfile,section,"x_raw_upper",&firmware->te_params[i]->x_raw_upper))
  921. MTXDBG(INTERROGATOR|CRITICAL,_("\"x_raw_upper\" variable not found in interrogation profile for table %i, ERROR\n"),i);
  922. if(!cfg_read_int(cfgfile,section,"x_precision",&firmware->te_params[i]->x_precision))
  923. MTXDBG(INTERROGATOR|CRITICAL,_("\"x_precision\" variable not found in interrogation profile for table %i, ERROR\n"),i);
  924. if(!cfg_read_string(cfgfile,section,"y_units",&firmware->te_params[i]->y_units))
  925. MTXDBG(INTERROGATOR|CRITICAL,_("\"y_units\" variable not found in interrogation profile, ERROR\n"));
  926. if(!cfg_read_string(cfgfile,section,"y_name",&firmware->te_params[i]->y_name))
  927. MTXDBG(INTERROGATOR|CRITICAL,_("\"y_name\" variable not found in interrogation profile, ERROR\n"));
  928. if(cfg_read_float(cfgfile,section,"y_fromecu_mult",&tmpf))
  929. {
  930. firmware->te_params[i]->y_fromecu_mult = g_new0(gfloat,1 );
  931. *(firmware->te_params[i]->y_fromecu_mult) = tmpf;
  932. }
  933. if(cfg_read_float(cfgfile,section,"y_fromecu_add",&tmpf))
  934. {
  935. firmware->te_params[i]->y_fromecu_add = g_new0(gfloat,1 );
  936. *(firmware->te_params[i]->y_fromecu_add) = tmpf;
  937. }
  938. if(!cfg_read_int(cfgfile,section,"y_raw_lower",&firmware->te_params[i]->y_raw_lower))
  939. MTXDBG(INTERROGATOR|CRITICAL,_("\"y_raw_lower\" variable not found in interrogation profile for table %i, ERROR\n"),i);
  940. if(!cfg_read_int(cfgfile,section,"y_raw_upper",&firmware->te_params[i]->y_raw_upper))
  941. MTXDBG(INTERROGATOR|CRITICAL,_("\"y_raw_upper\" variable not found in interrogation profile for table %i, ERROR\n"),i);
  942. if(!cfg_read_int(cfgfile,section,"y_precision",&firmware->te_params[i]->y_precision))
  943. MTXDBG(INTERROGATOR|CRITICAL,_("\"y_precision\" variable not found in interrogation profile for table %i, ERROR\n"),i);
  944. if(!cfg_read_string(cfgfile,section,"title",&firmware->te_params[i]->title))
  945. MTXDBG(INTERROGATOR|CRITICAL,_("\"title\" variable not found in interrogation profile, ERROR\n"));
  946. g_free(section);
  947. }
  948. cfg_free(cfgfile);
  949. /* Allocate RAM for the Req_Fuel_Params structures.*/
  950. firmware->rf_params = g_new0(Req_Fuel_Params *,firmware->total_tables);
  951. /* Allocate RAM for the Table_Params structures and copy data in..*/
  952. for (i=0;i<firmware->total_tables;i++)
  953. {
  954. firmware->rf_params[i] = g_new0(Req_Fuel_Params ,1);
  955. /* Check for multi source table handling */
  956. if (firmware->table_params[i]->x_multi_source)
  957. {
  958. firmware->table_params[i]->x_multi_hash = g_hash_table_new_full(g_str_hash,g_str_equal,NULL,NULL);
  959. expr_keys = g_strsplit(firmware->table_params[i]->x_multi_expr_keys,",",-1);
  960. sources = g_strsplit(firmware->table_params[i]->x_sources,",",-1);
  961. suffixes = g_strsplit(firmware->table_params[i]->x_suffixes,",",-1);
  962. fromecu_mults = g_strsplit(firmware->table_params[i]->x_fromecu_mults,",",-1);
  963. fromecu_adds = g_strsplit(firmware->table_params[i]->x_fromecu_adds,",",-1);
  964. precisions = g_strsplit(firmware->table_params[i]->x_precisions,",",-1);
  965. if (firmware->table_params[i]->x_lookuptables)
  966. tables = g_strsplit(firmware->table_params[i]->x_lookuptables,",",-1);
  967. else
  968. tables = NULL;
  969. len1 = g_strv_length(expr_keys);
  970. len2 = g_strv_length(sources);
  971. len3 = g_strv_length(suffixes);
  972. len4 = g_strv_length(fromecu_mults);
  973. len5 = g_strv_length(fromecu_adds);
  974. len6 = g_strv_length(precisions);
  975. if ((len1 != len2) || (len1 != len3) || (len1 != len4) || (len1 != len5) || (len1 != len6))
  976. printf(_("X multi_sources length mismatch!\n"));
  977. for (j=0;j<len1;j++)
  978. {
  979. multi = g_new0(MultiSource,1);
  980. multi->table_num = i;
  981. multi->source = g_strdup(sources[j]);
  982. multi->multiplier = g_new0(gfloat, 1);
  983. multi->adder = g_new0(gfloat, 1);
  984. *multi->multiplier = (gfloat)g_strtod(fromecu_mults[j],NULL);
  985. *multi->adder = (gfloat)g_strtod(fromecu_adds[j],NULL);
  986. multi->suffix = g_strdup(suffixes[j]);
  987. multi->precision = (gint)strtol(precisions[j],NULL,10);
  988. if (tables && tables[j])
  989. multi->lookuptable = g_strdup(tables[j]);
  990. else
  991. multi->lookuptable = NULL;
  992. g_hash_table_insert(firmware->table_params[i]->x_multi_hash,g_strdup(expr_keys[j]),(gpointer)multi);
  993. }
  994. g_strfreev(expr_keys);
  995. g_strfreev(sources);
  996. g_strfreev(suffixes);
  997. g_strfreev(fromecu_mults);
  998. g_strfreev(fromecu_adds);
  999. g_strfreev(precisions);
  1000. if (tables)
  1001. g_strfreev(tables);
  1002. }
  1003. else
  1004. {
  1005. if (firmware->table_params[i]->x_complex)
  1006. {
  1007. firmware->table_params[i]->x_ul_eval = evaluator_create_f(firmware->table_params[i]->x_fromecu_conv_expr);
  1008. firmware->table_params[i]->x_dl_eval = evaluator_create_f(firmware->table_params[i]->x_toecu_conv_expr);
  1009. }
  1010. }
  1011. /* Check for multi source table handling */
  1012. if (firmware->table_params[i]->y_multi_source)
  1013. {
  1014. firmware->table_params[i]->y_multi_hash = g_hash_table_new_full(g_str_hash,g_str_equal,NULL,NULL);
  1015. expr_keys = g_strsplit(firmware->table_params[i]->y_multi_expr_keys,",",-1);
  1016. sources = g_strsplit(firmware->table_params[i]->y_sources,",",-1);
  1017. suffixes = g_strsplit(firmware->table_params[i]->y_suffixes,",",-1);
  1018. fromecu_mults = g_strsplit(firmware->table_params[i]->y_fromecu_mults,",",-1);
  1019. fromecu_adds = g_strsplit(firmware->table_params[i]->y_fromecu_adds,",",-1);
  1020. precisions = g_strsplit(firmware->table_params[i]->y_precisions,",",-1);
  1021. if (firmware->table_params[i]->y_lookuptables)
  1022. tables = g_strsplit(firmware->table_params[i]->y_lookuptables,",",-1);
  1023. else
  1024. tables = NULL;
  1025. len1 = g_strv_length(expr_keys);
  1026. len2 = g_strv_length(sources);
  1027. len3 = g_strv_length(suffixes);
  1028. len4 = g_strv_length(fromecu_mults);
  1029. len5 = g_strv_length(fromecu_adds);
  1030. len6 = g_strv_length(precisions);
  1031. if ((len1 != len2) || (len1 != len3) || (len1 != len4) || (len1 != len5) || (len1 != len6))
  1032. printf(_("Y multi_sources length mismatch!\n"));
  1033. for (j=0;j<len1;j++)
  1034. {
  1035. multi = g_new0(MultiSource,1);
  1036. multi->table_num = i;
  1037. multi->source = g_strdup(sources[j]);
  1038. multi->multiplier = g_new0(gfloat, 1);
  1039. multi->adder = g_new0(gfloat, 1);
  1040. *multi->multiplier = (gfloat)g_strtod(fromecu_mults[j],NULL);
  1041. *multi->adder = (gfloat)g_strtod(fromecu_adds[j],NULL);
  1042. multi->suffix = g_strdup(suffixes[j]);
  1043. multi->precision = (gint)strtol(precisions[j],NULL,10);
  1044. if (tables && tables[j])
  1045. multi->lookuptable = g_strdup(tables[j]);
  1046. else
  1047. multi->lookuptable = NULL;
  1048. g_hash_table_insert(firmware->table_params[i]->y_multi_hash,g_strdup(expr_keys[j]),(gpointer)multi);
  1049. }
  1050. g_strfreev(expr_keys);
  1051. g_strfreev(sources);
  1052. g_strfreev(suffixes);
  1053. g_strfreev(fromecu_mults);
  1054. g_strfreev(fromecu_adds);
  1055. g_strfreev(precisions);
  1056. if (tables)
  1057. g_strfreev(tables);
  1058. }
  1059. else
  1060. {
  1061. if (firmware->table_params[i]->y_complex)
  1062. {
  1063. firmware->table_params[i]->y_ul_eval = evaluator_create_f(firmware->table_params[i]->y_fromecu_conv_expr);
  1064. firmware->table_params[i]->y_dl_eval = evaluator_create_f(firmware->table_params[i]->y_toecu_conv_expr);
  1065. }
  1066. }
  1067. /* Check for multi source table handling */
  1068. if (firmware->table_params[i]->z_multi_source)
  1069. {
  1070. firmware->table_params[i]->z_multi_hash = g_hash_table_new_full(g_str_hash,g_str_equal,NULL,NULL);
  1071. expr_keys = g_strsplit(firmware->table_params[i]->z_multi_expr_keys,",",-1);
  1072. sources = g_strsplit(firmware->table_params[i]->z_sources,",",-1);
  1073. suffixes = g_strsplit(firmware->table_params[i]->z_suffixes,",",-1);
  1074. fromecu_mults = g_strsplit(firmware->table_params[i]->z_fromecu_mults,",",-1);
  1075. fromecu_adds = g_strsplit(firmware->table_params[i]->z_fromecu_adds,",",-1);
  1076. precisions = g_strsplit(firmware->table_params[i]->z_precisions,",",-1);
  1077. if (firmware->table_params[i]->z_lookuptables)
  1078. tables = g_strsplit(firmware->table_params[i]->z_lookuptables,",",-1);
  1079. else
  1080. tables = NULL;
  1081. len1 = g_strv_length(expr_keys);
  1082. len2 = g_strv_length(sources);
  1083. len3 = g_strv_length(suffixes);
  1084. len4 = g_strv_length(fromecu_mults);
  1085. len5 = g_strv_length(fromecu_adds);
  1086. len6 = g_strv_length(precisions);
  1087. if ((len1 != len2) || (len1 != len3) || (len1 != len4) || (len1 != len5) || (len1 != len6))
  1088. printf(_("Z multi_sources length mismatch!\n"));
  1089. for (j=0;j<len1;j++)
  1090. {
  1091. multi = g_new0(MultiSource,1);
  1092. multi->table_num = i;
  1093. multi->source = g_strdup(sources[j]);
  1094. multi->multiplier = g_new0(gfloat, 1);
  1095. multi->adder = g_new0(gfloat, 1);
  1096. *multi->multiplier = (gfloat)g_strtod(fromecu_mults[j],NULL);
  1097. *multi->adder = (gfloat)g_strtod(fromecu_adds[j],NULL);
  1098. multi->suffix = g_strdup(suffixes[j]);
  1099. multi->precision = (gint)strtol(precisions[j],NULL,10);
  1100. if (tables && tables[j])
  1101. multi->lookuptable = g_strdup(tables[j]);
  1102. else
  1103. multi->lookuptable = NULL;
  1104. g_hash_table_insert(firmware->table_params[i]->z_multi_hash,g_strdup(expr_keys[j]),(gpointer)multi);
  1105. }
  1106. g_strfreev(expr_keys);
  1107. g_strfreev(sources);
  1108. g_strfreev(suffixes);
  1109. g_strfreev(fromecu_mults);
  1110. g_strfreev(fromecu_adds);
  1111. g_strfreev(precisions);
  1112. if (tables)
  1113. g_strfreev(tables);
  1114. }
  1115. else
  1116. {
  1117. if (firmware->table_params[i]->z_complex)
  1118. {
  1119. firmware->table_params[i]->z_ul_eval = evaluator_create_f(firmware->table_params[i]->z_fromecu_conv_expr);
  1120. firmware->table_params[i]->z_dl_eval = evaluator_create_f(firmware->table_params[i]->z_toecu_conv_expr);
  1121. }
  1122. }
  1123. }
  1124. mem_alloc_f();
  1125. /* Display firmware version in the window... */
  1126. MTXDBG(INTERROGATOR,_("Detected Firmware: %s\n"),firmware->name);
  1127. update_logbar_f("interr_view","warning",g_strdup_printf(_("Detected Firmware: %s\n"),firmware->name),FALSE,FALSE,TRUE);
  1128. update_logbar_f("interr_view","info",g_strdup_printf(_("Loading Settings from: \"%s\"\n"),firmware->profile_filename),FALSE,FALSE,TRUE);
  1129. EXIT();
  1130. return TRUE;
  1131. }
  1132. /*!
  1133. \brief validate_and_load_tests() loads the list of tests from the system
  1134. checks them for validity, populates an array and returns it
  1135. \param tests_hash is a double pointer to a hashtable to also populate
  1136. \returns a pointer to a GArray of tests
  1137. */
  1138. G_MODULE_EXPORT GArray * validate_and_load_tests(GHashTable **tests_hash)
  1139. {
  1140. ConfigFile *cfgfile;
  1141. GArray * tests = NULL;
  1142. Detection_Test *test = NULL;
  1143. gchar * filename = NULL;
  1144. gchar *section = NULL;
  1145. gchar * tmpbuf = NULL;
  1146. gint total_tests = 0;
  1147. gint len = 0;
  1148. unsigned long crc32 = 0;
  1149. gint result = 0;
  1150. gint major = 0;
  1151. gint minor = 0;
  1152. gint tmpi = 0;
  1153. gint i = 0;
  1154. gint j = 0;
  1155. gchar *pathstub = NULL;
  1156. ENTER();
  1157. pathstub = g_build_filename(INTERROGATOR_DATA_DIR,"Profiles",DATA_GET(global_data,"ecu_family"),"tests.cfg",NULL);
  1158. filename = get_file((const gchar *)DATA_GET(global_data,"project_name"),pathstub,NULL);
  1159. g_free(pathstub);
  1160. if (!filename)
  1161. {
  1162. update_logbar_f("interr_view","warning",g_strdup_printf(_("Interrogation profile tests file %s not found!\n"),filename),FALSE,FALSE,TRUE);
  1163. EXIT();
  1164. return NULL;
  1165. }
  1166. cfgfile = cfg_open_file(filename);
  1167. if (!cfgfile)
  1168. {
  1169. update_logbar_f("interr_view","warning",g_strdup_printf(_("Interrogation profile tests file %s unable to be opened!\n"),filename),FALSE,FALSE,TRUE);
  1170. EXIT();
  1171. return NULL;
  1172. }
  1173. get_file_api_f(cfgfile,&major,&minor);
  1174. if ((major != INTERROGATE_MAJOR_API) || (minor != INTERROGATE_MINOR_API))
  1175. {
  1176. update_logbar_f("interr_view","warning",g_strdup_printf(_("Interrogation profile tests API mismatch (%i.%i != %i.%i):\n\tFile %s.\n"),major,minor,INTERROGATE_MAJOR_API,INTERROGATE_MINOR_API,filename),FALSE,FALSE,TRUE);
  1177. EXIT();
  1178. return NULL;
  1179. }
  1180. *tests_hash = g_hash_table_new(g_str_hash,g_str_equal);
  1181. MTXDBG(INTERROGATOR,_("File %s, opened successfully\n"),filename);
  1182. tests = g_array_new(FALSE,TRUE,sizeof(Detection_Test *));
  1183. cfg_read_int(cfgfile,"interrogation_tests","total_tests",&total_tests);
  1184. for (i=0;i<total_tests;i++)
  1185. {
  1186. test = g_new0(Detection_Test, 1);
  1187. cfg_read_boolean(cfgfile,"interrogation_tests","ms3_crc32",&test->ms3_crc32);
  1188. section = g_strdup_printf("test_%.2i",i);
  1189. if (!cfg_read_string(cfgfile,section,"test_name",&test->test_name))
  1190. {
  1191. MTXDBG(INTERROGATOR|CRITICAL,_("test_name for %s is NULL\n"),section);
  1192. g_free(section);
  1193. break;
  1194. }
  1195. if (!cfg_read_string(cfgfile,section,"test_result_type",&tmpbuf))
  1196. {
  1197. MTXDBG(INTERROGATOR|CRITICAL,_("test_result_type for %s is NULL\n"),section);
  1198. g_free(section);
  1199. break;
  1200. }
  1201. else
  1202. {
  1203. test->result_type=translate_string_f(tmpbuf);
  1204. g_free(tmpbuf);
  1205. }
  1206. if (!cfg_read_string(cfgfile,section,"actual_test",&test->actual_test))
  1207. {
  1208. MTXDBG(INTERROGATOR|CRITICAL,_("actual_test for %s is NULL\n"),section);
  1209. g_free(section);
  1210. break;
  1211. }
  1212. else
  1213. len = strlen(test->actual_test);
  1214. if (test->ms3_crc32)
  1215. {
  1216. test->send_buf = g_new0(guint8, len + 6); /*length + CRC32 */
  1217. test->send_buf[0] = (len >> 8 ) & 0xff;
  1218. test->send_buf[1] = len & 0xff;
  1219. g_memmove(&test->send_buf[2],test->actual_test,len);
  1220. crc32 = crc32_computebuf(0,&test->send_buf[2],len);
  1221. test->send_buf[2 + len + 0] = (crc32 >> 24) & 0xff;
  1222. test->send_buf[2 + len + 1] = (crc32 >> 16) & 0xff;
  1223. test->send_buf[2 + len + 2] = (crc32 >> 8) & 0xff;
  1224. test->send_buf[2 + len + 3] = crc32 & 0xff;
  1225. test->send_len = len + 6;
  1226. }
  1227. else /* NON CRC edition */
  1228. {
  1229. test->send_buf = (guint8 *)g_memdup(test->actual_test,len);
  1230. test->send_len = len;
  1231. }
  1232. cfg_read_string(cfgfile,section,"test_desc",
  1233. &test->test_desc);
  1234. g_free(section);
  1235. g_array_append_val(tests,test);
  1236. g_hash_table_insert(*tests_hash,test->test_name,test);
  1237. }
  1238. cfg_free(cfgfile);
  1239. g_free(filename);
  1240. EXIT();
  1241. return tests;
  1242. }
  1243. /*!
  1244. \brief translate_capabilities() converts a stringlist into a mask of
  1245. enumerations and returns it
  1246. \param string is the listing of capabilities in textual format
  1247. \returns an integer mask of the capabilites
  1248. */
  1249. G_MODULE_EXPORT gint translate_capabilities(const gchar *string)
  1250. {
  1251. gchar **vector = NULL;
  1252. gint i = 0;
  1253. gint value = 0;
  1254. gint tmpi = 0;
  1255. ENTER();
  1256. if (!string)
  1257. {
  1258. MTXDBG(INTERROGATOR|CRITICAL,_("String fed is NULL\n"));
  1259. EXIT();
  1260. return -1;
  1261. }
  1262. vector = g_strsplit(string,",",0);
  1263. MTXDBG(INTERROGATOR,_("String fed is %s\n"),string);
  1264. while (vector[i] != NULL)
  1265. {
  1266. MTXDBG(INTERROGATOR,_("Trying to translate %s\n"),vector[i]);
  1267. tmpi = translate_string_f(vector[i]);
  1268. MTXDBG(INTERROGATOR,_("Translated value of %s is %i\n"),vector[i],value);
  1269. value += tmpi;
  1270. i++;
  1271. }
  1272. g_strfreev(vector);
  1273. EXIT();
  1274. return value;
  1275. }
  1276. /*!
  1277. \brief check_for_match() compares the results of the interrogation with the
  1278. ECU to the canidates in turn. When a match occurs TRUE is returned
  1279. otherwise it returns FALSE
  1280. \param tests_hash is a pointer to the hashtable of tests
  1281. \param filename isa pointer to the file to compare against
  1282. \returns TRUE on match, FALSE on failure
  1283. */
  1284. G_MODULE_EXPORT gboolean check_for_match(GHashTable *tests_hash, gchar *filename)
  1285. {
  1286. ConfigFile *cfgfile = NULL;
  1287. Detection_Test *test = NULL;
  1288. guint i = 0;
  1289. gint len = 0;
  1290. gboolean pass = FALSE;
  1291. gchar * tmpbuf = NULL;
  1292. gchar ** vector = NULL;
  1293. gchar ** match_on = NULL;
  1294. gint major = 0;
  1295. gint minor = 0;
  1296. MatchClass mclass;
  1297. ENTER();
  1298. cfgfile = cfg_open_file(filename);
  1299. if (!cfgfile)
  1300. {
  1301. EXIT();
  1302. return FALSE;
  1303. }
  1304. get_file_api_f(cfgfile,&major,&minor);
  1305. if ((major != INTERROGATE_MAJOR_API) || (minor != INTERROGATE_MINOR_API))
  1306. {
  1307. update_logbar_f("interr_view","warning",g_strdup_printf(_("Interrogation profile API mismatch (%i.%i != %i.%i):\n\tFile %s will be skipped\n"),major,minor,INTERROGATE_MAJOR_API,INTERROGATE_MINOR_API,filename),FALSE,FALSE,TRUE);
  1308. cfg_free(cfgfile);
  1309. EXIT();
  1310. return FALSE;
  1311. }
  1312. if (cfg_read_string(cfgfile,"interrogation","match_on",&tmpbuf) == FALSE)
  1313. printf(_("ERROR:!! \"match_on\" key missing from interrogation profile [interrogation] section\n"));
  1314. match_on = g_strsplit(tmpbuf,",",-1);
  1315. g_free(tmpbuf);
  1316. for (i=0;i<g_strv_length(match_on);i++)
  1317. {
  1318. pass = FALSE;
  1319. /*printf("checking for match on %s\n",match_on[i]);*/
  1320. test = (Detection_Test *)g_hash_table_lookup(tests_hash,match_on[i]);
  1321. if (!test)
  1322. {
  1323. printf(_("ERROR test data not found for test \"%s\"\n"),match_on[i]);
  1324. continue;
  1325. }
  1326. /* If the test_name is NOT IN the interrogation profile, we
  1327. * abort as it's NOT match
  1328. */
  1329. if (!cfg_read_string(cfgfile,"interrogation",test->test_name,&tmpbuf))
  1330. {
  1331. MTXDBG(INTERROGATOR,_("MISMATCH,\"%s\" is NOT a match...\n\n"),filename);
  1332. cfg_free(cfgfile);
  1333. g_strfreev(match_on);
  1334. EXIT();
  1335. return FALSE;
  1336. }
  1337. vector = g_strsplit(tmpbuf,",",-1);
  1338. g_free(tmpbuf);
  1339. /* Possible choices are "Count", "submatch" and "fullmatch", so
  1340. * stringparse to get them into a consistent form
  1341. */
  1342. if (g_strv_length(vector) != 2)
  1343. printf(_("ERROR interrogation check_for match vector does NOT have two args it has %i\n"),g_strv_length(vector));
  1344. mclass = (MatchClass)translate_string_f(vector[0]);
  1345. /*printf("potential data is %s\n",vector[1]);*/
  1346. switch (mclass)
  1347. {
  1348. case COUNT:
  1349. if (test->recv_len == atoi(vector[1]))
  1350. pass = TRUE;
  1351. break;
  1352. case NUMMATCH:
  1353. if (test->result_str)
  1354. {
  1355. if ((gint)(test->result_str[0]) == atoi(vector[1]))
  1356. pass = TRUE;
  1357. }
  1358. else
  1359. pass = FALSE;
  1360. break;
  1361. case SUBMATCH:
  1362. if (test->result_str)
  1363. {
  1364. if (strstr(test->result_str,vector[1]) != NULL)
  1365. pass = TRUE;
  1366. }
  1367. else
  1368. pass = FALSE;
  1369. break;
  1370. case FULLMATCH:
  1371. if (test->result_str)
  1372. {
  1373. if (g_ascii_strcasecmp(test->result_str,vector[1]) == 0)
  1374. pass = TRUE;
  1375. }
  1376. else
  1377. pass = FALSE;
  1378. break;
  1379. case REGEX:
  1380. if (test->result_str)
  1381. {
  1382. if (g_regex_match_simple(vector[1],
  1383. test->result_str,
  1384. (GRegexCompileFlags)0,
  1385. (GRegexMatchFlags)0))
  1386. pass = TRUE;
  1387. }
  1388. else
  1389. pass = FALSE;
  1390. break;
  1391. default:
  1392. pass=FALSE;
  1393. }
  1394. g_strfreev(vector);
  1395. if (pass == TRUE)
  1396. continue;
  1397. else
  1398. {
  1399. MTXDBG(INTERROGATOR,_("MISMATCH,\"%s\" is NOT a match...\n\n"),filename);
  1400. g_strfreev(match_on);
  1401. cfg_free(cfgfile);
  1402. EXIT();
  1403. return FALSE;
  1404. }
  1405. }
  1406. g_strfreev(match_on);
  1407. MTXDBG(INTERROGATOR,_("\"%s\" is a match for all conditions ...\n"),filename);
  1408. cfg_free(cfgfile);
  1409. EXIT();
  1410. return TRUE;
  1411. }
  1412. /*!
  1413. \brief destroys Array holding Detection_Test structures
  1414. \param tests is the pointer to the array to destroy
  1415. */
  1416. G_MODULE_EXPORT void free_tests_array(GArray *tests)
  1417. {
  1418. guint i = 0;
  1419. Detection_Test *test = NULL;
  1420. ENTER();
  1421. for (i=0;i<tests->len;i++)
  1422. {
  1423. test = g_array_index(tests,Detection_Test *,i);
  1424. if (test->test_name)
  1425. g_free(test->test_name);
  1426. if (test->test_desc)
  1427. g_free(test->test_desc);
  1428. if (test->actual_test)
  1429. g_free(test->actual_test);
  1430. if (test->result_str)
  1431. g_free(test->result_str);
  1432. if (test->send_buf)
  1433. g_free(test->send_buf);
  1434. g_free(test);
  1435. test = NULL;
  1436. }
  1437. g_array_free(tests,TRUE);
  1438. EXIT();
  1439. return;
  1440. }
  1441. /*!
  1442. \brief interrogate_error, dumps an error out to the error handling
  1443. based on passed string and numeric pararms
  1444. \param text is the text to display
  1445. \param num is the number to display
  1446. */
  1447. G_MODULE_EXPORT void interrogate_error(const gchar *text, gint num)
  1448. {
  1449. ENTER();
  1450. EXIT();
  1451. return;
  1452. }
  1453. /*!
  1454. \brief updates the interrogation gui with the text revision, signature
  1455. and ecu numerical revision
  1456. */
  1457. G_MODULE_EXPORT void update_interrogation_gui_pf(void)
  1458. {
  1459. GtkWidget *widget = NULL;
  1460. GtkAdjustment *adj = NULL;
  1461. Serial_Params *serial_params = NULL;
  1462. Firmware_Details *firmware = NULL;
  1463. ENTER();
  1464. serial_params = (Serial_Params *)DATA_GET(global_data,"serial_params");
  1465. firmware = (Firmware_Details *)DATA_GET(global_data,"firmware");
  1466. g_return_if_fail(serial_params);
  1467. g_return_if_fail(firmware);
  1468. widget = lookup_widget_f("read_wait_spin");
  1469. if (GTK_IS_SPIN_BUTTON(widget))
  1470. {
  1471. gfloat min = 0.0;
  1472. gfloat val = 0.0;
  1473. adj = gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(widget));
  1474. val = gtk_adjustment_get_value(adj);
  1475. if (firmware->capabilities & MS1)
  1476. {
  1477. min = 1000.0*(1.0/(960.0/(firmware->rtvars_size+2.0)));
  1478. min *= 1.2; /* Add 20% buffer */
  1479. }
  1480. else if (firmware->capabilities & PIS)
  1481. {
  1482. min = 1000.0*(1.0/(819.2/(firmware->rtvars_size+2.0)));
  1483. min *= 1.1; /* Add 10% buffer */
  1484. }
  1485. else
  1486. {
  1487. min = 1000.0*(1.0/(11520.0/(firmware->rtvars_size+5.0)));
  1488. min *= 1.2; /* Add 20% buffer */
  1489. if (min < 30)
  1490. min = 30;
  1491. }
  1492. if (val <= min)
  1493. {
  1494. /* Safety net */
  1495. val = min + 10;
  1496. serial_params->read_wait = (gint)val;
  1497. }
  1498. gtk_adjustment_set_lower(adj,min);
  1499. gtk_adjustment_set_value(adj,val);
  1500. gtk_spin_button_set_adjustment(GTK_SPIN_BUTTON(widget),adj);
  1501. }
  1502. if (firmware->TextVerVia)
  1503. io_cmd_f(firmware->TextVerVia,NULL);
  1504. if (firmware->NumVerVia)
  1505. io_cmd_f(firmware->NumVerVia,NULL);
  1506. if (firmware->SignatureVia)
  1507. io_cmd_f(firmware->SignatureVia,NULL);
  1508. EXIT();
  1509. return;
  1510. }
  1511. /*!
  1512. \brief initialize_page_params() creates and initializes the page_params
  1513. datastructure to sane defaults and returns it
  1514. \return a pointer to an initialized Page_Params structure
  1515. \see Page_Params
  1516. */
  1517. G_MODULE_EXPORT Page_Params * initialize_page_params(void)
  1518. {
  1519. Page_Params *page_params = NULL;
  1520. ENTER();
  1521. page_params = (Page_Params *)g_malloc0(sizeof(Page_Params));
  1522. page_params->length = 0;
  1523. page_params->spconfig_offset = -1;
  1524. EXIT();
  1525. return page_params;
  1526. }
  1527. /*!
  1528. \brief initialize_table_params() creates and initializes the Table_Params
  1529. datastructure to sane defaults and returns it
  1530. \return a pointer to an initialized Table_Params structure
  1531. \see Table_Params
  1532. */
  1533. G_MODULE_EXPORT Table_Params * initialize_table_params(void)
  1534. {
  1535. Table_Params *table_params = NULL;
  1536. ENTER();
  1537. table_params = (Table_Params *)g_malloc0(sizeof(Table_Params));
  1538. table_params->is_fuel = FALSE;
  1539. table_params->alternate_offset = -1;
  1540. table_params->divider_offset = -1;
  1541. table_params->rpmk_offset = -1;
  1542. table_params->reqfuel_offset = -1;
  1543. table_params->x_page = -1;
  1544. table_params->y_page = -1;
  1545. table_params->z_page = -1;
  1546. table_params->x_base = -1;
  1547. table_params->y_base = -1;
  1548. table_params->z_base = -1;
  1549. table_params->x_bincount = -1;
  1550. table_params->y_bincount = -1;
  1551. table_params->x_precision = 0;
  1552. table_params->y_precision = 0;
  1553. table_params->z_precision = 0;
  1554. table_params->bind_to_list = NULL;
  1555. table_params->x_suffix = NULL;
  1556. table_params->y_suffix = NULL;
  1557. table_params->z_suffix = NULL;
  1558. table_params->x_fromecu_mults = NULL;
  1559. table_params->y_fromecu_mults = NULL;
  1560. table_params->z_fromecu_mults = NULL;
  1561. table_params->x_fromecu_adds = NULL;
  1562. table_params->y_fromecu_adds = NULL;
  1563. table_params->z_fromecu_adds = NULL;
  1564. table_params->x_source_key = NULL;
  1565. table_params->y_source_key = NULL;
  1566. table_params->z_source_key = NULL;
  1567. table_params->table_name = NULL;
  1568. table_params->x_ul_eval = NULL;
  1569. table_params->y_ul_eval = NULL;
  1570. table_params->z_ul_eval = NULL;
  1571. table_params->x_dl_eval = NULL;
  1572. table_params->y_dl_eval = NULL;
  1573. table_params->z_dl_eval = NULL;
  1574. table_params->x_multi_hash = NULL;
  1575. table_params->y_multi_hash = NULL;
  1576. table_params->z_multi_hash = NULL;
  1577. table_params->x_multi_source = FALSE;
  1578. table_params->y_multi_source = FALSE;
  1579. table_params->z_multi_source = FALSE;
  1580. EXIT();
  1581. return table_params;
  1582. }
  1583. /*!
  1584. \brief initialize_te_params() creates and initializes the TE_Params
  1585. datastructure to sane defaults and returns it
  1586. \return a pointer to an initialized TE_Params structure
  1587. \see TE_Params
  1588. */
  1589. G_MODULE_EXPORT TE_Params * initialize_te_params(void)
  1590. {
  1591. TE_Params *te_params = NULL;
  1592. ENTER();
  1593. te_params = (TE_Params *)g_malloc0(sizeof(TE_Params));
  1594. te_params->x_lock = FALSE;
  1595. te_params->y_lock = FALSE;
  1596. te_params->x_use_color = FALSE;
  1597. te_params->y_use_color = FALSE;
  1598. te_params->x_temp_dep = FALSE;
  1599. te_params->y_temp_dep = FALSE;
  1600. te_params->x_page = -1;
  1601. te_params->y_page = -1;
  1602. te_params->x_base = -1;
  1603. te_params->y_base = -1;
  1604. te_params->reversed = FALSE;
  1605. te_params->bincount = -1;
  1606. te_params->x_precision = 0;
  1607. te_params->y_precision = 0;
  1608. te_params->x_axis_label = NULL;
  1609. te_params->y_axis_label = NULL;
  1610. te_params->x_name = NULL;
  1611. te_params->y_name = NULL;
  1612. te_params->x_units = NULL;
  1613. te_params->y_units = NULL;
  1614. te_params->x_fromecu_mult = NULL;
  1615. te_params->x_fromecu_add = NULL;
  1616. te_params->y_fromecu_mult = NULL;
  1617. te_params->y_fromecu_add = NULL;
  1618. te_params->gauge_temp_dep = FALSE;
  1619. te_params->title = NULL;
  1620. EXIT();
  1621. return te_params;
  1622. }