Example #1
0
 std::vector<uint8_t> TransmitRequest::SerializeFrame() const {
   std::vector<uint8_t> temp;
   temp.push_back(start);
   std::vector<uint8_t> t1 = HexData(length);
   temp.insert(temp.end(), t1.begin(), t1.end());
   temp.push_back(frame_type);
   temp.push_back(frame_id);
   t1 = HexData(target_mac_64);
   temp.insert(temp.end(), t1.begin(), t1.end());
   t1 = HexData(target_mac_16);
   temp.insert(temp.end(), t1.begin(), t1.end());
   temp.push_back(broadcast_radius);
   temp.push_back(options);
   auto itr = data.begin();
   while(*itr != 0x00)
     temp.push_back(*itr++);
   temp.push_back(checksum);
   return temp;
 }
Example #2
0
void XBeeRemote::init()
{
    std::string hex = HexData(_interface->macAddress()).toHexStr();
    sendAT(std::string("DH"+hex.substr(0,8)));
    sendAT(std::string("DL"+hex.substr(8,8)));
}
Example #3
0
int main(int argc, char* argv[])
{
	const char* dbname;
	const char* verifykey = NULL;
	union {
		unsigned char buf[64];
		uint256_t hash;
	};
	std::vector<node_t> nodes;
	std::vector<node_t>::const_iterator it;
	int idx, cnt, pos;
	int mode = MODE_ROOT;
	char *ptr;
	DB* db;

	if(argc<2) {
		fprintf(stderr, "Usage: %s <dbname> [key=verifier key] [<position>|<hash>|root|dump|gendata]\n", argv[0]);
		return 0;
	}

	dbname = argv[1];

	for(idx=2; idx<argc; ++idx) {
		if(!strncmp(argv[idx], "key=", 4)) {
			verifykey = argv[idx] + 4;
		} else if(!strcmp(argv[idx], "dump")) {
			mode = MODE_DUMP;
		} else if(!strcmp(argv[idx], "root")) {
			mode = MODE_ROOT;
		} else if(!strcmp(argv[idx], "gendata")) {
			mode = MODE_GENTESTDATA;
		} else if(sizeof(uint256_t)*2==strlen(argv[idx])) {
			if(!HexData(argv[idx], buf, sizeof(buf))) {
				fprintf(stderr, "Invalid hash value: %s\n", argv[idx]);
				return 0;
			}
			mode = MODE_HASH;
		} else if(argv[idx][0]>='0' && argv[idx][0]<='9') {
			pos = strtol(argv[idx], &ptr, 10);
			if(ptr && *ptr) {
				fprintf(stderr, "Invalid position value: %s\n", argv[idx]);
				return 0;
			}
			mode = MODE_POSITION;
		} else {
			fprintf(stderr, "Unknown option: %s\n", argv[idx]);
			return 0;
		}
	}

	if(MODE_GENTESTDATA==mode) {
		if(!GenTestData(dbname))
			fprintf(stderr, "Error generating data\n");
	}

	db = new DB(dbname, verifykey);
	if(!db->Open()) {
		fprintf(stderr, "Open DB failed\n");
		delete(db);
		return 0;
	}

	switch(mode) {
	case MODE_HASH:
		if(db->GetNodes(hash, nodes)) {
			idx = 0;
			for(idx=0,it=nodes.begin(); idx<nodes.size(); idx+=2) {
				fprintf(stdout, "%d: ", idx/2);
				if(idx+1<nodes.size()) {
					ShowHex(it->hash, sizeof(it->hash), false);
					++it;
					fprintf(stdout, " / ");
				}
				ShowHex(it->hash, sizeof(it->hash), true);
				++it;
			}
		} else
			fprintf(stderr, "Hash not found\n");

		break;
	case MODE_POSITION:
		if(db->GetNodes(pos, nodes)) {
			idx = 0;
			for(idx=0,it=nodes.begin(); idx<nodes.size(); idx+=2) {
				fprintf(stdout, "%d: ", idx/2);
				if(idx+1<nodes.size()) {
					ShowHex(it->hash, sizeof(it->hash), false);
					++it;
					fprintf(stdout, " / ");
				}
				ShowHex(it->hash, sizeof(it->hash), true);
				++it;
			}
		} else
			fprintf(stderr, "Error reading tree\n");

		break;
	case MODE_ROOT:
		if(db->GetRoot(nodes)) {
			fprintf(stdout, "Root %ld: ", nodes[2].data.value);
			ShowHex(nodes[2].hash, sizeof(nodes[2].hash), true);
			fprintf(stdout, "Hashes: ");
			ShowHex(nodes[0].hash, sizeof(nodes[0].hash), false);
			fprintf(stdout, " / ");
			ShowHex(nodes[1].hash, sizeof(nodes[1].hash), true);
		} else
			fprintf(stderr, "Error reading tree\n");

		break;
	case MODE_DUMP:
		if(!db->Dump())
			fprintf(stderr, "Error reading tree\n");
		break;
	}

	return 1;
}