/*
 ******************************************************************************
 *  Copyright 1998 DeltaLink bv. All Rights Reserved.
 ******************************************************************************
 *
 * File: sapi_ev.c
 *
 * This module contains the events function for the sapi driver.
 *
 */
#ifdef WIN32
#pragma warning(disable : 4121)
#define NOMSG             /* typedef MSG and associated routines */
#define _OLE2_H_          /* no ole */

#include  <windows.h>
#include  <process.h>

#undef ERROR

#endif


#include  <stdlib.h>
#include  <string.h>
#include  <stdio.h>
#include  <stdarg.h>


#include  <flib.h>						 /* FactoryLink definitions */
#include  <fl_utils.h>
#include  <g_utils.h>

#pragma warning( disable : 4214 )
#include  <imx.h>              /* Mailbox Communication Interface definitions */
#include  <imx_mt.h>           /* Mailbox Communication Interface definitions */
#include  <imx_fmt.h>          /* Mailbox Communication Interface definitions */
#pragma warning( default : 4214 )

#include  <protocol.h>				 /*  DeltaLink SAPI definitions */
#pragma warning( disable : 4115 )
#include  <sapi_s7.h>					 /*  Siemens SAPI definitions   */
#pragma warning( default : 4115 )
#include  <sapi.h>						 /*  DeltaLink SAPI definitions */


/*-----------------------------------------------------------------------------
 * FUNCTION: void  imx_event( IMXDS *ds )
 *
 * PURPOSE :  This function is not used
 *
 -----------------------------------------------------------------------------*/
#pragma warning(disable:4100)
int imx_event( IMXDS *ds )
{
  return GOOD;
}
#pragma warning(default:4100)


/*-----------------------------------------------------------------------------
 * FUNCTION: disable_fnc
 *
 * PURPOSE: Set or reset the disable flag on the device of a specific function.
 -----------------------------------------------------------------------------*/
int disable_fnc( void *flag, VAL value)
{
  char * disable = ( char * )flag;

  /* set the value of the disable flag */

  disable[ INTERNAL ] = ( char)value.dig;
  disable[ USER     ] = ( char)value.dig;

  debug_log( &Task_win, "DBG_DISABLE", 5, (int)value.dig);

  return 0;
}


/*-----------------------------------------------------------------------------
 * FUNCTION: cyclic_read
 *
 * PURPOSE: Start or stop the cyclic read functionality
 -----------------------------------------------------------------------------*/
int cyclic_read( void *ds, VAL cyclic_rate )
{
  DS_INFO *ds_info = ( DS_INFO * )ds;
  IMXDS               *my_ds;


  /* get the pointer to the registered dataset */
  my_ds = ds_info->device->dataset[ ds_info->ds_index ];

  if (my_ds)
    debug_log( &Task_win, "Event 'cyclic_read' for dataset '%s:%s', cyclic rate %d", 
               8, ds_info->device->name, my_ds->name, cyclic_rate.ana);

  cyclic_read_task( &Task_win, ds_info, cyclic_rate );

  return 0;
} //cyclic_read


/*-----------------------------------------------------------------------------
 * FUNCTION: set_board
 *
 * PURPOSE: Set the board for the depending devices
 -----------------------------------------------------------------------------*/
#pragma warning(disable:4100)
int __cdecl set_board( void *flag, VAL value)
{
  //DEVICE *dev = flag;
  
  //if (strlen(value.msg)) strcpy( dev->board_name ,value.msg);
  return 0;
} //set_board
#pragma warning(default:4100)

