Exemplo n.º 1
0
int main(int argc, char *argv[]) {
	int ret;
	void *p;
	
	/* this is the connection we will make... again, you don't have access to the struct */
	struct xbee_con *conA;
	struct xbee_con *conB;
	
	/* the packet that is recieved... you have access to this! (see xbee.h) */
	struct xbee_pkt *pkt;
	
	/* set the log level REALLY high, so we can see all the messages. default is 0 */
	//xbee_logSetLevel(100);

	/* setup the xbee instances! */
	if (setupXbee(&xbeeA, "/dev/ttyUSB0", &conA, 0x0013A200, 0x402D607E)) exit(1);
	if (setupXbee(&xbeeB, "/dev/ttyUSB1", &conB, 0x0013A200, 0x402D607B)) exit(2);

	usleep(25000);

	/* start the chain reaction! */
	xbee_conTx(xbeeA, conA, "Hello!");

	/* the main loop */
	for (;;) {
		sleep(5);
	}
	
	/* shutdown the libxbee instance */
	xbee_shutdown(xbeeA);
	xbee_shutdown(xbeeB);
	
	return 0;
}
Exemplo n.º 2
0
int main(void) {
	void *d;
	struct xbee *xbee;
	struct xbee_con *con;
	struct xbee_conAddress address;
	xbee_err ret;

	if ((ret = xbee_setup(&xbee, "xbee1", "/dev/ttyUSB0", 57600)) != XBEE_ENONE) {
		printf("ret: %d (%s)\n", ret, xbee_errorToStr(ret));
		return ret;
	}

	if ((ret = xbee_netStart(xbee, 27015, myClientFilter)) != XBEE_ENONE) {
		printf("ret: %d (%s)\n", ret, xbee_errorToStr(ret));
		return ret;
	}

	printf("Ready!... waiting for 30 secs\n");

	usleep(30000000);

	xbee_netStop(xbee);

	xbee_shutdown(xbee);

	return 0;
}
Exemplo n.º 3
0
int main(void) {
	void *d;
	struct xbee *xbee;
	struct xbee_con *con;
	char txRet;
	xbee_err ret;

	if ((ret = xbee_setup(&xbee, "xbee2", "/dev/ttyUSB1", 57600)) != XBEE_ENONE) {
		printf("ret: %d (%s)\n", ret, xbee_errorToStr(ret));
		return ret;
	}
	if ((ret = xbee_conNew(xbee, &con, "Identify", NULL)) != XBEE_ENONE) {
		xbee_log(xbee, -1, "xbee_conNew() returned: %d (%s)", ret, xbee_errorToStr(ret));
		return ret;
	}

	if ((ret = xbee_conCallbackSet(con, myCB, NULL)) != XBEE_ENONE) {
		xbee_log(xbee, -1, "xbee_conCallbackSet() returned: %d", ret);
		return ret;
	}
	
	sleep(3000);
	
	if ((ret = xbee_conEnd(con)) != XBEE_ENONE) {
		xbee_log(xbee, -1, "xbee_conEnd() returned: %d", ret);
		return ret;
	}

	xbee_shutdown(xbee);

	return 0;
}
Exemplo n.º 4
0
int main(int argc, char *argv[]) {
	struct xbee *xbee;
	xbee_err ret;
	int level;

	if ((ret = xbee_setup(&xbee, "xbee1", "/dev/ttyUSB0", 57600)) != XBEE_ENONE) {
		printf("ret: %d (%s)\n", ret, xbee_errorToStr(ret));
		return ret;
	}

	if ((ret = xbee_logLevelGet(xbee, &level)) != XBEE_ENONE) {
		printf("xbee_logLevelGet() returned: %d\n", ret);
		return ret;
	}
	printf("libxbee log level is currently: %d\n", level);
	printf("\nDon't forget you can set the log level via the environment, for example:\n\tXBEE_LOG_LEVEL=100 %s\n\n", argv[0]);

	xbee_log(xbee, 50, "Test Message 1...");

	printf("setting libxbee log level to: 100\n");
	if ((ret = xbee_logLevelSet(xbee, 100)) != XBEE_ENONE) {
		printf("xbee_logLevelSet() returned: %d\n", ret);
		return ret;
	}

	xbee_log(xbee, 50, "Test Message 2...");

	xbee_shutdown(xbee);

	return 0;
}
Exemplo n.º 5
0
int main(void) {
	void *d;
	struct xbee *xbee;
	struct xbee_con *con;
	struct xbee_conAddress address;
	xbee_err ret;

	if ((ret = xbee_setup(&xbee, "xbee1", "/dev/ttyUSB0", 9600)) != XBEE_ENONE) {
		printf("ret: %d (%s)\n", ret, xbee_errorToStr(ret));
		return ret;
	}

	memset(&address, 0, sizeof(address));
	address.addr64_enabled = 1;
	address.addr64[0] = 0x00;
	address.addr64[1] = 0x13;
	address.addr64[2] = 0xA2;
	address.addr64[3] = 0x00;
	address.addr64[4] = 0x40;
	address.addr64[5] = 0x08;
	address.addr64[6] = 0x18;
	address.addr64[7] = 0x26;
	if ((ret = xbee_conNew(xbee, &con, "64-bit Data", &address)) != XBEE_ENONE) {
		xbee_log(xbee, -1, "xbee_conNew() returned: %d (%s)", ret, xbee_errorToStr(ret));
		return ret;
	}

	if ((ret = xbee_conDataSet(con, xbee, NULL)) != XBEE_ENONE) {
		xbee_log(xbee, -1, "xbee_conDataSet() returned: %d", ret);
		return ret;
	}

	if ((ret = xbee_conCallbackSet(con, myCB, NULL)) != XBEE_ENONE) {
		xbee_log(xbee, -1, "xbee_conCallbackSet() returned: %d", ret);
		return ret;
	}

	for (;;) {
		void *p;

		if ((ret = xbee_conCallbackGet(con, (xbee_t_conCallback*)&p)) != XBEE_ENONE) {
			xbee_log(xbee, -1, "xbee_conCallbackGet() returned: %d", ret);
			return ret;
		}

		if (p == NULL) break;

		usleep(1000000);
	}

	if ((ret = xbee_conEnd(con)) != XBEE_ENONE) {
		xbee_log(xbee, -1, "xbee_conEnd() returned: %d", ret);
		return ret;
	}

	xbee_shutdown(xbee);

	return 0;
}
Exemplo n.º 6
0
int main(void) {
	void *d;
	struct xbee *xbee;
	struct xbee_con *con;
	struct xbee_pkt *pkt;
	struct xbee_conAddress address;
	char txRet;
	int i;
	xbee_err ret;

	if ((ret = xbee_setup(&xbee, "xbee2", "/dev/ttyUSB1", 57600)) != XBEE_ENONE) {
		printf("ret: %d (%s)\n", ret, xbee_errorToStr(ret));
		return ret;
	}

	memset(&address, 0, sizeof(address));
	address.addr64_enabled = 1;
	address.addr64[0] = 0x00;
	address.addr64[1] = 0x13;
	address.addr64[2] = 0xA2;
	address.addr64[3] = 0x00;
	address.addr64[4] = 0x40;
	address.addr64[5] = 0x2D;
	address.addr64[6] = 0x60;
	address.addr64[7] = 0x7B;
	if ((ret = xbee_conNew(xbee, &con, "Remote AT", &address)) != XBEE_ENONE) {
		xbee_log(xbee, -1, "xbee_conNew() returned: %d (%s)", ret, xbee_errorToStr(ret));
		return ret;
	}
	
	for (i = 0; i < 60 * 4; i++) {
		unsigned char value;
		if ((ret = xbee_conTx(con, NULL, "IS")) != XBEE_ENONE) break;
		if ((ret = xbee_conRx(con, &pkt, NULL)) != XBEE_ENONE) break;
		
		if ((ret = xbee_pktDigitalGet(pkt, 3, 0, &value)) != XBEE_ENONE) {
			printf("xbee_pktDigitalGet(channel=3): ret %d\n", ret);
		} else {
			printf("D3: %d\n", value);
		}
		
		xbee_pktFree(pkt);
		usleep(250000);
	}
	if (ret != XBEE_ENONE) {
		xbee_log(xbee, -1, "xbee_conTx() or xbee_conRx() returned: %d", ret);
		return ret;
	}
	
	if ((ret = xbee_conEnd(con)) != XBEE_ENONE) {
		xbee_log(xbee, -1, "xbee_conEnd() returned: %d", ret);
		return ret;
	}

	xbee_shutdown(xbee);

	return 0;
}
Exemplo n.º 7
0
int main(int argc, char *argv[]) {
  xbee_err ret;
  struct xbee *xbee;

  struct xbee_conAddress addr;
  struct xbee_con *con;

  if ((ret = xbee_setup(&xbee, "xbee1", "/dev/ttyUSB1", 57600)) != XBEE_ENONE) {
    fprintf(stderr, "failed to setup libxbee...\n");
    return 1;
  }

  memset(&addr, 0, sizeof(addr));
  addr.addr64_enabled = 1;
  addr.addr64[0] = 0x00;
  addr.addr64[1] = 0x13;
  addr.addr64[2] = 0xA2;
  addr.addr64[3] = 0x00;
	addr.addr64[4] = 0x40;
	addr.addr64[5] = 0x4B;
	addr.addr64[6] = 0x75;
	addr.addr64[7] = 0xDE;

  if ((ret = xbee_conNew(xbee, &con, "64-bit Data", &addr)) != XBEE_ENONE) {
    fprintf(stderr, "failed to setup a connection...\n");
    return 2;
  }

	if ((ret = xbee_conDataSet(con, xbee, NULL)) != XBEE_ENONE) {
		fprintf(stderr, "failed to setup connection data...\n");
		return 3;
	}

	if ((ret = xbee_conCallbackSet(con, callback, NULL)) != XBEE_ENONE) {
		fprintf(stderr, "failed to setup connection callback...\n");
		return 4;
	}

	for (;;) {
		void *p;
		if ((ret = xbee_conDataGet(con, &p)) != XBEE_ENONE) {
			fprintf(stderr, "failed to get connection's data...\n");
			return 5;
		}
		if (p == NULL) break;
		usleep(25000);
	}

	xbee_conEnd(con);
	xbee_shutdown(xbee);

	sleep(5);

	fprintf(stderr, "test complete!\n");
  
  return 0;
}
Exemplo n.º 8
0
int main(void) {
	void *d;
	struct xbee *xbee;
	struct xbee_con *con;
	unsigned char txRet;
	xbee_err ret;

	/* setup libxbee, using the USB to Serial adapter '/dev/ttyUSB0' at 57600 baud */
	if ((ret = xbee_setup(&xbee, "xbee1", "/dev/ttyUSB0", 57600)) != XBEE_ENONE) {
		printf("ret: %d (%s)\n", ret, xbee_errorToStr(ret));
		return ret;
	}

	/* create a new AT connection to the local XBee */
	if ((ret = xbee_conNew(xbee, &con, "Local AT", NULL)) != XBEE_ENONE) {
		xbee_log(xbee, -1, "xbee_conNew() returned: %d (%s)", ret, xbee_errorToStr(ret));
		return ret;
	}

	/* send the AT command 'NI' (request the Node Identifier)
	   when the response is recieved, the packet will be directed to the callback function */
	ret = xbee_conTx(con, &txRet, "NI");
	/* print out the return value
	   if this is non-zero, then check 'enum xbee_errors' in xbee.h for its meaning
	   alternatively look at the xbee_errorToStr() function */
	printf("tx: %d\n", ret);
	if (ret) {
		/* if ret was non-zero, then some error occured
		   if ret == XBEE_ETX then it is possible that txRet is now -17 / XBEE_ETIMEOUT
		   alternatively, txRet will contain the status code returned by the XBee */
		printf("txRet: %d\n", txRet);
	} else {
		struct xbee_pkt *pkt;
		if ((ret = xbee_conRx(con, &pkt, NULL)) != XBEE_ENONE) {
			printf("Error after calling xbee_conRx(): %s\n", xbee_errorToStr(ret));
		} else {
			int i;
			printf("Response is %d bytes long:\n", pkt->dataLen);
			for (i = 0; i < pkt->dataLen; i++) {
				printf("%3d: 0x%02X - %c\n", i, pkt->data[i], (((pkt->data[i] >= ' ') && (pkt->data[i] <= '~'))?pkt->data[i]:'.'));
			}
		}
	}
	
	/* shutdown the connection */
	if ((ret = xbee_conEnd(con)) != XBEE_ENONE) {
		xbee_log(xbee, -1, "xbee_conEnd() returned: %d", ret);
		return ret;
	}

	/* shutdown libxbee */
	xbee_shutdown(xbee);

	return 0;
}
Exemplo n.º 9
0
int main(void) {
	void *d;
	struct xbee *xbee;
	struct xbee_con *con;
	xbee_err ret;
	unsigned char txRet;
	struct timespec to;

	if (sem_init(&ndComplete, 0, 0) != 0) {
		printf("sem_init() returned an error: %d - %s\n", errno, strerror(errno));
		return -1;
	}
	
	if ((ret = xbee_setup(&xbee, "xbee1", "/dev/ttyUSB0", 57600)) != XBEE_ENONE) {
		printf("ret: %d (%s)\n", ret, xbee_errorToStr(ret));
		return ret;
	}

	if ((ret = xbee_conNew(xbee, &con, "Local AT", NULL)) != XBEE_ENONE) {
		xbee_log(xbee, -1, "xbee_conNew() returned: %d (%s)", ret, xbee_errorToStr(ret));
		return ret;
	}

	if ((ret = xbee_conCallbackSet(con, nodeCB, NULL)) != XBEE_ENONE) {
		xbee_log(xbee, -1, "xbee_conCallbackSet() returned: %d", ret);
		return ret;
	}

	if ((ret = xbee_conTx(con, &txRet, "ND")) != XBEE_ENONE && (ret != XBEE_ETX && ret != XBEE_ETIMEOUT)) {
		xbee_log(xbee, -1, "xbee_conTx() returned: %d-%d", ret, txRet);
		return ret;
	}

	printf("ND Sent!... waiting for completion\n");

	clock_gettime(CLOCK_REALTIME, &to);
	to.tv_sec  += 10;
	if (sem_timedwait(&ndComplete, &to) != 0) {
		if (errno == ETIMEDOUT) {
			printf("Timeout while waiting for ND command to complete...\n");
		} else {
			printf("Error calling sem_timedwait()... sleeping for 10 seconds instead\n");
			sleep(10);
		}
	}

	if ((ret = xbee_conEnd(con)) != XBEE_ENONE) {
		xbee_log(xbee, -1, "xbee_conEnd() returned: %d", ret);
		return ret;
	}

	xbee_shutdown(xbee);

	return 0;
}
Exemplo n.º 10
0
int main(void) {
	void *d;
	struct xbee *xbee;
	struct xbee_con *con;
	struct xbee_conAddress address;
	struct xbee_conSettings settings;
	xbee_err ret;

	if ((ret = xbee_setup(&xbee, "xbee2", "/dev/ttyUSB1", 57600)) != XBEE_ENONE) {
		printf("ret: %d (%s)\n", ret, xbee_errorToStr(ret));
		return ret;
	}

	memset(&address, 0, sizeof(address));
	address.addr64_enabled = 1;
	address.addr64[0] = 0x00;
	address.addr64[1] = 0x00;
	address.addr64[2] = 0x00;
	address.addr64[3] = 0x00;
	address.addr64[4] = 0x00;
	address.addr64[5] = 0x00;
	address.addr64[6] = 0xFF;
	address.addr64[7] = 0xFF;
	if ((ret = xbee_conNew(xbee, &con, "Data", &address)) != XBEE_ENONE) {
		xbee_log(xbee, -1, "xbee_conNew() returned: %d (%s)", ret, xbee_errorToStr(ret));
		return ret;
	}

	if ((ret = xbee_conCallbackSet(con, myCB, NULL)) != XBEE_ENONE) {
		xbee_log(xbee, -1, "xbee_conCallbackSet() returned: %d", ret);
		return ret;
	}

	/* getting an ACK for a broadcast message is kinda pointless... */
	xbee_conSettings(con, NULL, &settings);
	settings.disableAck = 1;
	xbee_conSettings(con, &settings, NULL);

	for (;;) {
		xbee_conTx(con, NULL, "Hello...\r\n");

		/* you probrably don't want to transmit much quicker than once per 2 seconds... read the datashee for more info */
		sleep(2);
	}

	if ((ret = xbee_conEnd(con)) != XBEE_ENONE) {
		xbee_log(xbee, -1, "xbee_conEnd() returned: %d", ret);
		return ret;
	}

	xbee_shutdown(xbee);

	return 0;
}
Exemplo n.º 11
0
int main(void) {
	void *d;
	struct xbee *xbee;
	struct xbee_con *con;
	struct xbee_conAddress address;
	unsigned char txRet;
	xbee_err ret;

	if ((ret = xbee_setup(&xbee, "xbee2", "/dev/ttyUSB1", 57600)) != XBEE_ENONE) {
		printf("ret: %d (%s)\n", ret, xbee_errorToStr(ret));
		return ret;
	}

	/* this is the 64-bit address of the remote XBee module
	   it should be entered with the MSB first, so the address below is
	   SH = 0x0013A200    SL = 0x40081826 */
	memset(&address, 0, sizeof(address));
	address.addr64_enabled = 1;
	address.addr64[0] = 0x00;
	address.addr64[1] = 0x13;
	address.addr64[2] = 0xA2;
	address.addr64[3] = 0x00;
	address.addr64[4] = 0x40;
	address.addr64[5] = 0x2D;
	address.addr64[6] = 0x60;
	address.addr64[7] = 0x7B;
	if ((ret = xbee_conNew(xbee, &con, "Remote AT", &address)) != XBEE_ENONE) {
		xbee_log(xbee, -1, "xbee_conNew() returned: %d (%s)", ret, xbee_errorToStr(ret));
		return ret;
	}

	if ((ret = xbee_conCallbackSet(con, myCB, NULL)) != XBEE_ENONE) {
		xbee_log(xbee, -1, "xbee_conCallbackSet() returned: %d", ret);
		return ret;
	}
	
	ret = xbee_conTx(con, &txRet, "NI");
	printf("tx: %d\n", ret);
	if (ret) {
		printf("txRet: %d\n", txRet);
	} else {
		usleep(1000000);
	}
	
	if ((ret = xbee_conEnd(con)) != XBEE_ENONE) {
		xbee_log(xbee, -1, "xbee_conEnd() returned: %d", ret);
		return ret;
	}

	xbee_shutdown(xbee);

	return 0;
}
Exemplo n.º 12
0
EXPORT libxbee::XBee::~XBee(void) {
	std::list<Con*>::iterator con;

	for (con = conList.begin(); con != conList.end(); con++) {
		(*con)->xbee = NULL;
		xbee_conEnd((*con)->con);
		(*con)->con = NULL;
	}

	xbee_shutdown(xbee);
	xbeeList.remove(this);
}
Exemplo n.º 13
0
int main(void) {
	void *d;
	struct xbee *xbee;
	struct xbee_con *con;
	struct xbee_conAddress address;
	struct xbee_conSettings settings;
	xbee_err ret;

	if ((ret = xbee_setup(&xbee, "xbee1", "/dev/ttyUSB0", 57600)) != XBEE_ENONE) {
		printf("ret: %d (%s)\n", ret, xbee_errorToStr(ret));
		return ret;
	}

	memset(&address, 0, sizeof(address));
	address.addr64_enabled = 1;
	address.addr64[0] = 0x00;
	address.addr64[1] = 0x00;
	address.addr64[2] = 0x00;
	address.addr64[3] = 0x00;
	address.addr64[4] = 0x00;
	address.addr64[5] = 0x00;
	address.addr64[6] = 0xFF;
	address.addr64[7] = 0xFF;
	if ((ret = xbee_conNew(xbee, &con, "64-bit Data", &address)) != XBEE_ENONE) {
		xbee_log(xbee, -1, "xbee_conNew() returned: %d (%s)", ret, xbee_errorToStr(ret));
		return ret;
	}

	xbee_conSettings(con, NULL, &settings);
	settings.catchAll = 1;
	xbee_conSettings(con, &settings, NULL);

	if ((ret = xbee_conCallbackSet(con, catchallCB, NULL)) != XBEE_ENONE) {
		xbee_log(xbee, -1, "xbee_conCallbackSet() returned: %d", ret);
		return ret;
	}

	printf("Ready!... waiting for 30 secs\n");
	
	usleep(30000000);

	if ((ret = xbee_conEnd(con)) != XBEE_ENONE) {
		xbee_log(xbee, -1, "xbee_conEnd() returned: %d", ret);
		return ret;
	}

	xbee_shutdown(xbee);

	return 0;
}
Exemplo n.º 14
0
int main(void) {
	void *d;
	struct xbee *xbee;
	struct xbee_con *con;
	struct xbee_conAddress address;
	char txRet;
	xbee_err ret;

	if ((ret = xbee_setup(&xbee, "xbee2", "/dev/ttyUSB1", 57600)) != XBEE_ENONE) {
		printf("ret: %d (%s)\n", ret, xbee_errorToStr(ret));
		return ret;
	}

	memset(&address, 0, sizeof(address));
	address.addr64_enabled = 1;
	address.addr64[0] = 0x00;
	address.addr64[1] = 0x13;
	address.addr64[2] = 0xA2;
	address.addr64[3] = 0x00;
	address.addr64[4] = 0x40;
	address.addr64[5] = 0x2D;
	address.addr64[6] = 0x60;
	address.addr64[7] = 0x7B;
	if ((ret = xbee_conNew(xbee, &con, "Remote AT", &address)) != XBEE_ENONE) {
		xbee_log(xbee, -1, "xbee_conNew() returned: %d (%s)", ret, xbee_errorToStr(ret));
		return ret;
	}

	if ((ret = xbee_conCallbackSet(con, myCB, NULL)) != XBEE_ENONE) {
		xbee_log(xbee, -1, "xbee_conCallbackSet() returned: %d", ret);
		return ret;
	}
	
	ret = xbee_conTx(con, &txRet, "NI");
	printf("tx: %d\n", ret);
	if (ret) {
		printf("txRet: %d\n", txRet);
	} else {
		sleep(1);
	}
	
	if ((ret = xbee_conEnd(con)) != XBEE_ENONE) {
		xbee_log(xbee, -1, "xbee_conEnd() returned: %d", ret);
		return ret;
	}

	xbee_shutdown(xbee);

	return 0;
}
Exemplo n.º 15
0
int main(void) {
	char **modes;
	int i;

	if (xbee_modeGetList(&modes) != XBEE_ENONE) {
		printf("xbee_modeGetList() returned an error...\n");
		return 1;
	}

	for (i = 0; modes[i]; i++) {
		struct xbee *xbee;
		char **types;
		int o;

		printf("mode %d - %s\n", i, modes[i]);

		if (!strcmp(modes[i], "net")) continue;
		if (!strcmp(modes[i], "debug")) continue;

		if (xbee_setup(&xbee, "debug", modes[i]) != XBEE_ENONE) {
			printf("   couldn't startup libxbee...\n");
			continue;
		}

		if (xbee_conGetTypes(xbee, &types) != XBEE_ENONE) {
			printf("   couldn't get a list of con types...\n");
			continue;
		}

		for (o = 0; types[o]; o++) {
			printf("  type %d - %s\n", o, types[o]);
		}

		free(types);

		xbee_shutdown(xbee);

	}

	free(modes);

	return 0;
}
Exemplo n.º 16
0
int main(void) {
	void *d;
	struct xbee *xbee;
	struct xbee_con *con;
	char txRet;
	xbee_err ret;

	if ((ret = xbee_setup(&xbee, "xbee1", "/dev/ttyUSB0", 57600)) != XBEE_ENONE) {
		printf("ret: %d (%s)\n", ret, xbee_errorToStr(ret));
		return ret;
	}

	if ((ret = xbee_conNew(xbee, &con, "Local AT", NULL)) != XBEE_ENONE) {
		xbee_log(xbee, -1, "xbee_conNew() returned: %d (%s)", ret, xbee_errorToStr(ret));
		return ret;
	}

	if ((ret = xbee_conCallbackSet(con, myCB, NULL)) != XBEE_ENONE) {
		xbee_log(xbee, -1, "xbee_conCallbackSet() returned: %d", ret);
		return ret;
	}
	
	ret = xbee_conTx(con, &txRet, "NI");
	printf("tx: %d\n", ret);
	if (ret) {
		printf("txRet: %d\n", txRet);
	} else {
		sleep(1);
	}
	
	if ((ret = xbee_conEnd(con)) != XBEE_ENONE) {
		xbee_log(xbee, -1, "xbee_conEnd() returned: %d", ret);
		return ret;
	}

	xbee_shutdown(xbee);

	return 0;
}
Exemplo n.º 17
0
int main(void) {
	void *d;
	struct xbee *xbee;
	struct xbee_con *con;
	struct xbee_conAddress address;
	xbee_err ret;

	if ((ret = xbee_setup(&xbee, "debug", "xbee1")) != XBEE_ENONE) {
		printf("ret: %d (%s)\n", ret, xbee_errorToStr(ret));
		return ret;
	}

	memset(&address, 0, sizeof(address));
	address.addr64_enabled = 1;
	address.addr64[0] = 0x00;
	address.addr64[1] = 0x13;
	address.addr64[2] = 0xA2;
	address.addr64[3] = 0x00;
	address.addr64[4] = 0x40;
	address.addr64[5] = 0x08;
	address.addr64[6] = 0x18;
	address.addr64[7] = 0x26;
	if ((ret = xbee_conNew(xbee, &con, "64-bit Data", &address)) != XBEE_ENONE) {
		xbee_log(xbee, -1, "xbee_conNew() returned: %d (%s)", ret, xbee_errorToStr(ret));
		return ret;
	}

	xbee_conTx(con, NULL, "testing...");

	if ((ret = xbee_conEnd(con)) != XBEE_ENONE) {
		xbee_log(xbee, -1, "xbee_conEnd() returned: %d", ret);
		return ret;
	}

	xbee_shutdown(xbee);

	return 0;
}
Exemplo n.º 18
0
int main(void) {
	void *d;
	struct xbee *xbee;
	struct xbee_con *con;
	char txRet;
	xbee_err ret;
	int i, o, t;

	sem_init(&sem, 0, 0);

	if ((ret = xbee_setup(&xbee, "xbee1", "/dev/ttyUSB0", 57600)) != XBEE_ENONE) {
		printf("ret: %d (%s)\n", ret, xbee_errorToStr(ret));
		return ret;
	}

	if ((ret = xbee_conNew(xbee, &con, "Local AT", NULL)) != XBEE_ENONE) {
		xbee_log(xbee, -1, "xbee_conNew() returned: %d (%s)", ret, xbee_errorToStr(ret));
		return ret;
	}

	if ((ret = xbee_conCallbackSet(con, myCB, NULL)) != XBEE_ENONE) {
		xbee_log(xbee, -1, "xbee_conCallbackSet() returned: %d", ret);
		return ret;
	}
	
	o = 0;
	t = 0;

	for (i = 0; i < 1000; i++) {
		ret = xbee_conTx(con, &txRet, "NI");
		printf("tx: %d\n", ret);
		if (ret) {
			printf("txRet: %d\n", txRet);
			sleep(1);
		} else {
			struct timespec to;
			clock_gettime(CLOCK_REALTIME, &to);
			to.tv_sec++;
			if (sem_timedwait(&sem, &to) == 0) {
				o++;
				usleep(10000);
			} else {
				printf("             TIMEOUT!\n");
				usleep(250000);
				t++;
			}
		}
	}

	printf("%d / %d / %d - success/timeout/total - success rate (%2.1f%%) / timeout rate (%2.1f%%)\n",
		o, t, i, (double)((double)o/(double)i)*100.0, (double)((double)t/(double)i)*100.0);
	
	if ((ret = xbee_conEnd(con)) != XBEE_ENONE) {
		xbee_log(xbee, -1, "xbee_conEnd() returned: %d", ret);
		return ret;
	}

	xbee_shutdown(xbee);

	return 0;
}
Exemplo n.º 19
0
int main(int argc, char *argv[]) {
	int ret, i;
	sem_t sem;
	void *p;
	struct xbee_pkt_ioData *io;
	
	/* this is our xbee instance... from 'user' space you don't have access to the struct */
	struct xbee *xbee;
	
	/* this is the connection we will make... again, you don't have access to the struct */
	struct xbee_con *con;
	struct xbee_conAddress addr;
	
	/* the packet that is recieved... you have access to this! (see xbee.h) */
	struct xbee_pkt *pkt;
	
	/* make a lixbee instance, and connect it to /dev/ttyUSB1 @ 57600 baud
	   you don't have to keep hold of the returned xbee, in which case you can pass NULL and the most recently started instance will be used! */
	if ((ret = xbee_setup("/dev/ttyUSB0", 57600, &xbee)) != 0) {
		xbee_log(NULL,-1,"xbee_setup(): failed... (%d)", ret);
		exit(1);
	}
	/* setup libxbee to use the series 1 packets - you have to do this before you do anything else! */
	xbee_modeSet(xbee, "series1");
	
	/* get the connection type ID, you pass in a string, it returns an ID */
	if ((ret = xbee_conTypeIdFromName(xbee, "Remote AT", &conType)) != 0) {
		xbee_log(xbee,-1,"xbee_conTypeIdFromName(): failed... (%d)", ret);
		exit(1);
	}
	
	if ((ret = sem_init(&sem, 0, 0)) != 0) {
		xbee_log(xbee,-1,"sem_init(): failed... (%d)", ret);
		exit(1);
	}
	
	/* clear the address field */
	memset(&addr, 0, sizeof(addr));
	/* build a connection to the following address */
	addr.addr64_enabled = 1;
	addr.addr64[0] = 0x00;
	addr.addr64[1] = 0x13;
	addr.addr64[2] = 0xA2;
	addr.addr64[3] = 0x00;
	addr.addr64[4] = 0x40;
	addr.addr64[5] = 0x3C;
	addr.addr64[6] = 0xB2;
	addr.addr64[7] = 0x6B;

	if ((ret = xbee_conNew(xbee, &con, conType, &addr, &sem)) != 0) {
		xbee_log(xbee,-1,"xbee_newcon(): failed... (%d)", ret);
		exit(1);
	}
	{
    struct xbee_conOptions opts;
    /* enable waitForAck... this allows us to see if the packet was sent successfully! */
    xbee_conOptions(xbee, con, &opts, NULL);
    opts.waitForAck = 1;
		opts.queueChanges = 0;
    xbee_conOptions(xbee, con, NULL, &opts);
	}
	/* attach the callback */
	xbee_conAttachCallback(xbee, con, myCB, NULL);

	/* try really hard to get this sent */
	if (ret = safeTx(xbee, con, 50, &pkt, "IS")) {
		printf("Error 'IS' : %d\n", ret);
		goto die;
	}
	
	/* print out the data recieved (in raw form) */
	for (i = 0; i < pkt->datalen; i++) {
		printf("%3d: 0x%02X\n", i, pkt->data[i]);
		fflush(stdout);
	}

#warning The I/O data handling needs re-working after 5c88c6859e458053634ad8417b9f3731dc4972b3
#if 0
	/* print out the data recieved (in friendly form) */
	io = (struct xbee_pkt_ioData *)pkt->data;
	
	printf("count: %d\n", io->sampleCount);
	
	printf("d0: %d\n", io->enable.pin.d0);
	printf("d1: %d\n", io->enable.pin.d1);
	printf("d2: %d\n", io->enable.pin.d2);
	printf("d3: %d\n", io->enable.pin.d3);
	printf("d4: %d\n", io->enable.pin.d4);
	printf("d5: %d\n", io->enable.pin.d5);
	printf("d6: %d\n", io->enable.pin.d6);
	printf("d7: %d\n", io->enable.pin.d7);
	printf("d8: %d\n", io->enable.pin.d8);
	printf("a0: %d\n", io->enable.pin.a0);
	printf("a1: %d\n", io->enable.pin.a1);
	printf("a2: %d\n", io->enable.pin.a2);
	printf("a3: %d\n", io->enable.pin.a3);
	printf("a4: %d\n", io->enable.pin.a4);
	printf("a5: %d\n", io->enable.pin.a5);
	printf("\n");
	/* unfortunately the struct doesn't fit for more than 1 sample */
	if (io->sampleCount >= 1) {
		printf("d0: %d\n", io->sample[0].digital.pin.d0);
		printf("d1: %d\n", io->sample[0].digital.pin.d1);
		printf("d2: %d\n", io->sample[0].digital.pin.d2);
		printf("d3: %d\n", io->sample[0].digital.pin.d3);
		printf("d4: %d\n", io->sample[0].digital.pin.d4);
		printf("d5: %d\n", io->sample[0].digital.pin.d5);
		printf("d6: %d\n", io->sample[0].digital.pin.d6);
		printf("d7: %d\n", io->sample[0].digital.pin.d7);
		printf("d8: %d\n", io->sample[0].digital.pin.d8);
		if (io->enable.pin.a0) printf("a0: %d\n", io->sample[0].a0);
		if (io->enable.pin.a0) printf("a0: %d\n", io->sample[0].a1);
		if (io->enable.pin.a0) printf("a0: %d\n", io->sample[0].a2);
		if (io->enable.pin.a0) printf("a0: %d\n", io->sample[0].a3);
		if (io->enable.pin.a0) printf("a0: %d\n", io->sample[0].a4);
		if (io->enable.pin.a0) printf("a0: %d\n", io->sample[0].a5);
	}
#endif

	xbee_pktFree(pkt);
	
die:
	sem_destroy(&sem);

	/* shutdown the connection */
	xbee_conEnd(xbee, con, NULL);
	
	/* shutdown the libxbee instance */
	xbee_shutdown(xbee);
	
	return 0;
}
Exemplo n.º 20
0
int main(int argc, char *argv[]) {
	int ret;
	sem_t sem;
	void *p;
	
	/* this is our xbee instance... from 'user' space you don't have access to the struct */
	struct xbee *xbee;
	
	/* this is the connection we will make... again, you don't have access to the struct */
	struct xbee_con *con;
	struct xbee_conAddress addr;
	
	/* the packet that is recieved... you have access to this! (see xbee.h) */
	struct xbee_pkt *pkt;
	
	/* make a lixbee instance, and connect it to /dev/ttyUSB1 @ 57600 baud
	   you don't have to keep hold of the returned xbee, in which case you can pass NULL and the most recently started instance will be used! */
	if ((ret = xbee_setup("/dev/ttyUSB0", 57600, &xbee)) != 0) {
		xbee_log(NULL,-1,"xbee_setup(): failed... (%d)", ret);
		exit(1);
	}
	/* setup libxbee to use the series 1 packets - you have to do this before you do anything else! */
	xbee_modeSet(xbee, "series1");
	
	/* get the connection type ID, you pass in a string, it returns an ID */
	if ((ret = xbee_conTypeIdFromName(xbee, "Remote AT", &conType)) != 0) {
		xbee_log(xbee,-1,"xbee_conTypeIdFromName(): failed... (%d)", ret);
		exit(1);
	}
	
	if ((ret = sem_init(&sem, 0, 0)) != 0) {
		xbee_log(xbee,-1,"sem_init(): failed... (%d)", ret);
		exit(1);
	}
	
	/* clear the address field */
	memset(&addr, 0, sizeof(addr));
	/* build a connection to the following address */
	addr.addr64_enabled = 1;
	addr.addr64[0] = 0x00;
	addr.addr64[1] = 0x13;
	addr.addr64[2] = 0xA2;
	addr.addr64[3] = 0x00;
	addr.addr64[4] = 0x40;
	addr.addr64[5] = 0x33;
	addr.addr64[6] = 0xCA;
	addr.addr64[7] = 0xCB;
	if ((ret = xbee_conNew(xbee, &con, conType, &addr, &sem)) != 0) {
		xbee_log(xbee,-1,"xbee_newcon(): failed... (%d)", ret);
		exit(1);
	}
	{
    struct xbee_conOptions opts;
    /* enable waitForAck... this allows us to see if the packet was sent successfully! */
    xbee_conOptions(xbee, con, &opts, NULL);
    opts.waitForAck = 1;
    xbee_conOptions(xbee, con, NULL, &opts);
	}
	/* attach the callback */
	xbee_conAttachCallback(xbee, con, myCB, NULL);

	/* send the request */
	if ((ret = xbee_conTx(xbee, con, "NI")) != 0) {
		xbee_log(xbee,-1,"Something went wrong... (%d)", ret);
	} else {
		struct timespec to;
		clock_gettime(CLOCK_REALTIME, &to);
		to.tv_sec += 5;
		if (sem_timedwait(&sem, &to)) {
			printf("Timeout...\n");
		}
	}

	sem_destroy(&sem);

	/* shutdown the connection */
	xbee_conEnd(xbee, con, NULL);
	
	/* shutdown the libxbee instance */
	xbee_shutdown(xbee);
	
	return 0;
}
Exemplo n.º 21
0
Server::~Server(void)
{
    if (_xbee)
        xbee_shutdown(_xbee);
}