// binary serial send&receive
#include "BinarySerial.h"
BinarySerial BSerial;
#define Serial BSerial // for convenience, so can use "Serial.print"
int pinState = 1;
byte testFile[1024];
char testString[] = "hello my name is test file and this is a second chunk, and a million more chunks.\r\n\
2=hello my name is test file and this is a second chunk, and a million more chunks\r\n\
3=hello my name is test file and this is a second chunk, and a million more chunks\r\n\
4=hello my name is test file and this is a second chunk, and a million more chunks\r\n\
5=hello my name is test file and this is a second chunk, and a million more chunks\r\n\
6=hello my name is test file and this is a second chunk, and a million more chunks\r\n\
7=hello my name is test file and this is a second chunk, and a million more chunks\r\n\
8=hello my name is test file and this is a second chunk, and a million more chunks\r\n\
9=hello my name is test file and this is a second chunk, and a million more chunks\r\n\
10=hello my name is test file and this is a second chunk, and a million more chunks";
struct specialBytes {
byte sendFile = 0x41; //65 0x41 A
byte log = 0x4C; //76 0x4C L
} specByte;
void sendLog(char* str) {
BSerial.startMsg(specByte.log);
BSerial.addString(str);
BSerial.endMsg();
}
void setup() {
pinMode(4, INPUT_PULLUP);
//for (int i = 0; i < strlen(testString); i++) {
// testFile[i] = testString[i];
//}
for (int i = 0; i < 1024; i++) {
testFile[i] = i;
}
// register function for processing complete serial msgs
// set cmd bytes for serial stream
BSerial.begin(230400, &receiveSerialMsg, &receiveSerialLog, &receiveSerialMulti);
Serial.println("Started Binary Serial");
Serial.print("Testing line1");
Serial.println(" and line 2");
}
void loop() {
// process bytes in serial buffer
BSerial.receiveBytes();
if (pinState != digitalRead(4)) {
pinState = digitalRead(4);
if (pinState == 0) buttonPress();
}
// put your main code here, to run repeatedly:
delay(10); // this speeds up the simulation
}
bool strEqual(const char* a, const char* b) { return strcmp(a, b) == 0; }
void receiveSerialMsg(byte header, byte* msg, int len) {
// file requested
if (header == specByte.sendFile) {
//char fileName[] = "test.txt";
//BSerial.sendMulti(&testFile[0], strlen(testString), &fileName[0]);
//BSerial.sendMulti(&testFile[0], 1024, &fileName[0]);
Serial.println("does nothing, reimpl with JSON fileCmd");
}
}
void receiveSerialLog(byte* msg, int len) {
// sorta useless, no real use for log messages PC -> device.
// maybe generating device log files?
// won't even Serial.print here, since goes straight back to where it came from
}
void receiveSerialMulti(byte* msg, byte* info, int len) {
Serial.println("unhandled MULTI transfer");
}
void buttonPress() {
//sendMulti(&testFile[0], 1024);
}
Loading
esp32-s3-devkitc-1
esp32-s3-devkitc-1