Skip to content

Commit

Permalink
Update led issue 2839 (#76)
Browse files Browse the repository at this point in the history
* Update fpp model (#56)

* Fixing changes to OSAL Tasks (#65)

Co-authored-by: Michael D Starch <Michael.D.Starch@jpl.nasa.gov>

* Update hpp copy paste code to include the override keyword to match the generated code (#68)

* Update instructions to reference install guide (#57)

* Update pre-requisites (#59)

* Update project name (#60)

* Add override to parameterUpdated (#63)

* Fix typos in requirements.md (#64)

* Update fprime git submodule to use https (#66)

* update hpp copy paste code to include the override keyword to match the generated code

---------

Co-authored-by: Thomas Boyer-Chammard <49786685+thomas-bc@users.noreply.github.com>
Co-authored-by: Nate Gay <email@n8.gay>
Co-authored-by: Roberto Valenzuela <valenzuelarober@gmail.com>
Co-authored-by: Joshua Anderson <joshua.l.anderson@jpl.nasa.gov>
Co-authored-by: crsmith <celeste.r.smith@jpl.nasa.gov>

* Fixes for nasa/fprime#2831  (#71)

* Fixes for nasa/fprime#2831

* Missing logger import

* Fixes for nasa/fprime#2823 (#73)

* update for compatibility with fpp #349

* update integration tests

---------

Co-authored-by: jawest <justine.a.west@jpl.nasa.gov>

* Update LedBlinkerPackets.xml (#74)

Remove systemResources TLM channels from deployment so pr-2866 can run successfully

Co-authored-by: Shivaly-Reddy <164100839+Shivaly-Reddy@users.noreply.github.com>

* Phase 1 State Machine changes (nasa/fprime#2829) (#75)

* Reworking tutorial to match improved workflow

reordering the sections so they better match best software engineering practices
updated parameterUpdated to use a switch statement
formatting
enum argument checking happens under the hood; so, removing the check from command handler. Also removing the EVR from fpp
marking which portion of the documentation needs to be updated to remove non-existing evr
using async instead of sync. No real good reason to use sync here, and async makes the code implementation issuer (avoid using mutex)
removing mutex and its use since we switch run handler to async port
updating documentation to remove mutex/lock
using member variable convention
updated member variables to use correct name. also fixed formatting
updated documentation to use new member variables
updated documentation to use new member variables
updated documentation to use new member variables
Adding formatting file from fprime
added missing step
Added clarifying note
updated day of component implementation
typo
using async port. improving parameterUpdated function
Added sequence diagram explaining blink command
removed unneeded tlm xml section. cleaned up code to use switch statement
adding missing dodispatch now that the run port in an async port
Having this parameter is critical for the unit test portion. Add it here and not leave it up to the students to add
Updating uts so they don't depend on 'try it yourself' activity
updated UT doc
fixed typos
fixed markdown formatting
making comments and signatures consistent with latest fprime-util
formatting
adding default value to parameter
adding default value to parameter
typo
Readding param get try-it-yourself task. It's a good exercise for the students to have
Readding since it's better for the reader to exercise these aspects
simplified run handler
Updated documentation so that all design for day 1 is together and all initial implementation for day 2 is together. This better follows the design and implementation workflow that we use when developing software
minor format updates
Updating words per review
Updated documentation so that all design for day 2 is together and all continued implementation for day 2 is together. This better follows the design and implementation workflow that we use when developing software
Using event instead of EVR since the word event is more consitent throughout the tutorial
Formatting
Formatting
Fixing title
giving member variable a better name and updating code in tutorial to match latest code
Updated documents per review
Adding spoiler tags around answers
fixing camelcase and comments
fixed code formatting to match fprime's formatting
fixing formatting
Updating per review.
fixing. want to use camel case
fixed formatting of UTs

* fixing formatting of code

* updated fprime pointer to point to latest in devel

* updated to work with packet tlm xml commented out. Also loading parameters as we should be

* Updated pointer to use latest fprime tag 3.5.0

* Escaping key word

* typo

* fixing gpio configuration to match with fprime 3.5.0

* fixed code for config of gpio

* updated led blinker for fprime 3.5.0

* Adding answer so tut flows better

---------

Co-authored-by: Rob Bocchino <bocchino@icloud.com>
Co-authored-by: Thomas Boyer-Chammard <49786685+thomas-bc@users.noreply.github.com>
Co-authored-by: Michael D Starch <Michael.D.Starch@jpl.nasa.gov>
Co-authored-by: csmith608 <63731123+csmith608@users.noreply.github.com>
Co-authored-by: Nate Gay <email@n8.gay>
Co-authored-by: Roberto Valenzuela <valenzuelarober@gmail.com>
Co-authored-by: Joshua Anderson <joshua.l.anderson@jpl.nasa.gov>
Co-authored-by: crsmith <celeste.r.smith@jpl.nasa.gov>
Co-authored-by: M Starch <LeStarch@googlemail.com>
Co-authored-by: Justine West <35715959+jwest115@users.noreply.github.com>
Co-authored-by: jawest <justine.a.west@jpl.nasa.gov>
Co-authored-by: Shivaly-Reddy <164100839+Shivaly-Reddy@users.noreply.github.com>
  • Loading branch information
13 people authored Oct 16, 2024
1 parent 5c1dc1c commit 7a80654
Show file tree
Hide file tree
Showing 30 changed files with 791 additions and 831 deletions.
5 changes: 5 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
BasedOnStyle: Chromium
IndentWidth: 4
ColumnLimit: 120
AccessModifierOffset: -2
24 changes: 18 additions & 6 deletions Components/Led/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
####
# F prime CMakeLists.txt:
#
# SOURCE_FILES: combined list of source and autocoding files
# MOD_DEPS: (optional) module dependencies
# UT_SOURCE_FILES: list of source files for unit tests
#
####
set(SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/Led.fpp"
"${CMAKE_CURRENT_LIST_DIR}/Led.cpp"
"${CMAKE_CURRENT_LIST_DIR}/Led.fpp"
"${CMAKE_CURRENT_LIST_DIR}/Led.cpp"
)

# Uncomment and add any modules that this component depends on, else
# they might not be available when cmake tries to build this component.

# set(MOD_DEPS
# Add your dependencies here
# )

register_fprime_module()

set(UT_SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/Led.fpp"
"${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
)
set(UT_AUTO_HELPERS ON) # Additional Unit-Test autocoding
register_fprime_ut()
121 changes: 49 additions & 72 deletions Components/Led/Led.cpp
Original file line number Diff line number Diff line change
@@ -1,123 +1,100 @@
// ======================================================================
// \title Led.cpp
// \author mstarch, ortega
// \author ortega
// \brief cpp file for Led component implementation class
// ======================================================================

#include <Components/Led/Led.hpp>
#include <FpConfig.hpp>
#include "Components/Led/Led.hpp"
#include "FpConfig.hpp"

namespace Components {

// ----------------------------------------------------------------------
// Construction, initialization, and destruction
// Component construction and destruction
// ----------------------------------------------------------------------

Led ::Led(const char* const compName)
: LedComponentBase(compName), state(Fw::On::OFF), transitions(0), count(0), blinking(false) {}
Led ::Led(const char* const compName) : LedComponentBase(compName) {}

Led ::~Led() {}

void Led ::parameterUpdated(FwPrmIdType id) {
// Read back the parameter value
Fw::ParamValid isValid;
U32 interval = this->paramGet_BLINK_INTERVAL(isValid);
// NOTE: isValid is always
FW_ASSERT(isValid == Fw::ParamValid::VALID, isValid);

// Check the parameter ID is expected
if (PARAMID_BLINK_INTERVAL == id) {
{
// Emit the blink set event
switch (id) {
case PARAMID_BLINK_INTERVAL: {
// Read back the parameter value
const U32 interval = this->paramGet_BLINK_INTERVAL(isValid);
// NOTE: isValid is always VALID in parameterUpdated as it was just properly set
FW_ASSERT(isValid == Fw::ParamValid::VALID, isValid);

// Emit the blink interval set event
this->log_ACTIVITY_HI_BlinkIntervalSet(interval);
break;
}
default:
FW_ASSERT(0, static_cast<FwAssertArgType>(id));
break;
}
}

// ----------------------------------------------------------------------
// Handler implementations for user-defined typed input ports
// ----------------------------------------------------------------------

void Led ::run_handler(const NATIVE_INT_TYPE portNum, NATIVE_UINT_TYPE context) {
void Led ::run_handler(NATIVE_INT_TYPE portNum, NATIVE_UINT_TYPE context) {
// Read back the parameter value
Fw::ParamValid isValid;
Fw::ParamValid isValid = Fw::ParamValid::INVALID;
U32 interval = this->paramGet_BLINK_INTERVAL(isValid);

// Force interval to be 0 when invalid or not set
interval = ((Fw::ParamValid::INVALID == isValid) || (Fw::ParamValid::UNINIT == isValid)) ? 0 : interval;
interval = ((isValid == Fw::ParamValid::INVALID) || (isValid == Fw::ParamValid::UNINIT)) ? 0 : interval;

// Only perform actions when set to blinking
this->lock.lock();
bool is_blinking = this->blinking;
this->lock.unlock();
if (is_blinking) {
Fw::On new_state = this->state;
// Check for transitions
if ((0 == this->count) && (this->state == Fw::On::OFF)) {
new_state = Fw::On::ON;
} else if (((interval / 2) == this->count) && (this->state == Fw::On::ON)) {
new_state = Fw::On::OFF;
}

// A transition has occurred
if (this->state != new_state) {
this->transitions = this->transitions + 1;
this->tlmWrite_LedTransitions(this->transitions);
if (this->m_blinking && (interval != 0)) {
// If toggling state
if (this->m_toggleCounter == 0) {
// Toggle state
this->m_state = (this->m_state == Fw::On::ON) ? Fw::On::OFF : Fw::On::ON;
this->m_transitions++;
this->tlmWrite_LedTransitions(this->m_transitions);

// Port may not be connected, so check before sending output
if (this->isConnected_gpioSet_OutputPort(0)) {
this->gpioSet_out(0, (Fw::On::ON == new_state) ? Fw::Logic::HIGH : Fw::Logic::LOW);
this->gpioSet_out(0, (Fw::On::ON == this->m_state) ? Fw::Logic::HIGH : Fw::Logic::LOW);
}

this->log_ACTIVITY_LO_LedState(new_state);
this->state = new_state;
this->log_ACTIVITY_LO_LedState(this->m_state);
}

this->count = ((this->count + 1) >= interval) ? 0 : (this->count + 1);
this->m_toggleCounter = (this->m_toggleCounter + 1) % interval;
}
// We are not blinking
else {
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);
if (this->m_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->m_state = Fw::On::OFF;
this->log_ACTIVITY_LO_LedState(this->m_state);
}
}
}

// ----------------------------------------------------------------------
// Command handler implementations
// Handler implementations for commands
// ----------------------------------------------------------------------

void Led ::BLINKING_ON_OFF_cmdHandler(const FwOpcodeType opCode, const U32 cmdSeq, Fw::On on_off) {
// Create a variable to represent the command response
auto cmdResp = Fw::CmdResponse::OK;

// Verify if on_off is a valid argument.
// Note: isValid is an autogenerate helper function for enums defined in fpp.
if (!on_off.isValid()) {
// NOTE: Add this event after going through the "Events" exercise.
this->log_WARNING_LO_InvalidBlinkArgument(on_off);

// Update command response with a validation error
cmdResp = Fw::CmdResponse::VALIDATION_ERROR;
} else {
this->count = 0; // Reset count on any successful command
this->lock.lock();
this->blinking = Fw::On::ON == on_off; // Update blinking state
this->lock.unlock();
// NOTE: This event will be added during the "Events" exercise.
this->log_ACTIVITY_HI_SetBlinkingState(on_off);

this->tlmWrite_BlinkingState(on_off);
}
void Led ::BLINKING_ON_OFF_cmdHandler(FwOpcodeType opCode, U32 cmdSeq, Fw::On onOff) {
this->m_toggleCounter = 0; // Reset count on any successful command
this->m_blinking = Fw::On::ON == onOff; // Update blinking state

this->log_ACTIVITY_HI_SetBlinkingState(onOff);

this->tlmWrite_BlinkingState(onOff);

// Provide command response
this->cmdResponse_out(opCode, cmdSeq, cmdResp);
this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
}

} // end namespace Components
} // namespace Components
15 changes: 5 additions & 10 deletions Components/Led/Led.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Components {

@ Command to turn on or off the blinking LED
async command BLINKING_ON_OFF(
on_off: Fw.On @< Indicates whether the blinking should be on or off
onOff: Fw.On @< Indicates whether the blinking should be on or off
)

@ Telemetry channel to report blinking state.
Expand All @@ -13,18 +13,13 @@ module Components {
@ Telemetry channel counting LED transitions
telemetry LedTransitions: U64

@ Indicates we received an invalid argument.
event InvalidBlinkArgument(badArgument: Fw.On) \
severity warning low \
format "Invalid Blinking Argument: {}"

@ Reports the state we set to blinking.
event SetBlinkingState(state: Fw.On) \
event SetBlinkingState($state: Fw.On) \
severity activity high \
format "Set blinking state to {}."

@ Event logged when the LED turns on or off
event LedState(on_off: Fw.On) \
event LedState(onOff: Fw.On) \
severity activity low \
format "LED is {}"

Expand All @@ -34,10 +29,10 @@ module Components {
format "LED blink interval set to {}"

@ Blinking interval in rate group ticks
param BLINK_INTERVAL: U32
param BLINK_INTERVAL: U32 default 1

@ Port receiving calls from the rate group
sync input port run: Svc.Sched
async input port run: Svc.Sched

@ Port sending calls to the GPIO driver
output port gpioSet: Drv.GpioWrite
Expand Down
89 changes: 45 additions & 44 deletions Components/Led/Led.hpp
Original file line number Diff line number Diff line change
@@ -1,71 +1,72 @@
// ======================================================================
// \title Led.hpp
// \author mstarch, ortega
// \author ortega
// \brief hpp file for Led component implementation class
// ======================================================================

#ifndef Led_HPP
#define Led_HPP
#include <Os/Mutex.hpp>
#ifndef Components_Led_HPP
#define Components_Led_HPP

#include "Components/Led/LedComponentAc.hpp"

namespace Components {

class Led : public LedComponentBase {
public:
// ----------------------------------------------------------------------
// Construction, initialization, and destruction
// Component construction and destruction
// ----------------------------------------------------------------------

//! Construct object Led
//!
Led(const char* const compName /*!< The component name*/
//! Construct Led object
Led(const char* const compName //!< The component name
);

//! Destroy object Led
//!
//! Destroy Led object
~Led();

PRIVATE:
//! Emit parameter updated EVR
//!
void parameterUpdated(FwPrmIdType id /*!< The parameter ID*/
);
PRIVATE :
//! Emit parameter updated EVR
//!
void
parameterUpdated(FwPrmIdType id //!< The parameter ID
) override;

PRIVATE:
// ----------------------------------------------------------------------
// Command handler implementations
// ----------------------------------------------------------------------
PRIVATE :

//! Implementation for BLINKING_ON_OFF command handler
//! Command to turn on or off the blinking LED
void BLINKING_ON_OFF_cmdHandler(const FwOpcodeType opCode, /*!< The opcode*/
const U32 cmdSeq, /*!< The command sequence number*/
Fw::On on_off /*!<
Indicates whether the blinking should be on or off
*/
);
// ----------------------------------------------------------------------
// Handler implementations for user-defined typed input ports
// ----------------------------------------------------------------------

PRIVATE:
// ----------------------------------------------------------------------
// Handler implementations for user-defined typed input ports
// ----------------------------------------------------------------------
//! Handler implementation for run
//!
//! Port receiving calls from the rate group
void
run_handler(NATIVE_INT_TYPE portNum, //!< The port number
NATIVE_UINT_TYPE context //!< The call order
) override;

//! Handler implementation for run
//!
void run_handler(const NATIVE_INT_TYPE portNum, /*!< The port number*/
NATIVE_UINT_TYPE context /*!<
The call order
*/
);
PRIVATE :
// ----------------------------------------------------------------------
// Handler implementations for commands
// ----------------------------------------------------------------------

//! Handler implementation for command BLINKING_ON_OFF
//!
//! Command to turn on or off the blinking LED
void
BLINKING_ON_OFF_cmdHandler(FwOpcodeType opCode, //!< The opcode
U32 cmdSeq, //!< The command sequence number
Fw::On onOff //!< Indicates whether the blinking should be on or off
) override;

Os::Mutex lock; //! Protects our data from thread race conditions
Fw::On state; //! Keeps track if LED is on or off
U64 transitions; //! The number of on/off transitions that have occurred from FSW boot up
U32 count; //! Keeps track of how many ticks the LED has been on for
bool blinking; //! Flag: if true then LED blinking will occur else no blinking will happen
Fw::On m_state = Fw::On::OFF; //! Keeps track if LED is on or off
U64 m_transitions = 0; //! The number of on/off transitions that have occurred
//! from FSW boot up
U32 m_toggleCounter = 0; //! Keeps track of how many ticks the LED has been on for
bool m_blinking = false; //! Flag: if true then LED blinking will occur else
//! no blinking will happen
};

} // end namespace Components
} // namespace Components

#endif
Binary file added Components/Led/docs/blink-cmd.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions Components/Led/docs/blink-cmd.uml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```plantuml
@startuml
ground -> cmdDispatcher: Turn On/Off blink
cmdDispatcher -> led: Turn On/Off blink
led -> led: Sets its blinking state to commanded state
@enduml
```
Loading

0 comments on commit 7a80654

Please sign in to comment.