Skip to content

Mocking environment for testing Arduino code. The sole objective of this project is to provide testing platform that could be used in ReCodEx for Arduino student assignments.

License

krulis-martin/Moccarduino

Repository files navigation

Windows MSVC Build Linux GCC Build

Moccarduino

Mocking environment for testing Arduino code. The sole objective of this project is to provide a testing platform that could be used in ReCodEx for Arduino assignments.

The emulator is operating on a well-defined API. We are not simulating any low-level aspects of the actual processors used on Arduino boards. On the other hand, we also implement support for Funshield which contains 3 buttons, 4 independent LEDs, and 4 digit 7-segment LED display controlled by a shift register filled from Arduino over a serial link.

Limitations and differences

There are several differences from the actual Arduino which may cause you problems. Please, check the following issues and use suggested workarounds so that your Arduino code works properly in Moccarduino.

Issue Example Workaround
Unsupported complex initialization of global variables size_t t = millis(); Initialize the variable with a default value and call the complex initialization in the setup() function.
Serial communication API Serial.print(); Only Serial.begin(), Serial.print(), and Serial.println() are currently implemented (which should be enough for debugging). The methods does not perform anything, they are placeholders, so you do not remove you debug-code when testing. The testing scenaion may opt-out (disable the serial interface).
max is a function (but a macro at Arduino IDE) int x; long y; max(x,y); Always use min/max with identical types of arguments.
int/long are 16/32 bits at Arduino but 32/64 in most other compilers int32_t x; long y; max(x,y); Do not mix int/long with int16_t/int32_t; make sure to use sufficiently large type for both platforms
Funshield include #include <funshield.h> Replace by #include "funshield.h"
Conservative C++ (order of declarations) int main() { foo(); ...}
void foo() {...}
In C++, you need to declare functions (classes, ...) before you use them (Arduino IDE is more benevolent).
Static methods class Foo { static void foo() ... } Static methods do not work in Moccarduino, use plain old C functions instead.
Initialization class Button {
Button() { pinMode( b[0], INPUT); }
};
Emulated functions from Arduino IDE (e.g., pinMode) MUST be called in setup (not in constructors). Early emulator initialization (e.g., in a constructor of a global object) causes a signal and your program is terminated.
Unsupported type String String stringOne = "Hello String"; Use standard C-strings instead, i.e., const char *stringOne = "Hello String";

Furthermore, the Moccarduino implements only functions from documented Arduino API. Hardware functionality that required direct access to registers (e.g., timers) is not supported.

Code Overview

The most important part of the code is in shared directory. The surrounding projects are mainly designed to demonstrate and test the code.

  • constants.hpp holds all constants and macros as defined in Arduino IDE
  • interface.hpp, interface.cpp implements the low-level API for the tested Arduino code
  • funshield.h holds additional constants needed for the Funshield (this header is given to students for development)
  • helpers.hpp gathers all helper classes (BitArray, ShiftRegister)
  • time_series.hpp is a generalized implementation of a sequence of events (used for various purposes, including analytical functions useful for behavioral assertions)
  • emulator.hpp implements the actual state of the Arduino board and provides an object-oriented interface (which is recalled from C interface)
  • simulation.hpp uses the emulator.hpp and implements controller for the simulation
  • led_display.hpp is an implementation of 7-seg LED display accompanied by shift register (sequentially fed matrix control) and its demultiplexing and content decoding
  • simulation_funshield.hpp uses simulation.hpp and implements higher-level simulation routines targeting specifically Funshield applications

Credits and Disclaimer

This code is currently being developed under the Department of software engineering, Faculty of Mathematics and Physics, Charles University (Prague, Czech Republic). It is being tailored to our needs and we provide no guarantees whatsoever.

About

Mocking environment for testing Arduino code. The sole objective of this project is to provide testing platform that could be used in ReCodEx for Arduino student assignments.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published