/* * Scheduling.h * * Created on: Nov 5, 2019 * Author: mala */ #ifndef STUDIO_TMTCSERVICES_SCHEDULING_H_ #define STUDIO_TMTCSERVICES_SCHEDULING_H_ #include #include #include #include #include "ScheduleTableIF.h" //make sure this alias works in global scope typedef uint8_t SubscheduleId_t; /** * @brief manages onboard time-based schedule, PUS service 11 * @details * * This service is responsible in managing an onboard time-based schedule of telecommands. * The schedule can be through this service enabled, disabled, and time-shifted * It can support subschedules. subschedules can be created,enabled and disabled, and time-shifted * * The service stores the schedule in the ScheduleMap, which has a ScheduleMapIF. * Current Map includes subschedules, but it can be replaced by implementing the interface * The service also can pre-load commands through scheduleLoaderIF. * scheduleLoader and scheduleTable should be instantiated in factory * * right now we do not have control over one single command,in terms of * shift/disable/delete. it might be required in future though, *The following constants are in standards but not implemented in this version *Time margin declared static const Time_Based_Schedule_Margin *Time between specified release time and actual release time , maximum, declared * * @author M.Taheran * */ class OPS_Scheduling: public PusServiceBase { public: OPS_Scheduling(uint16_t apid,bool HasInitialSchedule, bool HasSubschedules); virtual ~OPS_Scheduling(); ReturnValue_t handleRequest(uint8_t subservice) override; ReturnValue_t performService() override; ReturnValue_t initialize() override; protected: ScheduleTableIF* scheduleMap = nullptr; ScheduleLoaderIF * scheduleLoader = nullptr; bool loadInitialSchedule; bool supportSubschedules; private: enum class subServices { static const uint8_t ENABLE_RELEASE_OF_TC = 1, static const uint8_t DISABLE_RELEASE_OF_TC =2, static const uint8_t ENABLE_SUBSCHEDULE = 20, static const uint8_t DISABLE_SUBSCHEDULE = 21, //static const uint8_t DELETE_TC = 5;//not implemented static const uint8_t RESET_SCHEDULE = 3, static const uint8_t TIMESHIFT_SCHEDULE = 15, static const uint8_t TIMESHIFT_SUBSCHEDULE = 8, static const uint8_t INSERT_TC_SCHEDULE = 4, //TODO //static const uint8_t REPORT_SCHEDULE = 16;//TM is type 10 }; //Interface and subsystem ID to be included in mission config static const unit8_t INTERFACE_ID = CLASS_ID::OPS_SCHEDULING_SERVICE; static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::OPS_SCHEDULER; //list of return codes, tbc static const ReturnValue_t TIME_ERROR = MAKE_RETURN_CODE (1); static const ReturnValue_t COMMAND_EXPIRED = MAKE_RETURN_CODE (2); static const ReturnValue_t ILLEGAL_APPLICATION_DATA= MAKE_RETURN_CODE (3); //static const ReturnValue_t SCHEDULE_MAP_FULL= MAKE_RETURN_CODE (4); static const ReturnValue_t INVALID_SHIFT= MAKE_RETURN_CODE (4); static const ReturnValue_t SCHEDULE_SHIFTED= MAKE_RETURN_CODE (5); static const ReturnValue_t SCHEDULE_SHIFT_FAILED= MAKE_RETURN_CODE (6); //list of events,tbc static const Event = OPS_SCHEDULE_DISABLED = MAKE_EVENT(1, SEVERITY::MEDIUM); static const Event = COMMAND_LOST = MAKE_EVENT (2, SEVERITY::LOW); static const Event = SCHEDULE_LOAD_FAILED = MAKE_EVENT (3, SEVERITY::MEDIUM); static const Event = SCHEDULE_LOADED_INCOMPLETE = MAKE_EVENT (4, SEVERITY::LOW); MessageQueueIF* commandQueue = nullptr; MessageQueueIF* eventQueue = nullptr; static const uint8_t N_POOLS = 4; static const uint16_t POOL_SIZES[N_POOLS]; static const uint16_t N_ELEMENTS[N_POOLS]; LocalPool commandStorage; //only used for reporting on incomplete loading uint8_t tcCounter = 0; bool SchedulingEnabled; bool NoTimeError; Returnvalue_t enableScheduling(); void disableScheduling(); ReturnValue_t enable_Subschedule (SubscheduleId_t SubScheduleID=0); ReturnValue_t disable_Subschedule(SubscheduleId_t SubScheduleID=0); Returnvalue_t resetSchedule(); Returnvalue_t insertCommandinSchedule(const uint8_t* data, uint16_t size); void do_Schedule(); void check_Events(); Returnvalue_t shift_Schedule (const uint8_t* data, uint16_t size); Returnvalue_t shift_SubSchedule (const uint8_t* data, uint16_t size); void shift_Subschedule_Map(OnboardSchedule_map::iterator it, timeval time_delta); void get_Subschedule(SubscheduleId_t* SubscheduleId,const uint8_t* data, uint32_t maxlength, uint32_t* foundlength, bool* NewId = false); ReturnValue_t loadSchedule(); void releaseCommand(store_address_t address); //TODO //ReturnValue_t Create_Schedule_Report(); #endif /* STUDIO_TMTCSERVICES_SCHEDULING_H_ */