@rflafla/motec-ld-reader
v1.0.1
Published
A Node.js library for reading MoTeC .ld telemetry files
Maintainers
Readme
MoTeC LD File Reader
A Node.js library for reading MoTeC .ld telemetry files. This library allows you to parse and extract data from MoTeC data logging files commonly used in motorsports and automotive testing.
Features
- Parse MoTeC .ld files
- Access session metadata (driver, vehicle, venue, datetime, etc.)
- Read channel data (speed, RPM, temperature, etc.)
- Support for multiple data types (int16, int32, float16, float32)
- TypeScript support with full type definitions
- Lazy loading of channel data for efficient memory usage
Installation
npm install
npm run buildUsage
Basic Example
import { LdData } from 'motec-ld-reader';
// Read an .ld file
const data = LdData.fromFile('path/to/file.ld');
// Access metadata
console.log(`Driver: ${data.head.driver}`);
console.log(`Vehicle: ${data.head.vehicleId}`);
console.log(`Date: ${data.head.datetime}`);
console.log(`Venue: ${data.head.venue}`);
// List all channels
console.log('\nAvailable channels:');
data.getChannelNames().forEach(name => {
console.log(` - ${name}`);
});
// Access a specific channel by name
const speedChannel = data.getChannel('Ground Speed');
console.log(`\nSpeed channel:`);
console.log(` Name: ${speedChannel.name}`);
console.log(` Unit: ${speedChannel.unit}`);
console.log(` Frequency: ${speedChannel.freq} Hz`);
console.log(` Data points: ${speedChannel.data.length}`);
// Access channel data
const speeds = speedChannel.data;
console.log(` Max speed: ${Math.max(...speeds)} ${speedChannel.unit}`);
console.log(` Avg speed: ${speeds.reduce((a, b) => a + b, 0) / speeds.length} ${speedChannel.unit}`);Access Channels by Index
// Access channels by numeric index
const firstChannel = data.getChannel(0);
console.log(firstChannel.name);
// Iterate over all channels
for (let i = 0; i < data.channelCount; i++) {
const channel = data.getChannel(i);
console.log(`${i}: ${channel.name} (${channel.unit})`);
}Export to JSON
// Convert to a plain object for JSON serialization
const dataObject = data.toObject();
console.log(JSON.stringify(dataObject, null, 2));
// Or just get the data as a map
const dataMap = data.toDataMap();
console.log(dataMap['Ground Speed']);Working with Channel Data
// Get multiple channels
const rpm = data.getChannel('Engine RPM').data;
const throttle = data.getChannel('Throttle Pos').data;
const speed = data.getChannel('Ground Speed').data;
// Perform calculations
for (let i = 0; i < Math.min(rpm.length, throttle.length); i++) {
if (throttle[i] > 80) {
console.log(`Full throttle at ${i}s: ${speed[i]} km/h, ${rpm[i]} RPM`);
}
}Channel Information
Each channel provides the following properties:
name: Full channel nameshortName: Abbreviated nameunit: Unit of measurementfreq: Sample frequency in Hzdata: Array of data values (lazy loaded)dataLen: Number of data points
Metadata Access
// Event information
if (data.head.event) {
console.log(`Event: ${data.head.event.name}`);
console.log(`Session: ${data.head.event.session}`);
console.log(`Comment: ${data.head.event.comment}`);
// Venue information
if (data.head.event.venue) {
console.log(`Venue: ${data.head.event.venue.name}`);
// Vehicle information
if (data.head.event.venue.vehicle) {
const vehicle = data.head.event.venue.vehicle;
console.log(`Vehicle ID: ${vehicle.id}`);
console.log(`Vehicle Type: ${vehicle.type}`);
console.log(`Weight: ${vehicle.weight}`);
}
}
}API Reference
LdData
Main class for reading .ld files.
Methods
static fromFile(filePath: string): LdData- Read and parse an .ld filegetChannel(nameOrIndex: string | number): LdChan- Get a channel by name or indexgetChannelNames(): string[]- Get all channel namestoObject()- Convert to plain object for serializationtoDataMap(): Record<string, number[]>- Get channel data as name-to-data map
Properties
head: LdHead- Header/metadata informationchannels: LdChan[]- Array of all channelschannelCount: number- Number of channels
LdHead
Header information containing metadata about the recording session.
Properties
driver: stringvehicleId: stringvenue: stringdatetime: DateshortComment: stringevent: LdEvent | null
LdChan
Channel data and metadata.
Properties
name: string- Full channel nameshortName: string- Abbreviated nameunit: string- Unit of measurementfreq: number- Sample frequency in Hzdata: number[]- Data array (lazy loaded)dataLen: number- Number of data pointsdtype: DataType- Data type ('int16' | 'int32' | 'float16' | 'float32')
File Format
The .ld file format is a binary format used by MoTeC data loggers. The library handles:
- File header with session metadata
- Event, venue, and vehicle information
- Channel metadata (linked list structure)
- Binary channel data with various numeric types
- Data scaling and conversion formulas
Development
# Install dependencies
npm install
# Build the project
npm run build
# Watch mode for development
npm run watchLicense
MIT
Credits
This library was created through reverse engineering the MoTeC .ld file format. It is not officially affiliated with MoTeC.
