libosdp 3.2.0__tar.gz → 3.2.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. {libosdp-3.2.0 → libosdp-3.2.3}/PKG-INFO +2 -2
  2. {libosdp-3.2.0 → libosdp-3.2.3}/libosdp.egg-info/PKG-INFO +2 -2
  3. {libosdp-3.2.0 → libosdp-3.2.3}/setup.py +9 -2
  4. {libosdp-3.2.0 → libosdp-3.2.3}/vendor/include/osdp_export.h +10 -0
  5. {libosdp-3.2.0 → libosdp-3.2.3}/vendor/python/osdp_sys/utils.c +27 -7
  6. {libosdp-3.2.0 → libosdp-3.2.3}/vendor/src/osdp_config.h +3 -3
  7. {libosdp-3.2.0 → libosdp-3.2.3}/vendor/utils/include/utils/assert.h +18 -1
  8. {libosdp-3.2.0 → libosdp-3.2.3}/vendor/utils/include/utils/utils.h +60 -5
  9. {libosdp-3.2.0 → libosdp-3.2.3}/vendor/utils/src/logger.c +3 -3
  10. {libosdp-3.2.0 → libosdp-3.2.3}/vendor/utils/src/utils.c +111 -14
  11. {libosdp-3.2.0 → libosdp-3.2.3}/MANIFEST.in +0 -0
  12. {libosdp-3.2.0 → libosdp-3.2.3}/README.md +0 -0
  13. {libosdp-3.2.0 → libosdp-3.2.3}/libosdp.egg-info/SOURCES.txt +0 -0
  14. {libosdp-3.2.0 → libosdp-3.2.3}/libosdp.egg-info/dependency_links.txt +0 -0
  15. {libosdp-3.2.0 → libosdp-3.2.3}/libosdp.egg-info/top_level.txt +0 -0
  16. {libosdp-3.2.0 → libosdp-3.2.3}/osdp/__init__.py +0 -0
  17. {libosdp-3.2.0 → libosdp-3.2.3}/osdp/channel.py +0 -0
  18. {libosdp-3.2.0 → libosdp-3.2.3}/osdp/constants.py +0 -0
  19. {libosdp-3.2.0 → libosdp-3.2.3}/osdp/control_panel.py +0 -0
  20. {libosdp-3.2.0 → libosdp-3.2.3}/osdp/helpers.py +0 -0
  21. {libosdp-3.2.0 → libosdp-3.2.3}/osdp/key_store.py +0 -0
  22. {libosdp-3.2.0 → libosdp-3.2.3}/osdp/peripheral_device.py +0 -0
  23. {libosdp-3.2.0 → libosdp-3.2.3}/pyproject.toml +0 -0
  24. {libosdp-3.2.0 → libosdp-3.2.3}/setup.cfg +0 -0
  25. {libosdp-3.2.0 → libosdp-3.2.3}/vendor/include/osdp.h +0 -0
  26. {libosdp-3.2.0 → libosdp-3.2.3}/vendor/python/osdp_sys/base.c +0 -0
  27. {libosdp-3.2.0 → libosdp-3.2.3}/vendor/python/osdp_sys/cp.c +0 -0
  28. {libosdp-3.2.0 → libosdp-3.2.3}/vendor/python/osdp_sys/data.c +0 -0
  29. {libosdp-3.2.0 → libosdp-3.2.3}/vendor/python/osdp_sys/module.c +0 -0
  30. {libosdp-3.2.0 → libosdp-3.2.3}/vendor/python/osdp_sys/module.h +0 -0
  31. {libosdp-3.2.0 → libosdp-3.2.3}/vendor/python/osdp_sys/pd.c +0 -0
  32. {libosdp-3.2.0 → libosdp-3.2.3}/vendor/src/crypto/tinyaes.c +0 -0
  33. {libosdp-3.2.0 → libosdp-3.2.3}/vendor/src/crypto/tinyaes_src.c +0 -0
  34. {libosdp-3.2.0 → libosdp-3.2.3}/vendor/src/crypto/tinyaes_src.h +0 -0
  35. {libosdp-3.2.0 → libosdp-3.2.3}/vendor/src/osdp_common.c +0 -0
  36. {libosdp-3.2.0 → libosdp-3.2.3}/vendor/src/osdp_common.h +0 -0
  37. {libosdp-3.2.0 → libosdp-3.2.3}/vendor/src/osdp_cp.c +0 -0
  38. {libosdp-3.2.0 → libosdp-3.2.3}/vendor/src/osdp_diag.c +0 -0
  39. {libosdp-3.2.0 → libosdp-3.2.3}/vendor/src/osdp_diag.h +0 -0
  40. {libosdp-3.2.0 → libosdp-3.2.3}/vendor/src/osdp_file.c +0 -0
  41. {libosdp-3.2.0 → libosdp-3.2.3}/vendor/src/osdp_file.h +0 -0
  42. {libosdp-3.2.0 → libosdp-3.2.3}/vendor/src/osdp_pd.c +0 -0
  43. {libosdp-3.2.0 → libosdp-3.2.3}/vendor/src/osdp_phy.c +0 -0
  44. {libosdp-3.2.0 → libosdp-3.2.3}/vendor/src/osdp_sc.c +0 -0
  45. {libosdp-3.2.0 → libosdp-3.2.3}/vendor/utils/include/utils/crc16.h +0 -0
  46. {libosdp-3.2.0 → libosdp-3.2.3}/vendor/utils/include/utils/disjoint_set.h +0 -0
  47. {libosdp-3.2.0 → libosdp-3.2.3}/vendor/utils/include/utils/list.h +0 -0
  48. {libosdp-3.2.0 → libosdp-3.2.3}/vendor/utils/include/utils/logger.h +0 -0
  49. {libosdp-3.2.0 → libosdp-3.2.3}/vendor/utils/include/utils/pcap_gen.h +0 -0
  50. {libosdp-3.2.0 → libosdp-3.2.3}/vendor/utils/include/utils/queue.h +0 -0
  51. {libosdp-3.2.0 → libosdp-3.2.3}/vendor/utils/include/utils/slab.h +0 -0
  52. {libosdp-3.2.0 → libosdp-3.2.3}/vendor/utils/src/crc16.c +0 -0
  53. {libosdp-3.2.0 → libosdp-3.2.3}/vendor/utils/src/disjoint_set.c +0 -0
  54. {libosdp-3.2.0 → libosdp-3.2.3}/vendor/utils/src/list.c +0 -0
  55. {libosdp-3.2.0 → libosdp-3.2.3}/vendor/utils/src/pcap_gen.c +0 -0
  56. {libosdp-3.2.0 → libosdp-3.2.3}/vendor/utils/src/queue.c +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: libosdp
