Skip to content

Commit 7055fdb

Browse files
authored
Initial commit (#1325)
1 parent 910e09e commit 7055fdb

File tree

5 files changed

+68
-67
lines changed

5 files changed

+68
-67
lines changed

core/MyMessage.cpp

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@
2626

2727
MyMessage::MyMessage(void)
2828
{
29-
clear();
29+
this->clear();
3030
}
3131

3232
MyMessage::MyMessage(const uint8_t _sensorId, const mysensors_data_t _dataType)
3333
{
34-
clear();
35-
(void)setSensor(_sensorId);
36-
(void)setType(static_cast<uint8_t>(_dataType));
34+
this->clear();
35+
(void)this->setSensor(_sensorId);
36+
(void)this->setType(static_cast<uint8_t>(_dataType));
3737
}
3838

3939
void MyMessage::clear(void)
@@ -45,10 +45,11 @@ void MyMessage::clear(void)
4545
this->command_echo_payload = 0u;
4646
this->type = 0u;
4747
this->sensor = 0u;
48+
// clear data buffer
4849
(void)memset((void *)this->data, 0u, sizeof(this->data));
4950

5051
// set message protocol version
51-
(void)this->setVersion(PROTOCOL_VERSION);
52+
(void)this->setVersion();
5253
}
5354

5455
uint8_t MyMessage::getHeaderSize(void) const
@@ -68,17 +69,17 @@ uint8_t MyMessage::getExpectedMessageSize(void) const
6869

6970
bool MyMessage::isProtocolVersionValid(void) const
7071
{
71-
return (this->getVersion() == PROTOCOL_VERSION);
72+
return (this->getVersion() == V2_MYS_HEADER_PROTOCOL_VERSION);
7273
}
7374

7475
uint8_t MyMessage::getType(void) const
7576
{
7677
return this->type;
7778
}
7879

79-
MyMessage& MyMessage::setType(const uint8_t _messageType)
80+
MyMessage& MyMessage::setType(const uint8_t messageType)
8081
{
81-
this->type = _messageType;
82+
this->type = messageType;
8283
return *this;
8384
}
8485

@@ -87,9 +88,9 @@ uint8_t MyMessage::getLast(void) const
8788
return this->last;
8889
}
8990

90-
MyMessage& MyMessage::setLast(const uint8_t _lastId)
91+
MyMessage& MyMessage::setLast(const uint8_t lastId)
9192
{
92-
this->last = _lastId;
93+
this->last = lastId;
9394
return *this;
9495
}
9596

@@ -98,9 +99,9 @@ uint8_t MyMessage::getSender(void) const
9899
return this->sender;
99100
}
100101

101-
MyMessage& MyMessage::setSender(const uint8_t _senderId)
102+
MyMessage& MyMessage::setSender(const uint8_t senderId)
102103
{
103-
this->sender = _senderId;
104+
this->sender = senderId;
104105
return *this;
105106
}
106107

@@ -109,9 +110,9 @@ uint8_t MyMessage::getSensor(void) const
109110
return this->sensor;
110111
}
111112

112-
MyMessage& MyMessage::setSensor(const uint8_t _sensorId)
113+
MyMessage& MyMessage::setSensor(const uint8_t sensorId)
113114
{
114-
this->sensor = _sensorId;
115+
this->sensor = sensorId;
115116
return *this;
116117
}
117118

@@ -120,9 +121,9 @@ uint8_t MyMessage::getDestination(void) const
120121
return this->destination;
121122
}
122123

123-
MyMessage& MyMessage::setDestination(const uint8_t _destinationId)
124+
MyMessage& MyMessage::setDestination(const uint8_t destinationId)
124125
{
125-
this->destination = _destinationId;
126+
this->destination = destinationId;
126127
return *this;
127128
}
128129

@@ -138,9 +139,9 @@ bool MyMessage::isEcho(void) const
138139
V2_MYS_HEADER_CEP_ECHOEQUEST_SIZE);
139140
}
140141

