MeterLogger
Functions
mqtt_utils.h File Reference
#include "c_types.h"
Include dependency graph for mqtt_utils.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

uint32_t ICACHE_FLASH_ATTR UTILS_Atoh (const int8_t *s)
 
uint8_t ICACHE_FLASH_ATTR UTILS_StrToIP (const int8_t *str, void *ip)
 
uint8_t ICACHE_FLASH_ATTR UTILS_IsIPV4 (int8_t *str)
 

Function Documentation

◆ UTILS_Atoh()

uint32_t ICACHE_FLASH_ATTR UTILS_Atoh ( const int8_t *  s)

Definition at line 130 of file mqtt_utils.c.

131 {
132  uint32_t value = 0, digit;
133  int8_t c;
134 
135  while((c = *s++)){
136  if('0' <= c && c <= '9')
137  digit = c - '0';
138  else if('A' <= c && c <= 'F')
139  digit = c - 'A' + 10;
140  else if('a' <= c && c<= 'f')
141  digit = c - 'a' + 10;
142  else break;
143 
144  value = (value << 4) | digit;
145  }
146 
147  return value;
148 }

◆ UTILS_IsIPV4()

uint8_t ICACHE_FLASH_ATTR UTILS_IsIPV4 ( int8_t *  str)

Definition at line 41 of file mqtt_utils.c.

42 {
43  uint8_t segs = 0; /* Segment count. */
44  uint8_t chcnt = 0; /* Character count within segment. */
45  uint8_t accum = 0; /* Accumulator for segment. */
46  /* Catch NULL pointer. */
47  if (str == 0)
48  return 0;
49  /* Process every character in string. */
50 
51  while (*str != '\0') {
52  /* Segment changeover. */
53 
54  if (*str == '.') {
55  /* Must have some digits in segment. */
56  if (chcnt == 0)
57  return 0;
58  /* Limit number of segments. */
59  if (++segs == 4)
60  return 0;
61  /* Reset segment values and restart loop. */
62  chcnt = accum = 0;
63  str++;
64  continue;
65  }
66 
67  /* Check numeric. */
68  if ((*str < '0') || (*str > '9'))
69  return 0;
70 
71  /* Accumulate and check segment. */
72 
73  if ((accum = accum * 10 + *str - '0') > 255)
74  return 0;
75  /* Advance other segment specific stuff and continue loop. */
76 
77  chcnt++;
78  str++;
79  }
80 
81  /* Check enough segments and enough characters in last segment. */
82 
83  if (segs != 3)
84  return 0;
85  if (chcnt == 0)
86  return 0;
87  /* Address okay. */
88 
89  return 1;
90 }

◆ UTILS_StrToIP()

uint8_t ICACHE_FLASH_ATTR UTILS_StrToIP ( const int8_t *  str,
void *  ip 
)

Definition at line 91 of file mqtt_utils.c.

Referenced by MQTT_Connect(), and wifi_softap_ip_config().

92 {
93 
94  /* The count of the number of bytes processed. */
95  int i;
96  /* A pointer to the next digit to process. */
97  const char * start;
98 
99  start = str;
100  for (i = 0; i < 4; i++) {
101  /* The digit being processed. */
102  char c;
103  /* The value of this byte. */
104  int n = 0;
105  while (1) {
106  c = * start;
107  start++;
108  if (c >= '0' && c <= '9') {
109  n *= 10;
110  n += c - '0';
111  }
112  /* We insist on stopping at "." if we are still parsing
113  the first, second, or third numbers. If we have reached
114  the end of the numbers, we will allow any character. */
115  else if ((i < 3 && c == '.') || i == 3) {
116  break;
117  }
118  else {
119  return 0;
120  }
121  }
122  if (n >= 256) {
123  return 0;
124  }
125  ((uint8_t*)ip)[i] = n;
126  }
127  return 1;
128 
129 }
Here is the caller graph for this function: