Esempio n. 1
0
int main(int argc, char ** argv)
{
	xbee_open((char *)PORT);

	//char * buf =  "\x7E\x00\x04\x08\x01\x4D\x59\x50";

	//char * buf = "\x7E\x00\x10\x10\x01\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\x00\x00\x22\x44\x8A";
	//char * buf = "\x7E\x00\x04\x08\x01\x4A\x4E\x5E";
	//char * buf = "\x7E\x00\x04\x08\x01\x57\x52\x4D";
	//write(xbee->fd, buf, 8); 
	//
	//xbee_send_data("\x22", 1, 0, 0);
	
	//struct at_command * at = malloc(sizeof(struct xbee_atcommand));
	//at->at_cmd = "MY";
	//at->at_cmd = 0x4D59;

	xbee_send_atcommand("MY", "", 0);
	//xbee_send_atwr(xbee->fd, "JN", "\x01", 0);

	struct xbee_rawframe * frame = malloc(sizeof(struct xbee_rawframe));
	xbee_read(frame);

	xbee_print_frame((uint8_t *)frame);

	free(frame);
	
	
	/* Closing file descriptor */
	xbee_close();
	return 0;
}
Esempio n. 2
0
File: main.c Progetto: wuwx/simba
static int test_frame_as_string(struct harness_t *harness_p)
{
    struct xbee_frame_t frame;

    /* AT Command - parameter read. */
    frame.type = XBEE_FRAME_TYPE_AT_COMMAND;
    frame.data.buf[0] = 0x01;
    frame.data.buf[1] = 'D';
    frame.data.buf[2] = 'L';
    frame.data.size = 3;

    BTASSERT(xbee_print_frame(&queue, &frame) == 0);
    BTASSERTI(harness_expect(&queue,
                             "AT Command(frame_id=0x01, at_command='DL')\r\n",
                             NULL), ==, 44);

    /* AT Command - parameter write. */
    frame.type = XBEE_FRAME_TYPE_AT_COMMAND;
    frame.data.buf[0] = 0x02;
    frame.data.buf[1] = 'D';
    frame.data.buf[2] = 'L';
    frame.data.buf[3] = 0x01;
    frame.data.buf[4] = 0x02;
    frame.data.buf[5] = 0x03;
    frame.data.buf[6] = 0x04;
    frame.data.size = 7;

    BTASSERT(xbee_print_frame(&queue, &frame) == 0);
    BTASSERTI(harness_expect(
                  &queue,
                  "AT Command(frame_id=0x02, at_command='DL', "
                  "parameter=0x01020304)\r\n",
                  NULL), ==, 66);

    /* RX Packet: 64-bit Address frame. */
    frame.type = XBEE_FRAME_TYPE_RX_PACKET_64_BIT_ADDRESS;
    frame.data.buf[0] = 0x12;
    frame.data.buf[1] = 0x34;
    frame.data.buf[2] = 0x56;
    frame.data.buf[3] = 0x78;
    frame.data.buf[4] = 0x9a;
    frame.data.buf[5] = 0xbc;
    frame.data.buf[6] = 0xde;
    frame.data.buf[7] = 0xf0;
    frame.data.buf[8] = 0x28;
    frame.data.buf[9] = 0x04;
    frame.data.buf[10] = 0x01;
    frame.data.buf[11] = 0x02;
    frame.data.buf[12] = 0x03;
    frame.data.size = 13;

    BTASSERT(xbee_print_frame(&queue, &frame) == 0);
    BTASSERTI(harness_expect(
                  &queue,
                  "RX Packet: 64-bit Address(address=0x123456789abcdef0, "
                  "rssi=-40 dBm, options=[adddress_broadcast=0, "
                  "pan_broadcast=1], data=0x010203)\r\n",
                  NULL), ==, 133);

    /* RX Packet: 16-bit Address frame. */
    frame.type = XBEE_FRAME_TYPE_RX_PACKET_16_BIT_ADDRESS;
    frame.data.buf[0] = 0x12;
    frame.data.buf[1] = 0x34;
    frame.data.buf[2] = 0x28;
    frame.data.buf[3] = 0x02;
    frame.data.buf[4] = 0x01;
    frame.data.buf[5] = 0x02;
    frame.data.buf[6] = 0x03;
    frame.data.size = 7;

    BTASSERT(xbee_print_frame(&queue, &frame) == 0);
    BTASSERTI(harness_expect(
                  &queue,
                  "RX Packet: 16-bit Address(address=0x1234, rssi=-40 dBm, "
                  "options=[adddress_broadcast=1, pan_broadcast=0], "
                  "data=0x010203)\r\n",
                  NULL), ==, 121);

    /* AT Command Response - parameter read. */
    frame.type = XBEE_FRAME_TYPE_AT_COMMAND_RESPONSE;
    frame.data.buf[0] = 0x03;
    frame.data.buf[1] = 'D';
    frame.data.buf[2] = 'L';
    frame.data.buf[3] = 0x00;
    frame.data.buf[4] = 0x04;
    frame.data.buf[5] = 0x03;
    frame.data.buf[6] = 0x02;
    frame.data.buf[7] = 0x01;
    frame.data.size = 8;

    BTASSERT(xbee_print_frame(&queue, &frame) == 0);
    BTASSERTI(harness_expect(
                  &queue,
                  "AT Command Response(frame_id=0x03, at_command='DL', "
                  "status='OK', data=0x04030201)\r\n",
                  NULL), ==, 83);

    /* AT Command Response - parameter write. */
    frame.type = XBEE_FRAME_TYPE_AT_COMMAND_RESPONSE;
    frame.data.buf[0] = 0x03;
    frame.data.buf[1] = 'D';
    frame.data.buf[2] = 'L';
    frame.data.buf[3] = 0x00;
    frame.data.size = 4;

    BTASSERT(xbee_print_frame(&queue, &frame) == 0);
    BTASSERTI(harness_expect(
                  &queue,
                  "AT Command Response(frame_id=0x03, at_command='DL', "
                  "status='OK')\r\n",
                  NULL), ==, 66);

    /* TX status. */
    frame.type = XBEE_FRAME_TYPE_TX_STATUS;
    frame.data.buf[0] = 0xff;
    frame.data.buf[1] = 0x00;
    frame.data.size = 2;

    BTASSERT(xbee_print_frame(&queue, &frame) == 0);
    BTASSERTI(harness_expect(&queue,
                             "TX Status(frame_id=0xff, status='Standard')\r\n",
                             NULL), ==, 45);

    /* Modem status. */
    frame.type = XBEE_FRAME_TYPE_MODEM_STATUS;
    frame.data.buf[0] = 0x00;
    frame.data.size = 1;

    BTASSERT(xbee_print_frame(&queue, &frame) == 0);
    BTASSERTI(harness_expect(&queue,
                             "Modem Status(status='Hardware reset')\r\n",
                             NULL), ==, 39);

    /* Unknown frame type. */
    frame.type = 0xff;
    frame.data.buf[0] = 'f';
    frame.data.buf[1] = 'o';
    frame.data.buf[2] = 'o';
    frame.data.size = 3;

    BTASSERT(xbee_print_frame(&queue, &frame) == -EINVAL);
    BTASSERTI(harness_expect(&queue,
                             "frame_type=0xff(\r\n"
                             "00000000: 66 6f 6f                  "
                             "                      'foo'\r\n"
                             ")\r\n",
                             NULL), ==, 86);

    return (0);
}