PrusaStatistics_test.cpp 16 KB

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