small refactor
- put unions on main for usage on several file - add DATA_IND on sender
This commit is contained in:
70
mac_sender.c
70
mac_sender.c
@@ -10,7 +10,12 @@ const osMessageQueueAttr_t queue_macData_attr = {
|
||||
void MacSender(void *argument) {
|
||||
struct queueMsg_t queueMsg; // queue message
|
||||
uint8_t* msg;
|
||||
Adresse src;
|
||||
Adresse dst;
|
||||
uint8_t length;
|
||||
Status status;
|
||||
osStatus_t retCode; // return error code
|
||||
char* strPtr;
|
||||
|
||||
lastToken = osMemoryPoolAlloc(memPool, osWaitForever);
|
||||
queue_macData_id = osMessageQueueNew(4, sizeof(struct queueMsg_t), &queue_macData_attr);
|
||||
@@ -54,8 +59,8 @@ void MacSender(void *argument) {
|
||||
osWaitForever);
|
||||
CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE);
|
||||
|
||||
// Send msg from internal queue if exist
|
||||
while (osMemoryPoolGetCount(queue_macData_id) != 0) { // Message in Queue
|
||||
// Send one msg from internal queue if exist
|
||||
if (osMemoryPoolGetCount(queue_macData_id) != 0) { // Message in Queue
|
||||
retCode = osMessageQueueGet(
|
||||
queue_macData_id,
|
||||
&queueMsg,
|
||||
@@ -87,7 +92,35 @@ void MacSender(void *argument) {
|
||||
// DATABACK MESSAGE
|
||||
//----------------------------------------------------------------------
|
||||
case DATABACK: {
|
||||
src.raw = msg[0];
|
||||
dst.raw = msg[1];
|
||||
length = msg[2];
|
||||
status.raw = msg[3+length];
|
||||
|
||||
if(status.read == 0) {
|
||||
if(status.ack == 0) {
|
||||
msg = osMemoryPoolAlloc(memPool, osWaitForever);
|
||||
queueMsg.type = TO_PHY;
|
||||
queueMsg.anyPtr =
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
strPtr = osMemoryPoolAlloc(memPool, osWaitForever);
|
||||
sprintf(strPtr, "Dest. %d couldn't read message from %d\0", dst.add+1, src.addr+1);
|
||||
queueMsg.type = MAC_ERROR;
|
||||
queueMsg.addr = src.addr;
|
||||
queueMsg.sapi = src.sapi;
|
||||
queueMsg.anyPtr = strPtr;
|
||||
retCode = osMessageQueuePut(
|
||||
queue_lcd_id,
|
||||
&queueMsg,
|
||||
osPriorityNormal,
|
||||
osWaitForever);
|
||||
CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -135,7 +168,40 @@ void MacSender(void *argument) {
|
||||
// DATA MESSAGE
|
||||
//----------------------------------------------------------------------
|
||||
case DATA_IND: {
|
||||
dst.addr = queueMsg.addr;
|
||||
dst.sapi = queueMsg.sapi;
|
||||
dst.nothing = 0;
|
||||
src.addr = gTokenInterface.myAddress;
|
||||
src.sapi = queueMsg.sapi;
|
||||
src.nothing = 0;
|
||||
length = strlen(queueMsg.anyPtr);
|
||||
|
||||
if(dst.addr == BROADCAST_ADDRESS) {
|
||||
status.read = 1;
|
||||
status.ack = 1;
|
||||
} else {
|
||||
status.read = 0;
|
||||
status.ack = 0;
|
||||
}
|
||||
|
||||
msg = osMemoryPoolAlloc(memPool, osWaitForever);
|
||||
msg[0] = src.raw;
|
||||
msg[1] = dst.raw;
|
||||
msg[2] = length;
|
||||
memcpy(&msg[3], queueMsg.anyPtr, length);
|
||||
status.checksum = Checksum(msg);
|
||||
msg[3+length] = status.raw;
|
||||
|
||||
retCode = osMemoryPoolFree(memPool, queueMsg.anyPtr);
|
||||
CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE);
|
||||
queueMsg.anyPtr = msg;
|
||||
queueMsg.type = TO_PHY;
|
||||
retCode = osMessageQueuePut(
|
||||
queue_macData_id,
|
||||
&queueMsg,
|
||||
osPriorityNormal,
|
||||
osWaitForever);
|
||||
CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user