bool Brain::parsePacket() {
	// Loop through the packet, extracting data.
	// Based on mindset_communications_protocol.pdf from the Neurosky Mindset SDK.
	hasPower = false;
	clearEegPower();	// clear the eeg power to make sure we're honest about missing values... null would be better than 0.

	for (int i = 0; i < packetLength; i++) {
		switch (packetData[i]) {
		case 2:
			signalQuality = packetData[++i];
			break;
		case 4:
			attention = packetData[++i];
			break;
		case 5:
			meditation = packetData[++i];
			break;
		case 131:
			// ASIC_EEG_POWER: eight big-endian 3-byte unsigned integer values representing delta, theta, low-alpha high-alpha, low-beta, high-beta, low-gamma, and mid-gamma EEG band power values			 
			// The next byte sets the length, usually 24 (Eight 24-bit numbers... big endian?)
			eegPowerLength = packetData[++i];

			// Extract the values. Possible memory savings here by creating three temp longs?
			for(int j = 0; j < EEG_POWER_BANDS; j++) {
				eegPower[j] = ((unsigned long)packetData[++i] << 16) | ((unsigned long)packetData[++i] << 8) | (unsigned long)packetData[++i];
			}

			hasPower = true;
			// This seems to happen once during start-up on the force trainer. Strange. Wise to wait a couple of packets before
			// you start reading.

			break;
		default:
			return false;
		}
	}
	CEEGdata temp;
	temp.signalQuality=signalQuality;
	temp.attention=attention;
	temp.time=time;
	for(int j = 0; j < EEG_POWER_BANDS; j++)
		temp.eegPower[j]=eegPower[j];
	eegdata.push_back(temp);
	return true;
}
Пример #2
0
void Brain::init() {
	brainSerial->begin(9600);

	freshPacket = false;
	inPacket = false;
	packetIndex = 0;
	packetLength = 0;
	checksum = 0;
	checksumAccumulator = 0;
	eegPowerLength = 0;
	hasPower = false;
	
	signalQuality = 200;
	attention = 0;
	meditation = 0;

	clearEegPower();
}
void Brain::init(const char *comport) {
	//brainSerial->begin(9600);// default, no need to set
	if (comport[0]=='n')
		yescome=false;
	else
		yescome=true;
	com.open(comport);
	// old lines
	freshPacket = false;
	inPacket = false;
	packetIndex = 0;
	packetLength = 0;
	checksum = 0;
	checksumAccumulator = 0;
	eegPowerLength = 0;
	hasPower = false;
	signalQuality = 200;
	attention = 0;
	meditation = 0;
	clearEegPower();
}