3
- Version: 3.2.0
3
+ Version: 3.2.3
4
4
  Summary: Library implementation of IEC 60839-11-5 OSDP (Open Supervised Device Protocol)
5
5
  Home-page: https://github.com/goToMain/libosdp
6
6
  Author: Siddharth Chandrasekaran
@@ -8,7 +8,7 @@ Author-email: sidcha.dev@gmail.com
8
8
  Classifier: Programming Language :: Python :: 3
9
9
  Classifier: License :: OSI Approved :: Apache Software License
10
10
  Classifier: Operating System :: OS Independent
11
- Requires-Python: >=3.8
11
+ Requires-Python: >=3.10
12
12
  Description-Content-Type: text/markdown
13
13
  Dynamic: author
14
14
  Dynamic: author-email
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: libosdp
3
- Version: 3.2.0
3
+ Version: 3.2.3
4
4
  Summary: Library implementation of IEC 60839-11-5 OSDP (Open Supervised Device Protocol)
5
5
  Home-page: https://github.com/goToMain/libosdp
6
6
  Author: Siddharth Chandrasekaran
@@ -8,7 +8,7 @@ Author-email: sidcha.dev@gmail.com
8
8
  Classifier: Programming Language :: Python :: 3
9
9
  Classifier: License :: OSI Approved :: Apache Software License
