Merge pull request #655 from DJ2LS/dev-message-auto-repeat

message auto repeat
This commit is contained in:
Mashintime 2024-02-18 15:37:37 -05:00 committed by GitHub
commit ee6ca66602
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 80 additions and 3 deletions

View file

@ -5,9 +5,24 @@ import { setActivePinia } from "pinia";
import pinia from "../store/index";
setActivePinia(pinia);
import { settingsStore as settings } from "../store/settingsStore.js";
import { settingsStore as settings, onChange } from "../store/settingsStore.js";
</script>
<template>
<h5>...soon...</h5>
<div class="input-group input-group-sm mb-1">
<label class="input-group-text w-50">Enable message auto repeat</label>
<label class="input-group-text w-50">
<div class="form-check form-switch form-check-inline ms-2">
<input
class="form-check-input"
type="checkbox"
@change="onChange"
v-model="settings.remote.MESSAGES.enable_auto_repeat"
/>
<label class="form-check-label" for="enableMessagesAutoRepeatSwitch"
>Re-send message on beacon</label
>
</div>
</label>
</div>
</template>

View file

@ -97,6 +97,9 @@ const defaultConfig = {
tci_ip: "127.0.0.1",
tci_port: 0,
},
MESSAGES: {
enable_auto_repeat: false,
},
},
};

View file

@ -55,3 +55,6 @@ rx_buffer_size = 64
tx_delay = 200
beacon_interval = 300
[MESSAGES]
enable_auto_repeat = False

View file

@ -66,6 +66,9 @@ class CONFIG:
'tx_delay': int,
'beacon_interval': int,
},
'MESSAGES': {
'enable_auto_repeat': bool,
}
}
default_values = {

View file

@ -4,6 +4,7 @@ import data_frame_factory
import frame_handler
import datetime
from message_system_db_beacon import DatabaseManagerBeacon
from message_system_db_messages import DatabaseManagerMessages
from message_system_db_manager import DatabaseManager
@ -15,3 +16,7 @@ class BeaconFrameHandler(frame_handler.FrameHandler):
self.details["snr"],
self.details['frame']["gridsquare"]
)
if self.config["MESSAGES"]["enable_auto_repeat"]:
# set message to queued if beacon received
DatabaseManagerMessages(self.event_manager).set_message_to_queued_for_callsign(self.details['frame']["origin"])

View file

@ -2,6 +2,9 @@ import frame_handler_ping
import helpers
import data_frame_factory
import frame_handler
from message_system_db_messages import DatabaseManagerMessages
class CQFrameHandler(frame_handler_ping.PingFrameHandler):
def should_respond(self):
@ -14,3 +17,7 @@ class CQFrameHandler(frame_handler_ping.PingFrameHandler):
self.details['snr']
)
self.transmit(qrv_frame)
if self.config["MESSAGES"]["enable_auto_repeat"]:
# set message to queued if CQ received
DatabaseManagerMessages(self.event_manager).set_message_to_queued_for_callsign(self.details['frame']["origin"])

View file

@ -201,4 +201,44 @@ class DatabaseManagerMessages(DatabaseManager):
session.rollback()
self.log(f"An error occurred while marking message {message_id} as read: {e}")
finally:
session.remove()
session.remove()
def set_message_to_queued_for_callsign(self, callsign):
session = self.get_thread_scoped_session()
try:
# Find the 'failed' status object
failed_status = session.query(Status).filter_by(name='failed').first()
# Find the 'queued' status object
queued_status = session.query(Status).filter_by(name='queued').first()
# Ensure both statuses are found
if not failed_status or not queued_status:
self.log("Failed or queued status not found", isWarning=True)
return
# Query for messages with the specified callsign, 'failed' status, and fewer than 10 attempts
messages = session.query(P2PMessage) \
.filter(P2PMessage.origin_callsign == callsign) \
.filter(P2PMessage.status_id == failed_status.id) \
.filter(P2PMessage.attempt < 10) \
.all()
if messages:
# Update each message's status to 'queued'
for message in messages:
# Increment attempt count using the existing function
self.increment_message_attempts(message.id)
message.status_id = queued_status.id
self.log(f"Set message {message.id} to queued and incremented attempt")
session.commit()
return {'status': 'success', 'message': f'{len(messages)} message(s) set to queued'}
else:
return {'status': 'failure', 'message': 'No eligible messages found'}
except Exception as e:
session.rollback()
self.log(f"An error occurred while setting messages to queued: {e}", isWarning=True)
return {'status': 'failure', 'message': str(e)}
finally:
session.remove()

View file

@ -93,6 +93,7 @@ def index():
@app.route('/config', methods=['GET', 'POST'])
def config():
if request.method in ['POST']:
print(request.json)
set_config = app.config_manager.write(request.json)
if not set_config:
response = api_response(None, 'error writing config')