From a0ce103a16816c248adf081d82268c8a9d3b20d9 Mon Sep 17 00:00:00 2001 From: Klagarge Date: Wed, 24 Apr 2024 15:25:06 +0200 Subject: [PATCH] change way to send token --- checksum_read-true_table.txt | 2 +- mac_sender.c | 58 +++++++++++++++++++++--------------- tokenring_project.uvoptx | 42 ++++++++++++++++++++++++-- 3 files changed, 75 insertions(+), 27 deletions(-) diff --git a/checksum_read-true_table.txt b/checksum_read-true_table.txt index 8c70793..da63731 100644 --- a/checksum_read-true_table.txt +++ b/checksum_read-true_table.txt @@ -6,4 +6,4 @@ C R | 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 +From someone else -> Send back now \ No newline at end of file diff --git a/mac_sender.c b/mac_sender.c index d64e6f3..6f78500 100644 --- a/mac_sender.c +++ b/mac_sender.c @@ -6,13 +6,25 @@ #include uint8_t* lastToken; -uint8_t* lastSentMsgPtr[15]; +uint8_t* lastSentMsgPtr; osMessageQueueId_t queue_macData_id; const osMessageQueueAttr_t queue_macData_attr = { .name = "MAC_DATA" }; +void sendToken() { + struct queueMsg_t queueMsg; + queueMsg.anyPtr = lastToken; + queueMsg.type = TO_PHY; + osStatus_t retCode = osMessageQueuePut( + queue_phyS_id, + &queueMsg, + osPriorityNormal, + 0); + CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); +} + void MacSender(void *argument) { struct queueMsg_t queueMsg; // queue message uint8_t* msg; @@ -75,17 +87,9 @@ void MacSender(void *argument) { osPriorityNormal, 0); CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); + } else { + sendToken(); } - - // Send token - queueMsg.anyPtr = lastToken; - queueMsg.type = TO_PHY; - retCode = osMessageQueuePut( - queue_phyS_id, - &queueMsg, - osPriorityNormal, - 0); - CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); break; } @@ -101,8 +105,9 @@ void MacSender(void *argument) { if(dst.addr == BROADCAST_ADDRESS) { retCode = osMemoryPoolFree(memPool, queueMsg.anyPtr); CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); + sendToken(); } else if(src.addr != gTokenInterface.myAddress) { - // Send original message when token is here + queueMsg.type = TO_PHY; retCode = osMessageQueuePut( queue_phyS_id, @@ -116,14 +121,17 @@ void MacSender(void *argument) { // Everything is fine, free memory retCode = osMemoryPoolFree(memPool, queueMsg.anyPtr); CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); + sendToken(); } else { - // Checksum error, send original message again when token is here - if(lastSentMsgPtr[src.addr] != NULL) { - queueMsg.anyPtr = lastSentMsgPtr[src.addr]; + // Checksum error, send original message again + if(lastSentMsgPtr != NULL) { + retCode = osMemoryPoolFree(memPool, queueMsg.anyPtr); + CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); queueMsg.type = TO_PHY; + queueMsg.anyPtr = lastSentMsgPtr; retCode = osMessageQueuePut( - queue_macData_id, + queue_phyS_id, &queueMsg, osPriorityNormal, 0); @@ -132,7 +140,7 @@ void MacSender(void *argument) { } else { // Error, no original message found strPtr = osMemoryPoolAlloc(memPool, osWaitForever); - sprintf(strPtr, "Someone did shit on the ring #1\0"); + sprintf(strPtr, "%d did shit on the ring #1\0", dst.addr); queueMsg.type = MAC_ERROR; queueMsg.addr = src.addr; queueMsg.sapi = src.sapi; @@ -147,13 +155,7 @@ void MacSender(void *argument) { } } else { - // Send original message when token is here - queueMsg.type = TO_PHY; - retCode = osMessageQueuePut( - queue_macData_id, - &queueMsg, - osPriorityNormal, - 0); + retCode = osMemoryPoolFree(memPool, queueMsg.anyPtr); CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); // Send error message to LCD @@ -169,6 +171,8 @@ void MacSender(void *argument) { osPriorityNormal, 0); CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); + + sendToken(); } break; @@ -248,6 +252,12 @@ void MacSender(void *argument) { retCode = osMemoryPoolFree(memPool, queueMsg.anyPtr); CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); + + if(dst.addr != BROADCAST_ADDRESS) { + lastSentMsgPtr = osMemoryPoolAlloc(memPool, osWaitForever); + memcpy(lastSentMsgPtr, msg, length+4); + } + queueMsg.anyPtr = msg; queueMsg.type = TO_PHY; retCode = osMessageQueuePut( diff --git a/tokenring_project.uvoptx b/tokenring_project.uvoptx index 81e7b16..ee93c83 100644 --- a/tokenring_project.uvoptx +++ b/tokenring_project.uvoptx @@ -120,7 +120,7 @@ 0 EVENTREC_CNF - -l0 -a1 -s0 -f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 + -l2 -a1 -s0 -f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0 @@ -153,7 +153,40 @@ UL2CM3(-S0 -C0 -P0 -FD20010000 -FC1000 -FN1 -FF0STM32F7x_1024 -FS08000000 -FL0100000 -FP0($$Device:STM32F746NGHx$CMSIS\Flash\STM32F7x_1024.FLM)) - + + + 0 + 0 + 18 + 1 +
134311210
+ 0 + 0 + 0 + 0 + 0 + 1 + .\mac_receiver.c + + \\tokenring_project\mac_receiver.c\18 +
+ + 1 + 0 + 199 + 1 +
0
+ 0 + 0 + 0 + 0 + 0 + 0 + .\main.c + + +
+
0 @@ -175,6 +208,11 @@ 1 lastToken + + 4 + 1 + queue_macData_id +