Exemple #1
0
int main() {

    if ( !initiateConnection()) {
        printf("Abort.\r\n");
        camera.disconnect();
        return 0;
    }

    printf("Connected to camera. Operating with %d baudrate.\r\n", camera.baudrate());

    if ( !camera.systemReset()) {
        printf("Failed to reset camera.\r\n");
        camera.disconnect();
        return 0;
    }

    /* Reset message should be:
    3 1.00
    Ctrl infr exist
    USER-defined sensor
    525
    Init end
    */

    printf("Camera has been reset. Reset message follows: \r\n%s\r\n",
           camera.responseData());

    camera.disconnect();
    return 0;
}
/**
 * @brief HTTP::download
 * @return int
 */
int HTTP::download()
{
    initiateConnection(); // connection init
    send_request(); // send request with headers
    get_headers(); // get headers, find if chunked, redirection etc.
    std::string s =  get_content(); // save the content

    std::ofstream out("output.xml");
    out << s; // save to file
    out.close();

    return 0;
}
int main() {

	if ( !initiateConnection()) {
		printf("Abort.\r\n");
		camera.disconnect();
		return 0;
	}

	printf("Connected to camera. Operating with %d baudrate.\r\n\n", camera.baudrate());
	char *reply = camera.responseData();
	printf("Version: \"%s\"\r\n", reply);
  
	boolean state = true;
	if ( !camera.motionDetectorEnabled(state)) {
		printf("Failed to get motion detector status.\r\n");
	} else printf("Motion detector state: %s\r\n", state ? "enabled" : "disabled");
  
  	
	if ( camera.setMotionDetectorEnabled(true)) {
		printf("Enabling motion detector.\r\n");
		if ( !camera.motionDetectorEnabled(state))
			printf("Failed to get status.\r\n");
		else printf("Motion detector state is: %s\r\n", state ? "enabled" : "disabled");
	} else {
      printf("Failed to enable motion detector.\r\n");
      camera.disconnect();
      return 0;
    }

	int rr = 0;

	printf("Detecting motion now (move over camera 10 times to quit)..\r\n");
	while ( rr < 10 )
		if ( camera.motionDetectorStatus())
			printf("%d. time: motion detected.\r\n", rr++);

	if ( !camera.setMotionDetectorEnabled(false)) {
		printf("Failed to disable camera's motion detector.\r\n");
	} else {
		while ( camera.flushData() != 0 );
		if ( !camera.motionDetectorEnabled(state))
			printf("Failed to get camera's motion detector's state.\r\n");
		else printf("Motion detector status: %s\r\n", state ? "YES" : "NO");
	}

	camera.disconnect();
	return 0;
}
Exemple #4
0
BenchDBConnector::BenchDBConnector(BenchResult & br) : mHttp(this) //constructor, taking the complete url of the publish_script as an arg
, mIsConnected(false)
{

	mDone = false;

	char devProperties[200];
	char devPropertiesUrlEnc[200];
	char completeUrl[1000];

	int ret = maGetSystemProperty("mosync.device", devProperties, 200); //store the properties of the device in the buffer devProperty
	printf("Device properties: %s, retval: %d\n", devProperties, ret);

	//remove whitespaces, and use a placeholder device name if maGetSystemProperty fails
	if(ret < 0){
		br.phone = "unknownDevice";
	}else{
		for(unsigned int i = 0, j = 0; i < strlen(devProperties) && i < 20; ++i){
			if(devProperties[i] == ' '){
				//do nothing
			}else{
				devPropertiesUrlEnc[j] = devProperties[i];
				++j;
			}
		}
		br.phone = devPropertiesUrlEnc;
	}

	br.runtime = "MoSync"; //this is of course always going to be the MoSync revision
	printf("publishing benchmark: %s", br.benchmark);
	printf("Publishing result via url:");

	//build url according to benchmark
	if(strcmp(br.benchmark, "linpack") == 0){
		mBenchmark = LINPACK;
		sprintf(completeUrl, "%s%s%s%s%s%s%s%s%s%s%s%s%.3f", M_URL, "?benchmark=linpack&revision=", br.revision, "&runtime=", br.runtime, "&git_hash=", br.git_hash, "&phone=", br.phone, "&native_sdk_ver=", br.nativeSdkVer, "&mflops=", br.mflops);
	}else if(strcmp(br.benchmark, "opengl") == 0){
		mBenchmark = OPENGL;
		sprintf(completeUrl, "%s%s%s%s%s%s%s%s%s%s%s%s%d%s%d%s%d%s%d", M_URL, "?benchmark=opengl&revision=", br.revision, "&runtime=", br.runtime, "&git_hash=", br.git_hash, "&phone=", br.phone, "&native_sdk_ver=", br.nativeSdkVer, "&test1=", br.test1, "&test2=", br.test2, "&test3=", br.test3, "&test4=", br.test4);
	}else if(strcmp(br.benchmark, "membench") == 0){
		mBenchmark = MEMBENCH;
		sprintf(completeUrl, "%s%s%s%s%s%s%s%s%s%s%s%s%f%s%f%s%f%s%f%s%f%s%f%s%f%s%f%s%f%s%f%s%f%s%f%s%f%s%f", M_URL, "?benchmark=membench&revision=", br.revision, "&runtime=", br.runtime, "&git_hash=", br.git_hash, "&phone=", br.phone, "&native_sdk_ver=", "0", "&alloc_str_10=", br.str_alloc_10,
					"&alloc_str_100=", br.str_alloc_100, "&alloc_void_1=", br.alloc_void_1, "&alloc_void_100=", br.alloc_void_100, "&alloc_void_1000=", br.alloc_void_1000, "&alloc_dummy=", br.alloc_dummy, "&alloc_dummy_struct=", br.alloc_dummy_struct, "&alloc_dummy_mix=", br.alloc_dummy_mix, "&access_array=", br.access_array,
					"&access_vector=", br.access_vector, "&add_vector=", br.add_vector, "&access_dummy=", br.access_dummy, "&access_dummy_struct=", br.access_dummy_struct, "&access_dummy_mix=", br.access_dummy_mix);
	}
	printf(completeUrl);
	initiateConnection(completeUrl); //connect to the url, publishing the results via HTTP GET OR POST
}
void ClientImpl::reconnectEventCallback() {
    if (m_pendingConnectionSize.load(boost::memory_order_consume) <= 0)  return;

    boost::mutex::scoped_lock lock(m_pendingConnectionLock);
    const int64_t now = get_sec_time();
    BOOST_FOREACH( PendingConnectionSPtr& pc, m_pendingConnectionList ) {
        if ((now - pc->m_startPending) > RECONNECT_INTERVAL){
            //pc->m_startPending = now;
            initiateConnection(pc);
        }
    }

    struct timeval tv;
    tv.tv_sec = RECONNECT_INTERVAL;
    tv.tv_usec = 0;

    event_base_once(m_base, -1, EV_TIMEOUT, reconnectCallback, this, &tv);
}
void ClientImpl::createConnection(const std::string& hostname, const unsigned short port) throw (voltdb::Exception, voltdb::ConnectException, voltdb::LibEventException) {

    std::stringstream ss;
    ss << "ClientImpl::createConnection" << " hostname:" << hostname << " port:" << port;
    logMessage(ClientLogger::INFO, ss.str());

    PendingConnectionSPtr pc(new PendingConnection(hostname, port, m_base, this));
    initiateConnection(pc);

    if (event_base_dispatch(m_base) == -1) {
        throw voltdb::LibEventException();
    }

    if (pc->m_status) {
        if (event_base_dispatch(m_base) == -1) {
            throw voltdb::LibEventException();
        }

        if (pc->m_loginExchangeCompleted) {
            return;
        }
    }
    throw ConnectException();
}