10
10
  Classifier: Operating System :: OS Independent
11
- Requires-Python: >=3.8
11
+ Requires-Python: >=3.10
12
12
  Description-Content-Type: text/markdown
13
13
  Dynamic: author
14
14
  Dynamic: author-email
@@ -6,12 +6,13 @@
6
6
 
7
7
  import os
8
8
  import re
9
+ import sys
9
10
  from setuptools import setup, Extension
10
11
  import shutil
11
12
  import subprocess
12
13
 
13
14
  project_name = "libosdp"
14
- project_version = "3.2.0"
15
+ project_version = "3.2.3"
15
16
  current_dir = os.path.dirname(os.path.realpath(__file__))
16
17
  repo_root = os.path.realpath(os.path.join(current_dir, ".."))
17
18
 
@@ -210,6 +211,12 @@ compile_args = (
210
211
  [ "-D" + define + "=1" for define in definitions ]
211
212
  )
212
213
 
214
+ # PyPI Windows wheels are built with MSVC via cibuildwheel. Its legacy
215
+ # preprocessor breaks the IS_ENABLED() macro in utils/include/utils/utils.h;
216
+ # /Zc:preprocessor switches to the C99/C11-conformant preprocessor.
217
+ if sys.platform == "win32":
218
+ compile_args.append("/Zc:preprocessor")
219
+
213
220
  if os.path.exists("README.md"):
214
221
  with open("README.md", "r") as f:
215
222
  long_description = f.read()
@@ -241,6 +248,6 @@ setup(
241
248
  ],
242
249
  long_description = long_description,
243
250
  long_description_content_type = "text/markdown",
244
- python_requires = ">=3.8",
251
+ python_requires = ">=3.10",
245
252
  package_data = { project_name : other_files }
246
253
  )
@@ -48,6 +48,16 @@
48
48
 
49
49
  /* ---------- Deprecation (with message) ---------- */
50
50
 
51
+ /*
52
+ * Undefine API_DEPRECATED before redefining it. On macOS the SDK header
53
+ * <os/availability.h> defines API_DEPRECATED with a different signature
54
+ * (platform/version specifiers, not a plain string), which causes macro
55
+ * expansion errors when osdp.h uses OSDP_DEPRECATED_EXPORT("msg").
56
+ */
57
+ #ifdef API_DEPRECATED
58
+ #undef API_DEPRECATED
59
+ #endif
60
+
51
61
  /* Prefer C++ [[deprecated("msg")]] if available, otherwise compiler specifics. */
52
62
  #if defined(__cplusplus) && API_HAS_CPP_ATTR(deprecated)
53
63
  /* [[deprecated("msg")]] supported */
@@ -7,25 +7,35 @@
7
7
  #include <stdarg.h>
8
8
  #include "module.h"
9
9
 
10
- #if PY_VERSION_HEX < 0x030c0000
10
+ #if PY_VERSION_HEX < 0x030C0000
11
+ /*
12
+ * PyErr_GetRaisedException() / PyErr_SetRaisedException() were added in
13
+ * Python 3.12. Back-fill them with the legacy fetch/restore API (matching
14
+ * reference-stealing semantics) so this file compiles on 3.8 - 3.11.
15
+ */
11
16
  static PyObject *PyErr_GetRaisedException(void)
12
17
  {
13
18
  PyObject *type, *value, *tb;
14
- PyErr_Fetch(&type, &value, &tb);
19
+
20
+ PyErr_Fetch(&type, &value, &tb); /* clears the error indicator */
21
+ if (type == NULL)
22
+ return NULL; /* no active exception */
15
23
  PyErr_NormalizeException(&type, &value, &tb);
16
24
  if (tb != NULL) {
17
25
  PyException_SetTraceback(value, tb);
18
26
  Py_DECREF(tb);
19
27
  }
20
- Py_XDECREF(type);
21
- return value;
28
+ Py_DECREF(type);
29
+ return value; /* strong ref (normalized instance) */
22
30
  }
