mf4

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 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)
	if err != nil {
		panic(err)
	}
	// 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())

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

}

Features

  • Parse MF4 file format and load metadata
  • Extract channel sample data
  • Support for attachments
  • Support for Events
  • Access to common metadata fields
  • Documentation
  • API 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 *DG.Block

	// 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
	// contains filtered or unexported fields
}

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
}

type MF4

type MF4 struct {
	File           *os.File
	Header         *HD.Block
	Identification *ID.Block
	//Address to First File History Block
	FileHistory  int64
	ChannelGroup []*ChannelGroup
	Channels     []*Channel
}

func ReadFile

func ReadFile(file *os.File) (*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

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

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

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

type VersionError struct {
}

func (*VersionError) Error

func (e *VersionError) Error() string

Directories

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

Jump to

Keyboard shortcuts

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