Skip to content

Commit

Permalink
Fixes for nasa/fprime#2293 (#43)
Browse files Browse the repository at this point in the history
* Updating to v3.3.2

* Fixed else statement otherwise events and port invocations to gpio would happen on every schedIn while blinking is false

* Removing redundant instruction (#39)

* Clarify instructions (#40)

* nasa/fprime#2239

* Reorder #include instruction

* Clarify where to add parameterUpdated

* Fix ... usage

* Clarify gpio configuration

* Update full-integration.md

* Clarify testing

* Update project-setup.md

* Update component-implementation-1.md

* minor changes

* add newline

* Change parameterUpdated scope

* Migrating Led unit tests to v3.4.0 standards

* Syncing docs and code

* Merged version of nasa/fprime#2293

---------

Co-authored-by: Kevin F. Ortega <[email protected]>
Co-authored-by: Thomas Boyer-Chammard <[email protected]>
  • Loading branch information
3 people authored Oct 5, 2023
1 parent bbe66bd commit 5e6dba0
Show file tree
Hide file tree
Showing 15 changed files with 78 additions and 136 deletions.
10 changes: 6 additions & 4 deletions Components/Led/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ register_fprime_module()

set(UT_SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/Led.fpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/TestMain.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/Tester.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/TesterHelpers.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/LedTestMain.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/LedTester.cpp"
)
set(UT_AUTO_HELPERS ON)
set(UT_MOD_DEPS
Os
)

register_fprime_ut()
15 changes: 9 additions & 6 deletions Components/Led/Led.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,16 @@ void Led ::run_handler(const NATIVE_INT_TYPE portNum, NATIVE_UINT_TYPE context)
this->count = ((this->count + 1) >= interval) ? 0 : (this->count + 1);
}
else {
// Port may not be connected, so check before sending output
if (this->isConnected_gpioSet_OutputPort(0)) {
this->gpioSet_out(0, Fw::Logic::LOW);
}
if(this->state == Fw::On::ON)
{
// Port may not be connected, so check before sending output
if (this->isConnected_gpioSet_OutputPort(0)) {
this->gpioSet_out(0, Fw::Logic::LOW);
}

this->state = Fw::On::OFF;
this->log_ACTIVITY_LO_LedState(this->state);
this->state = Fw::On::OFF;
this->log_ACTIVITY_LO_LedState(this->state);
}
}
}

