コード例 #1
0
ファイル: sensors.c プロジェクト: philippe-mon/cletus
void get_sensors(sensors_t * const y) {
  gettime(&(y->timestamp));
  double t = floating_time(&(y->timestamp));
  some_data(&(y->gyro), t, 2);
  some_data(&(y->accel), t, 3);
  some_data(&(y->gps_pos), t, 4);
  some_data(&(y->gps_vel), t, 5);
  printf("read sensors!: %.4f\n",t);
}
コード例 #2
0
ファイル: builtins.cpp プロジェクト: stoopkid420/LemonChain
void build_in_dht()
{
#ifdef DHT

	static bool running = false;
	static mutex mut;
	static dht::DhtRunner ht;
	static int port = 4443;
	
	if (!running)
	{
		running = true;
		int port = 4443;
		dout << "firing up DHT on port " << port << endl;
		// Launch a dht node on a new thread, using a
		// generated RSA key pair, and listen on port 4222.
		ht.run(port, dht::crypto::generateIdentity(), true);

		// Join the network through any running node,
		// here using a known bootstrap node.
		ht.bootstrap("127.0.0.1", "4444");

		// put some data on the dht
		std::vector<uint8_t> some_data(5, 10);
		ht.put("unique_key", some_data);

		// put some data on the dht, signed with our generated private key
		ht.putSigned("unique_key_42", some_data);

	}

	auto ht_ = &ht;

	EEE;	
	
	string bu = "http://idni.org/dht#put";
	auto bui = dict.set(mkiri(pstr(bu)));

	builtins[bui].push_back(
		[bu, entry, ht_](Thing *dummy, Thing *x) mutable {
		setproc(bu);
		TRACE_ENTRY;
		dout <<"sssss" << endl;
		switch(entry){
		case 0:
			x = getValue(x);
			
			if(is_node(*x))
			{
				node n = dict[get_node(*x)];
				string v = *n.value;
				string key,val;

				if (n._type == node::IRI)
				{
					if (has(mykb->first, v))
					{
						key = "root_graph_" + v;
						stringstream ss;
						ss << mykb->first[v];
						val = ss.str();
					}
					else
					{
						string h = strhash(v);
						key = "root_iri_" + h;
						val = v;
					}
				}
				else if (n._type == node::LITERAL)
				{
					string h = strhash(v);
					key = "root_lit_" + h;
					val = v;
				}
				else
				{
					dout << "nope." << endl;
					DONE;
				}
				dout << "putting " << key << "=" << val << endl;
				ht_->put(key, val);
				
			}
			else
				dout << "nope." << endl;
			
						
			END;
		}
	});
	
	
	
	bu = "http://idni.org/dht#dbg";
	bui = dict.set(mkiri(pstr(bu)));

	builtins[bui].push_back(
		[bu, entry, ht_](Thing *dummy, Thing *x) mutable {
		setproc(bu);
		TRACE_ENTRY;
		
		switch(entry){
		case 0:
			x = getValue(x);
					
			if(is_node(*x))
			{
				node n = dict[get_node(*x)];
				string v = *n.value;
				if (v == "on")
				{
					MSG("dht dbg on");
					enableDhtLogging(*ht_);
				}
				else{
					MSG("dht dbg off");
					ht_->setLoggers(dht::NOLOG, dht::NOLOG, dht::NOLOG);
				}
			}
						
			END;
		}
	});

	bu = "http://idni.org/dht#setPort";
	bui = dict.set(mkiri(pstr(bu)));

	builtins[bui].push_back(
		[bu, entry, ht_](Thing *dummy, Thing *x) mutable {
		setproc(bu);
		TRACE_ENTRY;
		
		switch(entry){
		case 0:
			x = getValue(x);
					
			if(is_node(*x))
			{
				node n = dict[get_node(*x)];
				string v = *n.value;
				if (v == "on")
				{
					MSG("dht dbg on");
					enableDhtLogging(*ht_);
				}
				else{
					MSG("dht dbg off");
					ht_->setLoggers(dht::NOLOG, dht::NOLOG, dht::NOLOG);
				}
			}
						
			END;
		}
	});


    // get data from the dht
    ht_->get("other_unique_key", [](const std::vector<std::shared_ptr<dht::Value>>& values) {
        // Callback called when values are found
        for (const auto& value : values)
            dout << "Found value: " << *value << std::endl;
        return true; // return false to stop the search
    });
#endif

}
コード例 #3
0
ファイル: mpicomm.c プロジェクト: xrf/phy905-hw
/** Ensure the data was transmitted intact. */
static void verify_data(unsigned char *data, size_t size, int rank)
{
    for (size_t i = 0; i < size; ++i) {
        assert(data[i] == some_data(i, rank));
    }
}
コード例 #4
0
ファイル: mpicomm.c プロジェクト: xrf/phy905-hw
static void init_data(unsigned char *data, size_t size, int rank)
{
    for (size_t i = 0; i < size; ++i) {
        data[i] = some_data(i, rank);
    }
}