robintibor/python-mindwave-mobile

Invalid dataRowCode value

ckbehemoth opened this issue · 8 comments

Hello,

I'm just getting off the ground w/ my new Mindwave Mobile+ and this package has been great for connecting with my Ubuntu 16.04 system. The snag I'm hitting is that the hardware sync works fine, but when it gets to the _createDataPoint function in the packet payload parser, it fails with an 'assert False' due to an invalid dataRowCode value.

Sniffing the bluetooth connection with Wireshark shows this packet arrives before other, proper-format packets:

aa aa 02 ba  04 41 
aa aa 02 bc  04 3f 

The 0xAA START_PACKETs are right, the 02 byte len is right, the checksum is right, but the codes 0xBA and 0xBC aren't accounted for and I can't find any reference to them in the on-line docs. So - am I missing something? Did they alter the protocol details?

TIA for any ideas and thanks again for releasing the code - it's made understanding the Mindwave much easier.

Cheers!

Bill

Hi Bill,

I'm also wondering if they changed the protocol details. I can sync my device, but when I try to run the read_mindwave_mobile.py example program:

from mindwavemobile.MindwaveDataPointReader import MindwaveDataPointReader
mindwaveDataPointReader = MindwaveDataPointReader()
# connect to the mindwave mobile headset...
mindwaveDataPointReader.start()
# read one data point, data point types are specified in  MindwaveDataPoints.py
dataPoint = mindwaveDataPointReader.readNextDataPoint()
print(dataPoint)

the readNextDataPoint() call seems to begin an infinite loop. It seems to do this because the function _goToStartOfNextPacket() in MindwaveDataPointReader.py is checking if the next byte from the buffer is equal to the START_OF_PACKET_BYTE.
byte == MindwaveMobileRawReader.START_OF_PACKET_BYTE

it's never getting past this comparison because the the next item from the buffer (contents at bottom) is never equal to 0xaa.

Does any of this make sense? For the record, I converted this library to python 3 code and I'm using osx.

Does anyone have any advice for me? Which documents were helpful in describing the packet contents sent by the Mindwave Mobile and the protocol used?

I am pretty clueless so any hints would be appreciated.

buffer contents:
['b', "'", '\', 'x', 'a', 'a', '\', 'x', 'a', 'a', '\', 'x', '0', '2', '\', 'x', 'b', 'a', '\', 'x', '0', '4', 'A', '\', 'x', 'a', 'a', '\', 'x', 'a', 'a', '\', 'x', '0', '2', '\', 'x', 'b', 'c', '\', 'x', '0', '5', '>', "'", 'b', "'", '\', 'x', 'a', 'a', '\', 'x', 'a', 'a', '\', 'x', '0', '4', '\', 'x', '8', '0', '\', 'x', '0', '2', '\', 'x', '0', '7', '\', 'x', 'f', 'f', 'w', "'", 'b', "'", '\', 'x', 'a', 'a', '\', 'x', 'a', 'a', '\', 'x', '0', '4', '\', 'x', '8', '0', '\', 'x', '0', '2', '\']

@ckbehemoth
I switched back to using the original python-mindwave-mobile Python 2 code and am now running into the same issue as you.

The 0xBA and 0xBC aren't accounted for in the file MindwavePacketPayloadParser.py. The _createDataPoint() method doesn't know what to do with the dataRawCode equaling 0xBA or 0xBC.

Did you figure out a work around?

Thanks!!

@ckbehemoth I found somewhat of an answer. https://github.com/NeuroSkyWuxi/StreamSDKforOSX/blob/master/StreamSDKForMac.pdf Check out the bottom of page 15/top of page 16. There is a bit of code that references the 0xBA 0xBC bytes. They just seem to be some sort of command. Whatever that means.

@a1noack It's a hack, but I got it working. I had to add an additional check for the weird codes [0xBA, 0xBC] and a 'dummy' DataPoint subclass to stash those values in, but once it got past those two codes at the start everything went as advertised.

I don't want to make a pull request since it's such a hack and I don't know what those values are for, but I can send you the tweaked files if you like. Let me know what's easiest.

@ckbehemoth cool. yeah I actually did the same thing as you. Thanks anyway!

Great minds think alike. :D If you ever figure out what those two errant op-codes are, let me know. Good luck!

Hi @ckbehemoth marvelous that you found some way to make it work. Since I don't own a NeuroSky right now, it would be very nice if you create a pull request! Doesn't matter if it seems hacky, it will be nicer for people if the library still works :) So can you do it? :) Would be really great!

Sure - don't mind at all! I need a day or two to clean things up and strip out all of my sloppy debugging bits. I'll try to keep it as un-hack-ish as possible. :)

More TK