mmu2_protocol_logic.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  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::Finished:
  217. logic->progressCode = ProgressCode::OK;
  218. state = State::Ready;
  219. return Finished;
  220. default:
  221. return ProtocolError;
  222. }
  223. break;
  224. case State::FilamentSensorStateSent:{
  225. auto expmsg = logic->ExpectingMessage(linkLayerTimeout);
  226. if (expmsg != MessageReady)
  227. return expmsg;
  228. SendFINDAQuery();
  229. } break;
  230. case State::FINDAReqSent:
  231. return ProcessFINDAReqSent(Processing, State::Wait);
  232. case State::ButtonSent:{
  233. // button is never confirmed ... may be it should be
  234. // auto expmsg = logic->ExpectingMessage(linkLayerTimeout);
  235. // if (expmsg != MessageReady)
  236. // return expmsg;
  237. SendQuery();
  238. } break;
  239. default:
  240. return ProtocolError;
  241. }
  242. return Processing;
  243. }
  244. void Idle::Restart() {
  245. state = State::Ready;
  246. }
  247. StepStatus Idle::Step() {
  248. switch (state) {
  249. case State::Ready: // check timeout
  250. if (logic->Elapsed(heartBeatPeriod)) {
  251. SendQuery();
  252. return Processing;
  253. }
  254. break;
  255. case State::QuerySent: { // check UART
  256. auto expmsg = logic->ExpectingMessage(linkLayerTimeout);
  257. if (expmsg != MessageReady)
  258. return expmsg;
  259. // 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.
  260. // That causes no issues here, we just need to switch to Command processing and continue there from now on.
  261. // 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.
  262. switch( logic->rsp.request.code ){
  263. case RequestMsgCodes::Cut:
  264. case RequestMsgCodes::Eject:
  265. case RequestMsgCodes::Load:
  266. case RequestMsgCodes::Mode:
  267. case RequestMsgCodes::Tool:
  268. case RequestMsgCodes::Unload:
  269. if( logic->rsp.paramCode != ResponseMsgParamCodes::Finished ){
  270. logic->SwitchFromIdleToCommand();
  271. return Processing;
  272. }
  273. break;
  274. case RequestMsgCodes::Reset:
  275. // this one is kind of special
  276. // we do not transfer to any "running" command (i.e. we stay in Idle),
  277. // but in case there is an error reported we must make sure it gets propagated
  278. if( logic->rsp.paramCode != ResponseMsgParamCodes::Finished ){
  279. logic->errorCode = static_cast<ErrorCode>(logic->rsp.paramValue);
  280. SendFINDAQuery(); // continue Idle state without restarting the communication
  281. return CommandError;
  282. } else {
  283. logic->errorCode = ErrorCode::OK;
  284. }
  285. break;
  286. default:
  287. break;
  288. }
  289. SendFINDAQuery();
  290. return Processing;
  291. } break;
  292. case State::FINDAReqSent:
  293. return ProcessFINDAReqSent(Finished, State::Ready);
  294. default:
  295. return ProtocolError;
  296. }
  297. // The "return Finished" in this state machine requires a bit of explanation:
  298. // The Idle state either did nothing (still waiting for the heartbeat timeout)
  299. // or just successfully received the answer to Q0, whatever that was.
  300. // In both cases, it is ready to hand over work to a command or something else,
  301. // therefore we are returning Finished (also to exit mmu_loop() and unblock Marlin's loop!).
  302. // If there is no work, we'll end up in the Idle state again
  303. // and we'll send the heartbeat message after the specified timeout.
  304. return Finished;
  305. }
  306. ProtocolLogic::ProtocolLogic(MMU2Serial *uart)
  307. : stopped(this)
  308. , startSeq(this)
  309. , idle(this)
  310. , command(this)
  311. , currentState(&stopped)
  312. , plannedRq(RequestMsgCodes::unknown, 0)
  313. , lastUARTActivityMs(0)
  314. , rsp(RequestMsg(RequestMsgCodes::unknown, 0), ResponseMsgParamCodes::unknown, 0)
  315. , state(State::Stopped)
  316. , lrb(0)
  317. , uart(uart)
  318. , lastFSensor((uint8_t)WhereIsFilament())
  319. {}
  320. void ProtocolLogic::Start() {
  321. state = State::InitSequence;
  322. currentState = &startSeq;
  323. startSeq.Restart();
  324. }
  325. void ProtocolLogic::Stop() {
  326. state = State::Stopped;
  327. currentState = &stopped;
  328. }
  329. void ProtocolLogic::ToolChange(uint8_t slot) {
  330. PlanGenericRequest(RequestMsg(RequestMsgCodes::Tool, slot));
  331. }
  332. void ProtocolLogic::UnloadFilament() {
  333. PlanGenericRequest(RequestMsg(RequestMsgCodes::Unload, 0));
  334. }
  335. void ProtocolLogic::LoadFilament(uint8_t slot) {
  336. PlanGenericRequest(RequestMsg(RequestMsgCodes::Load, slot));
  337. }
  338. void ProtocolLogic::EjectFilament(uint8_t slot) {
  339. PlanGenericRequest(RequestMsg(RequestMsgCodes::Eject, slot));
  340. }
  341. void ProtocolLogic::CutFilament(uint8_t slot){
  342. PlanGenericRequest(RequestMsg(RequestMsgCodes::Cut, slot));
  343. }
  344. void ProtocolLogic::ResetMMU() {
  345. PlanGenericRequest(RequestMsg(RequestMsgCodes::Reset, 0));
  346. }
  347. void ProtocolLogic::Button(uint8_t index){
  348. PlanGenericRequest(RequestMsg(RequestMsgCodes::Button, index));
  349. }
  350. void ProtocolLogic::Home(uint8_t mode){
  351. PlanGenericRequest(RequestMsg(RequestMsgCodes::Home, mode));
  352. }
  353. void ProtocolLogic::PlanGenericRequest(RequestMsg rq) {
  354. plannedRq = rq;
  355. if( ! currentState->ExpectsResponse() ){
  356. ActivatePlannedRequest();
  357. } // otherwise wait for an empty window to activate the request
  358. }
  359. bool ProtocolLogic::ActivatePlannedRequest(){
  360. if( plannedRq.code == RequestMsgCodes::Button ){
  361. // only issue the button to the MMU and do not restart the state machines
  362. // @@TODO - this is not completely correct, but it does the job.
  363. // In Idle mode the command part is not active, but we still need button handling in Idle mode (resolve MMU init errors)
  364. // -> command.SendButton is not correct, but it sends the message and everything works (for now)
  365. command.SendButton(plannedRq.value);
  366. plannedRq = RequestMsg(RequestMsgCodes::unknown, 0);
  367. return true;
  368. } else if( plannedRq.code != RequestMsgCodes::unknown ){
  369. currentState = &command;
  370. command.SetRequestMsg(plannedRq);
  371. plannedRq = RequestMsg(RequestMsgCodes::unknown, 0);
  372. command.Restart();
  373. return true;
  374. }
  375. return false;
  376. }
  377. void ProtocolLogic::SwitchFromIdleToCommand(){
  378. currentState = &command;
  379. command.SetRequestMsg(rsp.request);
  380. // we are recovering from a communication drop out, the command is already running
  381. // and we have just received a response to a Q0 message about a command progress
  382. command.ContinueFromIdle();
  383. }
  384. void ProtocolLogic::SwitchToIdle() {
  385. state = State::Running;
  386. currentState = &idle;
  387. idle.Restart();
  388. }
  389. void ProtocolLogic::HandleCommunicationTimeout() {
  390. uart->flush(); // clear the output buffer
  391. currentState = &startSeq;
  392. state = State::InitSequence;
  393. startSeq.Restart();
  394. }
  395. bool ProtocolLogic::Elapsed(uint32_t timeout) const {
  396. return _millis() >= (lastUARTActivityMs + timeout);
  397. }
  398. void ProtocolLogic::RecordUARTActivity() {
  399. lastUARTActivityMs = _millis();
  400. }
  401. void ProtocolLogic::RecordReceivedByte(uint8_t c){
  402. lastReceivedBytes[lrb] = c;
  403. lrb = (lrb+1) % lastReceivedBytes.size();
  404. }
  405. constexpr char NibbleToChar(uint8_t c){
  406. switch (c) {
  407. case 0:
  408. case 1:
  409. case 2:
  410. case 3:
  411. case 4:
  412. case 5:
  413. case 6:
  414. case 7:
  415. case 8:
  416. case 9:
  417. return c + '0';
  418. case 10:
  419. case 11:
  420. case 12:
  421. case 13:
  422. case 14:
  423. case 15:
  424. return (c - 10) + 'a';
  425. default:
  426. return 0;
  427. }
  428. }
  429. void ProtocolLogic::FormatLastReceivedBytes(char *dst){
  430. for(uint8_t i = 0; i < lastReceivedBytes.size(); ++i){
  431. uint8_t b = lastReceivedBytes[ (lrb-i-1) % lastReceivedBytes.size() ];
  432. dst[i*3] = NibbleToChar(b >> 4);
  433. dst[i*3+1] = NibbleToChar(b & 0xf);
  434. dst[i*3+2] = ' ';
  435. }
  436. dst[ (lastReceivedBytes.size() - 1) * 3 + 2] = 0; // terminate properly
  437. }
  438. void ProtocolLogic::FormatLastResponseMsgAndClearLRB(char *dst){
  439. *dst++ = '<';
  440. for(uint8_t i = 0; i < lrb; ++i){
  441. uint8_t b = lastReceivedBytes[ i ];
  442. if( b < 32 )b = '.';
  443. if( b > 127 )b = '.';
  444. *dst++ = b;
  445. }
  446. *dst = 0; // terminate properly
  447. lrb = 0; // reset the input buffer index in case of a clean message
  448. }
  449. void ProtocolLogic::LogRequestMsg(const uint8_t *txbuff, uint8_t size){
  450. constexpr uint_fast8_t rqs = modules::protocol::Protocol::MaxRequestSize() + 2;
  451. char tmp[rqs] = ">";
  452. static char lastMsg[rqs] = "";
  453. for(uint8_t i = 0; i < size; ++i){
  454. uint8_t b = txbuff[i];
  455. if( b < 32 )b = '.';
  456. if( b > 127 )b = '.';
  457. tmp[i+1] = b;
  458. }
  459. tmp[size+1] = '\n';
  460. tmp[size+2] = 0;
  461. if( !strncmp(tmp, ">S0.\n", rqs) && !strncmp(lastMsg, tmp, rqs) ){
  462. // @@TODO we skip the repeated request msgs for now
  463. // to avoid spoiling the whole log just with ">S0" messages
  464. // especially when the MMU is not connected.
  465. // We'll lose the ability to see if the printer is actually
  466. // trying to find the MMU, but since it has been reliable in the past
  467. // we can live without it for now.
  468. } else {
  469. MMU2_ECHO_MSG(tmp);
  470. }
  471. memcpy(lastMsg, tmp, rqs);
  472. }
  473. void ProtocolLogic::LogError(const char *reason){
  474. char lrb[lastReceivedBytes.size() * 3];
  475. FormatLastReceivedBytes(lrb);
  476. MMU2_ERROR_MSG(reason);
  477. SERIAL_ECHO(", last bytes: ");
  478. SERIAL_ECHOLN(lrb);
  479. }
  480. void ProtocolLogic::LogResponse(){
  481. char lrb[lastReceivedBytes.size()];
  482. FormatLastResponseMsgAndClearLRB(lrb);
  483. MMU2_ECHO_MSG(lrb);
  484. SERIAL_ECHOLN();
  485. }
  486. StepStatus ProtocolLogic::HandleCommError(const char *msg, StepStatus ss){
  487. protocol.ResetResponseDecoder();
  488. HandleCommunicationTimeout();
  489. if( dataTO.Record(ss) ){
  490. LogError(msg);
  491. return dataTO.InitialCause();
  492. } else {
  493. return Processing; // suppress short drop outs of communication
  494. }
  495. }
  496. StepStatus ProtocolLogic::Step() {
  497. if( ! currentState->ExpectsResponse() ){ // if not waiting for a response, activate a planned request immediately
  498. ActivatePlannedRequest();
  499. }
  500. auto currentStatus = currentState->Step();
  501. switch (currentStatus) {
  502. case Processing:
  503. // we are ok, the state machine continues correctly
  504. break;
  505. case Finished: {
  506. // We are ok, switching to Idle if there is no potential next request planned.
  507. // But the trouble is we must report a finished command if the previous command has just been finished
  508. // i.e. only try to find some planned command if we just finished the Idle cycle
  509. bool previousCommandFinished = currentState == &command; // @@TODO this is a nasty hack :(
  510. if( ! ActivatePlannedRequest() ){ // if nothing is planned, switch to Idle
  511. SwitchToIdle();
  512. } else {
  513. // if the previous cycle was Idle and now we have planned a new command -> avoid returning Finished
  514. if( ! previousCommandFinished && currentState == &command){
  515. currentStatus = Processing;
  516. }
  517. }
  518. }
  519. break;
  520. case CommandRejected:
  521. // we have to repeat it - that's the only thing we can do
  522. // no change in state
  523. // @@TODO wait until Q0 returns command in progress finished, then we can send this one
  524. LogError("Command rejected");
  525. command.Restart();
  526. break;
  527. case CommandError:
  528. LogError("Command Error");
  529. // we shall probably transfer into the Idle state and await further instructions from the upper layer
  530. // Idle state may solve the problem of keeping up the heart beat running
  531. break;
  532. case VersionMismatch:
  533. LogError("Version mismatch");
  534. Stop(); // cannot continue
  535. break;
  536. case ProtocolError:
  537. currentStatus = HandleCommError("Protocol error", ProtocolError);
  538. break;
  539. case CommunicationTimeout:
  540. currentStatus = HandleCommError("Communication timeout", CommunicationTimeout);
  541. break;
  542. default:
  543. break;
  544. }
  545. return currentStatus;
  546. }
  547. uint8_t ProtocolLogic::CommandInProgress() const {
  548. if( currentState != &command )
  549. return 0;
  550. return (uint8_t)command.ReqMsg().code;
  551. }
  552. bool DropOutFilter::Record(StepStatus ss){
  553. if( occurrences == maxOccurrences ){
  554. cause = ss;
  555. }
  556. --occurrences;
  557. return occurrences == 0;
  558. }
  559. } // namespace MMU2