PowerwindowRequired.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #ifndef POWERWINDOWREQUIRED_H_
  2. #define POWERWINDOWREQUIRED_H_
  3. #include "sc_types.h"
  4. #include "Powerwindow.h"
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. /*! \file This header defines prototypes for all functions that are required by the state machine implementation.
  9. This is a state machine uses time events which require access to a timing service. Thus the function prototypes:
  10. - powerwindow_setTimer and
  11. - powerwindow_unsetTimer
  12. are defined.
  13. These functions will be called during a 'run to completion step' (runCycle) of the statechart.
  14. There are some constraints that have to be considered for the implementation of these functions:
  15. - never call the statechart API functions from within these functions.
  16. - make sure that the execution time is as short as possible.
  17. */
  18. /*
  19. * This is a simple hack; for a real FMI code gen for Yakindu, make this a bit more generic
  20. */
  21. double relativeError(double a, double b);
  22. /*
  23. * Helper function for absolute error
  24. */
  25. double absoluteError(double a, double b);
  26. /*
  27. * is_close function for double comparison
  28. */
  29. int is_close(double a, double b, double REL_TOL, double ABS_TOL);
  30. typedef struct{
  31. double nextTime;
  32. double currentTime;
  33. Powerwindow * handle;
  34. sc_eventid evid;
  35. int period;
  36. int isPeriodic;
  37. int active;
  38. void (*callback) (const Powerwindow*, sc_eventid evid);
  39. }fmi_timer;
  40. fmi_timer *thePWTimer;
  41. void powerwindow_timeradvance(fmi_timer *theTimer, double currentTime);
  42. void powerwindow_initTimer(fmi_timer *timer);
  43. /*!
  44. * This is a timed state machine that requires timer services
  45. */
  46. /*! This function has to set up timers for the time events that are required by the state machine. */
  47. /*!
  48. This function will be called for each time event that is relevant for a state when a state will be entered.
  49. \param evid An unique identifier of the event.
  50. \time_ms The time in milli seconds
  51. \periodic Indicates the the time event must be raised periodically until the timer is unset
  52. */
  53. extern void powerwindow_setTimer(Powerwindow* handle, const sc_eventid evid, const sc_integer time_ms, const sc_boolean periodic);
  54. /*! This function has to unset timers for the time events that are required by the state machine. */
  55. /*!
  56. This function will be called for each time event taht is relevant for a state when a state will be left.
  57. \param evid An unique identifier of the event.
  58. */
  59. extern void powerwindow_unsetTimer(Powerwindow* handle, const sc_eventid evid);
  60. #ifdef __cplusplus
  61. }
  62. #endif
  63. #endif /* POWERWINDOWREQUIRED_H_ */