|
@@ -18,7 +18,7 @@ const (
|
|
|
type VoltloggerDumpRawHeader struct {
|
|
|
Version byte
|
|
|
Magic [11]byte
|
|
|
- Modificators byte // Bit: 1 — NoClock; 2 — Bitness8ADC; the rest is reserved
|
|
|
+ Modificators byte // Bit: 1 — NoClock; 2 — Bitness8ADC; 4 — ZeroClockOnNewBlock; the rest is reserved
|
|
|
ChannelsNum byte
|
|
|
BlockWriteClockDelay byte
|
|
|
Reserved0 [1]byte
|
|
@@ -27,11 +27,12 @@ type VoltloggerDumpRawHeader struct {
|
|
|
}
|
|
|
|
|
|
type VoltloggerDumpHeader struct {
|
|
|
- DeviceName string
|
|
|
- NoClock bool
|
|
|
- Bitness8ADC bool
|
|
|
+ DeviceName [16]byte
|
|
|
+ NoClock uint8
|
|
|
+ Bitness8ADC uint8
|
|
|
+ ZeroClockOnNewBlock uint8
|
|
|
BlockWriteClockDelay int64
|
|
|
- ChannelsNum int
|
|
|
+ ChannelsNum uint8
|
|
|
}
|
|
|
|
|
|
func get16(dumpFile *os.File) (r uint16, err error) {
|
|
@@ -44,7 +45,7 @@ func get8(dumpFile *os.File) (r uint8, err error) {
|
|
|
return r, err
|
|
|
}
|
|
|
|
|
|
-func ParseVoltloggerDump(dumpPath string, noHeaders bool, channelsNum int, headerHandler func(VoltloggerDumpHeader, interface{})(error), rowHandler func(int64, []int32, VoltloggerDumpHeader, interface{})(error), arg interface{}) (err error) {
|
|
|
+func ParseVoltloggerDump(dumpPath string, noHeaders bool, channelsNum uint8, headerHandler func(VoltloggerDumpHeader, interface{})(error), rowHandler func(int64, []int32, VoltloggerDumpHeader, interface{})(error), arg interface{}) (err error) {
|
|
|
var r VoltloggerDumpHeader
|
|
|
|
|
|
// Openning the "dumpPath" as a file
|
|
@@ -60,7 +61,7 @@ func ParseVoltloggerDump(dumpPath string, noHeaders bool, channelsNum int, heade
|
|
|
|
|
|
if (noHeaders) {
|
|
|
r.ChannelsNum = 1
|
|
|
- r.NoClock = false
|
|
|
+ r.NoClock = 0
|
|
|
} else {
|
|
|
|
|
|
// Reading binary header to a VoltloggerDumpRawHeader
|
|
@@ -79,7 +80,7 @@ func ParseVoltloggerDump(dumpPath string, noHeaders bool, channelsNum int, heade
|
|
|
if (raw.Version != 0) {
|
|
|
return fmt.Errorf("Unsupported dump version: %v", raw.Version)
|
|
|
}
|
|
|
- if ((raw.Modificators & (0xff ^ 0x03)) != 0) {
|
|
|
+ if ((raw.Modificators & (0xff ^ 0x07)) != 0) {
|
|
|
return fmt.Errorf("Unsupported modificators bitmask: %o %o", raw.Modificators)
|
|
|
}
|
|
|
if (raw.ChannelsNum == 0) {
|
|
@@ -87,17 +88,19 @@ func ParseVoltloggerDump(dumpPath string, noHeaders bool, channelsNum int, heade
|
|
|
}
|
|
|
|
|
|
// Filling the VoltloggerDump struct
|
|
|
- r.DeviceName = strings.Trim(string(raw.DeviceName[:]), "\000")
|
|
|
- r.NoClock = (raw.Modificators & 0x01 != 0)
|
|
|
- r.Bitness8ADC = (raw.Modificators & 0x02 != 0)
|
|
|
- r.BlockWriteClockDelay = int64(raw.BlockWriteClockDelay)
|
|
|
+ DeviceName := strings.Trim(string(raw.DeviceName[:]), "\000")
|
|
|
+ copy(r.DeviceName[:], DeviceName)
|
|
|
+ r.NoClock = raw.Modificators & 0x01
|
|
|
+ r.Bitness8ADC = raw.Modificators & 0x02
|
|
|
+ r.ZeroClockOnNewBlock = raw.Modificators & 0x04
|
|
|
+ r.BlockWriteClockDelay = int64(raw.BlockWriteClockDelay)
|
|
|
|
|
|
err = headerHandler(r, arg);
|
|
|
if (err != nil) {
|
|
|
- return err;
|
|
|
+ return fmt.Errorf("Got an error from headerHandler: %v", err);
|
|
|
}
|
|
|
|
|
|
- r.ChannelsNum = int(raw.ChannelsNum)
|
|
|
+ r.ChannelsNum = uint8(raw.ChannelsNum)
|
|
|
}
|
|
|
|
|
|
if (channelsNum > 0) {
|
|
@@ -113,7 +116,7 @@ func ParseVoltloggerDump(dumpPath string, noHeaders bool, channelsNum int, heade
|
|
|
|
|
|
for err = nil; err == nil; pos++ {
|
|
|
|
|
|
- if (r.NoClock) {
|
|
|
+ if (r.NoClock != 0) {
|
|
|
timestampGlobal++
|
|
|
} else {
|
|
|
timestampLocal, err := get16(dumpFile)
|
|
@@ -132,22 +135,22 @@ func ParseVoltloggerDump(dumpPath string, noHeaders bool, channelsNum int, heade
|
|
|
|
|
|
timestampLocalOld = uint16(timestampLocal)
|
|
|
if (timestampLocalDiff < 0) {
|
|
|
- timestampLocalDiff += (1 << 16)
|
|
|
+ if (r.ZeroClockOnNewBlock != 0) {
|
|
|
+ timestampLocalDiff = 0
|
|
|
+ } else {
|
|
|
+ timestampLocalDiff += (1 << 16)
|
|
|
+ }
|
|
|
+ timestampGlobal += r.BlockWriteClockDelay
|
|
|
}
|
|
|
|
|
|
timestampGlobal += int64(timestampLocalDiff)
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (pos % WRITEBLOCK_SIZE == 0) {
|
|
|
- timestampGlobal += r.BlockWriteClockDelay
|
|
|
- }
|
|
|
-
|
|
|
row := make([]int32, r.ChannelsNum)
|
|
|
- for i:=0; i < r.ChannelsNum; i++ {
|
|
|
+ for i:=uint8(0); i < r.ChannelsNum; i++ {
|
|
|
var value uint16
|
|
|
- if (r.Bitness8ADC == true) {
|
|
|
+ if (r.Bitness8ADC != 0) {
|
|
|
var value8 uint8
|
|
|
value8, err = get8(dumpFile)
|
|
|
value = uint16(value8)
|