I have the following Sketch:
#include <ATCommands.h>
#define LASTBLOCK 1023
#define LASTPAGE 63
#define LASTBYTE 2111
#define PAGE_READ 0x13
#define PAGE_READ_CACHE_SEQUENCIAL 0x03
#define READ_FROM_CACHE 0x3B
#define PAGE_READ_CACHE_END 0x3F
#define PAGE_SIZE 2111
#define BUFFER_LEN 32
#define SERIAL_BUFFER_SIZE 255
ATCommands AT;
unsigned int page_to_read = 1;
unsigned int block_to_read = 1;
boolean spi_begun = false;
uint8_t bytes_index = 1;
bool readCallback(ATCommands *sender){
if(page_to_read > LASTPAGE){
page_to_read = 1;
block_to_read ++;
}
if(block_to_read > LASTBLOCK){
spi_begun=false;
return false;
}
if(!spi_begun){
spi_begun=true;
}
sender->serial->print(F("PAGE:"));
sender->serial->println(page_to_read);
sender->serial->print(F("BLOCK:"));
sender->serial->println(block_to_read);
sender->serial->print(F("BYTES_TOTAL:"));
sender->serial->println(block_to_read);
sender->serial->print(F("DATA:"));
// Reading page there's no need for seperate function in order to avoid stack usage
for(int bytes_to_read = PAGE_SIZE; bytes_to_read > 0; bytes_to_read-=BUFFER_LEN){
uint8_t bytes_to_send = bytes_to_read < BUFFER_LEN ? bytes_to_read: BUFFER_LEN;
byte data[BUFFER_LEN] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
for (size_t i = 0; i < BUFFER_LEN; i++){
sender->serial->print(data[i] >>4, HEX);
sender->serial->print(data[i] & 0x0F, HEX);
}
delay(100);
bytes_index++;
}
page_to_read++;
delay(100);
sender->serial->println();
return true;
}
bool at_test_cmd_print(ATCommands *sender){
sender->serial->print(sender->command);
Serial.println(F("Reads next page. If all pages read, then reads the first page from the next block"));
}
static at_command_t commands[] = {
{"+READ", readCallback, at_test_cmd_print, NULL, NULL},
};
void setup() {
Serial.begin(9600);
AT.begin(&Serial, commands, sizeof(commands), SERIAL_BUFFER_SIZE);
}
void loop() {
AT.update();
}
And I want somehow via software serial once I print or read to funnet the data as well. What I want to do is:
- Once I
Serial.print, orSerial.printlnorSerial.writeto also print in software serial - Once I
Serial.readand anySerial.read*method to send the read data back to software serial as well.
The reason is that I have a no easy way to have some soft of debug monitor that read and writes data once the serial port is busy from a custom software that offers no logs or whatoever about serial data sent.