int main() { p2p::UDP::Socket socket(46668); std::cout << "UDP socket created" << std::endl; p2p::Kademlia::IdGenerator<1> generator; std::cout << "Created ID Generator" << std::endl; p2p::RPCProtocol<p2p::UDP::Endpoint, IdType> protocol(socket, generator); std::cout << "Created RPC Protocol" << std::endl; TestDatabase<1> database; std::cout << "Created database" << std::endl; IdType myId; myId.data[0] = 'B'; p2p::Kademlia::DHT<p2p::UDP::Endpoint, 1> dht(protocol, myId, database); std::cout << "Created DHT" << std::endl; char s[1]; std::cin.getline(s, 1); std::cout << "Got line" << std::endl; return 0; }
int main(void) { float *ht; //Exit on failure to start communications with the GrovePi if(init()==-1) exit(1); //Set pin mode to input pinMode(7,0); while(1) { ht=dht(7,0); printf("humidity = %.02f%% temp = %.02f C\n", ht[0], ht[1]); //Sleep for 50ms pi_sleep(50); } return 1; }
int main(int c, char *v[]) { if (c != 1 && c != 2 && c != 3) { fprintf(stderr, "usage:\n\t%s [in [out]]\n", *v); // 0 1 2 return 1; } char *in = c > 1 ? v[1] : "-"; char *out = c > 2 ? v[2] : "-"; int w, h, pd; float *x = iio_read_image_float_split(in, &w, &h, &pd); normalize_float_array_inplace(x, w*h*pd); float *y = xmalloc(w*h*pd*sizeof*y); for (int i = 0; i < pd; i++) dht(y + i*w*h, x + i*w*h, w, h); iio_save_image_float_split(out, y, w, h, pd); free(x); free(y); return 0; }
int main() { p2p::UDP::Socket socket(46667); std::cout << "UDP socket created" << std::endl; p2p::Kademlia::IdGenerator<1> generator; std::cout << "Created ID Generator" << std::endl; p2p::RPC::Protocol<p2p::UDP::Endpoint, IdType> protocol(socket, generator); std::cout << "Created RPC Protocol" << std::endl; p2p::Kademlia::MapDatabase<1> database; std::cout << "Created database" << std::endl; IdType myId; myId.data[0] = 'A'; p2p::Kademlia::DHT<p2p::UDP::Endpoint, 1> dht(protocol, myId, database); std::cout << "Created DHT" << std::endl; boost::optional<NodeType> r1 = dht.addEndpoint(p2p::UDP::Endpoint(boost::asio::ip::address_v4::loopback(), 46668), p2p::Timeout(2.0)); if (r1) { std::cout << "Endpoint found " << (*r1).endpoint.port() << " " << r1->id.data[0] << std::endl; } else { std::cout << "Endpoint not found" << std::endl; } std::cout << "Finding node..." << std::endl; IdType findId; findId.data[0] = 'B'; boost::optional<NodeType> r2 = dht.findNode(findId, p2p::Timeout(2.0)); if (r2) { std::cout << "Node found" << std::endl; } else { std::cout << "Node not found" << std::endl; } std::cout << "Bucket has:" << std::endl; GroupType group1 = dht.bucketNearest(findId); for (GroupType::Iterator i = group1.iterator(); i.isValid(); i++) { std::cout << " " << (*i).endpoint.port() << " " << (*i).id.data[0] << std::endl; } std::cout << "DHT Nearest is:" << std::endl; GroupType group2 = dht.findNearest(findId); for (GroupType::Iterator i = group2.iterator(); i.isValid(); i++) { std::cout << " " << (*i).endpoint.port() << " " << (*i).id.data[0] << std::endl; } std::cout << "Storing..." << std::endl; IdType dataId; dataId.data[0] = 'C'; bool r3 = dht.store(dataId, p2p::MakeBuffer<TextStream>("Hello world"), p2p::Timeout(2.0)); if (r3) { std::cout << "Store successful" << std::endl; } else { std::cout << "Store failed" << std::endl; } std::cout << "Retrieving..." << std::endl; boost::optional<p2p::Buffer> r4 = dht.findValue(dataId, p2p::Timeout(2.0)); if (r4) { std::cout << "Found data..." << std::endl; printData(*r4); } else { std::cout << "Data not found" << std::endl; } return 0; }