//Rewrote the interpretBinaryMessage fxn to avoid stumbling over a BYTE_END or BYTE_START on accident int ofxOpenBCI::interpretBinaryMessageForward(int startIdx) { //assume curBuffIndex has already been incremented to the next starting spot int endIdx = -1; int nInt32 = 8; unsigned char n_bytes = 32; //this is the number of bytes in the payload if (currBuffer[startIdx] != BYTE_START) throw; //Counting forward, do we see the BYTE_END? if (currBuffer[startIdx + n_bytes] != BYTE_END) { printf("Bad packet: %i, %i. Got: %.02x \n", startIdx, endIdx, currBuffer[startIdx + n_bytes]); return endIdx; } endIdx = startIdx + n_bytes; dataPacket_ADS1299 dataPacket(nInt32); dataPacket.timestamp = time(NULL); dataPacket.sampleIndex = (int)currBuffer[startIdx+1]; //Full doc here: http://docs.openbci.com/05-OpenBCI_Streaming_Data_Format startIdx += 2; //increment the start index for (int i = 0; i < nInt32; i++) { dataPacket.values[i] = interpret24bitAsInt32(&currBuffer[startIdx]); startIdx += 3; //increment the start index } outputPacketBuffer.push(dataPacket); //printf("\n"); return endIdx; }
ndn::Data createDataPacket() { ndn::Data dataPacket(m_prefixName); std::stringstream payloadStream; payloadStream << std::cin.rdbuf(); std::string payload = payloadStream.str(); dataPacket.setContent(reinterpret_cast<const uint8_t*>(payload.c_str()), payload.length()); if (m_freshnessPeriod >= ndn::time::milliseconds::zero()) dataPacket.setFreshnessPeriod(m_freshnessPeriod); if (m_isLastAsFinalBlockIdSet) { if (!m_prefixName.empty()) dataPacket.setFinalBlockId(m_prefixName.get(-1)); else { std::cerr << "Name Provided Has 0 Components" << std::endl; exit(1); } } if (m_isUseDigestSha256Set) m_keyChain.signWithSha256(dataPacket); else { if (!static_cast<bool>(m_identityName)) m_keyChain.sign(dataPacket); else m_keyChain.signByIdentity(dataPacket, *m_identityName); } return dataPacket; }