Skip to content

Commit

Permalink
Get unit tests updated and working for fpp state machines phase 1 del…
Browse files Browse the repository at this point in the history
…ivery
  • Loading branch information
watney committed Aug 28, 2024
1 parent ff7b023 commit 08d8135
Show file tree
Hide file tree
Showing 13 changed files with 363 additions and 26 deletions.
2 changes: 2 additions & 0 deletions FppTest/state_machine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ set(SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/SmTest.cpp"
"${CMAKE_CURRENT_LIST_DIR}/SmTest.fpp"
"${CMAKE_CURRENT_LIST_DIR}/DeviceSm.cpp"
"${CMAKE_CURRENT_LIST_DIR}/HackSm.cpp"
)
set(MOD_DEPS Fw/SMSignal)

Expand All @@ -13,6 +14,7 @@ set(UT_SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/test/ut/Tester.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/TesterHelpers.cpp"
"${CMAKE_CURRENT_LIST_DIR}/DeviceSm.cpp"
"${CMAKE_CURRENT_LIST_DIR}/HackSm.cpp"
)
set(UT_MOD_DEPS STest)
register_fprime_ut()
25 changes: 19 additions & 6 deletions FppTest/state_machine/DeviceSm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,19 @@
#include "DeviceSm.hpp"


void FppTest::DeviceSm::init()
void FppTest::DeviceSm::init(const FwEnumStoreType stateMachineId)
{
parent->DeviceSm_turnOff(stateMachineId);
this->state = OFF;

}


