PrusaStatistics_test.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777
  1. /**
  2. * @file
  3. * @author Marek Kuhn
  4. */
  5. // For now the functions are just COPIED (lots of depencendies in ultralcd.h)
  6. #include "catch.hpp"
  7. #include <iostream>
  8. std::string itostr3(int i){
  9. return std::to_string(i);
  10. }
  11. std::string eeprom_read_word(uint16_t* i){
  12. return "eeprom_read";
  13. }
  14. int _millis(){return 10000;}
  15. int farm_no;
  16. int busy_state;
  17. int PAUSED_FOR_USER;
  18. int status_number;
  19. int total_filament_used;
  20. int feedmultiply;
  21. int longFilenameOLD;
  22. int starttime;
  23. int isPrintPaused;
  24. int IS_SD_PRINTING;
  25. int farm_status;
  26. int farm_timer;
  27. int loading_flag;
  28. int target_temperature[1];
  29. int current_temperature[1];
  30. int target_temperature_bed;
  31. int current_temperature_bed;
  32. uint16_t nozzle_diameter;
  33. uint16_t* EEPROM_NOZZLE_DIAMETER_uM;
  34. std::string FW_VERSION;
  35. struct Card {
  36. int paused = 0;
  37. int percentDone(){ return 50; }
  38. } card;
  39. void setup_mockups(){
  40. farm_no = 0;
  41. busy_state = 0;
  42. status_number = 0;
  43. PAUSED_FOR_USER = 0;
  44. total_filament_used = 0;
  45. feedmultiply = 0;
  46. longFilenameOLD = 0;
  47. starttime = 0;
  48. FW_VERSION = "3.8.0";
  49. isPrintPaused = 0;
  50. IS_SD_PRINTING = 0;
  51. farm_status = 0;
  52. farm_timer = 1;
  53. loading_flag = 0;
  54. target_temperature[0] = {215};
  55. current_temperature[0] = {204};
  56. target_temperature_bed = 60;
  57. current_temperature_bed = 55;
  58. nozzle_diameter = 400;
  59. EEPROM_NOZZLE_DIAMETER_uM = &nozzle_diameter;
  60. }
  61. // Copy of pre 3.8 version set of functions
  62. namespace old_code
  63. {
  64. // Mocking Serial line
  65. std::string SERIAL_BUFFER = "";
  66. void SERIAL_ECHO(std::string s){
  67. SERIAL_BUFFER += s;
  68. }
  69. void SERIAL_ECHO(int i){
  70. SERIAL_BUFFER += std::to_string(i);
  71. }
  72. void SERIAL_ECHO(char c){
  73. SERIAL_BUFFER += char(c);
  74. }
  75. void SERIAL_ECHOLN(std::string s){
  76. SERIAL_BUFFER += s + "\n";
  77. }
  78. void SERIAL_ECHOLN(char c){
  79. SERIAL_BUFFER += char(c);
  80. }
  81. void SERIAL_RESET(){
  82. SERIAL_BUFFER.clear();
  83. }
  84. struct MySerial {
  85. void print(int i){
  86. SERIAL_ECHO(i);
  87. }
  88. } MYSERIAL;
  89. static void prusa_stat_printerstatus(int _status)
  90. {
  91. SERIAL_ECHO("[PRN:");
  92. SERIAL_ECHO(_status);
  93. SERIAL_ECHO("]");
  94. }
  95. static void prusa_stat_farm_number() {
  96. SERIAL_ECHO("[PFN:");
  97. SERIAL_ECHO(farm_no);
  98. SERIAL_ECHO("]");
  99. }
  100. static void prusa_stat_diameter() {
  101. SERIAL_ECHO("[DIA:");
  102. SERIAL_ECHO(eeprom_read_word((uint16_t*)EEPROM_NOZZLE_DIAMETER_uM));
  103. SERIAL_ECHO("]");
  104. }
  105. static void prusa_stat_temperatures()
  106. {
  107. SERIAL_ECHO("[ST0:");
  108. SERIAL_ECHO(target_temperature[0]);
  109. SERIAL_ECHO("][STB:");
  110. SERIAL_ECHO(target_temperature_bed);
  111. SERIAL_ECHO("][AT0:");
  112. SERIAL_ECHO(current_temperature[0]);
  113. SERIAL_ECHO("][ATB:");
  114. SERIAL_ECHO(current_temperature_bed);
  115. SERIAL_ECHO("]");
  116. }
  117. static void prusa_stat_printinfo()
  118. {
  119. SERIAL_ECHO("[TFU:");
  120. SERIAL_ECHO(total_filament_used);
  121. SERIAL_ECHO("][PCD:");
  122. SERIAL_ECHO(itostr3(card.percentDone()));
  123. SERIAL_ECHO("][FEM:");
  124. SERIAL_ECHO(itostr3(feedmultiply));
  125. SERIAL_ECHO("][FNM:");
  126. SERIAL_ECHO(longFilenameOLD);
  127. SERIAL_ECHO("][TIM:");
  128. if (starttime != 0)
  129. {
  130. SERIAL_ECHO(_millis() / 1000 - starttime / 1000);
  131. }
  132. else
  133. {
  134. SERIAL_ECHO(0);
  135. }
  136. SERIAL_ECHO("][FWR:");
  137. SERIAL_ECHO(FW_VERSION);
  138. SERIAL_ECHO("]");
  139. prusa_stat_diameter();
  140. }
  141. void prusa_statistics(int _message, uint8_t _fil_nr) {
  142. #ifdef DEBUG_DISABLE_PRUSA_STATISTICS
  143. return;
  144. #endif //DEBUG_DISABLE_PRUSA_STATISTICS
  145. switch (_message)
  146. {
  147. case 0: // default message
  148. if (busy_state == PAUSED_FOR_USER)
  149. {
  150. SERIAL_ECHO("{");
  151. prusa_stat_printerstatus(15);
  152. prusa_stat_farm_number();
  153. prusa_stat_printinfo();
  154. SERIAL_ECHOLN("}");
  155. status_number = 15;
  156. }
  157. else if (isPrintPaused || card.paused)
  158. {
  159. SERIAL_ECHO("{");
  160. prusa_stat_printerstatus(14);
  161. prusa_stat_farm_number();
  162. prusa_stat_printinfo();
  163. SERIAL_ECHOLN("}");
  164. status_number = 14;
  165. }
  166. else if (IS_SD_PRINTING || loading_flag)
  167. {
  168. SERIAL_ECHO("{");
  169. prusa_stat_printerstatus(4);
  170. prusa_stat_farm_number();
  171. prusa_stat_printinfo();
  172. SERIAL_ECHOLN("}");
  173. status_number = 4;
  174. }
  175. else
  176. {
  177. SERIAL_ECHO("{");
  178. prusa_stat_printerstatus(1);
  179. prusa_stat_farm_number();
  180. prusa_stat_diameter();
  181. SERIAL_ECHOLN("}");
  182. status_number = 1;
  183. }
  184. break;
  185. case 1: // 1 heating
  186. farm_status = 2;
  187. SERIAL_ECHO("{");
  188. prusa_stat_printerstatus(2);
  189. prusa_stat_farm_number();
  190. SERIAL_ECHOLN("}");
  191. status_number = 2;
  192. farm_timer = 1;
  193. break;
  194. case 2: // heating done
  195. farm_status = 3;
  196. SERIAL_ECHO("{");
  197. prusa_stat_printerstatus(3);
  198. prusa_stat_farm_number();
  199. SERIAL_ECHOLN("}");
  200. status_number = 3;
  201. farm_timer = 1;
  202. if (IS_SD_PRINTING || loading_flag)
  203. {
  204. farm_status = 4;
  205. SERIAL_ECHO("{");
  206. prusa_stat_printerstatus(4);
  207. prusa_stat_farm_number();
  208. SERIAL_ECHOLN("}");
  209. status_number = 4;
  210. }
  211. else
  212. {
  213. SERIAL_ECHO("{");
  214. prusa_stat_printerstatus(3);
  215. prusa_stat_farm_number();
  216. SERIAL_ECHOLN("}");
  217. status_number = 3;
  218. }
  219. farm_timer = 1;
  220. break;
  221. case 3: // filament change
  222. break;
  223. case 4: // print succesfull
  224. SERIAL_ECHO("{[RES:1][FIL:");
  225. MYSERIAL.print(int(_fil_nr));
  226. SERIAL_ECHO("]");
  227. prusa_stat_printerstatus(status_number);
  228. prusa_stat_farm_number();
  229. SERIAL_ECHOLN("}");
  230. farm_timer = 2;
  231. break;
  232. case 5: // print not succesfull
  233. SERIAL_ECHO("{[RES:0][FIL:");
  234. MYSERIAL.print(int(_fil_nr));
  235. SERIAL_ECHO("]");
  236. prusa_stat_printerstatus(status_number);
  237. prusa_stat_farm_number();
  238. SERIAL_ECHOLN("}");
  239. farm_timer = 2;
  240. break;
  241. case 6: // print done
  242. SERIAL_ECHO("{[PRN:8]");
  243. prusa_stat_farm_number();
  244. SERIAL_ECHOLN("}");
  245. status_number = 8;
  246. farm_timer = 2;
  247. break;
  248. case 7: // print done - stopped
  249. SERIAL_ECHO("{[PRN:9]");
  250. prusa_stat_farm_number();
  251. SERIAL_ECHOLN("}");
  252. status_number = 9;
  253. farm_timer = 2;
  254. break;
  255. case 8: // printer started
  256. SERIAL_ECHO("{[PRN:0][PFN:");
  257. status_number = 0;
  258. SERIAL_ECHO(farm_no);
  259. SERIAL_ECHOLN("]}");
  260. farm_timer = 2;
  261. break;
  262. case 20: // echo farm no
  263. SERIAL_ECHO("{");
  264. prusa_stat_printerstatus(status_number);
  265. prusa_stat_farm_number();
  266. SERIAL_ECHOLN("}");
  267. farm_timer = 4;
  268. break;
  269. case 21: // temperatures
  270. SERIAL_ECHO("{");
  271. prusa_stat_temperatures();
  272. prusa_stat_farm_number();
  273. prusa_stat_printerstatus(status_number);
  274. SERIAL_ECHOLN("}");
  275. break;
  276. case 22: // waiting for filament change
  277. SERIAL_ECHO("{[PRN:5]");
  278. prusa_stat_farm_number();
  279. SERIAL_ECHOLN("}");
  280. status_number = 5;
  281. break;
  282. case 90: // Error - Thermal Runaway
  283. SERIAL_ECHO("{[ERR:1]");
  284. prusa_stat_farm_number();
  285. SERIAL_ECHOLN("}");
  286. break;
  287. case 91: // Error - Thermal Runaway Preheat
  288. SERIAL_ECHO("{[ERR:2]");
  289. prusa_stat_farm_number();
  290. SERIAL_ECHOLN("}");
  291. break;
  292. case 92: // Error - Min temp
  293. SERIAL_ECHO("{[ERR:3]");
  294. prusa_stat_farm_number();
  295. SERIAL_ECHOLN("}");
  296. break;
  297. case 93: // Error - Max temp
  298. SERIAL_ECHO("{[ERR:4]");
  299. prusa_stat_farm_number();
  300. SERIAL_ECHOLN("}");
  301. break;
  302. case 99: // heartbeat
  303. SERIAL_ECHO("{[PRN:99]");
  304. prusa_stat_temperatures();
  305. SERIAL_ECHO("[PFN:");
  306. SERIAL_ECHO(farm_no);
  307. SERIAL_ECHO("]");
  308. SERIAL_ECHOLN("}");
  309. break;
  310. }
  311. }
  312. }
  313. // Copy of 3.8 version of functions
  314. namespace new_code
  315. {
  316. // Mocking Serial line
  317. std::string SERIAL_BUFFER = "";
  318. void SERIAL_ECHO(std::string s){
  319. SERIAL_BUFFER += s;
  320. }
  321. void SERIAL_ECHO(int i){
  322. SERIAL_BUFFER += std::to_string(i);
  323. }
  324. void SERIAL_ECHO(char c){
  325. SERIAL_BUFFER += char(c);
  326. }
  327. void SERIAL_ECHOLN(std::string s){
  328. SERIAL_BUFFER += s + "\n";
  329. }
  330. void SERIAL_ECHOLN(char c){
  331. SERIAL_BUFFER += char(c);
  332. }
  333. void SERIAL_RESET(){
  334. SERIAL_BUFFER.clear();
  335. }
  336. struct MySerial {
  337. void print(int i){
  338. SERIAL_ECHO(i);
  339. }
  340. } MYSERIAL;
  341. static void prusa_stat_printerstatus(int _status)
  342. {
  343. SERIAL_ECHO("[PRN:");
  344. SERIAL_ECHO(_status);
  345. SERIAL_ECHO(']');
  346. }
  347. static void prusa_stat_farm_number() {
  348. SERIAL_ECHO("[PFN:");
  349. SERIAL_ECHO(farm_no);
  350. SERIAL_ECHO(']');
  351. }
  352. static void prusa_stat_diameter() {
  353. SERIAL_ECHO("[DIA:");
  354. SERIAL_ECHO(eeprom_read_word((uint16_t*)EEPROM_NOZZLE_DIAMETER_uM));
  355. SERIAL_ECHO(']');
  356. }
  357. static void prusa_stat_temperatures()
  358. {
  359. SERIAL_ECHO("[ST0:");
  360. SERIAL_ECHO(target_temperature[0]);
  361. SERIAL_ECHO("][STB:");
  362. SERIAL_ECHO(target_temperature_bed);
  363. SERIAL_ECHO("][AT0:");
  364. SERIAL_ECHO(current_temperature[0]);
  365. SERIAL_ECHO("][ATB:");
  366. SERIAL_ECHO(current_temperature_bed);
  367. SERIAL_ECHO(']');
  368. }
  369. static void prusa_stat_printinfo()
  370. {
  371. SERIAL_ECHO("[TFU:");
  372. SERIAL_ECHO(total_filament_used);
  373. SERIAL_ECHO("][PCD:");
  374. SERIAL_ECHO(itostr3(card.percentDone()));
  375. SERIAL_ECHO("][FEM:");
  376. SERIAL_ECHO(itostr3(feedmultiply));
  377. SERIAL_ECHO("][FNM:");
  378. SERIAL_ECHO(longFilenameOLD);
  379. SERIAL_ECHO("][TIM:");
  380. if (starttime != 0)
  381. {
  382. SERIAL_ECHO(_millis() / 1000 - starttime / 1000);
  383. }
  384. else
  385. {
  386. SERIAL_ECHO(0);
  387. }
  388. SERIAL_ECHO("][FWR:");
  389. SERIAL_ECHO(FW_VERSION);
  390. SERIAL_ECHO(']');
  391. prusa_stat_diameter();
  392. }
  393. void prusa_statistics_err(char c){
  394. SERIAL_ECHO("{[ERR:");
  395. SERIAL_ECHO(c);
  396. SERIAL_ECHO(']');
  397. prusa_stat_farm_number();
  398. }
  399. void prusa_statistics(int _message, uint8_t _fil_nr) {
  400. #ifdef DEBUG_DISABLE_PRUSA_STATISTICS
  401. return;
  402. #endif //DEBUG_DISABLE_PRUSA_STATISTICS
  403. switch (_message)
  404. {
  405. case 0: // default message
  406. if (busy_state == PAUSED_FOR_USER)
  407. {
  408. status_number = 15;
  409. }
  410. else if (isPrintPaused || card.paused)
  411. {
  412. status_number = 14;
  413. }
  414. else if (IS_SD_PRINTING || loading_flag)
  415. {
  416. status_number = 4;
  417. }
  418. else
  419. {
  420. status_number = 1;
  421. }
  422. SERIAL_ECHO('{');
  423. prusa_stat_printerstatus(status_number);
  424. prusa_stat_farm_number();
  425. prusa_stat_printinfo();
  426. break;
  427. case 1: // 1 heating
  428. farm_status = 2;
  429. SERIAL_ECHO('{');
  430. prusa_stat_printerstatus(2);
  431. prusa_stat_farm_number();
  432. status_number = 2;
  433. farm_timer = 1;
  434. break;
  435. case 2: // heating done
  436. farm_status = 3;
  437. SERIAL_ECHO('{');
  438. prusa_stat_printerstatus(3);
  439. prusa_stat_farm_number();
  440. SERIAL_ECHOLN('}');
  441. status_number = 3;
  442. farm_timer = 1;
  443. if (IS_SD_PRINTING || loading_flag)
  444. {
  445. farm_status = 4;
  446. SERIAL_ECHO('{');
  447. prusa_stat_printerstatus(4);
  448. prusa_stat_farm_number();
  449. status_number = 4;
  450. }
  451. else
  452. {
  453. SERIAL_ECHO('{');
  454. prusa_stat_printerstatus(3);
  455. prusa_stat_farm_number();
  456. status_number = 3;
  457. }
  458. farm_timer = 1;
  459. break;
  460. case 3: // filament change
  461. // must do a return here to prevent doing SERIAL_ECHOLN("}") at the very end of this function
  462. // saved a considerable amount of FLASH
  463. return;
  464. break;
  465. case 4: // print succesfull
  466. SERIAL_ECHO("{[RES:1][FIL:");
  467. MYSERIAL.print(int(_fil_nr));
  468. SERIAL_ECHO(']');
  469. prusa_stat_printerstatus(status_number);
  470. prusa_stat_farm_number();
  471. farm_timer = 2;
  472. break;
  473. case 5: // print not succesfull
  474. SERIAL_ECHO("{[RES:0][FIL:");
  475. MYSERIAL.print(int(_fil_nr));
  476. SERIAL_ECHO(']');
  477. prusa_stat_printerstatus(status_number);
  478. prusa_stat_farm_number();
  479. farm_timer = 2;
  480. break;
  481. case 6: // print done
  482. SERIAL_ECHO("{[PRN:8]");
  483. prusa_stat_farm_number();
  484. status_number = 8;
  485. farm_timer = 2;
  486. break;
  487. case 7: // print done - stopped
  488. SERIAL_ECHO("{[PRN:9]");
  489. prusa_stat_farm_number();
  490. status_number = 9;
  491. farm_timer = 2;
  492. break;
  493. case 8: // printer started
  494. SERIAL_ECHO("{[PRN:0][PFN:");
  495. status_number = 0;
  496. SERIAL_ECHO(farm_no);
  497. SERIAL_ECHO(']');
  498. farm_timer = 2;
  499. break;
  500. case 20: // echo farm no
  501. SERIAL_ECHO('{');
  502. prusa_stat_printerstatus(status_number);
  503. prusa_stat_farm_number();
  504. farm_timer = 4;
  505. break;
  506. case 21: // temperatures
  507. SERIAL_ECHO('{');
  508. prusa_stat_temperatures();
  509. prusa_stat_farm_number();
  510. prusa_stat_printerstatus(status_number);
  511. break;
  512. case 22: // waiting for filament change
  513. SERIAL_ECHO("{[PRN:5]");
  514. prusa_stat_farm_number();
  515. status_number = 5;
  516. break;
  517. case 90: // Error - Thermal Runaway
  518. prusa_statistics_err('1');
  519. break;
  520. case 91: // Error - Thermal Runaway Preheat
  521. prusa_statistics_err('2');
  522. break;
  523. case 92: // Error - Min temp
  524. prusa_statistics_err('3');
  525. break;
  526. case 93: // Error - Max temp
  527. prusa_statistics_err('4');
  528. break;
  529. case 99: // heartbeat
  530. SERIAL_ECHO("{[PRN:99]");
  531. prusa_stat_temperatures();
  532. SERIAL_ECHO("[PFN:");
  533. SERIAL_ECHO(farm_no);
  534. SERIAL_ECHO(']');
  535. break;
  536. }
  537. SERIAL_ECHOLN('}');
  538. }
  539. } // end namespace new
  540. void SERIALS_RESET(){
  541. old_code::SERIAL_RESET();
  542. new_code::SERIAL_RESET();
  543. }
  544. std::string SERIALS_SERIALIZE(){
  545. return old_code::SERIAL_BUFFER + "\n" + new_code::SERIAL_BUFFER;
  546. }
  547. void SERIALS_PRINT(){
  548. std::cout << "[Printing buffers...] \n";
  549. std::cout << old_code::SERIAL_BUFFER << "\n";
  550. std::cout << new_code::SERIAL_BUFFER << "\n";
  551. }
  552. int SERIALS_COMPARE(){
  553. // Trim the newline at the end
  554. if(old_code::SERIAL_BUFFER.back() == '\n'){
  555. old_code::SERIAL_BUFFER.pop_back();
  556. }
  557. if(new_code::SERIAL_BUFFER.back() == '\n'){
  558. new_code::SERIAL_BUFFER.pop_back();
  559. }
  560. std::cout << "Comparing: \n";
  561. std::cout << old_code::SERIAL_BUFFER << "\n";
  562. std::cout << new_code::SERIAL_BUFFER << "\n";
  563. return old_code::SERIAL_BUFFER.compare(new_code::SERIAL_BUFFER);
  564. }
  565. // --------------- TEST CASES ---------------- //
  566. TEST_CASE("Serials compare ignore newline at the end", "[helper]")
  567. {
  568. SERIALS_RESET();
  569. old_code::SERIAL_BUFFER = "Hello compare me.";
  570. new_code::SERIAL_BUFFER = "Hello compare me.";
  571. CHECK(SERIALS_COMPARE() == 0);
  572. SERIALS_RESET();
  573. old_code::SERIAL_BUFFER = "Hello compare me.\n";
  574. new_code::SERIAL_BUFFER = "Hello compare me.";
  575. CHECK(SERIALS_COMPARE() == 0);
  576. SERIALS_RESET();
  577. old_code::SERIAL_BUFFER = "Hello compare me.";
  578. new_code::SERIAL_BUFFER = "Hello compare me.\n";
  579. CHECK(SERIALS_COMPARE() == 0);
  580. }
  581. TEST_CASE("Printer status is shown", "[prusa_stats]")
  582. {
  583. SERIALS_RESET();
  584. setup_mockups();
  585. old_code::prusa_stat_printerstatus(1);
  586. new_code::prusa_stat_printerstatus(1);
  587. INFO(SERIALS_SERIALIZE());
  588. CHECK(SERIALS_COMPARE() == 0);
  589. }
  590. TEST_CASE("Printer info is shown", "[prusa_stats]")
  591. {
  592. SERIALS_RESET();
  593. setup_mockups();
  594. old_code::prusa_stat_printinfo();
  595. new_code::prusa_stat_printinfo();
  596. INFO(SERIALS_SERIALIZE());
  597. CHECK(SERIALS_COMPARE() == 0);
  598. }
  599. TEST_CASE("Printer temperatures are shown", "[prusa_stats]")
  600. {
  601. SERIALS_RESET();
  602. setup_mockups();
  603. old_code::prusa_stat_temperatures();
  604. new_code::prusa_stat_temperatures();
  605. INFO(SERIALS_SERIALIZE());
  606. CHECK(SERIALS_COMPARE() == 0);
  607. }
  608. TEST_CASE("Prusa_statistics test", "[prusa_stats]")
  609. {
  610. SERIALS_RESET();
  611. setup_mockups();
  612. int test_codes[] = {0,1,2,3,4,5,6,7,8,20,21,22,90,91,92,93,99};
  613. int size = sizeof(test_codes)/sizeof(test_codes[0]);
  614. for(int i = 0; i < size; i++){
  615. std::cout << "Testing prusa_statistics(" << std::to_string(i) << ")\n";
  616. switch(i)
  617. {
  618. case 0: {
  619. busy_state = 0;
  620. PAUSED_FOR_USER = 0;
  621. old_code::prusa_statistics(test_codes[i],0);
  622. new_code::prusa_statistics(test_codes[i],0);
  623. CHECK(SERIALS_COMPARE() == 0);
  624. SERIALS_RESET();
  625. busy_state = 1;
  626. PAUSED_FOR_USER = 0;
  627. isPrintPaused = 1;
  628. old_code::prusa_statistics(test_codes[i],0);
  629. new_code::prusa_statistics(test_codes[i],0);
  630. CHECK(SERIALS_COMPARE() == 0);
  631. SERIALS_RESET();
  632. isPrintPaused = 0;
  633. card.paused = 0;
  634. IS_SD_PRINTING = 1;
  635. old_code::prusa_statistics(test_codes[i],0);
  636. new_code::prusa_statistics(test_codes[i],0);
  637. CHECK(SERIALS_COMPARE() == 0);
  638. SERIALS_RESET();
  639. busy_state = 1;
  640. PAUSED_FOR_USER = 0;
  641. isPrintPaused = 0;
  642. IS_SD_PRINTING = 0;
  643. loading_flag = 0;
  644. old_code::prusa_statistics(test_codes[i],0);
  645. new_code::prusa_statistics(test_codes[i],0);
  646. CHECK(SERIALS_COMPARE() == 0);
  647. SERIALS_RESET();
  648. break;
  649. }
  650. case 2: {
  651. IS_SD_PRINTING = 1;
  652. old_code::prusa_statistics(test_codes[i],0);
  653. new_code::prusa_statistics(test_codes[i],0);
  654. CHECK(SERIALS_COMPARE() == 0);
  655. SERIALS_RESET();
  656. IS_SD_PRINTING = 0;
  657. loading_flag = 0;
  658. old_code::prusa_statistics(test_codes[i],0);
  659. new_code::prusa_statistics(test_codes[i],0);
  660. CHECK(SERIALS_COMPARE() == 0);
  661. SERIALS_RESET();
  662. break;
  663. }
  664. default:{
  665. old_code::prusa_statistics(test_codes[i],0);
  666. new_code::prusa_statistics(test_codes[i],0);
  667. CHECK(SERIALS_COMPARE() == 0);
  668. SERIALS_RESET();
  669. }
  670. }
  671. }
  672. }