Exemplo n.º 1
0
void simpleQueueDestroy(struct SimpleQueue* queue){
	while(xSemaphoreTakeRecursive(queue->xSemHandle,(TickType_t) 0)!=pdTRUE){}

	while(!simpleQueueEmpty(queue))
		simpleQueueDequeue(queue);
	 xSemaphoreGiveRecursive(queue->xSemHandle);
	 vSemaphoreDelete(queue->xSemHandle);	//TODO: ZUPPA
}
Exemplo n.º 2
0
SimpleQueueValue* simpleQueueFront(struct SimpleQueue* queue){
	while(xSemaphoreTakeRecursive(queue->xSemHandle,(TickType_t)0) != pdTRUE){}
	SimpleQueueValue* return_Value = NULL;
	if (simpleQueueEmpty(queue))
		return_Value =  NULL;
	else
		return_Value =  queue->head->value;
	xSemaphoreGiveRecursive(queue->xSemHandle);
	 return return_Value;
}
Exemplo n.º 3
0
void simpleQueueEnqueue(struct SimpleQueue* queue, SimpleQueueValue* value){
//	while(xSemaphoreTakeRecursive(queue->xSemHandle,(TickType_t)0) != pdTRUE){}
	struct SimpleQueueNode* new_node = (struct SimpleQueueNode*)malloc(sizeof(struct SimpleQueueNode));
	new_node->value = value;
	new_node->next_node = queue->tail;
	new_node->previous_node = NULL;
	if (!simpleQueueEmpty(queue))
		new_node->next_node->previous_node = new_node;
	else
		queue->head = new_node;
	queue->tail = new_node;
	queue->size++;
//	xSemaphoreGiveRecursive(queue->xSemHandle);	//TODO: Decommentare
}
Exemplo n.º 4
0
SimpleQueueValue* simpleQueueDequeue(struct SimpleQueue* queue){
	while(xSemaphoreTakeRecursive(queue->xSemHandle,(TickType_t)0) != pdTRUE){}
	SimpleQueueValue* return_Value = NULL;
	if (simpleQueueEmpty(queue))
		return_Value = NULL;
	else{
		struct SimpleQueueNode* old_head = queue->head;
		return_Value = queue->head->value;

		if (old_head->previous_node != NULL){
			old_head->previous_node->next_node = NULL;
		}

		queue->head = old_head->previous_node;
		if (queue->size == 1)
			queue->tail = NULL;

		free(old_head);
		queue->size--;
	}
	xSemaphoreGiveRecursive(queue->xSemHandle);
	 return return_Value;
}
Exemplo n.º 5
0
/**
 *  Funzione eseguita ciclicamente. Disaccoda un pacchetto, ne verifica il tipo
 *  ed chiama la primitiva di invio appropriata.
 */
