diff --git a/gui/preload-chat.js b/gui/preload-chat.js index 9f90fcf1..a76450f1 100644 --- a/gui/preload-chat.js +++ b/gui/preload-chat.js @@ -460,50 +460,57 @@ window.addEventListener("DOMContentLoaded", () => { } var timestamp = Math.floor(Date.now() / 1000); + // check if broadcast - if (dxcallsign == "broadcast") { - var tnc_command = "broadcast"; - + dxcallsign.starts + if (dxcallsign.startsWith('BC-')) { + var tnc_command = "broadcast" let Data = { - command: tnc_command, - data: chatmessage, - }; - ipcRenderer.send("run-tnc-command", Data); + command: tnc_command, + broadcastChannel: dxcallsign, + data: chatmessage, + }; + ipcRenderer.send("run-tnc-command", Data); + + + } else { - var file_checksum = crc32(file).toString(16).toUpperCase(); - var tnc_command = "msg"; - var file_checksum = crc32(file).toString(16).toUpperCase(); - console.log(file_checksum); - var data_with_attachment = - timestamp + - split_char + - chatmessage + - split_char + - filename + - split_char + - filetype + - split_char + - file; + var file_checksum = crc32(file).toString(16).toUpperCase(); + var tnc_command = "msg" + var file_checksum = crc32(file).toString(16).toUpperCase(); + console.log(file_checksum); + var data_with_attachment = + timestamp + + split_char + + chatmessage + + split_char + + filename + + split_char + + filetype + + split_char + + file; - document.getElementById("selectFilesButton").innerHTML = ``; - var uuid = uuidv4(); - let uuidlast = uuid.lastIndexOf("-"); - uuidlast += 1; - if (uuidlast > 0) { - uuid = uuid.substring(uuidlast); - } - console.log(data_with_attachment); - let Data = { - command: tnc_command, - dxcallsign: dxcallsign, - mode: 255, - frames: 5, - data: data_with_attachment, - checksum: file_checksum, - uuid: uuid, - }; - ipcRenderer.send("run-tnc-command", Data); + document.getElementById("selectFilesButton").innerHTML = ``; + var uuid = uuidv4(); + let uuidlast = uuid.lastIndexOf("-"); + uuidlast += 1; + if (uuidlast > 0) { + uuid = uuid.substring(uuidlast); } + console.log(data_with_attachment); + let Data = { + command: tnc_command, + dxcallsign: dxcallsign, + mode: 255, + frames: 5, + data: data_with_attachment, + checksum: file_checksum, + uuid: uuid, + }; + ipcRenderer.send("run-tnc-command", Data); + } + + db.post({ _id: uuid, diff --git a/gui/preload-main.js b/gui/preload-main.js index be7dc993..c62b426b 100644 --- a/gui/preload-main.js +++ b/gui/preload-main.js @@ -2785,6 +2785,12 @@ ipcRenderer.on("run-tnc-command", (event, arg) => { arg.uuid, arg.command ); + } + if (arg.command == "broadcast") { + sock.sendBroadcastChannel( + arg.broadcastChannel, + arg.data + ); } if (arg.command == "stop_transmission") { sock.stopTransmission(); diff --git a/gui/sock.js b/gui/sock.js index a2262971..ed84ac96 100644 --- a/gui/sock.js +++ b/gui/sock.js @@ -835,6 +835,35 @@ exports.sendFecIsWriting = function (mycallsign) { writeTncCommand(command); }; +// SEND FEC TO BROADCASTCHANNEL +exports.sendBroadcastChannel = function (channel, data) { + + let checksum = '' + let uuid = '' + let command = '' + data = FD.btoa_FD( + "m" + + split_char + + command + + split_char + + checksum + + split_char + + uuid + + split_char + + data + ); + + + + let payload = data; + command = + '{"type" : "fec", "command" : "transmit", "mode": "datac4", "wakeup": "True", "payload" : "' + + payload + + '"}'; + writeTncCommand(command); +}; + + // RECORD AUDIO exports.record_audio = function () { command = '{"type" : "set", "command" : "record_audio"}'; diff --git a/tnc/codec2.py b/tnc/codec2.py index 424ac8d3..12172be1 100644 --- a/tnc/codec2.py +++ b/tnc/codec2.py @@ -35,6 +35,7 @@ class FREEDV_MODE(Enum): fsk_ldpc_0 = 200 fsk_ldpc_1 = 201 + class FREEDV_MODE_USED_SLOTS(Enum): """ Enumeration for codec2 used slots diff --git a/tnc/config.ini b/tnc/config.ini index a0dba20c..a353bb3b 100644 --- a/tnc/config.ini +++ b/tnc/config.ini @@ -10,14 +10,14 @@ ssid_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] [AUDIO] #audio settings -rx = 10 -tx = 10 +rx = 0 +tx = 0 txaudiolevel = 250 auto_tune = False [RADIO] #radio settings -radiocontrol = rigctld +radiocontrol = disabled rigctld_ip = 127.0.0.1 rigctld_port = 4532 @@ -38,3 +38,4 @@ tx_delay = 50 [TCI] ip = 127.0.0.1 port = 50001 + diff --git a/tnc/data_handler.py b/tnc/data_handler.py index ee7d1354..c93c2a03 100644 --- a/tnc/data_handler.py +++ b/tnc/data_handler.py @@ -324,15 +324,17 @@ class DATA: # [5] attempts self.open_dc_and_transmit(data[1], data[2], data[3], data[4], data[5]) - elif data[0] == "FEC": - # [1] DATA_OUT bytes - # [2] MODE str datac0/1/3... - self.send_fec_frame(data[1], data[2]) elif data[0] == "FEC_IS_WRITING": # [1] DATA_OUT bytes # [2] MODE str datac0/1/3... self.send_fec_is_writing(data[1]) + + elif data[0] == "FEC": + # [1] WAKEUP bool + # [2] MODE str datac0/1/3... + # [3] PAYLOAD + self.send_fec(data[1], data[2], data[3]) else: self.log.error( "[TNC] worker_transmit: received invalid command:", data=data @@ -3447,8 +3449,21 @@ class DATA: frame_to_tx=[test_frame], c2_mode=FREEDV_MODE.datac13.value ) - def send_fec_frame(self, payload, mode) -> None: + def send_fec(self, mode, wakeup, payload): """Send an empty test frame""" + print(mode) + print(wakeup) + print(payload) + print(codec2.FREEDV_MODE[mode.lower()].value) + if mode: + mode_int = codec2.freedv_get_mode_value_by_name("sig0") + payload_per_frame = modem.get_bytes_per_frame(mode_int) - 2 + fec_wakeup_frame = bytearray(payload_per_frame) + fec_wakeup_frame[:1] = bytes([FR_TYPE.FEC_WAKEUP.value]) + fec_wakeup_frame[1:7] = helpers.callsign_to_bytes(Station.mycallsign) + self.enqueue_frame_for_tx( + frame_to_tx=[fec_wakeup_frame], c2_mode=codec2.FREEDV_MODE[mode].value + ) mode_int = codec2.freedv_get_mode_value_by_name(mode) payload_per_frame = modem.get_bytes_per_frame(mode_int) - 2 @@ -3462,7 +3477,7 @@ class DATA: ) def send_fec_is_writing(self, mycallsign) -> None: - """Send an empty test frame""" + """Send an fec is writing frame""" fec_frame = bytearray(14) fec_frame[:1] = bytes([FR_TYPE.IS_WRITING.value]) @@ -3477,6 +3492,7 @@ class DATA: else: return False + def save_data_to_folder(self, transmission_uuid, timestamp, diff --git a/tnc/sock.py b/tnc/sock.py index b150df89..25f679b5 100644 --- a/tnc/sock.py +++ b/tnc/sock.py @@ -482,12 +482,13 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler): def tnc_fec_transmit(self, received_json): try: mode = received_json["mode"] + wakeup = received_json["wakeup"] base64data = received_json["payload"] if len(base64data) % 4: raise TypeError payload = base64.b64decode(base64data) - DATA_QUEUE_TRANSMIT.put(["FEC", payload, mode]) + DATA_QUEUE_TRANSMIT.put(["FEC", mode, wakeup, payload]) command_response("fec_transmit", True) except Exception as err: command_response("fec_transmit", False) diff --git a/tnc/static.py b/tnc/static.py index 4a6f4a4b..d480decd 100644 --- a/tnc/static.py +++ b/tnc/static.py @@ -174,6 +174,7 @@ class FRAME_TYPE(Enum): ARQ_STOP = 249 BEACON = 250 FEC = 251 + FEC_WAKEUP = 252 IDENT = 254 TEST_FRAME = 255