Skip to content
This repository has been archived by the owner on Oct 3, 2022. It is now read-only.

Commit

Permalink
feat: extended CEREG regex to support newer levels
Browse files Browse the repository at this point in the history
  • Loading branch information
bencefr committed Nov 16, 2020
1 parent 6ba8992 commit 5eacf4f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
4 changes: 3 additions & 1 deletion __tests__/ResponseConverters.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ const testCommands = [
rejectCause: undefined,
stat: 1,
status: 'registered, home network',
tac: 47
tac: 47,
activeTime: undefined,
periodicTau: undefined
}
],
[
Expand Down
10 changes: 9 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 12 additions & 6 deletions src/api/Registration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [<n>,]<stat>[,<tac>,<ci>,<AcT>[,<cause_type>,<reject_cause>]]
const expect = /\+C([EG])REG: (?:(\d+),)?(\d+)(?:,"([0-9A-F]{1,4})","([0-9A-F]{1,8})"(?:,(\d)(?:,([^,]*),(.*))?)?)?/
// +CEREG: [<n>,]<stat>[,<tac>,<ci>,<AcT>[,<cause_type>,<reject_cause>[,<Active-Time>,<Periodic-TAU>]]]
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',
Expand All @@ -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',
Expand All @@ -42,6 +46,8 @@ function convertResponse (resp) {
AcT,
causeType,
rejectCause,
activeTime,
periodicTau,
category: EventCategory.NETWORK,
message: `${domain.toUpperCase()} registration: ${Stat[stat]}`
}
Expand Down

0 comments on commit 5eacf4f

Please sign in to comment.