Skip to content

Commit

Permalink
Merge pull request #7 from bparks13/main
Browse files Browse the repository at this point in the history
Update to allow larger packets of data
  • Loading branch information
jonnew authored Mar 13, 2024
2 parents aa723ba + 439afe0 commit 841aeba
Show file tree
Hide file tree
Showing 8 changed files with 500 additions and 213 deletions.
33 changes: 23 additions & 10 deletions Resources/python-example.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,34 @@
# ---- SPECIFY THE SIGNAL PROPERTIES ---- #
totalDuration = 10 # the total duration of the signal
numChannels = 4 # number of channels to send
bufferSize = 500 # size of the data buffer
numSamples = 500 # size of the data buffer
Freq = 30000 # sample rate of the signal
testingValue1 = 100 # high value
testingValue2= -100 # low value

# ---- DEFINE HEADER VALUES ---- #
headerSize = 22 # Specifies that there are 22 bytes in the header
offset = 0 # Offset of bytes in this packet; only used for buffers > ~64 kB
dataType = 2 # Enumeration value based on OpenCV.Mat data types
elementSize = 2 # Number of bytes per element. elementSize = 2 for U16
# Data types: [ U8, S8, U16, S16, S32, F32, F64 ]
# Enum value: [ 0, 1, 2, 3, 4, 5, 6 ]
# Element Size: [ 1, 1, 2, 2, 4, 4, 8 ]
bytesPerBuffer = numChannels * numSamples * elementSize

header = np.array([offset, bytesPerBuffer], dtype='i4').tobytes() + \
np.array([dataType], dtype='i2').tobytes() + \
np.array([elementSize, numChannels, numSamples], dtype='i4').tobytes()

# ---- COMPUTE SOME USEFUL VALUES ---- #
bytesPerBuffer = bufferSize * 2 * numChannels
buffersPerSecond = Freq / bufferSize
buffersPerSecond = Freq / numSamples
bufferInterval = 1 / buffersPerSecond

# ---- GENERATE THE DATA ---- #
OpenEphysOffset = 32768
convertedValue1 = OpenEphysOffset+(testingValue1/0.195)
convertedValue2 = OpenEphysOffset+(testingValue2/0.195)
intList_1 = (np.ones((int(Freq/2),)) * convertedValue1).astype('uint16')
OpenEphysOffset = 100
convertedValue1 = OpenEphysOffset+(testingValue1)
convertedValue2 = OpenEphysOffset+(testingValue2)
intList_1 = (np.ones((int(Freq/2),)) * convertedValue1).astype('uint16') # if dataType == 2, use astype('uint16')
intList_2 = (np.ones((int(Freq/2),)) * convertedValue2).astype('uint16')
oneCycle = np.concatenate((intList_1, intList_2))
allData = np.tile(oneCycle, (numChannels, totalDuration)).T
Expand All @@ -47,12 +60,12 @@ def currentTime():
# ---- STREAM DATA ---- #
while (bufferIndex < totalBytes):
t1 = currentTime()
UDPClientSocket.sendto(bytesToSend[bufferIndex:bufferIndex+bytesPerBuffer], serverAddressPort)
rc = UDPClientSocket.sendto(header + bytesToSend[bufferIndex:bufferIndex+bytesPerBuffer], serverAddressPort)
t2 = currentTime()

while ((t2 - t1) < bufferInterval):
t2 = currentTime()

bufferIndex += bytesPerBuffer

print("Done")
Loading

0 comments on commit 841aeba

Please sign in to comment.