#ifndef _WATERALARM_H
#define _WATERALARM_H

#include "DataManager.h"
#include "Sio32Interface.h"

/*
CLASS 
WaterAlarm

DESCRIPTION
Interface between Datamanager alarm/threshold items and CPU water
detectors

AUTHOR
Tom O'Reilly
*/

class WaterAlarm : public ErrorHandler
{
  public:
  
  ///////////////////////////////////////////////////////////////////
  // Constructor
  // [input] statusName: Full name of status DataManager item
  // [input] threshName: Full name of threshold DataManager item
  // [input] getStatusCmd: Micro command to get alarm status
  // [input] getStatusMask: Mask for extracting alarm value 
  // [input] getThreshCmd: Micro command to get alarm threshold
  // [input] setThreshCmd: Micro command to set alarm threshold
  // [input] onSrqCode: SRQ code indicating alarm is active
  // [input] offSrqCode: SRQ code indicating alarm is inactive
  WaterAlarm(const char *statusName,
	     const char *threshName,
	     Word getStatusCmd,
	     Word getStatusMask,
	     Word getThreshCmd,
	     Word setThreshCmd,
	     Word onSrqCode,
	     Word offSrqCode);

  ///////////////////////////////////////////////////////////////////
  // Constructor
  // [input] status: Status DataManager object
  // [input] threshold: Threshold DataManager object
  // [input] getStatusCmd: Micro command to get alarm status
  // [input] getStatusMask: Mask for extracting alarm value 
  // [input] getThreshCmd: Micro command to get alarm threshold
  // [input] setThreshCmd: Micro command to set alarm threshold
  // [input] onSrqCode: SRQ code indicating alarm is active
  // [input] offSrqCode: SRQ code indicating alarm is inactive
  WaterAlarm(DmBooleanObject *status,
	     DmNat16Object *threshold,
	     Word getStatusCmd,
	     Word getStatusMask,
	     Word getThreshCmd,
	     Word setThreshCmd,
	     Word onSrqCode,
	     Word offSrqCode);

  ~WaterAlarm();
  
  ///////////////////////////////////////////////////////////////////
  // If SRQ corresponds to change in alarm status, update DM item and
  // return TRUE. Else return FALSE.
  MBool statusChanged(Word srqCode);

  ///////////////////////////////////////////////////////////////////
  // Set micro's alarm threshold to current DM threshold value
  int updateThreshold(sio32Chan *channel);

  ///////////////////////////////////////////////////////////////////
  // Set DM threshold value to current micro threshold value
  int updateThresholdDm(sio32Chan *channel);
  
  ///////////////////////////////////////////////////////////////////
  // Set DM alarm value to current micro alarm value
  int updateDm(sio32Chan *channel);

  ///////////////////////////////////////////////////////////////////
  // Status DataManager object
  DmBooleanObject *status;

  ///////////////////////////////////////////////////////////////////
  // Alarm threshold DataManager object
  DmNat16Object *threshold;

  ///////////////////////////////////////////////////////////////////
  // Ack DataManager object
  DmNat16Object *ack;

  protected:

  Errno init(Word getStatusCmd,
	     Word getStatusMask,
	     Word getThreshCmd,
	     Word setThreshCmd,
	     Word onSrqCode,
	     Word offSrqCode);

  Word _getStatusCmd;
  Word _getStatusMask;
  Word _getThreshCmd;
  Word _setThreshCmd;
  Word _onSrqCode;
  Word _offSrqCode;
};

#endif
