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

fix: unknown proprietary pgns where not being forwarded properly #194

Merged
merged 1 commit into from
Jun 15, 2022
Merged
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
55 changes: 45 additions & 10 deletions lib/fromPgn.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,17 @@ class Parser extends EventEmitter {
pgnList = [ ...customPgns.definitions, ...(pgnList||[]) ]
}

let pgnData = pgnList[0]
let pgnData
let origPGNList = pgnList

if ( pgnList.length > 1 ) {
pgnData = this.findMatchPgn(pgnList)
}

if ( !pgnData ) {
pgnData = pgnList[0]
}

let couldBeMulti = false;

if ( pgnList.length > 0 && len == 8 ) {
Expand Down Expand Up @@ -204,16 +214,29 @@ class Parser extends EventEmitter {
if ( pgnList.length == 0 ) {
//this.emit('warning', pgn, `no conversion found for pgn`)
trace('warning no conversion found for pgn %j', pgn)
const ts = _.get(pgn, 'timestamp', new Date())
pgn.timestamp = _.isDate(ts) ? ts.toISOString() : ts
this.emit('pgn', pgn)
cb && cb(undefined, pgn)
return pgn

let nonMatch = this.findNonMatchPgn(origPGNList)
if ( nonMatch ) {
pgnList = [ nonMatch ]
pgnData = pgnList[0]
fields = pgnData.Fields
var postProcessor = fieldTypePostProcessors[field.Type]
if ( postProcessor ) {
value = postProcessor(pgnData.Fields[i], value)
}
} else {
const ts = _.get(pgn, 'timestamp', new Date())
pgn.timestamp = _.isDate(ts) ? ts.toISOString() : ts
this.emit('pgn', pgn)
cb && cb(undefined, pgn)
return pgn
}
} else {
pgnData = pgnList[0]
fields = pgnData.Fields
//console.log(`using ${JSON.stringify(pgnData, null, 2)}`)
value = pgnData.Fields[i].Description
}
pgnData = pgnList[0]
fields = pgnData.Fields
//console.log(`using ${JSON.stringify(pgnData, null, 2)}`)
value = pgnData.Fields[i].Description
}

if ( !_.isUndefined(value) && value != null ) {
Expand Down Expand Up @@ -260,6 +283,18 @@ class Parser extends EventEmitter {
}
}

findNonMatchPgn(pgnList) {
return pgnList.find(f => {
return !f.Fields.find(f => !_.isUndefined(f.Match))
})
}

findMatchPgn(pgnList) {
return pgnList.find(f => {
return f.Fields.find(f => !_.isUndefined(f.Match))
})
}

parse(data, cb) {
if (_.isString(data) ) {
return this.parseString(data, cb)
Expand Down