serialControl.ino 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. void serialEvent() {
  2. //bool doEval = false;
  3. while (Serial.available()) {
  4. char ch = Serial.read();
  5. cmdBuffer[cmdBufferCount] = ch;
  6. if ((ch == 13 || ch == 10)) { // ASCII code 13 = "CR", 10 = "LF"
  7. cmdBuffer[cmdBufferCount] = 0; // nullterminator
  8. //Serial.print("CR_ ");
  9. //Serial.print(cmdBuffer);
  10. //evalCmd();
  11. if (cmdBufferCount >= 1) evalCmd();
  12. else {
  13. cmdBufferCount = 0;
  14. for ( int i = 0; i < sizeof(cmdBuffer); ++i ) cmdBuffer[i] = (char)0;
  15. }
  16. }
  17. // else if (ch == 10 && cmdBufferCount > 1) { // ASCII code 10 = "LF"
  18. // cmdBuffer[cmdBufferCount] = 0; // nullterminator
  19. // //Serial.print("LF__ ");
  20. // //Serial.print(cmdBuffer);
  21. // //evalCmd();
  22. // doEval = true;
  23. // }
  24. else {
  25. cmdBufferCount++;
  26. }
  27. }
  28. }
  29. void evalCmd() {
  30. if (debug) {
  31. Serial.print("cmd: '");
  32. Serial.print(cmdBuffer);
  33. Serial.println("'");
  34. //Serial.println(strlen(cmdBuffer));
  35. }
  36. // begin commands
  37. if (strncmp(cmdBuffer, "ID", 2) == 0 && strlen(cmdBuffer) == 2) {
  38. Serial.print(PROJECT_NAME);
  39. Serial.print(" v");
  40. Serial.print(PROJECT_VERSION);
  41. Serial.println();
  42. }
  43. else if (strncmp(cmdBuffer, "get eeprom", 10) == 0 && strlen(cmdBuffer) == 10) {
  44. getEEPROMContent();
  45. }
  46. else if (strncmp(cmdBuffer, "save data", 9) == 0 && strlen(cmdBuffer) == 9) {
  47. saveAllCurrentData(false);
  48. }
  49. else if (strncmp(cmdBuffer, "debug 1", 7) == 0 && strlen(cmdBuffer) == 7) {
  50. debug = true;
  51. debuglevel = 1;
  52. byte tmpval = 1;
  53. Serial.println(F("DEBUG ENABLED"));
  54. EEPROM.put(eeprom_addr_debug, tmpval);
  55. }
  56. else if (strncmp(cmdBuffer, "debug 0", 7) == 0 && strlen(cmdBuffer) == 7) {
  57. debug = false;
  58. debuglevel = 0;
  59. byte tmpval = 0;
  60. Serial.println(F("DEBUG DISABLED"));
  61. EEPROM.put(eeprom_addr_debug, tmpval);
  62. }
  63. else if (strncmp(cmdBuffer, "format all", 10) == 0 && strlen(cmdBuffer) == 10) {
  64. formatEEPROM_AllData();
  65. }
  66. else if (strncmp(cmdBuffer, "format c", 8) == 0 && strlen(cmdBuffer) >= 8) {
  67. if (strlen(cmdBuffer) == 8) {
  68. Serial.println(F("missing counter number"));
  69. }
  70. else if (strlen(cmdBuffer) == 9) {
  71. char _tmpcNum[2];
  72. _tmpcNum[0] = cmdBuffer[8];
  73. _tmpcNum[1] = '\0';
  74. byte _cNum = atoi(_tmpcNum);
  75. //Serial.println(_cNum);
  76. if (_cNum > 0 && _cNum <= COUNTERS_COUNT) {
  77. formatEEPROMAreaOfCounter(_cNum - 1);
  78. }
  79. else {
  80. Serial.println(F("invalid counter number"));
  81. }
  82. }
  83. }
  84. else if (strncmp(cmdBuffer, "get readings", 12) == 0 && strlen(cmdBuffer) == 12) {
  85. printCurrentReadings();
  86. }
  87. else if (strncmp(cmdBuffer, "get imp c", 9) == 0 && strlen(cmdBuffer) >= 9) {
  88. if (strlen(cmdBuffer) == 9) {
  89. Serial.println(F("missing counter number"));
  90. }
  91. else if (strlen(cmdBuffer) == 10) {
  92. char _tmpcNum[2];
  93. _tmpcNum[0] = cmdBuffer[9];
  94. _tmpcNum[1] = '\0';
  95. byte _cNum = atoi(_tmpcNum);
  96. //Serial.println(_cNum);
  97. if (_cNum > 0 && _cNum <= COUNTERS_COUNT) {
  98. restoreLastSavedImpulseCount(_cNum - 1, true);
  99. }
  100. else {
  101. Serial.println(F("invalid counter number"));
  102. }
  103. }
  104. }
  105. else if (strncmp(cmdBuffer, "get pwrgood", 11) == 0 && strlen(cmdBuffer) == 11) {
  106. printPowerValue();
  107. }
  108. else if (strncmp(cmdBuffer, "set pwrgood", 11) == 0 && strlen(cmdBuffer) >= 13) {
  109. uint16_t tmpvalue = 0;
  110. char offset = 13;
  111. char len = strlen(cmdBuffer) - offset;
  112. if (strlen(cmdBuffer) >= offset) {
  113. for (char i = 0; i < len; i++) {
  114. if (i < (sizeof(cmdDataBuffer) - 1)) cmdDataBuffer[i] = cmdBuffer[i + offset];
  115. }
  116. cmdDataBuffer[len] = '\0';
  117. //Serial.println();
  118. //Serial.print("'");
  119. //Serial.print(cmdDataBuffer);
  120. //Serial.println("'");
  121. char _value1[6];
  122. uint8_t _ivalue1;
  123. byte _i2 = 0;
  124. for (byte i = offset; i < strlen(cmdBuffer); i++) {
  125. _value1[_i2] = cmdBuffer[i];
  126. _i2++;
  127. }
  128. _value1[_i2] = '\0';
  129. _ivalue1 = atoi(_value1);
  130. if (_ivalue1 >= 0 && _ivalue1 <= 1023) {
  131. Serial.print(F("RES: set pwrGood="));
  132. Serial.print(_ivalue1);
  133. Serial.println();
  134. powerGoodMinValue = _ivalue1;
  135. }
  136. saveGlobalConfig();
  137. }
  138. }
  139. else if (strncmp(cmdBuffer, "set json 0", 10) == 0 && strlen(cmdBuffer) == 10) {
  140. output_json = false;
  141. byte tmpval = 0;
  142. EEPROM.put(eeprom_addr_output_json, tmpval);
  143. }
  144. else if (strncmp(cmdBuffer, "set json 1", 10) == 0 && strlen(cmdBuffer) == 10) {
  145. output_json = true;
  146. byte tmpval = 1;
  147. EEPROM.put(eeprom_addr_output_json, tmpval);
  148. }
  149. else if (strncmp(cmdBuffer, "get conf", 8) == 0 && strlen(cmdBuffer) >= 8) {
  150. // if (strlen(cmdBuffer) > 8 && cmdBuffer[8] == ' ' && cmdBuffer[9] == 'c') {
  151. // // is "get conf c#"
  152. // if (strlen(cmdBuffer) == 10) {
  153. // Serial.println(F("missing counter number"));
  154. // }
  155. // else {
  156. // uint16_t tmpvalue = 0;
  157. // char offset = 10;
  158. // char len = strlen(cmdBuffer) - offset;
  159. // if (strlen(cmdBuffer) >= offset) {
  160. // for (char i = 0; i < len; i++) {
  161. // if (i < (sizeof(cmdDataBuffer) - 1)) cmdDataBuffer[i] = cmdBuffer[i + offset];
  162. // }
  163. // cmdDataBuffer[len] = '\0';
  164. // //Serial.println(cmdDataBuffer);
  165. // tmpvalue = atoi(cmdDataBuffer);
  166. // if (tmpvalue > 0 && tmpvalue <= COUNTERS_COUNT) {
  167. // //Serial.print("conf counter ");
  168. // //Serial.println(tmpvalue);
  169. // printCounterConf(tmpvalue - 1);
  170. // }
  171. // else {
  172. // Serial.println(F("counter number invalid"));
  173. // }
  174. //
  175. // }
  176. // }
  177. // }
  178. // else {
  179. // // is "get conf" - so show all
  180. printGlobalConf();
  181. for (byte i = 0; i < COUNTERS_COUNT; i++) {
  182. printCounterConf(i);
  183. }
  184. // }
  185. }
  186. else if (strncmp(cmdBuffer, "set debounce", 12) == 0 && strlen(cmdBuffer) >= 14) {
  187. uint16_t tmpvalue = 0;
  188. char offset = 13;
  189. char len = strlen(cmdBuffer) - offset;
  190. if (strlen(cmdBuffer) >= offset) {
  191. for (char i = 0; i < len; i++) {
  192. if (i < (sizeof(cmdDataBuffer) - 1)) cmdDataBuffer[i] = cmdBuffer[i + offset];
  193. }
  194. cmdDataBuffer[len] = '\0';
  195. //Serial.println();
  196. //Serial.print("'");
  197. //Serial.print(cmdDataBuffer);
  198. //Serial.println("'");
  199. char _value1[6];
  200. char _value2[6];
  201. uint8_t _ivalue1, _ivalue2;
  202. bool _withValue2;
  203. byte _sepOffset = 0;
  204. byte _i2 = 0;
  205. for (byte i = offset; i < strlen(cmdBuffer); i++) {
  206. if (cmdBuffer[i] == ',') {
  207. //Serial.print("found , at offset ");
  208. //Serial.println(i);
  209. _sepOffset = i;
  210. }
  211. else if (_sepOffset == 0) {
  212. _value1[_i2] = cmdBuffer[i];
  213. _i2++;
  214. }
  215. }
  216. _value1[_i2] = '\0';
  217. if (_sepOffset > 0) {
  218. _i2 = 0;
  219. for (byte i = _sepOffset + 1; i < strlen(cmdBuffer); i++) {
  220. _value2[_i2] = cmdBuffer[i];
  221. _i2++;
  222. }
  223. _value2[_i2] = '\0';
  224. _withValue2 = true;
  225. }
  226. else {
  227. _value2[0] = '\0'; // no _value2 was given
  228. _withValue2 = false;
  229. }
  230. _ivalue1 = atoi(_value1);
  231. _ivalue2 = atoi(_value2);
  232. if (_ivalue1 >= 0 && _ivalue1 <= 200) {
  233. Serial.print(F("RES: set debounce="));
  234. Serial.print(_ivalue1);
  235. debounceDelay = _ivalue1;
  236. }
  237. if (_withValue2 && _ivalue2 >= 0 && _ivalue2 <= 500) {
  238. Serial.print(F(", debounceRecov="));
  239. Serial.print(_ivalue2);
  240. debounceRecoveryDelay = _ivalue2;
  241. }
  242. Serial.println();
  243. saveGlobalConfig();
  244. }
  245. }
  246. else if (strncmp(cmdBuffer, "get debounce", 12) == 0 && strlen(cmdBuffer) == 12) {
  247. Serial.print(F("debounce: "));
  248. Serial.print(debounceDelay);
  249. Serial.print(", ");
  250. Serial.println(debounceRecoveryDelay);
  251. }
  252. else if (strncmp(cmdBuffer, "set conf c", 10) == 0 && strlen(cmdBuffer) >= 10) {
  253. if (strlen(cmdBuffer) == 10) {
  254. Serial.println(F("missing counter number"));
  255. }
  256. else if (strlen(cmdBuffer) >= 15) {
  257. uint16_t tmpvalue = 0;
  258. char offset = 10;
  259. char len = strlen(cmdBuffer) - offset;
  260. if (strlen(cmdBuffer) >= offset) {
  261. char _cNumBuf[2];
  262. char _commandBuffer[11];
  263. char _valueBuffer[11];
  264. //byte _delimitersFound = 0;
  265. byte _cNum;
  266. boolean _cNumOK = false;
  267. //
  268. for (byte i = 0; i < len; i++) {
  269. if (i < (sizeof(cmdDataBuffer) - 1)) cmdDataBuffer[i] = cmdBuffer[i + offset];
  270. }
  271. cmdDataBuffer[len] = '\0';
  272. Serial.print("cmdDataBuffer: '");
  273. Serial.print(cmdDataBuffer);
  274. Serial.println("'");
  275. // get counter number, expect it on 1st place and 1 char long
  276. _cNumBuf[0] = cmdDataBuffer[0];
  277. _cNumBuf[1] = '\0';
  278. _cNum = atoi(_cNumBuf);
  279. if (_cNum > 0 && _cNum <= COUNTERS_COUNT) {
  280. Serial.print("_cNum=");
  281. Serial.println(_cNum);
  282. _cNumOK = true;
  283. }
  284. else if (cmdDataBuffer[1] != ' ') {
  285. Serial.println(F("ERROR - invalid syntax"));
  286. }
  287. else {
  288. Serial.print("_cNum invalid: ");
  289. Serial.println(_cNum);
  290. }
  291. // Serial.println();
  292. // Serial.print("cmdDataBuffer[1]='");
  293. // Serial.print(cmdDataBuffer[1]);
  294. // Serial.println("'");
  295. if (_cNumOK && strlen(cmdDataBuffer) > 4) {
  296. // https://arduino.stackexchange.com/questions/1013/how-do-i-split-an-incoming-string
  297. // Read each command pair
  298. char* _param = strtok(cmdDataBuffer, " ");
  299. while (_param != 0)
  300. {
  301. // Split the command in two values
  302. char* _value = strchr(_param, '=');
  303. if (_value != 0)
  304. {
  305. // Actually split the string in 2: replace ':' with 0
  306. *_value = 0;
  307. strlwr(_param);
  308. // Serial.print("_param='");
  309. // Serial.print(_param);
  310. ++_value;
  311. // Serial.print("' ");
  312. // Serial.print("_value='");
  313. // Serial.print(_value);
  314. // Serial.println("'");
  315. if (strcmp(_param, "impperunit") == 0) {
  316. Serial.print("impPerUnit=");
  317. Serial.println(atoi(_value));
  318. meter_impPerUnit[_cNum - 1] = atoi(_value);
  319. }
  320. else if (strcmp(_param, "noimptout") == 0) {
  321. Serial.print("noImpTout=");
  322. Serial.println(atoi(_value));
  323. meter_noImpulseTimeout_seconds[_cNum - 1] = atoi(_value);
  324. }
  325. else if (strcmp(_param, "saveint") == 0) {
  326. Serial.print("saveInt=");
  327. Serial.println(atoi(_value));
  328. meter_savePulsesOnInterval_mins[_cNum - 1] = atoi(_value);
  329. }
  330. else {
  331. Serial.print(F("unknown parameter '"));
  332. Serial.print(_param);
  333. Serial.println("'");
  334. }
  335. printCounterConf(_cNum - 1);
  336. }
  337. // Find the next command in input string
  338. _param = strtok(0, ";");
  339. }
  340. }
  341. else {
  342. Serial.println(F("invalid command"));
  343. }
  344. }
  345. }
  346. }
  347. else if (strncmp(cmdBuffer, "save conf", 9) == 0 && strlen(cmdBuffer) == 9) {
  348. Serial.println(F("SAVING CONFIG"));
  349. saveCountersConfig();
  350. saveGlobalConfig();
  351. }
  352. #ifdef INCLUDE_TESTFUNCTIONS
  353. else if (strncmp(cmdBuffer, "test init c2", 12) == 0 && strlen(cmdBuffer) == 12) {
  354. Serial.println("test init c2");
  355. formatEEPROMAreaOfCounter(1);
  356. eeprom_writecounter_currentReadingImpulses[1] = 65530;
  357. eeprom_nextoffset_currentReadingImpulses[1] = 0;
  358. }
  359. else if (strncmp(cmdBuffer, "test c2", 7) == 0 && strlen(cmdBuffer) == 7) {
  360. increaseCounter(1);
  361. storeCurrentImpulses(1, false);
  362. }
  363. #endif
  364. else if (strncmp(cmdBuffer, "set reading", 11) == 0 && strlen(cmdBuffer) >= 11) {
  365. uint16_t tmpvalue = 0;
  366. char tmpdata_1[10];
  367. char tmpdata_2[10];
  368. unsigned long newReading;
  369. uint16_t newImpulses;
  370. if (strlen(cmdBuffer) <= 13) {
  371. Serial.println(F("ERROR: missing valid counter number"));
  372. }
  373. else if ( strlen(cmdBuffer) > 13 && cmdBuffer[11] == ' ' && cmdBuffer[12] == 'c') {
  374. byte _cNum;
  375. char tmp_cNum[2];
  376. tmp_cNum[0] = cmdBuffer[13]; // atoi needs char array to work...
  377. tmp_cNum[1] = 0;
  378. _cNum = atoi(tmp_cNum);
  379. if (_cNum < 1 || _cNum > COUNTERS_COUNT) {
  380. Serial.println(F("ERROR: invalid counter number"));
  381. }
  382. else if (_cNum > 0 && _cNum <= COUNTERS_COUNT) {
  383. Serial.print(F("got valid counter number: "));
  384. Serial.println(_cNum);
  385. _cNum = _cNum - 1; // we actually need the array index, not the pretty number...
  386. //char offset = 12;
  387. byte offset = 15;
  388. byte len = strlen(cmdBuffer) - offset;
  389. Serial.println("SET READING");
  390. if (strlen(cmdBuffer) > offset) {
  391. //for (char i = 0; i < len; i++) {
  392. // if (i < (sizeof(cmdDataBuffer) - 1)) cmdDataBuffer[i] = cmdBuffer[i + offset];
  393. //}
  394. bool value_1_finished = false;
  395. bool value_2_finished = false;
  396. bool commaGiven = false;
  397. bool impulsesGiven = false;
  398. uint8_t i1 = 0;
  399. uint8_t i2 = 0;
  400. //Serial.println("vor val1");
  401. while (!value_1_finished) {
  402. if (isdigit(cmdBuffer[i1 + offset])) {
  403. if (i1 < (sizeof(tmpdata_1) - 1)) tmpdata_1[i1] = cmdBuffer[i1 + offset];
  404. //Serial.print(" ");
  405. //Serial.print(i1);
  406. i1++;
  407. i2++;
  408. }
  409. else if (cmdBuffer[i1 + offset] == '.' || cmdBuffer[i1 + offset] == ',' || cmdBuffer[i1 + offset] == ' ') {
  410. value_1_finished = true;
  411. if (cmdBuffer[i1 + offset] == '.' || cmdBuffer[i1 + offset] == ',') commaGiven = true;
  412. //Serial.println("value_1_finished=true");
  413. i1++;
  414. }
  415. else if (cmdBuffer[i1 + offset] == '\0') {
  416. //Serial.println("value_[1|2]_finished=true");
  417. value_1_finished = true;
  418. value_2_finished = true; // end of string reached - no value 2 was given
  419. }
  420. }
  421. tmpdata_1[i2] = '\0';
  422. newReading = atol(tmpdata_1);
  423. //Serial.print(F("value 1: "));
  424. //Serial.println(tmpdata_1);
  425. if (!value_2_finished) {
  426. impulsesGiven = true;
  427. i2 = 0;
  428. while (!value_2_finished) {
  429. if (isdigit(cmdBuffer[i1 + offset])) {
  430. if (i2 < (sizeof(tmpdata_2) - 1)) tmpdata_2[i2] = cmdBuffer[i1 + offset];
  431. i1++;
  432. i2++;
  433. }
  434. else if (cmdBuffer[i1 + offset] == ' ' || cmdBuffer[i1 + offset] == '\0') {
  435. value_2_finished = true; // end of string reached
  436. }
  437. }
  438. tmpdata_2[i2] = '\0';
  439. newImpulses = atoi(tmpdata_2);
  440. //Serial.print(F("value 2: "));
  441. //Serial.println(tmpdata_2);
  442. }
  443. if (commaGiven && impulsesGiven && tmpdata_2 >= 0) {
  444. if ((meter_impPerUnit[_cNum] == 10 && newImpulses < 10) || (meter_impPerUnit[_cNum] == 100 && newImpulses < 100) || (meter_impPerUnit[_cNum] == 1000 && newImpulses < 1000) || (meter_impPerUnit[_cNum] == 10000 && newImpulses < 10000)) {
  445. Serial.print(F("INFO: set new reading: "));
  446. Serial.print(newReading);
  447. Serial.print(".");
  448. if (meter_impPerUnit[_cNum] == 100 && newImpulses < 10) Serial.print("0");
  449. else if (meter_impPerUnit[_cNum] == 1000 && newImpulses < 10) Serial.print("00");
  450. else if (meter_impPerUnit[_cNum] == 1000 && newImpulses < 100) Serial.print("0");
  451. Serial.println(newImpulses);
  452. currentReading[_cNum] = newReading;
  453. currentReadingImpulses[_cNum] = newImpulses;
  454. formatEEPROMAreaOfCounter(_cNum);
  455. storeCurrentReading(_cNum, true);
  456. storeCurrentImpulses(_cNum, true);
  457. }
  458. else {
  459. Serial.print(F("ERROR: invalid decimals for set impPerUnit="));
  460. Serial.print(meter_impPerUnit[_cNum]);
  461. Serial.println(" !!!");
  462. }
  463. }
  464. else if (!commaGiven && impulsesGiven) {
  465. Serial.print(F("INFO: set new reading: "));
  466. Serial.println(newReading);
  467. Serial.print(F("INFO: set new impulses: "));
  468. Serial.println(newImpulses);
  469. currentReading[_cNum] = newReading;
  470. currentReadingImpulses[_cNum] = newImpulses;
  471. formatEEPROMAreaOfCounter(_cNum);
  472. storeCurrentReading(_cNum, true);
  473. storeCurrentImpulses(_cNum, true);
  474. }
  475. else if (!commaGiven && !impulsesGiven) {
  476. Serial.print(F("INFO: set new reading: "));
  477. Serial.println(newReading);
  478. currentReading[_cNum] = newReading;
  479. currentReadingImpulses[_cNum] = 0;
  480. formatEEPROMAreaOfCounter(_cNum);
  481. storeCurrentReading(_cNum, true);
  482. storeCurrentImpulses(_cNum, true);
  483. }
  484. }
  485. }
  486. }
  487. }
  488. else if (strncmp(cmdBuffer, "get wcount", 10) == 0 && strlen(cmdBuffer) == 10) {
  489. for (int i = 0; i < COUNTERS_COUNT; i++) {
  490. Serial.print(F("wCount C"));
  491. Serial.print(i + 1);
  492. Serial.print("=");
  493. Serial.println(eeprom_writecounter_currentReadingImpulses[i]);
  494. }
  495. }
  496. else if (strncmp(cmdBuffer, "reset", 5) == 0 && strlen(cmdBuffer) >= 5) {
  497. if (strlen(cmdBuffer) == 5) {
  498. resetForFlashing(0);
  499. }
  500. else {
  501. uint16_t tmpvalue = 0;
  502. char offset = 6;
  503. char len = strlen(cmdBuffer) - offset;
  504. if (strlen(cmdBuffer) >= offset) {
  505. for (char i = 0; i < len; i++) {
  506. if (i < (sizeof(cmdDataBuffer) - 1)) cmdDataBuffer[i] = cmdBuffer[i + offset];
  507. }
  508. cmdDataBuffer[len] = '\0';
  509. Serial.println(cmdDataBuffer);
  510. tmpvalue = atoi(cmdDataBuffer);
  511. if (tmpvalue >= 0 && tmpvalue <= 15000) {
  512. resetForFlashing(tmpvalue);
  513. }
  514. else Serial.println(F("out of range 0-15000"));
  515. }
  516. }
  517. }
  518. else {
  519. Serial.print(F("UNKNOWN COMMAND: '"));
  520. Serial.print(cmdBuffer);
  521. Serial.println("'");
  522. }
  523. cmdBufferCount = 0;
  524. for ( int i = 0; i < sizeof(cmdBuffer); ++i ) cmdBuffer[i] = (char)0;
  525. }