Expand Down
1 change: 1 addition & 0 deletions Components/Led/Led.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Led : public LedComponentBase {
//!
~Led();

PRIVATE:
//! Emit parameter updated EVR
//!
void parameterUpdated(FwPrmIdType id /*!< The parameter ID*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
// TestMain.cpp
// ----------------------------------------------------------------------

#include "Tester.hpp"
#include "LedTester.hpp"

TEST(Nominal, TestBlinking) {
Components::Tester tester;
Components::LedTester tester;
tester.testBlinking();
}

TEST(Nominal, TestBlinkInterval) {
Components::Tester tester;
Components::LedTester tester;
tester.testBlinkInterval();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@
// \brief cpp file for Led test harness implementation class
// ======================================================================

#include "Tester.hpp"
#include "LedTester.hpp"

namespace Components {

// ----------------------------------------------------------------------
// Construction and destruction
// ----------------------------------------------------------------------

Tester ::Tester() : LedGTestBase("Tester", Tester::MAX_HISTORY_SIZE), component("Led") {
LedTester ::LedTester() : LedGTestBase("Tester", LedTester::MAX_HISTORY_SIZE), component("Led") {
this->initComponents();
this->connectPorts();
}

Tester ::~Tester() {}
LedTester ::~LedTester() {}

// ----------------------------------------------------------------------
// Tests
// ----------------------------------------------------------------------

void Tester ::testBlinking() {
void LedTester ::testBlinking() {
// Ensure LED stays off when blinking is disabled
// The Led component defaults to blinking off
this->invoke_to_run(0, 0); // invoke the 'run' port to simulate running one cycle
Expand Down Expand Up @@ -66,7 +66,7 @@ void Tester ::testBlinking() {
ASSERT_TLM_LedTransitions(2, 3);
}

void Tester ::testBlinkInterval() {
void LedTester ::testBlinkInterval() {
// Enable LED Blinking
this->sendCmd_BLINKING_ON_OFF(0, 0, Fw::On::ON);
this->component.doDispatch(); // Trigger execution of async command
Expand All @@ -91,7 +91,7 @@ void Tester ::testBlinkInterval() {
// Handlers for typed from ports
// ----------------------------------------------------------------------

void Tester ::from_gpioSet_handler(const NATIVE_INT_TYPE portNum, const Fw::Logic& state) {
void LedTester ::from_gpioSet_handler(const NATIVE_INT_TYPE portNum, const Fw::Logic& state) {
this->pushFromPortEntry_gpioSet(state);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
#define TESTER_HPP

#include "Components/Led/Led.hpp"
#include "GTestBase.hpp"
#include "LedGTestBase.hpp"

namespace Components {

class Tester : public LedGTestBase {
class LedTester : public LedGTestBase {
// ----------------------------------------------------------------------
// Construction and destruction
// ----------------------------------------------------------------------
Expand All @@ -25,13 +25,13 @@ class Tester : public LedGTestBase {
// Queue depth supplied to component instance under test
static const NATIVE_INT_TYPE TEST_INSTANCE_QUEUE_DEPTH = 10;

//! Construct object Tester
//! Construct object LedTester
//!
Tester();
LedTester();

//! Destroy object Tester
//! Destroy object LedTester
//!
~Tester();
~LedTester();

public:
// ----------------------------------------------------------------------
Expand Down
56 changes: 0 additions & 56 deletions Components/Led/test/ut/TesterHelpers.cpp

This file was deleted.

25 changes: 11 additions & 14 deletions docs/component-implementation-1.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ It is time to create the basic component. In a terminal, navigate to the project

```bash
# In led-blinker
mkdir -p Components
cd Components

fprime-util new --component
Expand Down Expand Up @@ -75,8 +74,8 @@ Enable Parameters?:
1 - yes
2 - no
Choose from 1, 2 [1]: 1
[INFO] Found CMake file at 'LedBLinker/project.cmake'
Add component Led to led-blinker/project.cmake at end of file (yes/no)? yes
[INFO] Found CMake file at 'led-blinker/Components/CMakeLists.txt'
Add component Led to led-blinker/Components/CMakeLists.txt at end of file (yes/no)? yes
Generate implementation files (yes/no)? yes
```
Your new component is located in the directory `led-blinker/Components/Led`.
Expand All @@ -85,7 +84,13 @@ Your new component is located in the directory `led-blinker/Components/Led`.

Many of the behaviors of the component discussed in the [Component Design](#component-design) section require the tracking of some state. Before diving into the implementation of the behavior let us set up and initialize that state.

Open `Led.hpp` in `led-blinker/Components/Led`, and add the following private member variables to the end of the file just before the two closing `}` of the class defintion and namespace.
Open `Led.hpp` in `led-blinker/Components/Led`. Add the following to the top of the `Led.hpp`:

```c++
#include <Os/Mutex.hpp>
```

Next, add the following private member variables to the end of the file just before the two closing `}` of the class defintion and namespace.

```cpp
Os::Mutex lock; //! Protects our data from thread race conditions
Expand All @@ -95,12 +100,6 @@ Open `Led.hpp` in `led-blinker/Components/Led`, and add the following private me
bool blinking; //! Flag: if true then LED blinking will occur else no blinking will happen
```

Add the following to the top of the `Led.hpp`:

```c++
#include <Os/Mutex.hpp>
```

Open `Led.cpp` in `led-blinker/Components/Led`, and initialize your member variables in the constructor:

```cpp
Expand Down Expand Up @@ -139,7 +138,7 @@ Replace that block with the following:
)
```
Exit the text editor, and run the following in the `led-blinker/Components/Led` directory:
Save the file, exit the text editor, and run the following in the `led-blinker/Components/Led` directory:
```bash
# In led-blinker/Components/Led
Expand Down Expand Up @@ -312,8 +311,6 @@ fprime-util build
## Conclusion

Congratulations! You have now implemented some basic functionality in a new F´ component. Before finishing the implementation, let's take a break and try running the above command through the ground system. This will require integrating the component into the system topology.

> When running in the ground system try running `led.BLINKING_ON_OFF` with a value of `ON` and ensure that the event `SetBlinkingState` is emitted indicating the blinking switched to on!
Congratulations! You have now implemented some basic functionality in a new F´ component. Before finishing the implementation, let's take a break and try running the above command through the ground system. This will require integrating the component into the system topology, which we will get into in the next section.

### Next Step: [Initial Component Integration](./initial-integration.md).
18 changes: 10 additions & 8 deletions docs/component-implementation-2.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ Save the file. In the terminal, run the following to verify your component is bu
fprime-util build
```

In your `led-blinker/Components/Led` directory, open the file `Led.hpp` and add the following function signature:
In your `led-blinker/Components/Led` directory, open the file `Led.hpp` and add the following function signature in the `PRIVATE:` scope:

```cpp
//! Emit parameter updated EVR
Expand Down Expand Up @@ -258,14 +258,17 @@ In your `led-blinker/Components/Led` directory, open `Led.cpp`, copy in the foll
}
else
{
// Port may not be connected, so check before sending output
if (this->isConnected_gpioSet_OutputPort(0))
if(this->state == Fw::On::ON)
{
this->gpioSet_out(0, Fw::Logic::LOW);
}
// Port may not be connected, so check before sending output
if (this->isConnected_gpioSet_OutputPort(0))
{
this->gpioSet_out(0, Fw::Logic::LOW);
}

this->state = Fw::On::OFF;
// TODO: Add an event to report the LED state (this->state).
this->state = Fw::On::OFF;
// TODO: Add an event to report the LED state (this->state).
}
}
}
```
Expand All @@ -285,7 +288,6 @@ Below is a table with tasks you should complete. These tasks require you to go b

| Task | Missing function calls |
|-------|-------------|
| Inside the `BLINKING_ON_OFF` command handler, report the blinking state via a telemetry channel. | `this->tlmWrite_BlinkingState(on_off);`|
| Inside the `parameterUpdated` function, add a severity activity high event named `BlinkIntervalSet` that takes in an argument of type `U32` to report the blink interval. | Left as an exercise for the reader. |
| Inside the `run_handler` port handler, get the `BLINK_INTERVAL` parameter value. | Left as an exercise for the reader. |
| Inside the `run_handler` port handler, add a telemetry channel to report the number of LED transitions. | Left as an exercise for the reader. |
Expand Down
5 changes: 1 addition & 4 deletions docs/full-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,13 @@ To do this, add the following lines to `led-blinker/LedBLinker/Top/topology.fpp`

So far the GPIO driver has been instantiated and wired, but has not been told what GPIO pin to control. For this tutorial, GPIO pin 13 will be used. To configure this, the `open` function needs to be called in the topology's C++ implementation and passed the pin's number and direction.

This is done by adding the following line to the `configureTopology` function defined in `led-blinker/LedBLinker/Top/LedBLinkerTopology.cpp`.
This is done by adding the following at the end of the `configureTopology` function defined in `led-blinker/LedBLinker/Top/LedBLinkerTopology.cpp`:

```
void configureTopology() {
...
bool gpio_success = gpioDriver.open(13, Drv::LinuxGpioDriver::GpioDirection::GPIO_OUT);
if (!gpio_success) {
Fw::Logger::logMsg("[ERROR] Failed to open GPIO pin\n");
}
}
```

This code tells the GPIO driver to open pin 13 as an output pin. If this fails, an error is printed to the console, but the system continues to start.
Expand Down
15 changes: 8 additions & 7 deletions docs/initial-integration.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# LED Blinker: Initial Component Integration

In this section, users will create a deployment and perform the initial integration the LED component into that deployment. This deployment will automatically include the basic command and data handling setup needed to interact with the component. Wiring the `Led` component to the GPIO driver component will be covered in a later section after the component implementation has finished.
In this section, users will create a deployment and perform the initial integration of the LED component into that deployment. This deployment will automatically include the basic command and data handling setup needed to interact with the component. Wiring the `Led` component to the GPIO driver component will be covered in a later section after the component implementation has finished.

> Users must have created the [initial Led component implementation](./component-implementation-1.md) in order to run through this section. Users may continue to define commands, events, telemetry, and ports after this initial integration.
Expand Down Expand Up @@ -31,14 +31,14 @@ Add component LedBlinker to led-blinker/project.cmake at end of file? (yes/no) [
In order to check that the deployment was created successfully, the user can build the deployment. This will build the code for the current host system, not the remote embedded hardware allowing local testing during development.

> This will reuse the build cache created during the project creation.
```shell
# In led-blinker
cd LedBlinker
fprime-util build
```

> This will reuse the build cache created during the project creation. CMake warnings may appear to indicate that the build cache is refreshing. The build should start shortly thereafter.
## Adding `Led` Component To The Deployment

The component can now be added to the deployment's topology effectively adding this component to the running system. This is done by modifying `instances.fpp` and `topology.fpp` in the `Top` directory.
Expand All @@ -54,12 +54,13 @@ Add the following to `led-blinker/LedBlinker/Top/instances.fpp`. Typically, thi

This defines an instance of the `Led` component called `led`. Since the component is active it needs a queue size, stack size, and priority for the thread of the component and the queue that thread serves. We have chosen the topology specified defaults and a priority of 95.

Next, the topology needs to use the above definition. This is done by adding the following to the list of instances defined in `led-blinker/LedBlinker/Top/topology.fpp`.
Next, the topology needs to use the above definition. This is done by adding the `led` instance to the list of instances defined in `led-blinker/LedBlinker/Top/topology.fpp`:

```
topology LedBlinker {
...
instance ...
# ----------------------------------------------------------------------
# Instances used in the topology
# ----------------------------------------------------------------------
instance led
```

Expand Down
5 changes: 2 additions & 3 deletions docs/project-setup.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# LED Blinker: Project Setup

First, make sure to read the tutorial's [readme](../README.md) and follow the [prerequisites section](../README.md#prerequisites). Then set up a new F´ project using the `fprime-util new --project` command. Please select a project name of `led-blinker`, an F´ version of `devel`, and to create a project virtual environment.
First, make sure to read the tutorial's [readme](../README.md) and follow the [prerequisites section](../README.md#prerequisites). Then set up a new F´ project using the `fprime-util new --project` command. Please select a project name of `led-blinker`, and select `yes` to installing the development tools.

> Remember to activate the virtual environment you created when installing F´.
Expand All @@ -12,9 +12,8 @@ $ fprime-util new --project
2 - no
Choose from [1/2] (1): 1
```
> If you bootstrapped the F´ tools in a virtual environment `deactivate` that environment before activating the new one below.

Next, activate the new virtual environment and generate a build cache using the following commands:
Next, generate a build cache using the following commands:

```
cd led-blinker
Expand Down
Loading

0 comments on commit 5e6dba0

Please sign in to comment.