change way to send token
This commit is contained in:
parent
d5e1467b3f
commit
a0ce103a16
@ -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
|
||||
From someone else -> Send back now
|
58
mac_sender.c
58
mac_sender.c
@ -6,13 +6,25 @@
|
||||
#include <cassert>
|
||||
|
||||
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(
|
||||
|
@ -120,7 +120,7 @@
|
||||
<SetRegEntry>
|
||||
<Number>0</Number>
|
||||
<Key>EVENTREC_CNF</Key>
|
||||
<Name>-l0 -a1 -s0 -f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000</Name>
|
||||
<Name>-l2 -a1 -s0 -f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000</Name>
|
||||
</SetRegEntry>
|
||||
<SetRegEntry>
|
||||
<Number>0</Number>
|
||||
@ -153,7 +153,40 @@
|
||||
<Name>UL2CM3(-S0 -C0 -P0 -FD20010000 -FC1000 -FN1 -FF0STM32F7x_1024 -FS08000000 -FL0100000 -FP0($$Device:STM32F746NGHx$CMSIS\Flash\STM32F7x_1024.FLM))</Name>
|
||||
</SetRegEntry>
|
||||
</TargetDriverDllRegistry>
|
||||
<Breakpoint/>
|
||||
<Breakpoint>
|
||||
<Bp>
|
||||
<Number>0</Number>
|
||||
<Type>0</Type>
|
||||
<LineNumber>18</LineNumber>
|
||||
<EnabledFlag>1</EnabledFlag>
|
||||
<Address>134311210</Address>
|
||||
<ByteObject>0</ByteObject>
|
||||
<HtxType>0</HtxType>
|
||||
<ManyObjects>0</ManyObjects>
|
||||
<SizeOfObject>0</SizeOfObject>
|
||||
<BreakByAccess>0</BreakByAccess>
|
||||
<BreakIfRCount>1</BreakIfRCount>
|
||||
<Filename>.\mac_receiver.c</Filename>
|
||||
<ExecCommand></ExecCommand>
|
||||
<Expression>\\tokenring_project\mac_receiver.c\18</Expression>
|
||||
</Bp>
|
||||
<Bp>
|
||||
<Number>1</Number>
|
||||
<Type>0</Type>
|
||||
<LineNumber>199</LineNumber>
|
||||
<EnabledFlag>1</EnabledFlag>
|
||||
<Address>0</Address>
|
||||
<ByteObject>0</ByteObject>
|
||||
<HtxType>0</HtxType>
|
||||
<ManyObjects>0</ManyObjects>
|
||||
<SizeOfObject>0</SizeOfObject>
|
||||
<BreakByAccess>0</BreakByAccess>
|
||||
<BreakIfRCount>0</BreakIfRCount>
|
||||
<Filename>.\main.c</Filename>
|
||||
<ExecCommand></ExecCommand>
|
||||
<Expression></Expression>
|
||||
</Bp>
|
||||
</Breakpoint>
|
||||
<WatchWindow1>
|
||||
<Ww>
|
||||
<count>0</count>
|
||||
@ -175,6 +208,11 @@
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>lastToken</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>4</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>queue_macData_id</ItemText>
|
||||
</Ww>
|
||||
</WatchWindow1>
|
||||
<MemoryWindow1>
|
||||
<Mm>
|
||||
|
Reference in New Issue
Block a user