add TOKEN in macSender
This commit is contained in:
		
							
								
								
									
										105
									
								
								mac_sender.c
									
									
									
									
									
								
							
							
						
						
									
										105
									
								
								mac_sender.c
									
									
									
									
									
								
							| @@ -1,10 +1,20 @@ | |||||||
| #include "main.h" | #include "main.h" | ||||||
| void MacSender(void *argument) | #include <string.h> | ||||||
| { |  | ||||||
| 	// TODO | uint8_t* lastToken; | ||||||
|  | osMessageQueueId_t queue_macData_id; | ||||||
|  | const osMessageQueueAttr_t queue_macData_attr = { | ||||||
|  | 	.name = "MAC_DATA" | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | void MacSender(void *argument) { | ||||||
| 	struct queueMsg_t queueMsg;	// queue message | 	struct queueMsg_t queueMsg;	// queue message | ||||||
| 	uint8_t* msg; | 	uint8_t* msg; | ||||||
| 	osStatus_t retCode;					// return error code | 	osStatus_t retCode;					// return error code | ||||||
|  |  | ||||||
|  | 	lastToken = osMemoryPoolAlloc(memPool, osWaitForever); | ||||||
|  | 	queue_macData_id = osMessageQueueNew(4, sizeof(struct queueMsg_t), &queue_macData_attr); | ||||||
|  |  | ||||||
| 	 | 	 | ||||||
| 	for(;;) { | 	for(;;) { | ||||||
| 		//---------------------------------------------------------------------------- | 		//---------------------------------------------------------------------------- | ||||||
| @@ -16,15 +26,50 @@ void MacSender(void *argument) | |||||||
| 			NULL, | 			NULL, | ||||||
| 			osWaitForever); | 			osWaitForever); | ||||||
| 		CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); | 		CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); | ||||||
|  | 		 | ||||||
| 		msg = queueMsg.anyPtr; | 		msg = queueMsg.anyPtr; | ||||||
| 		 | 		 | ||||||
| 		switch(queueMsg.type) { | 		switch(queueMsg.type) { | ||||||
| 			 | 			 | ||||||
| 			case TOKEN: | 			case TOKEN: { | ||||||
| 				msg[gTokenInterface.myAddress] = gTokenInterface.station_list[gTokenInterface.myAddress]; | 				// Get token and save it | ||||||
| 				for(uint8_t i = 1; i < TOKENSIZE-2; i++) { | 				memcpy(lastToken, msg, TOKENSIZE-2); | ||||||
| 					gTokenInterface.station_list[i] = msg[i]; |  | ||||||
|  | 				// update token | ||||||
|  | 				lastToken[gTokenInterface.myAddress+1] = (0x1 << TIME_SAPI) + (gTokenInterface.connected << CHAT_SAPI); | ||||||
|  | 				for(uint8_t i = 1; i < sizeof(gTokenInterface.station_list); i++) { | ||||||
|  | 					gTokenInterface.station_list[i-1] = lastToken[i]; | ||||||
| 				} | 				} | ||||||
|  |  | ||||||
|  | 				// send to lcd | ||||||
|  | 				queueMsg.type = TOKEN_LIST; | ||||||
|  | 				queueMsg.anyPtr = lastToken; | ||||||
|  | 				retCode = osMessageQueuePut( | ||||||
|  | 					queue_lcd_id, | ||||||
|  | 					&queueMsg, | ||||||
|  | 					osPriorityNormal, | ||||||
|  | 					osWaitForever); | ||||||
|  | 				CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); | ||||||
|  |  | ||||||
|  | 				// Send msg from internal queue if exist | ||||||
|  | 				while (osMemoryPoolGetCount(queue_macData_id) != 0) { // Message in Queue | ||||||
|  | 					retCode = osMessageQueueGet( | ||||||
|  | 						queue_macData_id, | ||||||
|  | 						&queueMsg, | ||||||
|  | 						NULL, | ||||||
|  | 						osWaitForever); | ||||||
|  | 					CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); | ||||||
|  | 					queueMsg.type = TO_PHY; | ||||||
|  | 					retCode = osMessageQueuePut( | ||||||
|  | 						queue_phyS_id, | ||||||
|  | 						&queueMsg, | ||||||
|  | 						osPriorityNormal, | ||||||
|  | 						osWaitForever); | ||||||
|  | 					CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); | ||||||
|  | 				} | ||||||
|  |  | ||||||
|  | 				// Send token | ||||||
|  | 				queueMsg.anyPtr = lastToken; | ||||||
| 				queueMsg.type = TO_PHY; | 				queueMsg.type = TO_PHY; | ||||||
| 				retCode = osMessageQueuePut( | 				retCode = osMessageQueuePut( | ||||||
| 					queue_phyS_id, | 					queue_phyS_id, | ||||||
| @@ -33,25 +78,26 @@ void MacSender(void *argument) | |||||||
| 					osWaitForever); | 					osWaitForever); | ||||||
| 				CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); | 				CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); | ||||||
| 				break; | 				break; | ||||||
|  | 			} | ||||||
| 			 | 			 | ||||||
| 			 | 			 | ||||||
| 			case DATABACK:  | 			case DATABACK: { | ||||||
| 				 |  | ||||||
| 				break; | 				break; | ||||||
|  | 			} | ||||||
| 			 | 			 | ||||||
| 			 | 			 | ||||||
| 			case NEW_TOKEN:  | 			case NEW_TOKEN: { | ||||||
| 				msg = osMemoryPoolAlloc(memPool, osWaitForever); | 				lastToken[0] = TOKEN_TAG; | ||||||
| 				msg[0] = TOKEN_TAG; |  | ||||||
| 				 | 				 | ||||||
| 				for(uint8_t i = 1; i < sizeof(TOKENSIZE-2); i++) { | 				for(uint8_t i = 1; i < sizeof(TOKENSIZE-2); i++) { | ||||||
| 					msg[i] = 0; | 					lastToken[i] = 0; | ||||||
| 				} | 				} | ||||||
| 				gTokenInterface.station_list[gTokenInterface.myAddress] = (0x1 << TIME_SAPI) + (gTokenInterface.connected << CHAT_SAPI); | 				gTokenInterface.station_list[gTokenInterface.myAddress] = (0x1 << TIME_SAPI) + (gTokenInterface.connected << CHAT_SAPI); | ||||||
| 				msg[gTokenInterface.myAddress+1] = gTokenInterface.station_list[gTokenInterface.myAddress]; | 				lastToken[gTokenInterface.myAddress+1] = gTokenInterface.station_list[gTokenInterface.myAddress]; | ||||||
| 				 | 				 | ||||||
| 				queueMsg.type = TO_PHY; | 				queueMsg.type = TO_PHY; | ||||||
| 				queueMsg.anyPtr = msg; | 				queueMsg.anyPtr = lastToken; | ||||||
| 				 | 				 | ||||||
| 				retCode = osMessageQueuePut( | 				retCode = osMessageQueuePut( | ||||||
| 					queue_phyS_id, | 					queue_phyS_id, | ||||||
| @@ -60,26 +106,31 @@ void MacSender(void *argument) | |||||||
| 					osWaitForever); | 					osWaitForever); | ||||||
| 				CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); | 				CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); | ||||||
| 				break; | 				break; | ||||||
|  | 			} | ||||||
| 			 | 			 | ||||||
| 			 |  | ||||||
| 			case START: | 			case START: { | ||||||
| 				 | 				// Do nothing, don't care to receive start | ||||||
| 				break; | 				break; | ||||||
|  | 			} | ||||||
| 			 | 			 | ||||||
| 			 |  | ||||||
| 			case STOP: | 			case STOP: { | ||||||
| 				 | 				// Do nothing, don't care to receive stop | ||||||
| 				break; | 				break; | ||||||
|  | 			} | ||||||
| 			 | 			 | ||||||
| 			 |  | ||||||
| 			case DATA_IND: | 			case DATA_IND: { | ||||||
| 				 |  | ||||||
| 				break; | 				break; | ||||||
|  | 			} | ||||||
|  |  | ||||||
| 			 | 			 | ||||||
| 			 | 			default: { | ||||||
| 			default: |  | ||||||
| 				 |  | ||||||
| 				break; | 				break; | ||||||
|  | 			} | ||||||
| 		} | 		} | ||||||
| 		 | 		 | ||||||
| 	} | 	} | ||||||
|   | |||||||
							
								
								
									
										4
									
								
								main.h
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								main.h
									
									
									
									
									
								
							| @@ -27,13 +27,13 @@ | |||||||
