Skip to content

Commit a0500c4

Browse files
committed
Use defined values
1 parent 7587e99 commit a0500c4

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

hal/transport/CAN/MyTransportCAN.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#define CAN_CLOCK MCP_8MHZ
2323
MCP_CAN CAN0(CAN_CS); // TODO make configurable
2424
//since long messages can be sliced and arrive mixed with other messages assemble buffer is required
25-
#define bufSize 8 //TODO make configurable
25+
#define CAN_BUF_SIZE 8 //TODO make configurable
2626
bool canInitialized=false;
2727

2828
//input buffer for raw data (from library).
@@ -36,7 +36,7 @@ unsigned char _nodeId;
3636
//buffer element
3737
typedef struct {
3838
uint8_t len;
39-
uint8_t data[32];
39+
uint8_t data[MAX_MESSAGE_SIZE];
4040
uint8_t address;
4141
uint8_t lastReceivedPart;
4242
bool locked;
@@ -45,7 +45,7 @@ typedef struct {
4545
bool ready;
4646
} CAN_Packet;
4747

48-
CAN_Packet packets[bufSize];
48+
CAN_Packet packets[CAN_BUF_SIZE];
4949

5050
//filter incoming messages (MCP2515 feature)
5151
void _initFilters() {
@@ -73,7 +73,7 @@ bool transportInit(void)
7373
return false;
7474
}
7575
canInitialized=true;
76-
for (uint8_t i = 0; i < bufSize; i++) {
76+
for (uint8_t i = 0; i < CAN_BUF_SIZE; i++) {
7777
_cleanSlot(i);
7878
}
7979
_initFilters();
@@ -94,20 +94,20 @@ void _cleanSlot(uint8_t slot) {
9494

9595
//find empty slot in buffer
9696
uint8_t _findCanPacketSlot() {
97-
uint8_t slot=bufSize;
97+
uint8_t slot=CAN_BUF_SIZE;
9898
uint8_t i;
99-
for (i = 0; i < bufSize; i++) {
99+
for (i = 0; i < CAN_BUF_SIZE; i++) {
100100
if(packets[i].locked) {
101101
packets[i].age++;
102102
} else {
103103
slot=i;
104104
}
105105
}
106-
if(slot<bufSize)
106+
if(slot < CAN_BUF_SIZE)
107107
return slot;
108108
//if empty slot not found. Clear oldest message.
109109
slot=0;
110-
for (i = 1; i < bufSize; i++) {
110+
for (i = 1; i < CAN_BUF_SIZE; i++) {
111111
if(packets[i].age>packets[slot].age) {
112112
slot=i;
113113
}
@@ -119,14 +119,14 @@ uint8_t _findCanPacketSlot() {
119119

120120
//find slot with previous data parts.
121121
uint8_t _findCanPacketSlot(long unsigned int from,long unsigned int currentPart,long unsigned int messageId){
122-
uint8_t slot=bufSize;
122+
uint8_t slot=CAN_BUF_SIZE;
123123
uint8_t i;
124-
for (i = 0; i < bufSize; i++) {
124+
for (i = 0; i < CAN_BUF_SIZE; i++) {
125125
if(packets[i].locked && packets[i].address==from && packets[i].packetId==messageId && packets[i].lastReceivedPart==currentPart+1) {
126126
slot=i;
127127
}
128128
}
129-
if (slot==bufSize) {
129+
if (slot == CAN_BUF_SIZE) {
130130
//log error. Received message id not found in buffer.
131131
}
132132
return slot;
@@ -217,7 +217,7 @@ bool transportDataAvailable(void)
217217
} else {
218218
slot=_findCanPacketSlot(from,currentPart,messageId);
219219
}
220-
if (slot!=bufSize) {
220+
if (slot != CAN_BUF_SIZE) {
221221
memcpy(packets[slot].data + packets[slot].len, rxBuf, len);
222222
packets[slot].lastReceivedPart++;
223223
packets[slot].len += len;
@@ -234,14 +234,14 @@ bool transportDataAvailable(void)
234234
}
235235
uint8_t transportReceive(void* data)
236236
{
237-
uint8_t slot=bufSize;
237+
uint8_t slot=CAN_BUF_SIZE;
238238
uint8_t i;
239-
for (i = 0; i < bufSize; i++) {
239+
for (i = 0; i < CAN_BUF_SIZE; i++) {
240240
if(packets[i].ready) {
241241
slot=i;
242242
}
243243
}
244-
if (slot<bufSize) {
244+
if (slot < CAN_BUF_SIZE) {
245245
memcpy(data,packets[slot].data,packets[slot].len);
246246
i=packets[slot].len;
247247
_cleanSlot(slot);

0 commit comments

Comments
 (0)