Skip to main content

Module import

Module import 

Source
Expand description

One entry point for every format HPR Sim reads: give read a file’s bytes, and it recognizes the layout from the content, never the file’s name, and reads it into the record every reader fills (FlightLog).

The layouts it recognizes, the raw downloads by their bytes, the GPS logs by their own marks, the rest by the first line that isn’t blank:

FormatRecognized by
Raven .FIPaits bytes: they open #Component=Raven, and a #den line within the first 4,096 is followed by a frame’s :; told before the file is decoded as text
RRC3 .rffits bytes: an MS-NRBF serialization header, version 1.0, and mDACS’s mDACS.AnalysisSupport+FlightRecord class name within the first 4,096; told before the file is decoded as text
ARTS2 .odfits bytes: the length 9, then Ozark.odf; told before the file is decoded as text
RTx .rtxits bytes: an MS-NRBF serialization header, version 1.0, then the class record of a List<Int32>; told before the file is decoded as text
KMLits root element is kml, after any XML declaration and comments
GPXits root element is gpx, after any XML declaration and comments
NMEA 0183at least 3 of its first 50 lines that aren’t blank open with a sentence whose checksum checks out, such as $GPGGA,…*hh
Featherweight GPS CSVthe first line opens UTCTIME,UNIXTIME, or TRACKER,DATE,TIME, and names the latitude and longitude
Featherweight summary CSVthe first line names Rocket Name, and one of the first 200 names Max Altitude or Launch time UTC
PerfectFlite .pf2names PerfectFlite, such as PerfectFlite Pnut, in a file with no **!!Data: line (a .pfa’s)
PerfectFlite .pfanames PerfectFlite, such as PerfectFlite Alt15K/WD, and has a **!!Data: line
PerfectFlite CSV and textTime, Altitude and more of an export’s names, by commas or tabs; or, with no header row, four tab-separated numbers, the third a temperature ending in F or C, in either case
AltOS CSVstarts #version,, or opens with # comments before a #version, or version,serial, header; or, a table cut from an export, its first line names time, state and state_name and only AltOS’s own columns, and of its first 100 rows one gives a state as AltOS’s exports number and name it, and none contradicts them
Raven FIP CSVopens with a time column and holds the Raven’s Axial Accel (Gs) channel
Blue Raven CSVopens Year,Month,Day,Time,Flight_Time_(s),Sync,, or Flight_Time_(s),Sync, in a file with no date
RRC3 CSVTime, Altitude, Pressure, Velocity, then any of Temperature, Events, Voltages
AltimeterCloud CSVa header within the first 65 lines whose first name is Time(ms), in any case, and which also names acceleration_total(mG) and tilt
Entacore AIM CSVthe first line starts with a time column, names at least two, and names one of the AIM’s own channels, such as Pressure AGL
AltOS .eeproma JSON object naming log_format and product; or, within the first 1,000 lines, a Config version: line and a manufacturer altusmetrum.org line
Blue Raven USB downloadone of the first 1,000 lines opens @ LOG_HIR or @ LOG_LOW and closes with a CRC that checks
Teensy data logger, tab-separatedits first line that isn’t blank is a tag, a whole-number clock and values, by tabs, and one of its first 100 is Alt, the clock, P and a number, MSL and a number
Radio packetsits first line that isn’t blank is a 255:…:254 packet, a whole number or Gain[…], and a packet is one of its first 100
Radio packets in RTFan RTF document, one of whose first 100 lines, its markup taken off, is a 255,…,254 packet
Teensy data logger, named fieldsits first line that isn’t blank states a tag’s units, ICM data in us, …, and one of its first 100 is a tag, t, a clock and name–value pairs, by commas
MARSA downloadits first line that isn’t blank is a <NAME> value setting, such as <BARO_ZERO 0> 790, and one of its first 200 is <MARSA VERSION> and a value
Console capturea start marker, such as ----++++//[[( data start )]]\\++++----, on a line of its own within the first 1,000; refused, naming its blocks, as its records need the caller’s layout (capture::read)
AltOS telemetrythe first line that isn’t blank is TELEM, a space, and an even number of hexadecimal digits
AltOS telemetry CSVthe first line that isn’t blank opens serial,tick,ptype,
R-DAS textthe first line that isn’t blank is *** Configuration ***, and a *** Raw data *** line comes within the first 200
ARTS2 CSVa first line of # and the names MET Acc Vel iAlt pAlt, by spaces, tabs or commas, in any case; tried before AltOS’s # comments
ARTS2 raw CSVthe first line that isn’t blank is MET,Acc(HI),Acc/Baro(LO),Baro(HI),State, the names as written
RTx CSV and textthe first line that isn’t blank is UTC Time,Latitude,Longitude,Altitude,Velocity,VDOP,NavStatus,Sats,SOG,COG, or its tab-separated text file’s UTC, Lat, an empty name, Lon, an empty name, Alt, Vel, VDOP, Nav, Sats, SOG, COG, the names as written
SillyGoose textthe first line, or the one after a CONFIG line, starts with timestampMs and names pressurePa and altitudeM
Silicdyne Fluctus CSVa sep= line, or none, then a header starting time that names deltaTime and baro-altitude
Eggtimer textan Eggtimer … Flight Settings title before an Eggtimer CSV header, within the first 200 lines that aren’t blank
Eggtimer CSVT,Alt, and more of Eggtimer’s column names
A table read by its headertried last: a header row within the first 64 lines, past blank lines, # comments and a sep= line, that names a clock with a unit of time, such as Time (s) or timestamp__ms, followed by a row with a number in the clock’s cell

Text is read as UTF-8, or as UTF-16 after its byte-order mark (decode), with any byte-order mark dropped; a byte that isn’t UTF-8 becomes U+FFFD, as a .pf2’s comments may be in another encoding and no reader uses them.

use hpr_flightdata::{import, log::LogFormat};

let text = "Time,Altitude,Velocity\n0.00,0,0\n0.05,1,8\n0.10,3,30\n";
assert_eq!(import::detect(text.as_bytes()), Some(LogFormat::PerfectFliteCsv));
let log = import::read(text.as_bytes())?;
assert_eq!(log.channels.len(), 2); // the altitude and the velocity; the time is their clock

Constants§

FORMATS
The formats read recognizes, in the order it tries them.

Functions§

decode
A file’s bytes as text: UTF-8, or UTF-16 if the file opens with UTF-16’s byte-order mark, as some mDACS exports of an RRC3’s flight are; any byte-order mark dropped, and a byte, or a pair of them, that isn’t a character replaced by U+FFFD. One such export, among the project’s sample files, opens after its UTF-16 mark with a UTF-8 mark’s three bytes, each written as a UTF-16 character (): they are dropped too, as the mark they are.
detect
The format of a log, recognized from its first line that isn’t blank; None for a layout HPR Sim doesn’t read.
read
Reads a flight log in any format HPR Sim reads.
read_one
Reads one record of a file that may hold several: the sheet sheet of a spreadsheet’s workbook (.xlsx by workbook::read, .xls by xls::read), each sheet read as a file of its own, or the recording recording of an Entacore AIM raw dump (entacore_raw::read_dump), each counted from 0. With no choice, a workbook’s one sheet, or of several the one that reads as a log, or the dump’s one recording. Any other file is read as read reads it, and takes neither choice.