Documentation ¶
Index ¶
- Constants
- Variables
- func ApplyPrediction(frameDef LogDefinition, values []int64, fieldIndex int, predictor int, ...) (int64, error)
- type ErrorFrame
- type Errorer
- type EventFrame
- type FieldDefinition
- type FieldName
- type FlightLogReader
- type FlightLogReaderOpts
- type Frame
- type FrameReader
- type FrameReaderOptions
- type FrameStatistics
- type Header
- type HeaderName
- type HeaderReader
- type LogDefinition
- type LogEventType
- type LogFrameType
- type LogStatistics
- type MainFrame
- type Sizer
- type SlowFrame
- type SysconfigType
- type Validater
Constants ¶
const ( // See https://cleanflight.readthedocs.io/en/stable/development/Blackbox%20Internals/ LogFrameEvent LogFrameType = 69 // E LogFrameIntra = 73 // I LogFrameInter = 80 // P LogFrameSlow = 83 // S LogFrameHeader = 72 // H LogFrameGPS = 71 // G )
const ( LogEventSyncBeep LogEventType = 0 LogEventInflightAdjustment = 13 LogEventLoggingResume = 14 LogEventFlightMode = 30 LogEventLogEnd = 255 )
const ( // EncodingSignedVB is for signed variable-byte EncodingSignedVB = 0 // EncodingUnsignedVB is for Unsigned variable-byte EncodingUnsignedVB = 1 // EncodingNeg14Bits is for Unsigned variable-byte but we negate the value before storing value is 14 bits EncodingNeg14Bits = 3 // EncodingTag8_8SVB is for First, an 8-bit (one byte) header is written. This header has its bits set to zero when the corresponding field (from a maximum of 8 fields) is set to zero, otherwise the bit is set to one. EncodingTag8_8SVB = 6 // EncodingTag2_3S32 is for a 2-bit header is written, followed by 3 signed field values of up to 32 bits each. EncodingTag2_3S32 = 7 // EncodingTag8_4S16 is for an 8-bit header is written, followed by 4 signed field values of up to 16 bits each. EncodingTag8_4S16 = 8 // EncodingNull is for nothing is written to the file take value to be zero EncodingNull = 9 )
const ( // PredictorZero returns the value unmodified PredictorZero = 0 // PredictorPrevious return the value substracted from the interframe PredictorPrevious = 1 // PredictorStraightLine assumes that the slope between the current measurement and the previous one will be similar to the slope between the previous measurement and the one before that. // This is common for fields which increase at a steady rate, such as the "time" field. The predictor is `history_age_2 - 2 * history_age_1`. PredictorStraightLine = 2 // PredicatorAverage2 is the average of the two previously logged values of the field (i.e. `(history_age_1 + history_age_2) / 2`). // It is used when there is significant random noise involved in the field, which means that the average of the recent history is a better predictor of the next value than the previous value on its own would be (for example, in gyroscope or motor measurements). PredicatorAverage2 = 3 // PredictorMinThrottle subtracts the value of "minthrottle" which is included in the log header. // In Cleanflight, motors always lie in the range of `[minthrottle ... maxthrottle]` when the craft is armed, so this predictor is used for the first motor value in intraframes. PredictorMinThrottle = 4 // PredictorMotor0 is set to the value of `motor[0]` which was decoded earlier within the current frame. // It is used in intraframes for every motor after the first one, because the motor commands typically lie in a tight grouping. PredictorMotor0 = 5 // PredictorInc assumes that the field will be incremented by 1 unit for every main loop iteration. This is used to predict the `loopIteration` field, which increases by 1 for every loop iteration. PredictorInc = 6 // Predictor1500 is set to a fixed value of 1500. // It is preferred for logging servo values in intraframes, since these typically lie close to the midpoint of 1500us. Predictor1500 = 8 // PredictorVbatRef is set to the "vbatref" field written in the log header. // It is used when logging intraframe battery voltages in Cleanflight, since these are expected to be broadly similar to the first battery voltage seen during arming. PredictorVbatRef = 9 // PredictorMinMotor returns the value and the minimum motor low output summed PredictorMinMotor = 11 )
Variables ¶
var LogFrameAllTypes = []byte{ LogFrameEvent, LogFrameIntra, LogFrameInter, LogFrameSlow, LogFrameHeader, LogFrameGPS, }
Functions ¶
Types ¶
type ErrorFrame ¶
type ErrorFrame struct {
// contains filtered or unexported fields
}
ErrorFrame represents a frame that couldn't be recognized
func NewErrorFrame ¶
func NewErrorFrame(values []byte, start, end int64, err error) *ErrorFrame
func (ErrorFrame) Start ¶
func (f ErrorFrame) Start() int
Start returns the Start in bytes of a Frame
func (ErrorFrame) Type ¶
func (f ErrorFrame) Type() LogFrameType
type Errorer ¶
type Errorer interface { // Error returns error which happened during reading/parsing the frame, or nil Error() error // contains filtered or unexported methods }
type EventFrame ¶
type EventFrame struct {
// contains filtered or unexported fields
}
func NewEventFrame ¶
func NewEventFrame(eventType LogEventType, values eventValues, start, end int64, err error) *EventFrame
func (EventFrame) EventType ¶
func (f EventFrame) EventType() LogEventType
func (EventFrame) Start ¶
func (f EventFrame) Start() int
Start returns the Start in bytes of a Frame
func (EventFrame) String ¶
func (f EventFrame) String() string
func (EventFrame) Type ¶
func (f EventFrame) Type() LogFrameType
func (EventFrame) Values ¶
func (f EventFrame) Values() interface{}
type FieldDefinition ¶
type FieldDefinition struct { Name FieldName Signed bool Predictor int64 Encoding int64 GroupCount int }
FieldDefinition represents a field
type FieldName ¶
type FieldName string
FieldName is the type for main frame fields
const ( FieldIteration FieldName = "loopIteration" FieldTime FieldName = "time" FieldVbatLatest FieldName = "vbatLatest" FieldAmperageLatest FieldName = "amperageLatest" FieldEnergyCumulative FieldName = "energyCumulative" FieldFlightModeFlags FieldName = "flightModeFlags" FieldStateFlags FieldName = "stateFlags" FieldFailsafePhase FieldName = "failsafePhase" FieldMotor0 FieldName = "motor[0]" )
List of all the fields used by the library
type FlightLogReader ¶
type FlightLogReader struct { FrameDef LogDefinition Stats *LogStatistics // contains filtered or unexported fields }
FlightLogReader parses logs generated by the CleanFlight controller
func NewFlightLogReader ¶
func NewFlightLogReader(opts FlightLogReaderOpts) *FlightLogReader
NewFlightLogReader returns a new FlightLogReader
type FlightLogReaderOpts ¶
type FlightLogReaderOpts struct {
Raw bool
}
FlightLogReaderOpts holds the options to get a new FlightLogReader
type Frame ¶
type Frame interface { Type() LogFrameType Values() interface{} Sizer Errorer Validater }
type FrameReader ¶
type FrameReader struct {
// contains filtered or unexported fields
}
FrameReader reads and decodes data frame
func NewFrameReader ¶
func NewFrameReader(dec *stream.Decoder, frameDef LogDefinition, opts *FrameReaderOptions) *FrameReader
NewFrameReader returns a new FrameReader
func (*FrameReader) ReadNextFrame ¶
func (f *FrameReader) ReadNextFrame() Frame
ReadNextFrame reads the next frame
type FrameReaderOptions ¶
type FrameReaderOptions struct {
Raw bool
}
FrameReaderOptions holds the options to create a new FrameReader
type FrameStatistics ¶
type FrameStatistics struct { ValidCount int Bytes int64 CorruptCount int DesyncCount int SizeCount map[int]int }
FrameStatistics represents stats for one type of frame
type HeaderName ¶
type HeaderName string
HeaderName is the type for flight recorder headers
const ( HeaderProduct HeaderName = "Product" HeaderDataVersion HeaderName = "Data version" HeaderIName HeaderName = "Field I name" HeaderISigned HeaderName = "Field I signed" HeaderIPredictor HeaderName = "Field I predictor" HeaderIEncoding HeaderName = "Field I encoding" HeaderPPredictor HeaderName = "Field P predictor" HeaderPEncoding HeaderName = "Field P encoding" HeaderSName HeaderName = "Field S name" HeaderSSigned HeaderName = "Field S signed" HeaderSPredictor HeaderName = "Field S predictor" HeaderSEncoding HeaderName = "Field S encoding" HeaderVbatref HeaderName = "vbatref" HeaderVbatcellvoltage HeaderName = "vbatcellvoltage" HeaderCurrentMeter HeaderName = "currentMeter" HeaderMotorOutput HeaderName = "motorOutput" HeaderFirmwareType HeaderName = "Firmware type" HeaderIInterval HeaderName = "I interval" HeaderPInterval HeaderName = "P interval" )
List of all the headers used by the library
type HeaderReader ¶
type HeaderReader struct {
// contains filtered or unexported fields
}
HeaderReader reads the headers of a log file
func NewHeaderReader ¶
func NewHeaderReader(enc *stream.Decoder) HeaderReader
NewHeaderReader returns a new HeaderReader
func (*HeaderReader) ProcessHeaders ¶
func (h *HeaderReader) ProcessHeaders() (LogDefinition, error)
ProcessHeaders process all the headers and returns the format of the data to come
type LogDefinition ¶
type LogDefinition struct { Product string DataVersion int LogStartDatetime string CraftName string FieldsS []FieldDefinition FieldsI []FieldDefinition FieldsP []FieldDefinition Headers []Header Sysconfig SysconfigType FieldIRL map[FieldName]int }
LogDefinition represents a log
func (*LogDefinition) GetFieldIndex ¶
func (f *LogDefinition) GetFieldIndex(fieldName FieldName) (int, error)
GetFieldIndex returns the position of a field
func (*LogDefinition) GetHeaderValue ¶
func (f *LogDefinition) GetHeaderValue(headerName HeaderName) (string, error)
GetHeaderValue returns the value of a header
type LogEventType ¶
type LogEventType = byte
type LogFrameType ¶
type LogFrameType = byte
type LogStatistics ¶
type LogStatistics struct { TotalCorruptedFrames int NonParsableFrames int IntentionallyAbsentIterations int TotalFrames int Frame map[LogFrameType]*FrameStatistics Bytes int HeaderBytes int CorruptedBytes int Start time.Time End time.Time }
LogStatistics represents global stats
func NewLogStatistics ¶
func NewLogStatistics() *LogStatistics
NewLogStatistics returns an initialized LogStatistic struct
func (LogStatistics) String ¶
func (s LogStatistics) String() string
type MainFrame ¶
type MainFrame struct {
// contains filtered or unexported fields
}
Frame represents a frame
func NewMainFrame ¶
func NewMainFrame(frameType LogFrameType, values []int64, start, end int64, err error) *MainFrame
NewFrame returns a new frame
func (MainFrame) Type ¶
func (f MainFrame) Type() LogFrameType
type SlowFrame ¶
type SlowFrame struct {
// contains filtered or unexported fields
}
SlowFrame represents a slow frame
func NewSlowFrame ¶
NewSlowFrame returns a new frame
func (SlowFrame) StringValues ¶
func (SlowFrame) Type ¶
func (f SlowFrame) Type() LogFrameType
type SysconfigType ¶
type SysconfigType struct { MinThrottle int MaxThrottle int MotorOutputLow int MotorOutputHigh int RcRate uint YawRate uint Acc1G uint16 GyroScale float64 Vbatscale uint8 Vbatmaxcellvoltage uint8 Vbatmincellvoltage uint8 Vbatwarningcellvoltage uint8 CurrentMeterOffset uint16 CurrentMeterScale uint16 Vbatref uint16 FirmwareType string FrameIntervalI int FrameIntervalPNum int FrameIntervalPDenom int }
SysconfigType represents a sysconfig