void dispatch (struct NLS_HandleTypedef* hNLS)   //XXX PER PAOLO: MODIFICA FATTA!!
{
	//scoda la prep queue se vuota
	if (!simpleQueueEmpty(hNLS->PREP_queue))
	{
		//TODO Log
		//EventLogger_LogEvent(&LOG_HANDLE, NETWORK, NOTICE, MY_ADDRESS, "dispatch()",
		//							LOG_STRING, "scoda la coda PREP", "OK",
		//							LOG_END);

		on_PREP(hNLS , simpleQueueDequeue(hNLS->PREP_queue));
	}

	//scoda la coda di ingresso
	datagram_info* d_info = (datagram_info*)priorityQueueDequeue(hNLS->routing_queue);

	if (d_info == NULL)
	{
		//TODO Log
		//EventLogger_LogEvent(&LOG_HANDLE, NETWORK, NOTICE, MY_ADDRESS, "dispatch()",
		//							LOG_STRING, "scoda la coda d'ingresso", "OK",
		//							LOG_STRING, "coda d'ingresso", "nessun datagram",
		//							LOG_END);

		return;
	}

	//TODO Log
	//EventLogger_LogEvent(&LOG_HANDLE, NETWORK, NOTICE, MY_ADDRESS, "dispatch()",
	//							LOG_STRING, "scoda la coda d'ingresso", "OK",
	//							LOG_STRING, "coda d'ingresso", "datagram scodato",
	//							LOG_INT, "if source", d_info->source_if,
	//							LOG_INT, "datagram type", d_info->type,
	//							LOG_INT, "packet length", d_info->packet_length,
	//							LOG_INT, "address", d_info->address,
	//							LOG_END);


	//i messaggi di upstream e downstream diretti al root vanno direttamente al livello superiore
#ifdef ROOT
	if (d_info->type == DATA_UP) //XXX CONTROLLARE DATA_DOWN
	{

		//TODO Log
		//EventLogger_LogEvent(&LOG_HANDLE, NETWORK, NOTICE, MY_ADDRESS, "dispatch()",
		//							LOG_STRING, "nodo ROOT: datagram type", "DATA UP",
		//							LOG_STRING, "nodo ROOT: trasferisci al livello superiore", "OK",
		//							LOG_END);

		on_datagram_received(d_info);
		return;
	}
#else
	if ((get_datagram_address(d_info->packet) == MY_ADDRESS) && (d_info->type == DATA_DOWN))
	{
		//è un datagramma dati, manda ai livelli superiori

		//TODO Log
		//EventLogger_LogEvent(&LOG_HANDLE, NETWORK, NOTICE, MY_ADDRESS, "dispatch()",
		//							LOG_STRING, "datagram dati", "trasferisci aL livellO superiorE",
		//							LOG_END);

		on_datagram_received(d_info);
		//BSP_LED_On(LED5);
		return;
	}


	//se non ho un path
	if(UTGetSize(hNLS->uTable) == 0)
	{
		//se non ho un path ma  ho pacchetti da inviare
		if(d_info != NULL)
		{

			//fai path discovery

			//TODO Log
			//EventLogger_LogEvent(&LOG_HANDLE, NETWORK, NOTICE, MY_ADDRESS, "dispatch",
			//							LOG_STRING, "nessun path e datagram da inviare", "esegui path discovery",
			//							LOG_END);

			on_path_discovery(hNLS , d_info);

		}

	}
#endif


	//qui sono associato
	switch(d_info->type)
	{

	case DATA_UP:
	{
#ifndef ROOT   //XXX PER PAOLO: Attenzione a questo #ifndef; potrebbe anche non essere necessario
		if(d_info->source_if == UTGetMainLink(hNLS->uTable))
		{

			//TODO Log
			//EventLogger_LogEvent(&LOG_HANDLE, NETWORK, NOTICE, MY_ADDRESS, "dispatch()",
			//							LOG_STRING, "datagram type", "DATA UP",
			//							LOG_STRING, "swap main link in Upstream Table", "OK",
			//							LOG_END);

			UTSwapMainLink(hNLS->uTable);
		}

		send_upstream(hNLS , d_info);
#endif
		break;

	}
	case DATA_DOWN:
	{

		//TODO Log
		//EventLogger_LogEvent(&LOG_HANDLE, NETWORK, NOTICE, MY_ADDRESS, "dispatch()",
		//							LOG_STRING, "datagram type", "DATA DOWN",
		//							LOG_STRING, "trasmissione DOWNSTREAM", "OK",
		//							LOG_END);

		send_downstream(hNLS , d_info);
		break;

	}
	case BSRP_PREQ:
	{
#ifndef ROOT
		if(hNLS->enabled_ifs_num!=1)  //XXX ZUPPA PAOLO: TENTATIVO DI AGGIUSTARE IL PROTOCOLLO
#endif

			//TODO Log
			//EventLogger_LogEvent(&LOG_HANDLE, NETWORK, NOTICE, MY_ADDRESS, "dispatch()",
			//							LOG_STRING, "datagram type", "PREQ",
			//							LOG_STRING, "on PREQ", "OK",
			//							LOG_END);

			on_PREQ(hNLS  , d_info);

		break;
	}
	case BSRP_PFWD:
	{

		//TODO Log
		//EventLogger_LogEvent(&LOG_HANDLE, NETWORK, NOTICE, MY_ADDRESS, "dispatch()",
		//							LOG_STRING, "datagram type", "PFWD",
		//							LOG_STRING, "on PFWD", "OK",
		//							LOG_END);

		on_PFWD(hNLS , d_info);
		break;
	}
	case BSRP_PREP:
	{
#ifndef ROOT

		//TODO Log
		//EventLogger_LogEvent(&LOG_HANDLE, NETWORK, NOTICE, MY_ADDRESS, "dispatch()",
		//							LOG_STRING, "datagram type", "PREP",
		//							LOG_STRING, "trasmissione DOWNSTREAM", "OK",
		//							LOG_END);

		send_downstream(hNLS  , d_info);
#endif
		break;

	}
	case BSRP_PACK:
	{
		break;
	}
	}


}