CerebusOSS / pycbsdk

Pure Python package for communicating with Blackrock Cerebus devices
MIT License
2 stars 0 forks source link

API should enable setting spike sorting incl. hoops values. #4

Closed cboulay closed 6 months ago

cboulay commented 7 months ago
  1. Use Wireshark to monitor which packets get sent when Central configures spike sorting, and verify that incoming spikes reflect the sorted unit values.
  2. Reproduce sending those packets via pycbsdk.
dkluger commented 7 months ago

One thing that pycbsdk could use is a better default argument definition for cbsdk.configure_channel_by_packet and cbhw.device.nsp.set_channel_config_by_packet Right now, cbhw.device.nsp.set_channel_config_by_packet mandates packet.header.type to be a 'chan_info' packet, but the header can be a different packet type per class CBPacketType, which tracks with cbproto. I've made changes to cbsdk.py to allow optional declaration of the packet type, but default to CBPacketType['CHANSET'], and then modified cbhw\device\nsp.py similarly.

My trying to use pycbsdk for hoops declarations is still hitting a headwall somewhere in the system stack even with this improved functionality in place, but it is worth noting that this functionality of changing the packet header could be useful down the road.

cboulay commented 6 months ago

Summarizing my findings using Wireshark and Central, focusing mostly on the packets that Central sends out.

To enable spiking:

  1. cbPKT_CHANINFO with type cbPKTTYPE_CHANSETREJECTAMPLITUDE
  2. cbPKT_CHANINFO with type cbPKTTYPE_CHANSETSPK

To set a hoop we use Single Neural Channel,. There are some innocuous periodic prevStreamCfg packets (chid 0x8002 (32770), type cbPKTTYPE_PREVSET).

While moving a hoop, Cenral sends cbPKT_CHANINFO with type cbPKTTYPE_CHANSETSPKHPS (0x00cb).

According to the firmware code, the only field that is read specifically for processing CHANSETSPKHPS is spkhoops. This is copied in its entirety from the packet to the device's internal representation of spkhoops.

Additionally, if the device's representation of that channel's spkopts & ALLSORT == HOOPSORT, then for each unit it'll take the first hoop's .valid and copy it to the device's chaninfo's unitmapping[unit_idx].bValid.


So, based on this, a custom sequence to enable hoops would require at least the following:

FYI, previously the Cerebus41.lua in CerebusWireshark was truncating CHANINFO packets before it got to ellipses and spikes. I just pushed a commit that will parse the result of the CHANINFO packet.

cboulay commented 6 months ago

I made a new issue to track the concern you raised above.