first commit

This commit is contained in:
2026-01-25 15:36:43 +01:00
commit 1a6dce142c
9 changed files with 499 additions and 0 deletions

37
include/README Normal file
View File

@@ -0,0 +1,37 @@
This directory is intended for project header files.
A header file is a file containing C declarations and macro definitions
to be shared between several project source files. You request the use of a
header file in your project source file (C, C++, etc) located in `src` folder
by including it, with the C preprocessing directive `#include'.
```src/main.c
#include "header.h"
int main (void)
{
...
}
```
Including a header file produces the same results as copying the header file
into each source file that needs it. Such copying would be time-consuming
and error-prone. With a header file, the related declarations appear
in only one place. If they need to be changed, they can be changed in one
place, and programs that include the header file will automatically use the
new version when next recompiled. The header file eliminates the labor of
finding and changing all the copies as well as the risk that a failure to
find one copy will result in inconsistencies within a program.
In C, the convention is to give header files names that end with `.h'.
Read more about using header files in official GCC documentation:
* Include Syntax
* Include Operation
* Once-Only Headers
* Computed Includes
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html

66
include/serialConnector.h Normal file
View File

@@ -0,0 +1,66 @@
#pragma once
#include <Arduino.h>
class SerialConnector
{
private:
String previouSent;
String received;
String command;
void (*acknowledgeHandler)(String args);
void (*repeatHandler)(String args);
void (*calibrationBeginHandler)(String args);
void (*calibrationInteruptHandler)(String args);
// Convert each character of `cmd` to its hexadecimal representation
// and return the concatenated hex string.
String stringToHex(String cmd);
// Compute a numeric 'check' value from `cmd` by converting chars to
// their hex digits and summing/concatenating (project-specific logic).
// Returns an integer suitable for use as a check-bit value.
int stringToCheckNum(String cmd);
// Return the index of character `ch` in `str`, or -1 if not found.
int getCharIndex(char ch, String str);
// Parse an incoming framed message and return the command portion
// (everything before the first '#').
String getCommandFromIncomming(String incomming);
// Parse an incoming framed message and return the arguments portion
// (text between the first and second '#').
String getArgsFromIncomming(String incomming);
// Parse an incoming framed message and return the final check-bit
// portion (everything after the second '#').
String getCheckBitFromIncomming(String incomming);
// Verify that the provided `checkBit` matches the computed check for
// the combination of `cmd` and `args`. Returns true when valid.
bool verifyCheckBit(String cmd, String args, int checkBit);
// Send a repeat request to the remote side to indicate the last
// message should be re-sent.
void repeat();
// Send an acknowledgement message containing `checkBit` back to the
// remote side.
void acknowledge(int checkBit);
// After sending a command, wait for and handle any follow-up messages
// (repeat or acknowledgement) related to `cmd`.
void afterSendCheck(String cmd);
public:
void cycle();
void onAcknowledge(void (*handler)(String args));
void onRepeat(void (*handler)(String args));
void onCalibrationBegin(void (*handler)(String args));
void onCalibrationInterupt(void (*handler)(String args));
void sendCommand(String cmd, String args);
};