Compare commits
2 commits
069020ef33
...
a53555446e
Author | SHA1 | Date | |
---|---|---|---|
Vojtěch Pour | a53555446e | ||
Vojtěch Pour | 713ace2919 |
|
@ -1,3 +1,4 @@
|
|||
# Neurosky Mindwave M5Stack Core2 connection
|
||||
- Neusky Mindwave MAC Address: 98:07:2d:7f:ea:15
|
||||
- documentation: http://developer.neurosky.com/docs/doku.php?id=thinkgear_communications_protocol
|
||||
- documentation: http://developer.neurosky.com/docs/doku.php?id=thinkgear_communications_protocol
|
||||
- quick start guide: http://download.neurosky.com/public/Products/MindWave%20Mobile%202/MindWave%20Mobile%202%20Quick%20Start%20Guide.pdf
|
107
parser/core2_C_Parser.ino
Normal file
107
parser/core2_C_Parser.ino
Normal file
|
@ -0,0 +1,107 @@
|
|||
#define BAUDRATE 57600
|
||||
#define DEBUGOUTPUT 0
|
||||
|
||||
// checksum variables
|
||||
byte generatedChecksum = 0;
|
||||
byte checksum = 0;
|
||||
int payloadLength = 0;
|
||||
byte payloadData[64] = {0};
|
||||
byte poorQuality = 0;
|
||||
byte attention = 0;
|
||||
byte meditation = 0;
|
||||
|
||||
// system variables
|
||||
long lastReceivedPacket = 0;
|
||||
boolean bigPacket = false;
|
||||
|
||||
//////////////////////////
|
||||
// Microprocessor Setup //
|
||||
//////////////////////////
|
||||
void setup(){
|
||||
Serial1.begin(BAUDRATE); // Serial port 1 (ATMEGA2560)
|
||||
Serial.begin(BAUDRATE); // USB
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
// Read data from Serial UART //
|
||||
////////////////////////////////
|
||||
byte ReadOneByte() {
|
||||
int ByteRead;
|
||||
while(!Serial1.available());
|
||||
ByteRead = Serial1.read();
|
||||
|
||||
#if DEBUGOUTPUT
|
||||
Serial.print((char)ByteRead); // echo the same byte out the USB serial (for debug purposes)
|
||||
#endif
|
||||
|
||||
return ByteRead;
|
||||
}
|
||||
|
||||
/////////////
|
||||
//MAIN LOOP//
|
||||
/////////////
|
||||
void loop() {
|
||||
// Look for sync bytes
|
||||
if(ReadOneByte() == 170) {
|
||||
if(ReadOneByte() == 170) {
|
||||
payloadLength = ReadOneByte();
|
||||
if(payloadLength > 169) //Payload length can not be greater than 169
|
||||
return;
|
||||
|
||||
generatedChecksum = 0;
|
||||
for(int i = 0; i < payloadLength; i++) {
|
||||
payloadData[i] = ReadOneByte(); //Read payload into memory
|
||||
generatedChecksum += payloadData[i];
|
||||
}
|
||||
|
||||
checksum = ReadOneByte(); //Read checksum byte from stream
|
||||
generatedChecksum = 255 - generatedChecksum; //Take one's compliment of generated checksum
|
||||
|
||||
if(checksum == generatedChecksum) {
|
||||
|
||||
poorQuality = 200;
|
||||
attention = 0;
|
||||
meditation = 0;
|
||||
|
||||
for(int i = 0; i < payloadLength; i++) { // Parse the payload
|
||||
switch (payloadData[i]) {
|
||||
case 2:
|
||||
i++;
|
||||
poorQuality = payloadData[i];
|
||||
bigPacket = true;
|
||||
break;
|
||||
case 4:
|
||||
i++;
|
||||
attention = payloadData[i];
|
||||
break;
|
||||
case 5:
|
||||
i++;
|
||||
meditation = payloadData[i];
|
||||
break;
|
||||
case 0x80:
|
||||
i = i + 3;
|
||||
break;
|
||||
case 0x83:
|
||||
i = i + 25;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
} // switch
|
||||
} // for loop
|
||||
|
||||
#if !DEBUGOUTPUT
|
||||
// *** Add your code here ***
|
||||
if(bigPacket) {
|
||||
Serial.print("Attention: ");
|
||||
Serial.print(attention);
|
||||
Serial.print("\n");
|
||||
}
|
||||
#endif
|
||||
bigPacket = false;
|
||||
}
|
||||
else {
|
||||
// Checksum Error
|
||||
} // end if else for checksum
|
||||
} // end if read 0xAA byte
|
||||
} // end if read 0xAA byte
|
||||
}
|
|
@ -57,6 +57,7 @@ int main( int argc, char **argv ) {
|
|||
* application. See documentation for "Serial I/O" for your
|
||||
* platform for details.
|
||||
*/
|
||||
|
||||
FILE *stream = 0;
|
||||
stream = fopen( "COM4", "r" );
|
||||
|
||||
|
|
Loading…
Reference in a new issue