static void send_config(char *msg) { int length; char buff[256]; struct DeviceConfigurationMessage message; buff[0] = DEVICE_CONFIG_DATA; strcpy(message._id, "LEGO_NXT"); message._id_len = 8; message._type = _LEGO_NXT; message._commands[0] = DC_EX_SET_M_OUTPUT_STATE; message._commands_len = 1; message._sensors[0] = 0x00; message._sensors_len = 1; length = DeviceConfigurationMessage_write_delimited_to(&message, buff, 1); bluetooth_write((uint8_t *)buff, length); }
int bluetooth_packet_write(char *buffer, size_t buf_size, blt_pkt_type type) { if ( ! bluetooth_run_flag ) { fprintf(stderr, "ERROR tried to write packet over bluetooth but bluetooth was interrupted\n"); return -1; } if ( buf_size > PKT_BUF_SIZE) { fprintf(stderr, "ERROR supplied buffer to bluetooth_write_packet is %zu bytes long, but only writes up to 256 bytes\n", buf_size); } /* Copy buffer to buffer of known size and store packet type */ char temp_buffer[PKT_BUF_SIZE] = { 0 }; memcpy(temp_buffer, buffer, 256); temp_buffer[PKT_TYPE_LOC] = type; return bluetooth_write(temp_buffer, PKT_TOT_SIZE); }
size_t device_write(const __ptr_t buf, size_t n, struct gn_statemachine *state) { switch (state->device.type) { case GN_CT_DKU2: case GN_CT_Serial: case GN_CT_Infrared: return serial_write(state->device.fd, buf, n, state); case GN_CT_Irda: return irda_write(state->device.fd, buf, n, state); case GN_CT_Bluetooth: return bluetooth_write(state->device.fd, buf, n, state); case GN_CT_Tekram: return tekram_write(state->device.fd, buf, n, state); case GN_CT_TCP: return tcp_write(state->device.fd, buf, n, state); case GN_CT_DKU2LIBUSB: return fbusdku2usb_write(buf, n, state); case GN_CT_SOCKETPHONET: return socketphonet_write(state->device.fd, buf, n, state); default: break; } return 0; }
static void send_msg(struct bc_msg * msg) { calc_chksumm(msg); msg->length += 2; bluetooth_write((uint8_t *) msg, msg->length + 1); }