PrusaStatistics_test.cpp 16 KB

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