From ecf4b3617e729f95bbf005bc351b4c065ec90163 Mon Sep 17 00:00:00 2001 From: Klagarge Date: Thu, 25 Apr 2024 14:59:15 +0200 Subject: [PATCH] finish project --- mac_sender.c | 77 ++++++++++++++++++++-------------------- tokenring_project.uvoptx | 40 ++++++++++++++++++--- 2 files changed, 75 insertions(+), 42 deletions(-) diff --git a/mac_sender.c b/mac_sender.c index 0ddf248..ee4a558 100644 --- a/mac_sender.c +++ b/mac_sender.c @@ -81,7 +81,7 @@ void MacSender(void *argument) { // Send one msg from internal queue if exist //if (osMemoryPoolGetCount(queue_macData_id) != 0) { // Message in Queue retCode = osMessageQueueGet(queue_macData_id, &queueMsg, NULL, 0); - CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); + //CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); if(retCode == 0){ queueMsg.type = TO_PHY; retCode = osMessageQueuePut( @@ -237,35 +237,37 @@ void MacSender(void *argument) { 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, 0); - if(msg == NULL) { - printf("Memory allocation failed #1\r\n"); - assert(false); - } - 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); - - stationStatus.raw = lastToken[dst.addr+1]; - - if(stationStatus.chat == 1) { - if(dst.addr != BROADCAST_ADDRESS) { - if(dst.sapi == CHAT_SAPI) { + stationStatus.raw = gTokenInterface.station_list[dst.addr]; + } + + if( (stationStatus.chat == 1) || (dst.addr == BROADCAST_ADDRESS)) { + + if(dst.addr == BROADCAST_ADDRESS) { + status.read = 1; + status.ack = 1; + } else { + status.read = 0; + status.ack = 0; + } + + msg = osMemoryPoolAlloc(memPool, 0); + if(msg == NULL) { + printf("Memory allocation failed #1\r\n"); + assert(false); + } + 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); + + + if( (dst.addr != BROADCAST_ADDRESS) && (dst.sapi == CHAT_SAPI) ) { lastSentMsgPtr = osMemoryPoolAlloc(memPool, 0); if(lastSentMsgPtr == NULL) { printf("Memory allocation failed #2\r\n"); @@ -274,16 +276,15 @@ void MacSender(void *argument) { memcpy(lastSentMsgPtr, msg, length+4); // TODO test if station is online } - } - queueMsg.anyPtr = msg; - queueMsg.type = TO_PHY; - retCode = osMessageQueuePut( - queue_macData_id, - &queueMsg, - osPriorityNormal, - 0); - CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); + queueMsg.anyPtr = msg; + queueMsg.type = TO_PHY; + retCode = osMessageQueuePut( + queue_macData_id, + &queueMsg, + osPriorityNormal, + 0); + CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); } else { strPtr = queueMsg.anyPtr; diff --git a/tokenring_project.uvoptx b/tokenring_project.uvoptx index c11daa1..b18b2c9 100644 --- a/tokenring_project.uvoptx +++ b/tokenring_project.uvoptx @@ -159,7 +159,7 @@ 0 18 1 -
134311438
+
134311450
0 0 0 @@ -173,9 +173,9 @@ 1 0 - 263 + 264 1 -
134256140
+
134256144
0 0 0 @@ -184,11 +184,43 @@ 1 .\mac_sender.c - \\tokenring_project\mac_sender.c\263 + \\tokenring_project\mac_sender.c\264
2 0 + 86 + 1 +
134255102
+ 0 + 0 + 0 + 0 + 0 + 1 + .\mac_sender.c + + \\tokenring_project\mac_sender.c\86 +
+ + 3 + 0 + 199 + 1 +
0
+ 0 + 0 + 0 + 0 + 0 + 0 + .\mac_sender.c + + +
+ + 4 + 0 199 1
0