LCOV - code coverage report
Current view: top level - AP_Networking - AP_Networking_address.cpp (source / functions) Hit Total Coverage
Test: lcov.info Lines: 18 18 100.0 %
Date: 2026-09-09 11:02:08 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /*
       2             :   class for holding IPv4 address parameters
       3             :  */
       4             : 
       5             : #include "AP_Networking_Config.h"
       6             : 
       7             : #if AP_NETWORKING_ENABLED
       8             : 
       9             : #include <arpa/inet.h>
      10             : #include "AP_Networking.h"
      11             : #include <AP_HAL/utility/Socket.h>
      12             : 
      13             : const AP_Param::GroupInfo AP_Networking_IPV4::var_info[] = {
      14             :     // @Param: 0
      15             :     // @DisplayName: IPv4 Address 1st byte
      16             :     // @Description: IPv4 address. Example: 192.xxx.xxx.xxx
      17             :     // @Range: 0 255
      18             :     // @RebootRequired: True
      19             :     AP_GROUPINFO("0", 1,  AP_Networking_IPV4, addr[0], 0),
      20             : 
      21             :     // @Param: 1
      22             :     // @DisplayName: IPv4 Address 2nd byte
      23             :     // @Description: IPv4 address. Example: xxx.168.xxx.xxx
      24             :     // @Range: 0 255
      25             :     // @RebootRequired: True
      26             :     AP_GROUPINFO("1", 2,  AP_Networking_IPV4, addr[1], 0),
      27             : 
      28             :     // @Param: 2
      29             :     // @DisplayName: IPv4 Address 3rd byte
      30             :     // @Description: IPv4 address. Example: xxx.xxx.144.xxx
      31             :     // @Range: 0 255
      32             :     // @RebootRequired: True
      33             :     AP_GROUPINFO("2", 3,  AP_Networking_IPV4, addr[2], 0),
      34             : 
      35             :     // @Param: 3
      36             :     // @DisplayName: IPv4 Address 4th byte
      37             :     // @Description: IPv4 address. Example: xxx.xxx.xxx.14
      38             :     // @Range: 0 255
      39             :     // @RebootRequired: True
      40             :     AP_GROUPINFO("3", 4,  AP_Networking_IPV4, addr[3], 0),
      41             : 
      42             :     AP_GROUPEND
      43             : };
      44             : 
      45             : 
      46             : /*
      47             :   IPV4 address parameter class
      48             :  */
      49       41960 : AP_Networking_IPV4::AP_Networking_IPV4(const char *default_addr)
      50             : {
      51        8392 :     AP_Param::setup_object_defaults(this, var_info);
      52        8392 :     set_default_uint32(SocketAPM::inet_str_to_addr(default_addr));
      53        8392 : }
      54             : 
      55         395 : uint32_t AP_Networking_IPV4::get_uint32(void) const
      56             : {
      57         395 :     uint32_t v = 0;
      58         395 :     uint8_t *b = (uint8_t*)&v;
      59        1975 :     for (uint8_t i=0; i<4; i++) {
      60        1580 :         b[3-i] = uint8_t(addr[i].get());
      61             :     }
      62         395 :     return v;
      63             : }
      64             : 
      65        8392 : void AP_Networking_IPV4::set_default_uint32(uint32_t v)
      66             : {
      67        8392 :     uint8_t *b = (uint8_t*)&v;
      68       41960 :     for (uint8_t i=0; i<ARRAY_SIZE(addr); i++) {
      69       33568 :         addr[3-i].set_default(b[i]);
      70             :     }
      71        8392 : }
      72             : 
      73         395 : const char* AP_Networking_IPV4::get_str()
      74             : {
      75         395 :     const auto ip = get_uint32();
      76         395 :     return SocketAPM::inet_addr_to_str(ip, strbuf, sizeof(strbuf));
      77             : }
      78             : 
      79             : #endif // AP_NETWORKING_ENABLED

Generated by: LCOV version 1.14