Skip to content

Commit

Permalink
com: remove non-const char overload of sendMsg
Browse files Browse the repository at this point in the history
Casting `char *` to `const char *` is a safe conversion that the compiler
performs automatically.
  • Loading branch information
jonathanperret authored and dl1com committed Jul 23, 2024
1 parent e960ad4 commit 72f113d
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 17 deletions.
5 changes: 1 addition & 4 deletions src/ayab/com.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,7 @@ void Com::sendMsg(AYAB_API_t id, const char *msg) {
while (*msg) {
msgBuffer[length++] = static_cast<uint8_t>(*msg++);
}
m_packetSerial.send(msgBuffer, length);
}
void Com::sendMsg(AYAB_API_t id, char *msg) {
sendMsg(id, static_cast<const char *>(msg));
send(msgBuffer, length);
}

/*!
Expand Down
3 changes: 0 additions & 3 deletions src/ayab/com.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ class ComInterface {
virtual void update() = 0;
virtual void send(uint8_t *payload, size_t length) const = 0;
virtual void sendMsg(AYAB_API_t id, const char *msg) = 0;
virtual void sendMsg(AYAB_API_t id, char *msg) = 0;
virtual void send_reqLine(const uint8_t lineNumber,
Err_t error = ErrorCode::success) const = 0;
virtual void send_indState(Carriage_t carriage, uint8_t position,
Expand All @@ -113,7 +112,6 @@ class GlobalCom final {
static void update();
static void send(uint8_t *payload, size_t length);
static void sendMsg(AYAB_API_t id, const char *msg);
static void sendMsg(AYAB_API_t id, char *msg);
static void send_reqLine(const uint8_t lineNumber, Err_t error = ErrorCode::success);
static void send_indState(Carriage_t carriage, uint8_t position,
Err_t error = ErrorCode::success);
Expand All @@ -129,7 +127,6 @@ class Com : public ComInterface {
void update() final;
void send(uint8_t *payload, size_t length) const final;
void sendMsg(AYAB_API_t id, const char *msg) final;
void sendMsg(AYAB_API_t id, char *msg) final;
void send_reqLine(const uint8_t lineNumber, Err_t error = ErrorCode::success) const final;
void send_indState(Carriage_t carriage, uint8_t position,
Err_t error = ErrorCode::success) const final;
Expand Down
4 changes: 0 additions & 4 deletions src/ayab/global_com.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ void GlobalCom::sendMsg(AYAB_API_t id, const char *msg) {
m_instance->sendMsg(id, msg);
}

void GlobalCom::sendMsg(AYAB_API_t id, char *msg) {
m_instance->sendMsg(id, msg);
}

// GCOVR_EXCL_START
void GlobalCom::onPacketReceived(const uint8_t *buffer, size_t size) {
m_instance->onPacketReceived(buffer, size);
Expand Down
5 changes: 0 additions & 5 deletions test/mocks/com_mock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ void Com::sendMsg(AYAB_API_t id, const char *msg) {
gComMock->sendMsg(id, msg);
}

void Com::sendMsg(AYAB_API_t id, char *msg) {
assert(gComMock != nullptr);
gComMock->sendMsg(id, msg);
}

void Com::send_reqLine(const uint8_t lineNumber, Err_t error) const {
assert(gComMock != nullptr);
gComMock->send_reqLine(lineNumber, error);
Expand Down
1 change: 0 additions & 1 deletion test/mocks/com_mock.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class ComMock : public ComInterface {
MOCK_METHOD0(update, void());
MOCK_CONST_METHOD2(send, void(uint8_t *payload, size_t length));
MOCK_METHOD2(sendMsg, void(AYAB_API_t id, const char *msg));
MOCK_METHOD2(sendMsg, void(AYAB_API_t id, char *msg));
MOCK_CONST_METHOD2(send_reqLine, void(const uint8_t lineNumber, Err_t error));
MOCK_CONST_METHOD3(send_indState, void(Carriage_t carriage, uint8_t position,
Err_t error));
Expand Down

0 comments on commit 72f113d

Please sign in to comment.