Notify caller when subscriber already listens to the channel radio

This commit is contained in:
evgeny committed 2026-10-19 15:05:09 +02:00
1 parent 5a318f6f60
commit 4deee21d9f
3 files changed
+15 -7

No files matched your search

+10 -4
View File
@@ -73,7 +73,9 @@ static void rc_schedule(struct radio_call_context* ctx) {
/* Формат события: id/group/peer:8LE, state/reason/incoming:1 (27 байт). */
static void rc_event(struct radio_call_context* ctx, const struct radio_call_session* s) {
static const char* states[] = {"invalid", "outgoing", "incoming", "ringing", "finished", "wait_decision"};
static const char* reasons[] = {"none", "accepted", "declined", "busy", "cancelled", "unavailable", "no_answer", "audio_error", "phone_busy"};
static const char* reasons[] = {
"none", "accepted", "declined", "busy", "cancelled", "unavailable", "no_answer", "audio_error", "phone_busy", "already_active"
};
uint8_t data[27];
memcpy(data, &s->id, 8); memcpy(data + 8, &s->group, 8); memcpy(data + 16, &s->peer, 8);
data[24] = s->state; data[25] = s->reason; data[26] = s->incoming;
@@ -202,7 +204,7 @@ static void rc_receive(struct ETCP_CONN* conn, struct ll_entry* entry) {
uint8_t command = b[0], reason = b[17];
DEBUG_TRACE(DEBUG_CATEGORY_RADIO, "radio call RX id=%016llx group=%016llx peer=%016llx command=%u reason=%u",
(unsigned long long)id, (unsigned long long)group, (unsigned long long)peer, command, reason);
if (!id || command < RC_INVITE || command > RC_FORCE || reason > RADIO_CALL_PHONE_BUSY ||
if (!id || command < RC_INVITE || command > RC_FORCE || reason > RADIO_CALL_ALREADY_ACTIVE ||
((command == RC_RESULT || command == RC_ACK) ? !reason : reason != 0)) {
DEBUG_WARN(DEBUG_CATEGORY_RADIO, "radio call invalid command=%u reason=%u id=%llu", command, reason, (unsigned long long)id); goto done;
}
@@ -226,7 +228,8 @@ static void rc_receive(struct ETCP_CONN* conn, struct ll_entry* entry) {
s->incoming = 1;
s->state = (ctx->inst->incoming_call_policy & CALL_POLICY_WARN_PHONE) && ctx->inst->phone_state == 2
? RADIO_CALL_WAIT_DECISION : RADIO_CALL_INCOMING;
if (busy) rc_finish(ctx, s, RADIO_CALL_BUSY, 1);
if (radio_is_active(ctx->inst, group)) rc_finish(ctx, s, RADIO_CALL_ALREADY_ACTIVE, 1);
else if (busy) rc_finish(ctx, s, RADIO_CALL_BUSY, 1);
else if (ctx->inst->incoming_call_policy & CALL_POLICY_BLOCK_RADIO) rc_finish(ctx, s, RADIO_CALL_DECLINED, 1);
else if (ctx->inst->phone_state == 2 && (ctx->inst->incoming_call_policy & CALL_POLICY_REJECT_PHONE))
rc_finish(ctx, s, RADIO_CALL_PHONE_BUSY, 1);
@@ -253,7 +256,7 @@ static void rc_receive(struct ETCP_CONN* conn, struct ll_entry* entry) {
}
} else if (command == RC_RESULT) {
if (s->incoming && (reason == RADIO_CALL_ACCEPTED || reason == RADIO_CALL_DECLINED || reason == RADIO_CALL_BUSY ||
reason == RADIO_CALL_PHONE_BUSY)) {
reason == RADIO_CALL_PHONE_BUSY || reason == RADIO_CALL_ALREADY_ACTIVE)) {
DEBUG_WARN(DEBUG_CATEGORY_RADIO, "radio call result invalid for callee id=%016llx reason=%u", (unsigned long long)id, reason); goto done;
}
if (!s->incoming && s->state == RADIO_CALL_OUTGOING && get_time_tb() - s->response_started >= RADIO_CALL_RESPONSE_TB)
@@ -264,6 +267,9 @@ static void rc_receive(struct ETCP_CONN* conn, struct ll_entry* entry) {
rc_finish(ctx, s, reason, 0);
} else if (s->state == RADIO_CALL_FINISHED) rc_send(ctx, s, RC_RESULT, s->reason);
else if ((command == RC_INVITE || command == RC_FORCE) && s->incoming) {
if (s->state == RADIO_CALL_WAIT_DECISION && radio_is_active(ctx->inst, group)) {
rc_finish(ctx, s, RADIO_CALL_ALREADY_ACTIVE, 1); goto done;
}
if (s->state == RADIO_CALL_WAIT_DECISION && ((ctx->inst->incoming_call_policy & CALL_POLICY_BLOCK_RADIO) ||
(ctx->inst->phone_state == 2 && (ctx->inst->incoming_call_policy & CALL_POLICY_REJECT_PHONE)))) {
rc_finish(ctx, s, (ctx->inst->incoming_call_policy & CALL_POLICY_BLOCK_RADIO) ? RADIO_CALL_DECLINED : RADIO_CALL_PHONE_BUSY, 1);
+2 -1
View File
@@ -19,7 +19,8 @@ enum radio_call_state {
};
enum radio_call_reason {
RADIO_CALL_NONE, RADIO_CALL_ACCEPTED, RADIO_CALL_DECLINED, RADIO_CALL_BUSY,
RADIO_CALL_CANCELLED, RADIO_CALL_UNAVAILABLE, RADIO_CALL_NO_ANSWER, RADIO_CALL_AUDIO_ERROR, RADIO_CALL_PHONE_BUSY
RADIO_CALL_CANCELLED, RADIO_CALL_UNAVAILABLE, RADIO_CALL_NO_ANSWER, RADIO_CALL_AUDIO_ERROR, RADIO_CALL_PHONE_BUSY,
RADIO_CALL_ALREADY_ACTIVE
};
enum radio_call_action {
RADIO_CALL_START = 1, RADIO_CALL_READY, RADIO_CALL_ACCEPT, RADIO_CALL_DECLINE,
+3 -2
View File
@@ -777,7 +777,7 @@ void MainWindow::onRadioCallRequested(const QString& channel, quint64 peer) {
/* Один диалог на незавершённое приглашение; принятая рация живёт своим обычным циклом. */
void MainWindow::onRadioCallEvent(const uint8_t* data, int len) {
if (!data || len != 27 || data[24] < RADIO_CALL_OUTGOING || data[24] > RADIO_CALL_WAIT_DECISION ||
data[25] > RADIO_CALL_PHONE_BUSY || data[26] > 1) {
data[25] > RADIO_CALL_ALREADY_ACTIVE || data[26] > 1) {
DEBUG_ERROR(DEBUG_CATEGORY_RADIO, "desktop invalid radio call event bytes=%d", len); return;
}
quint64 id, group, peer;
@@ -799,7 +799,8 @@ void MainWindow::onRadioCallEvent(const uint8_t* data, int len) {
if (reason == RADIO_CALL_ACCEPTED) return;
}
if ((incoming && reason != RADIO_CALL_AUDIO_ERROR) || reason == RADIO_CALL_CANCELLED) return;
const char* text = reason == RADIO_CALL_PHONE_BUSY ? "Subscriber is on a phone call" : reason == RADIO_CALL_DECLINED ? "Radio call declined" :
const char* text = reason == RADIO_CALL_ALREADY_ACTIVE ? "Subscriber's radio is already on in this channel" :
reason == RADIO_CALL_PHONE_BUSY ? "Subscriber is on a phone call" : reason == RADIO_CALL_DECLINED ? "Radio call declined" :
reason == RADIO_CALL_BUSY ? "Subscriber is busy" : reason == RADIO_CALL_NO_ANSWER ? "No answer" :
reason == RADIO_CALL_AUDIO_ERROR ? "Could not start channel radio" : "Subscriber is unavailable";
auto* notice = new QMessageBox(QMessageBox::Information, QCoreApplication::translate("ChatGui", "Radio call"),