23
31
 
24
32
  static void PyErr_SetRaisedException(PyObject *exc)
25
33
  {
26
34
  PyObject *type = (PyObject *)Py_TYPE(exc);
35
+ PyObject *tb = PyException_GetTraceback(exc); /* new ref or NULL */
36
+
27
37
  Py_INCREF(type);
28
- PyErr_Restore(type, exc, NULL);
38
+ PyErr_Restore(type, exc, tb); /* steals type, exc, tb */
29
39
  }
30
40
  #endif
31
41
 
@@ -391,8 +401,18 @@ void pyosdp_get_channel(PyObject *channel, struct osdp_channel *ops)
391
401
  PyObject *id_obj;
392
402
 
393
403
  id_obj = PyObject_GetAttrString(channel, "id");
394
- if (id_obj && PyLong_Check(id_obj)) {
395
- id = (int)PyLong_AsLong(id_obj);
404
+ if (id_obj) {
405
+ if (PyLong_Check(id_obj)) {
406
+ id = (int)PyLong_AsLong(id_obj);
407
+ }
408
+ Py_DECREF(id_obj);
409
+ } else {
410
+ /* "id" is optional on the channel object; GetAttrString raises
411
+ * AttributeError when it's absent. Clear it so the exception
412
+ * doesn't linger and get flagged as "ignored" by the next
413
+ * unrelated C-API call (seen under CPython 3.13+).
414
+ */
415
+ PyErr_Clear();
396
416
  }
397
417
 
398
418
  ops->id = id;
@@ -11,10 +11,10 @@
11
11
  * @brief The following macros are defined defined from the variable in cmake
12
12
  * files. All @XXX@ are replaced by the value of XXX as resolved by cmake.
13
13
  */
14
- #define PROJECT_VERSION "3.2.0"
14
+ #define PROJECT_VERSION "3.2.3"
15
15
  #define PROJECT_NAME "libosdp"
16
- #define GIT_BRANCH "master"
17
- #define GIT_REV "b07d9ff"
16
+ #define GIT_BRANCH "release_v3.2"
17
+ #define GIT_REV "a4079c9"
18
18
  #define GIT_TAG ""
19
19
  #define GIT_DIFF ""
20
20
  #define REPO_ROOT "/home/runner/work/libosdp/libosdp"
@@ -18,7 +18,24 @@ extern "C" {
18
18
 
19
19
  #include <zephyr/sys/__assert.h>
20
20
 
21
- #else /* __ZEPHYR__ */
21
+ #elif defined(__BARE_METAL__)
22
+
23
+ /*
24
+ * Bare-metal: avoid exit()/atexit cleanup (pulls in newlib stdio teardown).
25
+ * printf is expected to be provided by the platform; on failure, halt.
26
+ */
27
+ #define __ASSERT_PRINT(fmt, ...) printf(fmt, ##__VA_ARGS__)
28
+ #define __ASSERT(test, fmt, ...) \
29
+ do { \
30
+ if (!(test)) { \
31
+ __ASSERT_PRINT("ASSERTION FAIL [%s] @ %s:%d\n\t" fmt "\n", \
32
+ STR(test), __FILE__, __LINE__, \
33
+ ##__VA_ARGS__); \
34
+ for (;;) { } \
35
+ } \
36
+ } while (0)
37
+
38
+ #else /* everything else expects libc */
22
39
 
23
40
  #define __ASSERT_PRINT(fmt, ...) printf(fmt, ##__VA_ARGS__)
24
41
 
@@ -51,7 +51,9 @@ extern "C" {
51
51
  #define STRINGIFY(x) #x
52
52
  #endif
53
53
 
54
+ #ifndef ROUND_UP
54
55
  #define ROUND_UP(x, y) ((x + y - 1) & ~ (y - 1))
56
+ #endif
55
57
 
56
58
  #define MATH_MOD(a, b) (((a % b) + b) % b)
57
59
 
@@ -65,20 +67,26 @@ extern "C" {
65
67
 
66
68
  #define OFFSET_OF(type, field) (size_t)(&((type *)(0))->field)
67
69
 
70
+ #ifndef CONTAINER_OF
68
71
  #define CONTAINER_OF(ptr, type, field) \
69
72
  ((type *)(((char *)(ptr)) - OFFSET_OF(type, field)))
73
+ #endif
70
74
 
75
+ #ifndef MAX
71
76
  #define MAX(a,b) ({ \
72
77
  __typeof__ (a) _a = (a); \
73
78
  __typeof__ (b) _b = (b); \
74
79
  _a > _b ? _a : _b; \
75
80
  })
81
+ #endif
76
82
 
83
+ #ifndef MIN
77
84
  #define MIN(a,b) ({ \
78
85
  __typeof__ (a) _a = (a); \
79
86
  __typeof__ (b) _b = (b); \
80
87
  _a > _b ? _b : _a; \
81
88
  })
89
+ #endif
82
90
 
83
91
  #define SWAP(a,b) { \
84
92
  __typeof__ (a) _tmp; \
@@ -102,12 +110,14 @@ extern "C" {
102
110
  #define ABS(x) ((x) >= 0 ? (x) : -(x))
103
111
 
104
112
  /* config_enabled() from the kernel */
113
+ #ifndef IS_ENABLED
105
114
  #define __IS_ENABLED1(x) __IS_ENABLED2(__XXXX ## x)
106
115
  #define __XXXX1 __YYYY,
107
116
  #define __IS_ENABLED2(y) __IS_ENABLED3(y 1, 0)
108
117
  #define __IS_ENABLED3(_i, val, ...) val
109
118
 
110
119
  #define IS_ENABLED(x) __IS_ENABLED1(x)
120
+ #endif
111
121
 
112
122
  /* gcc attribute shorthands */
113
123
  #ifndef __fallthrough
@@ -142,7 +152,11 @@ extern "C" {
142
152
  #define __format_printf(x, y)
143
153
  #define __noreturn __declspec(noreturn)
144
154
  #define __weak
155
+ #if defined(_MSC_VER)
145
156
  #define __unreachable() __assume(0)
157
+ #else
158
+ #define __unreachable() __builtin_unreachable()
159
+ #endif
146
160
  #define likely(p) (p)
147
161
  #define unlikely(p) (p)
148
162
  #define PATH_SEPARATOR '\\'
@@ -151,9 +165,21 @@ extern "C" {
151
165
 
152
166
  #include <zephyr/toolchain.h> // __weak, __builtin_xxx() etc.,
153
167
 
168
+ /*
169
+ * The #undef __weak above unconditionally drops any prior definition. When
170
+ * <zephyr/toolchain.h> was already pulled in (e.g. via <zephyr/kernel.h>),
171
+ * its include guard makes the re-include a no-op and __weak stays undefined.
172
+ * Restore it so header-level __weak declarations below still parse.
173
+ */
174
+ #ifndef __weak
175
+ #define __weak __attribute__((weak))
176
+ #endif
154
177
  #define PATH_SEPARATOR '/'
155
178
  #define __unreachable() __builtin_unreachable()
156
179
  #define __format_printf(x, y) __attribute__((format(printf, x, y)))
180
+ #ifndef __noreturn
181
+ #define __noreturn __attribute__((noreturn))
182
+ #endif
157
183
 
158
184
  #else
159
185
 
@@ -166,10 +192,39 @@ extern "C" {
166
192
  #define PATH_SEPARATOR '/'
167
193
  #endif
168
194
 
195
+ #if defined(__BARE_METAL__) && defined(USE_32BIT_TICK_T)
196
+ /*
197
+ * Bare-metal timing note:
198
+ *
199
+ * When __BARE_METAL__ and USE_32BIT_TICK_T are both enabled, tick_t uses
200
+ * 32-bit storage. The selected tick source and tick width together define the
201
+ * maximum delay interval that can be measured safely in the project.
202
+ *
203
+ * Example: with a 1 kHz tick source, uint32_t spans about 49.7 days.
204
+ * Make sure your largest required delay/timeout remains safe for your chosen
205
+ * tick source and counter width.
206
+ */
207
+ typedef uint32_t tick_t;
208
+ #else
209
+ typedef uint64_t tick_t;
210
+ #endif
211
+
212
+ /**
213
+ * @brief Return a non-cryptographic random uint32.
214
+ *
215
+ * Bare-metal builds use an internal xorshift; hosted builds forward to
216
+ * libc rand(). Cryptographic callers must NOT use this.
217
+ *
218
+ * Defined as __weak: platforms that can do better (e.g. an STM32 RNG
219
+ * peripheral, an mbedTLS DRBG, /dev/urandom) should provide their own
220
+ * strong override.
221
+ */
222
+ __weak uint32_t rand_u32(void);
223
+
169
224
  /**
170
225
  * @brief Return random number between 0 and `limit` both inclusive.
171
226
  *
172
- * Note: the random number generator must be pre-seeded.
227
+ * Backed by rand_u32(). Non-cryptographic.
173
228
  */
174
229
  int randint(int limit);
175
230
 
@@ -199,18 +254,18 @@ void hexdump(const void *data, size_t len, const char *fmt, ...);
199
254
  /**
200
255
  * @brief Get the time in micro seconds.
201
256
  */
202
- int64_t usec_now();
257
+ tick_t usec_now();
203
258
 
204
259
  /**
205
260
  * @brief Get time elapsed in micro seconds since `last`. Used along with
206
261
  * usec_now().
207
262
  */
208
- int64_t usec_since(int64_t last);
263
+ tick_t usec_since(tick_t last);
209
264
 
210
265
  /**
211
266
  * @brief Get the time in milli seconds.
212
267
  */
213
- int64_t millis_now();
268
+ tick_t millis_now();
214
269
 
215
270
  /**
216
271
  * @brief Get time in seconds and micro_seconds
@@ -228,7 +283,7 @@ int add_iso8601_utc_datetime(char *buf, size_t size);
228
283
  * @brief Get time elapsed in milli seconds since `last`. Used along with
229
284
  * millis_now().
230
285
  */
231
- int64_t millis_since(int64_t last);
286
+ tick_t millis_since(tick_t last);
232
287
 
233
288
  /**
234
289
  * @brief Print the stack trace
@@ -59,7 +59,7 @@ static const char *log_level_names[LOG_MAX_LEVEL] = {
59
59
 
60
60
  static inline void logger_log_set_color(logger_t *ctx, const char *color)
61
61
  {
62
- #if !defined(__BARE_METAL__)
62
+ #if !defined(__BARE_METAL__) && !defined(__ZEPHYR__) && !defined(MYNEWT)
63
63
  size_t ret, len;
64
64
 
65
65
  if (ctx->flags & LOGGER_FLAG_NO_COLORS)
@@ -95,7 +95,7 @@ static int terminate_log_line(char *buf, int len)
95
95
 
96
96
  #define LOG_BUF_LEN 192
97
97
 
98
- __format_printf(5, 6)
98
+ __weak __format_printf(5, 6)
99
99
  int __logger_log(logger_t *ctx, int log_level, const char *file, unsigned long line,
100
100
  const char *fmt, ...)
101
101
  {
@@ -111,7 +111,7 @@ int __logger_log(logger_t *ctx, int log_level, const char *file, unsigned long l
111
111
  {
112
112
  file = filename + 1;
113
113
  }
114
-
114
+
115
115
  if (!ctx->cb) {
116
116
  if (log_level < LOG_EMERG ||
117
117
  log_level >= LOG_MAX_LEVEL ||
@@ -12,15 +12,50 @@
12
12
 
13
13
  #include <utils/utils.h>
14
14
 
15
+ /*
16
+ * _Static_assert is C11. Pre-C11 compilers reject it at file scope (notably
17
+ * MSVC's default C mode, which Python's setuptools uses to build the wheel).
18
+ * Gate the self-test on C11; the IS_ENABLED() macro itself needs only a
19
+ * standard preprocessor, so skipping the assert loses nothing on those builds.
20
+ */
21
+ #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
22
+ #define _IS_ENABLED_SELFTEST_ON 1
23
+ _Static_assert(IS_ENABLED(_IS_ENABLED_SELFTEST_ON) == 1,
24
+ "IS_ENABLED(): defined-as-1 flag must evaluate to 1");
25
+ _Static_assert(IS_ENABLED(_IS_ENABLED_SELFTEST_OFF) == 0,
26
+ "IS_ENABLED(): undefined flag must evaluate to 0");
27
+ #undef _IS_ENABLED_SELFTEST_ON
28
+ #endif
29
+
30
+ __weak uint32_t rand_u32(void)
31
+ {
32
+ #ifdef __BARE_METAL__
33
+ /*
34
+ * libc's rand() references _impure_ptr, which pulls newlib's
35
+ * default FILE table (__sf) and the stdio teardown chain
36
+ * (_close_r/_lseek_r/_read_r/_write_r) into the link even when
37
+ * nothing else uses stdio. Replace it with a self-contained
38
+ * xorshift — same non-cryptographic quality as rand(), zero libc
39
+ * dependency.
40
+ */
41
+ static uint32_t s_state = 0x9E3779B9u;
42
+ uint32_t x = s_state;
43
+
44
+ x ^= x << 13;
45
+ x ^= x >> 17;
46
+ x ^= x << 5;
47
+ s_state = x ? x : 1u;
48
+ return x;
49
+ #else
50
+ return (uint32_t)rand();
51
+ #endif
52
+ }
53
+
15
54
  int randint(int limit)
16
55
  {
17
- int r;
18
- int divisor = RAND_MAX / (limit + 1);
56
+ uint32_t span = (uint32_t)limit + 1u;
19
57
 
20
- do {
21
- r = rand() / divisor;
22
- } while (r > limit);
23
- return r;
58
+ return (int)(rand_u32() % span);
24
59
  }
25
60
 
26
61
  uint32_t round_up_pow2(uint32_t v)
@@ -47,6 +82,18 @@ int num_digits_in_number(int num)
47
82
  return digits;
48
83
  }
49
84
 
85
+ #ifdef __BARE_METAL__
86
+
87
+ __format_printf(3, 4)
88
+ void hexdump(const void *p, size_t len, const char *fmt, ...)
89
+ {
90
+ ARG_UNUSED(p);
91
+ ARG_UNUSED(len);
92
+ ARG_UNUSED(fmt);
93
+ }
94
+
95
+ #else
96
+
50
97
  __format_printf(3, 4)
51
98
  void hexdump(const void *p, size_t len, const char *fmt, ...)
52
99
  {
@@ -85,6 +132,8 @@ void hexdump(const void *p, size_t len, const char *fmt, ...)
85
132
  printf("\n");
86
133
  }
87
134
 
135
+ #endif /* __BARE_METAL__ */
136
+
88
137
  #if (defined(_WIN32) || defined(_WIN64))
89
138
  #define WIN32_LEAN_AND_MEAN
90
139
  #include <Windows.h>
@@ -131,7 +180,7 @@ int add_iso8601_utc_datetime(char* buf, size_t size)
131
180
  return r;
132
181
  }
133
182
 
134
- #elif defined(__linux__) || defined(__APPLE__)
183
+ #elif defined(__linux__) || defined(__APPLE__) || defined(ESP_PLATFORM)
135
184
 
136
185
  #include <sys/time.h>
137
186
  #include <time.h>
@@ -182,6 +231,13 @@ int add_iso8601_utc_datetime(char* buf, size_t size) {
182
231
 
183
232
  #include <sys/time.h>
184
233
 
234
+ int add_iso8601_utc_datetime(char *buf, size_t size)
235
+ {
236
+ ARG_UNUSED(buf);
237
+ ARG_UNUSED(size);
238
+ return 0;
239
+ }
240
+
185
241
  #elif defined(__BARE_METAL__)
186
242
 
187
243
  #ifndef _TIMEVAL_DEFINED
@@ -211,22 +267,61 @@ int add_iso8601_utc_datetime(char* buf, size_t size) {
211
267
  ARG_UNUSED(size);
212
268
  return 0;
213
269
  }
270
+ #elif defined(MYNEWT)
271
+
272
+ #include <os/os_time.h>
273
+
274
+ #ifndef _TIMEVAL_DEFINED
275
+ struct timeval {
276
+ long tv_sec; // seconds since epoch
277
+ long tv_usec; // microseconds
278
+ };
279
+ #endif
280
+
281
+ #ifndef _TIMEZONE_DEFINED
282
+ struct timezone {
283
+ int tz_minuteswest; // minutes west of UTC
284
+ int tz_dsttime; // daylight saving time flag
285
+ };
286
+ #endif
287
+
288
+ int gettimeofday(struct timeval * tp, struct timezone * tzp)
289
+ {
290
+ struct os_timeval tv;
291
+ struct os_timezone tz;
292
+
293
+ os_gettimeofday(&tv, &tz);
294
+
295
+ tp->tv_sec = (long)tv.tv_sec;
296
+ tp->tv_usec = (long)tv.tv_usec;
297
+
298
+ tzp->tz_minuteswest = (int)tz.tz_minuteswest;
299
+ tzp->tz_dsttime = (int)tz.tz_dsttime;
300
+
301
+ return 0;
302
+ }
214
303
 
304
+ int add_iso8601_utc_datetime(char *buf, size_t size)
305
+ {
306
+ ARG_UNUSED(buf);
307
+ ARG_UNUSED(size);
308
+ return 0;
309
+ }
215
310
  #else
216
311
 
217
312
  #error Platform test failed
218
313
 
219
314
  #endif
220
315
 
221
- int64_t usec_now()
316
+ tick_t usec_now()
222
317
  {
223
- int64_t usec;
318
+ uint64_t usec;
224
319
  struct timeval tv;
225
320
 
226
321
  gettimeofday(&tv, NULL);
227
322
  usec = tv.tv_sec * 1000LL * 1000LL + tv.tv_usec;
228
323
 
229
- return usec;
324
+ return (tick_t)usec;
230
325
  }
231
326
 
232
327
  void get_time(uint32_t *seconds, uint32_t *micro_seconds)
@@ -238,17 +333,17 @@ void get_time(uint32_t *seconds, uint32_t *micro_seconds)
238
333
  *micro_seconds = tv.tv_usec;
239
334
  }
240
335
 
241
- int64_t usec_since(int64_t last)
336
+ tick_t usec_since(tick_t last)
242
337
  {
243
338
  return usec_now() - last;
244
339
  }
245
340
 
246
- int64_t millis_now()
341
+ tick_t millis_now()
247
342
  {
248
- return (int64_t)(usec_now() / 1000LL);
343
+ return (tick_t)(usec_now() / 1000U);
249
344
  }
250
345
 
251
- int64_t millis_since(int64_t last)
346
+ tick_t millis_since(tick_t last)
252
347
  {
253
348
  return millis_now() - last;
254
349
  }
@@ -269,6 +364,8 @@ void dump_trace(void)
269
364
  puts("");
270
365
  free(strings);
271
366
  }
367
+ #elif defined(__BARE_METAL__)
368
+ void dump_trace(void) { }
272
369
  #else
273
370
  void dump_trace(void)
274
371
  {
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes