|
| 1 | +/** |
| 2 | + * @file |
| 3 | + * @author Marek Kuhn |
| 4 | + */ |
| 5 | + |
| 6 | +// For now the functions are just COPIED (lots of depencendies in ultralcd.h) |
| 7 | + |
| 8 | +#include "catch.hpp" |
| 9 | +#include <iostream> |
| 10 | + |
| 11 | +// Mocking Serial line |
| 12 | +std::string SERIAL_BUFFER = ""; |
| 13 | + |
| 14 | +//#define SERIAL_ECHO(s) ( SERIAL_BUFFER += s ) |
| 15 | +/* |
| 16 | +#define SERIAL_FLUSH() ( SERIAL_BUFFER.clear() ) |
| 17 | +#define SERIAL_ECHOLN(s) { \ |
| 18 | + SERIAL_ECHO(s); \ |
| 19 | + SERIAL_BUFFER += "\n"; \ |
| 20 | +} |
| 21 | +*/ |
| 22 | +void SERIAL_ECHO(std::string s){ |
| 23 | + SERIAL_BUFFER += s; |
| 24 | +} |
| 25 | + |
| 26 | +void SERIAL_ECHO(int i){ |
| 27 | + SERIAL_BUFFER += std::to_string(i); |
| 28 | +} |
| 29 | + |
| 30 | +void SERIAL_ECHOLN(std::string s){ |
| 31 | + SERIAL_BUFFER += s + "\n"; |
| 32 | +} |
| 33 | + |
| 34 | +void SERIAL_FLUSH(){ |
| 35 | + SERIAL_BUFFER.clear(); |
| 36 | +} |
| 37 | + |
| 38 | +std::string itostr3(int i){ |
| 39 | + return std::to_string(i); |
| 40 | +} |
| 41 | + |
| 42 | +int _millis(){return 10000;} |
| 43 | + |
| 44 | +int farm_no; |
| 45 | +int busy_state; |
| 46 | +int PAUSED_FOR_USER; |
| 47 | +int status_number; |
| 48 | +int total_filament_used; |
| 49 | +int feedmultiply; |
| 50 | +int longFilenameOLD; |
| 51 | +int starttime; |
| 52 | + |
| 53 | +int target_temperature[1] = {215}; |
| 54 | +int current_temperature[1] = {204}; |
| 55 | +int target_temperature_bed = 60; |
| 56 | +int current_temperature_bed = 55; |
| 57 | + |
| 58 | +std::string FW_VERSION; |
| 59 | + |
| 60 | +struct Card { |
| 61 | + int percentDone(){ return 50; } |
| 62 | +} card; |
| 63 | + |
| 64 | +void setup_mockups(){ |
| 65 | + farm_no = 0; |
| 66 | + |
| 67 | + busy_state = 0; |
| 68 | + status_number = 0; |
| 69 | + PAUSED_FOR_USER = 0; |
| 70 | + |
| 71 | + total_filament_used = 0; |
| 72 | + feedmultiply = 0; |
| 73 | + longFilenameOLD = 0; |
| 74 | + starttime = 0; |
| 75 | + |
| 76 | + FW_VERSION = "3.8.0"; |
| 77 | +} |
| 78 | + |
| 79 | +/* |
| 80 | +void prusa_statistics(int _message, uint8_t _fil_nr) { |
| 81 | +#ifdef DEBUG_DISABLE_PRUSA_STATISTICS |
| 82 | + return; |
| 83 | +#endif //DEBUG_DISABLE_PRUSA_STATISTICS |
| 84 | + switch (_message) |
| 85 | + { |
| 86 | +
|
| 87 | + case 0: // default message |
| 88 | + if (busy_state == PAUSED_FOR_USER) |
| 89 | + { |
| 90 | + SERIAL_ECHO("{"); |
| 91 | + prusa_stat_printerstatus(15); |
| 92 | + prusa_stat_farm_number(); |
| 93 | + prusa_stat_printinfo(); |
| 94 | + SERIAL_ECHOLN("}"); |
| 95 | + status_number = 15; |
| 96 | + } |
| 97 | + else if (isPrintPaused || card.paused) |
| 98 | + { |
| 99 | + SERIAL_ECHO("{"); |
| 100 | + prusa_stat_printerstatus(14); |
| 101 | + prusa_stat_farm_number(); |
| 102 | + prusa_stat_printinfo(); |
| 103 | + SERIAL_ECHOLN("}"); |
| 104 | + status_number = 14; |
| 105 | + } |
| 106 | + else if (IS_SD_PRINTING) |
| 107 | + { |
| 108 | + SERIAL_ECHO("{"); |
| 109 | + prusa_stat_printerstatus(4); |
| 110 | + prusa_stat_farm_number(); |
| 111 | + prusa_stat_printinfo(); |
| 112 | + SERIAL_ECHOLN("}"); |
| 113 | + status_number = 4; |
| 114 | + } |
| 115 | + else |
| 116 | + { |
| 117 | + SERIAL_ECHO("{"); |
| 118 | + prusa_stat_printerstatus(1); |
| 119 | + prusa_stat_farm_number(); |
| 120 | + SERIAL_ECHOLN("}"); |
| 121 | + status_number = 1; |
| 122 | + } |
| 123 | + break; |
| 124 | +
|
| 125 | + case 1: // 1 heating |
| 126 | + farm_status = 2; |
| 127 | + SERIAL_ECHO("{"); |
| 128 | + prusa_stat_printerstatus(2); |
| 129 | + prusa_stat_farm_number(); |
| 130 | + SERIAL_ECHOLN("}"); |
| 131 | + status_number = 2; |
| 132 | + farm_timer = 1; |
| 133 | + break; |
| 134 | +
|
| 135 | + case 2: // heating done |
| 136 | + farm_status = 3; |
| 137 | + SERIAL_ECHO("{"); |
| 138 | + prusa_stat_printerstatus(3); |
| 139 | + prusa_stat_farm_number(); |
| 140 | + SERIAL_ECHOLN("}"); |
| 141 | + status_number = 3; |
| 142 | + farm_timer = 1; |
| 143 | +
|
| 144 | + if (IS_SD_PRINTING) |
| 145 | + { |
| 146 | + farm_status = 4; |
| 147 | + SERIAL_ECHO("{"); |
| 148 | + prusa_stat_printerstatus(4); |
| 149 | + prusa_stat_farm_number(); |
| 150 | + SERIAL_ECHOLN("}"); |
| 151 | + status_number = 4; |
| 152 | + } |
| 153 | + else |
| 154 | + { |
| 155 | + SERIAL_ECHO("{"); |
| 156 | + prusa_stat_printerstatus(3); |
| 157 | + prusa_stat_farm_number(); |
| 158 | + SERIAL_ECHOLN("}"); |
| 159 | + status_number = 3; |
| 160 | + } |
| 161 | + farm_timer = 1; |
| 162 | + break; |
| 163 | +
|
| 164 | + case 3: // filament change |
| 165 | +
|
| 166 | + break; |
| 167 | + case 4: // print succesfull |
| 168 | + SERIAL_ECHO("{[RES:1][FIL:"); |
| 169 | + MYSERIAL.print(int(_fil_nr)); |
| 170 | + SERIAL_ECHO("]"); |
| 171 | + prusa_stat_printerstatus(status_number); |
| 172 | + prusa_stat_farm_number(); |
| 173 | + SERIAL_ECHOLN("}"); |
| 174 | + farm_timer = 2; |
| 175 | + break; |
| 176 | + case 5: // print not succesfull |
| 177 | + SERIAL_ECHO("{[RES:0][FIL:"); |
| 178 | + MYSERIAL.print(int(_fil_nr)); |
| 179 | + SERIAL_ECHO("]"); |
| 180 | + prusa_stat_printerstatus(status_number); |
| 181 | + prusa_stat_farm_number(); |
| 182 | + SERIAL_ECHOLN("}"); |
| 183 | + farm_timer = 2; |
| 184 | + break; |
| 185 | + case 6: // print done |
| 186 | + SERIAL_ECHO("{[PRN:8]"); |
| 187 | + prusa_stat_farm_number(); |
| 188 | + SERIAL_ECHOLN("}"); |
| 189 | + status_number = 8; |
| 190 | + farm_timer = 2; |
| 191 | + break; |
| 192 | + case 7: // print done - stopped |
| 193 | + SERIAL_ECHO("{[PRN:9]"); |
| 194 | + prusa_stat_farm_number(); |
| 195 | + SERIAL_ECHOLN("}"); |
| 196 | + status_number = 9; |
| 197 | + farm_timer = 2; |
| 198 | + break; |
| 199 | + case 8: // printer started |
| 200 | + SERIAL_ECHO("{[PRN:0][PFN:"); |
| 201 | + status_number = 0; |
| 202 | + SERIAL_ECHO(farm_no); |
| 203 | + SERIAL_ECHOLN("]}"); |
| 204 | + farm_timer = 2; |
| 205 | + break; |
| 206 | + case 20: // echo farm no |
| 207 | + SERIAL_ECHO("{"); |
| 208 | + prusa_stat_printerstatus(status_number); |
| 209 | + prusa_stat_farm_number(); |
| 210 | + SERIAL_ECHOLN("}"); |
| 211 | + farm_timer = 4; |
| 212 | + break; |
| 213 | + case 21: // temperatures |
| 214 | + SERIAL_ECHO("{"); |
| 215 | + prusa_stat_temperatures(); |
| 216 | + prusa_stat_farm_number(); |
| 217 | + prusa_stat_printerstatus(status_number); |
| 218 | + SERIAL_ECHOLN("}"); |
| 219 | + break; |
| 220 | + case 22: // waiting for filament change |
| 221 | + SERIAL_ECHO("{[PRN:5]"); |
| 222 | + prusa_stat_farm_number(); |
| 223 | + SERIAL_ECHOLN("}"); |
| 224 | + status_number = 5; |
| 225 | + break; |
| 226 | + |
| 227 | + case 90: // Error - Thermal Runaway |
| 228 | + SERIAL_ECHO("{[ERR:1]"); |
| 229 | + prusa_stat_farm_number(); |
| 230 | + SERIAL_ECHOLN("}"); |
| 231 | + break; |
| 232 | + case 91: // Error - Thermal Runaway Preheat |
| 233 | + SERIAL_ECHO("{[ERR:2]"); |
| 234 | + prusa_stat_farm_number(); |
| 235 | + SERIAL_ECHOLN("}"); |
| 236 | + break; |
| 237 | + case 92: // Error - Min temp |
| 238 | + SERIAL_ECHO("{[ERR:3]"); |
| 239 | + prusa_stat_farm_number(); |
| 240 | + SERIAL_ECHOLN("}"); |
| 241 | + break; |
| 242 | + case 93: // Error - Max temp |
| 243 | + SERIAL_ECHO("{[ERR:4]"); |
| 244 | + prusa_stat_farm_number(); |
| 245 | + SERIAL_ECHOLN("}"); |
| 246 | + break; |
| 247 | +
|
| 248 | + case 99: // heartbeat |
| 249 | + SERIAL_ECHO("{[PRN:99]"); |
| 250 | + prusa_stat_temperatures(); |
| 251 | + SERIAL_ECHO("[PFN:"); |
| 252 | + SERIAL_ECHO(farm_no); |
| 253 | + SERIAL_ECHO("]"); |
| 254 | + SERIAL_ECHOLN("}"); |
| 255 | + |
| 256 | + break; |
| 257 | + } |
| 258 | +
|
| 259 | +} |
| 260 | +*/ |
| 261 | +static void prusa_stat_printerstatus(int _status) |
| 262 | +{ |
| 263 | + SERIAL_ECHO("[PRN:"); |
| 264 | + SERIAL_ECHO(_status); |
| 265 | + SERIAL_ECHO("]"); |
| 266 | +} |
| 267 | + |
| 268 | +static void prusa_stat_farm_number() { |
| 269 | + SERIAL_ECHO("[PFN:"); |
| 270 | + SERIAL_ECHO(farm_no); |
| 271 | + SERIAL_ECHO("]"); |
| 272 | +} |
| 273 | + |
| 274 | +static void prusa_stat_temperatures() |
| 275 | +{ |
| 276 | + SERIAL_ECHO("[ST0:"); |
| 277 | + SERIAL_ECHO(target_temperature[0]); |
| 278 | + SERIAL_ECHO("][STB:"); |
| 279 | + SERIAL_ECHO(target_temperature_bed); |
| 280 | + SERIAL_ECHO("][AT0:"); |
| 281 | + SERIAL_ECHO(current_temperature[0]); |
| 282 | + SERIAL_ECHO("][ATB:"); |
| 283 | + SERIAL_ECHO(current_temperature_bed); |
| 284 | + SERIAL_ECHO("]"); |
| 285 | +} |
| 286 | + |
| 287 | +static void prusa_stat_printinfo() |
| 288 | +{ |
| 289 | + SERIAL_ECHO("[TFU:"); |
| 290 | + SERIAL_ECHO(total_filament_used); |
| 291 | + SERIAL_ECHO("][PCD:"); |
| 292 | + SERIAL_ECHO(itostr3(card.percentDone())); |
| 293 | + SERIAL_ECHO("][FEM:"); |
| 294 | + SERIAL_ECHO(itostr3(feedmultiply)); |
| 295 | + SERIAL_ECHO("][FNM:"); |
| 296 | + SERIAL_ECHO(longFilenameOLD); |
| 297 | + SERIAL_ECHO("][TIM:"); |
| 298 | + if (starttime != 0) |
| 299 | + { |
| 300 | + SERIAL_ECHO(_millis() / 1000 - starttime / 1000); |
| 301 | + } |
| 302 | + else |
| 303 | + { |
| 304 | + SERIAL_ECHO(0); |
| 305 | + } |
| 306 | + SERIAL_ECHO("][FWR:"); |
| 307 | + SERIAL_ECHO(FW_VERSION); |
| 308 | + SERIAL_ECHO("]"); |
| 309 | +} |
| 310 | + |
| 311 | + |
| 312 | +TEST_CASE("Printer status is shown", "[prusa_stats]") |
| 313 | +{ |
| 314 | + SERIAL_FLUSH(); |
| 315 | + prusa_stat_printerstatus(1); |
| 316 | + CHECK(SERIAL_BUFFER.compare("[PRN:1]") == 0); |
| 317 | +} |
| 318 | + |
| 319 | +TEST_CASE("Printer info is showsn", "[prusa_stats]") |
| 320 | +{ |
| 321 | + SERIAL_FLUSH(); |
| 322 | + setup_mockups(); |
| 323 | + prusa_stat_printinfo(); |
| 324 | + CHECK(SERIAL_BUFFER.compare("[TFU:0][PCD:50][FEM:0][FNM:0][TIM:0][FWR:3.8.0]") == 0); |
| 325 | +} |
| 326 | + |
| 327 | +TEST_CASE("Printer temperatures are shown", "[prusa_stats]") |
| 328 | +{ |
| 329 | + SERIAL_FLUSH(); |
| 330 | + setup_mockups(); |
| 331 | + prusa_stat_temperatures(); |
| 332 | + CHECK(SERIAL_BUFFER.compare("[ST0:215][STB:60][AT0:204][ATB:55]") == 0); |
| 333 | +} |
| 334 | + |
| 335 | +TEST_CASE("Prusa_statistics Paused test", "[prusa_stats]") |
| 336 | +{ |
| 337 | + |
| 338 | + |
| 339 | + CHECK(1 == 1); |
| 340 | +} |
0 commit comments