Example #1
0
void routing_master_from_pc(const char *data, const uint16_t length, const ComType com) {
	uint32_t uid = ((MessageHeader*)data)->uid;

	// Broadcast
	if(uid == 0) {
		for(uint8_t i = 1; i <= com_info.last_stack_address; i++) {
			uint32_t options = i;
			send_blocking_with_timeout_options(data, length, COM_SPI_STACK, &options);
		}

		if(com_info.ext_type[0] == COM_TYPE_MASTER) {
			send_blocking_with_timeout(data, length, com_info.ext[0]);
		}
		if(com_info.ext_type[1] == COM_TYPE_MASTER) {
			send_blocking_with_timeout(data, length, com_info.ext[1]);
		}
	// Message for brickd
	} else if(uid == 1) {
		if(com == COM_ETHERNET || com == COM_WIFI) {
			MessageHeader *header = (MessageHeader*)data;
			switch(header->fid) {
				case BRICKD_FID_GET_AUTHENTICATION_NONCE: {
					brickd_get_authentication_nonce(com, (GetAuthenticationNonce*)data);
					break;
				}

				case BRICKD_FID_AUTHENTICATE: {
					brickd_authenticate(com, (Authenticate*)data);
					break;
				}
			}
		}
	// Discover Route
	} else {
		const RouteTo route_to = routing_route_to(uid);
		if(route_to.to == ROUTING_STACK) {
			uint32_t options = route_to.option;
			send_blocking_with_timeout_options(data, length, COM_SPI_STACK, &options);
		} else if(master_mode & MASTER_MODE_MASTER) {
			if(route_to.to == ROUTING_EXTENSION_1) {
				if(com_info.ext_type[0] == COM_TYPE_MASTER) {
					send_blocking_with_timeout(data, length, com_info.ext[0]);
				}
			} else if(route_to.to == ROUTING_EXTENSION_2) {
				if(com_info.ext_type[1] == COM_TYPE_MASTER) {
					send_blocking_with_timeout(data, length, com_info.ext[1]);
				}
			} else {
				if(com_info.ext_type[0] == COM_TYPE_MASTER) {
					send_blocking_with_timeout(data, length, com_info.ext[0]);
				}
				if(com_info.ext_type[1] == COM_TYPE_MASTER) {
					send_blocking_with_timeout(data, length, com_info.ext[1]);
				}
			}
		}
	}
}
Example #2
0
uint16_t chibi_send_broadcast(const void *data, const uint16_t length) {
	if(chibi_type != CHIBI_TYPE_MASTER) {
		return length;
	}

	for(uint8_t i = 0; i < CHIBI_NUM_SLAVE_ADDRESS; i++) {
		if(chibi_slave_address[i] == 0) {
			return length;
		}
		uint32_t options = chibi_slave_address[i];
		send_blocking_with_timeout_options(data, length, COM_CHIBI, &options);
	}

	return length;
}
Example #3
0
uint16_t send_blocking_with_timeout(const void *data,
                                    const uint16_t length,
                                    const ComType com) {
	return send_blocking_with_timeout_options(data, length, com, NULL);
}