mf4

package module
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2024 License: MIT Imports: 24 Imported by: 0

README

GoMDF - Read and Write ASAM MF4 FILES

Go package for reading ASAM MF4 files.

Installation

⚠️ The package not finalized !!! ⚠️

go get github.com/LincolnG4/GoMDF

Usage

package main

import (
	"fmt"
	"os"

	mf4 "github.com/LincolnG4/GoMDF"
)

func main() {
	file, err := os.Open("sample1.mf4")
	if err != nil {
		panic(err)
	}

	m, err := mf4.ReadFile(file, &mf4.ReadOptions{})
	if err != nil {
		panic(err)
	}


	fmt.Println()
	// Get channel samples
	channels := m.ListAllChannels()

	for _, channel := range channels {
		samples, err := channel.Sample()
		if err != nil {
			panic(err)
		}

		fmt.Println(samples[:10])
	}

	sample, err := m.GetChannelSample(2, "EngTripFuel")
	if err != nil {
		panic(err)
	}
	fmt.Println(sample[:10])
	// Download attachments
	//att := m.GetAttachments()[0]
	//m.SaveAttachmentTo(att, "/PATH/TO/BE/SAVE/")

	// Read Change logs
	// m.ReadChangeLog()
	// Access metadata
	fmt.Println(m.Version())
	fmt.Println("Version ID --> ", m.MdfVersion())
	fmt.Println("Start Time NS --> ", m.GetStartTimeNs())
	fmt.Println("Start StartTimeLT --> ", m.GetStartTimeLT())
	fmt.Println()
	fmt.Println("List Names -->", m.ListAllChannelsNames())
	fmt.Println("Mapped Channels -->", m.MapAllChannels())
}

Features

  • Parse MF4 file format and load metadata
  • Extract channel sample data
  • Support for attachments
  • Support for Events
  • Access to common metadata fields
  • Documentation
  • Documentation is available at https://godoc.org/github.com/LincolnG4/GoMDF

Contributing

Pull requests are welcome! Please open any issues.

This provides a high-level overview of how to use the package from Go code along with installation instructions. Let me know if any part of the README explanation could be improved!

References

ASAM MDF
MDF Validator

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Channel

type Channel struct {
	//channel's name
	Name string

	//conversion formula to convert the raw values to physical values with a
	//physical unit
	Conversion CC.Conversion

	//channel type
	Type string

	//pointer to the master channel of the channel group.
	//A 'nil' value indicates that this channel itself is the master.
	Master *Channel

	//pointer to data group
	DataGroup *DataGroup

	//data group's index
	DataGroupIndex int

	//pointer to channel group
	ChannelGroup *CG.Block

	//channel group's index
	ChannelGroupIndex int

	//describes the source of an acquisition mode or of a signal
	SourceInfo SI.SourceInfo

	//additional information about the channel. Can be 'nil'
	Comment string

	//Samples are cached in memory if file was set with MemoryOptimized is true
	CachedSamples []interface{}
	// contains filtered or unexported fields
}

func (*Channel) LoadDataAdress added in v1.1.2

func (c *Channel) LoadDataAdress()

func (*Channel) RawSample

func (c *Channel) RawSample() ([]interface{}, error)

RawSample returns a array with the measures of the channel not applying conversion block on it

func (*Channel) Sample

func (c *Channel) Sample() ([]interface{}, error)

Sample returns a array with the measures of the channel applying conversion block on it

type ChannelGroup

type ChannelGroup struct {
	Block       *CG.Block
	Channels    map[string]*Channel
	DataGroup   *DG.Block
	SourceInfo  SI.SourceInfo
	Comment     string
	IsVLSDBlock bool
}

type ChannelReader added in v1.1.1

type ChannelReader struct {
	//Byte order conversion (LittleEndian/BigEndian)
	ByteOrder binary.ByteOrder

	//Number of bits per row
	SizeMeasureRow int64

	DataType interface{}

	DataAddress int64

	MeasureBuffer []byte

	//Length of the row in block
	RowSize int64

	//Offset in the row
	StartOffset int64
}

type DataGroup added in v1.1.0

type DataGroup struct {
	ChannelGroup    []*ChannelGroup
	CachedDataGroup []byte
	// contains filtered or unexported fields
}

func NewDataGroup added in v1.1.0

func NewDataGroup(f *os.File, address int64) DataGroup

func (*DataGroup) DataAddress added in v1.1.2

func (d *DataGroup) DataAddress() int64

type MF4

type MF4 struct {
	File           *os.File
	Header         *HD.Block
	Identification *ID.Block

	//Address to First File History Block
	FileHistory int64

	DataGroups   []DataGroup
	ChannelGroup []ChannelGroup
	Channels     []Channel

	//Unsorted
	UnsortedBlocks []*UnsortedBlock

	ReadOptions *ReadOptions
}

func ReadFile

func ReadFile(file *os.File, readOptions *ReadOptions) (*MF4, error)

func (*MF4) CreatedBy

func (m *MF4) CreatedBy() string

CreatedBy method returns the MDF Program identifier

func (*MF4) DaylightOffsetMin

func (m *MF4) DaylightOffsetMin(tFlag uint8) (int16, error)

