Esempio n. 1
0
void GOUpdate( GameObject* go )
{
	MsgObject msg;
	msg.name = MSG_RESERVED_Update;
	msg.receiver_id = go->unique_id;
	msg.sender_id = go->unique_id;

	RouteMessage( &msg );

}
Esempio n. 2
0
void sendSettingConfig(char *name, float var, float minV, float maxV, uint8_t req) {
	struct timespec requested_time, remaining;
	psMessage_t msg;
	psInitPublish(msg, SETTING);
	strncpy(msg.settingPayload.name, name, PS_NAME_LENGTH);
	msg.settingPayload.value = var;
	msg.settingPayload.min = minV;
	msg.settingPayload.max = maxV;
	msg.settingPayload.subsystem = req;
	RouteMessage(&msg);
	configCount++;

	//delay
	requested_time.tv_sec = 0;
	requested_time.tv_nsec = MESSAGE_DELAY * 1000000;
	nanosleep(&requested_time, &remaining);
}
Esempio n. 3
0
File: agent.c Progetto: wda2945/Fido
//thread function for Rx
void *AgentRxThread(void *arg)
{
	int mychan = (int) arg;
	int socket = rxSocket[mychan];

	psMessage_t rxMessage;
	status_t parseStatus;

	DEBUGPRINT("agent: Rx %i thread: fd=%i\n",mychan, socket);

    parseStatus.noCRC       = 0; ///< Do not expect a CRC, if > 0
    parseStatus.noSeq       = 0; ///< Do not check seq #s, if > 0
    parseStatus.noLength2   = 0; ///< Do not check for duplicate length, if > 0
    parseStatus.noTopic     = 1; ///< Do not check for topic ID, if > 0

    ResetParseStatus(&parseStatus);

	agentOnline++;
	connected[mychan] = true;

    while(connected[mychan])
    {
    	uint8_t readByte;
    	int result;

    	do {
    		if (recv(socket, &readByte, 1, 0) <= 0)
    		{
    			//quit on failure, EOF, etc.
    			ERRORPRINT("agent: Rx %i recv(fd=%i) error: %s\n", mychan, socket, strerror(errno));
    			AGENTreceiveErrors++;
    			pthread_mutex_lock(&agentMtx);

    			close(socket);
    			rxSocket[mychan] = -1;

    		    close(txSocket[mychan]);
    		    txSocket[mychan] = -1;
    			connected[mychan] = false;

       			agentOnline--;

    			pthread_mutex_unlock(&agentMtx);

    		    pthread_exit(NULL);

    			return 0;
    		}
    		result = ParseNextCharacter(readByte, &rxMessage, &parseStatus);
    	} while (result == 0);

    	if (rxMessage.header.messageType == KEEPALIVE)
    	{
    		if (loopback)
    		{
    			rxMessage.header.source = 0;
    			CopyMessageToQ(&agentQueue, &rxMessage);
    		}
    		else
    		{
    			rxMessage.header.source = APP_XBEE;
    			XBeeBrokerProcessMessage(&rxMessage);
    		}
    	}
    	else
    	{
			DEBUGPRINT("agent: Rx %i. %s message received\n", mychan, psLongMsgNames[rxMessage.header.messageType]);
			AGENTmessagesReceived++;
			rxMessage.header.source = APP_XBEE;
			RouteMessage(&rxMessage);
    	}
    }
    //Tx disconnected
    DEBUGPRINT("agent: Rx %i exiting.\n", mychan);

	pthread_mutex_lock(&agentMtx);

    close(socket);
    rxSocket[mychan] = -1;

	agentOnline--;

	pthread_mutex_unlock(&agentMtx);

    pthread_exit(NULL);

    return 0;
}
Esempio n. 4
0
//thread to receive messages and respond
void *ResponderMessageThread(void *arg)
{
	uint8_t requestor;

	DEBUGPRINT("responder: thread started\n");

	while (1)
	{
		psMessage_t *msg = GetNextMessage(&responderQueue);

		//check message for response requirement
		switch (msg->header.messageType)
		{
		case CONFIG:
			if (msg->configPayload.responder == XBEE)
			{
				requestor = msg->configPayload.requestor;

				DEBUGPRINT("responder: Send Config received\n");
				configCount = 0;

#define optionmacro(name, var, minV, maxV, def) sendOptionConfig(name, var, minV, maxV, requestor);
#include "options.h"
#undef optionmacro


#define settingmacro(name, var, minV, maxV, def) sendSettingConfig(name, var, minV, maxV, requestor);
#include "settings.h"
#undef settingmacro

				{
					psMessage_t msg;
					psInitPublish(msg, CONFIG_DONE);
					msg.configPayload.requestor = requestor;
					msg.configPayload.responder = XBEE;
					msg.configPayload.count = configCount;
					RouteMessage(&msg);
				}
				DEBUGPRINT("responder: Config Done\n");
			}
			break;

		case PING_MSG:
		{
			if (msg->header.source != OVERMIND)
			{
				DEBUGPRINT("responder: APP Ping received\n");
				psMessage_t msg2;
				psInitPublish(msg2, PING_RESPONSE);
				strcpy(msg2.responsePayload.subsystem, "BEE");
				msg2.responsePayload.flags = (startFlag ? RESPONSE_FIRST_TIME : 0) |  (agentOnline ? RESPONSE_AGENT_ONLINE : 0);
				msg2.responsePayload.requestor = msg->requestPayload.requestor;
				startFlag = 0;
				RouteMessage(&msg2);

				PublishConditions(true);
				SendXBeeStats();
				SendAgentStats();
			}
		}
		break;
		case NEW_SETTING:
			DEBUGPRINT("responder: New Setting: %s = %f\n", msg->settingPayload.name, msg->settingPayload.value);
#define settingmacro(n, var, minV, maxV, def) if (strncmp(n,msg->settingPayload.name,PS_NAME_LENGTH) == 0)\
		var = msg->settingPayload.value;\
		sendSettingConfig(n, var, minV, maxV, 0);
#include "settings.h"
#undef settingmacro

			if (strncmp("Power Level",msg->settingPayload.name,PS_NAME_LENGTH) == 0) SetPowerLevel((int) powerLevel);

			break;

		case SET_OPTION:
			DEBUGPRINT("responder: Set Option: %s = %i\n", msg->optionPayload.name, msg->optionPayload.value);
#define optionmacro(n, var, minV, maxV, def) if (strncmp(n,msg->optionPayload.name,PS_NAME_LENGTH) == 0)\
		var = msg->optionPayload.value;\
		sendOptionConfig(n, var, minV, maxV, 0);
#include "options.h"
#undef optionmacro
			break;
		default:
			//ignore anything else
			break;
		}
		DoneWithMessage(msg);
	}
	return 0;
}