141-
MyMessage& MyMessage::setEcho(const bool _echo)
142+
MyMessage& MyMessage::setEcho(const bool echo)
142143
{
143-
BF_SET(this->command_echo_payload, _echo, V2_MYS_HEADER_CEP_ECHOREQUEST_POS,
144+
BF_SET(this->command_echo_payload, echo, V2_MYS_HEADER_CEP_ECHOREQUEST_POS,
144145
V2_MYS_HEADER_CEP_ECHOEQUEST_SIZE);
145146
return *this;
146147
}
@@ -151,9 +152,9 @@ bool MyMessage::getRequestEcho(void) const
151152
V2_MYS_HEADER_CEP_ECHO_SIZE);
152153
}
153154

154-
MyMessage& MyMessage::setRequestEcho(const bool _requestEcho)
155+
MyMessage& MyMessage::setRequestEcho(const bool requestEcho)
155156
{
156-
BF_SET(this->command_echo_payload, _requestEcho, V2_MYS_HEADER_CEP_ECHO_POS,
157+
BF_SET(this->command_echo_payload, requestEcho, V2_MYS_HEADER_CEP_ECHO_POS,
157158
V2_MYS_HEADER_CEP_ECHO_SIZE);
158159
return *this;
159160
}
@@ -164,9 +165,9 @@ uint8_t MyMessage::getVersion(void) const
164165
V2_MYS_HEADER_VSL_VERSION_SIZE);
165166
}
166167

167-
MyMessage& MyMessage::setVersion(const uint8_t _version)
168+
MyMessage& MyMessage::setVersion(void)
168169
{
169-
BF_SET(this->version_length, _version, V2_MYS_HEADER_VSL_VERSION_POS,
170+
BF_SET(this->version_length, V2_MYS_HEADER_PROTOCOL_VERSION, V2_MYS_HEADER_VSL_VERSION_POS,
170171
V2_MYS_HEADER_VSL_VERSION_SIZE);
171172
return *this;
172173
}
@@ -177,9 +178,9 @@ mysensors_command_t MyMessage::getCommand(void) const
177178
V2_MYS_HEADER_CEP_COMMAND_POS, V2_MYS_HEADER_CEP_COMMAND_SIZE));
178179
}
179180

180-
MyMessage& MyMessage::setCommand(const mysensors_command_t _command)
181+
MyMessage& MyMessage::setCommand(const mysensors_command_t command)
181182
{
182-
BF_SET(this->command_echo_payload, static_cast<uint8_t>(_command), V2_MYS_HEADER_CEP_COMMAND_POS,
183+
BF_SET(this->command_echo_payload, static_cast<uint8_t>(command), V2_MYS_HEADER_CEP_COMMAND_POS,
183184
V2_MYS_HEADER_CEP_COMMAND_SIZE);
184185
return *this;
185186
}
@@ -190,9 +191,9 @@ mysensors_payload_t MyMessage::getPayloadType(void) const
190191
V2_MYS_HEADER_CEP_PAYLOADTYPE_POS, V2_MYS_HEADER_CEP_PAYLOADTYPE_SIZE));
191192
}
192193

193-
MyMessage& MyMessage::setPayloadType(const mysensors_payload_t _payloadType)
194+
MyMessage& MyMessage::setPayloadType(const mysensors_payload_t payloadType)
194195
{
195-
BF_SET(this->command_echo_payload, static_cast<uint8_t>(_payloadType),
196+
BF_SET(this->command_echo_payload, static_cast<uint8_t>(payloadType),
196197
V2_MYS_HEADER_CEP_PAYLOADTYPE_POS, V2_MYS_HEADER_CEP_PAYLOADTYPE_SIZE);
197198
return *this;
198199
}
@@ -203,9 +204,10 @@ bool MyMessage::getSigned(void) const
203204
V2_MYS_HEADER_VSL_SIGNED_SIZE);
204205
}
205206

206-
MyMessage& MyMessage::setSigned(const bool _signed)
207+
MyMessage& MyMessage::setSigned(const bool signedFlag)
207208
{
208-
BF_SET(this->version_length, _signed, V2_MYS_HEADER_VSL_SIGNED_POS, V2_MYS_HEADER_VSL_SIGNED_SIZE);
209+
BF_SET(this->version_length, signedFlag, V2_MYS_HEADER_VSL_SIGNED_POS,
210+
V2_MYS_HEADER_VSL_SIGNED_SIZE);
209211
return *this;
210212
}
211213

@@ -220,15 +222,16 @@ uint8_t MyMessage::getLength(void) const
220222
return length;
221223
}
222224

