Skip to content

Refactored testing, Deprecated OF dependency in EmotiBit packet#28

Merged
Joseph-Jacobson merged 11 commits intomasterfrom
1.12.1.feat-appendTestData
Jun 24, 2025
Merged

Refactored testing, Deprecated OF dependency in EmotiBit packet#28
Joseph-Jacobson merged 11 commits intomasterfrom
1.12.1.feat-appendTestData

Conversation

@Joseph-Jacobson
Copy link
Contributor

@Joseph-Jacobson Joseph-Jacobson commented May 29, 2025

Description

The purpose of this PR is to deprecate OF dependencies in EmotiBit Packet, and refactor appendTestData so it will have expected results that can be compared from the EmotiBit and an external source. Below is a more detailed list of the additions.

  • Moved and refactored testing logic from for appendTestData in EmotiBit.cpp to EmotiBitPacket
  • Added structure to use CMake to create an exe from a testing file that creates a comparable output file
  • BASH script to compare SD card output and main tester
  • Removed OF dependancies
  • Bumped versioning to FeatherWing 1.13.1 and XPlat 1.7.1
  • Added a new createPacket that intakes a header and data

Requirements

To you run this branch you would need a minimum of:

  • FeatherWing 1.13.1
  • XPlat 1.7.1

Issues Referenced

Issue #29

Documentation update

None

Notes for Reviewer

Requirements for review

Additional Review Information

New testing structure

  • Added CMake file: This is used to make main.cpp.
  • Added main.cpp: This is used to run tests and outputs test.csv
  • Added BASH script: This is used to run our tests by comparing the test.csv with an expected output
  • New file structure for testing

OF deprecation

  • Moved ArduinoString.h: Moved into XPlat from ofx
  • Edited EmotiBitPacket.h and EmotiBitPacket.cpp: Refactored OF out from being a dependency. I created a function to input ofGetElapsedTimeMillis into the headers if we are i nan OF build. headerToString now uses to_string. Created three test functions: createTestDataPacket, used as an entry point to access each test and iterates for the specified number. It also creates the packets using the new createTestPacket. createTestSawtoothData is used to generate the sawtooth data packets. testHeaderToString is used to test the OF refactor. These two functionalities have determined outputs.
  • Added a new createPacket that intakes a header of class EmotiBitPacket::Header and a template for data. This allows users to pass in either a String or std::string for data. Diagram below:
    createPacketDiagram drawio

Testing

Please follow "Mock Data Testing" and "Arduino String Testing" in the "EmotiBit Feature Test Protocols" document

To run this test you will need to pull both this, and 1.12.1 AppendTestData from the featherwing branch, and ofX. This process was built using Platform.io and the EmotiBit Oscilloscope. I also ran the follow tests on an Arduino build, and the oscilliscope with the new xPlat.

Results

Note: for CI both tests return 0/1 for pass/fail. The terminal prints is to communicate more information if needed.

For MockDataTest: the BASH script will show the results between the new MockDataTest and the EmotiBit's sd card result. The file path to the sd card will need to be specified.

  • Success:
    MockDataTestSuccess
  • Fail:
    MockDataTestFail

For ArduinoStringTest: the BASH script will show the result of the pass/fails.

  • Success:
    ArduinoStringTestSuccess
  • Fail:
    ArduinoStringTestFail

Feature Tests

none

Shared files

  • Firmware binary: [Link to firmware binary]
    None
  • Other files.
    None

Checklist to allow merge

  • All dependent repositories used were on branch master
  • Software
    • Get approval from the reviewer
    • Passed testing on Windows
    • Passed testing on macOS (for major changes/GUI changes/ PRs adding files distributed with the EmotiBit software)
    • Passed testing on linux (ubuntu) (for major changes/GUI changes/ PRs adding files distributed with the EmotiBit software)
    • Update software bundle version in ofxEmotiBitVersion.h
    • Test OF software builds to ensure proper functionality after ArduinoString.h refactor
  • Firmware
    • Set testingMode to TestingMode::NONE
    • Set const bool DIGITAL_WRITE_DEBUG = false (if set true while testing)
    • Update version in EmotiBit.h
    • Update library.properties to the correct version (should match EmotiBit.h)
  • doxygen style comments included for new code snippets
  • Required documentation updated

Screenshots:

added OF tag, cleaned up bash script
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR removes openFrameworks dependencies, refactors packet creation for deterministic testing, and adds tooling to build and compare test data outputs.

  • Refactor EmotiBitPacket to remove OF-specific code and introduce appendTestDataMessage, createTestSawtoothData, and testHeaderToString methods
  • Add EmotiBitDataTester executable with CMake support to generate a CSV of test packets
  • Provide a Bash script to locate and compare SD card output against the generated test CSV

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/EmotiBitPacket.h Declared maxTestLength and new test data methods
src/EmotiBitPacket.cpp Defined maxTestLength, refactored headerToString/createPacket, and implemented test data functions
src/EmotiBitDataTester.cpp New CLI tool to call appendTestDataMessage and write test.csv
src/ArduinoString.h Introduced a minimal EmotiBit::String wrapper around std::string
bashScripts/compare_test.sh Script to find the most recent SD card CSV and diff against test.csv
CMakeLists.txt Build configuration for EmotiBitDataTester

minor edits to EmotiBitPackets and the bash script, added toDos,
Copy link
Collaborator

@nitin710 nitin710 left a comment

Choose a reason for hiding this comment

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

Review-01 by Nitin

I like that you took the time to populate the PR description. It reads well, but there are some issues that I have highlighted below.

General comments on the PR description

  • "Moved testing logic for appendTestData to EmotiBitPacket". Maybe having a link to where it was moved from can add context to the PR.
  • "Included CMake for running main testing file and associated data testing file". I am not sure it is clear enough to add value to the description. It either needs to in reviewer notes under a section "usage" or better explained if a part of the description.
  • I think the list under "requirements" better lives under Testing > Requirements.
    • This section was intended more for "you need this in your stack to be able to compile/run the new features". For us, that would be FW/SW version x.y.z. We can discuss more on this.
  • Myabe adding a block diagram that explains the testing process helps in understanding the testing flow.
  • We should discuss branch naming, XPlat was at version 1.6.1. So i think the feature is built on top of that version. I believe, currently it is using the FW version as base.

File/folder structure

  • Generally, whenever we are adding new files/folders, there is always a question of naming conventions and location of the new files
  • I am not sure bashScripts is the correct name or the correct location.
    • Are we using camel case as a convention? Why not bash-scripts or bash_scripts?
    • It would also be nice to add the reasoning for the name. for example, could we should call it scripts, or maybe helper-scripts?
    • regarding structure, could we have the following? (see the next bullet point for an alternate organization)
scripts
├── script1_name
│   ├── script1.sh
│   └── README.md
└── script2_name
    ├── script2.sh
    └── README.md
  • CMakeLists is another file i dont think belongs in root.
    • I think it should live in a different folder. Maybe apps?
    • There should be a correlation between this CMakeListt and the bashScript
    • Maybe something like this is what we need?
apps (probably some other appropriate name?)
├── DataTester
│   ├── README.md
│   ├── CMakeLists.txt
│   ├── src
│   │   └── EmotiBitDataTester.cpp 
│   ├── scripts
│   │  ├── README.md 
│   │  └── script1.sh
|   └── build

ToDo

  • Bump the version in the library.properties files in root. Follow semantic versioning for the version bump

Reviewer notes

  • successfully compiled on PIO. Failed on Arduino, but i suspect it's a personal arduino setup issue.
  • Did not run the CMake or bash. If we move the files, the sript and possible CMake file will change. So, I plan to test it then,

1. bumped library
2. code refactor
3. file restructure for testing
4. added ArduinoString.h tests
Copy link
Collaborator

@produceconsumerobot produceconsumerobot left a comment

Choose a reason for hiding this comment

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

Overall there are a number of good things in the code changes, but there are a handful of places where the rationale for the choices weren't immediately clear to me. The biggest omission from the PR itself is that you should include your complete results that fully demonstrates your code tested working. I shouldn't have to run your code to be sure that it works. Similar to presentation of scientific results in a journal article, I should be able to read your thorough description of your methods and your results and have everything I need to assess whether your conclusions are supported by your methods and results.

