3 #include "AudioTools/CoreAudio/Buffers.h"
37 int32_t spi_speed = 8000000;
39 int frequency = 868E6;
41 int spreading_factor = 6;
44 int signal_bandwidth = 500E3;
48 int max_begin_retry = 10;
79 is_audio_info_sent =
false;
80 buffer.resize(cfg.max_size);
83 LOGI(
"LoRa begin...");
84 LoRa.setPins(cfg.pin_ss, cfg.pin_rst, cfg.pin_dio0);
86 rc = LoRa.begin(cfg.frequency);
87 if (++count > cfg.max_begin_retry)
return false;
89 LOGI(
"LoRa begin failed");
93 LoRa.setSignalBandwidth(cfg.signal_bandwidth);
94 LoRa.setSpreadingFactor(cfg.spreading_factor);
95 LoRa.setTxPower(cfg.tx_power);
96 LoRa.setSPIFrequency(cfg.spi_speed);
97 LoRa.setSyncWord(cfg.sync_word);
98 if (rc) LOGI(
"LoRa begin success");
107 size_t readBytes(uint8_t* data,
size_t len) {
108 LOGI(
"LoRaStream::readBytes: %d", len);
109 size_t packetSize = LoRa.parsePacket();
110 if (!cfg && packetSize ==
sizeof(AudioInfo)) {
112 packetSize = LoRa.parsePacket();
114 int toRead = min(len, packetSize);
115 int read = LoRa.readBytes(data, toRead);
119 int available() {
return cfg.max_size; }
121 int availableForWrite() {
return cfg.max_size; }
123 size_t write(
const uint8_t* data,
size_t len) {
124 LOGI(
"LoRaStream::write: %d", len);
126 if (cfg && !is_audio_info_sent) {
128 is_audio_info_sent =
true;
131 for (
int j = 0; j < len; j++) {
132 buffer.
write(data[j]);
145 SingleBuffer<uint8_t> buffer;
146 bool is_audio_info_sent =
false;
148 void readAudioInfo() {
151 int read = LoRa.readBytes((uint8_t*)&tmp,
sizeof(AudioInfo));
155 void writeAudioInfo() {
159 LoRa.write((uint8_t*)&ai,
sizeof(ai));