forked from matth-x/MicroOcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlatform.h
More file actions
99 lines (83 loc) · 2.61 KB
/
Copy pathPlatform.h
File metadata and controls
99 lines (83 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// matth-x/ArduinoOcpp
// Copyright Matthias Akstaller 2019 - 2022
// MIT License
#ifndef AO_PLATFORM_H
#define AO_PLATFORM_H
#ifdef __cplusplus
#define EXT_C extern "C"
#else
#define EXT_C
#endif
#define AO_PLATFORM_ARDUINO 0
#define AO_PLATFORM_ESPIDF 1
#define AO_PLATFORM_UNIX 2
#ifndef AO_PLATFORM
#define AO_PLATFORM AO_PLATFORM_ARDUINO
#endif
#ifdef AO_CUSTOM_CONSOLE
#include <cstdio>
#ifndef AO_CUSTOM_CONSOLE_MAXMSGSIZE
#define AO_CUSTOM_CONSOLE_MAXMSGSIZE 196
#endif
void ao_set_console_out(void (*console_out)(const char *msg));
namespace ArduinoOcpp {
void ao_console_out(const char *msg);
}
#define AO_CONSOLE_PRINTF(X, ...) \
do { \
char msg [AO_CUSTOM_CONSOLE_MAXMSGSIZE]; \
if (snprintf(msg, AO_CUSTOM_CONSOLE_MAXMSGSIZE, X, ##__VA_ARGS__) < 0) { \
sprintf(msg + AO_CUSTOM_CONSOLE_MAXMSGSIZE - 7, " [...]"); \
} \
ArduinoOcpp::ao_console_out(msg); \
} while (0)
#else
#define ao_set_console_out(X) \
do { \
X("[AO] CONSOLE ERROR: ao_set_console_out ignored if AO_CUSTOM_CONSOLE " \
"not defined\n"); \
char msg [100]; \
snprintf(msg, 100, " > see %s:%i",__FILE__,__LINE__); \
X(msg); \
X("\n > see ArduinoOcpp/Platform.h\n"); \
} while (0)
#if AO_PLATFORM == AO_PLATFORM_ARDUINO
#include <Arduino.h>
#ifndef AO_USE_SERIAL
#define AO_USE_SERIAL Serial
#endif
#define AO_CONSOLE_PRINTF(X, ...) AO_USE_SERIAL.printf_P(PSTR(X), ##__VA_ARGS__)
#elif AO_PLATFORM == AO_PLATFORM_ESPIDF || AO_PLATFORM == AO_PLATFORM_UNIX
#include <stdio.h>
#define AO_CONSOLE_PRINTF(X, ...) printf(X, ##__VA_ARGS__)
#endif
#endif
#ifdef AO_CUSTOM_TIMER
void ao_set_timer(unsigned long (*get_ms)());
unsigned long ao_tick_ms_custom();
#define ao_tick_ms ao_tick_ms_custom
#else
#if AO_PLATFORM == AO_PLATFORM_ARDUINO
#include <Arduino.h>
#define ao_tick_ms millis
#elif AO_PLATFORM == AO_PLATFORM_ESPIDF
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#define ao_tick_ms(X) ((xTaskGetTickCount() * 1000UL) / configTICK_RATE_HZ)
#elif AO_PLATFORM == AO_PLATFORM_UNIX
unsigned long ao_tick_ms_unix();
#define ao_tick_ms ao_tick_ms_unix
#endif
#endif
#ifndef ao_avail_heap
#if AO_PLATFORM == AO_PLATFORM_ARDUINO
#include <Arduino.h>
#define ao_avail_heap ESP.getFreeHeap
#elif AO_PLATFORM == AO_PLATFORM_ESPIDF
#include "freertos/FreeRTOS.h"
#define ao_avail_heap xPortGetFreeHeapSize
#elif AO_PLATFORM == AO_PLATFORM_UNIX
#define ao_avail_heap(X) 1000000 //suppress this technique on unix
#endif
#endif
#endif