Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: ICE-Application/src/ConfigurationHandler/Controls/SequenceControl.h
- Revision:
- 0:61364762ee0e
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ICE-Application/src/ConfigurationHandler/Controls/SequenceControl.h Tue Jan 24 19:05:33 2017 +0000 @@ -0,0 +1,139 @@ +/****************************************************************************** + * + * File: SetpointControl.h + * Desciption: ICE Timer Control Class + * + *****************************************************************************/ +#ifndef SEQUENCECONTROL_H +#define SEQUENCECONTROL_H + +#include <global.h> +#include <string> +#include <stdio.h> +#include <vector> + +#define SEQUENCE_CONTROL_DEBUG +#define SEQUENCE_CONTROL_FILENAME_PREFIX "seq_" + +typedef enum { + SEQUENCE_CONTROL_OK, + SEQUENCE_CONTROL_UNK_STATE, + SEQUENCE_CONTROL_ERROR, + SEQUENCE_CONTROL_DESTROY, + SEQUENCE_CONTROL_BAD_CONTROL_TYPE, + SEQUENCE_CONTROL_BAD_ACTION +} SequenceControlError_t; + +//! SequenceControl - implements a sequence control that is comprised of +// sub-controls and operations to achieve a sequence of activities. +class SequenceControl +{ +private: + std::string controlFile; // the control file + std::string id; // unique identifier + std::string startTrigger; // start trigger: once the start + // trigger evals to true, the + // control will start executing + // the entries in the sequence table + + typedef struct Action_tag { + std::string action; // create/delete/execute + std::string id; // control, vreg or script identifier + float value; // for assignment action + } Action_t; + + // A Sequence Entry: + // + // startTrigger -> an expression that evals to true + // actions[] -> list of actions to perform when the start condition is satisfied + // stopTrigger -> an expression that evals to true + // + typedef struct SequenceEntry_tag { + std::string startTrigger; // trigger to load the sequence + std::vector<Action_t> actions; // actions to perform + std::string stopTrigger; // trigger to load the next entry + } SequenceEntry; + + // the sequence table + std::vector<SequenceEntry> sequenceTable; + + // state machine information + enum SequenceControlState_t { + SEQ_STATE_INIT, // object successfully created + SEQ_STATE_START, // object programmatically started + SEQ_STATE_LOADING_NEXT_ENTRY, // loading the next entry (transient) + SEQ_STATE_WAITING_START, // waiting for entry start trigger(s) + SEQ_STATE_WAITING_STOP, // waiting for entry stop trigger(s) + SEQ_STATE_FINISHED, // finished with all entries in the sequence table + SEQ_STATE_FAILED, // something went awry + SEQ_STATE_MAX + }; + + SequenceControlState_t currentState; // control's current state + SequenceEntry currentEntry; // currently loaded entry in the seq table + unsigned int nextEntryIndex; // next entry index + + /// validate the contents of the control file + bool validateControlData(const char *); + + /// assign control data from control file to object data + void copyControlData(const char *); + + /// has the control starting trigger fired? + bool isControlStartTriggerOn(void); + + /// has the sequence entry starting trigger fired? + bool isCurrentEntryStartTriggerOn(void); + + /// has the sequence entry stopping trigger fired? + bool isCurrentEntryStopTriggerOn(void); + + /// load the next entry from the sequence table + bool loadNextEntry(void); + + /// perform the actions from the sequence entry + SequenceControlError_t performActions(void); + + /// create a control from the sequence table + SequenceControlError_t createSubControl(const std::string controlId, + Control_t type); + + /// delete a control from the sequence table + SequenceControlError_t destroySubControl(const std::string controlId, + Control_t type); + + /// assign a virtual register + bool assignRegister(const std::string id, float value); + +public: + /// create a sequence control + SequenceControl() { + currentState = SEQ_STATE_INIT; + nextEntryIndex = 0; + }; + /// destructor + ~SequenceControl() { + printf("\r%s invoked\n", __func__); + } + + /// load sequence control data from a JSON configuration file + bool load(std::string filename); + + /// start the sequence control + void start(void); + + /// the motor + SequenceControlError_t run(void); + + /// display the pertinents + void display(void); + + /// get sequence control identifier + std::string getId(void) const { return id; } + + /// get starting trigger + std::string getStartTrigger(void) const { return startTrigger; } +}; + +#endif +