Enhance logging functionality across multiple scripts, enabling debug mode checks and detailed communication logs for serial connections and firmware updates.
This commit is contained in:
@@ -68,7 +68,54 @@ async function createFirmwareUpdate(){
|
||||
|
||||
}
|
||||
|
||||
/*! For license information please see main.js.LICENSE.txt */
|
||||
async function logCommunication(data, direction) {
|
||||
// Only log if debug mode is enabled
|
||||
if (typeof DEBUG === 'undefined' || !DEBUG) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// Get service token for API authentication
|
||||
const serviceToken = document.getElementById("servicetoken")?.innerHTML || '';
|
||||
|
||||
// Get serial number if available
|
||||
let serialNumber = '';
|
||||
if (typeof serial !== 'undefined' && serial) {
|
||||
serialNumber = serial;
|
||||
}
|
||||
|
||||
const logData = {
|
||||
data: data,
|
||||
direction: direction, // 'sent', 'received', 'connected', 'disconnected', 'handshake', 'upload', 'verify'
|
||||
timestamp: new Date().toISOString(),
|
||||
serial_number: serialNumber,
|
||||
maintenance_run: 0 // Not applicable for upload, set to 0
|
||||
};
|
||||
|
||||
// Get base URL for API calls (assuming 'link' variable is defined globally)
|
||||
const url = link + '/v2/com_log/log';
|
||||
|
||||
const bearer = 'Bearer ' + serviceToken;
|
||||
|
||||
const response = await fetch(url, {
|
||||
method: 'POST',
|
||||
withCredentials: true,
|
||||
credentials: 'include',
|
||||
headers: {
|
||||
'Authorization': bearer,
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(logData)
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
console.warn('Failed to log communication:', response.status);
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('Error logging communication:', error);
|
||||
}
|
||||
}
|
||||
|
||||
(() => {
|
||||
var e = {
|
||||
184: (e, t, r) => {
|
||||
@@ -166,13 +213,13 @@ async function createFirmwareUpdate(){
|
||||
emergencyPlug: {
|
||||
signature: n.from([30, 149, 15]),
|
||||
pageSize: 128,
|
||||
timeout: 400,
|
||||
timeout: 1000,
|
||||
baudRate: 57600
|
||||
},
|
||||
EMP2: {
|
||||
signature: n.from([30, 149, 15]),
|
||||
pageSize: 128,
|
||||
timeout: 400,
|
||||
timeout: 1000,
|
||||
baudRate: 115200
|
||||
}
|
||||
};
|
||||
@@ -184,6 +231,7 @@ async function createFirmwareUpdate(){
|
||||
baudRate: e.baudRate
|
||||
});
|
||||
r(0);
|
||||
await logCommunication('Starting firmware upload process', 'upload');
|
||||
const a = new c.default;
|
||||
let u = 0,
|
||||
p = i.length / e.pageSize;
|
||||
@@ -194,6 +242,7 @@ async function createFirmwareUpdate(){
|
||||
r(e)
|
||||
}
|
||||
}, await f.default.series([a.sync.bind(a, o, 3, e.timeout), a.sync.bind(a, o, 3, e.timeout), a.sync.bind(a, o, 3, e.timeout), a.verifySignature.bind(a, o, e.signature, e.timeout), a.setOptions.bind(a, o, {}, e.timeout), a.enterProgrammingMode.bind(a, o, e.timeout), a.upload.bind(a, o, i, e.pageSize, e.timeout), n ? a.verify.bind(a, o, i, e.pageSize, e.timeout) : h, a.exitProgrammingMode.bind(a, o, e.timeout)])
|
||||
await logCommunication('Firmware upload process completed', 'upload');
|
||||
} finally {
|
||||
s.default.close()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user