Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get firmware release during detection #447

Merged
merged 3 commits into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions tools/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -440,12 +440,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' ]]
Expand All @@ -457,12 +468,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
Expand Down
21 changes: 16 additions & 5 deletions web_app/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,24 +613,35 @@ 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"}
else:
#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:
Expand Down
37 changes: 15 additions & 22 deletions web_app/static/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,44 +334,37 @@ $(document).ready(function () {
detectApplyBtnElt.innerText = "Apply";
detectApplyBtnElt.setAttribute('disabled', '');
detectApplyBtnElt.removeAttribute('data-dismiss');
detectCancelBtnElt.hidden = false;
detectBodyElt.innerHTML = '<span class="spinner-border spinner-border-sm"></span> 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 = '<b>' + response['gnss_type'] + '</b>' + ' detected on ' + '<b>' + response['port'] + '</b>' + '<br>' + '<br>' + '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 = '<span class="spinner-border spinner-border-sm"></span> 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. <br> would you still like to try to configure the receiver?';
//detectApplyBtnElt.onclick = function (){
// socket.emit("configure_receiver");
// detectBodyElt.innerHTML = '<span class="spinner-border spinner-border-sm"></span> 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(/#$/, '');
}
})

Expand All @@ -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 = '<span class="spinner-border spinner-border-sm"></span> Configuring GNSS receiver...';
socket.emit("configure_receiver");
$('#detectModal').modal();
Expand Down
Loading