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]); } } } } }
void spi_stack_master_update_routing_table(void* data, const uint8_t position) { if(spi_stack_buffer_size_recv > sizeof(MessageHeader)) { EnumerateCallback *enum_cb = (EnumerateCallback*)data; if(enum_cb->header.fid == FID_ENUMERATE_CALLBACK) { RouteTo route_to = routing_route_to(enum_cb->header.uid); if(route_to.to == 0 && route_to.option == 0) { route_to.to = ROUTING_STACK; route_to.option = position; routing_add_route(enum_cb->header.uid, route_to); } } } }