diff --git a/src/ipc_client.c b/src/ipc_client.c index 5fb9a20..39b1448 100644 --- a/src/ipc_client.c +++ b/src/ipc_client.c @@ -27,6 +27,29 @@ void ipc_close(IPC_Client *client) { client->fd = -1; } +int ipc_send_streams(IPC_Client *client, uint8_t streams) { + if (client->fd < 0) return -1; + + uint8_t msg[2]; + msg[0] = 113; + msg[1] = streams; + + ssize_t sent = send(client->fd, msg, sizeof(msg), 0); + if (sent != (ssize_t)sizeof(msg)) { + fprintf(stderr, "fm95 ipc: short/failed send\n"); + return -1; + } + + uint8_t reply; + if (recv(client->fd, &reply, 1, 0) <= 0) { + fprintf(stderr, "fm95 ipc: no reply / disconnected\n"); + return -1; + } + if (reply == 1) fprintf(stderr, "fm95 rejected message (unknown opcode?)\n"); + + return 0; +} + // Pulls one group's worth of bits (BITS_PER_GROUP), differentially encodes, // packs 8-to-a-byte, sends as opcode 112 with the stream index. int ipc_send_bits(IPC_Client *client, RDSEncoder *enc, uint8_t stream) { diff --git a/src/ipc_client.h b/src/ipc_client.h index ae2953f..b12e40f 100644 --- a/src/ipc_client.h +++ b/src/ipc_client.h @@ -8,4 +8,5 @@ typedef struct { int ipc_connect(IPC_Client *client, const char *socket_path); void ipc_close(IPC_Client *client); +int ipc_send_streams(IPC_Client *client, uint8_t streams); int ipc_send_bits(IPC_Client *client, RDSEncoder *enc, uint8_t stream); \ No newline at end of file diff --git a/src/rds95.c b/src/rds95.c index f8f84ff..2037dcf 100644 --- a/src/rds95.c +++ b/src/rds95.c @@ -188,11 +188,16 @@ int main(int argc, char **argv) { IPC_Client client; if (ipc_connect(&client, "/etc/fm95/ctl.socket") < 0) goto exit; + uint8_t sent_num = config.num_streams; ipc_send_streams(&client, sent_num); + while (!stop_rds) { for (uint8_t s = 0; s < config.num_streams; s++) { ipc_send_bits(&client, &rdsEncoder, s); } sleep_until_next_group(BITS_PER_GROUP, 1187.5); + if(config.num_streams != sent_num) { + sent_num = config.num_streams; ipc_send_streams(&client, sent_num); + } } ipc_close(&client);