Beispiel #1
0
size_t bluetooth_read(size_t len) {
	if (data_pack) {
		pnet_pack_destroy(data_pack);
	}
	data_pack = pnet_pack_create(NULL, len, PNET_PACK_TYPE_SINGLE);

	assert(data_pack);

	data_pack->node = &this_data;

	REG_STORE(&(us_dev_regs->US_RPR), (uint32_t) pnet_pack_get_data(data_pack));
	REG_STORE(&(us_dev_regs->US_RCR), len);

	return 0;
}
Beispiel #2
0
/* timer handler
 * we scan PIN_BT4 for changing and if it changed bt state switch to disconnect
 *  mode.
 */
static void  nxt_bt_timer_handler(struct sys_timer *timer, void *param) {
	static int bt_last_state; //TODO init state? //inited with 0, ok
	int bt_state = REG_LOAD(AT91C_ADC_CDR6) > 0x200 ? 1 : 0;

	if (bt_last_state != bt_state) {
		struct pnet_pack *pack = pnet_pack_create(NULL, 1, PNET_PACK_TYPE_SINGLE);
		assert(pack);
		pack->node = &this_ctrl;

		*((uint8_t *) pnet_pack_get_data(pack)) = bt_state;
		if (0 != pnet_entry(pack)) {
			pnet_pack_destroy(pack);
		}
		bt_last_state = bt_state;
	}

	REG_STORE(AT91C_ADC_CR, AT91C_ADC_START);
}
Beispiel #3
0
static int dc_rx_hnd(struct pnet_pack *pack) {
	struct lego_dc_msg *lego_msg;
	int addit_len = 0;
	char *msg;

	msg = pnet_pack_get_data(pack);

	switch (msg[0]) {
		case DEVICE_CONFIG_DATA:
			send_config(msg);
			break;
		case EXECUTE_COMMAND:
			lego_msg = (struct lego_dc_msg *) (msg);
			handle_command(lego_msg, &addit_len, dc_out_msg.body.tail + 1);
			break;
		case REQUEST_SENSOR_DATA:
			break;
	}

	return NET_HND_STOP_FREE;
}
Beispiel #4
0
static int ctrl_rx(struct pnet_pack *pack) {
	return ctrl_hnd(pnet_pack_get_data(pack));

}
Beispiel #5
0
static int data_rx(struct pnet_pack *pack) {
	return data_hnd(pnet_pack_get_data(pack));
}