Daylight saving time (DST) offset in minutes for the starting timestamp. During the summer months, many regions observe a DST offset of 60 minutes (1 hour).

func (*MF4) GetAttachments

func (m *MF4) GetAttachments() ([]AT.AttFile, error)

GetAttachmemts iterates over all AT blocks and return to an array

func (*MF4) GetChannelSample

func (m *MF4) GetChannelSample(indexDataGroup int, channelName string) ([]interface{}, error)

GetChannelSample loads sample based DataGroupName and ChannelName

func (*MF4) GetMeasureComment

func (m *MF4) GetMeasureComment() string

func (*MF4) GetStartTimeLT

func (m *MF4) GetStartTimeLT() time.Time

func (*MF4) GetStartTimeNs

func (m *MF4) GetStartTimeNs() int64

StartTimeNs returns the start timestamp of measurement in nanoseconds

func (*MF4) GetTimeNs

func (m *MF4) GetTimeNs(t uint64, tzo uint64, dlo uint64, tf uint8) int64

func (*MF4) ID

func (m *MF4) ID() string

ID method returns the MDF file ID

func (*MF4) IsFinalized

func (m *MF4) IsFinalized() bool

isUnfinalized method returns Standard flags for unfinalized MDF

func (*MF4) IsMemoryOptimized added in v1.1.2

func (m *MF4) IsMemoryOptimized() bool

GetAttachmemts iterates over all AT blocks and return to an array

func (*MF4) ListAllChannels

func (m *MF4) ListAllChannels() []Channel

ListAllChannelsNames returns an slice with all channels from the MF4 file

func (*MF4) ListAllChannelsFromDataGroup

func (m *MF4) ListAllChannelsFromDataGroup(datagroupIndex int) ([]*Channel, error)

ListAllChannels returns an slice with all channels from the MF4 file

func (*MF4) ListAllChannelsNames

func (m *MF4) ListAllChannelsNames() []string

ListAllChannels returns an slice with all channels from the MF4 file

func (*MF4) ListEvents

func (m *MF4) ListEvents() []*EV.Event

loadEvents loads and processes events from the given MF4 instance. Events are represented by EVBLOCK structures, providing synchronization details. The function iterates through the linked list of events, creating EV instances and handling event details such as names, comments, and scopes. If file has no events or errors occur during EV instance creation, it will return `nil`.

func (*MF4) MapAllChannels

func (m *MF4) MapAllChannels() map[int]Channel

MapAllChannels returns an map with all channels from the MF4 file group by data group

func (*MF4) MapAllChannelsNames

func (m *MF4) MapAllChannelsNames() map[int]string

MapAllChannelsNames returns an map with all channels from the MF4 file group by data group

func (*MF4) MdfVersion

func (m *MF4) MdfVersion() uint16

VersionNumber method returns the Version number of the MDF format, i.e. 420

func (*MF4) ReadChangeLog

func (m *MF4) ReadChangeLog() []string

ReadChangeLog reads and prints the change log entries from the MF4 file. The change log is stored in FHBLOCK structures, each representing a change made to the MDF file. The function iterates through the linked list of FHBLOCKs starting from the first one referenced by the HDBLOCK, printing the chronological change history.

Parameters:

m: A pointer to the MF4 instance containing the file change log.

func (*MF4) SaveAttachmentTo

func (m *MF4) SaveAttachmentTo(attachment AT.AttFile, outputPath string) AT.AttFile

Saves attachment file input to output path

func (*MF4) Sort added in v1.1.0

func (m *MF4) Sort(us UnsortedBlock) error

Sort is applied for unsorted files.

func (*MF4) StartAngleRad

func (m *MF4) StartAngleRad() (float64, error)

Start angle in radians at the beginning of the measurement serves as the reference point for angle synchronous measurements.

func (*MF4) StartDistanceM

func (m *MF4) StartDistanceM() (float64, error)

Start distance in meters in meters at the beginning of the measurement serves as the reference point for distance synchronous measurements.

func (*MF4) TimezoneOffsetMin

func (m *MF4) TimezoneOffsetMin(tzo int16, timeFlag uint8) (int16, error)

Time zone offset in minutes. Range (-840, 840) minutes. For instance, a value of 60 minutes implies UTC+1 time zone, corresponding to Central European Time (CET).

func (*MF4) Version

func (m *MF4) Version() string

Version method returns the MDF file version

type ReadOptions added in v1.1.0

type ReadOptions struct {
	// MemoryOptimized indicates whether to store data in memory or use
	// file-based storage.
	// Default is false, measures are cached in memory, which can improve
	// performance by avoiding file I/O operations but may increase memory usage
	// , particularly with large datasets.
	//
	// If true, measures are saved to a file or re-read as needed. This approach
	// helps manage memory usage more effectively by offloading data to disk,
	// making it suitable for very large datasets that might exceed available
	// memory
	MemoryOptimized bool
}

type UnsortedBlock added in v1.1.0

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

type VersionError

type VersionError struct {
}

func (*VersionError) Error

func (e *VersionError) Error() string

Directories

Path Synopsis
AT
CA
CC
CG
CN
DG
DL
DT
DZ
EV
FH
HD
HL
ID
MD
SD
SI
SR
TX

Jump to

Keyboard shortcuts

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