/*****************************************************************************
 * File:       SPPIO_bridge.c
 *
 * Description:
 *
 * External Entity: 'PIO_2'  (SPPIO)
 ****************************************************************************/


#include "e_mechs.h"
#include "e_events.h"
#include "A_objects.h"
#include "A_enums.h"
#include "A_CAR_object.h"
#include "A_CAR_events.h"
#include "A_SP_object.h"
#include "A_SP_events.h"

#include "SPPIO_bridge.h"

/* Dummy up instance handle for event generation.  */
static Escher_InstanceHandle_t self = &self;
/*****************************************************************************
 * Bridge:  raise_needle
 ****************************************************************************/
unsigned char
SPPIO_raise_needle(
    const int ee_probe_id,
    const int ee_radial_position,
    const int ee_theta_offset )
{
  unsigned char result = 0;

  /* Replace the following instructions with your specific code.  */
  {
  A_SP_s * v2;  /* probe */

  /* SELECT ANY probe FROM INSTANCES OF SP
     WHERE SELECTED.probe_ID == PARAM.probe_id */
  v2 = (A_SP_s *)0;
  { /* Begin selection scope */
    A_SP_s * w1;
    Escher_Iterator_s iter3_SP;
    Escher_IteratorReset( &iter3_SP, pG_A_SP_extent );
    while ( (w1 = (A_SP_s *)Escher_IteratorNext( &iter3_SP )) != 0 )
    {
      if ( w1->m_probe_ID == ee_probe_id )
      {
        v2 = w1;
        break;
      }
    }
  } /* End selection scope */

  /* GENERATE SP3:'probe_in_position'(altitude:'up') TO probe */
  {
    A_SP_Event3_s * event4 = (A_SP_Event3_s *) Escher_NewOoaEvent( (void *) v2, &A_SP_Event3_sc );
    event4->m_altitude = A_position_up_e;
    SetEventSendingInstance( event4, self );
    Escher_SendEvent( (OoaEvent_t *)event4 );
  }

  return A_position_up_e;

  }
  
  return result;
}

/*****************************************************************************
 * Bridge:  lower_needle
 ****************************************************************************/
unsigned char
SPPIO_lower_needle(
    const int ee_probe_id,
    const int ee_radial_position,
    const int ee_theta_offset )
{
  unsigned char result = 0;

  /* Replace the following instructions with your specific code.  */
  {
  A_SP_s * v6;  /* probe */

  /* SELECT ANY probe FROM INSTANCES OF SP
     WHERE SELECTED.probe_ID == PARAM.probe_id */
  v6 = (A_SP_s *)0;
  { /* Begin selection scope */
    A_SP_s * w5;
    Escher_Iterator_s iter7_SP;
    Escher_IteratorReset( &iter7_SP, pG_A_SP_extent );
    while ( (w5 = (A_SP_s *)Escher_IteratorNext( &iter7_SP )) != 0 )
    {
      if ( w5->m_probe_ID == ee_probe_id )
      {
        v6 = w5;
        break;
      }
    }
  } /* End selection scope */

  /* GENERATE SP3:'probe_in_position'(altitude:'down') TO probe */
  {
    A_SP_Event3_s * event8 = (A_SP_Event3_s *) Escher_NewOoaEvent( (void *) v6, &A_SP_Event3_sc );
    event8->m_altitude = A_position_down_e;
    SetEventSendingInstance( event8, self );
    Escher_SendEvent( (OoaEvent_t *)event8 );
  }

  return A_position_down_e;

  }
  
  return result;
}