From 0bb2ce2e638e2a43fde7dcbd6f73f26ae68f6734 Mon Sep 17 00:00:00 2001 From: nguyentrungthat <80239428+nguentrungthat@users.noreply.github.com> Date: Tue, 17 Mar 2026 08:35:35 +0700 Subject: [PATCH] =?UTF-8?q?Update=20ping=20tr=C6=B0=E1=BB=9Bc=20khi=20load?= =?UTF-8?q?=20ios,=20license?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BACKEND/app/services/line_connection.ts | 28 +++++++++++++++++++++++++ BACKEND/app/ultils/helper.ts | 9 ++++++++ BACKEND/providers/socket_io_provider.ts | 2 ++ 3 files changed, 39 insertions(+) diff --git a/BACKEND/app/services/line_connection.ts b/BACKEND/app/services/line_connection.ts index 4b90aff..f11239f 100644 --- a/BACKEND/app/services/line_connection.ts +++ b/BACKEND/app/services/line_connection.ts @@ -142,6 +142,8 @@ export default class LineConnection { private testingPortPoE: boolean private outputTestingPortPoE: string private debounceSendSummaryReport: NodeJS.Timeout | null = null + private isPingToServer: boolean + private outputPingToServer: string constructor(config: LineConfig, socketIO: any, handleClearLine: () => void) { this.config = config @@ -175,6 +177,8 @@ export default class LineConnection { this.debounceSendSummaryReport = null this.testingPortPoE = false this.outputTestingPortPoE = '' + this.isPingToServer = false + this.outputPingToServer = '' } /** * Connect to line with socket @@ -237,6 +241,8 @@ export default class LineConnection { this.flushLogBuffer() }, 1000) // 1s debounce } + if (this.isPingToServer) this.outputPingToServer += cleanData(data.toString()) + if (data.toString().includes('More') || data.toString().includes('MORE')) this.writeCommand(' ') @@ -1946,4 +1952,26 @@ ${log} this.sendFeatureTested() console.log('Reset DPELP data and features', this.config.id, this.config.listFeatureTested) } + + async pingToServer(serverIP: string) { + this.isPingToServer = true + this.writeCommand('\r\n') + this.writeCommand('enable\r\n') + await sleep(500) + this.writeCommand(`ping ${serverIP}\r\n`) + await sleep(500) + const start = Date.now() + // console.log('[EXPECT]', expect, timeout) + while (Date.now() - start < 60000) { + if (this.outputPingToServer.includes('Success rate')) { + this.outputPingToServer = '' + this.isPingToServer = false + return true + } + await sleep(500) + } + this.isPingToServer = false + this.outputPingToServer = '' + return false + } } diff --git a/BACKEND/app/ultils/helper.ts b/BACKEND/app/ultils/helper.ts index 682a746..3ac8dc6 100644 --- a/BACKEND/app/ultils/helper.ts +++ b/BACKEND/app/ultils/helper.ts @@ -961,6 +961,9 @@ export function buildBody( note: '', }, { expect: '', send: ``, delay: '4', repeat: '1', note: '' }, + { expect: '', send: `ping ${tftpIp}`, delay: '3', repeat: '1', note: '' }, + { expect: 'Success rate', send: ``, delay: '2', repeat: '1', note: '' }, + { expect: '', send: ``, delay: '2', repeat: '1', note: '' }, { expect: '#', send: listDeviceIos?.includes(fileName) ? '' : `copy tftp: flash:`, @@ -1145,6 +1148,9 @@ export function buildBody( repeat: '1', note: '', }, + { expect: '', send: `ping ${tftpIp}`, delay: '3', repeat: '1', note: '' }, + { expect: 'Success rate', send: ``, delay: '2', repeat: '1', note: '' }, + { expect: '', send: ``, delay: '2', repeat: '1', note: '' }, { expect: '#', send: `license install tftp://${tftpIp}/License/${fileName}`, @@ -1306,6 +1312,9 @@ export function buildBody( repeat: '1', note: '', }, + { expect: '', send: `ping ${tftpIp}`, delay: '3', repeat: '1', note: '' }, + { expect: 'Success rate', send: ``, delay: '2', repeat: '1', note: '' }, + { expect: '', send: ``, delay: '2', repeat: '1', note: '' }, { expect: '#', send: `license install tftp://${tftpIp}/License/${fileName}`, diff --git a/BACKEND/providers/socket_io_provider.ts b/BACKEND/providers/socket_io_provider.ts index 2553895..ac440ce 100644 --- a/BACKEND/providers/socket_io_provider.ts +++ b/BACKEND/providers/socket_io_provider.ts @@ -763,6 +763,8 @@ export class WebSocketIo { [lineId], async (lineCon) => { if (isReboot) { + const pingSuccess = await lineCon.pingToServer(station?.tftp_ip || '172.16.7.69') + if (!pingSuccess) return await lineCon.backupIos(iosName) if (!outletNumber || outletNumber < 0) return if (!station) return