Skip to content

Commit 1a22173

Browse files
committed
KARadioProtocol
1 parent beb68a0 commit 1a22173

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/AudioTools/AudioLibs/KARadioProtocol.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,13 @@ namespace audio_tools {
1212

1313
/***
1414
* @brief KA-Radio Protocol: We can use the KA-Radio protocol to control the
15-
* audio player provided by the audiotools. Example: volume=50&play=128&infos
15+
* audio player provided by the audiotools.
16+
* Supported commands: play, instant, volume, volume+, volume-, pause,
17+
* resume, stop, start, next, prev, mute, infos, version.
18+
* Example: volume=50&play=128&infos
1619
* See https://github.com/karawin/Ka-Radio32/blob/master/Interface.md
20+
*
21+
* @ingroup player
1722
* @author Phil Schatzmann
1823
*/
1924

@@ -188,6 +193,8 @@ class KARadioProtocol {
188193
for (Action& act : actions) {
189194
if (name.equals(act.cmd)) {
190195
return act.callback(*p_player, name, arg, result, this);
196+
} else {
197+
LOGD("-> %s vs %s: failed", name.c_str(), act.cmd);
191198
}
192199
}
193200

@@ -208,6 +215,7 @@ class KARadioProtocol {
208215
Action act;
209216
act.cmd = cmd;
210217
act.callback = cb;
218+
actions.push_back(act);
211219
}
212220

213221
protected:

src/AudioTools/AudioLibs/KARadioProtocolServer.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,25 +50,35 @@ class KARadioProtocolServer {
5050
void loop() { server.copy(); }
5151
void copy() { server.copy(); }
5252

53+
/// Defines the buffer size that is made available for the http reply
54+
void setBufferSize(int size){
55+
buffer_size = size;
56+
}
57+
5358
protected:
5459
WiFiServer wifi;
5560
HttpServer server{wifi};
5661
KARadioProtocol protocol;
57-
RingBuffer<uint8_t> ringBuffer{512};
62+
RingBuffer<uint8_t> ringBuffer{0};
5863
QueueStream<uint8_t> queueStream{ringBuffer};
5964
Vector<void*> context{1};
6065
int port = 80;
6166
const char* ssid = nullptr;
6267
const char* password = nullptr;
68+
int buffer_size = 512;
6369

6470
static void parse(HttpServer* server, const char* requestPath,
6571
HttpRequestHandlerLine* hl) {
6672
LOGI("parse: %s", requestPath);
6773
KARadioProtocolServer* self = (KARadioProtocolServer*)hl->context[0];
74+
self->ringBuffer.resize(self->buffer_size);
6875
QueueStream<uint8_t>& queueStream = self->queueStream;
76+
queueStream.begin();
6977
bool ok = self->protocol.processCommand(requestPath, queueStream);
78+
LOGI("available: %d", queueStream.available());
7079
server->reply("text/plain", queueStream, queueStream.available(),
7180
ok ? 200 : 400, ok ? SUCCESS : "Error");
81+
self->ringBuffer.resize(0);
7282
}
7383
};
7484
} // namespace audio_tools

0 commit comments

Comments
 (0)