223-
MyMessage& MyMessage::setLength(const uint8_t _length)
225+
MyMessage& MyMessage::setLength(const uint8_t length)
224226
{
225-
uint8_t length = _length;
227+
uint8_t finalLength = length;
226228
// limit length
227-
if (length > MAX_PAYLOAD_SIZE) {
228-
length = MAX_PAYLOAD_SIZE;
229+
if (finalLength > MAX_PAYLOAD_SIZE) {
230+
finalLength = MAX_PAYLOAD_SIZE;
229231
}
230232

231-
BF_SET(this->version_length, length, V2_MYS_HEADER_VSL_LENGTH_POS, V2_MYS_HEADER_VSL_LENGTH_SIZE);
233+
BF_SET(this->version_length, finalLength, V2_MYS_HEADER_VSL_LENGTH_POS,
234+
V2_MYS_HEADER_VSL_LENGTH_SIZE);
232235
return *this;
233236
}
234237

core/MyMessage.h

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
#define V2_MYS_HEADER_CEP_PAYLOADTYPE_POS (5u) //!< bitfield position payload type field
5757
#define V2_MYS_HEADER_CEP_PAYLOADTYPE_SIZE (3u) //!< size payload type field
5858

59-
#define PROTOCOL_VERSION V2_MYS_HEADER_PROTOCOL_VERSION //!< The version of the protocol
6059
#define MAX_MESSAGE_SIZE V2_MYS_HEADER_MAX_MESSAGE_SIZE //!< The maximum size of a message (including header)
6160
#define HEADER_SIZE V2_MYS_HEADER_SIZE //!< The size of the header
6261
#define MAX_PAYLOAD_SIZE (MAX_MESSAGE_SIZE - HEADER_SIZE) //!< The maximum size of a payload depends on #MAX_MESSAGE_SIZE and #HEADER_SIZE
@@ -301,10 +300,10 @@ class MyMessage
301300

302301
/**
303302
* Constructor
304-
* @param _sensorId id of the child sensor for this message
305-
* @param _dataType
303+
* @param sensorId id of the child sensor for this message
304+
* @param dataType
306305
*/
307-
MyMessage(const uint8_t _sensorId, const mysensors_data_t _dataType);
306+
MyMessage(const uint8_t sensorId, const mysensors_data_t dataType);
308307

309308
/**
310309
* @brief Clear message contents.
@@ -396,7 +395,6 @@ class MyMessage
396395
*/
397396
uint8_t getExpectedMessageSize(void) const;
398397

399-
400398
/**
401399
* @brief isProtocolVersionValid
402400
* @return true if the protocol version is valid
@@ -411,9 +409,9 @@ class MyMessage
411409

412410
/**
413411
* @brief Setter for echo request
414-
* @param _requestEcho
412+
* @param requestEcho
415413
*/
416-
MyMessage& setRequestEcho(const bool _requestEcho);
414+
MyMessage& setRequestEcho(const bool requestEcho);
417415

418416
/**
419417
* @brief Getter for version
@@ -423,9 +421,8 @@ class MyMessage
423421

424422
/**
425423
* @brief Setter for version
426-
* @param _version
427424
*/
428-
MyMessage& setVersion(const uint8_t _version);
425+
MyMessage& setVersion(void);
429426

430427
/**
431428
* @brief Getter for length
@@ -435,9 +432,9 @@ class MyMessage
435432

436433
/**
437434
* @brief Setter for length
438-
* @param _length
435+
* @param length
439436
*/
440-
MyMessage& setLength(const uint8_t _length);
437+
MyMessage& setLength(const uint8_t length);
441438

442439
/**
443440
* @brief Getter for command type
@@ -447,9 +444,9 @@ class MyMessage
447444

448445
/**
449446
* @brief Setter for command type
450-
* @param _command
447+
* @param command
451448
*/
452-
MyMessage& setCommand(const mysensors_command_t _command);
449+
MyMessage& setCommand(const mysensors_command_t command);
453450

454451
/**
455452
* @brief Getter for payload type
@@ -459,9 +456,9 @@ class MyMessage
459456

460457
/**
461458
* @brief Setter for payload type
462-
* @param _payloadType
459+
* @param payloadType
463460
*/
464-
MyMessage& setPayloadType(const mysensors_payload_t _payloadType);
461+
MyMessage& setPayloadType(const mysensors_payload_t payloadType);
465462

466463
/**
467464
* @brief Getter for sign field
@@ -471,9 +468,9 @@ class MyMessage
471468

472469
/**
473470
* @brief Setter for sign field
474-
* @param _signed
471+
* @param signedFlag
475472
*/
476-
MyMessage& setSigned(const bool _signed);
473+
MyMessage& setSigned(const bool signedFlag);
477474

478475
/**
479476
* \deprecated use isEcho()
@@ -490,9 +487,9 @@ class MyMessage
490487

491488
/**
492489
* @brief Setter for echo-flag.
493-
* @param _echo true if this an echo message
490+
* @param echo true if this an echo message
494491
*/
495-
MyMessage& setEcho(const bool _echo);
492+
MyMessage& setEcho(const bool echo);
496493

497494
/**
498495
* @brief Get message type
@@ -502,9 +499,9 @@ class MyMessage
502499

503500
/**
504501
* @brief Set message type
505-
* @param _messageType
502+
* @param messageType
506503
*/
507-
MyMessage& setType(const uint8_t _messageType);
504+
MyMessage& setType(const uint8_t messageType);
508505

509506
/**
510507
* @brief Get last ID
@@ -514,9 +511,9 @@ class MyMessage
514511

515512
/**
516513
* @brief Set last ID
517-
* @param _lastId
514+
* @param lastId
518515
*/
519-
MyMessage& setLast(const uint8_t _lastId);
516+
MyMessage& setLast(const uint8_t lastId);
520517

521518
/**
522519
* @brief Get sender ID
@@ -526,9 +523,9 @@ class MyMessage
526523

527524
/**
528525
* @brief Set sender ID
529-
* @param _senderId
526+
* @param senderId
530527
*/
531-
MyMessage& setSender(const uint8_t _senderId);
528+
MyMessage& setSender(const uint8_t senderId);
532529

533530
/**
534531
* @brief Get sensor ID of message
@@ -538,9 +535,9 @@ class MyMessage
538535

539536
/**
540537
* @brief Set which child sensor this message belongs to
541-
* @param _sensorId
538+
* @param sensorId
542539
*/
543-
MyMessage& setSensor(const uint8_t _sensorId);
540+
MyMessage& setSensor(const uint8_t sensorId);
544541

545542
/**
546543
* @brief Get destination
@@ -550,16 +547,16 @@ class MyMessage
550547

551548
/**
552549
* @brief Set final destination node id for this message
553-
* @param _destinationId
550+
* @param destinationId
554551
*/
555-
MyMessage& setDestination(const uint8_t _destinationId);
552+
MyMessage& setDestination(const uint8_t destinationId);
556553

557554
/**
558555
* @brief Set entire payload
559556
* @param payload pointer to the buffer where the payload is stored
560-
* @param _length of the payload
557+
* @param length of the payload
561558
*/
562-
MyMessage& set(const void* payload, const size_t _length);
559+
MyMessage& set(const void* payload, const size_t length);
563560

564561
/**
565562
* @brief Set payload to character array

core/MyTransport.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,7 @@ void transportProcessFIFO(void)
968968
bool transportSendWrite(const uint8_t to, MyMessage &message)
969969
{
970970
message.setLast(_transportConfig.nodeId); // Update last
971+
971972
// sign message if required
972973
if (!signerSignMsg(message)) {
973974
TRANSPORT_DEBUG(PSTR("!TSF:MSG:SIGN FAIL\n"));

hal/transport/MyTransportHAL.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ bool transportHALReceive(MyMessage *inMsg, uint8_t *msgLength)
115115
MyMessage tmp = *inMsg;
116116
if (!tmp.isProtocolVersionValid()) {
117117
setIndication(INDICATION_ERR_VERSION);
118-
TRANSPORT_HAL_DEBUG(PSTR("!THA:RCV:PVER,%" PRIu8 "!=%" PRIu8 "\n"), tmp.getVersion(),
119-
PROTOCOL_VERSION); // protocol version mismatch
118+
TRANSPORT_HAL_DEBUG(PSTR("!THA:RCV:PVER=%" PRIu8 "\n"),
119+
tmp.getVersion()); // protocol version mismatch
120120
return false;
121121
}
122122
*msgLength = tmp.getLength();

0 commit comments

Comments
 (0)