コード例 #1
0
ファイル: main.c プロジェクト: C24IO/libxbee3
void myCB(struct xbee *xbee, struct xbee_con *con, struct xbee_pkt **pkt, void **data) {
	xbee_err ret;
	char *ni;
	struct xbee_conAddress *addr;

	printf("An XBee joined the network!\n");
	
	if ((ret = xbee_pktDataGet(*pkt, "NI", 0, 0, (void**)&ni)) == XBEE_ENONE && ni != NULL) {
		printf("  It is called: [%s]\n", ni);
	} else {
		printf("  Error while retrieving its NI - %d (%s)\n", ret, xbee_errorToStr(ret));
	}
	
	/* you could also use 'Address (16-bit)' or 'Address (64-bit)' to get the raw byte arrays */
	if ((ret = xbee_pktDataGet(*pkt, "Address", 0, 0, (void**)&addr)) == XBEE_ENONE && addr != NULL) {
		printf("  It's address is:\n");
		if (addr->addr16_enabled) {
			printf("   16-bit address:  0x%02X%02X\n", addr->addr16[0], addr->addr16[1]);
		} else {
			printf("   16-bit address:  --\n");
		}
		if (addr->addr64_enabled) {
			printf("   64-bit address:  0x%02X%02X%02X%02X 0x%02X%02X%02X%02X\n",
														addr->addr64[0], addr->addr64[1], addr->addr64[2], addr->addr64[3],
														addr->addr64[4], addr->addr64[5], addr->addr64[6], addr->addr64[7]);
		} else {
			printf("   64-bit address:  --\n");
		}
	} else {
		printf("  Error while retrieving its Address - %d (%s)\n", ret, xbee_errorToStr(ret));
	}
}
コード例 #2
0
ファイル: main.c プロジェクト: alex-melo/libxbee.libxbee-v3
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;
}
コード例 #3
0
ファイル: main.c プロジェクト: C24IO/libxbee3
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;
}
コード例 #4
0
ファイル: main.c プロジェクト: Nithilias/Xbee-comunication
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;
}
コード例 #5
0
ファイル: main.c プロジェクト: C24IO/libxbee3
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;
}
コード例 #6
0
ファイル: main.c プロジェクト: ywang-git/XBeeProject
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;
}
コード例 #7
0
ファイル: main.c プロジェクト: alex-melo/libxbee.libxbee-v3
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;
}
コード例 #8
0
ファイル: main.c プロジェクト: C24IO/libxbee3
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;
}
コード例 #9
0
ファイル: main.c プロジェクト: alex-melo/libxbee.libxbee-v3
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;
}
コード例 #10
0
ファイル: main.c プロジェクト: alex-melo/libxbee.libxbee-v3
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;
}
コード例 #11
0
ファイル: main.c プロジェクト: bensmith28/EagleEye
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;
}
コード例 #12
0
ファイル: main.c プロジェクト: C24IO/libxbee3
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;
}
コード例 #13
0
ファイル: main.c プロジェクト: alex-melo/libxbee.libxbee-v3
void catchallCB(struct xbee *xbee, struct xbee_con *con, struct xbee_pkt **pkt, void **data) {
	xbee_err ret;
	struct xbee_con *newCon;
	
	printf("Got packet from new node!\n");
	if ((*pkt)->address.addr16_enabled) {
		printf("    16-bit (0x%02X%02X)\n", (*pkt)->address.addr16[0], (*pkt)->address.addr16[1]);
	}
	if ((*pkt)->address.addr64_enabled) {
		printf("    64-bit (0x%02X%02X%02X%02X 0x%02X%02X%02X%02X)\n", (*pkt)->address.addr64[0], (*pkt)->address.addr64[1],
		                                                               (*pkt)->address.addr64[2], (*pkt)->address.addr64[3],
		                                                               (*pkt)->address.addr64[4], (*pkt)->address.addr64[5],
		                                                               (*pkt)->address.addr64[6], (*pkt)->address.addr64[7]);
	}
	if ((*pkt)->address.endpoints_enabled) {
		printf("    Endpoints (local: 0x%02X, remote: 0x%02X)\n", (*pkt)->address.endpoint_local,
		                                                          (*pkt)->address.endpoint_remote);
	}
	
	/* you should really hold on to the returned newCon somehow, but for the sample it is just let loose! */
	if ((ret = xbee_conNew(xbee, &newCon, (*pkt)->conType, &(*pkt)->address)) != XBEE_ENONE) {
		xbee_log(xbee, -1, "xbee_conNew() returned: %d (%s)", ret, xbee_errorToStr(ret));
		return;
	}

	if ((ret = xbee_conCallbackSet(newCon, specificCB, NULL)) != XBEE_ENONE) {
		xbee_conEnd(newCon);
		xbee_log(xbee, -1, "xbee_conCallbackSet() returned: %d", ret);
		return;
	}
	
	specificCB(xbee, newCon, pkt, data);
}
コード例 #14
0
ファイル: Server.cpp プロジェクト: martinvEsiee/AlgoCarto
bool
Server::Init(const std::string& port)
{
    xbee_err ret;

    //"\\\\.\\COM16"
    if ((ret = xbee_setup(&_xbee, "xbee2", port)) != XBEE_ENONE) {
        printf("ret: %d (%s)\n", ret, xbee_errorToStr(ret));
        return false;
    }
    return true;
}
コード例 #15
0
ファイル: rx.c プロジェクト: OpenISDM/Lbeacon-zigbee
xbee_err xbee_rx(struct xbee *xbee, int *restart, void *arg) {
	xbee_err ret;
	struct xbee_rxInfo *info;
	struct xbee_tbuf *buf;
	
	info = arg;
	if (!info->bufList || !info->ioFunc) {
		*restart = 0;
		return XBEE_EINVAL;
	}
	
	while (!xbee->die) {
		buf = NULL;
		if ((ret = info->ioFunc(xbee, info->ioArg, &buf)) != XBEE_ENONE) {
			if (ret == XBEE_EEOF) {
				*restart = 0;
				if (info->eofCallback) info->eofCallback(xbee, info);
				return XBEE_EEOF;
			} else if (ret == XBEE_ESHUTDOWN && xbee->die) {
				break;
			}
			xbee_log(1, "rx() returned %d (%s)... retrying in 10 ms", ret, xbee_errorToStr(ret));
			usleep(10000); /* 10 ms */
			continue;
		}

#ifndef XBEE_DISABLE_LOGGING
#ifndef XBEE_LOG_NO_RX
		if (xbee->log->enable_rx) {
			/* format: tx[0x0000000000000000] */
			char label[42]; /* enough space for a 64-bit pointer and ANSI color codes */
#ifndef XBEE_LOG_NO_COLOR
			if (xbee->log->use_color) {
				snprintf(label, sizeof(label), "Rx[%c[%dm%p%c[0m]", 27, 30 + info->logColor, info,  27);
			} else {
#endif /* !XBEE_LOG_NO_COLOR */
				snprintf(label, sizeof(label), "Rx[%p]", info);
#ifndef XBEE_LOG_NO_COLOR
			}
#endif /* !XBEE_LOG_NO_COLOR */
			xbee_logData(25, label, buf->data, buf->len);
		}
#endif /* !XBEE_LOG_NO_RX */
#endif /* !XBEE_DISABLE_LOGGING */
		
		if (xbee_ll_add_tail(info->bufList, buf) != XBEE_ENONE) return XBEE_ELINKEDLIST;
		buf = NULL;
		if (xsys_sem_post(&info->sem) != 0) return XBEE_ESEMAPHORE;
	}
	
	return XBEE_ESHUTDOWN;
}
コード例 #16
0
ファイル: main.c プロジェクト: C24IO/libxbee3
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;
}
コード例 #17
0
ファイル: Server.cpp プロジェクト: martinvEsiee/AlgoCarto
bool
Server::StartConnection(void)
{
    xbee_err ret;

    if (_connection != nullptr)
        EndConnection();
    if ((ret = xbee_conNew(_xbee, &_connection, "Local AT", NULL)) != XBEE_ENONE) {
        printf("xbee_conNew: %d (%s)\n", ret, xbee_errorToStr(ret));
        return false;
    }
    return true;
}
コード例 #18
0
ファイル: main.c プロジェクト: C24IO/libxbee3
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;
}
コード例 #19
0
ファイル: Server.cpp プロジェクト: martinvEsiee/AlgoCarto
bool
Server::EndConnection(void)
{
    xbee_err ret;

    if (_connection == nullptr)
        return false;
    if ((ret = xbee_conEnd(_connection)) != XBEE_ENONE) {
        printf("xbee_conEnd: %d (%s)\n", ret, xbee_errorToStr(ret));
        return false;
    }
    _connection = nullptr;
    return true;
}
コード例 #20
0
ファイル: main.c プロジェクト: C24IO/libxbee3
int main(int argc, char *argv[]) {
	int mode = -1;
	char *filename = NULL;
	FILE *f = NULL;
	int write = 0;
	
	xbee_err ret;
	struct xbee *xbee;
	struct xbee_con *con;
	
	int i;
	char *t;
	
	for (i = 1; i < argc; i++) {
		
		if (argv[i][0] == '-' && argv[i][1] == '-') {
			t = &(argv[i][2]);
			if (!strcmp(t, "save")) {
				mode = 1;
			} else if (!strcmp(t, "load")) {
				mode = 2;
			} else if (!strcmp(t, "write")) {
				write = 1;
			} else if (!strcmp(t, "file")) {
				if (++i >= argc) usage(argv[0]);
				filename = argv[i];
			}
			continue;
		}
		if (argv[i][0] == '-') {
			int o;
			for (o = 1; o >= 0 && argv[i][o]; o++) {
				switch (argv[i][o]) {
					case 's': mode = 1;  break;
					case 'l': mode = 2;  break;
					case 'w': write = 1; break;
          case 'f':
						if (argv[i][o+1] != '\0') usage(argv[0]);
						if (++i >= argc) usage(argv[0]);
						filename = argv[i];
						o = -2;
						break;
				}
			}
			continue;
		}
		usage(argv[0]);
	}
	if (mode == -1) usage(argv[0]);
	
	if (mode == 1) {
		if (!filename) {
			f = stdout;
		} else {
			f = fopen(filename, "w");
		}
	} else if (mode == 2) {
		if (!filename) {
			f = stdin;
		} else {
			f = fopen(filename, "r");
		}
	} else {
		usage(argv[0]);
	}
	
	if (!f) {
		perror("fopen()");
		exit(1);
	}
	
	if ((ret = xbee_setup(&xbee, "xbee1", "/dev/ttyUSB0", 57600)) != XBEE_ENONE) {
		fprintf(stderr, "xbee_setup(): %d - %s\n", ret, xbee_errorToStr(ret));
		exit(1);
	}
	
	if ((ret = xbee_conNew(xbee, &con, "Local AT", NULL)) != XBEE_ENONE) {
		fprintf(stderr, "xbee_conNew(): %d - %s\n", ret, xbee_errorToStr(ret));
		exit(1);
	}
	
	if (mode == 1) {
		config_save(f, con);
	} else {
		config_load(f, con, write);
	}

	fprintf(stderr, "complete!\n");
}
コード例 #21
0
ファイル: main.c プロジェクト: C24IO/libxbee3
void config_save(FILE *f, struct xbee_con *con) {
	int a,b,s,l,q;
	int i;
	
	xbee_err ret;
	unsigned char retVal;
	struct xbee_pkt *pkt;
	unsigned char cmd[3];
	
	l = sizeof(skip) / sizeof(*skip);
	fprintf(stderr, "Skipping %d special commands:", l);
	for (i = 0; i < l; i++) {
		if (!(i % 10)) fprintf(stderr,"\n  ");
		fprintf(stderr, "%s%s", (i % 10 ? ", " : ""), skip[i]);
	}
	fprintf(stderr, "\n");
	
	i = 0;
	for (a = 0; achars[a]; a++) {
		for (b = 0; bchars[b]; b++) {
			for (s = 0; s < l; s++) {
				if (!skip[s]) continue;
				if (skip[s][0] == '\0') continue;
				if (skip[s][1] == '\0') continue;
				if (achars[a] == skip[s][0] && bchars[b] == skip[s][1]) break;
			}
			if (s != l) continue;
			if ((ret = xbee_conPurge(con)) != XBEE_ENONE) {
				fprintf(stderr, "xbee_conPurge(): %d - %s\n", ret, xbee_errorToStr(ret));
				exit(1);
			}
			cmd[0] = achars[a];
			cmd[1] = bchars[b];
			cmd[2] = '\0';
			if ((ret = xbee_conTx(con, &retVal, "%c%c", achars[a], bchars[b])) != XBEE_ENONE && ret != XBEE_ETX) {
				fprintf(stderr, "xbee_conTx(): %d - %s\n", ret, xbee_errorToStr(ret));
				exit(1);
			}
			if (retVal != 0) continue;
			if ((ret = xbee_conRx(con, &pkt, NULL)) != XBEE_ENONE) {
				fprintf(stderr, "xbee_conRx(): %d - %s\n", ret, xbee_errorToStr(ret));
				exit(1);
			}
			if (pkt->status != 0) {
				fprintf(stderr, "xbee_conRx(): AT command returned error - %d\n", pkt->status);
				exit(1);
			}
			if (strncasecmp(pkt->atCommand, cmd, 2)) {
				fprintf(stderr, "xbee_conRx(): AT command response mis-match\n");
				exit(1);
			}
			if (pkt->dataLen > 0) {
				fprintf(stderr, "\r%c%c...", achars[a], bchars[b]);
				fflush(stderr);
				fprintf(f, "%c%c =", achars[a], bchars[b]);
				for (q = 0; q < pkt->dataLen; q++) {
					fprintf(f, " 0x%02X", pkt->data[q]);
				}
				fprintf(f, "\n");
				i++;
			}
			xbee_pktFree(pkt);
		}
	}
	
	printf("\rTotal: %d\n", i);
}
コード例 #22
0
ファイル: main.c プロジェクト: bensmith28/EagleEye
void xbee_error(xbee_err err) {
	printf("xbee_setup(): %d - %s\n", err, xbee_errorToStr(err));
	exit(1);
}
コード例 #23
0
ファイル: main.c プロジェクト: C24IO/libxbee3
void config_load(FILE *f, struct xbee_con *con, int write) {
	char *buf;
	int bufLen;
	char *p, *q;
	int a, b;
	unsigned char val;
	
	xbee_err ret;
	struct xbee_pkt *pkt;
	unsigned char retVal;
	struct xbee_conSettings settings;
	
	if (xbee_conSettings(con, NULL, &settings) != XBEE_ENONE) return;
	settings.queueChanges = 1;
	if (xbee_conSettings(con, &settings, NULL) != XBEE_ENONE) return;
	
	buf = NULL;
	bufLen = 0;
	
	while (!feof(f)) {
		if (getline(&buf, &bufLen, f) == -1) {
			if (feof(f)) break;
			fprintf(stderr, "\ngetline(): unknown error...\n");
			exit(1);
		}
		
		if (buf[0] == '#') continue;
		
		for (a = 0; achars[a]; a++) {
			if (achars[a] == buf[0]) break;
		}
		if (!achars[a]) goto skip;
		
		for (b = 0; bchars[b]; b++) {
			if (bchars[b] == buf[1]) break;
		}
		if (!bchars[b]) goto skip;
		
		p = &(buf[2]);
		q = strchr(p, '=');
		*q = '\0';
		q++;
		
		while (*q != '\0' && *q != '\n') {
			while (*q == ' ') { q++; }
			if (sscanf(q, "0x%02hhX", &val) != 1) {
				fprintf(stderr, "\nInvalid parameters for %c%c\n", buf[0], buf[1]);
				exit(1);
			}
			q += 4;
			*p = val;
			if (p != &(buf[2]) || val != 0) p++;
		}
		if (p == &(buf[2])) p++;
		
		fprintf(stderr, "\r%c%c...", buf[0], buf[1]);
		fflush(stderr);
		if ((ret = xbee_conPurge(con)) != XBEE_ENONE) {
			fprintf(stderr, "\nxbee_conPurge(): %d - %s\n", ret, xbee_errorToStr(ret));
			exit(1);
		}
		if ((ret = xbee_connTx(con, &retVal, buf, p - buf + 1)) != XBEE_ENONE && ret != XBEE_ETX) {
			fprintf(stderr, "\nxbee_conTx(): %d - %s\n", ret, xbee_errorToStr(ret));
			exit(1);
		}
		if (retVal != 0) {
			fprintf(stderr, "\nError sending command: %c%c - %hhd\n", buf[0], buf[1], retVal);
			//exit(1);
		}
		continue;
		
skip:
		fprintf(stderr, "\nSkipping invalid command: %c%c\n", buf[0], buf[1]);
	}
	
	if (buf) free(buf);
	
	if (xbee_conSettings(con, NULL, &settings) != XBEE_ENONE) return;
	settings.queueChanges = 0;
	if (xbee_conSettings(con, &settings, NULL) != XBEE_ENONE) return;
	
	xbee_conTx(con, NULL, "AC");
	if (write) xbee_conTx(con, NULL, "WR");
}
コード例 #24
0
ファイル: in_xbee.c プロジェクト: syohex/fluent-bit
/* Init kmsg input */
int in_xbee_init(struct flb_config *config)
{
    int ret;
    int opt_baudrate = 9600;
    char *tmp;
    char *opt_device = FLB_XBEE_DEFAULT_DEVICE;
    struct stat dev_st;
	struct xbee *xbee;
	struct xbee_con *con;
	struct xbee_conAddress address;
    struct flb_in_xbee_config *ctx;

    /* Check an optional baudrate */
    tmp = getenv("FLB_XBEE_BAUDRATE");
    if (tmp) {
        opt_baudrate = atoi(tmp);
    }

    /* Get the target device entry */
    tmp = getenv("FLB_XBEE_DEVICE");
    if (tmp) {
        opt_device = strdup(tmp);
    }
    flb_info("XBee device=%s, baudrate=%i", opt_device, opt_baudrate);

    ret = stat(opt_device, &dev_st);
    if (ret < 0) {
        printf("Error: could not open %s device\n", opt_device);
        exit(EXIT_FAILURE);
    }

    if (!S_ISCHR(dev_st.st_mode)) {
        printf("Error: invalid device %s \n", opt_device);
        exit(EXIT_FAILURE);
    }

    if (access(opt_device, R_OK | W_OK) == -1) {
        printf("Error: cannot open the device %s (permission denied ?)\n",
               opt_device);
        exit(EXIT_FAILURE);
    }

    /* Init library */
    xbee_init();

	ret = xbee_setup(&xbee, "xbeeZB", opt_device, opt_baudrate);
    if (ret != XBEE_ENONE) {
        flb_utils_error_c("xbee_setup");
		return ret;
	}

    /* FIXME: just a built-in example */
	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] = 0xB7;
    address.addr64[6] = 0xB1;
    address.addr64[7] = 0xEB;

    /* Prepare a connection with the peer XBee */
	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;
	}

    /* Prepare the configuration context */
    ctx = calloc(1, sizeof(struct flb_in_xbee_config));
    if (!ctx) {
        perror("calloc");
        return -1;
    }
    ctx->device     = opt_device;
    ctx->baudrate   = opt_baudrate;
    ctx->con        = con;
    ctx->buffer_len = 0;

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


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


    /* Set the context */
    ret = flb_input_set_context("xbee", ctx, config);
    if (ret == -1) {
        flb_utils_error_c("Could not set configuration for xbee input plugin");
    }

    /*
     * Set our collector based on time. We will trigger a collection at certain
     * intervals. For now it works but it's not the ideal implementation. I am
     * talking with libxbee maintainer to check possible workarounds and use
     * proper events mechanism.
     */
    ret = flb_input_set_collector_time("xbee",
                                       in_xbee_collect,
                                       IN_XBEE_COLLECT_SEC,
                                       IN_XBEE_COLLECT_NSEC,
                                       config);
    if (ret == -1) {
        flb_utils_error_c("Could not set collector for xbee input plugin");
    }

    return 0;
}
コード例 #25
0
ファイル: main.c プロジェクト: C24IO/libxbee3
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;
}
コード例 #26
0
ファイル: in_xbee.c プロジェクト: coxnegative/fluent-bit
/* Init xbee input */
int in_xbee_init(struct flb_config *config, void *data)
{
    int ret;
    struct stat dev_st;
    struct xbee *xbee;
    struct xbee_conAddress address;
    struct flb_in_xbee_config *ctx;
    struct xbee_conSettings settings;
    (void) data;

    /* Prepare the configuration context */
    ctx = calloc(1, sizeof(struct flb_in_xbee_config));
    if (!ctx) {
        perror("calloc");
        return -1;
    }

    if (!config->file) {
        flb_utils_error_c("XBee input plugin needs configuration file");
        return -1;
    }

    xbee_config_read(ctx, config->file);

    /* initialize MessagePack buffers */
    msgpack_sbuffer_init(&ctx->mp_sbuf);
    msgpack_packer_init(&ctx->mp_pck, &ctx->mp_sbuf, msgpack_sbuffer_write);

    flb_info("XBee device=%s, baudrate=%i", ctx->file, ctx->baudrate);

    ret = stat(ctx->file, &dev_st);
    if (ret < 0) {
        printf("Error: could not open %s device\n", ctx->file);
        free(ctx->file);
        exit(EXIT_FAILURE);
    }

    if (!S_ISCHR(dev_st.st_mode)) {
        printf("Error: invalid device %s \n", ctx->file);
        free(ctx->file);
        exit(EXIT_FAILURE);
    }

    if (access(ctx->file, R_OK | W_OK) == -1) {
        printf("Error: cannot open the device %s (permission denied ?)\n",
               ctx->file);
        free(ctx->file);
        exit(EXIT_FAILURE);
    }

    ctx->config = config;
    pthread_mutex_init(&ctx->mtx_mp, NULL);
    ctx->buffer_len = 0;

    /* Init library */
    xbee_init();

    ret = xbee_setup(&xbee, ctx->xbeeMode, ctx->file, ctx->baudrate);
    if (ret != XBEE_ENONE) {
        flb_utils_error_c("xbee_setup");
        return ret;
    }

    /* 000000000000FFFF: broadcast address */
    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 (ctx->xbeeLogLevel >= 0)
        xbee_logLevelSet(xbee, ctx->xbeeLogLevel);

    /* Prepare a connection with the peer XBee */

    if ((ret = xbee_conNew(xbee, &ctx->con_data, "Data", &address)) != XBEE_ENONE) {
        xbee_log(xbee, -1, "xbee_conNew() returned: %d (%s)", ret, xbee_errorToStr(ret));
        return ret;
    }

    xbee_conSettings(ctx->con_data, NULL, &settings);
    settings.disableAck = ctx->xbeeDisableAck ? 1 : 0;
    settings.catchAll = ctx->xbeeCatchAll ? 1 : 0;
    xbee_conSettings(ctx->con_data, &settings, NULL);

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

    if ((ret = xbee_conCallbackSet(ctx->con_data, in_xbee_cb, NULL)) != XBEE_ENONE) {
        xbee_log(xbee, -1, "xbee_conCallbackSet() returned: %d", ret);
        return ret;
    }


    if ((ret = xbee_conNew(xbee, &ctx->con_io, "I/O", &address)) != XBEE_ENONE) {
        xbee_log(xbee, -1, "xbee_conNew() returned: %d (%s)", ret, xbee_errorToStr(ret));
        return ret;
    }

    xbee_conSettings(ctx->con_io, NULL, &settings);
    settings.disableAck = ctx->xbeeDisableAck ? 1 : 0;
    settings.catchAll = ctx->xbeeCatchAll ? 1 : 0;
    xbee_conSettings(ctx->con_io, &settings, NULL);

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

    if ((ret = xbee_conCallbackSet(ctx->con_io, in_xbee_iosampling_cb, NULL)) != XBEE_ENONE) {
        xbee_log(xbee, -1, "xbee_conCallbackSet() returned: %d", ret);
        return ret;
    }

    /* Set the context */
    ret = flb_input_set_context("xbee", ctx, config);
    if (ret == -1) {
        flb_utils_error_c("Could not set configuration for xbee input plugin");
    }

    return 0;
}