Skip to content

Commit

Permalink
Merge pull request #2 from ShimmerEngineering/SWF-18
Browse files Browse the repository at this point in the history
SWF-18
  • Loading branch information
JongChern authored Jun 20, 2024
2 parents ad608c8 + 3ece2d2 commit 8d60c13
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions ShimmerBluetooth/ShimmerBluetooth/ObjectCluster.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class ObjectCluster {
public var SignalNames : [String] = []
public var SignalData : [Double] = []
let Seperator = "_"
public var PacketReceptionRate = -1
public func addData(sensorName:String,formatName:String,unitName:String,value:Double){
let newName = [sensorName,Seperator,formatName,Seperator,unitName].joined()
SignalNames.append(newName)
Expand Down
20 changes: 18 additions & 2 deletions ShimmerBluetooth/ShimmerBluetooth/Shimmer3Protocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public class Shimmer3Protocol : NSObject, ShimmerProtocol {
}
}


var startTime = Date()
var numberOfPackets = 0
public var REV_HW_MAJOR: Int = -1

public var REV_HW_MINOR: Int = -1
Expand All @@ -39,7 +40,6 @@ public class Shimmer3Protocol : NSObject, ShimmerProtocol {

public var EXPANSION_BOARD_REV_SPECIAL: Int = -1


var lnAccelSensor: LNAccelSensor = LNAccelSensor()
public var wrAccelSensor: WRAccelSensor = WRAccelSensor()
var timeSensor: TimeSensor = TimeSensor()
Expand Down Expand Up @@ -400,6 +400,21 @@ public class Shimmer3Protocol : NSObject, ShimmerProtocol {
if battVoltageSensor.sensorEnabled{
ojc = battVoltageSensor.processData(sensorPacket: bytes, objectCluster: ojc)
}
if (numberOfPackets==0){
startTime = Date()
}
numberOfPackets+=1
let endTime = Date()
var elapsedTime = endTime.timeIntervalSince(self.startTime)
if (elapsedTime == 0){
elapsedTime = 1
}
var PRR = Int((((Double)(numberOfPackets)/self.CurrentSamplingRate)/elapsedTime)*100)
if (PRR>100){
PRR=100
}
ojc.PacketReceptionRate = PRR
print("Elapsed time: \(elapsedTime) seconds ; Number of packets: \(numberOfPackets) ; Packet Reception Rate(%): \(PRR)")
return ojc
}

Expand Down Expand Up @@ -1145,6 +1160,7 @@ public class Shimmer3Protocol : NSObject, ShimmerProtocol {
}
if (result!){
print("StartStreaming!")
numberOfPackets = 0
self.changeState(btState:Shimmer3BTState.STREAMING)
}
return result
Expand Down

0 comments on commit 8d60c13

Please sign in to comment.