void FppTest::DeviceSm::update(const DeviceSmEvents signal, const Fw::SMSignalBuffer &data)
void FppTest::DeviceSm::update(
const FwEnumStoreType stateMachineId,
const DeviceSm_Interface::DeviceSmEvents signal,
const Fw::SMSignalBuffer &data
)
{
switch (this->state) {

Expand All @@ -30,8 +35,12 @@ void FppTest::DeviceSm::update(const DeviceSmEvents signal, const Fw::SMSignalBu

switch (signal) {

case RTI_SIG:
this->state = ON;
case DeviceSm_Interface::DeviceSmEvents::RTI_SIG:
if ( parent->DeviceSm_g1(stateMachineId) ) {
parent->DeviceSm_a1(stateMachineId, signal, data);
parent->DeviceSm_turnOn(stateMachineId);
this->state = ON;
}

break;

Expand All @@ -47,8 +56,12 @@ void FppTest::DeviceSm::update(const DeviceSmEvents signal, const Fw::SMSignalBu

switch (signal) {

case RTI_SIG:
this->state = OFF;
case DeviceSm_Interface::DeviceSmEvents::RTI_SIG:
if (parent->DeviceSm_g2(stateMachineId, signal, data) ) {
parent->DeviceSm_a2(stateMachineId);
parent->DeviceSm_turnOff(stateMachineId);
this->state = OFF;
}

break;

Expand Down
42 changes: 35 additions & 7 deletions FppTest/state_machine/DeviceSm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define DEVICESM_H_

#include <Fw/SMSignal/SMSignalBuffer.hpp>
#include <config/FpConfig.hpp>

namespace Fw {
class SMSignals;
Expand All @@ -19,6 +20,34 @@ namespace FppTest {

class DeviceSm_Interface {
public:
enum DeviceSmEvents {
RTI_SIG,
};


virtual bool DeviceSm_g1(const FwEnumStoreType stateMachineId) = 0;


virtual bool DeviceSm_g2(
const FwEnumStoreType stateMachineId,
const DeviceSm_Interface::DeviceSmEvents signal,
const Fw::SMSignalBuffer &data) = 0;


virtual void DeviceSm_turnOff(const FwEnumStoreType stateMachineId) = 0;


virtual void DeviceSm_a1(
const FwEnumStoreType stateMachineId,
const DeviceSm_Interface::DeviceSmEvents signal,
const Fw::SMSignalBuffer &data) = 0;


virtual void DeviceSm_turnOn(const FwEnumStoreType stateMachineId) = 0;


virtual void DeviceSm_a2(const FwEnumStoreType stateMachineId) = 0;


};

Expand All @@ -35,18 +64,17 @@ class DeviceSm {
OFF,
ON,
};

enum DeviceSmEvents {
RTI_SIG,
};

enum DeviceSmStates state;

void * extension;

void init();
void update(const DeviceSmEvents signal, const Fw::SMSignalBuffer &data);

void init(const FwEnumStoreType stateMachineId);
void update(
const FwEnumStoreType stateMachineId,
const DeviceSm_Interface::DeviceSmEvents signal,
const Fw::SMSignalBuffer &data
);
};

}
Expand Down
7 changes: 4 additions & 3 deletions FppTest/state_machine/DeviceSm.plantuml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
[*] --> OFF

state OFF {
OFF::Entry: turnOff()
}

state ON {

ON::Entry: turnOn()
}

OFF --> ON : RTI
ON --> OFF : RTI
OFF --> ON : RTI [g1()]/a1(e)
ON --> OFF : RTI [g2(e)]/a2()
@enduml
2 changes: 0 additions & 2 deletions FppTest/state_machine/DeviceSm.trans

This file was deleted.

100 changes: 100 additions & 0 deletions FppTest/state_machine/HackSm.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@

// ======================================================================
// \title HackSm.cpp
// \author Auto-generated
// \brief cpp file for state machine HackSm
//
// ======================================================================

#include "stdio.h"
#include "assert.h"
#include "Fw/Types/SMSignalsSerializableAc.hpp"
#include "HackSm.hpp"


void FppTest::HackSm::init(const FwEnumStoreType stateMachineId)
{
parent->HackSm_turnOff(stateMachineId);
this->state = OFF;

}


void FppTest::HackSm::update(
const FwEnumStoreType stateMachineId,
const HackSm_Interface::HackSmEvents signal,
const Fw::SMSignalBuffer &data
)
{
switch (this->state) {

/**
* state OFF
*/
case OFF:

switch (signal) {

case HackSm_Interface::HackSmEvents::RTI_SIG:
parent->HackSm_turnOn(stateMachineId);
this->state = ON;

break;

case HackSm_Interface::HackSmEvents::CHECK_SIG:
parent->HackSm_doDiag(stateMachineId);
this->state = DIAG;

break;

default:
break;
}
break;

/**
* state ON
*/
case ON:

switch (signal) {

case HackSm_Interface::HackSmEvents::RTI_SIG:
parent->HackSm_turnOff(stateMachineId);
this->state = OFF;

break;

case HackSm_Interface::HackSmEvents::CHECK_SIG:
parent->HackSm_doDiag(stateMachineId);
this->state = DIAG;

break;

default:
break;
}
break;

/**
* state DIAG
*/
case DIAG:

switch (signal) {

case HackSm_Interface::HackSmEvents::RTI_SIG:
parent->HackSm_turnOff(stateMachineId);
this->state = OFF;

break;

default:
break;
}
break;

default:
assert(0);
}
}
69 changes: 69 additions & 0 deletions FppTest/state_machine/HackSm.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@

// ======================================================================
// \title HackSm.h
// \author Auto-generated
// \brief header file for state machine HackSm
//
// ======================================================================

#ifndef HACKSM_H_
#define HACKSM_H_

#include <Fw/SMSignal/SMSignalBuffer.hpp>
#include <config/FpConfig.hpp>

namespace Fw {
class SMSignals;
}

namespace FppTest {

class HackSm_Interface {
public:
enum HackSmEvents {
RTI_SIG,
CHECK_SIG,
};


virtual void HackSm_turnOff(const FwEnumStoreType stateMachineId) = 0;


virtual void HackSm_turnOn(const FwEnumStoreType stateMachineId) = 0;


virtual void HackSm_doDiag(const FwEnumStoreType stateMachineId) = 0;


};

class HackSm {

private:
HackSm_Interface *parent;

public:

HackSm(HackSm_Interface* parent) : parent(parent) {}

enum HackSmStates {
OFF,
ON,
DIAG,
};

enum HackSmStates state;

void * extension;

void init(const FwEnumStoreType stateMachineId);
void update(
const FwEnumStoreType stateMachineId,
const HackSm_Interface::HackSmEvents signal,
const Fw::SMSignalBuffer &data
);
};

}

#endif
23 changes: 23 additions & 0 deletions FppTest/state_machine/HackSm.plantuml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

@startuml

[*] --> OFF

state OFF {
OFF::Entry: turnOff()
}

state ON {
ON::Entry: turnOn()
}

state DIAG {
DIAG::Entry: doDiag()
}

OFF --> ON : RTI
ON --> OFF : RTI
ON --> DIAG : CHECK
OFF --> DIAG : CHECK
DIAG --> OFF : RTI
@enduml
Loading

0 comments on commit 08d8135

Please sign in to comment.