From 5eacf4f6f8597e3ba71973487acf85a31d083b43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bence=20Freny=C3=B3?= <26139379+bencefr@users.noreply.github.com> Date: Mon, 16 Nov 2020 12:22:15 +0100 Subject: [PATCH] feat: extended CEREG regex to support newer levels --- __tests__/ResponseConverters.spec.js | 4 +++- package-lock.json | 10 +++++++++- src/api/Registration.js | 18 ++++++++++++------ 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/__tests__/ResponseConverters.spec.js b/__tests__/ResponseConverters.spec.js index 70c1686..a974859 100644 --- a/__tests__/ResponseConverters.spec.js +++ b/__tests__/ResponseConverters.spec.js @@ -112,7 +112,9 @@ const testCommands = [ rejectCause: undefined, stat: 1, status: 'registered, home network', - tac: 47 + tac: 47, + activeTime: undefined, + periodicTau: undefined } ], [ diff --git a/package-lock.json b/package-lock.json index 7cc54f7..fa1e8c8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -214,7 +214,15 @@ "dev": true, "requires": { "exec-sh": "^0.3.2", - "minimist": ">=1.2.3" + "minimist": "^1.2.0" + }, + "dependencies": { + "minimist": { + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", + "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", + "dev": true + } } }, "@commitlint/cli": { diff --git a/src/api/Registration.js b/src/api/Registration.js index 1fcd3c7..7fc98ca 100644 --- a/src/api/Registration.js +++ b/src/api/Registration.js @@ -4,11 +4,13 @@ const Registration = { DISABLE: 0, ENABLE: 1, ENABLE_WITH_LOCATION: 2, - ENABLE_WITH_LOCATION_AND_CAUSE: 3 + ENABLE_WITH_LOCATION_AND_CAUSE: 3, + ENABLE_4: 4, + ENABLE_5: 5 } -// +CEREG: [,][,,,[,,]] -const expect = /\+C([EG])REG: (?:(\d+),)?(\d+)(?:,"([0-9A-F]{1,4})","([0-9A-F]{1,8})"(?:,(\d)(?:,([^,]*),(.*))?)?)?/ +// +CEREG: [,][,,,[,,[,,]]] +const expect = /\+C([EG])REG: (?:(\d+),)?(\d+)(?:,"([0-9A-F]{1,4})","([0-9A-F]{1,8})"(?:,(\d)(?:,(\d?),(\d*)(?:,"([0-9A-F]{1,8})","([0-9A-F]{1,8})")?)?)?)?/ const Stat = { 0: 'not registered', @@ -24,12 +26,14 @@ const Stat = { function convertResponse (resp) { const r = expect.exec(resp) if (r) { - const [, d, n0, stat0, tac0, ci0, act0, causeType0, rejectCause0] = r + const [, d, n0, stat0, tac0, ci0, act0, causeType0, rejectCause0, activeTime0, periodicTau0] = r const [n, stat, AcT, causeType, rejectCause] = arrayParseInt( [n0, stat0, act0, causeType0, rejectCause0], 10 ) - const tac = parseInt(tac0, 16) - const ci = parseInt(ci0, 16) + const tac = tac0 ? parseInt(tac0, 16) : undefined + const ci = ci0 ? parseInt(ci0, 16) : undefined + const activeTime = activeTime0 ? parseInt(activeTime0, 16) : undefined + const periodicTau = periodicTau0 ? parseInt(periodicTau0, 16) : undefined const domain = { E: 'eps', G: 'gprs' }[d] return { id: 'registration', @@ -42,6 +46,8 @@ function convertResponse (resp) { AcT, causeType, rejectCause, + activeTime, + periodicTau, category: EventCategory.NETWORK, message: `${domain.toUpperCase()} registration: ${Stat[stat]}` }