Alex2ESP/src/AlexaCompat.h
David 3215457f91 AlexaStatusMessage: DeferredResponse, ChangeReport, ErrorResponse, scene and doorbell events, UUID-shaped messageId
A message has a kind, and the kind decides its topic: answers on
<root>/<id>/alexaResponce, the answer after a DeferredResponse on
<root>/<id>/deferredResponse (sendAsync()), a ChangeReport on
<root>/changeReport with the changed properties apart from the others
(context()), DoorbellPress on <root>/event. AlexaDirective gains deferred(),
error(type, message), sceneStarted() and sceneStopped(); thermostat error
types go out in the namespace of the thermostat. The helpers are add*Prop,
the Add*Prop names stay; a temperature keeps its scale (69 FAHRENHEIT, was
20.56 CELSIUS). messageId is a version 4 UUID from the hardware random
source, where rand() seeded per second gave two messages one id.
basicLight: static RAM 30,540 B (-76), flash 334,981 B (+1,280);
112 host tests (bridge logic 52, messages 19, new).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-28 20:35:56 +00:00

37 lines
1.1 KiB
C++

// Lets the sources that have no hardware dependency compile on a host (pio test -e native), where the
// program-memory helpers of the Arduino cores do not exist: there a PROGMEM object is an ordinary constant and a
// pointer to one an ordinary pointer. On a board this is Arduino.h and the random source of the hardware.
#ifndef ALEXA_COMPAT_H
#define ALEXA_COMPAT_H
#if defined(ARDUINO)
#include <Arduino.h>
#else
#include <stdint.h>
#include <string.h>
#include <random>
#define PROGMEM
#define PGM_P const char *
#define PSTR(text) (text)
#define F(text) (text)
#define FPSTR(text) (text)
#define pgm_read_byte(address) (*reinterpret_cast<const uint8_t *>(address))
#define pgm_read_ptr(address) (*reinterpret_cast<const void *const *>(address))
#define strcmp_P strcmp
#define strncpy_P strncpy
#endif
// 32 bits that cannot be predicted and differ after every reset
inline uint32_t alexaRandom32()
{
#if defined(ESP8266)
return RANDOM_REG32; // fed by the noise of the radio
#elif defined(ESP32)
return esp_random(); // ESP32: untested
#else
static std::random_device source;
return source();
#endif
}
#endif // ALEXA_COMPAT_H