Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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
185 changes: 135 additions & 50 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 @@ -1746,20 +1746,6 @@ uint8_t EmotiBit::update()
{
dataSendTimer = millis();



if (_sendTestData)
{
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();

Expand All @@ -1771,7 +1757,6 @@ uint8_t EmotiBit::update()
startBufferOverflowTest = false;
bufferOverflowTest();
}
}
}

// Hibernate after writing data
Expand Down Expand Up @@ -3423,36 +3408,93 @@ 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);
Comment thread
Joseph-Jacobson marked this conversation as resolved.
Outdated

if (getPowerMode() == PowerMode::NORMAL_POWER)
{
_emotiBitWiFi.sendData(_outDataPackets);
// Write a split marker to SD card (for test/debug only)
if (addSplitterIndicator) {
Comment thread
Joseph-Jacobson marked this conversation as resolved.
Outdated
writeSdCardMessage("\nS\n");
}

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 (getPowerMode() == PowerMode::NORMAL_POWER)
{
_emotiBitWiFi.sendData(_outDataPackets);
}
writeSdCardMessage(_outDataPackets);
_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);

// Write a split marker to SD card (for test/debug only)
if (addSplitterIndicator) {
writeSdCardMessage("\nS\n");
}

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

Expand Down Expand Up @@ -3631,22 +3673,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 +3883,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 +3991,12 @@ 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 z to toggle OFF splitter indicators");
Comment thread
Joseph-Jacobson marked this conversation as resolved.
Outdated
Serial.println("Press Z to toggle ON splitter indicators");
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 +4343,41 @@ void EmotiBit::processDebugInputs(String &debugPackets, uint16_t &packetNumber)
_emotibitNvmController.eraseEeprom();
}
}

else if (c == 'Z')
{
addSplitterIndicator = true;
Serial.println("Adding Splitter Print");
}

else if (c == 'z')
{
addSplitterIndicator = false;
Serial.println("Removing Splitter Print");
}

else if (c == '>')
{
_sendTestData = true;
Serial.println("Entering Sending Test Data Mode");
}
else if (c == '@' && _sendTestData == true)
Comment thread
Joseph-Jacobson marked this conversation as resolved.
Outdated
{
testDataType = "Splitter";
Serial.println("TestDataType: SPLITTER");
}

else if (c == '#' && _sendTestData == true)
Comment thread
Joseph-Jacobson marked this conversation as resolved.
Outdated
{
testDataType = "Sawtooth";
Serial.println("TestDataType: SAWTOOTH");
}

else if (c == '<')
{
_sendTestData = false;
Serial.println("Exiting Sending Test Data Mode");
}
}
}

Expand Down
6 changes: 4 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; // new max send length for splitting in send data, used to be "MAX_SD_WRITE_LEN"
Comment thread
Joseph-Jacobson marked this conversation as resolved.
Outdated
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,8 @@ class EmotiBit {
volatile bool _sdWrite;
PowerMode _powerMode;
bool _sendTestData = false;
const char* testDataType = "Sawtooth"; // Default to Sawtooth
Comment thread
Joseph-Jacobson marked this conversation as resolved.
Outdated
bool addSplitterIndicator = false; // Adds an indicator to the data packets written to the SD Card on when a split occurs
Comment thread
Joseph-Jacobson marked this conversation as resolved.
Outdated
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 <[email protected]>
sentence=A library written for EmotiBit FeatherWing that supports all sensors included on the wing.
Expand Down
19 changes: 19 additions & 0 deletions testing/PacketFixedLengthTest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 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 |
|--------|--------|
| Z | Turns on "splitter" indicator, which is a "S" that is printed after each split|
| z | Turns off "splitter" indicator|
| < | Sets "sendTestData" to true|
| > | Sets "sendTestData" to false|
| @ | Sets test data to Splitter|
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 -e or --extension argument
Comment thread
Joseph-Jacobson marked this conversation as resolved.
Outdated
while [[ $# -gt 0 ]]; do
case "$1" in
-e|--extension)
EMOTIBIT_CSV="$2"
shift 2
;;
*)
echo "Usage: $0 -e|--extension <emotibit_csv_path>"
exit 1
;;
esac
done

if [[ -z "$EMOTIBIT_CSV" ]]; then
echo "Error: You must specify -e or --extension <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.