Save some more RAM in protocol_logic
This commit is contained in:
parent
022aa53b2d
commit
0e036b9d8a
|
|
@ -24,6 +24,8 @@ void LogEchoEvent_P(const char *msg);
|
||||||
|
|
||||||
#define MMU2_ECHO_MSG(S) do{ SERIAL_ECHO_START; SERIAL_MMU2(); SERIAL_ECHO(S); }while(0)
|
#define MMU2_ECHO_MSG(S) do{ SERIAL_ECHO_START; SERIAL_MMU2(); SERIAL_ECHO(S); }while(0)
|
||||||
#define MMU2_ERROR_MSG(S) do{ SERIAL_ERROR_START; SERIAL_MMU2(); SERIAL_ECHO(S); }while(0)
|
#define MMU2_ERROR_MSG(S) do{ SERIAL_ERROR_START; SERIAL_MMU2(); SERIAL_ECHO(S); }while(0)
|
||||||
|
#define MMU2_ECHO_MSGRPGM(S) do{ SERIAL_ECHO_START; SERIAL_MMU2(); SERIAL_ECHORPGM(S); }while(0)
|
||||||
|
#define MMU2_ERROR_MSGRPGM(S) do{ SERIAL_ERROR_START; SERIAL_MMU2(); SERIAL_ECHORPGM(S); }while(0)
|
||||||
|
|
||||||
#else // #ifndef UNITTEST
|
#else // #ifndef UNITTEST
|
||||||
|
|
||||||
|
|
@ -31,5 +33,7 @@ void LogEchoEvent_P(const char *msg);
|
||||||
#define MMU2_ERROR_MSG(S) /* */
|
#define MMU2_ERROR_MSG(S) /* */
|
||||||
#define SERIAL_ECHO(S) /* */
|
#define SERIAL_ECHO(S) /* */
|
||||||
#define SERIAL_ECHOLN(S) /* */
|
#define SERIAL_ECHOLN(S) /* */
|
||||||
|
#define MMU2_ECHO_MSGRPGM(S) /* */
|
||||||
|
#define MMU2_ERROR_MSGRPGM(S) /* */
|
||||||
|
|
||||||
#endif // #ifndef UNITTEST
|
#endif // #ifndef UNITTEST
|
||||||
|
|
|
||||||
|
|
@ -598,7 +598,7 @@ void ProtocolLogic::LogRequestMsg(const uint8_t *txbuff, uint8_t size){
|
||||||
}
|
}
|
||||||
tmp[size+1] = '\n';
|
tmp[size+1] = '\n';
|
||||||
tmp[size+2] = 0;
|
tmp[size+2] = 0;
|
||||||
if( !strncmp(tmp, ">S0.\n", rqs) && !strncmp(lastMsg, tmp, rqs) ){
|
if( !strncmp_P(tmp, PSTR(">S0*99.\n"), rqs) && !strncmp(lastMsg, tmp, rqs) ){
|
||||||
// @@TODO we skip the repeated request msgs for now
|
// @@TODO we skip the repeated request msgs for now
|
||||||
// to avoid spoiling the whole log just with ">S0" messages
|
// to avoid spoiling the whole log just with ">S0" messages
|
||||||
// especially when the MMU is not connected.
|
// especially when the MMU is not connected.
|
||||||
|
|
@ -611,12 +611,12 @@ void ProtocolLogic::LogRequestMsg(const uint8_t *txbuff, uint8_t size){
|
||||||
memcpy(lastMsg, tmp, rqs);
|
memcpy(lastMsg, tmp, rqs);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProtocolLogic::LogError(const char *reason){
|
void ProtocolLogic::LogError(const char *reason_P){
|
||||||
char lrb[lastReceivedBytes.size() * 3];
|
char lrb[lastReceivedBytes.size() * 3];
|
||||||
FormatLastReceivedBytes(lrb);
|
FormatLastReceivedBytes(lrb);
|
||||||
|
|
||||||
MMU2_ERROR_MSG(reason);
|
MMU2_ERROR_MSGRPGM(reason_P);
|
||||||
SERIAL_ECHO(", last bytes: ");
|
SERIAL_ECHOPGM(", last bytes: ");
|
||||||
SERIAL_ECHOLN(lrb);
|
SERIAL_ECHOLN(lrb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -627,9 +627,9 @@ void ProtocolLogic::LogResponse(){
|
||||||
SERIAL_ECHOLN();
|
SERIAL_ECHOLN();
|
||||||
}
|
}
|
||||||
|
|
||||||
StepStatus ProtocolLogic::SuppressShortDropOuts(const char *msg, StepStatus ss) {
|
StepStatus ProtocolLogic::SuppressShortDropOuts(const char *msg_P, StepStatus ss) {
|
||||||
if( dataTO.Record(ss) ){
|
if( dataTO.Record(ss) ){
|
||||||
LogError(msg);
|
LogError(msg_P);
|
||||||
return dataTO.InitialCause();
|
return dataTO.InitialCause();
|
||||||
} else {
|
} else {
|
||||||
return Processing; // suppress short drop outs of communication
|
return Processing; // suppress short drop outs of communication
|
||||||
|
|
@ -640,7 +640,7 @@ StepStatus ProtocolLogic::HandleCommunicationTimeout() {
|
||||||
uart->flush(); // clear the output buffer
|
uart->flush(); // clear the output buffer
|
||||||
protocol.ResetResponseDecoder();
|
protocol.ResetResponseDecoder();
|
||||||
Start();
|
Start();
|
||||||
return SuppressShortDropOuts("Communication timeout", CommunicationTimeout);
|
return SuppressShortDropOuts(PSTR("Communication timeout"), CommunicationTimeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
StepStatus ProtocolLogic::HandleProtocolError() {
|
StepStatus ProtocolLogic::HandleProtocolError() {
|
||||||
|
|
@ -648,7 +648,7 @@ StepStatus ProtocolLogic::HandleProtocolError() {
|
||||||
state = State::InitSequence;
|
state = State::InitSequence;
|
||||||
currentState = &delayedRestart;
|
currentState = &delayedRestart;
|
||||||
delayedRestart.Restart();
|
delayedRestart.Restart();
|
||||||
return SuppressShortDropOuts("Protocol Error", ProtocolError);
|
return SuppressShortDropOuts(PSTR("Protocol Error"), ProtocolError);
|
||||||
}
|
}
|
||||||
|
|
||||||
StepStatus ProtocolLogic::Step() {
|
StepStatus ProtocolLogic::Step() {
|
||||||
|
|
@ -678,16 +678,16 @@ StepStatus ProtocolLogic::Step() {
|
||||||
// we have to repeat it - that's the only thing we can do
|
// we have to repeat it - that's the only thing we can do
|
||||||
// no change in state
|
// no change in state
|
||||||
// @@TODO wait until Q0 returns command in progress finished, then we can send this one
|
// @@TODO wait until Q0 returns command in progress finished, then we can send this one
|
||||||
LogError("Command rejected");
|
LogError(PSTR("Command rejected"));
|
||||||
command.Restart();
|
command.Restart();
|
||||||
break;
|
break;
|
||||||
case CommandError:
|
case CommandError:
|
||||||
LogError("Command Error");
|
LogError(PSTR("Command Error"));
|
||||||
// we shall probably transfer into the Idle state and await further instructions from the upper layer
|
// we shall probably transfer into the Idle state and await further instructions from the upper layer
|
||||||
// Idle state may solve the problem of keeping up the heart beat running
|
// Idle state may solve the problem of keeping up the heart beat running
|
||||||
break;
|
break;
|
||||||
case VersionMismatch:
|
case VersionMismatch:
|
||||||
LogError("Version mismatch");
|
LogError(PSTR("Version mismatch"));
|
||||||
Stop(); // cannot continue
|
Stop(); // cannot continue
|
||||||
break;
|
break;
|
||||||
case ProtocolError:
|
case ProtocolError:
|
||||||
|
|
|
||||||
|
|
@ -268,7 +268,7 @@ private:
|
||||||
StepStatus ExpectingMessage(uint32_t timeout);
|
StepStatus ExpectingMessage(uint32_t timeout);
|
||||||
void SendMsg(RequestMsg rq);
|
void SendMsg(RequestMsg rq);
|
||||||
void SwitchToIdle();
|
void SwitchToIdle();
|
||||||
StepStatus SuppressShortDropOuts(const char *msg, StepStatus ss);
|
StepStatus SuppressShortDropOuts(const char *msg_P, StepStatus ss);
|
||||||
StepStatus HandleCommunicationTimeout();
|
StepStatus HandleCommunicationTimeout();
|
||||||
StepStatus HandleProtocolError();
|
StepStatus HandleProtocolError();
|
||||||
bool Elapsed(uint32_t timeout) const;
|
bool Elapsed(uint32_t timeout) const;
|
||||||
|
|
@ -277,7 +277,7 @@ private:
|
||||||
void FormatLastReceivedBytes(char *dst);
|
void FormatLastReceivedBytes(char *dst);
|
||||||
void FormatLastResponseMsgAndClearLRB(char *dst);
|
void FormatLastResponseMsgAndClearLRB(char *dst);
|
||||||
void LogRequestMsg(const uint8_t *txbuff, uint8_t size);
|
void LogRequestMsg(const uint8_t *txbuff, uint8_t size);
|
||||||
void LogError(const char *reason);
|
void LogError(const char *reason_P);
|
||||||
void LogResponse();
|
void LogResponse();
|
||||||
void SwitchFromIdleToCommand();
|
void SwitchFromIdleToCommand();
|
||||||
void SwitchFromStartToIdle();
|
void SwitchFromStartToIdle();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue