Beispiel #1
0
static pwr_tStatus AoRangeToCoef( 
  io_sChannel 	*chanp)
{
  pwr_sClass_ChanAo	*cop;
  char			buf[120];
  pwr_tStatus		sts;
  int			i;
  pwr_tFloat32		PolyCoef1;
  pwr_tFloat32		PolyCoef0;

  cop = chanp->cop;

  if ( cop)
  {
    cop->CalculateNewCoef = 0;

    /* Coef for ActualValue to RawValue conversion */
    if ( cop->ActValRangeHigh != cop->ActValRangeLow)
    {
      cop->SigValPolyCoef1 = (cop->SensorSigValRangeHigh - cop->SensorSigValRangeLow)/
		(cop->ActValRangeHigh - cop->ActValRangeLow);
      cop->SigValPolyCoef0 = cop->SensorSigValRangeHigh - cop->ActValRangeHigh *
		cop->SigValPolyCoef1;
    }
    else
    {
      sts = gdh_ObjidToName( chanp->ChanObjid, buf, sizeof(buf), 
			cdh_mName_volumeStrict);
      if ( EVEN(sts)) return sts;
      errh_Error( "Invalid ActValueRange in Ao channel %s", buf);
      return IO__CHANRANGE;
    }
    /* Coef for ActualValue to SignalValue conversion */
    if ( cop->ChannelSigValRangeHigh != 0)
    {
      PolyCoef0 = 0;
      PolyCoef1 = 2047. / cop->ChannelSigValRangeHigh;
      cop->OutPolyCoef1 = cop->SigValPolyCoef1 * PolyCoef1;
      cop->OutPolyCoef0 = PolyCoef0 + PolyCoef1*
		cop->SigValPolyCoef0;
    }
    else
    {
      sts = gdh_ObjidToName( chanp->ChanObjid, buf, sizeof(buf), 
			cdh_mName_volumeStrict);
      if ( EVEN(sts)) return sts;
      errh_Error( "Invalid SigValueRange in Ao channel %s", buf);
      return IO__CHANRANGE;
    }
  }
  return IO__SUCCESS;
}
Beispiel #2
0
static void pwrsrv_WriteAttribute( rpvd_sMsgWriteAttribute *msg)
{
  rpvd_sMsgAny rmsg;
  pwr_tAName name;
  pwr_tUInt32 asize, aoffs, aelem;
  pwr_tTypeId atid;
  pwr_tStatus sts;
  
  rmsg.Type = rpvd_eMsg_Status;
  rmsg.Id = msg->Id;

  sts = gdh_ObjidToName( msg->Oid, name, sizeof(name), cdh_mName_volumeStrict);
  if ( EVEN(sts)) {
    rmsg.Status = sts;
    udp_Send( (char *)&rmsg, sizeof(rmsg));
    return;
  }

  strcat( name, ".");
  strcat( name, msg->Attribute);

  sts = gdh_GetAttributeCharacteristics( name, &atid, &asize, &aoffs, &aelem);
  if ( EVEN(sts)) {
    rmsg.Status = sts;
    udp_Send( (char *)&rmsg, sizeof(rmsg));
    return;
  }

  sts = gdh_SetObjectInfo( name, &msg->Value, msg->Size);
  rmsg.Status = sts;
  udp_Send( (char *)&rmsg, sizeof(rmsg));
}
Beispiel #3
0
/*------------------------------------------------------------------------------
*/
static char *FormatOperator(
  pwr_tObjid Outunit
)
{
  pwr_tStatus	  sts;
  static char	  Text[100];
  pwr_tClassId	  Class;
  pwr_sClass_User Operator;
  pwr_tFullName	  FullName;

  strcpy(Text,"--");
  sts = gdh_GetObjectClass(Outunit, &Class); 
  if (ODD(sts)) {
    if (Class == pwr_cClass_User) {
      sts = gdh_ObjidToName(Outunit, FullName, sizeof(FullName), cdh_mNName);
      if (ODD(sts)) {   
	sts = gdh_GetObjectInfo(FullName, &Operator, sizeof(pwr_sClass_User));
	if (ODD(sts)) {
	  sprintf(Text, "%s %d %s %s", _OPPLACE, Operator.OpNumber,
	    _OPERATOR, Operator.UserName
	  );
	}
      }
    }
  }

  return Text;
}
Beispiel #4
0
int rtt_crossref_channel(unsigned long ctx, pwr_tObjid objid, void* arg1,
    void* arg2, void* arg3, void* arg4)
{
  pwr_tAName hiername;
  int sts;
  pwr_sAttrRef signal_aref;

  sts = gdh_ObjidToName(objid, hiername, sizeof(hiername), cdh_mNName);
  if (EVEN(sts)) {
    rtt_message('E', "Cross reference not defined");
    return RTT__NOPICTURE;
  }
  strcat(hiername, ".SigChanCon");
  sts = gdh_GetObjectInfo(
      hiername, (pwr_tAddress)&signal_aref, sizeof(signal_aref));
  if (EVEN(sts))
    return sts;

  sts = gdh_AttrrefToName(&signal_aref, hiername, sizeof(hiername), cdh_mNName);
  if (EVEN(sts)) {
    rtt_message('E', "Cross reference not defined");
    return RTT__NOPICTURE;
  }

  sts = rtt_crr_signal(NULL, hiername);
  return sts;
}
Beispiel #5
0
static void
create_thread (
  plc_sThread	*tp,
  plc_sProctbl	*ptp,
  plc_sProcess	*pp
)
{
  pwr_tStatus	sts;
  long int phase;

  tp->aref.Objid = ptp->thread;
  tp->init = ptp->init;
  tp->exec = ptp->exec;
  tp->first_scan = 1;

  tp->PlcThread = pwrb_PlcThread_Init(&sts, tp);
  tp->csup_lh = csup_Init(&sts, ptp->thread, tp->f_scan_time);

  tp->i_scan_time = tp->f_scan_time * 1000.0 + 0.5;

  time_FloatToD(&tp->scan_time, tp->f_scan_time);

  tp->pp = pp;
 
  plc_inittimer(tp);
  tp->exit = FALSE;
  link_io_copy_areas(tp);

  que_Create(&sts, &tp->q_in);
  que_Create(&sts, &tp->q_out);

  sts = gdh_ObjidToName(ptp->thread, tp->name, sizeof(tp->name), cdh_mNName);
  if (EVEN(sts)) {
    errh_Error("Get name of thread object %s, %m", cdh_ObjidToString(NULL, ptp->thread, 1), sts);
    return;
  }

  sts = gdh_ObjidToPointer(ptp->thread, (void *)&tp->PlcThread);
  if (EVEN(sts)) {
    errh_Error("Direct link to thread object \"%s\", %m", tp->name, sts);
    return;
  }

#if defined OS_LYNX && USE_RT_TIMER
  sem_init(&tp->ScanSem, 0, 0);
  tp->ScanMultiple = tp->i_scan_time / (CLK_TCK/1000);
  tp->IntervalCount = tp->ScanMultiple; 
#endif


  sts = thread_Create(&tp->tid, tp->name, (void *(*)())&plc_thread, tp);
  if (EVEN(sts)) {
    errh_Error("Creating thread \"%s\", %m", tp->name, sts);
    return;
  }

  /* Wait for thread to initialize.  */
  phase = (long int)que_Get(&sts, &tp->q_out, NULL, NULL);
  pwr_Assert(phase == 1);
}
Beispiel #6
0
//
// Set attribute value
//
int XAttNav::set_attr_value( brow_tObject node, char *name, char *value_str)
{
  Item		*base_item;
  int		sts;
  char 		buff[1024];
  pwr_tAName    attr_str;

  // Check authorization
  if ( is_authorized_cb) {
    if ( !(is_authorized_cb( parent_ctx, 
			     pwr_mAccess_RtWrite | pwr_mAccess_System))) {
      message( 'E', "Not authorized for this operation");
      return XATT__NOTAUTHORIZED;
    }
  }

  // Check that object still exist
  if ( !object_exist( node))
    return XATT__DISAPPEARD;

  brow_GetUserData( node, (void **)&base_item);

  switch( base_item->type) {
    case xnav_eItemType_AttrArrayElem:
    case xnav_eItemType_Attr:
    case xnav_eItemType_Collect:
    {
      ItemAttr *item = (ItemAttr *)base_item;

      // Check that objid is still the same
      if ( strcmp(item->attr, name) != 0)
        return XATT__DISAPPEARD;

      sts = gdh_ObjidToName( item->objid, 
	    	attr_str, sizeof(attr_str), cdh_mName_volumeStrict);
      if ( EVEN(sts)) return sts;
      strcat( attr_str, ".");
      strcat( attr_str, item->attr);

      sts =  XNav::attr_string_to_value( item->type_id, 
	value_str, buff, sizeof(buff), item->size);
      if ( EVEN(sts))
        message( 'E', "Input syntax error");
      else
      {
        sts = gdh_SetObjectInfo( attr_str, buff, item->size);
        if ( EVEN(sts)) return sts;
      }
      return sts;
    }
    default:
      ;
  }
  return 1;
}
Beispiel #7
0
//
// Set scan
//
static pwr_tStatus SetScan( xmenu_sMenuCall *ip)
{
    pwr_tObjid child;
    int sts;
    pwr_tBoolean local;
    pwr_tObjid io_handler;
    pwr_sClass_IOHandler *io_handler_p;
    pwr_tBoolean value = 0;
    pwr_tOName name;
    pwr_tClassId classid;

    if ( strcmp( "Enable", ip->ItemList[ip->ChosenItem].MethodArguments[0]) == 0)
        value = 0;
    else if ( strcmp( "Disable", ip->ItemList[ip->ChosenItem].MethodArguments[0]) == 0)
        value = 1;
    else
        return XNAV__SUCCESS;

    // Only on local objects
    sts = gdh_GetObjectLocation( ip->Pointed.Objid, &local);
    if ( EVEN(sts) || !local)
        return 0;

    // Only if simulate
    sts = gdh_GetClassList( pwr_cClass_IOHandler, &io_handler);
    if ( EVEN(sts)) return sts;

    sts = gdh_ObjidToPointer( io_handler, (void **) &io_handler_p);
    if ( EVEN(sts)) return sts;

    if ( !io_handler_p->IOSimulFlag)
        return 0;

    sts = gdh_GetChild( ip->Pointed.Objid, &child);
    while( ODD(sts)) {
        sts = gdh_GetObjectClass( child, &classid);
        if ( EVEN(sts)) return sts;

        if ( classid == pwr_cClass_windowplc) {
            sts = gdh_ObjidToName( child, name, sizeof(name),
                                   cdh_mName_volumeStrict);
            if ( EVEN(sts)) return sts;
            strcat( name, ".ScanOff");
            sts = gdh_SetObjectInfo( name, (void *) &value, sizeof( value));
            if ( EVEN(sts)) return sts;

            return XNAV__SUCCESS;
        }
    }
    return 0;
}
Beispiel #8
0
int rtt_crossref_signal(unsigned long ctx, pwr_tObjid objid, void* arg1,
    void* arg2, void* arg3, void* arg4)
{
  pwr_tOName hiername;
  int sts;

  sts = gdh_ObjidToName(objid, hiername, sizeof(hiername), cdh_mNName);
  if (EVEN(sts)) {
    rtt_message('E', "Cross reference not defined");
    return RTT__NOPICTURE;
  }

  sts = rtt_crr_signal(NULL, hiername);
  return sts;
}
Beispiel #9
0
void disksup_object::exec()
{
#if defined OS_LINUX
  struct statfs buf;
  int sts;

  pwr_sClass_DiskSup *o = (pwr_sClass_DiskSup *)p;

  sts = statfs( o->DiskName, &buf);
  if ( sts != 0) {
    sts = errno_GetStatus();
    if ( o->Status != sts) {
      o->Status = sts;
      printf( "Can't find disk\n");
    }
    return;
  }

  o->CurrentUse = 100.0 - 100.0 * buf.f_bfree / buf.f_blocks;

  // Check if limit is exceeded
  if ( !(o->CurrentUse < o->UsedMaxLimit)) {
    if ( o->Status != SMON__DISKHIGHLIMIT) {
      o->Status = SMON__DISKHIGHLIMIT;
      if ( o->Action & pwr_mDiskSupActionMask_Alarm) {
	pwr_tOName name;

	sts = gdh_ObjidToName( aref.Objid, name, sizeof(name), cdh_mNName);
	rt_sysmon::alarm_send( aref.Objid, o->DetectText, name, o->EventPriority);
      }
      if ( o->Action & pwr_mDiskSupActionMask_Command) {
	if ( strcmp( o->Command, "") != 0) {
	  char msg[200];

	  system( o->Command);
	  sprintf( msg, "Command %s: %s", o->DiskName, o->Command);
	  errh_Info( msg);
	}
      }
    }
  }
  else
    o->Status = SMON__SUCCESS;
#endif
}
Beispiel #10
0
static pwr_tStatus AiRangeToCoef( 
  io_sChannel 		*chanp)
{
  pwr_sClass_ChanAi	*cop;
  char			buf[120];
  pwr_tStatus		sts;
  pwr_tFloat32		PolyCoef1;
  pwr_tFloat32		PolyCoef0;

  cop = chanp->cop;

  if ( cop)
  {
    cop->CalculateNewCoef = 0;


    /* Coef for RawValue to SignalValue conversion */
    cop->SigValPolyCoef0 = 0;
    cop->SigValPolyCoef1 = cop->ChannelSigValRangeHigh / 30000;

    /* Coef for SignalValue to ActualValue conversion */
    if ( chanp->ChanClass != pwr_cClass_ChanAit && cop->SensorPolyType == 1)
    {
      if ( cop->SensorSigValRangeHigh != cop->SensorSigValRangeLow)
      {
        PolyCoef1 = (cop->ActValRangeHigh - cop->ActValRangeLow)/
		(cop->SensorSigValRangeHigh - cop->SensorSigValRangeLow);
        PolyCoef0 = cop->ActValRangeHigh - cop->SensorSigValRangeHigh *
		PolyCoef1;
        cop->SensorPolyCoef1 = cop->SigValPolyCoef1 * PolyCoef1;
        cop->SensorPolyCoef0 = PolyCoef0 + PolyCoef1*
		cop->SigValPolyCoef0;
      }
      else
      {
        sts = gdh_ObjidToName( chanp->ChanAref.Objid, buf, sizeof(buf), 
			cdh_mName_volumeStrict);
        if ( EVEN(sts)) return sts;
        errh_Error( "Invalid SigValueRange in Ai channel %s", buf);
        return IO__CHANRANGE;
      }
    }
  }
  return IO__SUCCESS;
}
Beispiel #11
0
// Open trace
static pwr_tStatus OpenTrace( xmenu_sMenuCall *ip)
{
    pwr_tOName name;
    pwr_tCmd cmd;
    int sts;

    printf( "OpenProgram method called\n");

    //foe_Open (ip->EditorContext, ip->WindowContext, ip->PointedSession,
    //  ip->Pointed.Objid);

    sts = gdh_ObjidToName( ip->Pointed.Objid, name, sizeof(name),
                           cdh_mName_volumeStrict);
    if ( EVEN(sts)) return sts;

    sprintf( cmd, "open trace/name=%s", name);
    ((XNav *)ip->EditorContext)->command( cmd);
    return 1;
}
Beispiel #12
0
static void pwrsrv_ObjectName( rpvd_sMsgObjectName *msg)
{
  rpvd_sMsgOid m;
  pwr_tStatus sts;
  char name[256];

  /* Simulate an oid request */
  m.Type = rpvd_eMsg_Oid;
  m.Id = msg->Id;
  if ( msg->POid.oix) {
    sts = gdh_ObjidToName( msg->POid, name, sizeof(name), cdh_mName_volumeStrict);
    if ( EVEN(sts)) {
      rpvd_sMsgObject rmsg;
      rmsg.Type = rpvd_eMsg_Object;
      rmsg.Id = msg->Id;
      rmsg.Status = sts;
      udp_Send( (char *)&rmsg, sizeof(rmsg));
      return;
    }
    strcat( name, "-");
    strcat( name, msg->Name);
  }
  else
    strncpy( name, msg->Name, sizeof(name));
  sts = gdh_NameToObjid( name, &m.Oid);
  if ( EVEN(sts)) {
    rpvd_sMsgObject rmsg;
    rmsg.Type = rpvd_eMsg_Object;
    rmsg.Id = msg->Id;
    rmsg.Status = sts;
    udp_Send( (char *)&rmsg, sizeof(rmsg));
    return;
  }
  
  pwrsrv_Oid( &m);
}
Beispiel #13
0
int Op::sup_init()
{
  pwr_tOid node_oid;
  pwr_tOid sup_oid;
  pwr_tAName aname;
  pwr_tStatus sts;
  

  // Index 0 is current node
  sts = gdh_GetNodeObject( 0, &node_oid);
  if ( EVEN(sts)) return sts;

  OpSup sup;
  sup.node_oid = node_oid;
  sts = gdh_ObjidToName( node_oid, sup.object_name, sizeof(sup.object_name), cdh_mName_volumeStrict);
  if ( EVEN(sts)) return sts;

  strcpy( aname, sup.object_name);
  strcat( aname, ".SystemStatus");
  sts = gdh_RefObjectInfo( aname, (void **)&sup.p, &sup.refid, sizeof(pwr_tStatus));
  if ( EVEN(sts)) return sts;

  syi_NodeName( &sts, sup.node_name, sizeof(sup.node_name));

  sup_vect.push_back(sup);			 

  // Add nodes in NodeLinkSup objects
  for ( sts = gdh_GetClassList( pwr_cClass_NodeLinkSup, &sup_oid);
	ODD(sts);
	sts = gdh_GetNextObject( sup_oid, &sup_oid)) {
    pwr_sClass_NodeLinkSup *sup_p;
    qcom_sNode 		qnode;
    pwr_tNid		nid;

    sts = gdh_ObjidToPointer( sup_oid, (void **)&sup_p);

    OpSup nsup;

    nsup.node_oid = sup_p->Node;

    sts = gdh_ObjidToName( nsup.node_oid, nsup.object_name, sizeof(nsup.object_name), 
			   cdh_mName_volumeStrict);
    if ( EVEN(sts)) strcpy( nsup.object_name, "");
    
    sts = gdh_ObjidToName( sup_oid, aname, sizeof(aname), cdh_mName_volumeStrict);
    if ( EVEN(sts)) return sts;
    
    strcat( aname, ".SystemStatus");
    sts = gdh_RefObjectInfo( aname, (void **)&nsup.p, &sup.refid, sizeof(pwr_tStatus));
    if ( EVEN(sts)) return sts;

    int found = 0;
    for (nid = qcom_cNNid; qcom_NextNode(&sts, &qnode, nid); nid = qnode.nid) {
      if ( qnode.nid == nsup.node_oid.vid) {
	strcpy( nsup.node_name, qnode.name);
	found = 1;
	break;
      }
    }
    if ( !found)
      strcpy( nsup.node_name, "Unknown");

    sup_vect.push_back(nsup);			 
  }
  return 1;
}
Beispiel #14
0
static pwr_tStatus IoRackInit (
  io_tCtx	ctx,
  io_sAgent	*ap,
  io_sRack	*rp
) 
{
  io_sCardLocal *local_card;
  io_sCard *cardp;
  io_sRackLocal *local;
  int no_di;
  int no_do;
  pwr_sClass_Modbus_RTU_Slave *op;
  char name[196];
  pwr_tStatus sts;
  pwr_tCid cid;
  
  io_sChannel *chanp;
  int i;

  sts = gdh_ObjidToName(rp->Objid, (char *) &name, sizeof(name), cdh_mNName);
  errh_Info( "Init of Modbus TCP Slave and Modules %s", name);

  op = (pwr_sClass_Modbus_RTU_Slave *) rp->op;
  
  rp->Local = calloc(1, sizeof(io_sRackLocal));
  local = rp->Local;

  op->Status = MB__NORMAL;
  
  /* Do configuration check and initialize modules. */

  cardp = rp->cardlist;

  unsigned int prev_input_area_offset = 0;
  unsigned int prev_output_area_offset = 0;
  unsigned int input_area_offset = 0;
  unsigned int output_area_offset = 0;
  unsigned int input_area_chansize = 0;
  unsigned int output_area_chansize = 0;

  while(cardp) {
    local_card = calloc(1, sizeof(*local_card));

    cid = cardp->Class;
    /* Find the super class */
    while ( ODD( gdh_GetSuperClass( cid, &cid, cardp->Objid))) ;

    switch (cid) {
    case pwr_cClass_Modbus_RTU_Module: {
      pwr_sClass_Modbus_RTU_Module *modulep;

      cardp->Local = local_card;
      no_di = 0;
      no_do = 0;

      local_card->msg[0].input_area = (void *) &(op->Inputs) + input_area_offset + 
	input_area_chansize;
      local_card->msg[0].output_area = (void *) &(op->Outputs) + output_area_offset + 
	output_area_chansize;

    
      modulep = (pwr_sClass_Modbus_RTU_Module *) cardp->op;
      modulep->Status = pwr_eModbusModule_StatusEnum_StatusUnknown;

      io_bus_card_init( ctx, cardp, &input_area_offset, &input_area_chansize,
			&output_area_offset, &output_area_chansize, 
			pwr_eByteOrderingEnum_BigEndian, io_eAlignment_Packed);

      /* Count number of di and do */
      for (i = 0; i < cardp->ChanListSize; i++) {
	chanp = &cardp->chanlist[i];
	switch (chanp->ChanClass) {      
	case pwr_cClass_ChanDi:
	  no_di++;
	  break;
	case pwr_cClass_ChanDo:
	  no_do++;
	  break;
	}
      }	   
      local_card->msg[0].input_size = input_area_offset + input_area_chansize - 
	prev_input_area_offset;
      local_card->msg[0].output_size = output_area_offset + output_area_chansize - 
	prev_output_area_offset;
      local_card->msg[0].no_di = no_di;
      local_card->msg[0].no_do = no_do;
      
      break;
    }
      
    } /* End - switch ... */


    prev_input_area_offset = input_area_offset + input_area_chansize;
    prev_output_area_offset = output_area_offset + output_area_chansize;

    cardp = cardp->next;
  }

  local->input_size = input_area_offset + input_area_chansize;
  local->output_size = output_area_offset + output_area_chansize;

  return IO__SUCCESS;
}
Beispiel #15
0
RtTraceGtk::RtTraceGtk( void *tr_parent_ctx, GtkWidget *tr_parent_wid, pwr_tObjid tr_objid,
			pwr_tStatus *status) :
  RtTrace( tr_parent_ctx, tr_objid, status), parent_wid(tr_parent_wid), toplevel(0), nav_shell(0)
{

  const int	window_width = 900;
  const int    	window_height = 800;
  const int    	nav_width = 180;
  pwr_tStatus 	sts;
  pwr_tObjid	window_objid;
  pwr_tClassId	cid;
  char   	title[220];
  pwr_tOName   	hostname;
  pwr_tOName   	plcconnect;
  pwr_tFileName fname;

  sts = gdh_ObjidToName( tr_objid, name, sizeof(name), cdh_mNName); 
  if (EVEN(sts)) {
    *status = sts;
    return;
  }
  strcpy( title, "Trace ");
  strcat( title, name);

  /* Find plcwindow */
  sts = gdh_GetObjectClass( tr_objid, &cid);
  if ( EVEN(sts)) {
    *status = sts;
    return;
  }

  if ( !(cid == pwr_cClass_windowplc ||
         cid == pwr_cClass_windowcond ||
         cid == pwr_cClass_windoworderact ||
         cid == pwr_cClass_windowsubstep )) {
    sts = gdh_GetChild( tr_objid, &window_objid);
    if ( EVEN(sts)) {
      *status = sts;
      return;
    }
  }
  else
    window_objid = tr_objid; 

  sts = gdh_GetObjectClass( window_objid, &cid);
  if ( EVEN(sts)) {
    *status = sts;
    return;
  }

  if ( !(cid == pwr_cClass_windowplc ||
         cid == pwr_cClass_windowcond ||
         cid == pwr_cClass_windoworderact ||
         cid == pwr_cClass_windowsubstep )) {
    *status = 0;
    return;
  }

  sts = get_filename( window_objid, filename, &m_has_host, hostname, 
		      plcconnect);
  if ( EVEN(sts)) {
    *status = sts;
    return;
  }

  /* Create object context */
  objid = window_objid;
  if ( m_has_host) {
    strcpy( m_hostname, hostname);
    strcpy( m_plcconnect, plcconnect);
  }

  char *titleutf8 = g_convert( title, -1, "UTF-8", "ISO8859-1", NULL, NULL, NULL);

  // Gtk
  toplevel = (GtkWidget *) g_object_new( GTK_TYPE_WINDOW, 
					 "default-height", window_height,
					 "default-width", window_width,
					 "title", titleutf8,
					 NULL);
  g_free( titleutf8);

  g_signal_connect( toplevel, "delete_event", G_CALLBACK(delete_event), this);
  g_signal_connect( toplevel, "destroy", G_CALLBACK(destroy_event), this);

  CoWowGtk::SetWindowIcon( toplevel);

  GtkAccelGroup *accel_g = (GtkAccelGroup *) g_object_new(GTK_TYPE_ACCEL_GROUP, NULL);
  gtk_window_add_accel_group(GTK_WINDOW(toplevel), accel_g);

  GtkMenuBar *menu_bar = (GtkMenuBar *) g_object_new(GTK_TYPE_MENU_BAR, NULL);

  // File Entry
  // Submenu Print
  GtkWidget *file_print = gtk_menu_item_new_with_mnemonic( CoWowGtk::translate_utf8("_Print"));
  g_signal_connect( file_print, "activate", 
		    G_CALLBACK(activate_print), this);

  GtkWidget *file_print_select = gtk_menu_item_new_with_mnemonic( CoWowGtk::translate_utf8("Print _Selected Documents"));
  g_signal_connect( file_print_select, "activate", 
		    G_CALLBACK(activate_printselect), this);

  GtkWidget *file_savetrace = gtk_menu_item_new_with_mnemonic( CoWowGtk::translate_utf8("Save _Trace"));
  g_signal_connect( file_savetrace, "activate", 
		    G_CALLBACK(activate_savetrace), this);

  GtkWidget *file_restoretrace = gtk_menu_item_new_with_mnemonic( CoWowGtk::translate_utf8("_Restore Trace"));
  g_signal_connect( file_restoretrace, "activate", 
		    G_CALLBACK(activate_restoretrace), this);

  GtkWidget *file_cleartrace = gtk_menu_item_new_with_mnemonic( CoWowGtk::translate_utf8("C_lear Trace"));
  g_signal_connect( file_cleartrace, "activate", 
		    G_CALLBACK(activate_cleartrace), this);

  GtkWidget *file_close = gtk_image_menu_item_new_from_stock(GTK_STOCK_CLOSE, accel_g);
  g_signal_connect(file_close, "activate", G_CALLBACK(activate_close), this);

  GtkMenu *file_menu = (GtkMenu *) g_object_new( GTK_TYPE_MENU, NULL);
  gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), file_print);
  gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), file_print_select);
  gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), file_savetrace);
  gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), file_restoretrace);
  gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), file_cleartrace);
  gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), file_close);

  GtkWidget *file = gtk_menu_item_new_with_mnemonic( CoWowGtk::translate_utf8("_File"));
  gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), file);
  gtk_menu_item_set_submenu(GTK_MENU_ITEM(file), GTK_WIDGET(file_menu));

  // Functions Entry
  GtkWidget *functions_open_object = gtk_menu_item_new_with_mnemonic( CoWowGtk::translate_utf8("_Open Object"));
  g_signal_connect( functions_open_object, "activate", 
		    G_CALLBACK(activate_open_object), this);
  gtk_widget_add_accelerator( functions_open_object, "activate", accel_g,
  			      'a', GdkModifierType(GDK_CONTROL_MASK), 
  			      GTK_ACCEL_VISIBLE);

  GtkWidget *functions_open_subwindow = gtk_menu_item_new_with_mnemonic( CoWowGtk::translate_utf8("Open S_ubwindow"));
  g_signal_connect( functions_open_subwindow, "activate", 
		    G_CALLBACK(activate_open_subwindow), this);
  gtk_widget_add_accelerator( functions_open_subwindow, "activate", accel_g,
  			      'l', GdkModifierType(GDK_CONTROL_MASK), 
  			      GTK_ACCEL_VISIBLE);

  GtkWidget *functions_display_object = gtk_menu_item_new_with_mnemonic( CoWowGtk::translate_utf8("_Display object in Navigator"));
  g_signal_connect( functions_display_object, "activate", 
		    G_CALLBACK(activate_display_object), this);
  gtk_widget_add_accelerator( functions_display_object, "activate", accel_g,
  			      'd', GdkModifierType(GDK_CONTROL_MASK), 
  			      GTK_ACCEL_VISIBLE);

  GtkWidget *functions_show_cross = gtk_menu_item_new_with_mnemonic( CoWowGtk::translate_utf8("_Show Crossreferences"));
  g_signal_connect( functions_show_cross, "activate", 
		    G_CALLBACK(activate_show_cross), this);
  gtk_widget_add_accelerator( functions_show_cross, "activate", accel_g,
  			      'r', GdkModifierType(GDK_CONTROL_MASK), 
  			      GTK_ACCEL_VISIBLE);

  GtkWidget *functions_open_classgraph = gtk_menu_item_new_with_mnemonic( CoWowGtk::translate_utf8("_Open ObjectGraph"));
  g_signal_connect( functions_open_classgraph, "activate", 
		    G_CALLBACK(activate_open_classgraph), this);
  gtk_widget_add_accelerator( functions_open_classgraph, "activate", accel_g,
  			      'g', GdkModifierType(GDK_CONTROL_MASK), 
  			      GTK_ACCEL_VISIBLE);

  GtkWidget *functions_collect_insert = gtk_menu_item_new_with_mnemonic( CoWowGtk::translate_utf8("_Collect Insert"));
  g_signal_connect( functions_collect_insert, "activate", 
		    G_CALLBACK(activate_collect_insert), this);
  gtk_widget_add_accelerator( functions_collect_insert, "activate", accel_g,
  			      'v', GdkModifierType(GDK_CONTROL_MASK), 
  			      GTK_ACCEL_VISIBLE);

  GtkMenu *functions_menu = (GtkMenu *) g_object_new( GTK_TYPE_MENU, NULL);
  gtk_menu_shell_append(GTK_MENU_SHELL(functions_menu), functions_open_object);
  gtk_menu_shell_append(GTK_MENU_SHELL(functions_menu), functions_open_subwindow);
  gtk_menu_shell_append(GTK_MENU_SHELL(functions_menu), functions_display_object);
  gtk_menu_shell_append(GTK_MENU_SHELL(functions_menu), functions_show_cross);
  gtk_menu_shell_append(GTK_MENU_SHELL(functions_menu), functions_open_classgraph);
  gtk_menu_shell_append(GTK_MENU_SHELL(functions_menu), functions_collect_insert);

  GtkWidget *functions = gtk_menu_item_new_with_mnemonic( CoWowGtk::translate_utf8("_Functions"));
  gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), functions);
  gtk_menu_item_set_submenu(GTK_MENU_ITEM(functions), GTK_WIDGET(functions_menu));


  // View Entry

  GtkWidget *view_zoom_in = gtk_image_menu_item_new_from_stock(GTK_STOCK_ZOOM_IN, NULL);
  g_signal_connect( view_zoom_in, "activate", 
		    G_CALLBACK(activate_zoomin), this);
  gtk_widget_add_accelerator( view_zoom_in, "activate", accel_g,
  			      'i', GdkModifierType(GDK_CONTROL_MASK), 
  			      GTK_ACCEL_VISIBLE);

  GtkWidget *view_zoom_out = gtk_image_menu_item_new_from_stock(GTK_STOCK_ZOOM_OUT, NULL);
  g_signal_connect( view_zoom_out, "activate", 
		    G_CALLBACK(activate_zoomout), this);
  gtk_widget_add_accelerator( view_zoom_out, "activate", accel_g,
  			      'o', GdkModifierType(GDK_CONTROL_MASK), 
  			      GTK_ACCEL_VISIBLE);

  GtkWidget *view_zoom_reset = gtk_image_menu_item_new_from_stock(GTK_STOCK_ZOOM_100, NULL);
  g_signal_connect( view_zoom_reset, "activate", 
		    G_CALLBACK(activate_zoomreset), this);
  gtk_widget_add_accelerator( view_zoom_reset, "activate", accel_g,
  			      'b', GdkModifierType(GDK_CONTROL_MASK), 
  			      GTK_ACCEL_VISIBLE);

  // Submenu ScanTime
  GSList *view_sc_group = NULL;
  GtkWidget *view_scantime1 = gtk_radio_menu_item_new_with_mnemonic( view_sc_group, 
									"0.50 s");
  view_sc_group = gtk_radio_menu_item_get_group( GTK_RADIO_MENU_ITEM(view_scantime1));
  g_signal_connect( view_scantime1, "activate", 
		    G_CALLBACK(activate_scantime1), this);

  GtkWidget *view_scantime2 = gtk_radio_menu_item_new_with_mnemonic( view_sc_group, 
									"0.20 s");
  view_sc_group = gtk_radio_menu_item_get_group( GTK_RADIO_MENU_ITEM(view_scantime1));
  g_signal_connect( view_scantime2, "activate", 
		    G_CALLBACK(activate_scantime2), this);

  GtkWidget *view_scantime3 = gtk_radio_menu_item_new_with_mnemonic( view_sc_group, 
									"0.10 s");
  view_sc_group = gtk_radio_menu_item_get_group( GTK_RADIO_MENU_ITEM(view_scantime1));
  g_signal_connect( view_scantime3, "activate", 
		    G_CALLBACK(activate_scantime3), this);

  GtkWidget *view_scantime4 = gtk_radio_menu_item_new_with_mnemonic( view_sc_group, 
									"0.05 s");
  view_sc_group = gtk_radio_menu_item_get_group( GTK_RADIO_MENU_ITEM(view_scantime1));
  g_signal_connect( view_scantime4, "activate", 
		    G_CALLBACK(activate_scantime4), this);

  GtkWidget *view_scantime5 = gtk_radio_menu_item_new_with_mnemonic( view_sc_group, 
									"0.02 s");
  g_signal_connect( view_scantime5, "activate", 
		    G_CALLBACK(activate_scantime5), this);

  GtkWidget *view_sc = gtk_menu_item_new_with_mnemonic( CoWowGtk::translate_utf8("_ScanTime"));
  GtkMenu *view_sc_menu = (GtkMenu *) g_object_new( GTK_TYPE_MENU, NULL);
  gtk_menu_shell_append(GTK_MENU_SHELL(view_sc_menu), view_scantime1);
  gtk_menu_shell_append(GTK_MENU_SHELL(view_sc_menu), view_scantime2);
  gtk_menu_shell_append(GTK_MENU_SHELL(view_sc_menu), view_scantime3);
  gtk_menu_shell_append(GTK_MENU_SHELL(view_sc_menu), view_scantime4);
  gtk_menu_shell_append(GTK_MENU_SHELL(view_sc_menu), view_scantime5);

  gtk_menu_item_set_submenu(GTK_MENU_ITEM(view_sc),
			    GTK_WIDGET(view_sc_menu));

  GtkMenu *view_menu = (GtkMenu *) g_object_new( GTK_TYPE_MENU, NULL);
  gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), view_zoom_in);
  gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), view_zoom_out);
  gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), view_zoom_reset);
  gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), view_sc);

  GtkWidget *view = gtk_menu_item_new_with_mnemonic( CoWowGtk::translate_utf8("_View"));
  gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), view);
  gtk_menu_item_set_submenu(GTK_MENU_ITEM(view), GTK_WIDGET(view_menu));

  // Mode entry
  GSList *mode_group = NULL;
  GtkWidget *mode_view = gtk_radio_menu_item_new_with_mnemonic( mode_group, CoWowGtk::translate_utf8("V_iew"));
  mode_group = gtk_radio_menu_item_get_group( GTK_RADIO_MENU_ITEM(mode_view));
  g_signal_connect( mode_view, "activate", 
		    G_CALLBACK(activate_view), this);

  GtkWidget *mode_trace = gtk_radio_menu_item_new_with_mnemonic( mode_group, CoWowGtk::translate_utf8("_Trace"));
  mode_group = gtk_radio_menu_item_get_group( GTK_RADIO_MENU_ITEM(mode_trace));
  g_signal_connect( mode_trace, "activate", 
		    G_CALLBACK(activate_trace), this);

  GtkWidget *mode_simulate = gtk_radio_menu_item_new_with_mnemonic( mode_group, CoWowGtk::translate_utf8("_Simulate"));
  gtk_widget_add_accelerator( mode_simulate, "activate", accel_g,
  			      's', GdkModifierType(GDK_CONTROL_MASK | GDK_SHIFT_MASK), 
  			      GTK_ACCEL_VISIBLE);
  g_signal_connect( mode_simulate, "activate", 
		    G_CALLBACK(activate_simulate), this);

  GtkMenu *mode_menu = (GtkMenu *) g_object_new( GTK_TYPE_MENU, NULL);
  gtk_menu_shell_append(GTK_MENU_SHELL(mode_menu), mode_view);
  gtk_menu_shell_append(GTK_MENU_SHELL(mode_menu), mode_trace);
  gtk_menu_shell_append(GTK_MENU_SHELL(mode_menu), mode_simulate);

  GtkWidget *mode = gtk_menu_item_new_with_mnemonic( CoWowGtk::translate_utf8("_Mode"));
  gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), mode);
  gtk_menu_item_set_submenu(GTK_MENU_ITEM(mode), GTK_WIDGET(mode_menu));

  // Menu Help
  GtkWidget *help_help = gtk_image_menu_item_new_with_mnemonic( CoWowGtk::translate_utf8("On _Trace"));
  gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM(help_help), 
				 gtk_image_new_from_stock( "gtk-help", GTK_ICON_SIZE_MENU));
  g_signal_connect(help_help, "activate", G_CALLBACK(activate_help), this);
  gtk_widget_add_accelerator( help_help, "activate", accel_g,
			      'h', GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);

  GtkWidget *help_plcpgm = gtk_check_menu_item_new_with_mnemonic( CoWowGtk::translate_utf8("On _PlcPgm"));
  g_signal_connect( help_plcpgm, "activate", 
		    G_CALLBACK(activate_helpplc), this);

  GtkMenu *help_menu = (GtkMenu *) g_object_new( GTK_TYPE_MENU, NULL);
  gtk_menu_shell_append(GTK_MENU_SHELL(help_menu), help_help);
  gtk_menu_shell_append(GTK_MENU_SHELL(help_menu), help_plcpgm);

  GtkWidget *help = gtk_menu_item_new_with_mnemonic( CoWowGtk::translate_utf8("_Help"));
  gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), help);
  gtk_menu_item_set_submenu(GTK_MENU_ITEM(help), GTK_WIDGET(help_menu));

  // Toolbar
  GtkToolbar *tools = (GtkToolbar *) g_object_new(GTK_TYPE_TOOLBAR, NULL);

  GtkWidget *tools_display_object = gtk_button_new();
  dcli_translate_filename( fname, "$pwr_exe/xtt_navigator.png");
  gtk_container_add( GTK_CONTAINER(tools_display_object), 
		     gtk_image_new_from_file( fname));
  g_signal_connect(tools_display_object, "clicked", G_CALLBACK(activate_display_object), this);
  gtk_toolbar_append_widget( tools, tools_display_object, "Display object in Navigator", "");
  
  GtkWidget *tools_show_cross = gtk_button_new();
  dcli_translate_filename( fname, "$pwr_exe/xtt_crossref.png");
  gtk_container_add( GTK_CONTAINER(tools_show_cross), 
		     gtk_image_new_from_file( fname));
  g_signal_connect(tools_show_cross, "clicked", G_CALLBACK(activate_show_cross), this);
  gtk_toolbar_append_widget( tools, tools_show_cross, "Show Crossreferences", "");
  
  GtkWidget *tools_zoom_in = gtk_button_new();
  dcli_translate_filename( fname, "$pwr_exe/xtt_zoom_in.png");
  gtk_container_add( GTK_CONTAINER(tools_zoom_in), 
		     gtk_image_new_from_file( fname));
  g_signal_connect(tools_zoom_in, "clicked", G_CALLBACK(activate_zoomin), this);
  gtk_toolbar_append_widget( tools, tools_zoom_in, "Zoom in", "");

  GtkWidget *tools_zoom_out = gtk_button_new();
  dcli_translate_filename( fname, "$pwr_exe/xtt_zoom_out.png");
  gtk_container_add( GTK_CONTAINER(tools_zoom_out), 
		     gtk_image_new_from_file( fname));
  g_signal_connect(tools_zoom_out, "clicked", G_CALLBACK(activate_zoomout), this);
  gtk_toolbar_append_widget( tools, tools_zoom_out, "Zoom out", "");

  GtkWidget *tools_zoom_reset = gtk_button_new();
  dcli_translate_filename( fname, "$pwr_exe/xtt_zoom_reset.png");
  gtk_container_add( GTK_CONTAINER(tools_zoom_reset), 
		     gtk_image_new_from_file( fname));
  g_signal_connect(tools_zoom_reset, "clicked", G_CALLBACK(activate_zoomreset), this);
  gtk_toolbar_append_widget( tools, tools_zoom_reset, "Zoom reset", "");

  // Flow widget
  GtkWidget *flow_scrolled = scrolledflowwidgetgtk_new( init_flow, 
							this, &flow_widget);
  gtk_widget_show_all(flow_widget);

  nav_widget = flownavwidgetgtk_new( flow_widget);

  GtkWidget *paned = gtk_hpaned_new();
  gtk_paned_pack1( GTK_PANED(paned), flow_scrolled, TRUE, TRUE);
  gtk_paned_pack2( GTK_PANED(paned), nav_widget, FALSE, TRUE);

  GtkWidget *vbox = gtk_vbox_new( FALSE, 0);
  gtk_box_pack_start( GTK_BOX(vbox), GTK_WIDGET(menu_bar), FALSE, FALSE, 0);
  gtk_box_pack_start( GTK_BOX(vbox), GTK_WIDGET(tools), FALSE, FALSE, 0);
  gtk_box_pack_start( GTK_BOX(vbox), GTK_WIDGET(paned), TRUE, TRUE, 0);

  gtk_container_add( GTK_CONTAINER(toplevel), vbox);
  gtk_widget_show_all( toplevel);

  gtk_paned_set_position( GTK_PANED(paned), window_width - nav_width);

