blackbox

package
v0.0.0-...-22a2ae8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 4, 2019 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
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
)
View Source
const (
	LogEventSyncBeep           LogEventType = 0
	LogEventInflightAdjustment              = 13
	LogEventLoggingResume                   = 14
	LogEventFlightMode                      = 30
	LogEventLogEnd                          = 255
)
View Source
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
)
View Source
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

Functions

func ApplyPrediction

func ApplyPrediction(frameDef LogDefinition, values []int64, fieldIndex int, predictor int, value int64, previous *MainFrame, previous2 *MainFrame) (int64, error)

ApplyPrediction a predictor on a field and return the resulting value

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) Error

func (f ErrorFrame) Error() error

func (ErrorFrame) Size

func (f ErrorFrame) Size() int

Size returns the size in bytes of a Frame

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

func (ErrorFrame) Validity

func (f ErrorFrame) Validity() bool

func (ErrorFrame) Values

func (f ErrorFrame) Values() interface{}

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) Error

func (f EventFrame) Error() error

func (EventFrame) EventType

func (f EventFrame) EventType() LogEventType

func (EventFrame) Size

func (f EventFrame) Size() int

Size returns the size in bytes of a Frame

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) Validity

func (f EventFrame) Validity() bool

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

func (*FlightLogReader) LoadFile

func (f *FlightLogReader) LoadFile(ctx context.Context, file io.Reader) (<-chan Frame, error)

LoadFile reads flight logs from a file. Accepts context and stops processing when the context is canceled. Returns channel with successfully parsed frames.

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 Header struct {
	Name  HeaderName
	Value string
}

Header represents a header value

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) Error

func (f MainFrame) Error() error

func (MainFrame) Size

func (f MainFrame) Size() int

Size returns the size in bytes of a Frame

func (MainFrame) Start

func (f MainFrame) Start() int

Start returns the Start in bytes of a Frame

func (MainFrame) Type

func (f MainFrame) Type() LogFrameType

func (MainFrame) Validity

func (f MainFrame) Validity() bool

func (MainFrame) Values

func (f MainFrame) Values() interface{}

type Sizer

type Sizer interface {
	Size() int
	Start() int
}

type SlowFrame

type SlowFrame struct {
	// contains filtered or unexported fields
}

SlowFrame represents a slow frame

func NewSlowFrame

func NewSlowFrame(values []int64, start, end int64, err error) *SlowFrame

NewSlowFrame returns a new frame

func (SlowFrame) Error

func (f SlowFrame) Error() error

func (SlowFrame) Size

func (f SlowFrame) Size() int

Size returns the size in bytes of a Frame

func (SlowFrame) Start

func (f SlowFrame) Start() int

Start returns the Start in bytes of a Frame

func (SlowFrame) String

func (f SlowFrame) String() string

func (SlowFrame) StringValues

func (f SlowFrame) StringValues() []string

func (SlowFrame) Type

func (f SlowFrame) Type() LogFrameType

func (SlowFrame) Validity

func (f SlowFrame) Validity() bool

func (SlowFrame) Values

func (f SlowFrame) Values() interface{}

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

type Validater

type Validater interface {
	Validity() bool
	// contains filtered or unexported methods
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL