Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
172 changes: 114 additions & 58 deletions EmotiBit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1648,7 +1648,7 @@ uint8_t EmotiBit::update()
static uint16_t serialPrevAvailable = Serial.available();
if (Serial.available() > serialPrevAvailable)
{
if(Serial.read() == 'F')
if(Serial.peek() == 'F')
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means that in debug mode, every Serial input will trigger an "info print" and then perform a Debug operation if a key listed in debug mode is entered.
Unless, F is entered, in which case, it will enter FTP mode.
Is that correct?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

{
#ifdef ARDUINO_FEATHER_ESP32
if(!_sdWrite) // if not writing to SD card
Expand Down Expand Up @@ -1678,7 +1678,7 @@ uint8_t EmotiBit::update()
#endif

}
else
else if (!_debugMode)
{
printEmotiBitInfo();
}
Expand Down Expand Up @@ -1746,31 +1746,15 @@ uint8_t EmotiBit::update()
{
dataSendTimer = millis();

// Perform data calculations in main loop
processData();
// Send data to SD card and over wireless
sendData();


if (_sendTestData)
if (startBufferOverflowTest)
{
addTestData(_outDataPackets);
if (getPowerMode() == PowerMode::NORMAL_POWER)
{
_emotiBitWiFi.sendData(_outDataPackets);
}
writeSdCardMessage(_outDataPackets);
_outDataPackets = "";
}
else
{
Comment thread
Joseph-Jacobson marked this conversation as resolved.
// Perform data calculations in main loop
processData();

// Send data to SD card and over wireless
sendData();

if (startBufferOverflowTest)
{
startBufferOverflowTest = false;
bufferOverflowTest();
}
startBufferOverflowTest = false;
bufferOverflowTest();
}
}

Expand Down Expand Up @@ -3423,35 +3407,82 @@ void EmotiBit::processData()

void EmotiBit::sendData()
{
// Test data packets would get added here
Comment thread
Joseph-Jacobson marked this conversation as resolved.
Outdated
if (_sendTestData)
{
addTestData(_outDataPackets);
}

for (int16_t i = 0; i < (uint8_t)EmotiBit::DataType::length; i++)
{
addPacket((EmotiBit::DataType) i);
if (!_sendTestData)
{
addPacket((EmotiBit::DataType) i);
}

if (_outDataPackets.length() > OUT_MESSAGE_TARGET_SIZE)
{
// Avoid overrunning our reserve memory
//if (_outDataPackets.length() > 2000)
//{
// Serial.println(_outDataPackets.length());
//}
int16_t firstIndex;
firstIndex = 0;
while (firstIndex < _outDataPackets.length()) {
int16_t lastIndex;
//Serial.println(firstIndex);
lastIndex = _outDataPackets.length() - 1; // message.length() - 1 to handle \n

// Search for the largest packet larger than MAX_SEND_LEN
while (lastIndex - firstIndex > MAX_SEND_LEN - 1) {
// Start at the end of the message and search for a packet delimiter less than MAX_SEND_LEN
lastIndex = _outDataPackets.lastIndexOf(EmotiBitPacket::PACKET_DELIMITER_CSV, lastIndex - 1);
//Serial.println(lastIndex);
if (lastIndex <= firstIndex)
{
// If we don't find a packet less than MAX_SEND_LEN, send the whole thing
lastIndex = _outDataPackets.length() - 1;
break;
}
}

String s = _outDataPackets.substring(firstIndex, lastIndex + 1); //ToDo:: Consider methods to optimize this

if (getPowerMode() == PowerMode::NORMAL_POWER)
{
_emotiBitWiFi.sendData(_outDataPackets);
if (getPowerMode() == PowerMode::NORMAL_POWER) {
_emotiBitWiFi.sendData(s);
}
writeSdCardMessage(s);
firstIndex = lastIndex + 1;
}
//Serial.println("_emotiBitWiFi.sendData()");
writeSdCardMessage(_outDataPackets);
//Serial.println("writeSdCardMessage()");
_outDataPackets = "";

}
}
if (_outDataPackets.length() > 0)
if (_outDataPackets.length() > 0) //ToDo: Consider removing this check since it only clears the remaining data on the buffer
{
if (getPowerMode() == PowerMode::NORMAL_POWER)
{
_emotiBitWiFi.sendData(_outDataPackets);
int16_t firstIndex;
Comment thread
Joseph-Jacobson marked this conversation as resolved.
firstIndex = 0;
while (firstIndex < _outDataPackets.length()) {
int16_t lastIndex;
//Serial.println(firstIndex);
lastIndex = _outDataPackets.length() - 1; // message.length() - 1 to handle \n

// Search for the largest packet larger than MAX_SEND_LEN
while (lastIndex - firstIndex > MAX_SEND_LEN - 1) {
// Start at the end of the message and search for a packet delimiter less than MAX_SEND_LEN
lastIndex = _outDataPackets.lastIndexOf(EmotiBitPacket::PACKET_DELIMITER_CSV, lastIndex - 1);
//Serial.println(lastIndex);
if (lastIndex <= firstIndex)
{
// If we don't find a packet less than MAX_SEND_LEN, send the whole thing
lastIndex = _outDataPackets.length() - 1;
break;
}
}

String s = _outDataPackets.substring(firstIndex, lastIndex + 1);

if (getPowerMode() == PowerMode::NORMAL_POWER) {
_emotiBitWiFi.sendData(s);
}
writeSdCardMessage(s);
firstIndex = lastIndex + 1;
}
writeSdCardMessage(_outDataPackets);
_outDataPackets = "";
}
}
Expand Down Expand Up @@ -3631,22 +3662,24 @@ bool EmotiBit::writeSdCardMessage(const String & s) {

if (_sdWrite && s.length() > 0) {
if (_dataFile) {
static int16_t firstIndex;
firstIndex = 0;
while (firstIndex < s.length()) {
static int16_t lastIndex;
if (s.length() - firstIndex > MAX_SD_WRITE_LEN) {
lastIndex = firstIndex + MAX_SD_WRITE_LEN;
}
else {
lastIndex = s.length();
}
if (s.length() > MAX_SEND_LEN)
{
Serial.println("Message too long for SD card write: ");
EmotiBitPacket::Header header = EmotiBitPacket::createHeader(
EmotiBitPacket::TypeTag::DATA_OVERFLOW,
millis(),
_outDataPacketCounter++,
1, 1, 100);
String data = String(s.length());
String errorPacket = EmotiBitPacket::createPacket(header, data);
Serial.println(errorPacket);
_dataFile.print(errorPacket);
return false; // ToDo: handle this case
}
#ifdef DEBUG_GET_DATA
Serial.println("writing to SD card");
#endif // DEBUG
_dataFile.print(s.substring(firstIndex, lastIndex));
firstIndex = lastIndex;
}
_dataFile.print(s);

static uint32_t syncTimer = millis();
if (millis() - syncTimer > targetFileSyncDelay)
Expand Down Expand Up @@ -3839,8 +3872,8 @@ void EmotiBit::updateBatteryIndication(float battPercent)

void EmotiBit::addTestData(String &dataMessage)
{
if (_sdWrite){ //only send test data if we are recording
EmotiBitPacket::createTestDataPacket(dataMessage);
if (_sdWrite) {//only send test data if we are recording
Comment thread
Joseph-Jacobson marked this conversation as resolved.
Outdated
EmotiBitPacket::createTestDataPacket(dataMessage, _testDataType);
}
}

Expand Down Expand Up @@ -3947,6 +3980,10 @@ void EmotiBit::processDebugInputs(String &debugPackets, uint16_t &packetNumber)
Serial.println("Press S to reset maxReadSensors metrics");
Serial.println("[ACUTE TESTING MODE] Press n to printEntireNvm");
Serial.println("[ACUTE TESTING MODE] Press N to eraseEeprom");
Serial.println("Press > to toggle ON Send Test Data");
Serial.println("Press < to toggle OFF Send Test Data");
Serial.println("Press @ to toggle Packet Fixed Length Test if Send Test Data is ON");
Serial.println("Press # to toggle Sawtooth Test Data if Send Test Data is ON");
}
else if (c == ':')
{
Expand Down Expand Up @@ -4293,6 +4330,25 @@ void EmotiBit::processDebugInputs(String &debugPackets, uint16_t &packetNumber)
_emotibitNvmController.eraseEeprom();
}
}
else if (c == '>') {
Comment thread
Joseph-Jacobson marked this conversation as resolved.
_sendTestData = true;
Serial.println("Entering Sending Test Data Mode");
}
else if (c == '<')
{
_sendTestData = false;
Serial.println("Exiting Sending Test Data Mode");
}
else if (c == '@' && _sendTestData == true)
{
_testDataType = EmotiBitPacket::TestType::FIXED_PACKET_LENGTH;
Serial.println("TestDataType: Fixed Packet Length Test");
}
else if (c == '#' && _sendTestData == true)
{
_testDataType = EmotiBitPacket::TestType::SAWTOOTH;
Serial.println("TestDataType: Sawtooth Test");
}
}
}

Expand Down
5 changes: 3 additions & 2 deletions EmotiBit.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class EmotiBit {



String firmware_version = "1.14.0";
String firmware_version = "1.14.1";



Expand Down Expand Up @@ -298,7 +298,7 @@ class EmotiBit {
static const uint16_t OUT_MESSAGE_RESERVE_SIZE = 2048;
static const uint16_t OUT_MESSAGE_TARGET_SIZE = 1024;
static const uint16_t DATA_SEND_INTERVAL = 100;
static const uint16_t MAX_SD_WRITE_LEN = 512; // 512 is the size of the sdFat buffer
static const uint16_t MAX_SEND_LEN = 512;
static const uint16_t MAX_DATA_BUFFER_SIZE = 48;
static const uint16_t NORMAL_POWER_MODE_PACKET_INTERVAL = 200;
static const uint16_t LOW_POWER_MODE_PACKET_INTERVAL = 1000;
Expand Down Expand Up @@ -425,6 +425,7 @@ class EmotiBit {
volatile bool _sdWrite;
PowerMode _powerMode;
bool _sendTestData = false;
EmotiBitPacket::TestType _testDataType = EmotiBitPacket::TestType::SAWTOOTH; // Default to Sawtooth
DataType _serialData = DataType::length;
volatile bool buttonPressed = false;
bool startBufferOverflowTest = false;
Expand Down
30 changes: 4 additions & 26 deletions EmotiBitWiFi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,32 +423,10 @@ int8_t EmotiBitWiFi::sendUdp(WiFiUDP& udp, const String& message, const IPAddres
return wifiStatus;
}

int16_t firstIndex;
firstIndex = 0;
while (firstIndex < message.length()) {
int16_t lastIndex;
//Serial.println(firstIndex);
lastIndex = message.length() - 1; // message.length() - 1 to handle \n

// Search for the largest packet larger than MAX_SEND_LEN
while (lastIndex - firstIndex > MAX_SEND_LEN - 1) {
// Start at the end of the message and search for a packet delimiter less than MAX_SEND_LEN
lastIndex = message.lastIndexOf(EmotiBitPacket::PACKET_DELIMITER_CSV, lastIndex - 1);
//Serial.println(lastIndex);
if (lastIndex <= firstIndex)
{
// If we don't find a packet less than MAX_SEND_LEN, send the whole thing
lastIndex = message.length() - 1;
break;
}
}
//Serial.println(message.substring(firstIndex, lastIndex));
for (uint8_t n = 0; n < _nDataSends; n++) {
udp.beginPacket(ip, port);
udp.print(message.substring(firstIndex, lastIndex + 1)); // use lastIndex + 1 to get \n back
udp.endPacket();
}
firstIndex = lastIndex + 1; // increment substring indexes for breaking up sends
for (uint8_t n = 0; n < _nDataSends; n++) {
udp.beginPacket(ip, port);
udp.print(message);
udp.endPacket();
}

return SUCCESS;
Comment thread
Joseph-Jacobson marked this conversation as resolved.
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=EmotiBit FeatherWing
version=1.14.0
version=1.14.1
author=Connected Future Labs
maintainer=Connected Future Labs <info@connectedfuturelabs.com>
sentence=A library written for EmotiBit FeatherWing that supports all sensors included on the wing.
Expand Down
17 changes: 17 additions & 0 deletions testing/PacketFixedLengthTest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Description
- This tests verifies that the Packet Fixed Length Test data in the EmotiBit SD card does not contain any Debug Overloads under conditions where the test runs up to 512 iterations.
Comment thread
Joseph-Jacobson marked this conversation as resolved.
Outdated
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From this description, I'm not sure I can understand what this test is doing. Perhaps improving the clarity would be helpful.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Edited for clarity

- The data is verified with the bash script, checking the SD card output
- Instructions to run this test can be found in the EmotiBit Test Protocols Document under Max Length Data Test
Comment thread
Joseph-Jacobson marked this conversation as resolved.
Outdated

Comment thread
Joseph-Jacobson marked this conversation as resolved.
The following table shows commands for choosing the test type. A typical workflow will consist of:
1. Going into debug mode
2. Setting sendTestData to true
3. Choosing the Splitter test '@'
4. Pressing record in the oscilliscope and waiting for the test to finish
5. Comparing the SD card result with the bash script, specifying the extension

Comment thread
Joseph-Jacobson marked this conversation as resolved.
| Command | Details |
|--------|--------|
| < | Sets "sendTestData" to true|
| > | Sets "sendTestData" to false|
| @ | Sets test data to Splitter|
Comment thread
Joseph-Jacobson marked this conversation as resolved.
Outdated
31 changes: 31 additions & 0 deletions testing/PacketFixedLengthTest/run_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash
set -u

EMOTIBIT_CSV=""

# Parse required -p or --path argument
while [[ $# -gt 0 ]]; do
case "$1" in
-p|--path)
EMOTIBIT_CSV="$2"
shift 2
;;
*)
echo "Usage: $0 -p|--path <emotibit_csv_path>"
exit 1
;;
esac
done

if [[ -z "$EMOTIBIT_CSV" ]]; then
echo "Error: You must specify -p or --path <emotibit_csv_path>"
exit 1
fi

if grep -q ',DO,' "$EMOTIBIT_CSV"; then
echo "DO found in $EMOTIBIT_CSV"
exit 1
else
echo "No DO found in $EMOTIBIT_CSV"
exit 0
fi
Comment thread
Joseph-Jacobson marked this conversation as resolved.