Skip to content

Commit

Permalink
feature: add log2sk utility
Browse files Browse the repository at this point in the history
Add utility to convert multiplexed log file to
SK deltas.
  • Loading branch information
tkurki committed Jul 4, 2018
1 parent 16bcddd commit 618c51e
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
59 changes: 59 additions & 0 deletions bin/log2sk
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env node

const Simple = require('../providers/simple')

let handleMessage = (id, delta) => {
console.log(JSON.stringify(delta))
}

if (process.argv[3]) {
const paths = JSON.parse(process.argv[3])
const outValues = [paths.length]
handleMessage = (id, delta) => {
delta.updates &&
delta.updates.forEach(update => {
update.values &&
update.values.forEach(pathValue => {
const index = paths.indexOf(pathValue.path)
if (index >= 0) {
outValues[index] = pathValue.value
console.log(outValues.join(';'))
}
})
})
}
}

const app = {
config: {
configPath: __dirname
},
signalk: {
emit: () => {}
},
emit: () => {},
handleMessage
}

const createPipedProvider = new require('../lib/pipedproviders')(app)
.createPipedProvider

createPipedProvider({
pipeElements: [
{
type: 'providers/Simple',
options: {
logging: false,
noThrottle: true,
type: 'FileStream',
subOptions: {
dataType: 'Multiplexed',
filename: process.argv[2],
noThrottle: true,
keepRunning: false
},
app
}
}
]
})
3 changes: 2 additions & 1 deletion lib/pipedproviders.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ module.exports = function (app) {
}

return (api = {
start: startProviders
start: startProviders,
createPipedProvider: createPipedProvider
})
}

0 comments on commit 618c51e

Please sign in to comment.