diff --git a/tools/install.sh b/tools/install.sh index 03b5fb6..3d49987 100755 --- a/tools/install.sh +++ b/tools/install.sh @@ -447,12 +447,23 @@ detect_gnss() { [[ ${#detected_gnss[*]} -eq 2 ]] && detected_gnss[2]='115200' # If /dev/ttyGNSS is a symlink of the detected serial port, switch to ttyGNSS [[ '/dev/ttyGNSS' -ef '/dev/'"${detected_gnss[0]}" ]] && detected_gnss[0]='ttyGNSS' + # Get firmware release + if [[ "${detected_gnss[1]}" =~ 'u-blox' ]] && [[ $(python3 "${rtkbase_path}"/tools/ubxtool -f /dev/"${detected_gnss[0]}" -s ${detected_gnss[2]} -p MON-VER) =~ 'ZED-F9P' ]] + then + #get F9P firmware release + detected_gnss[3]=$(python3 "${rtkbase_path}"/tools/ubxtool -f /dev/"${detected_gnss[0]}" -s ${detected_gnss[2]} -p MON-VER | grep 'FWVER' | awk '{print $NF}') + sudo -u "${RTKBASE_USER}" sed -i s/^receiver_firmware=.*/receiver_firmware=\'${firmware}\'/ "${rtkbase_path}"/settings.conf + elif [[ "${detected_gnss[1]}" =~ 'Septentrio' ]] && [[ $(python3 "${rtkbase_path}"/tools/sept_tool.py --port /dev/ttyGNSS_CTRL --baudrate ${detected_gnss[2]} --command get_model --retry 5) =~ 'mosaic-X5' ]] + then + #get mosaic-X5 firmware release + detected_gnss[3]="$(python3 "${rtkbase_path}"/tools/sept_tool.py --port /dev/ttyGNSS_CTRL --baudrate ${detected_gnss[2]} --command get_firmware --retry 5)" || firmware='?' + fi # "send" result - echo '/dev/'"${detected_gnss[0]}" ' - ' "${detected_gnss[1]}"' - ' "${detected_gnss[2]}" + echo '/dev/'"${detected_gnss[0]}" ' - ' "${detected_gnss[1]}"' - ' "${detected_gnss[2]}"' - ' "${detected_gnss[3]}" #Write Gnss receiver settings inside settings.conf #Optional argument --no-write-port (here as variable $1) will prevent settings.conf modifications. It will be just a detection without any modification. - if [[ ${#detected_gnss[*]} -eq 3 ]] && [[ "${1}" -eq 0 ]] + if [[ ${#detected_gnss[*]} -eq 4 ]] && [[ "${1}" -eq 0 ]] then echo 'GNSS RECEIVER DETECTED: /dev/'"${detected_gnss[0]}" ' - ' "${detected_gnss[1]}" ' - ' "${detected_gnss[2]}" #if [[ ${detected_gnss[1]} =~ 'u-blox' ]] @@ -464,12 +475,12 @@ detect_gnss() { #change the com port value/settings inside settings.conf sudo -u "${RTKBASE_USER}" sed -i s/^com_port=.*/com_port=\'${detected_gnss[0]}\'/ "${rtkbase_path}"/settings.conf sudo -u "${RTKBASE_USER}" sed -i s/^com_port_settings=.*/com_port_settings=\'${detected_gnss[2]}:8:n:1\'/ "${rtkbase_path}"/settings.conf - + sudo -u "${RTKBASE_USER}" sed -i s/^receiver_firmware=.*/receiver_firmware=\'"${detected_gnss[3]}"\'/ "${rtkbase_path}"/settings.conf else echo 'settings.conf is missing' return 1 fi - elif [[ ${#detected_gnss[*]} -ne 3 ]] + elif [[ ${#detected_gnss[*]} -ne 4 ]] then return 1 fi diff --git a/web_app/server.py b/web_app/server.py index 9435d60..6837fdb 100755 --- a/web_app/server.py +++ b/web_app/server.py @@ -612,8 +612,8 @@ def detect_receiver(json_msg): #print("DEBUG ok stdout: ", answer.stdout) try: device_info = next(x for x in answer.stdout.splitlines() if x.startswith('/dev/')).split(' - ') - port, gnss_type, speed = [x.strip() for x in device_info] - result = {"result" : "success", "port" : port, "gnss_type" : gnss_type, "port_speed" : speed} + port, gnss_type, speed, firmware = [x.strip() for x in device_info] + result = {"result" : "success", "port" : port, "gnss_type" : gnss_type, "port_speed" : speed, "firmware" : firmware} result.update(json_msg) except Exception: result = {"result" : "failed"} @@ -621,15 +621,26 @@ def detect_receiver(json_msg): #print("DEBUG Not ok stdout: ", answer.stdout) result = {"result" : "failed"} #result = {"result" : "failed"} - #result = {"result" : "success", "port" : "bestport", "gnss_type" : "F12P"} - #print('DEBUG result: ', result) + #result = {"result" : "success", "port" : "/dev/ttybestport", "gnss_type" : "F12P", "port_speed" : "115200", "firmware" : "1.55"} + result.update(json_msg) ## get back "then_configure" key/value socketio.emit("gnss_detection_result", json.dumps(result), namespace="/test") +@socketio.on("apply_receiver_settings", namespace="/test") +def apply_receiver_settings(json_msg): + print("Applying gnss receiver new settings") + print(json_msg) + rtkbaseconfig.update_setting("main", "com_port", json_msg.get("port").strip("/dev/"), write_file=False) + rtkbaseconfig.update_setting("main", "com_port_settings", json_msg.get("port_speed") + ':8:n:1', write_file=False) + rtkbaseconfig.update_setting("main", "receiver", json_msg.get("gnss_type"), write_file=False) + rtkbaseconfig.update_setting("main", "receiver_firmware", json_msg.get("firmware"), write_file=True) + + socketio.emit("gnss_settings_saved", json.dumps(json_msg), namespace="/test") + @socketio.on("configure_receiver", namespace="/test") def configure_receiver(brand="", model=""): # only some receiver could be configured automaticaly # After port detection, the main service will be restarted, and it will take some time. But we have to stop it to - # configure the receiver. We wait 2 seconds before stopping it to remove conflicting calls. + # configure the receiver. We wait a few seconds before stopping it to remove conflicting calls. time.sleep(4) main_service = services_list[0] if main_service.get("active") is True: diff --git a/web_app/static/settings.js b/web_app/static/settings.js index 9f48006..d27ca24 100644 --- a/web_app/static/settings.js +++ b/web_app/static/settings.js @@ -334,44 +334,37 @@ $(document).ready(function () { detectApplyBtnElt.innerText = "Apply"; detectApplyBtnElt.setAttribute('disabled', ''); detectApplyBtnElt.removeAttribute('data-dismiss'); + detectCancelBtnElt.hidden = false; detectBodyElt.innerHTML = ' Detecting GNSS receiver...'; socket.emit("detect_receiver", {"then_configure" : false}); $('#detectModal').modal(); }); socket.on("gnss_detection_result", function(msg) { - // open modal box with detection result and asking for configuration if detection is a success and a u-blox receiver + // open modal box with detection result and asking for configuration if detection is a success response = JSON.parse(msg); console.log(response); detectApplyBtnElt.setAttribute('data-dismiss', 'modal'); if (response['result'] === 'success') { detectBodyElt.innerHTML = '' + response['gnss_type'] + '' + ' detected on ' + '' + response['port'] + '' + '
' + '
' + 'Do you want to apply?'; detectApplyBtnElt.onclick = function (){ - document.querySelector('#com_port').value = response['port'].replace(/^\/dev\//, ''); - document.querySelector('#com_port_settings').value = response['port_speed'] + ':8:n:1'; - // NEW METHOD from https://stackoverflow.com/questions/35154348/trigger-form-submission-with-javascript - document.getElementById("main").dispatchEvent(new SubmitEvent('submit', {cancelable: true})); - if (response['then_configure']) { - // We need to wait for the service stop/restart after the previous click on form save button. - // Yes, it's dirty... - //setTimeout(() => { document.querySelector('#configure_receiver_button').click(); }, 2000); - document.querySelector('#configure_receiver_button').click(); - } - // detectBodyElt.innerHTML = ' Configuring GNSS receiver...'; - // detectApplyBtnElt.setAttribute('disabled', ''); + socket.emit("apply_receiver_settings", response) }; detectApplyBtnElt.removeAttribute('disabled'); } else { detectApplyBtnElt.setAttribute('disabled', ''); detectBodyElt.innerHTML = 'No GNSS receiver detected'; - // TODO add a way to send the configuration even though the receiver isn't detected. It could be useful for F9P connected with Uart. - //detectBodyElt.innerHTML = 'No GNSS receiver detected.
would you still like to try to configure the receiver?'; - //detectApplyBtnElt.onclick = function (){ - // socket.emit("configure_receiver"); - // detectBodyElt.innerHTML = ' Configuring GNSS receiver...'; - // detectApplyBtnElt.setAttribute('disabled', ''); - //}; - //detectApplyBtnElt.removeAttribute('disabled'); + } + }) + socket.on("gnss_settings_saved", function(msg) { + // gnss settings are saved. + response = JSON.parse(msg); + if (response['then_configure']) { + // asking for gnss receiver configuration + document.querySelector('#configure_receiver_button').click(); + } else { + // refreshing the page to display the new informations + location.href = document.URL.replace(/#$/, ''); } }) @@ -381,7 +374,7 @@ $(document).ready(function () { detectApplyBtnElt.onclick = function (){}; //remove the previous attached event which launched the gnss configuration detectApplyBtnElt.innerText = "Close"; detectApplyBtnElt.setAttribute('disabled', ''); - detectCancelBtnElt.remove(); + detectCancelBtnElt.hidden = true; detectBodyElt.innerHTML = ' Configuring GNSS receiver...'; socket.emit("configure_receiver"); $('#detectModal').modal();