adjust volume level on TX

This commit is contained in:
dj2ls 2022-03-31 21:13:30 +02:00
parent d3ee911186
commit 3f35a01b94
10 changed files with 130 additions and 18 deletions

View File

@ -209,7 +209,7 @@ exports.getDaemonState = function() {
// START TNC
// ` `== multi line string
exports.startTNC = function(mycall, mygrid, rx_audio, tx_audio, radiocontrol, devicename, deviceport, pttprotocol, pttport, serialspeed, data_bits, stop_bits, handshake, rigctld_ip, rigctld_port, enable_fft, enable_scatter, low_bandwith_mode, tuning_range_fmin, tuning_range_fmax, enable_fsk) {
exports.startTNC = function(mycall, mygrid, rx_audio, tx_audio, radiocontrol, devicename, deviceport, pttprotocol, pttport, serialspeed, data_bits, stop_bits, handshake, rigctld_ip, rigctld_port, enable_fft, enable_scatter, low_bandwith_mode, tuning_range_fmin, tuning_range_fmax, enable_fsk, tx_audio_level) {
var json_command = JSON.stringify({
type: 'set',
command: 'start_tnc',
@ -234,7 +234,8 @@ exports.startTNC = function(mycall, mygrid, rx_audio, tx_audio, radiocontrol, de
enable_fsk: enable_fsk,
low_bandwith_mode : low_bandwith_mode,
tuning_range_fmin : tuning_range_fmin,
tuning_range_fmax : tuning_range_fmax
tuning_range_fmax : tuning_range_fmax,
tx_audio_level : tx_audio_level
}]
})

View File

@ -161,6 +161,12 @@ document.getElementById('openReceivedFilesFolder').addEventListener('click', ()
document.getElementById("tuning_range_fmin").value = config.tuning_range_fmin;
document.getElementById("tuning_range_fmax").value = config.tuning_range_fmax;
// Update TX Audio Level
document.getElementById("audioLevelTXvalue").innerHTML = config.tx_audio_level;
document.getElementById("audioLevelTX").value = config.tx_audio_level;
if (config.spectrum == 'waterfall') {
document.getElementById("waterfall-scatter-switch1").checked = true;
document.getElementById("waterfall-scatter-switch2").checked = false;
@ -378,14 +384,35 @@ document.getElementById('openReceivedFilesFolder').addEventListener('click', ()
});
// on change tnc port
document.getElementById("tnc_port").addEventListener("change", () => {
config.tnc_port = document.getElementById("tnc_port").value;
config.daemon_port = parseInt(document.getElementById("tnc_port").value) + 1;
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
});
// on change audio TX Level
document.getElementById("audioLevelTX").addEventListener("change", () => {
var tx_audio_level = document.getElementById("audioLevelTX").value;
document.getElementById("audioLevelTXvalue").innerHTML = tx_audio_level;
config.tx_audio_level = tx_audio_level;
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
let Data = {
command: "set_tx_audio_level",
tx_audio_level: tx_audio_level
};
ipcRenderer.send('run-tnc-command', Data);
});
document.getElementById("sendTestFrame").addEventListener("click", () => {
let Data = {
type: "set",
command: "send_test_frame"
};
ipcRenderer.send('run-tnc-command', Data);
});
// saveMyCall button clicked
document.getElementById("saveMyCall").addEventListener("click", () => {
callsign = document.getElementById("myCall").value;
@ -644,7 +671,7 @@ document.getElementById('openReceivedFilesFolder').addEventListener('click', ()
var radiocontrol = 'disabled';
}
var tx_audio_level = document.getElementById("audioLevelTX").value;
config.radiocontrol = radiocontrol;
@ -668,6 +695,7 @@ document.getElementById('openReceivedFilesFolder').addEventListener('click', ()
config.enable_fft = enable_fft;
config.enable_fsk = enable_fsk;
config.low_bandwith_mode = low_bandwith_mode;
config.tx_audio_level = tx_audio_level;
@ -688,7 +716,7 @@ document.getElementById('openReceivedFilesFolder').addEventListener('click', ()
*/
daemon.startTNC(callsign_ssid, mygrid, rx_audio, tx_audio, radiocontrol, deviceid, deviceport, pttprotocol, pttport, serialspeed, data_bits, stop_bits, handshake, rigctld_ip, rigctld_port, enable_fft, enable_scatter, low_bandwith_mode, tuning_range_fmin, tuning_range_fmax, enable_fsk);
daemon.startTNC(callsign_ssid, mygrid, rx_audio, tx_audio, radiocontrol, deviceid, deviceport, pttprotocol, pttport, serialspeed, data_bits, stop_bits, handshake, rigctld_ip, rigctld_port, enable_fft, enable_scatter, low_bandwith_mode, tuning_range_fmin, tuning_range_fmax, enable_fsk, tx_audio_level);
})
@ -1782,6 +1810,14 @@ ipcRenderer.on('run-tnc-command', (event, arg) => {
if (arg.command == 'stop_transmission') {
sock.stopTransmission();
}
if (arg.command == 'set_tx_audio_level') {
sock.setTxAudioLevel(arg.tx_audio_level);
}
if (arg.command == 'send_test_frame') {
sock.sendTestFrame();
}
});

View File

@ -365,6 +365,14 @@ exports.sendCQ = function() {
writeTncCommand(command)
}
// Set AUDIO Level
exports.setTxAudioLevel = function(value) {
command = '{"type" : "set", "command" : "tx_audio_level", "value" : "'+ value +'"}'
writeTncCommand(command)
}
// Send File
exports.sendFile = function(dxcallsign, mode, frames, filename, filetype, data, checksum) {
@ -447,3 +455,9 @@ exports.disconnectARQ = function() {
command = '{"type" : "arq", "command" : "disconnect"}'
writeTncCommand(command)
}
// SEND SINE
exports.sendTestFrame = function() {
command = '{"type" : "set", "command" : "send_test_frame"}'
writeTncCommand(command)
}

View File

@ -802,7 +802,7 @@
<div class="col-5">
<div class="card text-dark mb-1">
<div class="card-header p-1"><i class="bi bi-volume-up" style="font-size: 1rem; color: black;"></i> <strong>AUDIO LEVEL</strong>
<!--<button type="button" id="audioModalButton" data-bs-toggle="modal" data-bs-target="#audioModal" class="btn btn-sm btn-secondary">Tune</button>-->
<button type="button" id="audioModalButton" data-bs-toggle="modal" data-bs-target="#audioModal" class="btn btn-sm btn-secondary">Tune</button>
</div>
@ -1173,10 +1173,24 @@
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Audio tuning</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
<button type="button" class="btn btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
...
<div class="input-group input-group-sm mb-1"> <span class="input-group-text" id="basic-addon1">Test-Frame</span>
<button type="button" id="sendTestFrame" class="btn btn-danger">Transmit</button>
</div>
<div class="input-group input-group-sm mb-1">
<span class="input-group-text" id="basic-addon1">TX Level</span>
<span class="input-group-text" id="audioLevelTXvalue">---</span>
<span class="input-group-text w-75" id="basic-addon1">
<input type="range" class="form-range" min="0" max="200" step="1" id="audioLevelTX"></span>
</div>
</div>
</div>
</div>

View File

@ -218,6 +218,10 @@ class DAEMON():
if data[21] == 'True':
options.append('--fsk')
options.append('--tx-audio-level')
options.append(data[22])
# try running tnc from binary, else run from source

View File

@ -163,6 +163,9 @@ class DATA():
# [0] DX CALLSIGN
self.close_session()
elif data[0] == 'SEND_TEST_FRAME':
# [0] DX CALLSIGN
self.send_test_frame()
else:
# wrong command
print(f"wrong command {data}")
@ -1943,3 +1946,8 @@ class DATA():
time.sleep(1)
self.transmit_session_heartbeat()
time.sleep(2)
def send_test_frame(self):
modem.MODEM_TRANSMIT_QUEUE.put([12,1,0,[bytearray(126)]])

View File

@ -71,7 +71,8 @@ if __name__ == '__main__':
PARSER.add_argument('--500hz', dest="low_bandwith_mode", action="store_true", help="Enable low bandwith mode ( 500 Hz only )")
PARSER.add_argument('--fsk', dest="enable_fsk", action="store_true", help="Enable FSK mode for ping, beacon and CQ")
PARSER.add_argument('--tuning_range_fmin', dest="tuning_range_fmin", choices=[-50.0, -100.0, -150.0, -200.0, -250.0], default=-50.0, help="Tuning range fmin", type=float)
PARSER.add_argument('--tuning_range_fmax', dest="tuning_range_fmax", choices=[50.0, 100.0, 150.0, 200.0, 250.0], default=50.0, help="Tuning range fmax", type=float)
PARSER.add_argument('--tuning_range_fmax', dest="tuning_range_fmax", choices=[50.0, 100.0, 150.0, 200.0, 250.0], default=50.0, help="Tuning range fmax", type=float)
PARSER.add_argument('--tx-audio-level', dest="tx_audio_level", default=50, help="Set the tx audio level at an early stage", type=int)
ARGS = PARSER.parse_args()
@ -108,7 +109,7 @@ if __name__ == '__main__':
static.LOW_BANDWITH_MODE = ARGS.low_bandwith_mode
static.TUNING_RANGE_FMIN = ARGS.tuning_range_fmin
static.TUNING_RANGE_FMAX = ARGS.tuning_range_fmax
static.TX_AUDIO_LEVEL = ARGS.tx_audio_level

View File

@ -216,11 +216,12 @@ class RF():
audio_thread_datac3 = threading.Thread(target=self.audio_datac3, name="AUDIO_THREAD DATAC3",daemon=True)
audio_thread_datac3.start()
audio_thread_fsk_ldpc0 = threading.Thread(target=self.audio_fsk_ldpc_0, name="AUDIO_THREAD FSK LDPC0",daemon=True)
audio_thread_fsk_ldpc0.start()
if static.ENABLE_FSK:
audio_thread_fsk_ldpc0 = threading.Thread(target=self.audio_fsk_ldpc_0, name="AUDIO_THREAD FSK LDPC0",daemon=True)
audio_thread_fsk_ldpc0.start()
audio_thread_fsk_ldpc1 = threading.Thread(target=self.audio_fsk_ldpc_1, name="AUDIO_THREAD FSK LDPC1",daemon=True)
audio_thread_fsk_ldpc1.start()
audio_thread_fsk_ldpc1 = threading.Thread(target=self.audio_fsk_ldpc_1, name="AUDIO_THREAD FSK LDPC1",daemon=True)
audio_thread_fsk_ldpc1.start()
hamlib_thread = threading.Thread(target=self.update_rig_data, name="HAMLIB_THREAD",daemon=True)
hamlib_thread.start()
@ -382,6 +383,7 @@ class RF():
codec2.api.freedv_rawdatatx(freedv,mod_out,data) # modulate DATA and save it into mod_out pointer
txbuffer += bytes(mod_out)
# append postamble to txbuffer
codec2.api.freedv_rawdatapostambletx(freedv, mod_out_postamble)
@ -393,6 +395,7 @@ class RF():
# resample up to 48k (resampler works on np.int16)
x = np.frombuffer(txbuffer, dtype=np.int16)
x = set_audio_volume(x, static.TX_AUDIO_LEVEL)
txbuffer_48k = self.resampler.resample8_to_48(x)
# explicitly lock our usage of mod_out_queue if needed
@ -411,6 +414,7 @@ class RF():
#structlog.get_logger("structlog").debug("[TNC] mod out shorter than audio buffer", delta=delta)
self.modoutqueue.append(c)
# Release our mod_out_lock so we can use the queue
@ -516,9 +520,10 @@ class RF():
""" """
while True:
data = self.modem_transmit_queue.get()
self.transmit(mode=data[0], repeats=data[1], repeat_delay=data[2], frames=data[3])
#self.modem_transmit_queue.task_done()
# worker for FIFO queue for processing received frames
@ -620,7 +625,8 @@ class RF():
static.HAMLIB_FREQUENCY = self.hamlib.get_frequency()
static.HAMLIB_MODE = self.hamlib.get_mode()
static.HAMLIB_BANDWITH = self.hamlib.get_bandwith()
def calculate_fft(self):
""" """
# channel_busy_delay counter
@ -723,4 +729,10 @@ def get_bytes_per_frame(mode):
# get number of bytes per frame for mode
return int(codec2.api.freedv_get_bits_per_modem_frame(freedv)/8)
def set_audio_volume(datalist, volume):
data = np.fromstring(datalist, np.int16) * (volume / 100.)
return data.astype(np.int16)

View File

@ -193,6 +193,26 @@ def process_tnc_commands(data):
# convert data to json object
received_json = json.loads(data)
# SET TX AUDIO LEVEL -----------------------------------------------------
if received_json["type"] == "set" and received_json["command"] == "tx_audio_level":
try:
static.TX_AUDIO_LEVEL = int(received_json["value"])
command_response("tx_audio_level", True)
except Exception as e:
command_response("tx_audio_level", False)
structlog.get_logger("structlog").warning("[SCK] command execution error", e=e, command=received_json)
# TRANSMIT SINE WAVE -----------------------------------------------------
if received_json["type"] == "set" and received_json["command"] == "send_test_frame":
try:
data_handler.DATA_QUEUE_TRANSMIT.put(['SEND_TEST_FRAME'])
command_response("send_test_frame", True)
except Exception as e:
command_response("send_test_frame", False)
structlog.get_logger("structlog").warning("[SCK] command execution error", e=e, command=received_json)
# CQ CQ CQ -----------------------------------------------------
if received_json["command"] == "cqcqcq":
try:
@ -492,7 +512,7 @@ def process_daemon_commands(data):
low_bandwith_mode = str(received_json["parameter"][0]["low_bandwith_mode"])
tuning_range_fmin = str(received_json["parameter"][0]["tuning_range_fmin"])
tuning_range_fmax = str(received_json["parameter"][0]["tuning_range_fmax"])
tx_audio_level = str(received_json["parameter"][0]["tx_audio_level"])
DAEMON_QUEUE.put(['STARTTNC', \
mycall, \
@ -515,7 +535,8 @@ def process_daemon_commands(data):
low_bandwith_mode, \
tuning_range_fmin, \
tuning_range_fmax, \
enable_fsk \
enable_fsk, \
tx_audio_level \
])
command_response("start_tnc", True)

View File

@ -70,6 +70,7 @@ ENABLE_FSK = False
# ---------------------------------
# Audio Defaults
TX_AUDIO_LEVEL = 50
AUDIO_INPUT_DEVICES = []
AUDIO_OUTPUT_DEVICES = []
AUDIO_INPUT_DEVICE = -2