diff options
author | David Crocker <dcrocker@eschertech.com> | 2021-01-30 14:30:48 +0300 |
---|---|---|
committer | David Crocker <dcrocker@eschertech.com> | 2021-01-30 14:30:48 +0300 |
commit | 54bad5a44f7149c39208251f51abae9b72ea7488 (patch) | |
tree | 6a932acd33e5441e5f9d54bcffc14a605448136d /src/CAN | |
parent | 85d61cbdb48ffdb566b3b80eaaf85cd76a780d13 (diff) |
CanInterface::WriteGpio no longer throws (for ATE)
Diffstat (limited to 'src/CAN')
-rw-r--r-- | src/CAN/CanInterface.cpp | 28 | ||||
-rw-r--r-- | src/CAN/CanInterface.h | 2 |
2 files changed, 19 insertions, 11 deletions
diff --git a/src/CAN/CanInterface.cpp b/src/CAN/CanInterface.cpp index 7a7a922e..56f4177a 100644 --- a/src/CAN/CanInterface.cpp +++ b/src/CAN/CanInterface.cpp @@ -57,6 +57,8 @@ constexpr float MinJumpWidth = 0.05; constexpr float MaxJumpWidth = 0.5; constexpr float DefaultJumpWidth = 0.25; +constexpr const char *NoCanBufferMessage = "no CAN buffer available"; + static uint32_t lastTimeSent = 0; static uint32_t longestWaitTime = 0; static uint16_t longestWaitMessageType = 0; @@ -506,7 +508,7 @@ CanMessageBuffer *CanInterface::AllocateBuffer(const GCodeBuffer* gb) THROWS(GCo CanMessageBuffer * const buf = CanMessageBuffer::Allocate(); if (buf == nullptr) { - throw GCodeException((gb == nullptr) ? -1 : gb->GetLineNumber(), -1, "no CAN buffer"); + throw GCodeException((gb == nullptr) ? -1 : gb->GetLineNumber(), -1, NoCanBufferMessage); } return buf; } @@ -764,7 +766,7 @@ template<class T> static GCodeResult SetRemoteDriverValues(const CanDriversData< CanMessageBuffer * const buf = CanMessageBuffer::Allocate(); if (buf == nullptr) { - reply.lcat("No CAN buffer available"); + reply.lcat(NoCanBufferMessage); return GCodeResult::error; } const CanRequestId rid = CanInterface::AllocateRequestId(boardAddress); @@ -796,7 +798,7 @@ static GCodeResult SetRemoteDriverStates(const CanDriversList& drivers, const St CanMessageBuffer * const buf = CanMessageBuffer::Allocate(); if (buf == nullptr) { - reply.lcat("No CAN buffer available"); + reply.lcat(NoCanBufferMessage); return GCodeResult::error; } const CanRequestId rid = CanInterface::AllocateRequestId(boardAddress); @@ -1120,7 +1122,7 @@ static GCodeResult GetRemoteInfo(uint8_t infoType, uint32_t boardAddress, uint8_ CanMessageBuffer * const buf = CanMessageBuffer::Allocate(); if (buf == nullptr) { - reply.copy("No CAN buffer available"); + reply.copy(NoCanBufferMessage); return GCodeResult::error; } @@ -1212,7 +1214,7 @@ GCodeResult CanInterface::CreateHandle(CanAddress boardAddress, RemoteInputHandl CanMessageBuffer * const buf = CanMessageBuffer::Allocate(); if (buf == nullptr) { - reply.copy("No CAN buffer"); + reply.copy(NoCanBufferMessage); return GCodeResult::error; } @@ -1244,7 +1246,7 @@ static GCodeResult ChangeInputMonitor(CanAddress boardAddress, RemoteInputHandle CanMessageBuffer * const buf = CanMessageBuffer::Allocate(); if (buf == nullptr) { - reply.copy("No CAN buffer"); + reply.copy(NoCanBufferMessage); return GCodeResult::error; } @@ -1284,10 +1286,10 @@ GCodeResult CanInterface::ChangeHandleResponseTime(CanAddress boardAddress, Remo GCodeResult CanInterface::ReadRemoteHandles(CanAddress boardAddress, RemoteInputHandle mask, RemoteInputHandle pattern, ReadHandlesCallbackFunction callback, const StringRef &reply) noexcept { - CanMessageBuffer *buf = CanMessageBuffer::Allocate(); + CanMessageBuffer * const buf = CanMessageBuffer::Allocate(); if (buf == nullptr) { - reply.copy("No CAN buffer"); + reply.copy(NoCanBufferMessage); return GCodeResult::error; } @@ -1330,9 +1332,15 @@ void CanInterface::Diagnostics(MessageType mtype) noexcept longestWaitMessageType = 0; } -GCodeResult CanInterface::WriteGpio(CanAddress boardAddress, uint8_t portNumber, float pwm, bool isServo, const GCodeBuffer* gb, const StringRef &reply) THROWS(GCodeException) +GCodeResult CanInterface::WriteGpio(CanAddress boardAddress, uint8_t portNumber, float pwm, bool isServo, const GCodeBuffer* gb, const StringRef &reply) noexcept { - CanMessageBuffer * const buf = AllocateBuffer(gb); + CanMessageBuffer * const buf = CanMessageBuffer::Allocate(); + if (buf == nullptr) + { + reply.copy(NoCanBufferMessage); + return GCodeResult::error; + } + const CanRequestId rid = CanInterface::AllocateRequestId(boardAddress); auto msg = buf->SetupRequestMessage<CanMessageWriteGpio>(rid, GetCanAddress(), boardAddress); msg->portNumber = portNumber; diff --git a/src/CAN/CanInterface.h b/src/CAN/CanInterface.h index 2a3b24ec..4789e84d 100644 --- a/src/CAN/CanInterface.h +++ b/src/CAN/CanInterface.h @@ -125,7 +125,7 @@ namespace CanInterface GCodeResult DeleteFilamentMonitor(DriverId driver, GCodeBuffer* gb, const StringRef& reply) noexcept; // called from a destructor, so must not throw // Misc functions - GCodeResult WriteGpio(CanAddress boardAddress, uint8_t portNumber, float pwm, bool isServo, const GCodeBuffer *gb, const StringRef& reply) THROWS(GCodeException); + GCodeResult WriteGpio(CanAddress boardAddress, uint8_t portNumber, float pwm, bool isServo, const GCodeBuffer *gb, const StringRef& reply) noexcept; GCodeResult ChangeAddressAndNormalTiming(GCodeBuffer& gb, const StringRef& reply) THROWS(GCodeException); GCodeResult ChangeFastTiming(GCodeBuffer& gb, const StringRef& reply) THROWS(GCodeException); } |