// ************************************************************************** //
//                                                                            //
//    eses                   eses                                             //
//   eses                     eses                                            //
//  eses    eseses  esesese    eses   Embedded Systems Group                  //
//  ese    ese  ese ese         ese                                           //
//  ese    eseseses eseseses    ese   Department of Computer Science          //
//  eses   eses          ese   eses                                           //
//   eses   eseses  eseseses  eses    University of Kaiserslautern            //
//    eses                   eses                                             //
//                                                                            //
// ************************************************************************** //
// Service AlarmSystem determines "AlarmCfg"                                  //
// ************************************************************************** //

package LightControl;

macro OCCUPANCY_LogicalDetection     = 4;
macro OCCUPANCY_TransponderDetection = 3;
macro OCCUPANCY_MotionDetection      = 2;
macro OCCUPANCY_EntryExitDetection   = 1;
macro OCCUPANCY_Off                  = 0;

macro LAMPBRIGHTNESS_dimmable    = 2;
macro LAMPBRIGHTNESS_switchable  = 1;
macro LAMPBRIGHTNESS_unavailable = 0;

macro ALARMSYSTEM_AlarmLight = 2;
macro ALARMSYSTEM_Alarm      = 1;
macro ALARMSYSTEM_Off        = 0;


module AlarmSystem(
   bool ?AlarmNotify,
   nat{5} ?OccupancyMode,
   nat{3} ?lampBrightness,
   event nat{3} !AlarmCfg) {
   AlarmCfg = ALARMSYSTEM_Off;
   loop {
      pause;
      case
         // -----------------------------------------------------------------------
         // switch to mode ALARMSYSTEM_AlarmLight
         // -----------------------------------------------------------------------
          (((OccupancyMode==OCCUPANCY_LogicalDetection) |
            (OccupancyMode==OCCUPANCY_EntryExitDetection) |
            (OccupancyMode==OCCUPANCY_MotionDetection))
          &
           ((lampBrightness==LAMPBRIGHTNESS_switchable) |
            (lampBrightness==LAMPBRIGHTNESS_dimmable))
          &
           AlarmNotify)
         do
            AlarmCfg = ALARMSYSTEM_AlarmLight;
         // -----------------------------------------------------------------------
         // switch to mode ALARMNOTIFICATION_Alarm
         // -----------------------------------------------------------------------
          (((OccupancyMode==OCCUPANCY_LogicalDetection) |
            (OccupancyMode==OCCUPANCY_EntryExitDetection) |
            (OccupancyMode==OCCUPANCY_MotionDetection))
           &
           AlarmNotify)
         do
            AlarmCfg = ALARMSYSTEM_Alarm;
         // -----------------------------------------------------------------------
         // switch to mode ALARMSYSTEM_Off
         // -----------------------------------------------------------------------
         default
            AlarmCfg = ALARMSYSTEM_Off;
   }
}