| #define TIME_SAPI 				0x03   		// sapi time application number (0-7) | #define TIME_SAPI 				0x03   		// sapi time application number (0-7) | ||||||
| #define BROADCAST_ADDRESS	0x0F			// broadcast address | #define BROADCAST_ADDRESS	0x0F			// broadcast address | ||||||
| #define TOKEN_TAG					0xFF			// tag of tokenring frame | #define TOKEN_TAG					0xFF			// tag of tokenring frame | ||||||
| #define TOKENSIZE					19				// size of a token frame | #define TOKENSIZE					19				// size of a token frame (16 stations + 1 tag + start + end) | ||||||
| #define STX 							0x02			// any frame start char | #define STX 							0x02			// any frame start char | ||||||
| #define ETX								0x03			// any frame end char | #define ETX								0x03			// any frame end char | ||||||
| #define CONTINUE					0x0				// for check return code halt | #define CONTINUE					0x0				// for check return code halt | ||||||
|  |  | ||||||
| //-------------------------------------------------------------------------------- | //-------------------------------------------------------------------------------- | ||||||
| // identifiers used in more the one file (thread) | // identifiers used in more the one file (thread)  | ||||||
| //-------------------------------------------------------------------------------- | //-------------------------------------------------------------------------------- | ||||||
| extern GListener 	gl; | extern GListener 	gl; | ||||||
| extern osMemoryPoolId_t memPool; | extern osMemoryPoolId_t memPool; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user