start work on lora ingest app
All checks were successful
Build Docker containers / Build (push) Successful in 16s
All checks were successful
Build Docker containers / Build (push) Successful in 16s
This commit is contained in:
61
lora/MeshtasticStream.js
Normal file
61
lora/MeshtasticStream.js
Normal file
@ -0,0 +1,61 @@
|
||||
import { Transform } from 'stream';
|
||||
import { Mesh, Channel, Config, ModuleConfig } from '@meshtastic/protobufs';
|
||||
import { fromBinary, create } from '@bufbuild/protobuf';
|
||||
|
||||
export class MeshtasticStream extends Transform {
|
||||
constructor(options) {
|
||||
super({ readableObjectMode: true, ...options });
|
||||
}
|
||||
_transform(chunk, encoding, callback) {
|
||||
const dataPacket = fromBinary(Mesh.FromRadioSchema, chunk);
|
||||
let schema = null;
|
||||
switch(dataPacket.payloadVariant.case) {
|
||||
case 'packet':
|
||||
schema = Mesh.MeshPacketSchema;
|
||||
break;
|
||||
case 'nodeInfo':
|
||||
schema = Mesh.NodeInfoSchema;
|
||||
break;
|
||||
case 'myInfo':
|
||||
schema = Mesh.MyNodeInfoSchema;
|
||||
break;
|
||||
case 'deviceuiConfig':
|
||||
// can't find, come back to this
|
||||
break;
|
||||
case 'config':
|
||||
// todo: config has another payloadVariant within it
|
||||
schema = Config.ConfigSchema
|
||||
break;
|
||||
case 'moduleConfig':
|
||||
// todo: config has another payloadVariant within it
|
||||
schema = ModuleConfig.ModuleConfigSchema
|
||||
break;
|
||||
case 'fileInfo':
|
||||
schema = Mesh.FileInfoSchema
|
||||
break;
|
||||
case 'channel':
|
||||
schema = Channel.ChannelSchema
|
||||
break;
|
||||
case 'metadata':
|
||||
schema = Mesh.DeviceMetadataSchema
|
||||
break;
|
||||
case 'configCompleteId':
|
||||
// done sending init data
|
||||
break;
|
||||
}
|
||||
if (schema !== null) {
|
||||
this.push(create(schema, dataPacket.payloadVariant.value));
|
||||
}
|
||||
callback();
|
||||
}
|
||||
_flush(callback) {
|
||||
try {
|
||||
if (this._buffer) {
|
||||
this.push(this._buffer.trim());
|
||||
}
|
||||
callback();
|
||||
} catch (err) {
|
||||
callback(err);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user