// ************************************************************************** //
//                                                                            //
//    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 Occupancy determines "OccupancyMode" and "OccupancyCfg"           //
// ************************************************************************** //

package LightControl;

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

module Occupancy(
   bool ?hasMotionDetection,
   bool ?hasCameraImage,
   bool ?hasTransponderID,
   bool ?hasEntryExit,
   nat{5} !OccupancyMode,
   event nat{5} !OccupancyCfg) {
   OccupancyCfg = OCCUPANCY_Off;
   loop {
      pause;
      case
         // -----------------------------------------------------------------------
         // switch to mode OCCUPANCY_OccupancyDetection
         // -----------------------------------------------------------------------
         (hasCameraImage)
         do {
            OccupancyCfg = OCCUPANCY_LogicalDetection;
            next(OccupancyMode) = OCCUPANCY_LogicalDetection;
         }
         // -----------------------------------------------------------------------
         // switch to mode OCCUPANCY_TransponderDetection
         // -----------------------------------------------------------------------
         (hasTransponderID)
         do {
            OccupancyCfg = OCCUPANCY_TransponderDetection;
            next(OccupancyMode) = OCCUPANCY_TransponderDetection;
         }
         // -----------------------------------------------------------------------
         // switch to mode OCCUPANCY_MotionDetection
         // -----------------------------------------------------------------------
         (hasMotionDetection)
         do {
            OccupancyCfg = OCCUPANCY_MotionDetection;
            next(OccupancyMode) = OCCUPANCY_MotionDetection;
         }
         // -----------------------------------------------------------------------
         // switch to mode OCCUPANCY_EntryExitDetection
         // -----------------------------------------------------------------------
         (hasEntryExit)
         do {
            OccupancyCfg = OCCUPANCY_EntryExitDetection;
            next(OccupancyMode) = OCCUPANCY_EntryExitDetection;
         }
         // -----------------------------------------------------------------------
         // switch to mode OCCUPANCY_Off
         // -----------------------------------------------------------------------
         default {
            OccupancyCfg = OCCUPANCY_Off;
            next(OccupancyMode) = OCCUPANCY_Off;
         }
   }
}