コード例 #1
0
void ofxRemoteUIClient::connect(){
	OSC_CHECK;
	if(!readyToSend){
		if(verbose_) cout << "ofxRemoteUIClient: connect()" << endl;
		sendHELLO();	//on first connect, send HI!
		sendTEST();		//and a lag test
		readyToSend = true;
	}else{
		if(verbose_) cout << "ofxRemoteUIClient: can't connect() now, we are already connected!" << endl;
	}
}
コード例 #2
0
ファイル: main.c プロジェクト: robotronik/archives
void main()
{
    /* Place your initialization/startup code here (e.g. MyInst_Start()) */
	UART_XBee_Start();
#if IS_TX_ASSER_BYPASSED
	UART_XBee_TX_isr_Start();
#endif // IS_TX_ASSER_BYPASSED
	UART_Asser_Start();
	UART_Asser_RX_isr_Start();
#ifndef NO_SERVO
	PWM_ServoDroit_Start();
	PWM_ServoGauche_Start();
#endif // ! NO_SERVO

    CYGlobalIntEnable;  /* Uncomment this line to enable global interrupts. */
	//UART_Asser_PutChar_Sniffed('a');
	//UART_Asser_PutChar('a');
#if ! IS_RX_ASSER_BYPASSED
	CyDelay(20);
	UART_XBee_PutChar('S');
#endif // ! IS_RX_ASSER_BYPASSED
	while (!isAsserReady) {
		sendTEST();
		CyDelay(10);
	}
#if ! IS_RX_ASSER_BYPASSED
	UART_XBee_PutChar('R');
#endif // ! IS_RX_ASSER_BYPASSED
	
	/* Purple :
	 * 		P    R
	 * 		^ y
	 * 		|  x  	sens trigo, 180° sur x
	 * 		0 ->
	 * 
	 * Red :
	 * 		P    R
	 * 		   y ^
	 * 		  x  |	sens horaire, 180° sur x
	 * 		  <- 0
	 */
	
#if IS_TESTING
	boolean hasColorChanged = TRUE;
	while(1) {
		if (isPurple != Couleur_Read()) {
			isPurple = Couleur_Read();
			hasColorChanged = TRUE;
		}
		if (hasColorChanged) {
			hasColorChanged = FALSE;
			if (isPurple) sendPURPLE();
			else sendRED();
		}
	
		while (nbAsserDone) {
			UART_XBee_PutChar('D');
			nbAsserDone --;
		}
#if ! IS_TX_ASSER_BYPASSED
		while (UART_XBee_GetRxBufferSize())
			test_message_processing();
#endif // ! IS_TX_ASSER_BYPASSED
	}
#endif // IS_TESTING
	
	// Avance à l'avant de la zone de départ
	sendXY_RAPIDE(300, 1750, 5);
	
	while (Depart_Read());
	
	isPurple = Couleur_Read();
	if (isPurple) sendPURPLE();
	else sendRED();
	
	T_Pos pos = getWaitPos();
	
	//sendXY_RAPIDE(pos.x + 2500, pos.y, 1);
	/*for (int i=0; i<10; i++) {
		sendALPHA(90, 10);
		sendALPHA(180, 10);
		sendALPHA(270, 10);
		sendALPHA(0, 10);
	}*/
	
	sendXY_RAPIDE(pos.x + 1000, pos.y + 750, 20);
	sendXY_RAPIDE(pos.x + 1500, pos.y + 750, 10);
	sendALPHA(180, 5);
	while(!nbAsserDone) CyDelay(10); nbAsserDone --;
	sendXY_COURBE(pos.x + 900, pos.y + 1350, 10);
	while(!nbAsserDone) CyDelay(10); nbAsserDone --;
	//sendXY_RAPIDE(pos.x + 400, pos.y, 20);
	//while(!nbAsserDone) CyDelay(10); nbAsserDone --;
	sendXY_RAPIDE(pos.x + 400, pos.y, 10);
	while(!nbAsserDone) CyDelay(10); nbAsserDone --;
	sendALPHA(180, 5);
	while(!nbAsserDone) CyDelay(10); nbAsserDone --;
	sendXY_RAPIDE(pos.x, pos.y, 10);
	while(!nbAsserDone) CyDelay(10); nbAsserDone --;
	while(!nbAsserDone) CyDelay(10); nbAsserDone --;
	while(!nbAsserDone) CyDelay(10); nbAsserDone --;
	/*sendALPHA(0, 5);
	sendXY_COURBE(pos.x, pos.y, 10);
	sendALPHA(0, 1);*/
	/*sendXY_RAPIDE(300, 1750, 10);
	while(!nbAsserDone) CyDelay(10); nbAsserDone --;*/
	//sendALPHA(180, 1);
	
    for(;;)
    {
        /* Place your application code here. */
    }
}
コード例 #3
0
void ofxRemoteUIClient::update(float dt){

	//cout << "ofxRemoteUIClient::update readyToSend = " << readyToSend << endl;

	if (readyToSend){ // if connected

		OSC_CHECK;

		timeCounter += dt;
		timeSinceLastReply += dt;
		//printf("waiting for reply: %d\n", waitingForReply);
		if (timeCounter > OFXREMOTEUI_LATENCY_TEST_RATE){
			if (!waitingForReply){
				timeCounter = 0.0f;
				sendTEST();
			}else{
				if (timeCounter > OFXREMOTEUI_CONNECTION_TIMEOUT){
					avgTimeSinceLastReply = -1;
					disconnect(); // testing here
					params.clear();
					orderedKeys.clear();
				}
			}
		}

		while( oscReceiver.hasWaitingMessages() ){// check for waiting messages from server

			ofxOscMessage m;
			oscReceiver.getNextMessage(&m);

			DecodedMessage dm = decode(m);
			RemoteUIClientCallBackArg cbArg; // to notify our "delegate"
			cbArg.host = m.getRemoteIp();
			switch (dm.action) {

				case HELO_ACTION:{ //server says hi back, we ask for a big update
					requestCompleteUpdate();
					if(callBack != NULL){
						cbArg.action = SERVER_CONNECTED;
						callBack(cbArg);
					}
				}break;

				case REQUEST_ACTION: //server closed the REQU, so we should have all the params
					if(verbose_) cout << "ofxRemoteUIClient: " << m.getRemoteIp() << " says REQUEST_ACTION!" << endl;
					if(callBack != NULL){
						cbArg.action = SERVER_SENT_FULL_PARAMS_UPDATE;
						callBack(cbArg);
					}
					break;

				case SEND_PARAM_ACTION:{ //server is sending us an updated val
					if(verbose_) cout << "ofxRemoteUIClient: " << m.getRemoteIp() << " says SEND_PARAM_ACTION!" << endl;
					updateParamFromDecodedMessage(m, dm);
					gotNewInfo = true;
				}
					break;

				case CIAO_ACTION:{
					if(verbose_) cout << "ofxRemoteUIClient: " << m.getRemoteIp() << " says CIAO!" << endl;
					if(callBack != NULL){
						cbArg.action = SERVER_DISCONNECTED;
						callBack(cbArg);
					}
					sendCIAO();
					params.clear();
					orderedKeys.clear();
					clearOscReceiverMsgQueue();
					readyToSend = false;
				}break;

				case TEST_ACTION: // we got a reply from the server, lets measure how long it took;
					waitingForReply = false;
					if (avgTimeSinceLastReply > 0.0f){
						avgTimeSinceLastReply = 0.8 * (avgTimeSinceLastReply) + 0.2 * (timeSinceLastReply);
					}else{
						avgTimeSinceLastReply = timeSinceLastReply ;
					}
					timeSinceLastReply = 0.0f;
					break;

				case PRESET_LIST_ACTION: //server sends us the list of current presets
					if(verbose_) cout << "ofxRemoteUIClient: " << m.getRemoteIp() << " says PRESET_LIST_ACTION!" << endl;
					fillPresetListFromMessage(m);
					if(callBack != NULL){
						cbArg.action = SERVER_PRESETS_LIST_UPDATED;
						callBack(cbArg);
					}
					break;

				case SET_PRESET_ACTION: // server confirms that it has set the preset, request a full update
					if(verbose_) cout << "ofxRemoteUIClient: " << m.getRemoteIp() << " says SET_PRESET_ACTION!" << endl;
					requestCompleteUpdate();
					if(callBack != NULL){
						cbArg.action = SERVER_DID_SET_PRESET;
						cbArg.msg = m.getArgAsString(0);
						callBack(cbArg);
					}
					break;

				case GET_MISSING_PARAMS_IN_PRESET:
					if(callBack != NULL){
						cbArg.action = SERVER_REPORTS_MISSING_PARAMS_IN_PRESET;
						for (int i = 0; i < m.getNumArgs(); i++){
							cbArg.paramList.push_back(m.getArgAsString(i));
						}
						callBack(cbArg);
					}

					break;

				case SAVE_PRESET_ACTION:{ // server confirms that it has save the preset,
					if(verbose_) cout << "ofxRemoteUIClient: " << m.getRemoteIp() << " says SAVE_PRESET_ACTION!" << endl;
					vector<string> a;
					sendPREL(a); //request preset list to server, send empty vector
					cbArg.action = SERVER_SAVED_PRESET;
					cbArg.msg = m.getArgAsString(0);
					if(callBack != NULL) callBack(cbArg);
				}break;

				case DELETE_PRESET_ACTION:{ // server confirms that it has deleted preset
					if(verbose_) cout << "ofxRemoteUIClient: " << m.getRemoteIp() << " says DELETE_PRESET_ACTION!" << endl;
					vector<string> a;
					sendPREL(a); //request preset list to server, send empty vector
					if(callBack != NULL){
						cbArg.action = SERVER_DELETED_PRESET;
						cbArg.msg = m.getArgAsString(0);
						callBack(cbArg);
					}
				}break;

				case RESET_TO_XML_ACTION:{ // server confrims
					if(verbose_) cout << "ofxRemoteUIClient: " << m.getRemoteIp() << " says RESET_TO_XML_ACTION!" << endl;
					requestCompleteUpdate();
					if(callBack != NULL){
						cbArg.action = SERVER_DID_RESET_TO_XML;
						callBack(cbArg);
					}
				}break;

				case RESET_TO_DEFAULTS_ACTION:{ // server confrims
					if(verbose_) cout << "ofxRemoteUIClient: " << m.getRemoteIp() << " says RESET_TO_DEFAULTS_ACTION!" << endl;
					requestCompleteUpdate();
					if(callBack != NULL){
						cbArg.action = SERVER_DID_RESET_TO_DEFAULTS;
						callBack(cbArg);
					}
				}break;

				case SAVE_CURRENT_STATE_ACTION: // server confirms that it has saved
					if(verbose_) cout << "ofxRemoteUIClient: " << m.getRemoteIp() << " says SAVE_CURRENT_STATE_ACTION!" << endl;
					if(callBack != NULL){
						cbArg.action = SERVER_CONFIRMED_SAVE;
						callBack(cbArg);
					}
					break;
					
				default: cout << "ofxRemoteUIClient::update >> UNKNOWN ACTION!!" <<endl; break;
			}
		}
	}
}
コード例 #4
0
void ofxRemoteUIServer::updateServer(float dt){

	timeCounter += dt;
	broadcastTime += dt;
	timeSinceLastReply  += dt;

	if(readyToSend){
		if (timeCounter > updateInterval){
			timeCounter = 0.0f;
			//vector<string> changes = scanForUpdatedParamsAndSync(); //sends changed params to client
			//cout << "ofxRemoteUIServer: sent " << ofToString(changes.size()) << " updates to client" << endl;
			//sendUpdateForParamsInList(changes);
		}
	}

	//let everyone know I exist and which is my port, every now and then
	if(broadcastTime > OFXREMOTEUI_BORADCAST_INTERVAL){
		if(doBroadcast){
			broadcastTime = 0.0f;
			if (computerName.size() == 0){
				#ifdef OF_AVAILABLE
					Poco::Environment e;
					computerName = e.nodeName();

					char pathbuf[2048];
					uint32_t  bufsize = sizeof(pathbuf);
					#ifdef TARGET_OSX
						_NSGetExecutablePath(pathbuf, &bufsize);
						Poco::Path p = Poco::Path(pathbuf);
						binaryName = p[p.depth()];
					#endif
					#ifdef TARGET_WIN32						
						GetModuleFileNameA( NULL, pathbuf, bufsize ); //no iea why, but GetModuleFileName() is not defined?
						Poco::Path p = Poco::Path(pathbuf);
						binaryName = p[p.depth()];
					#endif
				#endif
			}
			ofxOscMessage m;
			m.addIntArg(port); //0
			m.addStringArg(computerName); //1
			m.addStringArg(binaryName);	//2
			broadcastSender.sendMessage(m);
		}
	}

	while( oscReceiver.hasWaitingMessages() ){// check for waiting messages from client

		ofxOscMessage m;
		oscReceiver.getNextMessage(&m);
		if (!readyToSend){ // if not connected, connect to our friend so we can talk back
			connect(m.getRemoteIp(), port + 1);
		}

		DecodedMessage dm = decode(m);
		RemoteUIServerCallBackArg cbArg; // to notify our "delegate"
		cbArg.host = m.getRemoteIp();
		switch (dm.action) {

			case HELO_ACTION: //if client says hi, say hi back
				sendHELLO();
				if(callBack != NULL){
					cbArg.action = CLIENT_CONNECTED;
					callBack(cbArg);
				}
				if(verbose_) cout << "ofxRemoteUIServer: " << m.getRemoteIp() << " says HELLO!"  << endl;
				onScreenNotifications.addNotification("CONNECTED (" + cbArg.host +  ")!");
				break;

			case REQUEST_ACTION:{ //send all params to client
				if(verbose_) cout << "ofxRemoteUIServer: " << m.getRemoteIp() << " sends REQU!"  << endl;
				vector<string>paramsList = getAllParamNamesList();
				syncAllParamsToPointers();
				sendUpdateForParamsInList(paramsList);
				sendREQU(true); //once all send, confirm to close the REQU
			}
				break;

			case SEND_PARAM_ACTION:{ //client is sending us an updated val
				if(verbose_) cout << "ofxRemoteUIServer: " << m.getRemoteIp() << " sends SEND!"  << endl;
				updateParamFromDecodedMessage(m, dm);
				if(callBack != NULL){
					cbArg.action = CLIENT_UPDATED_PARAM;
					cbArg.paramName = dm.paramName;
					cbArg.param = params[dm.paramName];  //copy the updated param to the callbakc arg
					callBack(cbArg);
				}
			}
				break;

			case CIAO_ACTION:{
				if(verbose_) cout << "ofxRemoteUIServer: " << m.getRemoteIp() << " says CIAO!" << endl;
				sendCIAO();
				onScreenNotifications.addNotification("DISCONNECTED (" + cbArg.host +  ")!");
				if(callBack != NULL){
					cbArg.action = CLIENT_DISCONNECTED;
					callBack(cbArg);
				}
				clearOscReceiverMsgQueue();
				readyToSend = false;
			}break;

			case TEST_ACTION: // we got a request from client, lets bounce back asap.
				sendTEST();
				//if(verbose)cout << "ofxRemoteUIServer: " << m.getRemoteIp() << " says TEST!" << endl;
				break;

			case PRESET_LIST_ACTION: //client wants us to send a list of all available presets
				presetNames = getAvailablePresets();
				if (presetNames.size() == 0){
					presetNames.push_back(OFXREMOTEUI_NO_PRESETS);
				}
				sendPREL(presetNames);
				break;

			case SET_PRESET_ACTION:{ // client wants to set a preset
				//presetNames = getAvailablePresets();
				string presetName = m.getArgAsString(0);
				vector<string> missingParams = loadFromXML(string(OFXREMOTEUI_PRESET_DIR) + "/" + presetName + ".xml");
				if(verbose_) cout << "ofxRemoteUIServer: setting preset: " << presetName << endl;
				sendSETP(presetName);
				sendMISP(missingParams);
				if(callBack != NULL){
					cbArg.action = CLIENT_DID_SET_PRESET;
					cbArg.msg = presetName;
					callBack(cbArg);
				}
				onScreenNotifications.addNotification("SET PRESET to '" + string(OFXREMOTEUI_PRESET_DIR) + "/" + presetName + ".xml'");
			}break;

			case SAVE_PRESET_ACTION:{ //client wants to save current xml as a new preset
				string presetName = m.getArgAsString(0);
				if(verbose_) cout << "ofxRemoteUIServer: saving NEW preset: " << presetName << endl;
				saveToXML(string(OFXREMOTEUI_PRESET_DIR) + "/" + presetName + ".xml");
				sendSAVP(presetName);
				onScreenNotifications.addNotification("SAVED PRESET to '" + string(OFXREMOTEUI_PRESET_DIR) + "/" + presetName + ".xml'");
				if(callBack != NULL){
					cbArg.action = CLIENT_SAVED_PRESET;
					cbArg.msg = presetName;
					callBack(cbArg);
				}
			}break;

			case DELETE_PRESET_ACTION:{
				string presetName = m.getArgAsString(0);
				if(verbose_) cout << "ofxRemoteUIServer: DELETE preset: " << presetName << endl;
				deletePreset(presetName);
				sendDELP(presetName);
				onScreenNotifications.addNotification("DELETED PRESET '" + string(OFXREMOTEUI_PRESET_DIR) + "/" + presetName + ".xml'");
				if(callBack != NULL){
					cbArg.action = CLIENT_DELETED_PRESET;
					cbArg.msg = presetName;
					callBack(cbArg);
				}
			}break;

			case SAVE_CURRENT_STATE_ACTION:{
				if(verbose_) cout << "ofxRemoteUIServer: SAVE CURRENT PARAMS TO DEFAULT XML: " << endl;
				saveToXML(OFXREMOTEUI_SETTINGS_FILENAME);
				onScreenNotifications.addNotification("SAVED CONFIG to default XML");
				sendSAVE(true);
				if(callBack != NULL){
					cbArg.action = CLIENT_SAVED_STATE;
					callBack(cbArg);
				}
			}break;

			case RESET_TO_XML_ACTION:{
				if(verbose_) cout << "ofxRemoteUIServer: RESET TO XML: " << endl;
				restoreAllParamsToInitialXML();
				sendRESX(true);
				onScreenNotifications.addNotification("RESET CONFIG TO SERVER-LAUNCH XML values");
				if(callBack != NULL){
					cbArg.action = CLIENT_DID_RESET_TO_XML;
					callBack(cbArg);
				}
			}break;

			case RESET_TO_DEFAULTS_ACTION:{
				if(verbose_) cout << "ofxRemoteUIServer: RESET TO DEFAULTS: " << endl;
				restoreAllParamsToDefaultValues();
				sendRESD(true);
				onScreenNotifications.addNotification("RESET CONFIG TO DEFAULTS (source defined values)");
				if(callBack != NULL){
					cbArg.action = CLIENT_DID_RESET_TO_DEFAULTS;
					callBack(cbArg);
				}
			}break;

			default: cout << "ofxRemoteUIServer::update >> ERR!" <<endl; break;
		}
	}
}