Fork of the espurna firmware for `mhsw` switches
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
1.3 KiB

Terminal: change command-line parser (#2247) Change the underlying command line handling: - switch to a custom parser, inspired by redis / sds - update terminalRegisterCommand signature, pass only bare minimum - clean-up `help` & `commands`. update settings `set`, `get` and `del` - allow our custom test suite to run command-line tests - clean-up Stream IO to allow us to print large things into debug stream (for example, `eeprom.dump`) - send parsing errors to the debug log As a proof of concept, introduce `TERMINAL_MQTT_SUPPORT` and `TERMINAL_WEB_API_SUPPORT` - MQTT subscribes to the `<root>/cmd/set` and sends response to the `<root>/cmd`. We can't output too much, as we don't have any large-send API. - Web API listens to the `/api/cmd?apikey=...&line=...` (or PUT, params inside the body). This one is intended as a possible replacement of the `API_SUPPORT`. Internals introduce a 'task' around the AsyncWebServerRequest object that will simulate what WiFiClient does and push data into it continuously, switching between CONT and SYS. Both are experimental. We only accept a single command and not every command is updated to use Print `ctx.output` object. We are also somewhat limited by the Print / Stream overall, perhaps I am overestimating the usefulness of Arduino compatibility to such an extent :) Web API handler can also sometimes show only part of the result, whenever the command tries to yield() by itself waiting for something. Perhaps we would need to create a custom request handler for that specific use-case.
4 years ago
  1. /*
  2. Arduino Stream from a generic generic byte range
  3. Implementation of the Print is taken by reference and will be proxied
  4. Copyright (C) 2020 by Maxim Prokhorov <prokhorov dot max at outlook dot com>
  5. */
  6. #include <Arduino.h>
  7. #include <core_version.h>
  8. #include <memory>
  9. #pragma once
  10. template <typename T>
  11. struct StreamAdapter final : public Stream {
  12. StreamAdapter(Print& writer, T&& begin, T&& end) :
  13. _writer(writer),
  14. _current(std::forward<T>(begin)),
  15. _begin(std::forward<T>(begin)),
  16. _end(std::forward<T>(end))
  17. {}
  18. int available() override {
  19. return (_end - _current);
  20. }
  21. int peek() override {
  22. if (available() && (_end != (1 + _current))) {
  23. return *(1 + _current);
  24. }
  25. return -1;
  26. }
  27. int read() override {
  28. if (_end != _current) {
  29. return *(_current++);
  30. }
  31. return -1;
  32. }
  33. void flush() override {
  34. // 2.3.0 - Stream::flush()
  35. // latest - Print::flush()
  36. #if not defined(ARDUINO_ESP8266_RELEASE_2_3_0)
  37. _writer.flush();
  38. #endif
  39. }
  40. size_t write(const uint8_t* buffer, size_t size) override {
  41. return _writer.write(buffer, size);
  42. }
  43. size_t write(uint8_t ch) override {
  44. return _writer.write(ch);
  45. }
  46. private:
  47. Print& _writer;
  48. T _current;
  49. T const _begin;
  50. T const _end;
  51. };