Exemplo n.º 1
0
void enumerate(const ComType com, const Enumerate *data) {
	logd("Returning Enumeration for Brick: %d\n\r", com);

	// Enumerate Brick
	EnumerateCallback ec = MESSAGE_EMPTY_INITIALIZER;
	make_brick_enumerate(&ec);

	ec.enumeration_type = ENUMERATE_TYPE_AVAILABLE;

	send_blocking_with_timeout(&ec, sizeof(EnumerateCallback), com);

	// Enumerate Bricklet
	for(uint8_t i = 0; i < BRICKLET_NUM; i++) {
		if(bs[i].uid == 0 || bricklet_attached[i] == BRICKLET_INIT_CO_MCU) {
			continue;
		}

		logd("Returning Enumeration for Bricklet %c\n\r", 'a' + i);

		EnumerateCallback ec = MESSAGE_EMPTY_INITIALIZER;
		make_bricklet_enumerate(&ec, i);

		ec.enumeration_type = ENUMERATE_TYPE_AVAILABLE;

		send_blocking_with_timeout(&ec, sizeof(EnumerateCallback), com);
	}

	com_info.current = com;
}
Exemplo n.º 2
0
void create_enumerate_connected(const ComType com, const CreateEnumerateConnected *data) {
	EnumerateCallback ec = MESSAGE_EMPTY_INITIALIZER;
	make_brick_enumerate(&ec);
	ec.enumeration_type = ENUMERATE_TYPE_ADDED;

	send_blocking_with_timeout(&ec, sizeof(EnumerateCallback), com);
	logd("Returning initial Enumeration for Brick: %lu\n\r", ec.header.uid);

#ifdef BRICK_CAN_BE_MASTER
	// Mark RS485/Chibi message as send.
	// This stops the rs485/chibi enumeration timer (we already enumerated).
	if(com == COM_RS485) {
		rs485_first_message = 2;
	} else 	if(com == COM_CHIBI) {
		chibi_first_message = 2;
	}
#endif

	// Set stack enumerate timer back to 0, we already are enumerating here.
	stack_enumerate_timer = 0;

	com_info.current = com;

	// Enumerate non-comcu bricklets asynchronously
#if BRICKLET_NUM > 0
	brick_init_bricklet_new_enumerate = 0;
	if((bricklet_attached[0] != BRICKLET_INIT_CO_MCU)) {
		brick_init_bricklet_new_enumerate |= 1 << 0;
	}
#endif
#if BRICKLET_NUM > 1
	if((bricklet_attached[1] != BRICKLET_INIT_CO_MCU)) {
		brick_init_bricklet_new_enumerate |= 1 << 1;
	}
#endif
#if BRICKLET_NUM > 2
	if((bricklet_attached[2] != BRICKLET_INIT_CO_MCU)) {
		brick_init_bricklet_new_enumerate |= 1 << 2;
	}
#endif
#if BRICKLET_NUM > 3
	if((bricklet_attached[3] != BRICKLET_INIT_CO_MCU)) {
		brick_init_bricklet_new_enumerate |= 1 << 3;
	}
#endif
}
Exemplo n.º 3
0
bool brick_init_enumeration(const ComType com) {
	EnumerateCallback ec = MESSAGE_EMPTY_INITIALIZER;
	make_brick_enumerate(&ec);
	ec.enumeration_type = ENUMERATE_TYPE_ADDED;

	if(SEND(&ec, sizeof(EnumerateCallback), com, NULL) != 0) {
		logd("Returning initial Enumeration for Brick: %lu\n\r", ec.header.uid);

		for(uint8_t i = 0; i < BRICKLET_NUM; i++) {
			EnumerateCallback ec = MESSAGE_EMPTY_INITIALIZER;
			make_bricklet_enumerate(&ec, i);
			if(ec.device_identifier != 0) {
				logd("Returning initial Enumeration for Bricklet %c: %lu\n\r", 'a' + i, ec.header.uid);
				ec.enumeration_type = ENUMERATE_TYPE_ADDED;
				while(send_blocking_with_timeout(&ec, sizeof(EnumerateCallback), com) == 0);
			}
		}

		return true;
	}

	return false;
}