mmu2_protocol_logic.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  1. #include "mmu2_protocol_logic.h"
  2. #include "mmu2_log.h"
  3. #include "mmu2_fsensor.h"
  4. #include "system_timer.h"
  5. #include <string.h>
  6. namespace MMU2 {
  7. StepStatus ProtocolLogicPartBase::ProcessFINDAReqSent(StepStatus finishedRV, State nextState){
  8. auto expmsg = logic->ExpectingMessage(linkLayerTimeout);
  9. if (expmsg != MessageReady)
  10. return expmsg;
  11. logic->findaPressed = logic->rsp.paramValue;
  12. state = nextState;
  13. return finishedRV;
  14. }
  15. void ProtocolLogicPartBase::CheckAndReportAsyncEvents(){
  16. // even when waiting for a query period, we need to report a change in filament sensor's state
  17. // - it is vital for a precise synchronization of moves of the printer and the MMU
  18. uint8_t fs = (uint8_t)WhereIsFilament();
  19. if( fs != logic->lastFSensor ){
  20. SendAndUpdateFilamentSensor();
  21. }
  22. }
  23. void ProtocolLogicPartBase::SendQuery(){
  24. logic->SendMsg(RequestMsg(RequestMsgCodes::Query, 0));
  25. state = State::QuerySent;
  26. }
  27. void ProtocolLogicPartBase::SendFINDAQuery(){
  28. logic->SendMsg(RequestMsg(RequestMsgCodes::Finda, 0 ) );
  29. state = State::FINDAReqSent;
  30. }
  31. void ProtocolLogicPartBase::SendAndUpdateFilamentSensor(){
  32. logic->SendMsg(RequestMsg(RequestMsgCodes::FilamentSensor, logic->lastFSensor = (uint8_t)WhereIsFilament() ) );
  33. state = State::FilamentSensorStateSent;
  34. }
  35. void ProtocolLogicPartBase::SendButton(uint8_t btn){
  36. logic->SendMsg(RequestMsg(RequestMsgCodes::Button, btn));
  37. state = State::ButtonSent;
  38. }
  39. StepStatus ProtocolLogic::ProcessUARTByte(uint8_t c) {
  40. switch (protocol.DecodeResponse(c)) {
  41. case DecodeStatus::MessageCompleted:
  42. return MessageReady;
  43. case DecodeStatus::NeedMoreData:
  44. return Processing;
  45. case DecodeStatus::Error:
  46. default:
  47. return ProtocolError;
  48. }
  49. }
  50. // searches for "ok\n" in the incoming serial data (that's the usual response of the old MMU FW)
  51. struct OldMMUFWDetector {
  52. uint8_t ok;
  53. inline constexpr OldMMUFWDetector():ok(0) { }
  54. enum class State : uint8_t { MatchingPart, SomethingElse, Matched };
  55. /// @returns true when "ok\n" gets detected
  56. State Detect(uint8_t c){
  57. // consume old MMU FW's data if any -> avoid confusion of protocol decoder
  58. if(ok == 0 && c == 'o'){
  59. ++ok;
  60. return State::MatchingPart;
  61. } else if(ok == 1 && c == 'k'){
  62. ++ok;
  63. return State::MatchingPart;
  64. } else if(ok == 2 && c == '\n'){
  65. return State::Matched;
  66. }
  67. return State::SomethingElse;
  68. }
  69. };
  70. StepStatus ProtocolLogic::ExpectingMessage(uint32_t timeout) {
  71. int bytesConsumed = 0;
  72. int c = -1;
  73. OldMMUFWDetector oldMMUh4x0r; // old MMU FW hacker ;)
  74. // try to consume as many rx bytes as possible (until a message has been completed)
  75. while((c = uart->read()) >= 0){
  76. ++bytesConsumed;
  77. RecordReceivedByte(c);
  78. switch (protocol.DecodeResponse(c)) {
  79. case DecodeStatus::MessageCompleted:
  80. rsp = protocol.GetResponseMsg();
  81. LogResponse();
  82. RecordUARTActivity(); // something has happened on the UART, update the timeout record
  83. return MessageReady;
  84. case DecodeStatus::NeedMoreData:
  85. break;
  86. case DecodeStatus::Error:{
  87. // consume old MMU FW's data if any -> avoid confusion of protocol decoder
  88. auto old = oldMMUh4x0r.Detect(c);
  89. if( old == OldMMUFWDetector::State::Matched ){
  90. // hack bad FW version - BEWARE - we silently assume that the first query is an "S0"
  91. // The old MMU FW responds with "ok\n" and we fake the response to a bad FW version at this spot
  92. rsp = ResponseMsg(RequestMsg(RequestMsgCodes::Version, 0), ResponseMsgParamCodes::Accepted, 0);
  93. return MessageReady;
  94. } else if( old == OldMMUFWDetector::State::MatchingPart ){
  95. break;
  96. }
  97. }
  98. // otherwise [[fallthrough]]
  99. default:
  100. RecordUARTActivity(); // something has happened on the UART, update the timeout record
  101. return ProtocolError;
  102. }
  103. }
  104. if( bytesConsumed != 0 ){
  105. RecordUARTActivity(); // something has happened on the UART, update the timeout record
  106. return Processing; // consumed some bytes, but message still not ready
  107. } else if (Elapsed(timeout)) {
  108. return CommunicationTimeout;
  109. }
  110. return Processing;
  111. }
  112. void ProtocolLogic::SendMsg(RequestMsg rq) {
  113. uint8_t txbuff[Protocol::MaxRequestSize()];
  114. uint8_t len = Protocol::EncodeRequest(rq, txbuff);
  115. uart->write(txbuff, len);
  116. LogRequestMsg(txbuff, len);
  117. RecordUARTActivity();
  118. }
  119. void StartSeq::Restart() {
  120. state = State::S0Sent;
  121. logic->SendMsg(RequestMsg(RequestMsgCodes::Version, 0));
  122. }
  123. StepStatus StartSeq::Step() {
  124. auto expmsg = logic->ExpectingMessage(linkLayerTimeout);
  125. if (expmsg != MessageReady)
  126. return expmsg;
  127. // solve initial handshake
  128. switch (state) {
  129. case State::S0Sent: // received response to S0 - major
  130. if (logic->rsp.paramValue != 2) {
  131. return VersionMismatch;
  132. }
  133. logic->dataTO.Reset(); // got meaningful response from the MMU, stop data layer timeout tracking
  134. logic->SendMsg(RequestMsg(RequestMsgCodes::Version, 1));
  135. state = State::S1Sent;
  136. break;
  137. case State::S1Sent: // received response to S1 - minor
  138. if (logic->rsp.paramValue != 0) {
  139. return VersionMismatch;
  140. }
  141. logic->SendMsg(RequestMsg(RequestMsgCodes::Version, 2));
  142. state = State::S2Sent;
  143. break;
  144. case State::S2Sent: // received response to S2 - revision
  145. if (logic->rsp.paramValue != 0) {
  146. return VersionMismatch;
  147. }
  148. // Start General Interrogation after line up.
  149. // For now we just send the state of the filament sensor, but we may request
  150. // data point states from the MMU as well. TBD in the future, especially with another protocol
  151. SendAndUpdateFilamentSensor();
  152. break;
  153. case State::FilamentSensorStateSent:
  154. state = State::Ready;
  155. return Finished;
  156. break;
  157. default:
  158. return VersionMismatch;
  159. }
  160. return Processing;
  161. }
  162. void Command::Restart() {
  163. state = State::CommandSent;
  164. logic->SendMsg(logic->command.rq);
  165. }
  166. StepStatus Command::Step() {
  167. switch (state) {
  168. case State::CommandSent: {
  169. auto expmsg = logic->ExpectingMessage(linkLayerTimeout);
  170. if (expmsg != MessageReady)
  171. return expmsg;
  172. switch (logic->rsp.paramCode) { // the response should be either accepted or rejected
  173. case ResponseMsgParamCodes::Accepted:
  174. logic->progressCode = ProgressCode::OK;
  175. logic->errorCode = ErrorCode::RUNNING;
  176. state = State::Wait;
  177. break;
  178. case ResponseMsgParamCodes::Rejected:
  179. // rejected - should normally not happen, but report the error up
  180. logic->progressCode = ProgressCode::OK;
  181. logic->errorCode = ErrorCode::PROTOCOL_ERROR;
  182. return CommandRejected;
  183. default:
  184. return ProtocolError;
  185. }
  186. } break;
  187. case State::Wait:
  188. if (logic->Elapsed(heartBeatPeriod)) {
  189. SendQuery();
  190. } else {
  191. // even when waiting for a query period, we need to report a change in filament sensor's state
  192. // - it is vital for a precise synchronization of moves of the printer and the MMU
  193. CheckAndReportAsyncEvents();
  194. }
  195. break;
  196. case State::QuerySent: {
  197. auto expmsg = logic->ExpectingMessage(linkLayerTimeout);
  198. if (expmsg != MessageReady)
  199. return expmsg;
  200. }
  201. // [[fallthrough]];
  202. case State::ContinueFromIdle:
  203. switch (logic->rsp.paramCode) {
  204. case ResponseMsgParamCodes::Processing:
  205. logic->progressCode = static_cast<ProgressCode>(logic->rsp.paramValue);
  206. logic->errorCode = ErrorCode::OK;
  207. SendAndUpdateFilamentSensor(); // keep on reporting the state of fsensor regularly
  208. break;
  209. case ResponseMsgParamCodes::Error:
  210. // in case of an error the progress code remains as it has been before
  211. logic->errorCode = static_cast<ErrorCode>(logic->rsp.paramValue);
  212. // keep on reporting the state of fsensor regularly even in command error state
  213. // - the MMU checks FINDA and fsensor even while recovering from errors
  214. SendAndUpdateFilamentSensor();
  215. return CommandError;
  216. case ResponseMsgParamCodes::Button:
  217. // The user pushed a button on the MMU. Save it, do what we need to do
  218. // to prepare, then pass it back to the MMU so it can work its magic.
  219. logic->buttonCode = static_cast<Buttons>(logic->rsp.paramValue);
  220. return ButtonPushed;
  221. case ResponseMsgParamCodes::Finished:
  222. logic->progressCode = ProgressCode::OK;
  223. state = State::Ready;
  224. return Finished;
  225. default:
  226. return ProtocolError;
  227. }
  228. break;
  229. case State::FilamentSensorStateSent:{
  230. auto expmsg = logic->ExpectingMessage(linkLayerTimeout);
  231. if (expmsg != MessageReady)
  232. return expmsg;
  233. SendFINDAQuery();
  234. } break;
  235. case State::FINDAReqSent:
  236. return ProcessFINDAReqSent(Processing, State::Wait);
  237. case State::ButtonSent:{
  238. // button is never confirmed ... may be it should be
  239. // auto expmsg = logic->ExpectingMessage(linkLayerTimeout);
  240. // if (expmsg != MessageReady)
  241. // return expmsg;
  242. SendQuery();
  243. } break;
  244. default:
  245. return ProtocolError;
  246. }
  247. return Processing;
  248. }
  249. void Idle::Restart() {
  250. state = State::Ready;
  251. }
  252. StepStatus Idle::Step() {
  253. switch (state) {
  254. case State::Ready: // check timeout
  255. if (logic->Elapsed(heartBeatPeriod)) {
  256. SendQuery();
  257. return Processing;
  258. }
  259. break;
  260. case State::QuerySent: { // check UART
  261. auto expmsg = logic->ExpectingMessage(linkLayerTimeout);
  262. if (expmsg != MessageReady)
  263. return expmsg;
  264. // If we are accidentally in Idle and we receive something like "T0 P1" - that means the communication dropped out while a command was in progress.
  265. // That causes no issues here, we just need to switch to Command processing and continue there from now on.
  266. // The usual response in this case should be some command and "F" - finished - that confirms we are in an Idle state even on the MMU side.
  267. switch( logic->rsp.request.code ){
  268. case RequestMsgCodes::Cut:
  269. case RequestMsgCodes::Eject:
  270. case RequestMsgCodes::Load:
  271. case RequestMsgCodes::Mode:
  272. case RequestMsgCodes::Tool:
  273. case RequestMsgCodes::Unload:
  274. if( logic->rsp.paramCode != ResponseMsgParamCodes::Finished ){
  275. logic->SwitchFromIdleToCommand();
  276. return Processing;
  277. }
  278. break;
  279. case RequestMsgCodes::Reset:
  280. // this one is kind of special
  281. // we do not transfer to any "running" command (i.e. we stay in Idle),
  282. // but in case there is an error reported we must make sure it gets propagated
  283. if( logic->rsp.paramCode != ResponseMsgParamCodes::Finished ){
  284. logic->errorCode = static_cast<ErrorCode>(logic->rsp.paramValue);
  285. SendFINDAQuery(); // continue Idle state without restarting the communication
  286. return CommandError;
  287. } else {
  288. logic->errorCode = ErrorCode::OK;
  289. }
  290. break;
  291. default:
  292. break;
  293. }
  294. SendFINDAQuery();
  295. return Processing;
  296. } break;
  297. case State::FINDAReqSent:
  298. return ProcessFINDAReqSent(Finished, State::Ready);
  299. default:
  300. return ProtocolError;
  301. }
  302. // The "return Finished" in this state machine requires a bit of explanation:
  303. // The Idle state either did nothing (still waiting for the heartbeat timeout)
  304. // or just successfully received the answer to Q0, whatever that was.
  305. // In both cases, it is ready to hand over work to a command or something else,
  306. // therefore we are returning Finished (also to exit mmu_loop() and unblock Marlin's loop!).
  307. // If there is no work, we'll end up in the Idle state again
  308. // and we'll send the heartbeat message after the specified timeout.
  309. return Finished;
  310. }
  311. ProtocolLogic::ProtocolLogic(MMU2Serial *uart)
  312. : stopped(this)
  313. , startSeq(this)
  314. , idle(this)
  315. , command(this)
  316. , currentState(&stopped)
  317. , plannedRq(RequestMsgCodes::unknown, 0)
  318. , lastUARTActivityMs(0)
  319. , rsp(RequestMsg(RequestMsgCodes::unknown, 0), ResponseMsgParamCodes::unknown, 0)
  320. , state(State::Stopped)
  321. , lrb(0)
  322. , uart(uart)
  323. , lastFSensor((uint8_t)WhereIsFilament())
  324. {}
  325. void ProtocolLogic::Start() {
  326. state = State::InitSequence;
  327. currentState = &startSeq;
  328. startSeq.Restart();
  329. }
  330. void ProtocolLogic::Stop() {
  331. state = State::Stopped;
  332. currentState = &stopped;
  333. }
  334. void ProtocolLogic::ToolChange(uint8_t slot) {
  335. PlanGenericRequest(RequestMsg(RequestMsgCodes::Tool, slot));
  336. }
  337. void ProtocolLogic::UnloadFilament() {
  338. PlanGenericRequest(RequestMsg(RequestMsgCodes::Unload, 0));
  339. }
  340. void ProtocolLogic::LoadFilament(uint8_t slot) {
  341. PlanGenericRequest(RequestMsg(RequestMsgCodes::Load, slot));
  342. }
  343. void ProtocolLogic::EjectFilament(uint8_t slot) {
  344. PlanGenericRequest(RequestMsg(RequestMsgCodes::Eject, slot));
  345. }
  346. void ProtocolLogic::CutFilament(uint8_t slot){
  347. PlanGenericRequest(RequestMsg(RequestMsgCodes::Cut, slot));
  348. }
  349. void ProtocolLogic::ResetMMU() {
  350. PlanGenericRequest(RequestMsg(RequestMsgCodes::Reset, 0));
  351. }
  352. void ProtocolLogic::Button(uint8_t index){
  353. PlanGenericRequest(RequestMsg(RequestMsgCodes::Button, index));
  354. }
  355. void ProtocolLogic::Home(uint8_t mode){
  356. PlanGenericRequest(RequestMsg(RequestMsgCodes::Home, mode));
  357. }
  358. void ProtocolLogic::PlanGenericRequest(RequestMsg rq) {
  359. plannedRq = rq;
  360. if( ! currentState->ExpectsResponse() ){
  361. ActivatePlannedRequest();
  362. } // otherwise wait for an empty window to activate the request
  363. }
  364. bool ProtocolLogic::ActivatePlannedRequest(){
  365. if( plannedRq.code == RequestMsgCodes::Button ){
  366. // only issue the button to the MMU and do not restart the state machines
  367. // @@TODO - this is not completely correct, but it does the job.
  368. // In Idle mode the command part is not active, but we still need button handling in Idle mode (resolve MMU init errors)
  369. // -> command.SendButton is not correct, but it sends the message and everything works (for now)
  370. command.SendButton(plannedRq.value);
  371. plannedRq = RequestMsg(RequestMsgCodes::unknown, 0);
  372. return true;
  373. } else if( plannedRq.code != RequestMsgCodes::unknown ){
  374. currentState = &command;
  375. command.SetRequestMsg(plannedRq);
  376. plannedRq = RequestMsg(RequestMsgCodes::unknown, 0);
  377. command.Restart();
  378. return true;
  379. }
  380. return false;
  381. }
  382. void ProtocolLogic::SwitchFromIdleToCommand(){
  383. currentState = &command;
  384. command.SetRequestMsg(rsp.request);
  385. // we are recovering from a communication drop out, the command is already running
  386. // and we have just received a response to a Q0 message about a command progress
  387. command.ContinueFromIdle();
  388. }
  389. void ProtocolLogic::SwitchToIdle() {
  390. state = State::Running;
  391. currentState = &idle;
  392. idle.Restart();
  393. }
  394. void ProtocolLogic::HandleCommunicationTimeout() {
  395. uart->flush(); // clear the output buffer
  396. currentState = &startSeq;
  397. state = State::InitSequence;
  398. startSeq.Restart();
  399. }
  400. bool ProtocolLogic::Elapsed(uint32_t timeout) const {
  401. return _millis() >= (lastUARTActivityMs + timeout);
  402. }
  403. void ProtocolLogic::RecordUARTActivity() {
  404. lastUARTActivityMs = _millis();
  405. }
  406. void ProtocolLogic::RecordReceivedByte(uint8_t c){
  407. lastReceivedBytes[lrb] = c;
  408. lrb = (lrb+1) % lastReceivedBytes.size();
  409. }
  410. constexpr char NibbleToChar(uint8_t c){
  411. switch (c) {
  412. case 0:
  413. case 1:
  414. case 2:
  415. case 3:
  416. case 4:
  417. case 5:
  418. case 6:
  419. case 7:
  420. case 8:
  421. case 9:
  422. return c + '0';
  423. case 10:
  424. case 11:
  425. case 12:
  426. case 13:
  427. case 14:
  428. case 15:
  429. return (c - 10) + 'a';
  430. default:
  431. return 0;
  432. }
  433. }
  434. void ProtocolLogic::FormatLastReceivedBytes(char *dst){
  435. for(uint8_t i = 0; i < lastReceivedBytes.size(); ++i){
  436. uint8_t b = lastReceivedBytes[ (lrb-i-1) % lastReceivedBytes.size() ];
  437. dst[i*3] = NibbleToChar(b >> 4);
  438. dst[i*3+1] = NibbleToChar(b & 0xf);
  439. dst[i*3+2] = ' ';
  440. }
  441. dst[ (lastReceivedBytes.size() - 1) * 3 + 2] = 0; // terminate properly
  442. }
  443. void ProtocolLogic::FormatLastResponseMsgAndClearLRB(char *dst){
  444. *dst++ = '<';
  445. for(uint8_t i = 0; i < lrb; ++i){
  446. uint8_t b = lastReceivedBytes[ i ];
  447. if( b < 32 )b = '.';
  448. if( b > 127 )b = '.';
  449. *dst++ = b;
  450. }
  451. *dst = 0; // terminate properly
  452. lrb = 0; // reset the input buffer index in case of a clean message
  453. }
  454. void ProtocolLogic::LogRequestMsg(const uint8_t *txbuff, uint8_t size){
  455. constexpr uint_fast8_t rqs = modules::protocol::Protocol::MaxRequestSize() + 2;
  456. char tmp[rqs] = ">";
  457. static char lastMsg[rqs] = "";
  458. for(uint8_t i = 0; i < size; ++i){
  459. uint8_t b = txbuff[i];
  460. if( b < 32 )b = '.';
  461. if( b > 127 )b = '.';
  462. tmp[i+1] = b;
  463. }
  464. tmp[size+1] = '\n';
  465. tmp[size+2] = 0;
  466. if( !strncmp(tmp, ">S0.\n", rqs) && !strncmp(lastMsg, tmp, rqs) ){
  467. // @@TODO we skip the repeated request msgs for now
  468. // to avoid spoiling the whole log just with ">S0" messages
  469. // especially when the MMU is not connected.
  470. // We'll lose the ability to see if the printer is actually
  471. // trying to find the MMU, but since it has been reliable in the past
  472. // we can live without it for now.
  473. } else {
  474. MMU2_ECHO_MSG(tmp);
  475. }
  476. memcpy(lastMsg, tmp, rqs);
  477. }
  478. void ProtocolLogic::LogError(const char *reason){
  479. char lrb[lastReceivedBytes.size() * 3];
  480. FormatLastReceivedBytes(lrb);
  481. MMU2_ERROR_MSG(reason);
  482. SERIAL_ECHO(", last bytes: ");
  483. SERIAL_ECHOLN(lrb);
  484. }
  485. void ProtocolLogic::LogResponse(){
  486. char lrb[lastReceivedBytes.size()];
  487. FormatLastResponseMsgAndClearLRB(lrb);
  488. MMU2_ECHO_MSG(lrb);
  489. SERIAL_ECHOLN();
  490. }
  491. StepStatus ProtocolLogic::HandleCommError(const char *msg, StepStatus ss){
  492. protocol.ResetResponseDecoder();
  493. HandleCommunicationTimeout();
  494. if( dataTO.Record(ss) ){
  495. LogError(msg);
  496. return dataTO.InitialCause();
  497. } else {
  498. return Processing; // suppress short drop outs of communication
  499. }
  500. }
  501. StepStatus ProtocolLogic::Step() {
  502. if( ! currentState->ExpectsResponse() ){ // if not waiting for a response, activate a planned request immediately
  503. ActivatePlannedRequest();
  504. }
  505. auto currentStatus = currentState->Step();
  506. switch (currentStatus) {
  507. case Processing:
  508. // we are ok, the state machine continues correctly
  509. break;
  510. case Finished: {
  511. // We are ok, switching to Idle if there is no potential next request planned.
  512. // But the trouble is we must report a finished command if the previous command has just been finished
  513. // i.e. only try to find some planned command if we just finished the Idle cycle
  514. bool previousCommandFinished = currentState == &command; // @@TODO this is a nasty hack :(
  515. if( ! ActivatePlannedRequest() ){ // if nothing is planned, switch to Idle
  516. SwitchToIdle();
  517. } else {
  518. // if the previous cycle was Idle and now we have planned a new command -> avoid returning Finished
  519. if( ! previousCommandFinished && currentState == &command){
  520. currentStatus = Processing;
  521. }
  522. }
  523. }
  524. break;
  525. case CommandRejected:
  526. // we have to repeat it - that's the only thing we can do
  527. // no change in state
  528. // @@TODO wait until Q0 returns command in progress finished, then we can send this one
  529. LogError("Command rejected");
  530. command.Restart();
  531. break;
  532. case CommandError:
  533. LogError("Command Error");
  534. // we shall probably transfer into the Idle state and await further instructions from the upper layer
  535. // Idle state may solve the problem of keeping up the heart beat running
  536. break;
  537. case VersionMismatch:
  538. LogError("Version mismatch");
  539. Stop(); // cannot continue
  540. break;
  541. case ProtocolError:
  542. currentStatus = HandleCommError("Protocol error", ProtocolError);
  543. break;
  544. case CommunicationTimeout:
  545. currentStatus = HandleCommError("Communication timeout", CommunicationTimeout);
  546. break;
  547. default:
  548. break;
  549. }
  550. return currentStatus;
  551. }
  552. uint8_t ProtocolLogic::CommandInProgress() const {
  553. if( currentState != &command )
  554. return 0;
  555. return (uint8_t)command.ReqMsg().code;
  556. }
  557. bool DropOutFilter::Record(StepStatus ss){
  558. if( occurrences == maxOccurrences ){
  559. cause = ss;
  560. }
  561. --occurrences;
  562. return occurrences == 0;
  563. }
  564. } // namespace MMU2