#else
string EmotiBitPacket::headerToString(const Header &header)
{
//Refactored to use to_string instead of ofToString
Copy link
Collaborator

Choose a reason for hiding this comment

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

Did you confirm that to_string performs the same as ofToString for all pertinent data types?
I'm not sure if I'm tracking where that's been tested explicitly.

Copy link
Contributor Author

@Joseph-Jacobson Joseph-Jacobson Jun 16, 2025

Choose a reason for hiding this comment

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

createTestHeader is used to test this refactor. We know to_string works the same as ofToString with the exceptions being it doesn't allow for string to string, which is why I omitted any conversion for the type tag. The other difference is to_string has more robust error handling.

Copy link
Collaborator

@nitin710 nitin710 left a comment

Choose a reason for hiding this comment

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

Review02 by Nitin


add_executable(ArduinoStringTest
src/main.cpp
../../src/ArduinoString.h
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe use target_include_directories function? I thnk add_executable should take cpp files by standard.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this meant to replace add_executable?

Copy link
Collaborator

Choose a reason for hiding this comment

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

No, I *think*, add_executable is used to link src files to an executable.
_target_include_directories is used for specifying header files for the specified source files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gotcha, target_include_directories specifies the directory so I will be specifying src so we can access arduino string

uint16_t packetNumber = 0;

// Define the type tags for the test data, can be used to expand the test data in the future
const char* typeTags[] = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Im not sure I understand why we are defining this here. Can you add your explanation on this comment thread?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was defining it there as a method to access the type tags in a previous version, this was left in however can be easily removed.

Updated readmes, doxygen comments, and tests based on comments
Cleaned up code
Added new createPacket and deprecated old createPackets
@Joseph-Jacobson Joseph-Jacobson changed the title Refactored for defined testing Refactored testing, Deprecated OF Jun 20, 2025
Copy link
Collaborator

@nitin710 nitin710 left a comment

Choose a reason for hiding this comment

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

Left some minor feedback, but I think it looks good!
Did not run any tests.
I think, lets change the ArduinoStringTest script per my notes, and then we can merge it.


add_executable(ArduinoStringTest
src/main.cpp
../../src/ArduinoString.h
Copy link
Collaborator

Choose a reason for hiding this comment

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

No, I *think*, add_executable is used to link src files to an executable.
_target_include_directories is used for specifying header files for the specified source files.

Copy link
Collaborator

@produceconsumerobot produceconsumerobot left a comment

Choose a reason for hiding this comment

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

Looks good. 2 small comments.

//! @param data Template parameter T for the data to include in the packet
//! @return String representation of the packet
template <typename T>
static String createPacket(const Header& header, const T& data)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think output of Type T from createPacket() would make the function more versatile

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, I had to add another conversion to ArduinoString.h to convert a String to std::string for c++ to work with this template T. Messy internally but now we don't need to expect String as the return type. Will need to test this function as well.

@nitin710 nitin710 changed the title Refactored testing, Deprecated OF Refactored testing, Deprecated OF dependency in EmotiBit packet Jun 23, 2025
@Joseph-Jacobson Joseph-Jacobson requested a review from nitin710 June 23, 2025 19:06
Copy link
Collaborator

@nitin710 nitin710 left a comment

Choose a reason for hiding this comment

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

Let's merge it!

After you merge to master, you can go ahead and make a release using the guidelines here: https://github.com/EmotiBit/.github/blob/master/Docs/FirmwareDependencyRelease.md

fi

"$EXECUTABLE"
RESULT=$?
Copy link
Collaborator

Choose a reason for hiding this comment

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

I hope you also tested that "a fail" is registered as a fail by this script.
Trying to tweak the test to intentionally fail temporarily is a good way to make sure your "fail catch" is working!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I confirmed fails get caught by the script as well!

@Joseph-Jacobson Joseph-Jacobson merged commit b7ce552 into master Jun 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants