HAN-FUN API  1.5.3
This project provides the common implementation of ULE Alliance's HAN-FUN application protocol.
HF::Core::Scheduling::Entry< _Type > Struct Template Reference

Base class for scheduling services entries. More...

#include <scheduling.h>

+ Collaboration diagram for HF::Core::Scheduling::Entry< _Type >:

Public Member Functions

 Entry (uint8_t _id, uint8_t _status, _Type _t, uint8_t _pid)
 Constructor. More...
 
bool active (uint32_t _time) const
 Check if the current entry is runnable at _time. More...
 
void step (void)
 Increment the next_run attribute.
 
uint16_t size () const
 Number bytes needed to serialize the message. More...
 
uint16_t pack (Common::ByteArray &array, uint16_t offset=0) const
 Write the object on to a ByteArray so it can be sent over the network. More...
 
uint16_t unpack (const Common::ByteArray &array, uint16_t offset=0)
 Read a message from a ByteArray. More...
 

Data Fields

uint8_t id
 Event ID. More...
 
bool status
 Event Status. More...
 
_Type time
 Scheduler configuration. More...
 
uint8_t pid
 Program ID to be invoked. More...
 
uint32_t next_run
 Next run timestamp. More...
 

Static Public Attributes

static constexpr uint16_t START_ID = 0x00
 Lower bound for the entries ID. More...
 
static constexpr uint16_t MAX_ID = 0xFE
 Upper bound for the entries ID. More...
 
static constexpr uint16_t AVAILABLE_ID = 0xFF
 Special ID for system allocated ID. More...
 
static constexpr uint16_t min_size
 Minimum pack/unpack required data size.
 

Detailed Description

template<typename _Type>
struct HF::Core::Scheduling::Entry< _Type >

Base class for scheduling services entries.

Template Parameters
_Typethe specific data for scheduling service entry.

Definition at line 175 of file scheduling.h.

Constructor & Destructor Documentation

◆ Entry()

template<typename _Type>
HF::Core::Scheduling::Entry< _Type >::Entry ( uint8_t  _id,
uint8_t  _status,
_Type  _t,
uint8_t  _pid 
)
inline

Constructor.

Parameters
[in]_idthe entry ID.
[in]_statusthe entry status.
[in]_tthe specific data for the scheduling service.
[in]_pidthe batch program ID to be run.

Definition at line 193 of file scheduling.h.

193  :
194  id(_id), status(_status), time(_t), pid(_pid), next_run(time.first())
195  {}
uint8_t id
Event ID.
Definition: scheduling.h:177
uint32_t next_run
Next run timestamp.
Definition: scheduling.h:183
bool status
Event Status.
Definition: scheduling.h:178
_Type time
Scheduler configuration.
Definition: scheduling.h:179
uint8_t pid
Program ID to be invoked.
Definition: scheduling.h:180

Member Function Documentation

◆ active()

template<typename _Type>
bool HF::Core::Scheduling::Entry< _Type >::active ( uint32_t  _time) const
inline

Check if the current entry is runnable at _time.

Parameters
[in]_timethe system time.
Return values
falseif the entry can't run.
trueif the entry can run.

Definition at line 211 of file scheduling.h.

References HF::Core::Scheduling::Entry< _Type >::next_run, HF::Core::Scheduling::Entry< _Type >::status, and HF::Core::Scheduling::Entry< _Type >::time.

212  {
213  return (status == 0x01 &&
214  time.active(_time) &&
215  _time >= next_run);
216  }
uint32_t next_run
Next run timestamp.
Definition: scheduling.h:183
bool status
Event Status.
Definition: scheduling.h:178
_Type time
Scheduler configuration.
Definition: scheduling.h:179

◆ pack()

template<typename _Type>
uint16_t HF::Core::Scheduling::Entry< _Type >::pack ( Common::ByteArray array,
uint16_t  offset = 0 
) const
inline

Write the object on to a ByteArray so it can be sent over the network.

The buffer passed in MUST have enough size to hold the serialized object, e.g.,

Serializable obj;
ByteArray payload(obj.size());
obj.pack(payload);
Parameters
[in,out]arrayByteArray reference to write the object to.
[in]offsetoffset to start writing to.
Returns
the number of bytes written.

Definition at line 239 of file scheduling.h.

References HF_SERIALIZABLE_CHECK, HF::Core::Scheduling::Entry< _Type >::pid, HF::Core::Scheduling::Entry< _Type >::size(), HF::Core::Scheduling::Entry< _Type >::status, HF::Core::Scheduling::Entry< _Type >::time, and HF::Common::ByteArray::write().

240  {
241  HF_SERIALIZABLE_CHECK(array, offset, size());
242 
243  uint16_t start = offset;
244 
245  offset += array.write(offset, id);
246  offset += array.write(offset, static_cast<uint8_t>((status << 7) & 0x80));
247  offset += time.pack(array, offset);
248  offset += array.write(offset, pid);
249 
250  return (offset - start);
251  }
#define HF_SERIALIZABLE_CHECK(__array, __offset, __size)
Helper macro to check if the given __array has enough size so __size bytes can be written/read from t...
bool status
Event Status.
Definition: scheduling.h:178
_Type time
Scheduler configuration.
Definition: scheduling.h:179
uint8_t pid
Program ID to be invoked.
Definition: scheduling.h:180
uint16_t size() const
Number bytes needed to serialize the message.
Definition: scheduling.h:233
+ Here is the call graph for this function:

◆ size()

template<typename _Type>
uint16_t HF::Core::Scheduling::Entry< _Type >::size ( ) const
inline

Number bytes needed to serialize the message.

Returns
number of bytes the message requires to be serialized.

Definition at line 233 of file scheduling.h.

References HF::Core::Scheduling::Entry< _Type >::min_size.

Referenced by HF::Core::Scheduling::Entry< _Type >::pack(), and HF::Core::Scheduling::Entry< _Type >::unpack().

234  {
235  return min_size;
236  }
static constexpr uint16_t min_size
Minimum pack/unpack required data size.
Definition: scheduling.h:227
+ Here is the caller graph for this function:

◆ unpack()

template<typename _Type>
uint16_t HF::Core::Scheduling::Entry< _Type >::unpack ( const Common::ByteArray array,
uint16_t  offset = 0 
)
inline

Read a message from a ByteArray.

Parameters
[in]arrayByteArray reference to read the message from.
[in]offsetoffset to start reading from.
Returns
the number of bytes read.

Definition at line 254 of file scheduling.h.

References HF_ASSERT, HF_SERIALIZABLE_CHECK, HF::Core::Scheduling::Entry< _Type >::min_size, HF::Core::Scheduling::Entry< _Type >::pid, HF::Common::ByteArray::read(), HF::Core::Scheduling::Entry< _Type >::size(), HF::Core::Scheduling::Entry< _Type >::status, and HF::Core::Scheduling::Entry< _Type >::time.

255  {
256  HF_SERIALIZABLE_CHECK(array, offset, min_size);
257 
258  uint16_t start = offset;
259 
260  offset += array.read(offset, id);
261 
262  uint8_t flags = 0;
263  offset += array.read(offset, flags);
264  status = (flags >> 7) & 0x01;
265 
266  uint16_t size = time.unpack(array, offset);
267  HF_ASSERT(size != 0, {return 0;});
268  offset += size;
269 
270  offset += array.read(offset, pid);
271 
272  return (offset - start);
273  }
static constexpr uint16_t min_size
Minimum pack/unpack required data size.
Definition: scheduling.h:227
#define HF_ASSERT(_expr, _block)
Helper macro to check for correct assumptions.
#define HF_SERIALIZABLE_CHECK(__array, __offset, __size)
Helper macro to check if the given __array has enough size so __size bytes can be written/read from t...
bool status
Event Status.
Definition: scheduling.h:178
_Type time
Scheduler configuration.
Definition: scheduling.h:179
uint8_t pid
Program ID to be invoked.
Definition: scheduling.h:180
uint16_t size() const
Number bytes needed to serialize the message.
Definition: scheduling.h:233
+ Here is the call graph for this function:

Field Documentation

◆ AVAILABLE_ID

template<typename _Type>
constexpr uint16_t HF::Core::Scheduling::Entry< _Type >::AVAILABLE_ID = 0xFF
static

Special ID for system allocated ID.

Definition at line 201 of file scheduling.h.

Referenced by HF::Core::Scheduling::Entries< _Type >::next_id().

◆ id

template<typename _Type>
uint8_t HF::Core::Scheduling::Entry< _Type >::id

Event ID.

(Unique per device)

Definition at line 177 of file scheduling.h.

Referenced by HF::Core::Scheduling::Entries< _Type >::destroy(), and HF::Core::Scheduling::Entries< _Type >::save().

◆ MAX_ID

template<typename _Type>
constexpr uint16_t HF::Core::Scheduling::Entry< _Type >::MAX_ID = 0xFE
static

Upper bound for the entries ID.

Definition at line 200 of file scheduling.h.

Referenced by HF::Core::Scheduling::Entries< _Type >::next_id().

◆ next_run

template<typename _Type>
uint32_t HF::Core::Scheduling::Entry< _Type >::next_run

Next run timestamp.

Definition at line 183 of file scheduling.h.

Referenced by HF::Core::Scheduling::Entry< _Type >::active(), and HF::Core::Scheduling::Entry< _Type >::step().

◆ pid

template<typename _Type>
uint8_t HF::Core::Scheduling::Entry< _Type >::pid

Program ID to be invoked.

Definition at line 180 of file scheduling.h.

Referenced by HF::Core::Scheduling::Entry< _Type >::pack(), and HF::Core::Scheduling::Entry< _Type >::unpack().

◆ START_ID

template<typename _Type>
constexpr uint16_t HF::Core::Scheduling::Entry< _Type >::START_ID = 0x00
static

Lower bound for the entries ID.

Definition at line 199 of file scheduling.h.

Referenced by HF::Core::Scheduling::Entries< _Type >::next_id().

◆ status

◆ time


The documentation for this struct was generated from the following file: