Skip to content

Commit

Permalink
Merge pull request #946 from retiutut/2021-pulse-sensor-update
Browse files Browse the repository at this point in the history
2021 pulse sensor update - GUI v5.0.3
  • Loading branch information
retiutut authored Jan 24, 2021
2 parents bfaec09 + f462b4c commit ae39b8e
Show file tree
Hide file tree
Showing 9 changed files with 289 additions and 80 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ application.*
*.autosave
.vscode/*
temp/*
libBoardController.so
libDataHandler.so
libGanglionLib.so
libGanglionScan.so
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# v5.0.3

### Improvements
* Increase sampling rate for Pulse data output in Networking Widget

### Bug Fixes
* Fix Pulse LSL output error #943
* Fix Accel/Aux UDP output #944
* Fix Expert Mode unplanned keyboard shortcuts crash GUI #941

Expand Down
58 changes: 58 additions & 0 deletions Networking-Test-Kit/LSL/lslStreamTest_AnalogPinPulse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"""Example program to show how to read a multi-channel time series from LSL."""
import time
from pylsl import StreamInlet, resolve_stream
from time import sleep
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import style
from collections import deque

# first resolve an EEG stream on the lab network
print("looking for an EEG stream...")
streams = resolve_stream('type', 'EEG')

# create a new inlet to read from the stream
inlet = StreamInlet(streams[0])
duration = 10

sleep(0)

def testLSLSamplingRate():
start = time.time()
numSamples = 0
numChunks = 0

while time.time() <= start + duration:
# get chunks of samples
chunk, timestamp = inlet.pull_chunk()
if timestamp:
numChunks += 1
for sample in chunk:
numSamples += 1

print( "Number of Chunks == {}".format(numChunks) )
print( "Avg Sampling Rate == {}".format(numSamples / duration) )


testLSLSamplingRate()

print("gathering data to plot...")

def testLSLPulseData():
start = time.time()
raw_pulse_signal = []

while time.time() <= start + duration:
chunk, timestamp = inlet.pull_chunk()
if timestamp:
for sample in chunk:
# print(sample)
raw_pulse_signal.append(sample[1])

print(raw_pulse_signal)
print( "Avg Sampling Rate == {}".format(len(raw_pulse_signal) / duration) )
plt.plot(raw_pulse_signal)
plt.ylabel('raw analog signal')
plt.show()

testLSLPulseData()
9 changes: 8 additions & 1 deletion Networking-Test-Kit/UDP/udp_receive.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,16 @@ def close_file(*args):

# Receive messages
print("Listening...")
while True:
start = time.time()
numSamples = 0
duration = 10
while time.time() <= start + duration:
data, addr = sock.recvfrom(20000) # buffer size is 20000 bytes
if args.option=="print":
print_message(data)
numSamples += 1
elif args.option=="record":
record_to_file(data)
print( "Samples == {}".format(numSamples) )
print( "Duration == {}".format(duration) )
print( "Avg Sampling Rate == {}".format(numSamples / duration) )
106 changes: 106 additions & 0 deletions Networking-Test-Kit/UDP/udp_receive_pulse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import socket
import sys
import time
import argparse
import signal
import struct
import os
import json
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import style

raw_pulse_signal = []

# Print received message to console
def print_message(*args):
try:
# print(args[0]) #added to see raw data
obj = json.loads(args[0].decode())
print(obj.get('data'))
except BaseException as e:
print(e)
# print("(%s) RECEIVED MESSAGE: " % time.time() +
# ''.join(str(struct.unpack('>%df' % int(length), args[0]))))

# Clean exit from print mode
def exit_print(signal, frame):
print("Closing listener")
sys.exit(0)

# Record received message in text file
def record_to_file(*args):
textfile.write(str(time.time()) + ",")
textfile.write(''.join(str(struct.unpack('>%df' % length,args[0]))))
textfile.write("\n")

# Save recording, clean exit from record mode
def close_file(*args):
print("\nFILE SAVED")
textfile.close()
sys.exit(0)

if __name__ == "__main__":
# Collect command line arguments
parser = argparse.ArgumentParser()
parser.add_argument("--ip",
default="127.0.0.1", help="The ip to listen on")
parser.add_argument("--port",
type=int, default=12345, help="The port to listen on")
parser.add_argument("--address",default="/openbci", help="address to listen to")
parser.add_argument("--option",default="print",help="Debugger option")
parser.add_argument("--len",default=8,help="Debugger option")
args = parser.parse_args()

# Set up necessary parameters from command line
length = args.len
if args.option=="print":
signal.signal(signal.SIGINT, exit_print)
elif args.option=="record":
i = 0
while os.path.exists("udp_test%s.txt" % i):
i += 1
filename = "udp_test%i.txt" % i
textfile = open(filename, "w")
textfile.write("time,address,messages\n")
textfile.write("-------------------------\n")
print("Recording to %s" % filename)
signal.signal(signal.SIGINT, close_file)

# Connect to socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
server_address = (args.ip, args.port)
sock.bind(server_address)

# Display socket attributes
print('--------------------')
print("-- UDP LISTENER -- ")
print('--------------------')
print("IP:", args.ip)
print("PORT:", args.port)
print('--------------------')
print("%s option selected" % args.option)

# Receive messages
print("Listening...")
start = time.time()
numSamples = 0
duration = 3

while time.time() <= start + duration:
data, addr = sock.recvfrom(20000) # buffer size is 20000 bytes
if args.option=="print":
print_message(data)
sample = json.loads(data.decode()).get('data')[1]
raw_pulse_signal.append(sample)
numSamples += 1
elif args.option=="record":
record_to_file(data)

print( "Samples == {}".format(numSamples) )
print( "Duration == {}".format(duration) )
print( "Avg Sampling Rate == {}".format(numSamples / duration) )
plt.plot(raw_pulse_signal)
plt.ylabel('raw analog signal')
plt.show()
2 changes: 1 addition & 1 deletion OpenBCI_GUI/Info.plist.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<key>CFBundleShortVersionString</key>
<string>4</string>
<key>CFBundleVersion</key>
<string>5.0.3-alpha.2</string>
<string>5.0.3-alpha.3</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>NSHumanReadableCopyright</key>
Expand Down
2 changes: 1 addition & 1 deletion OpenBCI_GUI/OpenBCI_GUI.pde
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ import http.requests.*;
// Global Variables & Instances
//------------------------------------------------------------------------
//Used to check GUI version in TopNav.pde and displayed on the splash screen on startup
String localGUIVersionString = "v5.0.3-alpha.2";
String localGUIVersionString = "v5.0.3-alpha.3";
String localGUIVersionDate = "January 2020";
String guiLatestVersionGithubAPI = "https://api.github.com/repos/OpenBCI/OpenBCI_GUI/releases/latest";
String guiLatestReleaseLocation = "https://github.com/OpenBCI/OpenBCI_GUI/releases/latest";
Expand Down
Loading

0 comments on commit ae39b8e

Please sign in to comment.