From 35b3457585b92b57076a7f567bc013f7580ae0e5 Mon Sep 17 00:00:00 2001 From: Klagarge Date: Wed, 24 Apr 2024 20:54:35 +0200 Subject: [PATCH] add sapi check online --- mac_sender.c | 32 +++++++++++++++++--- tokenring_project.uvoptx | 63 ++++++++++++++++++++++++++++++++++++++- tokenring_project.uvprojx | 2 +- 3 files changed, 91 insertions(+), 6 deletions(-) diff --git a/mac_sender.c b/mac_sender.c index 709ddbd..0ddf248 100644 --- a/mac_sender.c +++ b/mac_sender.c @@ -34,6 +34,7 @@ void MacSender(void *argument) { Status status; osStatus_t retCode; // return error code char* strPtr; + SapiToken stationStatus; lastToken = osMemoryPoolAlloc(memPool, osWaitForever); queue_macData_id = osMessageQueueNew(4, sizeof(struct queueMsg_t), &queue_macData_attr); @@ -79,7 +80,9 @@ void MacSender(void *argument) { // Send one msg from internal queue if exist //if (osMemoryPoolGetCount(queue_macData_id) != 0) { // Message in Queue - if(osMessageQueueGet(queue_macData_id, &queueMsg, NULL, 0) == 0){ + retCode = osMessageQueueGet(queue_macData_id, &queueMsg, NULL, 0); + CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); + if(retCode == 0){ queueMsg.type = TO_PHY; retCode = osMessageQueuePut( queue_phyS_id, @@ -102,7 +105,7 @@ void MacSender(void *argument) { length = msg[2]; status.raw = msg[3+length]; - if(dst.addr == BROADCAST_ADDRESS) { + if (dst.addr == BROADCAST_ADDRESS) { retCode = osMemoryPoolFree(memPool, queueMsg.anyPtr); CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); sendToken(); @@ -121,6 +124,8 @@ void MacSender(void *argument) { // Everything is fine, free memory retCode = osMemoryPoolFree(memPool, queueMsg.anyPtr); CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); + retCode = osMemoryPoolFree(memPool, lastSentMsgPtr); + CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); sendToken(); } else { @@ -129,7 +134,7 @@ void MacSender(void *argument) { //retCode = osMemoryPoolFree(memPool, queueMsg.anyPtr); //CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); - memcpy(queueMsg.anyPtr, lastSentMsgPtr, sizeof(lastSentMsgPtr)); + memcpy(queueMsg.anyPtr, lastSentMsgPtr, lastSentMsgPtr[2]+4); queueMsg.type = TO_PHY; //queueMsg.anyPtr = lastSentMsgPtr; retCode = osMessageQueuePut( @@ -240,7 +245,7 @@ void MacSender(void *argument) { status.ack = 0; } - msg = osMemoryPoolAlloc(memPool, 0); // TODO - Leak of memory + msg = osMemoryPoolAlloc(memPool, 0); if(msg == NULL) { printf("Memory allocation failed #1\r\n"); assert(false); @@ -255,6 +260,10 @@ void MacSender(void *argument) { 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) { lastSentMsgPtr = osMemoryPoolAlloc(memPool, 0); @@ -275,6 +284,21 @@ void MacSender(void *argument) { osPriorityNormal, 0); CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); + + } else { + strPtr = queueMsg.anyPtr; + sprintf(strPtr, "%d is not online\0", dst.addr+1); + queueMsg.type = MAC_ERROR; + queueMsg.addr = src.addr; + queueMsg.anyPtr = strPtr; + retCode = osMessageQueuePut( + queue_lcd_id, + &queueMsg, + osPriorityNormal, + 0); + CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); + } + break; } diff --git a/tokenring_project.uvoptx b/tokenring_project.uvoptx index ca70f24..c11daa1 100644 --- a/tokenring_project.uvoptx +++ b/tokenring_project.uvoptx @@ -153,7 +153,56 @@ UL2CM3(-S0 -C0 -P0 -FD20010000 -FC1000 -FN1 -FF0STM32F7x_1024 -FS08000000 -FL0100000 -FP0($$Device:STM32F746NGHx$CMSIS\Flash\STM32F7x_1024.FLM)) - + + + 0 + 0 + 18 + 1 +
134311438
+ 0 + 0 + 0 + 0 + 0 + 1 + .\mac_receiver.c + + \\tokenring_project\mac_receiver.c\18 +
+ + 1 + 0 + 263 + 1 +
134256140
+ 0 + 0 + 0 + 0 + 0 + 1 + .\mac_sender.c + + \\tokenring_project\mac_sender.c\263 +
+ + 2 + 0 + 199 + 1 +
0
+ 0 + 0 + 0 + 0 + 0 + 0 + .\main.c + + +
+
0 @@ -175,6 +224,11 @@ 1 lastToken + + 4 + 1 + memPool + @@ -244,6 +298,13 @@ + + + 0 + `memPool + FF00000000000000000000000000E0FFFFFFEF41000000000000000000000000000000006D656D506F6F6C000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000001000000000000000000F03F1000000000000000000000000000000000000000726D0108 + + 1 0 diff --git a/tokenring_project.uvprojx b/tokenring_project.uvprojx index 0ad19f1..6099233 100644 --- a/tokenring_project.uvprojx +++ b/tokenring_project.uvprojx @@ -10,7 +10,7 @@ Target 1 0x4 ARM-ADS - 5060960::V5.06 update 7 (build 960)::..\..\Program Files (x86)\ARM_Compiler_5.06u7 + 5060960::V5.06 update 7 (build 960)::C:\Program Files (x86)\ARM_Compiler_5.06u7 0