#if 0
  // Navigator window
  nav_shell = (GtkWidget *) g_object_new( GTK_TYPE_WINDOW, 
					  "default-height", 200,
					  "default-width", 200,
					  "title", "Navigator",
					  NULL);
  g_signal_connect( nav_shell, "delete_event", G_CALLBACK(nav_delete_event), this);

  nav_widget = flownavwidgetgtk_new( flow_widget);
  gtk_container_add( GTK_CONTAINER(nav_shell), nav_widget);
  gtk_widget_show_all( nav_shell);
#endif

  wow = new CoWowGtk( toplevel);
  trace_timerid = wow->timer_new();

  viewsetup();
  flow_Open( flow_ctx, filename);

  gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM( mode_trace), TRUE);
  gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM( view_scantime1), TRUE);

  //trasetup();
  //trace_start();

#if defined OS_LINUX
  {
    struct stat info;

    if ( stat( filename, &info) != -1)
      version = info.st_ctime;    
  }
#endif

  // Check version
  unsigned int flow_version;
  pwr_tUInt32 window_version;
  pwr_tAName aname;

  flow_GetCtxUserVersion( flow_ctx, &flow_version);

  strcpy( aname, name);
  strcat( aname, ".Version");

  sts = gdh_GetObjectInfo( aname, &window_version, sizeof(window_version));
  if ( EVEN(sts)) return;

  if ( flow_version > window_version)
    wow->DisplayError( "Version mismatch", "Trace file is newer than database version");
  else if ( flow_version < window_version)
    wow->DisplayError( "Version mismatch", "Trace file is older than database version");
}
Beispiel #16
0
int XNav::GetObjectMenu( xmenu_sMenuCall	*ip,
			 pwr_tCid		classid,
			 xmenu_sMenuItem	**Item,
			 pwr_tUInt32		Level,
			 int			*nItems,
			 int			AddSeparator,
			 pwr_sAttrRef		*CurrentObject)
{
  int                   sts;
  pwr_tObjid            child;
  pwr_tObjid		menu_objid;
  char  		menu[80];
  pwr_tOName  		classname;
  pwr_sAttrRef		currentar = pwr_cNAttrRef;
  pwr_tCid		supercid;


  if ( cdh_ObjidIsNotNull( CurrentObject->Objid))
    currentar = *CurrentObject;

    if ( ip->ItemType == xmenu_eItemType_Object) {
      // Popup-menu for an object
      if ( !cdh_tidIsCid( classid))
	return XNAV__SUCCESS;


      // Get the RtXtt common menu-objects
      strcpy( menu, "pwrs:Class-$Object-RtXtt");
      sts = gdh_NameToObjid( menu, &menu_objid);
      if ( ODD(sts)) {
        sts = gdh_GetChild( menu_objid, &child);
        while( ODD(sts)) {
          sts = getAllMenuItems( ip, Item, child, Level, nItems, 0, &currentar);
          if ( EVEN(sts)) return sts;
          sts = gdh_GetNextSibling( child, &child);
        }
      }

      // Get the RtXtt menu-objects for superclasses
      // TODO shadow overlayed methods...
      sts = gdh_GetSuperClass( classid, &supercid, CurrentObject->Objid);
      while ( ODD(sts)) {
	sts = gdh_ObjidToName( cdh_ClassIdToObjid( supercid), classname, 
			       sizeof(classname), cdh_mName_volumeStrict);
	if ( EVEN(sts)) return sts;

	sprintf( menu, "%s-RtXtt", classname);
	sts = gdh_NameToObjid( menu, &menu_objid);
	if ( ODD(sts)) {
	  sts = gdh_GetChild( menu_objid, &child);
	  while( ODD(sts)) {
	    sts = getAllMenuItems( ip, Item, child, 0, nItems, 0, &currentar);
	    if ( EVEN(sts)) return sts;
	    sts = gdh_GetNextSibling( child, &child);
	  }
	}
	sts = gdh_GetSuperClass( supercid, &supercid, CurrentObject->Objid);
      }

      // Get the RtXtt menu-objects for this class, or for superclasses
      sts = gdh_ObjidToName( cdh_ClassIdToObjid( classid), classname, 
		     sizeof(classname), cdh_mName_volumeStrict);
      if ( EVEN(sts)) return sts;

      sprintf( menu, "%s-RtXtt", classname);
      sts = gdh_NameToObjid( menu, &menu_objid);
      if ( ODD(sts)) {
        sts = gdh_GetChild( menu_objid, &child);
        while( ODD(sts)) {
          sts = getAllMenuItems( ip, Item, child, 0, nItems, 0, &currentar);
          if ( EVEN(sts)) return sts;
          sts = gdh_GetNextSibling( child, &child);
        }
      }
    }
    else if ( ip->ItemType == xmenu_eItemType_AttrObject) {   
      // Find attribute object methods...
      if ( !cdh_tidIsCid( classid))
	return XNAV__SUCCESS;

      // Get the RtXtt common menu-objects
      strcpy( menu, "pwrs:Class-$Object-RtXttAttrObject");
      sts = gdh_NameToObjid( menu, &menu_objid);
      if ( ODD(sts)) {
        sts = gdh_GetChild( menu_objid, &child);
        while( ODD(sts)) {
          sts = getAllMenuItems( ip, Item, child, 0, nItems, 0, &currentar);
          if ( EVEN(sts)) return sts;
          sts = gdh_GetNextSibling( child, &child);
        }
      }

      // Get the RtXtt menu-objects for this class
      sts = gdh_ObjidToName( cdh_ClassIdToObjid( classid), classname, 
		     sizeof(classname), cdh_mName_volumeStrict);
      if ( EVEN(sts)) return sts;

      sprintf( menu, "%s-RtXtt", classname);
      sts = gdh_NameToObjid( menu, &menu_objid);
      if ( ODD(sts)) {
        sts = gdh_GetChild( menu_objid, &child);
        while( ODD(sts)) {
          sts = getAllMenuItems( ip, Item, child, 0, nItems, 0, &currentar);
          if ( EVEN(sts)) return sts;
          sts = gdh_GetNextSibling( child, &child);
        }
      }
    }
    else if ( ip->ItemType == xmenu_eItemType_Attribute) {   
      // Find attribute methods...
      // Get the RtXttAttribute common menu-objects
      strcpy( menu, "pwrs:Class-$Object-RtXttAttribute");
      sts = gdh_NameToObjid( menu, &menu_objid);
      if ( ODD(sts)) {
        sts = gdh_GetChild( menu_objid, &child);
        while( ODD(sts)) {
          sts = getAllMenuItems( ip, Item, child, 0, nItems, 0, &currentar);
          if ( EVEN(sts)) return sts;
          sts = gdh_GetNextSibling( child, &child);
        }
      }
    }
    else if ( ip->ItemType == xmenu_eItemType_Crossref) {   
      // Find attribute methods...
      // Get the RtXttCrossref common menu-objects
      strcpy( menu, "pwrs:Class-$Object-RtXttCrossref");
      sts = gdh_NameToObjid( menu, &menu_objid);
      if ( ODD(sts)) {
        sts = gdh_GetChild( menu_objid, &child);
        while( ODD(sts)) {
          sts = getAllMenuItems( ip, Item, child, 0, nItems, 0, &currentar);
          if ( EVEN(sts)) return sts;
          sts = gdh_GetNextSibling( child, &child);
        }
      }
    }

  return XNAV__SUCCESS;
}
Beispiel #17
0
static pwr_tStatus xtt_pb_dp_slave_load_modules( xtt_slave_sCtx *ctx)
{
  pwr_tOid oid;
  pwr_tCid cid;
  int found;
  pwr_tObjName name;
  pwr_tString40 module_name;
  int sts;
  pwr_tAttrRef maref, aaref;

  for ( sts = gdh_GetChild( ctx->aref.Objid, &oid);
	ODD(sts);
	sts = gdh_GetNextSibling( oid, &oid)) {

    // Check that this is a module
    sts = gdh_GetObjectClass( oid, &cid);
    if ( EVEN(sts)) return sts;

    found = 0;
    for ( int i = 0; ; i++) {
      if ( ctx->gsd->module_classlist[i].cid == 0)
	break;
      if ( ctx->gsd->module_classlist[i].cid == cid) {
	found = 1;
	break;
      }
    }
    if ( !found)
      // This is not a known module object
      continue;

    // Get name
    sts = gdh_ObjidToName( oid, name, sizeof(name), cdh_mName_object);
    if ( EVEN(sts)) return sts;

    maref = cdh_ObjidToAref( oid);

    // Get ModuleName attribute
    sts = gdh_ArefANameToAref( &maref, "ModuleName", &aaref);
    if ( EVEN(sts)) return sts;
      
    sts = gdh_GetObjectInfoAttrref( &aaref, module_name, sizeof(module_name));
    if ( EVEN(sts)) return sts;

    ctx->gsd->add_module_conf( cid, oid, name, module_name);
  }

  // Set address
  pwr_tUInt16 address;
  
  sts = gdh_ArefANameToAref( &ctx->aref, "SlaveAddress", &aaref);
  if ( EVEN(sts)) return sts;

  sts = gdh_GetObjectInfoAttrref( &aaref, &address, sizeof(address));
  if ( EVEN(sts)) return sts;

  ctx->gsd->address = address;

  // Set byte order
  pwr_tByteOrderingEnum byte_order;
  
  sts = gdh_ArefANameToAref( &ctx->aref, "ByteOrdering", &aaref);
  if ( EVEN(sts)) return sts;

  sts = gdh_GetObjectInfoAttrref( &aaref, &byte_order, sizeof(byte_order));
  if ( EVEN(sts)) return sts;

  ctx->gsd->byte_order = byte_order;

  // Set Ext_User_Prm_Data
  pwr_tUInt8 prm_user_data[256];
  pwr_tUInt16 prm_user_data_len;
  int len;
  
  sts = gdh_ArefANameToAref( &ctx->aref, "PrmUserData", &aaref);
  if ( EVEN(sts)) return sts;

  sts = gdh_GetObjectInfoAttrref( &aaref, prm_user_data, sizeof(prm_user_data));
  if ( EVEN(sts)) return sts;

  sts = gdh_ArefANameToAref( &ctx->aref, "PrmUserDataLen", &aaref);
  if ( EVEN(sts)) return sts;

  sts = gdh_GetObjectInfoAttrref( &aaref, &prm_user_data_len, sizeof(prm_user_data_len));
  if ( EVEN(sts)) return sts;

  len = prm_user_data_len;
  if ( len != 0) {
    sts = ctx->gsd->unpack_ext_user_prm_data( (char *)prm_user_data, len);
    if ( EVEN(sts)) return sts;
  }
  return 1;
}
Beispiel #18
0
static pwr_tStatus IoRackInit (
  io_tCtx	ctx,
  io_sAgent	*ap,
  io_sRack	*rp
) 
{
  io_sServerLocal *local;
  pthread_t 	thread;
  pwr_tOName 	name;
  pwr_tStatus   sts;
  pwr_sClass_Modbus_TCP_Server *op;
  int 		i;
  unsigned short port;
    
  op = (pwr_sClass_Modbus_TCP_Server *) rp->op;
  op->Connections = 0;

  port = op->Port == 0 ? 502 : op->Port;

  sts = gdh_ObjidToName(rp->Objid, (char *) &name, sizeof(name), cdh_mNName);
  errh_Info( "Init of Modbus TCP Server %s", name);

  rp->Local = calloc(1, sizeof(io_sServerLocal));
  local = rp->Local;

  if ( op->DisableServer)
    return IO__SUCCESS;

  /* Create socket, store in local struct */
  uid_t ruid;
  ruid = getuid();
  printf( "ruid: %d\n", ruid);
  
  local->s = socket(AF_INET, SOCK_STREAM, 0);
  if (local->s < 0) { 
    errh_Error( "Error creating socket for IO modbus tcp server %s, %d", rp->Name, local->s);
    return 0;
  }

  local->loc_addr.sin_family = AF_INET;
  local->loc_addr.sin_port = htons(port);
  for ( i = 0; i < 10; i++) {
    sts = bind( local->s, (struct sockaddr *) &local->loc_addr, sizeof(local->loc_addr));
    if ( sts == 0)
      break;
    perror( "Modbus TCP Bind socket failure, retrying... ");
    sleep( 10);
  }
  if ( sts != 0) {
    printf( "Modbus TCP Bind socket failure, exiting");
    errh_Error( "Error bind socket to port for IO modbus tcp server %s, %d", rp->Name, local->s);
    return 0;
  }

  errh_Info( "Modbus TCP Sever bind to port %d, %s", port, name);
  
  sts = listen( local->s, 16);

  sts = thread_MutexInit( &local->mutex);
  if ( EVEN(sts)) return sts;

  /* Create a thread that listens for connections */
  sts = pthread_create( &thread, NULL, mb_connect, (void *)rp);
  if ( sts != 0) return sts;

  sts = mb_init_channels( ctx, ap, rp);
  if ( EVEN(sts)) return sts;

  op->Status = MB__NORMAL;

  return IO__SUCCESS;
}
Beispiel #19
0
static pwr_tStatus IoRackInit (
  io_tCtx	ctx,
  io_sAgent	*ap,
  io_sRack	*rp
) 
{
  io_sCardLocal *local_card;
  io_sCard *cardp;
  short input_counter;
  short output_counter;
  pwr_sClass_Pb_DP_Slave *op;
  pwr_sClass_Pb_Di *dip;
  pwr_sClass_Pb_Do *dop;
  pwr_sClass_Pb_Ai *aip;
  pwr_sClass_Pb_Ao *aop;
  pwr_sClass_Pb_Ii *iip;
  pwr_sClass_Pb_Io *iop;
  pwr_sClass_Pb_Module *mp;
  char name[196];
  pwr_tStatus sts;
  pwr_tCid cid;
  
  io_sChannel *chanp;
  int i, latent_input_count, latent_output_count;
  pwr_tInt32 chan_size;
  pwr_sClass_ChanDi *chan_di;
  pwr_sClass_ChanDo *chan_do;
  pwr_sClass_ChanAi *chan_ai;
  pwr_sClass_ChanAit *chan_ait;
  pwr_sClass_ChanIi *chan_ii;
  pwr_sClass_ChanAo *chan_ao;
  pwr_sClass_ChanIo *chan_io;

  sts = gdh_ObjidToName(rp->Objid, (char *) &name, sizeof(name), cdh_mNName);
  errh_Info( "Init of Profibus DP Slave and Modules %s", name);

  op = (pwr_sClass_Pb_DP_Slave *) rp->op;
  
  // Do configuration check and initialize modules.

  cardp = rp->cardlist;
  input_counter = 0;
  output_counter = 0;
  op->NumberModules = 0;

  latent_input_count = 0;
  latent_output_count = 0;

  while(cardp) {
    local_card = calloc(1, sizeof(*local_card));
    cardp->Local = local_card;
    local_card->input_area = (void *) &(op->Inputs);
    local_card->output_area = (void *) &(op->Outputs);

    /* From v4.1.3 we can have subclasses, find the super class */
    
    cid = cardp->Class;
    while ( ODD( gdh_GetSuperClass( cid, &cid, cardp->Objid))) ;

    switch (cid) {

      /* Old style configuring with Pb_xx objects. Still here for combatibility reasons. 
         New systems (from v4.1.3) should be build with Pb_Module objects or subclasses */
	 
      case pwr_cClass_Pb_Di:
        dip = (pwr_sClass_Pb_Di *) cardp->op;
        dip->OffsetInputs = input_counter;
        dip->BytesOfInput = dip->NumberOfChannels / 8;
        input_counter += dip->BytesOfInput;
        dip->Status = PB_MODULE_STATE_OPERATE;
        break;

      case pwr_cClass_Pb_Do:
        dop = (pwr_sClass_Pb_Do *) cardp->op;
        dop->OffsetOutputs = output_counter;
        dop->BytesOfOutput = dop->NumberOfChannels / 8;
        output_counter += dop->BytesOfOutput;
        dop->Status = PB_MODULE_STATE_OPERATE;
        break;

      case pwr_cClass_Pb_Ai:
        aip = (pwr_sClass_Pb_Ai *) cardp->op;
        aip->OffsetInputs = input_counter;
        aip->BytesOfInput = aip->NumberOfChannels * aip->BytesPerChannel;
        input_counter += aip->BytesOfInput;
        aip->Status = PB_MODULE_STATE_OPERATE;
        break;

      case pwr_cClass_Pb_Ao:
        aop = (pwr_sClass_Pb_Ao *) cardp->op;
        aop->OffsetOutputs = output_counter;
        aop->BytesOfOutput = aop->NumberOfChannels * aop->BytesPerChannel;
        output_counter += aop->BytesOfOutput;
        aop->Status = PB_MODULE_STATE_OPERATE;
        break;

      case pwr_cClass_Pb_Ii:
        iip = (pwr_sClass_Pb_Ii *) cardp->op;
        iip->OffsetInputs = input_counter;
        iip->BytesOfInput = iip->NumberOfChannels * iip->BytesPerChannel;
        input_counter += iip->BytesOfInput;
        iip->Status = PB_MODULE_STATE_OPERATE;
        break;

      case pwr_cClass_Pb_Io:
        iop = (pwr_sClass_Pb_Io *) cardp->op;
        iop->OffsetOutputs = output_counter;
        iop->BytesOfOutput = iop->NumberOfChannels * iop->BytesPerChannel;
        output_counter += iop->BytesOfOutput;
        iop->Status = PB_MODULE_STATE_OPERATE;
        break;

      /* New style configuring (from v4.1.3) with Pb_Module objects or subclass. Loop all channels
        in the module and set channel size and offset. */	 

      case pwr_cClass_Pb_Module:
        mp = (pwr_sClass_Pb_Module *) cardp->op;
        mp->Status = PB__INITFAIL;
	cardp->offset = 0;
        for (i=0; i<cardp->ChanListSize; i++) {
          chanp = &cardp->chanlist[i];

	  if ( is_diag( &chanp->ChanAref)) {
	    chanp->udata |= PB_UDATA_DIAG;
	    switch (chanp->ChanClass) {	    
            case pwr_cClass_ChanIi:
	      chanp->offset = ((pwr_sClass_ChanIi *)chanp->cop)->Number;
	      chanp->size = GetChanSize( ((pwr_sClass_ChanIi *)chanp->cop)->Representation);
	      break;
	    default:
	      errh_Error( "Diagnostic channel class, card %s", cardp->Name);
	    }
	    continue;
	  }

          if (chanp->ChanClass != pwr_cClass_ChanDi) {
            input_counter += latent_input_count;
	    latent_input_count = 0;
          }

          if (chanp->ChanClass != pwr_cClass_ChanDo) {
            output_counter += latent_output_count;
	    latent_output_count = 0;
          }
      
          switch (chanp->ChanClass) {
      
            case pwr_cClass_ChanDi:
	      chan_di = (pwr_sClass_ChanDi *) chanp->cop;
              if (chan_di->Number == 0) {
	        input_counter += latent_input_count;
	        latent_input_count = 0;
	      }
              chanp->offset = input_counter;
	      chanp->mask = 1<<chan_di->Number;
	      if (chan_di->Representation == pwr_eDataRepEnum_Bit16 && op->ByteOrdering == pwr_eByteOrderingEnum_BigEndian) 
	        chanp->mask = swap16(chanp->mask);
	      if (chan_di->Representation == pwr_eDataRepEnum_Bit32 && op->ByteOrdering == pwr_eByteOrderingEnum_BigEndian)
	        chanp->mask = swap32((unsigned short) chanp->mask);
	      if (chan_di->Number == 0) latent_input_count = GetChanSize(chan_di->Representation);
//	      printf("Di channel found in %s, Number %d, Offset %d\n", cardp->Name, chan_di->Number, chanp->offset);
	      break;
	  
            case pwr_cClass_ChanAi:
	      chan_ai = (pwr_sClass_ChanAi *) chanp->cop;
              chanp->offset = input_counter;
	      chan_size = GetChanSize(chan_ai->Representation);
              chanp->size = chan_size;
	      chanp->mask = 0;
	      input_counter += chan_size;
              io_AiRangeToCoef(chanp);
//	      printf("Ai channel found in %s, Number %d, Offset %d\n", cardp->Name, chan_ai->Number, chanp->offset);
	      break;
	  
            case pwr_cClass_ChanAit:
	      chan_ait = (pwr_sClass_ChanAit *) chanp->cop;
              chanp->offset = input_counter;
	      chan_size = GetChanSize(chan_ait->Representation);
              chanp->size = chan_size;
	      chanp->mask = 0;
	      input_counter += chan_size;
              io_AiRangeToCoef(chanp);
	      break;
	  
            case pwr_cClass_ChanIi:
	      chan_ii = (pwr_sClass_ChanIi *) chanp->cop;
              chanp->offset = input_counter;
	      chan_size = GetChanSize(chan_ii->Representation);
              chanp->size = chan_size;
	      chanp->mask = 0;
	      input_counter += chan_size;
//	      printf("Ii channel found in %s, Number %d, Offset %d\n", cardp->Name, chan_ii->Number, chanp->offset);
	      break;
	  
            case pwr_cClass_ChanDo:
	      chan_do = (pwr_sClass_ChanDo *) chanp->cop;
              if (chan_do->Number == 0) {
	        output_counter += latent_output_count;
	        latent_output_count = 0;
	      }
              chanp->offset = output_counter;
	      chan_size = GetChanSize(chan_do->Representation);
	      chanp->mask = 1<<chan_do->Number;
	      if (chan_do->Representation == pwr_eDataRepEnum_Bit16 && op->ByteOrdering == pwr_eByteOrderingEnum_BigEndian) 
	        chanp->mask = swap16(chanp->mask);
	      if (chan_do->Representation == pwr_eDataRepEnum_Bit32 && op->ByteOrdering == pwr_eByteOrderingEnum_BigEndian)
	        chanp->mask = swap32((unsigned short) chanp->mask);
	      if (chan_do->Number == 0) latent_output_count = GetChanSize(chan_do->Representation);
//	      printf("Do channel found in %s, Number %d, Offset %d\n", cardp->Name, chan_do->Number, chanp->offset);
	      break;
	  
	    case pwr_cClass_ChanAo:
	      chan_ao = (pwr_sClass_ChanAo *) chanp->cop;
              chanp->offset = output_counter;
	      chan_size = GetChanSize(chan_ao->Representation);
              chanp->size = chan_size;
	      chanp->mask = 0;
	      output_counter += chan_size;
              io_AoRangeToCoef(chanp);
//	      printf("Ao channel found in %s, Number %d, Offset %d\n", cardp->Name, chan_ao->Number, chanp->offset);
	      break;
	  
            case pwr_cClass_ChanIo:
	      chan_io = (pwr_sClass_ChanIo *) chanp->cop;
              chanp->offset = output_counter;
	      chan_size = GetChanSize(chan_io->Representation);
              chanp->size = chan_size;
	      chanp->mask = 0;
	      output_counter += chan_size;
//	      printf("Io channel found in %s, Number %d, Offset %d\n", cardp->Name, chan_io->Number, chanp->offset);
	      break;
          }
        }

        mp->Status = PB__NOCONN;
        break;
    }

    op->NumberModules++;
    cardp = cardp->next;
  }

  return IO__SUCCESS;
}
Beispiel #20
0
int rtt_show_signals(
    menu_ctx parent_ctx, char* filename, char* windowname, int debug)
{
  pwr_tFileName default_filename;
  FILE* file;
  char line[500];
  int window_spaces;
  pwr_tOName window;
  pwr_tOName object;
  pwr_tOName objname;
  int spaces = 30;
  int sts;
  char* s;
  int wildcard;
  char title[250];
  char classname[32];
  int j;
  int index = 0;
  pwr_tObjid objid;
  pwr_tObjid childobjid;
  rtt_t_menu* menulist = 0;
  char filestr[80];
  int lines;
  int window_found;
  pwr_tVolumeId volid;

  window_found = 0;
  rtt_toupper(windowname, windowname);

  /* Check if wildcard */
  s = strchr(windowname, '*');
  if (s == 0)
    wildcard = 0;
  else
    wildcard = 1;

  /* Open file */
  if (filename == NULL) {
    /* Open file, first get the volume id */
    if (!wildcard) {
      sts = gdh_NameToObjid(windowname, &objid);
      if (EVEN(sts)) {
        rtt_message('E', "Window not found");
        return RTT__NOPICTURE;
      }
      volid = objid.vid;
    } else {
      sts = gdh_GetNodeObject(0, &objid);
      if (EVEN(sts))
        return sts;
      volid = objid.vid;
    }

    sprintf(default_filename, "%srtt_plc_%s.dat", rtt_pwr_dir("pwrp_load"),
        rtt_VolumeIdToStr(volid));
    rtt_get_defaultfilename(default_filename, filestr, NULL);
    file = fopen(filestr, "r");
  } else {
    rtt_get_defaultfilename(filename, filestr, ".lis");
    file = fopen(filestr, "r");
  }

  if (file == 0) {
    rtt_message('E', "Unable to open file");
    return RTT__NOPICTURE;
  }

  /* First line is a header, skip it */
  sts = rtt_get_signal_line(
      file, line, sizeof(line), &window_spaces, object, &lines);
  if (EVEN(sts))
    return RTT__NOFILE;

  /* Get the hierarchy */
  while (spaces >= 30) {
    /* This is still the header */
    sts = rtt_get_signal_line(
        file, line, sizeof(line), &spaces, object, &lines);
    if (EVEN(sts))
      return RTT__NOFILE;
  }
  window_spaces = spaces;

  while (1) {
    while (spaces != window_spaces) {
      sts = rtt_get_signal_line(
          file, line, sizeof(line), &spaces, object, &lines);
      if (EVEN(sts))
        goto finish;
    }
    strcpy(window, object);
    rtt_toupper(window, window);

    sts = rtt_wildcard(windowname, window);
    if (!sts) {
      window_found = 1;
      /* Hit, print the window */
      /* Get objid for the object */
      sts = gdh_NameToObjid(window, &objid);
      if (EVEN(sts)) {
        sts = rtt_get_signal_line(
            file, line, sizeof(line), &spaces, object, &lines);
        if (EVEN(sts))
          goto finish;
        continue;
      }

      /* Get the object name */
      sts = gdh_ObjidToName(objid, objname, sizeof(objname), cdh_mNName);
      if (EVEN(sts))
        return sts;

      /* Get class name */
      sts = rtt_objidtoclassname(objid, classname);
      if (EVEN(sts))
        return sts;

      /* Add class name to objname in title */
      strcpy(title, objname);
      for (j = strlen(title); j < 45; j++)
        strcat(title, " ");
      strcat(title, " ");
      strcat(title, classname);

      /* Mark if the object has children */
      sts = gdh_GetChild(objid, &childobjid);
      if (ODD(sts))
        strcat(title, " *");

      if (!debug) {
        sts = rtt_menu_list_add(&menulist, index, 0, title,
            &rtt_hierarchy_child, &rtt_object_parameters, &rtt_crossref_signal,
            objid, 0, 0, 0, 0);
        if (EVEN(sts))
          return sts;
        index++;
      }

      /* Find the signal list */
      sts = rtt_get_signal_line(
          file, line, sizeof(line), &spaces, object, &lines);
      if (EVEN(sts))
        goto finish;
      while (spaces > window_spaces) {
        if (streq(object, "Signals")) {
          /* This is the signals */
          sts = rtt_get_signal_line(
              file, line, sizeof(line), &spaces, object, &lines);
          if (EVEN(sts))
            goto finish;
          lines = 1;
          while ((spaces > window_spaces) && (lines == 1)) {
            /* Insert the object in menulist */

            /* Get objid for the object */
            sts = gdh_NameToObjid(object, &objid);
            if (EVEN(sts)) {
              /* End of this list, read next line and continue */
              sts = rtt_get_signal_line(
                  file, line, sizeof(line), &spaces, object, &lines);
              if (EVEN(sts))
                goto finish;
              continue;
            }
            /* Get the object name */
            sts = gdh_ObjidToName(objid, objname, sizeof(objname), cdh_mNName);
            if (EVEN(sts))
              return sts;

            /* Get class name */
            sts = rtt_objidtoclassname(objid, classname);
            if (EVEN(sts))
              return sts;

            /* Add class name to objname in title */
            strcpy(title, "    ");
            strcat(title, objname);
            for (j = strlen(title); j < 45; j++)
              strcat(title, " ");
            strcat(title, " ");
            strcat(title, classname);

            if (!debug) {
              sts = rtt_menu_list_add(&menulist, index, 0, title,
                  &rtt_hierarchy_child, &rtt_object_parameters,
                  &rtt_crossref_signal, objid, 0, 0, 0, 0);
              if (EVEN(sts))
                return sts;
              index++;
            } else {
              sts = rtt_debug_object_add(
                  objid, (rtt_t_menu_upd**)&menulist, &index, &one, 0, 0);
              if (EVEN(sts))
                return sts;
            }

            sts = rtt_get_signal_line(
                file, line, sizeof(line), &spaces, object, &lines);
            if (EVEN(sts))
              goto finish;
            /* Check if end of signals !! */
          }
        } else {
          sts = rtt_get_signal_line(
              file, line, sizeof(line), &spaces, object, &lines);
          if (EVEN(sts))
            goto finish;
        }
      }
      if (!wildcard)
        goto finish;
    } else {
      if (window_found)
        goto finish;

      sts = rtt_get_signal_line(
          file, line, sizeof(line), &spaces, object, &lines);
      if (EVEN(sts))
        goto finish;
    }
  }

finish:
  fclose(file);

  if (menulist != 0) {
    strcpy(title, "LIST OF SIGNALS");
    /*	  sts = rtt_menu_bubblesort( menulist);*/
    if (!debug)
      sts = rtt_menu_new(
          parent_ctx, pwr_cNObjid, &menulist, title, 0, RTT_MENUTYPE_DYN);
    else
      sts = rtt_menu_upd_new(parent_ctx, pwr_cNObjid,
          (rtt_t_menu_upd**)&menulist, title, 0, RTT_MENUTYPE_DYN);
    if (sts == RTT__FASTBACK)
      return sts;
    else if (sts == RTT__BACKTOCOLLECT)
      return sts;
    else if (EVEN(sts))
      return sts;
  } else {
    rtt_message('E', "No windows found");
    return RTT__NOPICTURE;
  }

  return RTT__SUCCESS;
}
Beispiel #21
0
static void pwrsrv_SubAdd( rpvd_sMsgSubAdd *msg)
{
  rpvd_sMsgAny rmsg;
  pwr_tAName name;
  pwr_tUInt32 asize, aoffs, aelem;
  pwr_tTypeId atid;
  pwr_tStatus sts;
  pwrsrv_sSubItem *si;
  void *p;
  pwr_tRefId dlid;
  
  rmsg.Type = rpvd_eMsg_Status;
  rmsg.Id = msg->Id;

  /* Check that this rix doesn't exist */
  for ( si = pwrsrv_sublist; si; si = si->next) {
    if ( si->rix == msg->Rix) {
      return;
    }
  }

  sts = gdh_ObjidToName( msg->Oid, name, sizeof(name), cdh_mName_volumeStrict);
  if ( EVEN(sts)) {
    rmsg.Status = sts;
    udp_Send( (char *)&rmsg, sizeof(rmsg));
    return;
  }

  if ( strcmp( msg->Attribute, "") != 0) {
    strcat( name, ".");
    strcat( name, msg->Attribute);

    sts = gdh_GetAttributeCharacteristics( name, &atid, &asize, &aoffs, &aelem);
    if ( EVEN(sts)) {
      rmsg.Status = sts;
      udp_Send( (char *)&rmsg, sizeof(rmsg));
      return;
    }
  }
  else {
    sts = gdh_GetObjectSize( msg->Oid, &asize);
    if ( EVEN(sts)) {
      rmsg.Status = sts;
      udp_Send( (char *)&rmsg, sizeof(rmsg));
      return;
    }
  }

  /* Direct link to atttribute */
  sts = gdh_RefObjectInfo( name, &p, &dlid, asize);
  if ( EVEN(sts)) {
    rmsg.Status = sts;
    udp_Send( (char *)&rmsg, sizeof(rmsg));
    return;
  }
       
  /* Insert first in sublist */
  si = (pwrsrv_sSubItem *) calloc( 1, sizeof(pwrsrv_sSubItem));
  si->oid = msg->Oid;
  strcpy( si->attribute, msg->Attribute);
  si->size = asize;
  si->rix = msg->Rix;
  si->p = p;
  si->dlid = dlid;
       
  si->next = pwrsrv_sublist;
  if ( si->next)
    si->next->prev = si;
  pwrsrv_sublist = si;

  
  printf( "SubAdd: %d %s\n", msg->Rix, name);

  rmsg.Status = GDH__SUCCESS;
  udp_Send( (char *)&rmsg, sizeof(rmsg));
}
Beispiel #22
0
static void  attrvalue_to_string( int type_id, void *value_ptr, 
	char *str, int size, int *len, char *format)
{
  pwr_tObjid		objid;
  pwr_sAttrRef		*attrref;
  int			sts;
  char			timstr[64];

  if ( value_ptr == 0)
  {
    strcpy( str, "UNDEFINED");
    return;
  }

  switch ( type_id )
  {
    case pwr_eType_Boolean:
    {
      if ( !format)
        *len = sprintf( str, "%d", *(pwr_tBoolean *)value_ptr);
      else
        *len = sprintf( str, format, *(pwr_tBoolean *)value_ptr);
      break;
    }
    case pwr_eType_Float32:
    {
      if ( !format)
        *len = sprintf( str, "%f", *(float *)value_ptr);
      else
        *len = sprintf( str, format, *(float *)value_ptr);
      break;
    }
    case pwr_eType_Float64:
    {
      if ( !format)
        *len = sprintf( str, "%f", *(double *)value_ptr);
      else
        *len = sprintf( str, format, *(double *)value_ptr);
      break;
    }
    case pwr_eType_Char:
    {
      if ( !format)
        *len = sprintf( str, "%c", *(char *)value_ptr);
      else
        *len = sprintf( str, format, *(char *)value_ptr);
      break;
    }
    case pwr_eType_Int8:
    {
      if ( !format)
        *len = sprintf( str, "%d", *(char *)value_ptr);
      else
        *len = sprintf( str, format, *(char *)value_ptr);
      break;
    }
    case pwr_eType_Int16:
    {
      if ( !format)
        *len = sprintf( str, "%hd", *(short *)value_ptr);
      else
        *len = sprintf( str, format, *(short *)value_ptr);
      break;
    }
    case pwr_eType_Int32:
    {
      if ( !format)
        *len = sprintf( str, "%d", *(int *)value_ptr);
      else
        *len = sprintf( str, format, *(int *)value_ptr);
      break;
    }
    case pwr_eType_Int64:
    {
      if ( !format)
        *len = sprintf( str, pwr_dFormatInt64, *(pwr_tInt64 *)value_ptr);
      else
        *len = sprintf( str, format, *(pwr_tInt64 *)value_ptr);
      break;
    }
    case pwr_eType_UInt8:
    {
      if ( !format)
        *len = sprintf( str, "%d", *(unsigned char *)value_ptr);
      else
        *len = sprintf( str, format, *(unsigned char *)value_ptr);
      break;
    }
    case pwr_eType_UInt16:
    {
      if ( !format)
        *len = sprintf( str, "%hd", *(unsigned short *)value_ptr);
      else
        *len = sprintf( str, format, *(unsigned short *)value_ptr);
      break;
    }
    case pwr_eType_UInt32:
    case pwr_eType_Mask:
    case pwr_eType_Enum:
    {
      if ( !format)
        *len = sprintf( str, "%d", *(unsigned int *)value_ptr);
      else
        *len = sprintf( str, format, *(unsigned int *)value_ptr);
      break;
    }
    case pwr_eType_UInt64:
    {
      if ( !format)
        *len = sprintf( str, pwr_dFormatUInt64, *(pwr_tUInt64 *)value_ptr);
      else
        *len = sprintf( str, format, *(pwr_tUInt64 *)value_ptr);
      break;
    }
    case pwr_eType_String:
    {
      strncpy( str, (char *)value_ptr, size);
      str[size-1] = 0;
      *len = strlen(str);
      break;
    }
    case pwr_eType_Objid:
    {
      pwr_tOName hiername;

      objid = *(pwr_tObjid *)value_ptr;
      if ( !objid.oix)
        sts = gdh_ObjidToName ( objid, hiername, sizeof(hiername), 
			 cdh_mName_volumeStrict);
      else
        sts = gdh_ObjidToName ( objid, hiername, sizeof(hiername), 
		cdh_mNName);
      if (EVEN(sts))
      {
        strcpy( str, "");
        *len = 0;
        break;
      }
      *len = sprintf( str, "%s", hiername);
      break;
    }
    case pwr_eType_AttrRef:
    {
      pwr_tAName hiername;

      attrref = (pwr_sAttrRef *) value_ptr;
      sts = gdh_AttrrefToName ( attrref, hiername, sizeof(hiername), cdh_mNName);
      if (EVEN(sts))
      {
        strcpy( str, "");
        *len = 0;
        break;
      }
      *len = sprintf( str, "%s", hiername);
      break;
    }
    case pwr_eType_Time:
    {
      sts = time_AtoAscii( (pwr_tTime *) value_ptr, time_eFormat_DateAndTime, 
		timstr, sizeof(timstr));
      if ( EVEN(sts))
        strcpy( timstr, "-");
      *len = sprintf( str, "%s", timstr);
      break;
    }
    case pwr_eType_DeltaTime:
    {
      sts = time_DtoAscii( (pwr_tDeltaTime *) value_ptr, 1, 
		timstr, sizeof(timstr));
      if ( EVEN(sts))
        strcpy( timstr, "Undefined time");
      *len = sprintf( str, "%s", timstr);
      break;
    }
    case pwr_eType_ObjectIx:
    {
      *len = sprintf( str, "%s", cdh_ObjectIxToString( NULL, 
		*(pwr_tObjectIx *) value_ptr, 1));
      break;
    }
    case pwr_eType_ClassId:
    {
      pwr_tOName hiername;

      objid = cdh_ClassIdToObjid( *(pwr_tClassId *) value_ptr);
      sts = gdh_ObjidToName ( objid, hiername, sizeof(hiername), cdh_mNName);
      if (EVEN(sts))
      {
        strcpy( str, "");
        *len = 0;
        break;
      }
      *len = sprintf( str, "%s", hiername);
      break;
    }
    case pwr_eType_TypeId:
    {
      pwr_tOName hiername;

      objid = cdh_TypeIdToObjid( *(pwr_tTypeId *) value_ptr);
      sts = gdh_ObjidToName ( objid, hiername, sizeof(hiername), cdh_mNName);
      if (EVEN(sts))
      {
        strcpy( str, "");
        *len = 0;
        break;
      }
      *len = sprintf( str, "%s", hiername);
      break;
    }
    case pwr_eType_VolumeId:
    {
      *len = sprintf( str, "%s", cdh_VolumeIdToString( NULL, 
		*(pwr_tVolumeId *) value_ptr, 1, 0));
      break;
    }
    case pwr_eType_RefId:
    {
      *len = sprintf( str, "%s", cdh_SubidToString( NULL, 
		*(pwr_tSubid *) value_ptr, 1));
      break;
    }

  }
}
Beispiel #23
0
pwr_tStatus xtt_pb_dp_slave_create_ctx( pwr_tAttrRef aref, void *editor_ctx, 
					xtt_slave_sCtx **ctxp)
{
  pwr_tAName name;
  pwr_tString80 gsdfile;
  int sts;
  pwr_tFileName fname;
  pwr_tCid cid;
  pwr_tOid oid;
  int found;
  int mc_cnt;
  int module_cnt;
  pwr_tAttrRef aaref;

  sts = gdh_ObjidToName( aref.Objid, 
			name, sizeof(name), cdh_mName_volumeStrict);
  if ( EVEN(sts)) return sts;

  sts = gdh_ArefANameToAref( &aref, "GSDFile", &aaref);
  if ( EVEN(sts)) return sts;

  sts = gdh_GetObjectInfoAttrref( &aaref, gsdfile, sizeof(gsdfile));
  if ( EVEN(sts)) return sts;
  if ( strcmp( gsdfile, "") == 0) {
    return PB__GSDATTR;
  }

  xtt_slave_sCtx *ctx = (xtt_slave_sCtx *) calloc( 1, sizeof(xtt_slave_sCtx));
  ctx->aref = aref;

  // Count modules
  module_cnt = 0;
  for ( sts = gdh_GetChild( aref.Objid, &oid);
	ODD(sts);
	sts = gdh_GetNextSibling( oid, &oid)) {
    module_cnt++;
  }

  ctx->mc = (gsd_sModuleClass *) calloc( module_cnt + 2, sizeof(gsd_sModuleClass));
  mc_cnt = 0;
  ctx->editor_ctx = editor_ctx;
  
  ctx->mc[0].cid = pwr_cClass_Pb_Module;
  sts = gdh_ObjidToName( cdh_ClassIdToObjid(ctx->mc[0].cid),  
			 ctx->mc[0].name, sizeof(ctx->mc[0].name), cdh_mName_object);
  if ( EVEN(sts)) return sts;
  mc_cnt++;

  for ( sts = gdh_GetChild( aref.Objid, &oid);
	ODD(sts);
	sts = gdh_GetNextSibling( oid, &oid)) {
    sts = gdh_GetObjectClass( oid, &cid);
    if ( EVEN(sts)) return sts;

    found = 0;
    for ( int i = 0; i < mc_cnt; i++) {
      if ( ctx->mc[i].cid == cid) {
	found = 1;
	break;
      }
    }
    if ( found)
      continue;

    ctx->mc[mc_cnt].cid = cid;
    sts = gdh_ObjidToName( cdh_ClassIdToObjid(cid),
			   ctx->mc[mc_cnt].name, sizeof(ctx->mc[0].name), cdh_mName_object);
    if ( EVEN(sts)) return sts;
    mc_cnt++;
  }

  if ( strchr( gsdfile, '/') == 0) {
    strcpy( fname, "$pwrp_exe/");
    strcat( fname, gsdfile);
  }
  else
    strcpy( fname, gsdfile);
    
  ctx->gsd = new pb_gsd();
  sts = ctx->gsd->read( fname);
  if ( EVEN(sts))
    return sts;
    
  ctx->gsd->set_classes( ctx->mc);

  sts = xtt_pb_dp_slave_load_modules( ctx);
  if ( EVEN(sts)) return sts;

  *ctxp = ctx;
  return 1;
}
Beispiel #24
0
static int graph_object_dx( Graph *graph, pwr_sAttrRef *arp)
{
    int sts;
    graph_sObjectDx *od;
    pwr_tAttrRef aref, chanaref;
    pwr_tAName aname;
    pwr_tCid card_cid;

    od = (graph_sObjectDx *) calloc( 1, sizeof(graph_sObjectDx));
    graph->graph_object_data = (void *) od;
    graph->graph_object_close = graph_object_dx_close;

    sts = gdh_GetAttrRefTid( arp, &od->cid);
    if ( EVEN(sts)) return sts;

    // Get channel object
    sts = gdh_ArefANameToAref( arp, "SigChanCon", &aref);
    if ( EVEN(sts)) {
        // Dv object, register scan function and return with success
        graph->graph_object_scan = graph_object_dx_scan;
        return 1;
    }

    sts = gdh_GetObjectInfoAttrref( &aref, &chanaref, sizeof(chanaref));
    if ( EVEN(sts)) return sts;

    od->local_conv_p = (pwr_tBoolean *) graph->localdb_ref_or_create( "ConversionOn",
                       pwr_eType_Boolean);
    od->local_inv_p = (pwr_tBoolean *) graph->localdb_ref_or_create( "InvertOn",
                      pwr_eType_Boolean);
    od->local_test_p = (pwr_tBoolean *) graph->localdb_ref_or_create( "TestOn",
                       pwr_eType_Boolean);

    // Get card object
    if ( chanaref.Flags.b.ObjectAttr) {
        sts = gdh_GetObjectClass( chanaref.Objid, &card_cid);
        if ( EVEN(sts)) return sts;
    }
    else
        card_cid = 0;

    switch ( card_cid) {
    case pwr_cClass_Ssab_DI32D: {
        pwr_tAName card_name;
        unsigned int chan_idx = (chanaref.Offset - pwr_AlignLW(sizeof(pwr_sClass_Ssab_BaseDiCard))) / pwr_AlignLW(sizeof(pwr_sClass_ChanDi));

        sts = gdh_ObjidToName( chanaref.Objid, card_name, sizeof(card_name), cdh_mNName);
        if ( EVEN(sts)) return sts;

        if ( chan_idx < 16) {
            strcpy( aname, card_name);
            strcat( aname, ".ConvMask1");

            graph->ref_object_info( glow_eCycle_Slow, aname, (void **)&od->conv_p, &od->conv_subid,
                                    sizeof(pwr_tBoolean), 0, true);

            strcpy( aname, card_name);
            strcat( aname, ".InvMask1");

            graph->ref_object_info( glow_eCycle_Slow, aname, (void **)&od->inv_p, &od->inv_subid,
                                    sizeof(pwr_tBoolean), 0, true);

            od->mask = 1 << chan_idx;
        }
        else if ( chan_idx < 32) {
            strcpy( aname, card_name);
            strcat( aname, ".ConvMask2");

            graph->ref_object_info( glow_eCycle_Slow, aname, (void **)&od->conv_p, &od->conv_subid,
                                    sizeof(pwr_tBoolean), 0, true);

            strcpy( aname, card_name);
            strcat( aname, ".InvMask2");

            graph->ref_object_info( glow_eCycle_Slow, aname, (void **)&od->inv_p, &od->inv_subid,
                                    sizeof(pwr_tBoolean), 0, true);

            od->mask = 1 << (chan_idx - 16);
        }
        else
            return 0;

        break;
    }
    case pwr_cClass_Ssab_DO32DKS:
    case pwr_cClass_Ssab_DO32DKS_Stall: {
        pwr_tAName card_name;
        unsigned int chan_idx = (chanaref.Offset - pwr_AlignLW(sizeof(pwr_sClass_Ssab_BaseDoCard))) / pwr_AlignLW(sizeof(pwr_sClass_ChanDo));

        sts = gdh_ObjidToName( chanaref.Objid, card_name, sizeof(card_name), cdh_mNName);
        if ( EVEN(sts)) return sts;

        if ( chan_idx < 16) {
            strcpy( aname, card_name);
            strcat( aname, ".TestMask1");

            graph->ref_object_info( glow_eCycle_Slow, aname, (void **)&od->test_p, &od->test_subid,
                                    sizeof(pwr_tBoolean), 0, true);

            strcpy( aname, card_name);
            strcat( aname, ".InvMask1");

            graph->ref_object_info( glow_eCycle_Slow, aname, (void **)&od->inv_p, &od->inv_subid,
                                    sizeof(pwr_tBoolean), 0, true);

            od->mask = 1 << chan_idx;
        }
        else if ( chan_idx < 32) {
            strcpy( aname, card_name);
            strcat( aname, ".TestMask2");

            graph->ref_object_info( glow_eCycle_Slow, aname, (void **)&od->test_p, &od->test_subid,
                                    sizeof(pwr_tBoolean), 0, true);

            strcpy( aname, card_name);
            strcat( aname, ".InvMask2");

            graph->ref_object_info( glow_eCycle_Slow, aname, (void **)&od->inv_p, &od->inv_subid,
                                    sizeof(pwr_tBoolean), 0, true);

            od->mask = 1 << (chan_idx - 16);
        }
        else
            return 0;

        if ( od->local_conv_p)
            *od->local_conv_p = 1;

        break;
    }
    default: {
        pwr_tAName chan_name;

        sts = gdh_AttrrefToName( &chanaref, chan_name, sizeof(chan_name),
                                 cdh_mNName);
        if ( ODD(sts)) {
            if ( od->cid == pwr_cClass_Di) {
                strcpy( aname, chan_name);
                strcat( aname, ".ConversionOn");
                graph->ref_object_info( glow_eCycle_Slow, aname, (void **)&od->conv_p, &od->conv_subid,
                                        sizeof(pwr_tBoolean), 0, true);
            }


            strcpy( aname, chan_name);
            strcat( aname, ".InvertOn");
            graph->ref_object_info( glow_eCycle_Slow, aname, (void **)&od->inv_p, &od->inv_subid,
                                    sizeof(pwr_tBoolean), 0, true);


            if ( od->cid == pwr_cClass_Do) {
                strcpy( aname, chan_name);
                strcat( aname, ".TestOn");
                graph->ref_object_info( glow_eCycle_Slow, aname, (void **)&od->test_p, &od->test_subid,
                                        sizeof(pwr_tBoolean), 0, true);

                if ( od->local_conv_p)
                    *od->local_conv_p = 1;
            }
        }
    }
    }

    // Register scan function
    graph->graph_object_scan = graph_object_dx_scan;
    return 1;
}
Beispiel #25
0
RtTraceMotif::RtTraceMotif( void *tr_parent_ctx, Widget tr_parent_wid, pwr_tObjid tr_objid,
			    pwr_tStatus *status) :
  RtTrace( tr_parent_ctx, tr_objid, status), parent_wid(tr_parent_wid)
{
  // FlowWidget	fwidget;
  char		uid_filename[120] = {"xtt_trace.uid"};
  char		*uid_filename_p = uid_filename;
  Arg 		args[20];
  unsigned long sts;
  pwr_tOName   	name;
  int		i;
  pwr_tObjid	window_objid;
  pwr_tClassId	cid;
  char   	title[220];
  pwr_tOName   	hostname;
  pwr_tOName   	plcconnect;
  MrmHierarchy s_DRMh;
  MrmType dclass;
  Widget	trace_widget;
  static MrmRegisterArg	reglist[] = {
        {(char*) "tra_ctx", 0 },
	{(char*) "tra_activate_close",(caddr_t)activate_close },
	{(char*) "tra_activate_print",(caddr_t)activate_print },
	{(char*) "tra_activate_printselect",(caddr_t)activate_printselect },
	{(char*) "tra_activate_savetrace",(caddr_t)activate_savetrace },
	{(char*) "tra_activate_restoretrace",(caddr_t)activate_restoretrace },
	{(char*) "tra_activate_cleartrace",(caddr_t)activate_cleartrace },
	{(char*) "tra_activate_trace",(caddr_t)activate_trace },
	{(char*) "tra_activate_display_object",(caddr_t)activate_display_object },
	{(char*) "tra_activate_open_object",(caddr_t)activate_open_object },
	{(char*) "tra_activate_show_cross",(caddr_t)activate_show_cross },
	{(char*) "tra_activate_open_classgraph",(caddr_t)activate_open_classgraph },
	{(char*) "tra_activate_collect_insert",(caddr_t)activate_collect_insert },
	{(char*) "tra_activate_view",(caddr_t)activate_view },
	{(char*) "tra_activate_simulate",(caddr_t)activate_simulate },
	{(char*) "tra_activate_zoomin",(caddr_t)activate_zoomin },
	{(char*) "tra_activate_zoomout",(caddr_t)activate_zoomout },
	{(char*) "tra_activate_zoomreset",(caddr_t)activate_zoomreset },
	{(char*) "tra_activate_scantime1",(caddr_t)activate_scantime1 },
	{(char*) "tra_activate_scantime2",(caddr_t)activate_scantime2 },
	{(char*) "tra_activate_scantime3",(caddr_t)activate_scantime3 },
	{(char*) "tra_activate_scantime4",(caddr_t)activate_scantime4 },
	{(char*) "tra_activate_scantime5",(caddr_t)activate_scantime5 },
	{(char*) "tra_activate_help",(caddr_t)activate_help },
	{(char*) "tra_activate_helpplc",(caddr_t)activate_helpplc },
	{(char*) "tra_create_form",(caddr_t)create_form },
	{(char*) "tra_create_menu",(caddr_t)create_menu }
	};

  static int	reglist_num = (sizeof reglist / sizeof reglist[0]);

  lng_get_uid( uid_filename, uid_filename);

  sts = gdh_ObjidToName( tr_objid, name, sizeof(name), cdh_mNName); 
  if (EVEN(sts)) {
    *status = sts;
    return;
  }
  strcpy( title, "Trace ");
  strcat( title, name);

  /* Find plcwindow */
  sts = gdh_GetObjectClass( tr_objid, &cid);
  if ( EVEN(sts)) {
    *status = sts;
    return;
  }

  if ( !(cid == pwr_cClass_windowplc ||
         cid == pwr_cClass_windowcond ||
         cid == pwr_cClass_windoworderact ||
         cid == pwr_cClass_windowsubstep ))
  {

    sts = gdh_GetChild( tr_objid, &window_objid);
    if ( EVEN(sts)) {
      *status = sts;
      return;
    }
  }
  else
    window_objid = tr_objid; 

  sts = gdh_GetObjectClass( window_objid, &cid);
  if ( EVEN(sts)) {
    *status = sts;
    return;
  }

  if ( !(cid == pwr_cClass_windowplc ||
         cid == pwr_cClass_windowcond ||
         cid == pwr_cClass_windoworderact ||
         cid == pwr_cClass_windowsubstep )) {
    *status = 0;
    return;
  }

  sts = get_filename( window_objid, filename, &m_has_host, hostname, 
		      plcconnect);
  if ( EVEN(sts)) {
    *status = sts;
    return;
  }

  /* Create object context */
  objid = window_objid;
  if ( m_has_host) {
    strcpy( m_hostname, hostname);
    strcpy( m_plcconnect, plcconnect);
  }
  reglist[0].value = (caddr_t) this;
 
  toplevel = XtCreatePopupShell( name, 
		topLevelShellWidgetClass, parent_wid, args, 0);

  /* Save the context structure in the widget */
  XtSetArg (args[0], XmNuserData, (XtPointer) this);

  sts = MrmOpenHierarchy( 1, &uid_filename_p, NULL, &s_DRMh);
  if (sts != MrmSUCCESS) printf("can't open %s\n", uid_filename);

  MrmRegisterNames(reglist, reglist_num);

  sts = MrmFetchWidgetOverride( s_DRMh, (char*) "trace_window", toplevel,
			title, args, 1, &trace_widget, &dclass);
  if (sts != MrmSUCCESS)  printf("can't fetch %s\n", name);

  MrmCloseHierarchy(s_DRMh);


  i = 0;
  XtSetArg(args[i],XmNwidth,800);i++;
  XtSetArg(args[i],XmNheight,600);i++;
  XtSetValues( toplevel ,args,i);
    
  XtManageChild( trace_widget);

  i = 0;
/*
  XtSetArg(args[i],XmNwidth,790);i++;
  XtSetArg(args[i],XmNheight,560);i++;
*/
  XtSetArg( args[i], XmNtopAttachment, XmATTACH_WIDGET);i++;
  XtSetArg( args[i], XmNtopWidget, menu);i++;
  XtSetArg( args[i], XmNrightAttachment, XmATTACH_FORM);i++;
  XtSetArg( args[i], XmNleftAttachment, XmATTACH_FORM);i++;
  XtSetArg( args[i], XmNbottomAttachment, XmATTACH_FORM);i++;
  flow_widget = FlowCreate( form, (char*) "Flow window", args, i, 
			    init_flow, (void *)this);

  XtManageChild( (Widget) flow_widget);
/*
  XtRealizeWidget(toplevel);
*/
  XtPopup( toplevel, XtGrabNone);

  // fwidget = (FlowWidget) flow_widget;
  // flow_ctx = (flow_tCtx)fwidget->flow.flow_ctx;
  // flow_SetCtxUserData( flow_ctx, this);

  /* Create navigator popup */

  i = 0;
  XtSetArg(args[i],XmNallowShellResize, TRUE); i++;
  XtSetArg(args[i],XmNallowResize, TRUE); i++;
  XtSetArg(args[i],XmNwidth,200);i++;
  XtSetArg(args[i],XmNheight,200);i++;
  XtSetArg(args[i],XmNx,500);i++;
  XtSetArg(args[i],XmNy,500);i++;

  nav_shell = XmCreateDialogShell( flow_widget, (char*) "Navigator",
        args, i);
  XtManageChild( nav_shell);

  i = 0;
  XtSetArg(args[i],XmNwidth,200);i++;
  XtSetArg(args[i],XmNheight,200);i++;
  nav_widget = FlowCreateNav( nav_shell, (char*) "navigator",
        args, i, flow_widget);
  XtManageChild( nav_widget);
  XtRealizeWidget( nav_shell);

  // Connect the window manager close-button to exit
  flow_AddCloseVMProtocolCb( toplevel, 
	(XtCallbackProc)activate_close, this);

  wow = new CoWowMotif( toplevel);
  trace_timerid = wow->timer_new();

  viewsetup();
  flow_Open( flow_ctx, filename);
  trasetup();
  trace_start();

#if defined OS_LINUX
  {
    struct stat info;

    if ( stat( filename, &info) != -1)
      version = info.st_ctime;    
  }
#endif

}
int main(int argc, char *argv[]) /*argv[2]=remnode name*/
{
  unsigned int sts;			/* Status from function calls etc. */
  unsigned char id[32];
  unsigned char pname[32];
  remtrans_item *remtrans;
  int i;
  char first;
  pssupd_buffer_vnet buff;		/* Buffer for 'hello' */
  pssupd_order_header *header;		/* Header for 'hello' */
  char name[80];

  /* Read arg number 2, should be id for this instance */

  if (argc >= 2)
    strcpy((char *) id, argv[1]);
  else
    strcpy((char *) id, "0");
    
  /* Build process name with id */

  sprintf((char *) pname, "rs_rem3964r_%s", id);

  /* Init of errh */

  errh_Init((char *) pname, errh_eAnix_remote);
  errh_SetStatus(PWR__SRVSTARTUP);

  /* Init of gdh */

  sts = gdh_Init((char *) pname);
  if ( EVEN(sts)) {
    errh_Error("gdh_Init, %m", sts);
    errh_SetStatus(PWR__SRVTERM);
    exit(sts);
  }

  /* Arg number 3 should be my remnodes objid in string representation,
     read it, convert to real objid and store in remnode_item */

  sts = 0;
  if (argc >= 3) sts = cdh_StringToObjid(argv[2], &rn.objid);
  if ( EVEN(sts)) {
    errh_Error("cdh_StringToObjid, %m", sts);
    errh_SetStatus(PWR__SRVTERM);
    exit(sts);
  }

  /* Get pointer to Remnode3964R object and store locally */
  
  sts = gdh_ObjidToPointer(rn.objid, (pwr_tAddress *) &rn_3964R);
  if ( EVEN(sts)) {
    errh_Error("cdh_ObjidToPointer, %m", sts);
    errh_SetStatus(PWR__SRVTERM);
    exit(sts);
  }
  
  /* Get name of object to use in sending poll */
  
  sts = gdh_ObjidToName(rn.objid, name, sizeof(name), cdh_mName_object);
  name[3] = 'P';
  name[4] = 'S';
  name[5] = 'S';
  name[6] = 0;
  RemUtils_AsciiToR50((char *) &name, (short *) &poll_id);
  
  if (debug) printf("%s, %d %d\n", name, poll_id[0], poll_id[1]);  
      
  /* Initialize some internal data and make standard remtrans init */

  rn.next = NULL;
  rn.local = NULL;		// We dont use local structure since we only have one remnode
  rn.retransmit_time = 10.0;	// Not used, but initialize anyway
  rn_3964R->ErrCount = 0;

  sts = RemTrans_Init(&rn);
  
  if ( EVEN(sts)) {
    errh_Error("RemTrans_Init, %m", sts);
    errh_SetStatus(PWR__SRVTERM);
    exit(sts);
  }

  sts = RemIO_Init_3964R(&rn);

  if ( EVEN(sts)) {
    errh_Error("RemIO_Init, %m", sts);
    errh_SetStatus(PWR__SRVTERM);
    exit(sts);
  }
  
  if (rn.remio_data == NULL) 
    use_remote_io = 0;
  else
    use_remote_io = 1;  

  time_since_poll = 0.0;
  time_since_io = 0.0;
  time_since_scan = 0.0;

  /* Store remtrans objects objid in remnode_3964R object */
  remtrans = rn.remtrans;
  i = 0;
  while(remtrans) {
    rn_3964R->RemTransObjects[i++] = remtrans->objid;
    if ( i >= (int)(sizeof(rn_3964R->RemTransObjects)/sizeof(rn_3964R->RemTransObjects[0])))
      break;
    remtrans = (remtrans_item *) remtrans->next;
  }

  /* Initialize device */

  ser_fd = RemUtils_InitSerialDev(rn_3964R->DevName, 
  				  rn_3964R->Speed, 
				  rn_3964R->DataBits,
				  rn_3964R->StopBits,
				  rn_3964R->Parity);
				  
  if (!ser_fd) {
    errh_Error("InitDev, %d", ser_fd);
    errh_SetStatus(PWR__SRVTERM);
    exit(0);
  }    

  first = TRUE;
  rn_3964R->LinkUp = 1;
  
  /* Loop forever */

  while (1)
  {

    if (rn_3964R->Disable == 1) {
      errh_Fatal("Disabled, exiting");
      errh_SetStatus(PWR__SRVTERM);
      exit(0);
    }   
    
    // Wait micro time  
    // Wait cycle time
//    timer = (int) (rn_3964R->ScanTime * 1000000.0);
    usleep(30000);
    
    Receive();
    
//    time_since_poll += rn_3964R->ScanTime;
//    time_since_io += rn_3964R->ScanTime;
    time_since_poll += 0.03;
    time_since_io += 0.03;
    time_since_scan += 0.03;

    if (first && use_remote_io) {
      /* Send Hello to subsystem if we have poll */
      header = (pssupd_order_header *) &buff.data;
      header->type = PSS_Switch_Done;
      header->size = 0;
      header->signal = 0;
      buff.no_of_updates = 1;
      buff.length = (sizeof(pssupd_buffer_vnet) -
      MAX_ORDER_BUFFERSIZE_VNET + sizeof(pssupd_order_header) + 1) / 2;
      send_pollbuff(&rn, &buff);
    }
        
//    if (debug) printf("Remtrans Cyclic\n");
    if (time_since_scan >= rn_3964R->ScanTime) {
      if (debug) printf("Remtrans Cyclic\n");
      RemTrans_Cyclic(&rn, &remnode_send);
      time_since_scan = 0.0;
    }

    if (use_remote_io) {
    
      if ((rn_3964R->LinkUp && time_since_poll >= rn_3964R->ScanTime*2.0) ||
          (!rn_3964R->LinkUp && time_since_poll >= rn_3964R->ScanTime*10.0))
      {
        if (debug) printf("RemIO Cyclic\n");
        sts = RemIO_Cyclic_3964R(&rn, &send_pollbuff);
        time_since_poll = 0.0;
      }

      if (time_since_io >= rn_3964R->LinkTimeout && rn_3964R->LinkTimeout > 0) {
        if (debug) printf("RemIO Stall\n");
        sts = RemIO_Stall_3964R(&rn, stall_action);
      }
    }

    first = FALSE;    
  }
}
Beispiel #27
0
static pwr_tStatus 
init_plc (
  plc_sProcess	*pp
)
{
  pwr_tStatus	sts = PLC__SUCCESS;
  pwr_tObjid   	oid;
  pwr_tObjid   	pp_oid;
  pwr_tObjid   	io_oid;
  pwr_tObjid	thread_oid;
  int		sec;
  int		msec;
  int		i;
  pwr_tCid	cid;

  sts = gdh_GetNodeObject(0, &oid);
  if (EVEN(sts)) {
    errh_Fatal("gdh_GetNodeObject, %m", sts);
    exit(sts);
  }

  sts = gdh_ObjidToPointer(oid, (void *)&pp->Node);
  if (EVEN(sts)) return sts;

  sts = gdh_GetClassList(pwr_cClass_PlcProcess, &pp_oid);
  if (EVEN(sts)) {
    errh_Error("Found no PlcProcess-object\n%m", sts);
    return sts;
  }

  sts = gdh_ObjidToPointer(pp_oid, (void *)&pp->PlcProcess);
  if (EVEN(sts)) return sts;

  i = 0;
  sts = gdh_GetChild( pp_oid, &thread_oid);
  while ( ODD(sts)) {
    sts = gdh_GetObjectClass( thread_oid, &cid);
    if ( EVEN(sts)) return sts;
    
    if ( cid == pwr_cClass_PlcThread)
      pp->PlcProcess->PlcThreadObjects[i++] = thread_oid;

    sts = gdh_GetNextSibling( thread_oid, &thread_oid);
  }
  for ( ; i > sizeof(pp->PlcProcess->PlcThreadObjects)/sizeof(pp->PlcProcess->PlcThreadObjects[0]); i++)
    pp->PlcProcess->PlcThreadObjects[i] = pwr_cNObjid;

  aproc_RegisterObject( pp_oid);

  sts = gdh_GetClassList(pwr_cClass_IOHandler, &io_oid);
  if (EVEN(sts)) {
    errh_Error("Found no IOHandler-object\n%m", sts);
    return sts;
  }

  sts = gdh_ObjidToPointer(io_oid, (void *)&pp->IOHandler);
  if (EVEN(sts)) return sts;

  /* Set subscription defaults for PLC job */

  sts = gdh_SetSubscriptionDefaults(
    (pwr_tInt32)(pp->PlcProcess->SubscriptionInterval * 1000.), 10000);

  sec = pp->PlcProcess->SubscriptionInterval;
  msec = (int)((pp->PlcProcess->SubscriptionInterval - sec) * 1000.);
  errh_Info("Setting subscription defaults to %d.%03d seconds", sec, msec);

  sts = gdh_ObjidToName(oid, pp->nodeName, sizeof(pp->nodeName), cdh_mNName);
  if (EVEN(sts)) return sts;

  init_grafcet(pp);
  link_io_base_areas(pp);

  return sts;
}
Beispiel #28
0
static void pwrsrv_Oid( rpvd_sMsgOid *msg)
{
  rpvd_sMsgObject rmsg;
  pwr_tOid fth;
  pwr_tOid fch;
  pwr_tOid lch;
  pwr_tOid bws;
  pwr_tOid fws;
  pwr_tCid cid;
  pwr_tObjName name;
  pwr_tOid o;
  pwr_tStatus sts;
  pwr_tOid plist[200];
  int psize = 0;
  int i, j;
  char *s;

  rmsg.Type = rpvd_eMsg_Object;
  rmsg.Id = msg->Id;
  rmsg.Status = 1;
  rmsg.Oid = msg->Oid;

  sts = gdh_GetObjectClass( msg->Oid, &cid);
  if ( EVEN(sts)) {
    rmsg.Status = sts;
    udp_Send( (char *)&rmsg, sizeof(rmsg));
    return;
  }

  plist[psize++] = msg->Oid;
  for ( sts = gdh_GetParent( plist[psize-1], &o); 
	ODD(sts);
	sts = gdh_GetParent( plist[psize-1], &o)) {
    plist[psize++] = o;
  }
  /* Add volume object */
  plist[psize].oix = 0;
  plist[psize++].vid = msg->Oid.vid;

  for ( j = 0; j < psize; j++) {
    i = psize - j - 1;

    sts = gdh_GetObjectClass( plist[i], &cid);

    if ( i == psize - 1) {
      /* Volume object */
      fth.oix = 0;

      sts = gdh_GetRootList( &fch);
      if ( EVEN(sts)) {
	fch.oix = 0;
	lch.oix = 0;
      }
      else {
	sts = 1;
	for ( lch = fch; ODD(sts); sts = gdh_GetNextSibling( lch, &o)) {
	  lch = o;
	}
      }
      fws.oix = 0;
      bws.oix = 0;

      sts = gdh_ObjidToName( plist[i], name, sizeof(name), cdh_mName_volume);
      if ( (s = strrchr( name, ':')))
	*s = 0;
    }
    else {
      sts = gdh_GetParent( plist[i], &fth);
      if ( EVEN(sts)) 
	fth.oix = 0;
      sts = gdh_GetChild( plist[i], &fch);
      if ( EVEN(sts)) {
	fch.oix = 0;
	lch.oix = 0;
      }
      else {
	lch = fch;
	for ( sts = gdh_GetNextSibling( lch, &o); 
	      ODD(sts); 
	      sts = gdh_GetNextSibling( lch, &o)) {
	  lch = o;
	}
      }
      sts = gdh_GetNextSibling( plist[i], &fws);
      if ( EVEN(sts))
	fws.oix = rmsg.o[j-1].fchoix;
      sts = gdh_GetPreviousSibling( plist[i], &bws);
      if ( EVEN(sts))
	bws.oix = rmsg.o[j-1].lchoix;
      sts = gdh_ObjidToName( plist[i], name, sizeof(name), cdh_mName_object);
    }
    rmsg.o[j].oix = plist[i].oix;
    rmsg.o[j].fthoix = fth.oix;
    rmsg.o[j].fchoix = fch.oix;
    rmsg.o[j].lchoix = lch.oix;
    rmsg.o[j].fwsoix = fws.oix;
    rmsg.o[j].bwsoix = bws.oix;
    rmsg.o[j].cid = cid;
    strcpy( rmsg.o[j].name, name);
  }
  rmsg.OSize = psize;
  udp_Send( (char *)&rmsg, sizeof(rmsg));
}
Beispiel #29
0
static pwr_tStatus mb_init_channels( io_tCtx ctx, io_sAgent *ap, io_sRack *rp) 
{
  io_sServerModuleLocal *local_card;
  io_sCard *cardp;
  io_sServerLocal *local;
  pwr_sClass_Modbus_TCP_Server *op;
  char name[196];
  pwr_tStatus sts;
  io_sChannel *chanp;
  int i;
  

  sts = gdh_ObjidToName(rp->Objid, (char *) &name, sizeof(name), cdh_mNName);

  op = (pwr_sClass_Modbus_TCP_Server *) rp->op;
  
  local = rp->Local;

  /* Create socket, store in local struct */
  
  /* Do configuration check and initialize modules. */

  cardp = rp->cardlist;

  unsigned int prev_input_area_offset = 0;
  unsigned int prev_output_area_offset = 0;
  unsigned int input_area_offset = 0;
  unsigned int output_area_offset = 0;
  unsigned int input_area_chansize = 0;
  unsigned int output_area_chansize = 0;

  while(cardp) {
    local_card = calloc(1, sizeof(*local_card));
    cardp->Local = local_card;

    local_card->input_area = (void *) &(op->Inputs) + input_area_offset + 
      input_area_chansize;
    local_card->output_area = (void *) &(op->Outputs) + output_area_offset + 
      output_area_chansize;


    io_bus_card_init( ctx, cardp, &input_area_offset, &input_area_chansize,
		      &output_area_offset, &output_area_chansize, 
		      pwr_eByteOrderingEnum_BigEndian);

    for (i = 0; i < cardp->ChanListSize; i++) {
      chanp = &cardp->chanlist[i];
      switch (chanp->ChanClass) {      
      case pwr_cClass_ChanDi: {
	pwr_sClass_ChanDi *chan_di = (pwr_sClass_ChanDi *) chanp->cop;

	if (local_card->di_size == 0)
	  local_card->di_offset = chanp->offset;
	if (chan_di->Number == 0 || local_card->di_size == 0)
	  local_card->di_size += GetChanSize(chan_di->Representation);

	break;
      }
      case pwr_cClass_ChanDo: {
	pwr_sClass_ChanDo *chan_do = (pwr_sClass_ChanDo *) chanp->cop;

	if (local_card->do_size == 0)
	  local_card->do_offset = chanp->offset;
	if (chan_do->Number == 0 || local_card->do_size == 0)
	  local_card->do_size += GetChanSize(chan_do->Representation);

	break;
      }
      case pwr_cClass_ChanD: {
	pwr_sClass_ChanD *chan_d = (pwr_sClass_ChanD *) chanp->cop;
	if ( chan_d->Type == pwr_eDChanTypeEnum_Di) {
	  if (local_card->di_size == 0)
	    local_card->di_offset = chanp->offset;
	  if (chan_d->Number == 0 || local_card->di_size == 0)
	    local_card->di_size += GetChanSize(chan_d->Representation);
	}
	else {
	  if (local_card->do_size == 0)
	    local_card->do_offset = chanp->offset;
	  if (chan_d->Number == 0 || local_card->do_size == 0)
	    local_card->do_size += GetChanSize(chan_d->Representation);
	}
	break;
      }
      }
    }	   

    local_card->input_size = input_area_offset + input_area_chansize - 
      prev_input_area_offset;
    local_card->output_size = output_area_offset + output_area_chansize - 
      prev_output_area_offset;

    prev_input_area_offset = input_area_offset + input_area_chansize;
    prev_output_area_offset = output_area_offset + output_area_chansize;

    cardp = cardp->next;
  }

  local->input_size = input_area_offset + input_area_chansize;
  local->output_size = output_area_offset + output_area_chansize;


  return IO__SUCCESS;
}
Beispiel #30
0
//
// Callbacks from brow
//
int XAttNav::brow_cb( FlowCtx *ctx, flow_tEvent event)
{
  XAttNav		*xattnav;
  Item	 		*item;

  if ( event->event == flow_eEvent_ObjectDeleted) {
    brow_GetUserData( event->object.object, (void **)&item);
    delete item;
    return 1;
  }

  brow_GetCtxUserData( (BrowCtx *)ctx, (void **) &xattnav);
  xattnav->message( ' ', "");

  switch ( event->event) {
  case flow_eEvent_Key_Up: {
    brow_tNode	*node_list;
    int		node_count;
    brow_tObject	object;
    int		sts;

    brow_GetSelectedNodes( xattnav->brow->ctx, &node_list, &node_count);
    if ( !node_count) {
      sts = brow_GetLastVisible( xattnav->brow->ctx, &object);
      if ( EVEN(sts)) return 1;
    }
    else {
      if ( !brow_IsVisible( xattnav->brow->ctx, node_list[0], flow_eVisible_Partial)) {
	sts = brow_GetLastVisible( xattnav->brow->ctx, &object);
	if ( EVEN(sts)) return 1;
      }
      else {
	sts = brow_GetPrevious( xattnav->brow->ctx, node_list[0], &object);
	if ( EVEN(sts)) {
	  if ( node_count)
	    free( node_list);
	  return 1;
	}
      }
    }
    brow_SelectClear( xattnav->brow->ctx);
    brow_SetInverse( object, 1);
    brow_SelectInsert( xattnav->brow->ctx, object);
    if ( !brow_IsVisible( xattnav->brow->ctx, object, flow_eVisible_Full))
      brow_CenterObject( xattnav->brow->ctx, object, 0.25);
    if ( node_count)
      free( node_list);
    break;
  }
  case flow_eEvent_Key_Down: {
    brow_tNode	*node_list;
    int		node_count;
    brow_tObject	object;
    int		sts;

    brow_GetSelectedNodes( xattnav->brow->ctx, &node_list, &node_count);
    if ( !node_count) {
      sts = brow_GetFirstVisible( xattnav->brow->ctx, &object);
      if ( EVEN(sts)) return 1;
    }
    else {
      if ( !brow_IsVisible( xattnav->brow->ctx, node_list[0], flow_eVisible_Partial)) {
	sts = brow_GetFirstVisible( xattnav->brow->ctx, &object);
	if ( EVEN(sts)) return 1;
      }
      else {
	sts = brow_GetNext( xattnav->brow->ctx, node_list[0], &object);
	if ( EVEN(sts)) {
	  if ( node_count)
	    free( node_list);
	  return 1;
	}
      }
    }
    brow_SelectClear( xattnav->brow->ctx);
    brow_SetInverse( object, 1);
    brow_SelectInsert( xattnav->brow->ctx, object);
    if ( !brow_IsVisible( xattnav->brow->ctx, object, flow_eVisible_Full))
      brow_CenterObject( xattnav->brow->ctx, object, 0.75);
    if ( node_count)
      free( node_list);
    break;
  }
  case flow_eEvent_SelectClear:
    brow_ResetSelectInverse( xattnav->brow->ctx);
    break;
  case flow_eEvent_MB1Click: {
    // Select
    double ll_x, ll_y, ur_x, ur_y;
    int		sts;

    switch ( event->object.object_type) {
    case flow_eObjectType_Node:
      brow_MeasureNode( event->object.object, &ll_x, &ll_y,
			&ur_x, &ur_y);
      if ( event->object.x < ll_x + 1.0) {
	// Simulate doubleclick
	flow_tEvent doubleclick_event;

	doubleclick_event = (flow_tEvent) calloc( 1, sizeof(*doubleclick_event));
	memcpy( doubleclick_event, event, sizeof(*doubleclick_event));
	doubleclick_event->event = flow_eEvent_MB1DoubleClick;
	sts = brow_cb( ctx, doubleclick_event);
	free( (char *) doubleclick_event);
	return sts;
      }

      if ( brow_FindSelectedObject( xattnav->brow->ctx, event->object.object)) {
	brow_SelectClear( xattnav->brow->ctx);
      }
      else {
	brow_SelectClear( xattnav->brow->ctx);
	brow_SetInverse( event->object.object, 1);
	brow_SelectInsert( xattnav->brow->ctx, event->object.object);
      }
      break;
    default:
      brow_SelectClear( xattnav->brow->ctx);
    }
    break;
  }
  case flow_eEvent_Key_PageDown: {
    brow_Page( xattnav->brow->ctx, 0.8);
    break;
  }
  case flow_eEvent_Key_PageUp: {
    brow_Page( xattnav->brow->ctx, -0.8);
    break;
  }
  case flow_eEvent_ScrollDown: {
    brow_Page( xattnav->brow->ctx, 0.1);
    break;
  }
  case flow_eEvent_ScrollUp: {
    brow_Page( xattnav->brow->ctx, -0.1);
    break;
  }
  case flow_eEvent_Key_Left: {
    brow_tNode	*node_list;
    int		node_count;
    brow_tObject	object;
    int		sts;

    brow_GetSelectedNodes( xattnav->brow->ctx, &node_list, &node_count);
    if ( !node_count)
      return 1;

    if ( brow_IsOpen( node_list[0]))
      // Close this node
      object = node_list[0];
    else {
      // Close parent
      sts = brow_GetParent( xattnav->brow->ctx, node_list[0], &object);
      if ( EVEN(sts)) {
	free( node_list);
	return 1;
      }
    }
    brow_GetUserData( object, (void **)&item);
    switch( item->type) {
    case xnav_eItemType_Attr: 
      ((ItemAttr *)item)->close( xattnav->brow, 0, 0);
      break;
    case xnav_eItemType_AttrArrayElem: 
      ((ItemAttrArrayElem *)item)->close( xattnav->brow, 0, 0);
      break;
    case xnav_eItemType_AttrArray: 
      ((ItemAttrArray *)item)->close( xattnav->brow, 0, 0);
      break;
    case xnav_eItemType_AttrObject: 
      ((ItemAttrObject *)item)->close( xattnav->brow, 0, 0);
      break;
    default:
      ;
    }
    brow_SelectClear( xattnav->brow->ctx);
    brow_SetInverse( object, 1);
    brow_SelectInsert( xattnav->brow->ctx, object);
    if ( !brow_IsVisible( xattnav->brow->ctx, object, flow_eVisible_Full))
      brow_CenterObject( xattnav->brow->ctx, object, 0.25);
    free( node_list);
    break;
  }
  case flow_eEvent_MB3Down: {
    brow_SetClickSensitivity( xattnav->brow->ctx, 
			      flow_mSensitivity_MB3Press);
    break;
  }
  case flow_eEvent_MB3Press: {
    // Popup menu
    int x, y;
    pwr_sAttrRef attrref;
    int sts;

    switch ( event->object.object_type) {
    case flow_eObjectType_Node:
      brow_GetUserData( event->object.object, (void **)&item);
      if ( cdh_ObjidIsNull( item->objid))
	break;

      xattnav->popup_position( event->any.x_pixel + 8, event->any.y_pixel, &x, &y);

      memset( &attrref, 0, sizeof(attrref));
      switch ( item->type) {
      case xnav_eItemType_Attr:
      case xnav_eItemType_AttrArrayElem:
      case xnav_eItemType_AttrObject: {
	pwr_tAName attr_str;

	sts = gdh_ObjidToName( item->objid, 
			       attr_str, sizeof(attr_str), cdh_mName_volumeStrict);
	if ( EVEN(sts)) return sts;

	strcat( attr_str, ".");
	strcat( attr_str, item->name);
	sts = gdh_NameToAttrref( pwr_cNObjid, attr_str, &attrref);
	if ( EVEN(sts)) return sts;

	(xattnav->popup_menu_cb)( xattnav->parent_ctx, attrref,
				  (unsigned long)xmenu_eItemType_Attribute,
				  (unsigned long)xmenu_mUtility_AttrEditor, NULL, x, y);

	break;
      }
      case xnav_eItemType_Collect: {
	sts = gdh_NameToAttrref( pwr_cNObjid, item->name, &attrref);
	if ( EVEN(sts)) return sts;

	(xattnav->popup_menu_cb)( xattnav->parent_ctx, attrref,
				  (unsigned long)xmenu_eItemType_Attribute,
				  (unsigned long)xmenu_mUtility_AttrEditor, NULL, x, y);

	break;
      }
      case xnav_eItemType_Crossref: {
	ItemCrossref *itemc = (ItemCrossref *)item;

	memset( &attrref, 0, sizeof(attrref));
	attrref.Objid = itemc->objid;
	(xattnav->popup_menu_cb)( xattnav->parent_ctx, attrref,
				  (unsigned long)xmenu_eItemType_Crossref,
				  (unsigned long)xmenu_mUtility_AttrEditor, 
				  itemc->ref_name, x, y);
	break;
      }
      default:
	;
      }
      break;
    default:
      ;
    }
    break;
  }
  case flow_eEvent_Key_Right: {
    brow_tNode	*node_list;
    int		node_count;
    pwr_tStatus	sts;

    brow_GetSelectedNodes( xattnav->brow->ctx, &node_list, &node_count);
    if ( !node_count)
      return 1;

    brow_GetUserData( node_list[0], (void **)&item);
    switch( item->type) {
    case xnav_eItemType_Attr:
    case xnav_eItemType_AttrArrayElem:
    case xnav_eItemType_Collect:
      sts = item->open_children( xattnav->brow, 0, 0);
      if (ODD(sts)) break;

      if ( xattnav->advanced_user && xattnav->change_value_cb)
	(xattnav->change_value_cb)( xattnav->parent_ctx);
      break;
    case xnav_eItemType_AttrArray: 
      ((ItemAttrArray *)item)->open_attributes( xattnav->brow, 0, 0);
      break;
    case xnav_eItemType_AttrObject: 
      ((ItemAttrObject *)item)->open_attributes( xattnav->brow, 0, 0);
      break;
    case xnav_eItemType_Enum:
      if ( xattnav->advanced_user)
	((ItemEnum *)item)->set_value();
      break;
    case xnav_eItemType_Mask:
      if ( xattnav->advanced_user)
	((ItemMask *)item)->toggle_value();
      break;
    default:
      ;
    }
    free( node_list);
    break;
  }
  case flow_eEvent_MB1DoubleClick:
    switch ( event->object.object_type) {
    case flow_eObjectType_Node:
      brow_GetUserData( event->object.object, (void **)&item);

      switch( item->type) {
      case xnav_eItemType_Attr:
	((ItemAttr *)item)->open_children( xattnav->brow,
					   event->object.x, event->object.y);
	break;
      case xnav_eItemType_AttrArray:
	((ItemAttrArray *)item)->open_attributes( xattnav->brow,
						  event->object.x, event->object.y);
	break;
      case xnav_eItemType_AttrObject:
	((ItemAttrObject *)item)->open_attributes( xattnav->brow,
						   event->object.x, event->object.y);
	break;
      case xnav_eItemType_AttrArrayElem:
	((ItemAttrArrayElem *)item)->open_children( xattnav->brow,
						    event->object.x, event->object.y);
	break;
      case xnav_eItemType_Crossref:
	if ( xattnav->start_trace_cb) {
	  (xattnav->start_trace_cb)( xattnav->parent_ctx, item->objid, 
				     ((ItemCrossref *)item)->ref_name);
	  if ( xattnav->close_cb) {
	    (xattnav->close_cb)( xattnav->parent_ctx);
	    return 1;
	  }
	}
	break;
      default:
	;
      }
      break;
    default:
      ;
    }
    break;
  case flow_eEvent_Radiobutton: {
    switch ( event->object.object_type) {
    case flow_eObjectType_Node:
      brow_GetUserData( event->object.object, (void **)&item);
      switch( item->type) {
      case xnav_eItemType_Enum: 
	if ( !event->radiobutton.value)
	  ((ItemEnum *)item)->set_value();
	break;
      case xnav_eItemType_Mask: 
	((ItemMask *)item)->set_value( !event->radiobutton.value);
	break;
      default:
	;
      }
      break;
    default:
      ;
    }
    break;
  }
  case flow_eEvent_Map: {
    xattnav->displayed = 1;
    break;
  }

  default:
    ;
  }
  return 1;
}