|
| 1 | +/* |
| 2 | + This file is part of ArduinoIoTCloud. |
| 3 | +
|
| 4 | + Copyright 2020 ARDUINO SA (http://www.arduino.cc/) |
| 5 | +
|
| 6 | + This software is released under the GNU General Public License version 3, |
| 7 | + which covers the main part of arduino-cli. |
| 8 | + The terms of this license can be found at: |
| 9 | + https://www.gnu.org/licenses/gpl-3.0.en.html |
| 10 | +
|
| 11 | + You can be released from the requirements of the above licenses by purchasing |
| 12 | + a commercial license. Buying such a license is mandatory if you want to modify or |
| 13 | + otherwise use the software for commercial activities involving the Arduino |
| 14 | + software without disclosing the source code of your own applications. To purchase |
| 15 | + a commercial license, send an email to license@arduino.cc. |
| 16 | +*/ |
| 17 | + |
| 18 | +/****************************************************************************** |
| 19 | + * INCLUDE |
| 20 | + ******************************************************************************/ |
| 21 | + |
| 22 | +#include <AIoTC_Config.h> |
| 23 | + |
| 24 | +#if OTA_ENABLED |
| 25 | + |
| 26 | +#include "OTA.h" |
| 27 | +#include <Arduino_DebugUtils.h> |
| 28 | + |
| 29 | +/****************************************************************************** |
| 30 | + * FUNCTION DEFINITION |
| 31 | + ******************************************************************************/ |
| 32 | + |
| 33 | +#ifdef ARDUINO_ARCH_SAMD |
| 34 | +int samd_onOTARequest(char const * url); |
| 35 | +String samd_getOTAImageSHA256(); |
| 36 | +#endif |
| 37 | + |
| 38 | +#ifdef ARDUINO_NANO_RP2040_CONNECT |
| 39 | +int rp2040_connect_onOTARequest(char const * url); |
| 40 | +String rp2040_connect_getOTAImageSHA256(); |
| 41 | +#endif |
| 42 | + |
| 43 | +#ifdef BOARD_STM32H7 |
| 44 | +int portenta_h7_onOTARequest(char const * url); |
| 45 | +String portenta_h7_getOTAImageSHA256(); |
| 46 | +void portenta_h7_setNetworkAdapter(NetworkAdapter iface); |
| 47 | +#endif |
| 48 | + |
| 49 | +#ifdef ARDUINO_ARCH_ESP32 |
| 50 | +int esp32_onOTARequest(char const * url); |
| 51 | +String esp32_getOTAImageSHA256(); |
| 52 | +#endif |
| 53 | + |
| 54 | +/****************************************************************************** |
| 55 | + * PUBLIC MEMBER FUNCTIONS |
| 56 | + ******************************************************************************/ |
| 57 | + |
| 58 | + |
| 59 | +int OTA::onRequest(String url) |
| 60 | +{ |
| 61 | + DEBUG_INFO("ArduinoIoTCloudTCP::%s _ota_url = %s", __FUNCTION__, url.c_str()); |
| 62 | + |
| 63 | +#if defined (ARDUINO_ARCH_SAMD) |
| 64 | + return samd_onOTARequest(url.c_str()); |
| 65 | +#elif defined (ARDUINO_NANO_RP2040_CONNECT) |
| 66 | + return rp2040_connect_onOTARequest(url.c_str()); |
| 67 | +#elif defined (BOARD_STM32H7) |
| 68 | + return portenta_h7_onOTARequest(url.c_str()); |
| 69 | +#elif defined (ARDUINO_ARCH_ESP32) |
| 70 | + return esp32_onOTARequest(url.c_str()); |
| 71 | +#else |
| 72 | + #error "OTA not supported for this architecture" |
| 73 | +#endif |
| 74 | +} |
| 75 | + |
| 76 | +String OTA::getImageSHA256() |
| 77 | +{ |
| 78 | +#if defined (ARDUINO_ARCH_SAMD) |
| 79 | + return samd_getOTAImageSHA256(); |
| 80 | +#elif defined (ARDUINO_NANO_RP2040_CONNECT) |
| 81 | + return rp2040_connect_getOTAImageSHA256(); |
| 82 | +#elif defined (BOARD_STM32H7) |
| 83 | + return portenta_h7_getOTAImageSHA256(); |
| 84 | +#elif defined (ARDUINO_ARCH_ESP32) |
| 85 | + return esp32_getOTAImageSHA256(); |
| 86 | +#else |
| 87 | + #error "No method for SHA256 checksum calculation over application image defined for this architecture." |
| 88 | +#endif |
| 89 | +} |
| 90 | + |
| 91 | + |
| 92 | +void OTA::setNetworkAdapter(NetworkAdapter iface) |
| 93 | +{ |
| 94 | +#if defined (ARDUINO_ARCH_SAMD) |
| 95 | + /* Only WiFi available */ |
| 96 | +#elif defined (ARDUINO_NANO_RP2040_CONNECT) |
| 97 | + /* Only WiFi available */ |
| 98 | +#elif defined (BOARD_STM32H7) |
| 99 | + portenta_h7_setNetworkAdapter(iface); |
| 100 | +#elif defined (ARDUINO_ARCH_ESP32) |
| 101 | + /* Only WiFi available */ |
| 102 | +#else |
| 103 | + #error "OTA not supported for this architecture" |
| 104 | +#endif |
| 105 | +} |
| 106 | + |
| 107 | +#endif /* OTA_ENABLED */ |
| 108 | + |
0 commit comments