diff --git a/checksum_read-true_table.txt b/checksum_read-true_table.txt new file mode 100644 index 0000000..8c70793 --- /dev/null +++ b/checksum_read-true_table.txt @@ -0,0 +1,9 @@ +From me +C R | +-------------- +0 0 | Station isn't on the ring -> Error msg on lcd +0 1 | Received message but checksum not ok -> Send again +1 0 | Sapi on the station isn't connected -> Error msg on lcd +1 1 | Everything all right -> free + +Frome someone else -> Send back now \ No newline at end of file diff --git a/mac_receiver.c b/mac_receiver.c index 9743296..63e8e09 100644 --- a/mac_receiver.c +++ b/mac_receiver.c @@ -105,7 +105,6 @@ void MacReceiver(void *argument) { &queueMsg, osPriorityNormal, osWaitForever); - printf("Token received\r\n"); CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); } else { @@ -127,7 +126,7 @@ void MacReceiver(void *argument) { status.ack = 1; if(dst.sapi == CHAT_SAPI && gTokenInterface.connected || - dst.sapi == TIME_SAPI && gTokenInterface.broadcastTime) { + dst.sapi == TIME_SAPI) { // Send to Time or Chat ---------------------------- send_DATA_IND(src, dst, queueMsg.anyPtr); status.read = 1; @@ -152,7 +151,7 @@ void MacReceiver(void *argument) { } else { // for me but bad checksum status.ack = 0; - status.read = 0; + status.read = gTokenInterface.connected; // Maybe it's 1 msg[3+length] = status.raw; send_DATABACK(src, dst, queueMsg.anyPtr); } diff --git a/mac_sender.c b/mac_sender.c index 7afc154..d64e6f3 100644 --- a/mac_sender.c +++ b/mac_sender.c @@ -1,10 +1,13 @@ #include "main.h" #include #include +#include #include #include uint8_t* lastToken; +uint8_t* lastSentMsgPtr[15]; + osMessageQueueId_t queue_macData_id; const osMessageQueueAttr_t queue_macData_attr = { .name = "MAC_DATA" @@ -60,7 +63,6 @@ void MacSender(void *argument) { &queueMsg, osPriorityNormal, osWaitForever); - printf("Token sended\r\n"); CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); // Send one msg from internal queue if exist @@ -99,18 +101,53 @@ void MacSender(void *argument) { if(dst.addr == BROADCAST_ADDRESS) { retCode = osMemoryPoolFree(memPool, queueMsg.anyPtr); CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); + } else if(src.addr != gTokenInterface.myAddress) { + // Send original message when token is here + queueMsg.type = TO_PHY; + retCode = osMessageQueuePut( + queue_phyS_id, + &queueMsg, + osPriorityNormal, + 0); + CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); + } else if(status.read == 1) { - if(status.ack == 0) { - msg = osMemoryPoolAlloc(memPool, osWaitForever); - queueMsg.type = TO_PHY; - //queueMsg.anyPtr = + if(status.ack == 1) { + // Everything is fine, free memory + retCode = osMemoryPoolFree(memPool, queueMsg.anyPtr); + CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); } else { + // Checksum error, send original message again when token is here + if(lastSentMsgPtr[src.addr] != NULL) { + queueMsg.anyPtr = lastSentMsgPtr[src.addr]; + queueMsg.type = TO_PHY; + retCode = osMessageQueuePut( + queue_macData_id, + &queueMsg, + osPriorityNormal, + 0); + CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); + } else { + // Error, no original message found + strPtr = osMemoryPoolAlloc(memPool, osWaitForever); + sprintf(strPtr, "Someone did shit on the ring #1\0"); + queueMsg.type = MAC_ERROR; + queueMsg.addr = src.addr; + queueMsg.sapi = src.sapi; + queueMsg.anyPtr = strPtr; + retCode = osMessageQueuePut( + queue_lcd_id, + &queueMsg, + osPriorityNormal, + 0); + CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); + } } } else { - // Send original message to PHY + // Send original message when token is here queueMsg.type = TO_PHY; retCode = osMessageQueuePut( queue_macData_id, @@ -133,7 +170,6 @@ void MacSender(void *argument) { 0); CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); } - } break; } diff --git a/main.c b/main.c index fc7af14..817b00e 100644 --- a/main.c +++ b/main.c @@ -354,8 +354,7 @@ uint32_t HAL_GetTick(void) ////////////////////////////////////////////////////////////////////////////////// /// \brief Init all and start RTX5 ////////////////////////////////////////////////////////////////////////////////// -int main(void) -{ +int main(void) { SystemClock_Config(); EventRecorderInitialize(EventRecordAll,0);