Example #1
0
static int get_length(void *_msg) {
	struct bc_msg *msg = _msg;
	data_hnd = get_body;
	bluetooth_read(msg->length);

	return NET_HND_STOP_FREE;
}
Example #2
0
/* First character sets type of packet */
int bluetooth_packet_read(char *buffer, size_t buf_size, blt_pkt_type *type)
{
	if ( ! bluetooth_run_flag )
	{
		fprintf(stderr, "ERROR tried to read from bluetooth_read_packet but bluetooth was interrupted\n");
		return -1;
	}
	
	if ( buf_size < 256 )
	{
		fprintf(stderr, "ERROR supplied buffer to bluetooth_read_packet is %zu bytes long, requires 256 bytes\n", buf_size);
		return -1;
	}

	char temp_buffer[PKT_TOT_SIZE] = { 0 };
//	int status = read(f_in, temp_buffer, PKT_TOT_SIZE);
	int status = bluetooth_read(temp_buffer, PKT_TOT_SIZE);
	if (status == -1)
	{
		perror("bluetooth_read_packet");
		return status;	
	}

	/* Set packet type and copy the rest of the buffer over */
	*type = (blt_pkt_type) temp_buffer[PKT_TYPE_LOC];
	memcpy(buffer, temp_buffer, PKT_BUF_SIZE - 1);

	/* Clear the rest of the buffer */
	if (buf_size > 256)
		memset(buffer+256, 0, buf_size - 256);
	
	return status;
}
Example #3
0
static int nxt_bluecore_start(struct net_node *node) {
	data_hnd = get_length;
	ctrl_hnd = wait_connect;

	bluetooth_hw_hard_reset();
	bluetooth_read(1);

	return 0;
}
Example #4
0
static int wait_disconnect(void *msg) {
	data_hnd = get_length;
	ctrl_hnd = wait_connect;

	bluetooth_hw_soft_reset();
	bluetooth_read(1);

	return NET_HND_FORWARD_DEFAULT;
}
Example #5
0
static int get_body(void *msg) {
	int answ = process_msg((struct bc_msg_body *) msg);
	if (answ == 0) {
		data_hnd = get_length;
		bluetooth_read(1);
	}

	return NET_HND_STOP_FREE;
}
Example #6
0
size_t device_read(__ptr_t buf, size_t nbytes, struct gn_statemachine *state)
{
	switch (state->device.type) {
	case GN_CT_DKU2:
	case GN_CT_Serial:
	case GN_CT_Infrared:
		return serial_read(state->device.fd, buf, nbytes, state);
	case GN_CT_Irda:
		return irda_read(state->device.fd, buf, nbytes, state);
	case GN_CT_Bluetooth:
		return bluetooth_read(state->device.fd, buf, nbytes, state);
	case GN_CT_Tekram:
		return tekram_read(state->device.fd, buf, nbytes, state);
	case GN_CT_TCP:
		return tcp_read(state->device.fd, buf, nbytes, state);
	case GN_CT_DKU2LIBUSB:
		return fbusdku2usb_read(buf, nbytes, state);
	case GN_CT_SOCKETPHONET:
		return socketphonet_read(state->device.fd, buf, nbytes, state);
	default:
		break;
	}
	return 0;
}