Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/Tools/AP_Periph/networking.cpp
Views: 1798
/*1This program is free software: you can redistribute it and/or modify2it under the terms of the GNU General Public License as published by3the Free Software Foundation, either version 3 of the License, or4(at your option) any later version.56This program is distributed in the hope that it will be useful,7but WITHOUT ANY WARRANTY; without even the implied warranty of8MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9GNU General Public License for more details.1011You should have received a copy of the GNU General Public License12along with this program. If not, see <http://www.gnu.org/licenses/>.13*/1415#include "AP_Periph.h"1617#ifdef HAL_PERIPH_ENABLE_NETWORKING1819const AP_Param::GroupInfo Networking_Periph::var_info[] {20// @Group:21// @Path: ../../libraries/AP_Networking/AP_Networking.cpp22AP_SUBGROUPINFO(networking_lib, "", 1, Networking_Periph, AP_Networking),2324/*25the NET_Pn_ parameters need to be here as otherwise we26are too deep in the parameter tree27*/2829#if AP_NETWORKING_NUM_PORTS > 030// @Group: P1_31// @Path: ../../libraries/AP_Networking/AP_Networking_port.cpp32AP_SUBGROUPINFO(networking_lib.ports[0], "P1_", 2, Networking_Periph, AP_Networking::Port),33#endif3435#if AP_NETWORKING_NUM_PORTS > 136// @Group: P2_37// @Path: ../../libraries/AP_Networking/AP_Networking_port.cpp38AP_SUBGROUPINFO(networking_lib.ports[1], "P2_", 3, Networking_Periph, AP_Networking::Port),39#endif4041#if AP_NETWORKING_NUM_PORTS > 242// @Group: P3_43// @Path: ../../libraries/AP_Networking/AP_Networking_port.cpp44AP_SUBGROUPINFO(networking_lib.ports[2], "P3_", 4, Networking_Periph, AP_Networking::Port),45#endif4647#if AP_NETWORKING_NUM_PORTS > 348// @Group: P4_49// @Path: ../../libraries/AP_Networking/AP_Networking_port.cpp50AP_SUBGROUPINFO(networking_lib.ports[3], "P4_", 5, Networking_Periph, AP_Networking::Port),51#endif5253#if AP_NETWORKING_NUM_PORTS > 454// @Group: P5_55// @Path: ../../libraries/AP_Networking/AP_Networking_port.cpp56AP_SUBGROUPINFO(networking_lib.ports[4], "P5_", 6, Networking_Periph, AP_Networking::Port),57#endif5859#if AP_NETWORKING_NUM_PORTS > 560// @Group: P6_61// @Path: ../../libraries/AP_Networking/AP_Networking_port.cpp62AP_SUBGROUPINFO(networking_lib.ports[5], "P6_", 7, Networking_Periph, AP_Networking::Port),63#endif6465#if AP_NETWORKING_NUM_PORTS > 666// @Group: P7_67// @Path: ../../libraries/AP_Networking/AP_Networking_port.cpp68AP_SUBGROUPINFO(networking_lib.ports[6], "P7_", 8, Networking_Periph, AP_Networking::Port),69#endif7071#if AP_NETWORKING_NUM_PORTS > 772// @Group: P8_73// @Path: ../../libraries/AP_Networking/AP_Networking_port.cpp74AP_SUBGROUPINFO(networking_lib.ports[7], "P8_", 9, Networking_Periph, AP_Networking::Port),75#endif7677#if AP_NETWORKING_NUM_PORTS > 878// @Group: P9_79// @Path: ../../libraries/AP_Networking/AP_Networking_port.cpp80AP_SUBGROUPINFO(networking_lib.ports[8], "P9_", 10, Networking_Periph, AP_Networking::Port),81#endif82838485#if HAL_PERIPH_NETWORK_NUM_PASSTHRU > 086// @Group: PASS1_87// @Path: networking_passthru.cpp88AP_SUBGROUPINFO(passthru[0], "PASS1_", 11, Networking_Periph, Passthru),89#endif9091#if HAL_PERIPH_NETWORK_NUM_PASSTHRU > 192// @Group: PASS2_93// @Path: networking_passthru.cpp94AP_SUBGROUPINFO(passthru[1], "PASS2_", 12, Networking_Periph, Passthru),95#endif9697#if HAL_PERIPH_NETWORK_NUM_PASSTHRU > 298// @Group: PASS3_99// @Path: networking_passthru.cpp100AP_SUBGROUPINFO(passthru[2], "PASS3_", 13, Networking_Periph, Passthru),101#endif102103#if HAL_PERIPH_NETWORK_NUM_PASSTHRU > 3104// @Group: PASS4_105// @Path: networking_passthru.cpp106AP_SUBGROUPINFO(passthru[3], "PASS4_", 14, Networking_Periph, Passthru),107#endif108109#if HAL_PERIPH_NETWORK_NUM_PASSTHRU > 4110// @Group: PASS5_111// @Path: networking_passthru.cpp112AP_SUBGROUPINFO(passthru[4], "PASS5_", 15, Networking_Periph, Passthru),113#endif114115#if HAL_PERIPH_NETWORK_NUM_PASSTHRU > 5116// @Group: PASS6_117// @Path: networking_passthru.cpp118AP_SUBGROUPINFO(passthru[5], "PASS6_", 16, Networking_Periph, Passthru),119#endif120121#if HAL_PERIPH_NETWORK_NUM_PASSTHRU > 6122// @Group: PASS7_123// @Path: networking_passthru.cpp124AP_SUBGROUPINFO(passthru[6], "PASS7_", 17, Networking_Periph, Passthru),125#endif126127#if HAL_PERIPH_NETWORK_NUM_PASSTHRU > 7128// @Group: PASS8_129// @Path: networking_passthru.cpp130AP_SUBGROUPINFO(passthru[7], "PASS8_", 18, Networking_Periph, Passthru),131#endif132133#if HAL_PERIPH_NETWORK_NUM_PASSTHRU > 8134// @Group: PASS9_135// @Path: networking_passthru.cpp136AP_SUBGROUPINFO(passthru[8], "PASS9_", 19, Networking_Periph, Passthru),137#endif138139#if AP_NETWORKING_BACKEND_PPP140// @Param: PPP_PORT141// @DisplayName: PPP serial port142// @Description: PPP serial port143// @Range: -1 10144AP_GROUPINFO("PPP_PORT", 20, Networking_Periph, ppp_port, AP_PERIPH_NET_PPP_PORT_DEFAULT),145146// @Param: PPP_BAUD147// @DisplayName: PPP serial baudrate148// @Description: PPP serial baudrate149// @CopyFieldsFrom: SERIAL1_BAUD150AP_GROUPINFO("PPP_BAUD", 21, Networking_Periph, ppp_baud, AP_PERIPH_NET_PPP_BAUD_DEFAULT),151#endif152153AP_GROUPEND154};155156157void Networking_Periph::init(void)158{159#if AP_NETWORKING_BACKEND_PPP160if (ppp_port >= 0) {161AP::serialmanager().set_protocol_and_baud(ppp_port, AP_SerialManager::SerialProtocol_PPP, ppp_baud.get());162}163#endif164165networking_lib.init();166167#if HAL_PERIPH_NETWORK_NUM_PASSTHRU > 0168for (auto &p : passthru) {169p.init();170}171#endif172}173174void Networking_Periph::update(void)175{176networking_lib.update();177178#if HAL_PERIPH_NETWORK_NUM_PASSTHRU > 0179for (auto &p : passthru) {180p.update();181}182#endif183184#if HAL_RAM_RESERVE_START >= 256185if (!got_addresses && networking_lib.get_ip_active() != 0) {186got_addresses = true;187auto *comms = (struct app_bootloader_comms *)HAL_RAM0_START;188if (comms->magic != APP_BOOTLOADER_COMMS_MAGIC) {189memset(comms, 0, sizeof(*comms));190}191comms->magic = APP_BOOTLOADER_COMMS_MAGIC;192comms->ip = networking_lib.get_ip_active();193comms->netmask = networking_lib.get_netmask_active();194comms->gateway = networking_lib.get_gateway_active();195}196#endif // HAL_RAM_RESERVE_START197}198199#endif // HAL_PERIPH_ENABLE_NETWORKING200201202203