Skip to content

Commit

Permalink
Merge pull request #367 from wadpac/issue361_axivitydemofile
Browse files Browse the repository at this point in the history
Issue361 axivitydemofile
  • Loading branch information
vincentvanhees authored Oct 20, 2020
2 parents 17d4292 + 2104a85 commit 49aedcd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
20 changes: 11 additions & 9 deletions R/g.cwaread.R
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ g.cwaread = function(fileName, start = 0, end = 0, progressBar = FALSE, desiredt
# sensorConfig = readBin(fid, raw(), size = 1) #offset 35
# sample rate and dynamic range accelerometer
samplerate_dynrange = readBin(fid, integer(), size = 1) #offset 36
frequency = round( 3200 / bitwShiftL(1, 15 - bitwAnd(samplerate_dynrange, 15)))
frequency_header = round( 3200 / bitwShiftL(1, 15 - bitwAnd(samplerate_dynrange, 15)))
accrange = bitwShiftR(16,(bitwShiftR(samplerate_dynrange,6)))
suppressWarnings(readChar(fid, 4, useBytes = TRUE)) #offset 37..40
version = readBin(fid, integer(), size = 1) #offset 41
Expand All @@ -124,9 +124,9 @@ g.cwaread = function(fileName, start = 0, end = 0, progressBar = FALSE, desiredt
if (is.null(datas)){
stop("Error in the first data block reading")
}
if (frequency != datas$frequency){
if (frequency_header != datas$frequency){
warning("Inconsistent value of measurement frequency: there is ",
frequency, " in header and ", datas$frequency, " in the first data block ")
frequency_header, " in header and ", datas$frequency, " in the first data block ")
}
} else {
return(invisible(NULL))
Expand All @@ -135,7 +135,7 @@ g.cwaread = function(fileName, start = 0, end = 0, progressBar = FALSE, desiredt
start = as.POSIXct(datas$start, origin = "1970-01-01", tz=desiredtz)

returnobject = list(
uniqueSerialCode = uniqueSerialCode, frequency = frequency,
uniqueSerialCode = uniqueSerialCode, frequency = frequency_header,
start = start,
device = "Axivity", firmwareVersion = version, blocks = numDBlocks,
accrange = accrange, hardwareType=hardwareType
Expand Down Expand Up @@ -260,7 +260,7 @@ g.cwaread = function(fileName, start = 0, end = 0, progressBar = FALSE, desiredt
# If tsOffset is not null then timestamp offset was artificially
# modified for backwards-compatibility ... therefore undo this...
if (bitwAnd(tsOffset, 0x8000L) != 0) {
frequency = round( 3200 / bitwShiftL(1, 15 - bitwAnd(samplerate_dynrange, 15)))
frequency_data = round( 3200 / bitwShiftL(1, 15 - bitwAnd(samplerate_dynrange, 15)))
accrange = bitwShiftR(16,(bitwShiftR(samplerate_dynrange,6)))
# Need to undo backwards-compatible shim:
# Take into account how many whole samples the fractional part
Expand All @@ -274,11 +274,13 @@ g.cwaread = function(fileName, start = 0, end = 0, progressBar = FALSE, desiredt
# use 15-bits as 16-bit fractional time
fractional = bitwShiftL(bitwAnd(tsOffset, 0x7fffL), 1);
# frequency is truncated to int in firmware
shift = shift + bitwShiftR((fractional * frequency), 16);
shift = shift + bitwShiftR((fractional * frequency_data), 16);
} else if (bitwAnd(tsOffset, 0x8000L) == 0) { # & class(frequency_data) == "function") {
frequency_data = round( 3200 / bitwShiftL(1, 15 - bitwAnd(samplerate_dynrange, 15)))
}
} else {
#Very old format, where offset 26 contains frequency
frequency = temp
frequency_data = temp
}
# Read data if necessary
if (complete){
Expand Down Expand Up @@ -317,8 +319,8 @@ g.cwaread = function(fileName, start = 0, end = 0, progressBar = FALSE, desiredt
suppressWarnings(readChar(fid, 482, useBytes = TRUE))
}
l = list(
frequency = frequency,
start = timestampDecoder(timeStamp, fractional,-shift / frequency),
frequency = frequency_data,
start = timestampDecoder(timeStamp, fractional,-shift / frequency_data),
temperature = temperature,
battery = battery,
light = light,
Expand Down
3 changes: 2 additions & 1 deletion inst/NEWS.Rd
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
\name{NEWS}
\title{News for Package \pkg{GGIR}}
\newcommand{\cpkg}{\href{http://CRAN.R-project.org/package=#1}{\pkg{#1}}}
\section{Changes in version 2.1-3 (GitHub-only-release date:15-10-2020)}{
\section{Changes in version 2.1-3 (GitHub-only-release date:20-10-2020)}{
\itemize{
\item Depricating sessionInfo storage as it caused problems for large scale parallel processing
\item Part 1 fix to 1 minute time shift when recording starts at full minute.
\item Improved compatibility with older .cwa file formats.
}
}
\section{Changes in version 2.1-2 (GitHub-only-release date:25-09-2020)}{
Expand Down

0 comments on commit 49aedcd

Please sign in to comment.