Exemplo n.º 1
0
static void
init (
)
{
  pwr_sClass_ASup *asp;
  pwr_sClass_DSup *dsp; 
  pwr_tStatus sts;
  sAttribute *ap;
  sObject *op;
  sSupObject *sp;
  pwr_tObjid oid;

  ltp = tree_CreateTable(&sts, sizeof(pwr_tObjid), offsetof(sObject, oid),
    sizeof(sObject), 200, tree_Comp_oid);

  sts = gdh_GetClassList(pwr_cClass_ASup, &oid);
  while (ODD(sts)) {
    sts = gdh_ObjidToPointer(oid, (void **)&asp);
    op = tree_Find(&sts, ltp, &asp->Attribute.Objid);
    if (op == NULL) {
      op = tree_Insert(&sts, ltp, &asp->Attribute.Objid);
      LstIni(&op->attr_l);
    }

    ap = findAttribute(op, &asp->Attribute, pwr_cClass_ASup);
    
    sp = calloc(1, sizeof(*sp));
    (void)LstIns(LstEnd(&ap->sup_l), sp, sup_l); 
    sp->oid = oid;
    sp->p = asp;
    op->sup_c++;
    ap->sup_c++;

    sts = gdh_GetNextObject(oid, &oid);
  }

  sts = gdh_GetClassList(pwr_cClass_DSup, &oid);
  while (ODD(sts)) {
    sts = gdh_ObjidToPointer(oid, (void **)&dsp);
    op = tree_Find(&sts, ltp, &dsp->Attribute.Objid);
    if (op == NULL) {
      op = tree_Insert(&sts, ltp, &dsp->Attribute.Objid);
      LstIni(&op->attr_l);
    }

    ap = findAttribute(op, &dsp->Attribute, pwr_cClass_DSup);
    
    sp = calloc(1, sizeof(*sp));
    (void)LstIns(LstEnd(&ap->sup_l), sp, sup_l); 
    sp->oid = oid;
    sp->p = dsp;
    op->sup_c++;
    ap->sup_c++;

    sts = gdh_GetNextObject(oid, &oid);
  }

}
Exemplo n.º 2
0
//
// Set Scan filter
//
static pwr_tStatus SetScanFilter( xmenu_sMenuCall *ip)
{
    pwr_tObjid child;
    int sts;
    pwr_tBoolean local;
    pwr_tObjid io_handler;
    pwr_sClass_IOHandler *io_handler_p;
    pwr_sClass_windowplc *window_p;
    pwr_tClassId classid;
    int enable;

    if ( !ip->Priv & pwr_mPrv_System)
        return XNAV__INSENSITIVE;

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

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

    // 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 XNAV__INSENSITIVE;

    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_ObjidToPointer( child, (void **) &window_p);
            if ( EVEN(sts)) return sts;

            if ( (enable && window_p->ScanOff) ||
                    (!enable && !window_p->ScanOff))
                return XNAV__SUCCESS;
            else
                return XNAV__INSENSITIVE;
        }
    }
    return XNAV__INVISIBLE;
}
Exemplo n.º 3
0
/* Supervise emon server process */
void
pwrs_Node_SupEmon (
)
{
  int i = errh_eAnix_emon - 1;
  pwr_tTime current_time;
  pwr_tDeltaTime diff;
  static float timeout = 3;

  if ( !np) {
    pwr_tOid oid;
    pwr_tStatus sts;

    sts = gdh_GetNodeObject( 0, &oid);
    if ( ODD(sts))
      gdh_ObjidToPointer( oid, (void **) &np);
    if ( EVEN(sts)) return;
  }

  if ( !np)
    return;

  if ( np->ProcStatus[i] != 0 && np->ProcStatus[i] != PWR__PTIMEOUT) {
    time_GetTime( &current_time);
    time_Adiff( &diff, &current_time, &np->ProcTimeStamp[i]);

    if ( time_DToFloat( 0, &diff) > timeout) {
      if ( errh_Severity( np->ProcStatus[i]) < errh_Severity(PWR__PTIMEOUT)) {
	np->ProcStatus[i] = PWR__PTIMEOUT;
	np->SystemStatus = PWR__PTIMEOUT;
      }
    }
  }
}
Exemplo n.º 4
0
static pwr_tStatus IoCardInit (
  io_tCtx	ctx,
  io_sAgent	*ap,
  io_sRack	*rp,
  io_sCard	*cp  
) 
{
  pwr_sClass_Ssab_PIDuP *op;
  io_sLocal 		*local;
  pwr_tStatus		sts;

  op = (pwr_sClass_Ssab_PIDuP *) cp->op;
  local = calloc( 1, sizeof(*local));
  cp->Local = local;
  local->Address = op->RegAddress;
  local->Qbus_fp = ((io_sRackLocal *)(rp->Local))->Qbus_fp;

  errh_Info( "Init of pid card '%s'", cp->Name);

  sts = gdh_ObjidToPointer(op->PidXCon, (void *) &local->objP);

  if ( EVEN(sts)) {
    errh_Error( "PID-card not properly connected, %s", cp->Name);
    return IO__ERRDEVICE;
  }

  /* Calculate indexes in I/O-area */

  local->dyn_ind = ((char *) &local->Dyn - (char *) local) / 2;
  local->par_ind = ((char *) &local->Par - (char *) local) / 2;
  local->stat_ind = ((char *) &local->Stat - (char *) local) / 2;
  local->ran_ind = ((char *) &local->AoRange - (char *) local) / 2;

  return 1;
}
Exemplo n.º 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);
}
Exemplo n.º 6
0
int xnav_open_URL( pwr_tURL url)
{
  char cmd[200];
  int sts;
  pwr_sClass_WebBrowserConfig *config_p = 0;
  char browser[40] = "firefox";
  pwr_tObjid config_objid;

  sts = gdh_GetClassList( pwr_cClass_WebBrowserConfig, &config_objid);
  if ( ODD(sts))
    sts = gdh_ObjidToPointer( config_objid, (void **)&config_p);

  if ( ODD(sts)) {
    if ( strcmp( config_p->WebBrowser, "") != 0)
      strcpy( browser, config_p->WebBrowser);
  }

  if ( strncmp( url, "$pwr_lang/", 10) == 0) {
    // If file in $pwr_lang, check if file exist, else take en_us

    if ( Lng::current() != lng_eLanguage_en_US) {
      pwr_tURL testurl;
      pwr_tTime t;
      
      replace_symbol( url, testurl, config_p);
      dcli_translate_filename( testurl, testurl);
      sts = dcli_file_time( testurl, &t);
      if ( EVEN(sts)) {
	// Try en_us
	strcpy( testurl, "$pwr_doc/en_us/");
	strcat( testurl, &url[10]);
	strcpy( url, testurl);
      }
    }
  }
  
  replace_symbol( url, url, config_p);

  if ( strcmp( browser, "mozilla") == 0 ||
       strcmp( browser, "rt_mozilla") == 0) {
    // Try remote display first
    sprintf( cmd, "%s -remote \"openurl(%s,new-window)\"", browser, url);
    sts = system(cmd);
    if ( sts) {
      // Not started yet 
      sprintf( cmd, "%s %s &", browser, url);
      system( cmd);
    }
  }
  else {
    sprintf( cmd, "%s %s &", browser, url);
    system( cmd);
  }
  return XNAV__SUCCESS;
}
Exemplo n.º 7
0
int print_data( pwr_sAttrRef *arp, FILE *fp)
{
  int		sts;
  char		*s;
  pwr_tClassId	classid;
  char		*object_p;
  pwr_tAName   	dataname;
  pwr_tAName   	objectname;
  pwr_tAName   	attributename;
  pwr_tObjid	objid;
  int 		object_backup;
  int		array_element = 0;
  int		index;
  int		nr;

  sts = gdh_AttrrefToName( arp, dataname, sizeof(dataname), cdh_mNName);
  if ( EVEN(sts)) return sts;

  strcpy( objectname, dataname);
  if ( (s = strchr( objectname, '.'))) {
    *s = 0;
    object_backup = 0;
    strcpy( attributename, dataname);
    if ( (s = strchr( dataname, '['))) {
      array_element = 1;

      nr = sscanf( s+1, "%d", &index);
      if ( nr != 1) return 0;
    }
  }
  else {
    object_backup = 1;
  }

  sts = gdh_NameToObjid( objectname, &objid);
  if ( EVEN(sts)) return sts;

  sts = gdh_ObjidToPointer( objid, (void **)&object_p);
  if ( EVEN(sts)) return sts;

  sts = gdh_GetObjectClass( objid, &classid);
  if ( EVEN(sts)) return sts;

  if ( object_backup) {
    print_object( objid, classid, object_p, 0, objectname, fp);
  }
  else {
    print_attribute( objid, classid, object_p, attributename, array_element, index, fp);
  }
  return 1;
}
Exemplo n.º 8
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;
}
Exemplo n.º 9
0
static pwr_tStatus SimulateOn( xmenu_sMenuCall *ip)
{
    int sts;
    pwr_tObjid io_handler;
    pwr_sClass_IOHandler *io_handler_p;

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

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

    if ( !io_handler_p->IOSimulFlag)
        return XNAV__INVISIBLE;

    return XNAV__SUCCESS;
}
Exemplo n.º 10
0
pwr_tStatus io_get_plhandler_object(pwr_sClass_EplHandler** o, pwr_tObjid* roid)
{
  pwr_tStatus sts;
  pwr_tObjid oid;

  // Get EplHandler object
  sts = gdh_GetClassList(pwr_cClass_EplHandler, &oid);
  if (EVEN(sts))
    return sts;

  sts = gdh_ObjidToPointer(oid, (void*)o);
  if (EVEN(sts))
    return sts;

  if (roid != NULL)
    *roid = oid;
  return IO__SUCCESS;
}
Exemplo n.º 11
0
void rt_fast::open()
{
  pwr_tStatus sts;
  pwr_sAttrRef aref;
  pwr_tObjid oid;
  pwr_sClass_DsFastConf *conf_p;

  // Open server configuration object DsFastConf
  sts = gdh_GetClassList( pwr_cClass_DsFastConf, &oid);
  if ( ODD(sts)) {
    sts = gdh_ObjidToPointer( oid, (void **)&conf_p);
    if ( EVEN(sts)) throw co_error( sts);

    scan_time = 1.0 / conf_p->BaseFrequency;
  }
  else {
    scan_time = 0.1;
    errh_Info( "No fast configuration, using base frequency 10 Hz");
    oid = pwr_cNObjid;
  }

  aproc_RegisterObject( oid);

  // Open FastCurve object
  for ( sts = gdh_GetClassListAttrRef( pwr_cClass_DsFastCurve, &aref);
	ODD(sts);
	sts = gdh_GetNextAttrRef( pwr_cClass_DsFastCurve, &aref, &aref)) {
    fastobject *o = new fastobject( &aref);
    objects.push_back( o);
    try {
      o->open( scan_time);
      fast_cnt++;
    }    
    catch ( co_error& e) {
      delete o;
      objects.pop_back();
      errh_Error( "DsFastCurve configuration error: &s", (char *)e.what().c_str());
    }
  }
}
Exemplo n.º 12
0
static void
init_grafcet ()
{
  pwr_tStatus	sts;
  pwr_tObjid	oid;
  pwr_sClass_initstep *o;

  sts = gdh_GetClassList(pwr_cClass_initstep, &oid);
  while (ODD(sts)) {
    sts = gdh_ObjidToPointer(oid, (void *)&o);
    if (EVEN(sts)) {
      errh_Error("Initialize all GRAFCET init steps, %m", sts);
      return;
    }
    if (!o->StatusInit) {
      /* This InitStep is not initialized. */
      o->Status[0] = 1;
      o->StatusInit = 1;
    }
    sts = gdh_GetNextObject(oid, &oid);
  }
}
Exemplo n.º 13
0
void EvEve::view_shift() 
{
  pwr_sClass_OpPlace *opp;
  pwr_tStatus sts;

  sts = gdh_ObjidToPointer( user, (pwr_tAddress *) &opp);
  if ( EVEN(sts)) return;

  if ( cdh_ObjidIsNull(ala->current_view)) {
    set_view( opp->AlarmViews[0]);
  }
  else {
    for ( unsigned int i = 0; i < sizeof(opp->AlarmViews)/sizeof(opp->AlarmViews[0]); i++) {
      if ( cdh_ObjidIsEqual( ala->current_view, opp->AlarmViews[i])) {
	if ( i == sizeof(opp->AlarmViews)/sizeof(opp->AlarmViews[0]) - 1)
	  set_view( pwr_cNObjid);
	else
	  set_view( opp->AlarmViews[i+1]);
	break;
      }	   
    }
  }
}
Exemplo n.º 14
0
void
pwrb_IOHandler_Exec (
  void (* handler_event_cb)(int, int),
  int swap
)
{
  static pwr_tBoolean old_CardErrorSoftLimit = 0;
  static pwr_tBoolean old_CardErrorHardLimit = 0;

  if ( !iop || swap) {
    pwr_tOid oid;
    pwr_tStatus sts;

    sts = gdh_GetClassList( pwr_cClass_IOHandler, &oid);
    if ( ODD(sts))
      gdh_ObjidToPointer( oid, (void **) &iop);
    if ( EVEN(sts)) return;
  }

  if ( !iop)
    return;

  if ( handler_event_cb) {
    if ( iop->CardErrorSoftLimit && !old_CardErrorSoftLimit)
      (handler_event_cb)(pwr_eSystemEventTypeEnum_IOErrorSoftLimit, 1);
    else if ( !iop->CardErrorSoftLimit && old_CardErrorSoftLimit)
      (handler_event_cb)(pwr_eSystemEventTypeEnum_IOErrorSoftLimit, 0);
    
    if ( iop->CardErrorHardLimit && !old_CardErrorHardLimit)
      (handler_event_cb)(pwr_eSystemEventTypeEnum_IOErrorHardLimit, 1);
    else if ( !iop->CardErrorHardLimit && old_CardErrorHardLimit)
      (handler_event_cb)(pwr_eSystemEventTypeEnum_IOErrorHardLimit, 0);  
  }
  old_CardErrorSoftLimit = iop->CardErrorSoftLimit;
  old_CardErrorHardLimit = iop->CardErrorHardLimit;
}
Exemplo n.º 15
0
void rt_post::open()
{
  pwr_tStatus sts;
  pwr_tObjid oid;
  pwr_tFileName filename;

  // Open server configuration object PostConfig
  sts = gdh_GetClassList( pwr_cClass_PostConfig, &oid);
  if ( ODD(sts)) {
    sts = gdh_ObjidToPointer( oid, (void **)&conf);
    if ( EVEN(sts)) throw co_error( sts);

    aproc_RegisterObject( oid);
  }
  else {
    errh_Info( "No Post configuration");
    errh_SetStatus( 0);
    exit(0);
  }

  conf->Status = PWR__SRVSTARTUP;

  // Connect to mh
  mh_UtilWaitForMh();

  sts = mh_OutunitConnect(
		oid,
		mh_eOutunitType_Post,
		0,
		mh_ack_bc,
		mh_alarm_bc,
		mh_block_bc,
		mh_cancel_bc,
		mh_clear_alarmlist_bc,
		mh_clear_blocklist_bc,
		mh_info_bc,
		mh_return_bc,
		NULL
		);
  if ( EVEN(sts)) {
    errh_Error( "Post terminated: %m", sts);
    conf->Status = sts;
    exit(0);
  }

  // Load user database
	
  sts = gdh_GetObjectInfo( "pwrNode-System.SystemGroup", &systemgroup, 
			   sizeof(systemgroup));
  if ( EVEN(sts)) {
    errh_Error( "Post terminated: %m", sts);
    conf->Status = sts;
    exit(0);
  }

  udb = new GeUser();
  sts = dcli_get_defaultfilename( user_cFilename, filename, "");
  udb->load( filename);

  conf->Status = PWR__SRUN;

}
Exemplo n.º 16
0
int main(int argc, char *argv[])
{
  remtrans_item *remtrans;
  unsigned char id[32];
  unsigned char pname[32];
  
  pwr_tStatus sts;
  int i;
  float time_since_scan = 0.0;
  
  
  
  /* Read arg number 2, should be id for this instance and id is our queue number */
  
  if (argc >= 2)
    strcpy((char *)id, argv[1]);
  else
    strcpy((char *)id, "0");
  
  /* Build process name with id */
  
  sprintf((char *) pname, "rs_remwmq_%s", id);
  
  /* Init of errh */
  
  errh_Init((char *) pname, errh_eAnix_remote);
  errh_SetStatus(PWR__SRVSTARTUP);
  
  /* Init of gdh */
  if (debug) printf("Before gdh_init\n");
  sts = gdh_Init((char *) pname);
  if ( EVEN(sts)) {
    errh_Fatal("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_Fatal("cdh_StringToObjid, %m", sts);
    errh_SetStatus(PWR__SRVTERM);
    exit(sts);
  }
  
  /* Get pointer to RemnodeWMQ object and store locally */
  
  sts = gdh_ObjidToPointer(rn.objid, (pwr_tAddress *) &rn_wmq);
  if ( EVEN(sts)) {
    errh_Fatal("cdh_ObjidToPointer, %m", sts);
    errh_SetStatus(PWR__SRVTERM);
    exit(sts);
  }
  
  /* 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_wmq->ErrCount = 0;
  
  if (debug) printf("Before remtrans_init\n");
  
  sts = RemTrans_Init(&rn);
  
  if ( EVEN(sts)) {
    errh_Fatal("RemTrans_Init, %m", sts);
    errh_SetStatus(PWR__SRVTERM);
    exit(sts);
  }
  
  /* Store remtrans objects objid in remnode_mq object */
  remtrans = rn.remtrans;
  i = 0;
  while(remtrans) {
    rn_wmq->RemTransObjects[i++] = remtrans->objid;
    if ( i >= (int)(sizeof(rn_wmq->RemTransObjects) / sizeof(rn_wmq->RemTransObjects[0])))
      break;
    remtrans = (remtrans_item *) remtrans->next;
  }
  
  /* Variables for MQ calls */
  
  strncpy(mgr_name, rn_wmq->QueueManager, MQ_Q_MGR_NAME_LENGTH);
  //  strncpy(mgr_name, "hejsanqqq", sizeof(MQ_Q_MGR_NAME_LENGTH));
  

  /* Open queue for receiving messages */
  
  strncpy(rcv_que_name, rn_wmq->RcvQueue, MQ_Q_NAME_LENGTH);
  //  strncpy(rcv_que_name, "hejsanqqq", sizeof(MQ_Q_NAME_LENGTH));

  /* Initialize object descriptor control block */

  strncpy(RcvObjDesc.ObjectName, rcv_que_name, MQ_Q_NAME_LENGTH);

  /* open queue for input but not if MQM stopping */

  RcvOpenOptions =  MQOO_INPUT_AS_Q_DEF | MQOO_FAIL_IF_QUIESCING;

  /* Open queue for sending messages */
  
  strncpy(snd_que_name, rn_wmq->SndQueue, MQ_Q_NAME_LENGTH);
  //  strncpy(snd_que_name, "hejsanqqq", sizeof(MQ_Q_NAME_LENGTH));

  /* Initialize object descriptor control block */

  strncpy(SndObjDesc.ObjectName, snd_que_name, MQ_Q_NAME_LENGTH);

  /* open queue for output but not if MQM stopping */

  SndOpenOptions =  MQOO_OUTPUT | MQOO_FAIL_IF_QUIESCING;
  
  errh_SetStatus(PWR__SRUN);
  
  /* Connect and open */

  sts = wmq_connectandopen();

  /* Set (re)start time in remnode object */
  
  time_GetTime(&rn_wmq->RestartTime);
  
  /* Loop forever */

  while (!doomsday) {
    if (rn_wmq->Disable == 1) {
      errh_Fatal("Disabled, exiting");
      errh_SetStatus(PWR__SRVTERM);
      exit(0);
    }   
    aproc_TimeStamp(TIME_INCR, 5);
    RemoteSleep(TIME_INCR);

    time_since_scan += TIME_INCR;

    if (!connected) 
      sts = wmq_connectandopen();

    if (connected) {
      sts = wmq_receive();

      if (time_since_scan >= rn_wmq->ScanTime) {
	sts = RemTrans_Cyclic(&rn, &wmq_send);
	time_since_scan = 0.0;
      }
    }
  }
}
Exemplo n.º 17
0
pwr_tUInt32 bck_WaitBackup (
		void *context,
		pwr_tBoolean timeout)
{
  pwr_tUInt32 sts;
  pwr_tObjid objid;
  pwr_tInt32 c;
  pwr_tTime t;
  pwr_tVaxTime tmo;
  pwr_tVaxTime tmptime;
  pwr_sClass_Backup_Conf *backup_confp;	/* Backup_Conf object pointer */
  $DESCRIPTOR (timeunitdsc, "0 0:0:0.1");	/* 0.1 second units */
  int cycletime;

#ifdef OS_ELN
  pwr_tInt32 res;
  pwr_tVaxTime *tmop;
#endif

#ifdef OS_VMS
  $DESCRIPTOR (efcname, BCK_EFC_NAME);
#endif

/*
 * Initialize
 */

#ifdef OS_ELN
  if (!areas_mapped) {
    BCK_MAP_AREAS;
    areas_mapped = TRUE;
  }
#endif

/*
 * Find the local Backup_Conf object
 */

  sts = gdh_GetClassList (pwr_cClass_Backup_Conf, &objid);
  while (ODD (sts)) {
    sts = gdh_ObjidToPointer (objid, (pwr_tAddress *)&backup_confp);
    if (ODD (sts)) break;
    sts = gdh_GetNextObject (objid, &objid);
  }
  if (EVEN (sts)) return sts;		/* Something wrong, quit */

/*
 * Pick up argument information
 */

  if (context == NULL) time_GetTime(&t);
  else {
    t = *(pwr_tTime *)context;
    free (context);
  }

#ifdef OS_ELN
  tmop = NULL;
#else
  timed_out = FALSE;  
  sts = sys$ascefc (BCK_EFC, &efcname, 0, 0);
  if (EVEN (sts)) lib$signal (sts);			/* BUG */
#endif

  if (timeout) {
    cycletime = backup_confp->CycleSlow * 2;
    if (cycletime == 0) cycletime = BCK_DEFAULT_SLOW * 2;

#ifdef OS_ELN
    tmo = eln$time_value (&timeunitdsc);
#else
    sts = sys$bintim (&timeunitdsc, &tmo);
    if (EVEN (sts)) lib$signal (sts);		/* BUG, should not happen */
#endif

    lib$mult_delta_time (
		&cycletime,		/* multiplier */
		&tmo);			/* delta_time (modified) */
    sys$gettim (&tmptime);
    lib$add_times (&tmo, &tmptime, &tmo); /* Make absolute time */

#ifdef OS_ELN
    tmop = &tmo;
#else
    sts = sys$setimr (BCK_WRITE_DONE, &tmo, &astrtn, 4711, 0);
    if (EVEN (sts)) lib$signal (sts);			/* BUG */
#endif
  }

/*
 * Loop, and wait for things to happen
 */

  while (TRUE) {
#ifdef OS_ELN
    ker$clear_event (NULL, bck_write_done);
    ker$wait_any (NULL, &res, tmop, bck_write_done);

    /* Check for timeout */

    if (res == 0) return SS$_TIMEOUT;
#else

    sts = sys$clref (BCK_WRITE_DONE);
    if (EVEN (sts)) lib$signal (sts);			/* BUG */
    sts = sys$waitfr (BCK_WRITE_DONE);
    if (EVEN (sts)) lib$signal (sts);			/* BUG */

    /* Check for timeout */

    if (timed_out) return SS$_TIMEOUT;

#endif

    /* Check if both cycles done */

    if (time_Acomp(&backup_confp->ObjTimeSlow, &t) < 0) 
        continue;
    if (time_Acomp(&backup_confp->ObjTimeFast, &t) < 0) 
        continue;

    break;

  } /* Loop */

#ifdef OS_VMS
  sys$cantim (4711, 0);
#endif

  return 1;	/* Done. */

} /* bck_WaitBackup */
Exemplo n.º 18
0
int main(int argc, char *argv[])
{
  remtrans_item *remtrans;
  unsigned char id[32];
  unsigned char pname[32];

  pwr_tStatus sts;
  struct timeval tv;
  int i;
  
  /* 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_remudp_%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 RemnodeUDP object and store locally */
  
  sts = gdh_ObjidToPointer(rn.objid, (pwr_tAddress *) &rn_udp);
  if ( EVEN(sts)) {
    errh_Error("cdh_ObjidToPointer, %m", sts);
    errh_SetStatus(PWR__SRVTERM);
    exit(sts);
  }

  /* 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 = rn_udp->RetransmitTime;
  rn_udp->ErrCount = 0;

  sts = RemTrans_Init(&rn);

  /* Log that we will multicast */
    
  if (rn.multicast) {
    errh_Info("Will send to dual address: %d.%d.%d.%d",
      rn.multicast->Address[0],
      rn.multicast->Address[1],
      rn.multicast->Address[2],
      rn.multicast->Address[3]);
  }

  if ( EVEN(sts)) {
    errh_Error("RemTrans_Init, %m", sts);
    errh_SetStatus(PWR__SRVTERM);
    exit(sts);
  }
  
  /* Store remtrans objects objid in remnode_udp object */
  remtrans = rn.remtrans;
  i = 0;
  while(remtrans) {
    rn_udp->RemTransObjects[i++] = remtrans->objid;
    if ( i >= (int)(sizeof(rn_udp->RemTransObjects)/sizeof(rn_udp->RemTransObjects[0])))
      break;
    remtrans = (remtrans_item *) remtrans->next;
  }

  /* Initialize no timeout value (poll) for select call */

  tv.tv_sec = 0;
  tv.tv_usec = 0;

  /* Create UDP socket and init adress structures */

  CreateSocket();

  /* Wait for one cycle */
  
  RemoteSleep(rn_udp->ScanTime);

  /* Set running status */
  
  errh_SetStatus(PWR__SRUN);
  
  /* Set (re)start time in remnode object */
  
  time_GetTime(&rn_udp->RestartTime);
  
  /* Loop forever */

  while (!doomsday)
  {
    /* Check disable flag */
    
    if (rn_udp->Disable == 1) {
      errh_Fatal("Disabled, exiting");
      errh_SetStatus(PWR__SRVTERM);
      exit(0);
    }   
    
    /* Timestamp */
    
    aproc_TimeStamp(TIME_INCR, 5);

    RemoteSleep(TIME_INCR);

    /* Increase time counters in local remnode and prevent big counters */
    
    time_since_scan += TIME_INCR;
    time_since_keepalive += TIME_INCR;
    time_since_rcv += TIME_INCR;
    time_since_scan = min(time_since_scan, rn_udp->ScanTime + 1.0);
    time_since_keepalive = min(time_since_keepalive, rn_udp->KeepaliveTime + 1.0);
    time_since_rcv = min(time_since_rcv, rn_udp->LinkTimeout + 1.0);

    /* Update retransmit time, could have been changed */
    
    rn.retransmit_time = rn_udp->RetransmitTime;

    remtrans = rn.remtrans;
    while(remtrans) {
      remtrans->time_since_send += TIME_INCR;
      /* Prevent big counter */
      remtrans->time_since_send = min(remtrans->time_since_send, rn.retransmit_time + 1.0);
      remtrans = (remtrans_item *) remtrans->next;
    }

    tv.tv_sec = 0;
    tv.tv_usec = 0;

    FD_ZERO(&fds);
    FD_SET(my_socket, &fds);
    sts = select(32, &fds, NULL, NULL, &tv);

    if (sts > 0) Receive();

    if (sts < 0) {
      errh_Error("Select, %d", sts);
      errh_SetStatus(PWR__SRVTERM);
      exit(0);
    }
    
    if (time_since_scan >= rn_udp->ScanTime) {
      if (!rn_udp->Disable) RemTrans_Cyclic(&rn, &RemnodeSend);
      time_since_scan = 0;
    }

    if (time_since_keepalive >= rn_udp->KeepaliveTime) {
      if (!rn_udp->Disable && rn_udp->UseKeepalive) SendKeepalive();
      time_since_keepalive = 0;
    }

    if (time_since_rcv >= rn_udp->LinkTimeout && rn_udp->LinkTimeout > 0) {
      if (rn_udp->LinkUp) {
        errh_Info("UDP link down %s", rn_udp->RemoteHostname);
        rn_udp->LinkUp = 0;
      }
    }
  }
}
Exemplo n.º 19
0
int XNav::getAllMenuItems( xmenu_sMenuCall	*ip,
			   xmenu_sMenuItem	**Item,
			   pwr_tObjid		objid,
			   pwr_tUInt32		Level,
			   int			*nItems,
			   int			AddSeparator,
			   pwr_sAttrRef		*CurrentObject)
{
  int                   sts;
  pwr_tCid	        classid;
  pwr_tObjid            child;
  pwr_sMenuButton	*mbp;
  pwr_sMenuCascade	*mcp;
  pwr_sMenuRef		*mrp;
  pwr_tStatus           (*filter)( xmenu_sMenuCall *);
  int                   sensitive;
  int                   i;


  Level++;
  memset(*Item, 0, sizeof(**Item));

  if(AddSeparator) {
    (*Item)->Level = Level;
    (*Item)->Item = xmenu_eMenuItem_Separator;
    (*Item)->MenuObject = pwr_cNObjid;
    (*Item)++;
    (*nItems)++;
  } 
  else {
    sts = gdh_GetObjectClass( objid, &classid);
    if ( EVEN(sts)) return sts;

    if ( classid == pwr_eClass_MenuButton) {
      sts = gdh_ObjidToPointer( objid, (void **) &mbp);
      if ( EVEN(sts)) return sts;

      
      ip->ChosenItem = *nItems;
      for ( i = 0; i < 5; i++) {
        strcpy( (*Item)->FilterArguments[i], mbp->FilterArguments[i]);
      }

      // Call any filter method
      (*Item)->CurrentObject = *CurrentObject;
      sensitive = 1;
      if ( strcmp( mbp->FilterName, "") != 0) {
        sts = GetMethod( mbp->FilterName, &filter);
        if ( ODD(sts)) {
          sts = (filter) ( ip);
	  if ( sts == XNAV__INSENSITIVE) 
            sensitive = 0;
        }
      }
      else
        sts = XNAV__SUCCESS;

      if ( ODD(sts)) {
        (*Item)->Level = Level;
        (*Item)->Item = xmenu_eMenuItem_Button;
        (*Item)->MenuObject = objid;

        (*Item)->Flags.f.Sensitive = sensitive;
        if (strcmp( mbp->MethodName, "")  == 0)
          (*Item)->Flags.f.Sensitive = 0;

        strcpy((*Item)->Name, mbp->ButtonName);
        strcpy( (*Item)->Method, mbp->MethodName);
        strcpy( (*Item)->Filter, mbp->FilterName);
        for ( i = 0; i < 5; i++) {
          strcpy( (*Item)->MethodArguments[i], mbp->MethodArguments[i]);
        }
        (*Item)++;
        (*nItems)++;
      }
    } 
    else if ( classid == pwr_eClass_MenuSeparator) {
      (*Item)->Level = Level;
      (*Item)->Item = xmenu_eMenuItem_Separator;
      (*Item)->MenuObject = objid;
      (*Item)++;
      (*nItems)++;
    } 
    else if ( classid == pwr_eClass_MenuCascade) {
      sts = gdh_ObjidToPointer( objid, (void **) &mcp);
      if ( EVEN(sts)) return sts;

      // Call any filter method
      (*Item)->CurrentObject = *CurrentObject;
      if ( strcmp( mcp->FilterName, "") != 0) {
        sts = GetMethod( mcp->FilterName, &filter);
        if ( ODD(sts)) {
          sts = (filter) ( ip);
        }
      }
      else
        sts = XNAV__SUCCESS;

      if ( ODD(sts)) {
        (*Item)->Level = Level;
        (*Item)->Item = xmenu_eMenuItem_Cascade;
        (*Item)->Flags.f.Sensitive = 1;
        strcpy((*Item)->Name, mcp->ButtonName);
        (*Item)->MenuObject = objid;
        (*Item)++;
        (*nItems)++;
     
        sts = gdh_GetChild( objid, &child);
        while( ODD(sts)) {
          sts = getAllMenuItems(ip, Item, child, Level, nItems, 0, CurrentObject);
          if ( EVEN(sts)) return sts;
          sts = gdh_GetNextSibling( child, &child);
        }
      }
    }
    else if ( classid == pwr_eClass_MenuRef && 
	      cdh_ObjidIsNull( CurrentObject->Objid)) {
      pwr_tAName aname;
      pwr_sAttrRef currentar;
      pwr_tCid current_cid;
      pwr_tTid a_tid;
      pwr_tUInt32 a_size, a_offs, a_elem;

      sts = gdh_ObjidToPointer( objid, (void **) &mrp);
      if ( EVEN(sts)) return sts;

      // Call any filter method
      (*Item)->CurrentObject = *CurrentObject;
      if ( strcmp( mrp->FilterName, "") != 0) {
        sts = GetMethod( mrp->FilterName, &filter);
        if ( ODD(sts)) {
          sts = (filter) ( ip);
        }
      }
      else
        sts = XNAV__SUCCESS;

      if ( ODD(sts)) {
	int create_object_button = 0;

	if ( strcmp( mrp->RefAttribute, "_SelfObject") == 0) {
	  // Object entry for attributes
	  char *s;

	  sts = gdh_AttrrefToName( &ip->Pointed, aname, sizeof(aname), cdh_mName_volumeStrict);
	  if ( EVEN(sts)) return sts;
	  if ( (s = strrchr( aname, '.')))
	    *s = 0;

	  sts = gdh_NameToAttrref( pwr_cNOid, aname, &currentar);
	  if ( EVEN(sts)) return sts;
	}
	else {
	  sts = gdh_AttrrefToName( &ip->Pointed, aname, sizeof(aname), cdh_mName_volumeStrict);
	  if ( EVEN(sts)) return sts;
	  strcat( aname, ".");
	  strcat( aname, mrp->RefAttribute);
	  
	  sts = gdh_GetAttributeCharacteristics( aname, &a_tid, &a_size,
						 &a_offs, &a_elem);
	  if ( ODD(sts)) {
	    switch ( a_tid) {
	    case pwr_eType_AttrRef:
	      sts = gdh_GetObjectInfo( aname, &currentar, sizeof(currentar));
	      break;
	    case pwr_eType_Objid: {
	      pwr_tOid oid;
	      
	      currentar = pwr_cNAttrRef;
	      sts = gdh_GetObjectInfo( aname, &oid, sizeof(oid));
	      currentar = cdh_ObjidToAref( oid);
	      break;
	    }
	    default:
	      sts = 0;
	  }
	  }
	  create_object_button = 0;
	}
	if ( ODD(sts) && cdh_ObjidIsNotNull( currentar.Objid)) {
	  (*Item)->Level = Level;
	  (*Item)->Item = xmenu_eMenuItem_Ref;
	  (*Item)->Flags.f.Sensitive = 1;
	  strcpy((*Item)->Name, mrp->ButtonName);
	  (*Item)->MenuObject = objid;
	  (*Item)++;
	  (*nItems)++;

	  // Create a label with current object name
	  sts = gdh_AttrrefToName( &currentar, aname, sizeof(aname), 
				   cdh_mNName);
	  if ( ODD(sts) && create_object_button) {
	    (*Item)->Level = Level;
	    (*Item)->Item = xmenu_eMenuItem_Button;
	    (*Item)->MenuObject = pwr_cNObjid;
	    strncpy((*Item)->Name, aname, sizeof((*Item)->Name));
	    (*Item)->Name[sizeof((*Item)->Name)-1] = 0;
	    (*Item)->MenuObject = pwr_cNObjid;
	    (*Item)->CurrentObject = currentar;
	    (*Item)->Flags.f.Sensitive = 1;
	    strcpy( (*Item)->Method, "$Object-OpenObject");
	    (*Item)++;
	    (*nItems)++;
	  }

	  sts = gdh_GetAttrRefTid( &currentar, &current_cid);
	  if ( EVEN(sts)) return sts;

	  xmenu_eItemType item_type = ip->ItemType;
	  if ( currentar.Flags.b.Object)
	    ip->ItemType =  xmenu_eItemType_Object;
	  else
	    ip->ItemType =  xmenu_eItemType_AttrObject;

	  sts = GetObjectMenu(ip, current_cid, Item, Level, nItems, 0, &currentar);
	  if ( EVEN(sts)) return sts;

	  ip->ItemType = item_type;
        }
      }
    }
  }
  return XNAV__SUCCESS;
}
Exemplo n.º 20
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;
}
Exemplo n.º 21
0
int main (int argc, char **argv)
{
  pwr_tStatus	    sts;
  pwr_tObjid	    ObjId;
  pwr_sClass_DsTrendConf *TConfP;
  pwr_tBoolean    InitOK;
  pwr_tTime		CurrentTime, LastScan, NextScan;
  pwr_tDeltaTime	ScanDeltaTime, WaitTime;
  qcom_sQid qini;
  qcom_sQattr qAttr;
  int tmo;
  char mp[2000];
  qcom_sQid qid = qcom_cNQid;
  qcom_sGet get;
  int swap = 0;
  trend_tCtx ctx;

  errh_Init("pwr_trend", errh_eAnix_trend);
  errh_SetStatus( PWR__SRVSTARTUP);

  sts = gdh_Init("ds_trend");
  If_Error_Log_Exit(sts, "gdh_Init");

  if (!qcom_Init(&sts, 0, "pwr_trend")) {
    errh_Fatal("qcom_Init, %m", sts);
    exit(sts);
  } 

  qAttr.type = qcom_eQtype_private;
  qAttr.quota = 100;
  if (!qcom_CreateQ(&sts, &qid, &qAttr, "events")) {
    errh_Fatal("qcom_CreateQ, %m", sts);
    exit(sts);
  } 

  qini = qcom_cQini;
  if (!qcom_Bind(&sts, &qid, &qini)) {
    errh_Fatal("qcom_Bind(Qini), %m", sts);
    exit(-1);
  }

  ctx = (trend_tCtx) calloc( 1, sizeof(trend_sCtx));

  /* Wait until local nethandler has started */
  while(EVEN(gdh_NethandlerRunning()))
    sleep(1);

  /* Fetch ScanTime */
  sts = gdh_GetClassList(pwr_cClass_DsTrendConf, &ObjId);
  if (EVEN(sts)) {
    errh_Info("Couldn't get the DsTrendConf object. Used ScanTime = 1 s");
    ctx->scantime = 1;
    ctx->scantime_tc = 1.0;
  } 
  else {
    gdh_ObjidToPointer(ObjId, (pwr_tAddress *)&TConfP);
    ctx->scantime = TConfP->ScanTime;
    if ( ctx->scantime > 3600)
      ctx->scantime = 3600;
    else if ( ctx->scantime < 1)
      ctx->scantime = 1;

    ctx->scantime_tc = TConfP->ScanTime;
    if ( ctx->scantime_tc > 3600)
      ctx->scantime_tc = 3600;
  }
  ctx->dstrend_multiple = (int) (ctx->scantime / ctx->scantime_tc + 0.5);

  aproc_RegisterObject( ObjId);

  InitOK = FALSE;
  sts = InitTrendList( ctx);
  if ( EVEN(sts)) { 
    /* This should be removed when we can wait for init messages. */
    errh_SetStatus(0);
    errh_Info("No DsTrend objects configured");
    exit(0);
  }

  /* If even sts, just wait for init message */

  time_GetTimeMonotonic(&LastScan);
  time_FloatToD( &ScanDeltaTime, ctx->scantime_tc);

  aproc_TimeStamp( ctx->scantime, 5.0);
  errh_SetStatus( PWR__SRUN);

  for (;;) {

    time_GetTimeMonotonic(&CurrentTime);
    time_Aadd(&NextScan, &LastScan, &ScanDeltaTime);
    if (time_Acomp(&CurrentTime, &NextScan) < 0) { 
      time_Adiff(&WaitTime, &NextScan, &CurrentTime);
      tmo = 1000 * time_DToFloat( 0, &WaitTime);

      get.maxSize = sizeof(mp);
      get.data = mp;
      qcom_Get( &sts, &qid, &get, tmo);
      if (sts == QCOM__TMO || sts == QCOM__QEMPTY) {
	if ( !swap)
	  StoreData( ctx);
      } 
      else {
	ini_mEvent  new_event;
	qcom_sEvent *ep = (qcom_sEvent*) get.data;

	new_event.m  = ep->mask;
	if (new_event.b.oldPlcStop && !swap) {
	  swap = 1;
	  errh_SetStatus( PWR__SRVRESTART);
	  CloseTrendList( ctx);
	} 
	else if (new_event.b.swapDone && swap) {
	  swap = 0;
	  sts = InitTrendList( ctx);
	  errh_SetStatus( PWR__SRUN);
	  errh_Info("Warm restart completed");
	}
	else if (new_event.b.terminate) {
	  exit(0);
	}
      }
    }
    else if ( !swap)
      StoreData( ctx);

    LastScan = NextScan;

    aproc_TimeStamp( ctx->scantime, 5.0);
  }

  return 1;
}
Exemplo n.º 22
0
int main(int argc, char *argv[])
{
  unsigned int sts;			/* Status from function calls etc. */
  unsigned char id[32];
  unsigned char pname[32];
  remtrans_item *remtrans;
  int i;

  /* 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_remser_%s", id);

  /* Init of errh */

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

  /* Set debug mode if arg number 4 is "debug" (started manually) */

  debug = 0;
  if (argc >= 4) {
    if (!strncmp(argv[3],"debug",5)) debug = 1;
  }

  if (debug) printf("debugmode valt\n");

  /* 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 RemnodeSerial object and store locally */
  
  sts = gdh_ObjidToPointer(rn.objid, (pwr_tAddress *) &rn_serial);
  if ( EVEN(sts)) {
    errh_Error("cdh_ObjidToPointer, %m", sts);
    errh_SetStatus(PWR__SRVTERM);
    exit(sts);
  }

  /* 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_serial->ErrCount = 0;

  sts = RemTrans_Init(&rn);

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

  time_since_scan = 0;
  time_since_rcv = 0;

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

  /* Initialize device */

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

  /* Loop forever */

  while (1)
  {
    if (rn_serial->Disable == 1) {
      errh_Fatal("Disabled, exiting");
      errh_SetStatus(PWR__SRVTERM);
      exit(0);
    }   
    sts = Receive();
    sts = RemTrans_Cyclic(&rn, &remnode_send);
  }
}
Exemplo n.º 23
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;
}
Exemplo n.º 24
0
/*
* Name:    
*   io_ConnectToDigSupLstSerial
*
*
* Function:
*   Initialize list of DSup object for digitala in- och output signals.
* Description:
*   
*/
pwr_tStatus io_ConnectToDigSupLstSerial (
    pwr_tClassId 	Class,
    pwr_tObjid		ObjId,
    pwr_tAddress	ObjP	/* Pointer to the object */
)
{
    pwr_tStatus	  Sts;
    pwr_sClass_DSup *DSupP;
    pwr_sClass_Di *DiP;
    pwr_sClass_Do *DoP;
    pwr_sClass_Po *PoP;
    pwr_tBoolean  *BooleanP;
    pwr_tObjid	  SupId;
    pwr_tClassId  ObjClass;
    sDSupLstLink  *DSupLstP;
    sDSupLstLink  *NextDSupLstP, *NextP;
    

    switch (Class) {
      case pwr_cClass_Di:
        DiP = (pwr_sClass_Di *) ObjP;
        BooleanP = gdh_TranslateRtdbPointer( (pwr_tUInt32)DiP->ActualValue ); 
	break;

      case pwr_cClass_Do:
        DoP = (pwr_sClass_Do *) ObjP;
        BooleanP = gdh_TranslateRtdbPointer( (pwr_tUInt32)DoP->ActualValue ); 
	break;

      case pwr_cClass_Po:
        PoP = (pwr_sClass_Po *) ObjP;
        BooleanP = gdh_TranslateRtdbPointer( (pwr_tUInt32)PoP->ActualValue ); 
	break;

      default:
	return ( IO__SUCCESS );
	break;
    }


    /* Get child with class DSup */
    Sts = gdh_GetChild ( ObjId, &SupId);

    while ( ODD(Sts)) {
       Sts = gdh_GetObjectClass ( SupId, &ObjClass);  
       if ( EVEN(Sts)) return (Sts);

       if ( ObjClass == pwr_cClass_DSup ) {
         Sts = gdh_ObjidToPointer ( SupId, (pwr_tAddress *)&DSupP); 
 	 if (EVEN(Sts)) return ( Sts );

         DSupLstP = (sDSupLstLink *) calloc( 1, sizeof(sDSupLstLink) );
         DSupLstP->SupP = DSupP;
         DSupLstP->ValueP = BooleanP;
         
         if ( DSupDigSerialLstP == NULL ) {
           DSupDigSerialLstP = DSupLstP;
         }
         else {
           if ( DSupDigSerialLstP->NextP == NULL ) {
             DSupDigSerialLstP->NextP = DSupLstP;
           }             
           else {
	     NextP = DSupDigSerialLstP->NextP;
	     while ( NextP != NULL ) {
	       NextDSupLstP = NextP;
	       NextP = NextP->NextP;
	     } 
             NextDSupLstP->NextP = DSupLstP;
           }
	 }
       }

       Sts = gdh_GetNextSibling ( SupId, &SupId);
    }		

    return IO__SUCCESS;
} /* END io_ConnectToDigSupLstSerial */
Exemplo n.º 25
0
/*
* Name:    
*   io_ConnectToAnaSupLstSerial
*
*
* Function:
*   Initialize list of ASup object for serial connected analog in- och output 
*   signals.
* Description:
*   
*/
pwr_tStatus io_ConnectToAnaSupLstSerial (
    pwr_tClassId 	Class,
    pwr_tObjid		ObjId,
    pwr_tAddress	ObjP	/* Pointer to the object */
)
{
    pwr_tStatus	  Sts;
    pwr_sClass_ASup *ASupP;
    pwr_sClass_Ai *AiP;
    pwr_sClass_Ao *AoP;
    pwr_tFloat32  *Float32P;
    pwr_tObjid	  SupId;
    pwr_tClassId  ObjClass;
    sASupLstLink  *ASupLstP;
    sASupLstLink  *NextASupLstP, *NextP;

    switch (Class) {
      case pwr_cClass_Ai:
        AiP = (pwr_sClass_Ai *) ObjP;
        Float32P = gdh_TranslateRtdbPointer( (pwr_tUInt32)AiP->ActualValue ); 
	break;

      case pwr_cClass_Ao:
        AoP = (pwr_sClass_Ao *) ObjP;
        Float32P = gdh_TranslateRtdbPointer( (pwr_tUInt32)AoP->ActualValue ); 
	break;

      default:
	return ( IO__SUCCESS );
	break;
    }


    /* Get child with class ASup */
    Sts = gdh_GetChild ( ObjId, &SupId);
    while ( ODD(Sts)) {
       Sts = gdh_GetObjectClass ( SupId, &ObjClass);  
       if ( EVEN(Sts)) return (Sts);

       if ( ObjClass == pwr_cClass_ASup ) {
         Sts = gdh_ObjidToPointer ( SupId, (pwr_tAddress *)&ASupP); 
 	 if (EVEN(Sts)) return ( Sts );

         ASupLstP = (sASupLstLink *) calloc( 1, sizeof(sASupLstLink) );
         ASupLstP->SupP = ASupP;
         ASupLstP->ValueP = Float32P;

         if ( ASupAnaSerialLstP == NULL ) {
           ASupAnaSerialLstP = ASupLstP;
         }
         else {
           if ( ASupAnaSerialLstP->NextP == NULL ) {
             ASupAnaSerialLstP->NextP = ASupLstP;
           }             
           else {
	     NextP = ASupAnaSerialLstP->NextP;
	     while ( NextP != NULL ) {
	       NextASupLstP = NextP;
	       NextP = NextP->NextP;
	     } 
             NextASupLstP->NextP = ASupLstP;
           }
	 }
       }

       Sts = gdh_GetNextSibling ( SupId, &SupId);
    }		

    return IO__SUCCESS;
} /* END io_ConnectToAnaSupLstSerial */
Exemplo n.º 26
0
/****************************************************************************
* Name:		logg_loggconflist_add()
*
* Type		pwr_tStatus
*
* Type		Parameter	IOGF	Description
*
* Description:
*		Add a conversion config object to the list.
*
**************************************************************************/
static pwr_tStatus	logg_loggconflist_add( 
			logg_ctx			loggctx,
			pwr_tObjid 			objid, 
			logg_t_loggconf_list 		**loggconflist,
			int				*loggconflist_count)
{
	logg_t_loggconf_list	*loggconflist_ptr;
	logg_t_loggconf_list	*new_loggconflist;
	pwr_sAttrRef		attrref;
	int			i;
	pwr_tStatus		sts;
	pwr_sClass_LoggConfig	*loggconf;

	/* Syntax check */
	sts = gdh_ObjidToPointer ( objid, (pwr_tAddress *) &loggconf);
	if ( EVEN(sts)) return sts;

	/* Check that there is some filename */
	if ( !strcmp( loggconf->LoggFile, ""))
	  return REM__LOGGFILE;

	/* Check that identity is unique */
	loggconflist_ptr = *loggconflist;
	for ( i = 0; i < *loggconflist_count; i++)
	{
	  if ( loggconflist_ptr->loggconf->Identity == loggconf->Identity)
	    return REM__DUPLIDENT;
	  loggconflist_ptr++;
	}

	if ( *loggconflist_count == 0)
	{
	  *loggconflist = calloc( 1 , sizeof(logg_t_loggconf_list));
	  if ( *loggconflist == 0)
	    return REM__NOMEMORY;
	}
	else
	{
	  new_loggconflist = calloc( *loggconflist_count + 1,
			sizeof(logg_t_loggconf_list));
	  if ( new_loggconflist == 0)
	    return REM__NOMEMORY;
	  memcpy( new_loggconflist, *loggconflist, 
			*loggconflist_count * sizeof(logg_t_loggconf_list));
	  free( *loggconflist);
	  *loggconflist = new_loggconflist;
	}
	loggconflist_ptr = *loggconflist + *loggconflist_count;
	loggconflist_ptr->objid = objid;

	/* Direct link to the cell */
	memset( &attrref, 0, sizeof(attrref));
	attrref.Objid = objid;
	sts = gdh_DLRefObjectInfoAttrref ( &attrref,
		(pwr_tAddress *) &loggconflist_ptr->loggconf,
		&loggconflist_ptr->subid);
	if ( EVEN(sts)) return sts;

	(*loggconflist_count)++;

	return REM__SUCCESS;
}
Exemplo n.º 27
0
void ini_StartApplications ()
{
    pwr_tStatus sts;
    pwr_sAppl *applp;
    pwr_tObjid objid;
#ifdef	OS_ELN
    $DESCRIPTOR(prognamedsc, "");
    $DESCRIPTOR(nulldsc, "");
    $DESCRIPTOR(argdsc, "");
    VARYING_STRING(255) filename;
    VARYING_STRING(41) progname;
    char tmpfilename[255],hostspec[20],*cp;
    PORT jobport;
#endif
#ifdef	OS_VMS
    $DESCRIPTOR(prognamedsc, "");
    $DESCRIPTOR(nulldsc, "");
    $DESCRIPTOR(argdsc, "");
    char spawnbuf [512] = "";
    $DESCRIPTOR (SpawnCommand, "");
    $DESCRIPTOR (SpawnPrcnam, "Appl Start");
    pwr_tUInt32 Flags;
#endif

    /* Find the $Appl objects on this particular node */

    sts = gdh_GetClassList(pwr_eClass_Appl, &objid);
    while (ODD(sts)) {
        if (ODD(gdh_ObjidToPointer(objid, (pwr_tAddress *)&applp))) {

            /* Found an object on this node, load the program */

#ifdef	OS_ELN

            if (strlen(applp->FileName) > 0) {

                /* Check whether we booted from a local disk or not */
                if (ini_LocalBoot()) {

                    /* Local boot */

                    /* Find the filename. Beyond the last ':' */
                    cp = strrchr(applp->FileName,':');
                    if ( cp )
                        *cp++;
                    else
                        cp = applp->FileName;

                    /* Build the application filename. */
                    sprintf(tmpfilename,"%s%s",ini_BootFilesLocation(),cp);

                } else {

                    /* Remote boot */

                    /* Check if application name contains '::'. If not - add hostspec */
                    cp = strstr(applp->FileName,"::");
                    if (!cp ) {
                        ini_GetNodeInfo(NULL, NULL, NULL, hostspec, NULL, NULL);
                        sprintf(tmpfilename,"%s::%s",hostspec,applp->FileName);
                    } else {
                        strcpy(tmpfilename,applp->FileName);
                    }
                }
                errh_Info("Load program '%s'", tmpfilename);

                CSTRING_TO_VARYING(tmpfilename, filename);
                CSTRING_TO_VARYING(applp->ProgramName, progname);

                eln$load_program(&filename, &progname, applp->KernelMode,
                                 applp->StartWithDebug, FALSE, applp->KernelStackSize, 1,
                                 10, applp->JobPriority, applp->ProcessPriority, &sts);
                if (EVEN(sts)) errh_Error("eln$load_program '%s'\n%m", applp->ProgramName, sts);
            }

            if (ODD(sts)) {

                /* Start it */

                errh_Info("Start program '%s'", applp->ProgramName);

                prognamedsc.dsc$a_pointer = applp->ProgramName;
                prognamedsc.dsc$w_length = strlen(applp->ProgramName);

                argdsc.dsc$a_pointer = applp->Arg;
                argdsc.dsc$w_length = strlen (applp->Arg);

                ker$create_job(&sts, &jobport, &prognamedsc, NULL, &nulldsc, &nulldsc, &nulldsc, &argdsc);

                if (EVEN(sts)) errh_Error("ker$create_job '%s'\n%m", applp->ProgramName, sts);
            }


#elif defined(OS_VMS)

            sprintf(spawnbuf, "$ @pwr_exe:rt_ini_appl_start %s \"%s\" %d %d \"%s\"",
                    applp->FileName, applp->ProgramName,
                    applp->StartWithDebug, applp->JobPriority,
                    applp->Arg);
            SpawnCommand.dsc$w_length = strlen(spawnbuf);
            SpawnCommand.dsc$a_pointer = spawnbuf;
            Flags = 1; /* Nowait and Notify */
            errh_Info("Starting %s\nin process %s", applp->FileName, applp->ProgramName);
            sts = lib$spawn(&SpawnCommand, NULL, NULL, &Flags);
            if (EVEN(sts)) errh_Error("lib$spawn '%s'\n%m", spawnbuf, sts);

#elif defined(OS_LYNX) || defined(OS_LINUX)

            errh_Error("NYI. start %s \"%s\" %d %d \"%s\"",
                       applp->FileName, applp->ProgramName,
                       applp->StartWithDebug, applp->JobPriority,
                       applp->Arg);
#endif

        } /* Local appl object */

        sts = gdh_GetNextObject (objid, &objid);
    }
}
Exemplo n.º 28
0
static void
load_backup ()
{
  pwr_tObjid			oid;
  pwr_sClass_AvArea		*avp;
  pwr_sClass_DvArea		*dvp;
  pwr_sClass_IvArea		*ivp;
  pwr_sClass_InitArea		*iavp;
  pwr_sClass_InitArea		*idvp;
  pwr_sClass_InitArea		*iivp;
  pwr_tStatus			sts;
  int				i;
  pwr_sClass_IOHandler		*iop;
  pwr_sAttrRef			aref;
 
  sts = io_get_iohandler_object(&iop, NULL);  
  if (EVEN(sts)) {
    errh_Error("io_get_iohandler_object, %m", sts);
    return;
  }

  sts = gdh_NameToObjid("pwrNode-active-io-av", &oid);
  if (EVEN(sts)) {
    errh_Error("gdh_NameToObjid(pwrNode-active-io-av, &oid), %m", sts);
    return;
  }

  sts = gdh_ObjidToPointer(oid, (void *) &avp);
  if (EVEN(sts)) {
    errh_Error("gdh_ObjidToPointer(oid, (void *) &avp), %m", sts);
    return;
  }

  sts = gdh_NameToObjid("pwrNode-active-io-av_init", &oid);
  if (EVEN(sts)) {
    errh_Error("gdh_NameToObjid(pwrNode-active-io-av_init, &oid), %m", sts);
    return;
  }

  sts = gdh_ObjidToPointer(oid, (void *) &iavp);
  if (EVEN(sts)) {
    errh_Error("gdh_ObjidToPointer(oid, (void *) &iavp), %m", sts);
    return;
  }

  sts = gdh_NameToObjid("pwrNode-active-io-dv", &oid);
  if (EVEN(sts)) {
    errh_Error("gdh_NameToObjid(pwrNode-active-io-dv, &oid), %m", sts);
    return;
  }

  sts = gdh_ObjidToPointer(oid, (void *) &dvp);
  if (EVEN(sts)) {
    errh_Error("gdh_ObjidToPointer(oid, (void *) &dvp), %m", sts);
    return;
  }

  sts = gdh_NameToObjid("pwrNode-active-io-dv_init", &oid);
  if (EVEN(sts)) {
    errh_Error("gdh_NameToObjid(pwrNode-active-io-dv_init, &oid), %m", sts);
    return;
  }

  sts = gdh_ObjidToPointer(oid, (void *) &idvp);
  if (EVEN(sts)) {
    errh_Error("gdh_ObjidToPointer(oid, (void *) &idvp), %m", sts);
    return;
  }

  sts = gdh_NameToObjid("pwrNode-active-io-iv", &oid);
  if (EVEN(sts)) {
    errh_Error("gdh_NameToObjid(pwrNode-active-io-iv, &oid), %m", sts);
    return;
  }

  sts = gdh_ObjidToPointer(oid, (void *) &ivp);
  if (EVEN(sts)) {
    errh_Error("gdh_ObjidToPointer(oid, (void *) &ivp), %m", sts);
    return;
  }

  sts = gdh_NameToObjid("pwrNode-active-io-iv_init", &oid);
  if (EVEN(sts)) {
    errh_Error("gdh_NameToObjid(pwrNode-active-io-iv_init, &oid), %m", sts);
    return;
  }

  sts = gdh_ObjidToPointer(oid, (void *) &iivp);
  if (EVEN(sts)) {
    errh_Error("gdh_ObjidToPointer(oid, (void *) &iivp), %m", sts);
    return;
  }

  for (i = 0; i < iop->AvCount; i++) {
    pwr_tFloat32 *ifp = gdh_TranslateRtdbPointer(iavp->Value[i]);
    avp->Value[i]= *ifp;
  }

  for (i = 0; i < iop->DvCount; i++) {
    pwr_tBoolean *ibp = gdh_TranslateRtdbPointer(idvp->Value[i]);
    dvp->Value[i] = *ibp;
  }

  for (i = 0; i < iop->IvCount; i++) {
    pwr_tInt32 *iip = gdh_TranslateRtdbPointer(iivp->Value[i]);
    ivp->Value[i] = *iip;
  }

  typedef struct {
    union {
      pwr_tFloat32 *f;
      pwr_tInt32   *i;
      pwr_tBoolean *b;
    } actval_p;
    pwr_tUInt32  validx;
    union {
      pwr_sClass_Av *av;
      pwr_sClass_Iv *iv;
      pwr_sClass_Dv *dv;
      pwr_sClass_Ai *ai;
      pwr_sClass_Ao *ao;
      pwr_sClass_Ii *ii;
      pwr_sClass_Io *io;
      pwr_sClass_Di *di;
      pwr_sClass_Do *dox;
      pwr_sClass_Co *co;
    } op;
  } ini_sRestoreSig;

  // Store ActualValue pointers
  ini_sRestoreSig *rsav = calloc( sizeof(ini_sRestoreSig), iop->AvCount);
  i = 0;
  for ( sts = gdh_GetClassListAttrRef(pwr_cClass_Av, &aref);
	ODD(sts);
	sts = gdh_GetNextAttrRef(pwr_cClass_Av, &aref, &aref)) {
    if ( i >= iop->AvCount) break;

    sts = gdh_AttrRefToPointer( &aref, (pwr_tAddress *)&rsav[i].op.av);
    if ( EVEN(sts)) {
      errh_Error("gdh_AttrRefToPointer Iv, %m", sts);
      return;
    }

    rsav[i].actval_p.f = rsav[i].op.av->ActualValue;
    rsav[i].validx = rsav[i].op.av->ValueIndex;
    i++;
  }
  
  ini_sRestoreSig *rsdv = calloc( sizeof(ini_sRestoreSig), iop->DvCount);
  i = 0;
  for ( sts = gdh_GetClassListAttrRef(pwr_cClass_Dv, &aref);
	ODD(sts);
	sts = gdh_GetNextAttrRef(pwr_cClass_Dv, &aref, &aref)) {
    if ( i >= iop->DvCount) break;

    sts = gdh_AttrRefToPointer( &aref, (pwr_tAddress *)&rsdv[i].op.dv);
    if ( EVEN(sts)) {
      errh_Error("gdh_AttrRefToPointer Iv, %m", sts);
      return;
    }

    rsdv[i].actval_p.b = rsdv[i].op.dv->ActualValue;
    rsdv[i].validx = rsdv[i].op.dv->ValueIndex;
    i++;
  }
  
  ini_sRestoreSig *rsiv = calloc( sizeof(ini_sRestoreSig), iop->IvCount);
  i = 0;
  for ( sts = gdh_GetClassListAttrRef(pwr_cClass_Iv, &aref);
	ODD(sts);
	sts = gdh_GetNextAttrRef(pwr_cClass_Iv, &aref, &aref)) {
    if ( i >= iop->IvCount) break;

    sts = gdh_AttrRefToPointer( &aref, (pwr_tAddress *)&rsiv[i].op.iv);
    if ( EVEN(sts)) {
      errh_Error("gdh_AttrRefToPointer Iv, %m", sts);
      return;
    }

    rsiv[i].actval_p.i = rsiv[i].op.iv->ActualValue;
    rsiv[i].validx = rsiv[i].op.iv->ValueIndex;
    i++;
  }
  
  ini_sRestoreSig *rsai = calloc( sizeof(ini_sRestoreSig), iop->AiCount);
  i = 0;
  for ( sts = gdh_GetClassListAttrRef(pwr_cClass_Ai, &aref);
	ODD(sts);
	sts = gdh_GetNextAttrRef(pwr_cClass_Ai, &aref, &aref)) {
    if ( i >= iop->AiCount) break;

    sts = gdh_AttrRefToPointer( &aref, (pwr_tAddress *)&rsai[i].op.ai);
    if ( EVEN(sts)) {
      errh_Error("gdh_AttrRefToPointer Iv, %m", sts);
      return;
    }

    rsai[i].actval_p.f = rsai[i].op.ai->ActualValue;
    rsai[i].validx = rsai[i].op.ai->ValueIndex;
    i++;
  }
  
  ini_sRestoreSig *rsao = calloc( sizeof(ini_sRestoreSig), iop->AoCount);
  i = 0;
  for ( sts = gdh_GetClassListAttrRef(pwr_cClass_Ao, &aref);
	ODD(sts);
	sts = gdh_GetNextAttrRef(pwr_cClass_Ao, &aref, &aref)) {
    if ( i >= iop->AoCount) break;

    sts = gdh_AttrRefToPointer( &aref, (pwr_tAddress *)&rsao[i].op.ao);
    if ( EVEN(sts)) {
      errh_Error("gdh_AttrRefToPointer Iv, %m", sts);
      return;
    }

    rsao[i].actval_p.f = rsao[i].op.ao->ActualValue;
    rsao[i].validx = rsao[i].op.ao->ValueIndex;
    i++;
  }
  
  ini_sRestoreSig *rsii = calloc( sizeof(ini_sRestoreSig), iop->IiCount);
  i = 0;
  for ( sts = gdh_GetClassListAttrRef(pwr_cClass_Ii, &aref);
	ODD(sts);
	sts = gdh_GetNextAttrRef(pwr_cClass_Ii, &aref, &aref)) {
    if ( i >= iop->IiCount) break;

    sts = gdh_AttrRefToPointer( &aref, (pwr_tAddress *)&rsii[i].op.ii);
    if ( EVEN(sts)) {
      errh_Error("gdh_AttrRefToPointer Iv, %m", sts);
      return;
    }

    rsii[i].actval_p.i = rsii[i].op.ii->ActualValue;
    rsii[i].validx = rsii[i].op.ii->ValueIndex;
    i++;
  }
  
  ini_sRestoreSig *rsio = calloc( sizeof(ini_sRestoreSig), iop->IoCount);
  i = 0;
  for ( sts = gdh_GetClassListAttrRef(pwr_cClass_Io, &aref);
	ODD(sts);
	sts = gdh_GetNextAttrRef(pwr_cClass_Io, &aref, &aref)) {
    if ( i >= iop->IoCount) break;

    sts = gdh_AttrRefToPointer( &aref, (pwr_tAddress *)&rsio[i].op.io);
    if ( EVEN(sts)) {
      errh_Error("gdh_AttrRefToPointer Iv, %m", sts);
      return;
    }

    rsio[i].actval_p.i = rsio[i].op.io->ActualValue;
    rsio[i].validx = rsio[i].op.io->ValueIndex;
    i++;
  }
  
  ini_sRestoreSig *rsdi = calloc( sizeof(ini_sRestoreSig), iop->DiCount);
  i = 0;
  for ( sts = gdh_GetClassListAttrRef(pwr_cClass_Di, &aref);
	ODD(sts);
	sts = gdh_GetNextAttrRef(pwr_cClass_Di, &aref, &aref)) {
    if ( i >= iop->DiCount) break;

    sts = gdh_AttrRefToPointer( &aref, (pwr_tAddress *)&rsdi[i].op.di);
    if ( EVEN(sts)) {
      errh_Error("gdh_AttrRefToPointer Iv, %m", sts);
      return;
    }

    rsdi[i].actval_p.b = rsdi[i].op.di->ActualValue;
    rsdi[i].validx = rsdi[i].op.di->ValueIndex;
    i++;
  }
  
  ini_sRestoreSig *rsdo = calloc( sizeof(ini_sRestoreSig), iop->DoCount);
  i = 0;
  for ( sts = gdh_GetClassListAttrRef(pwr_cClass_Do, &aref);
	ODD(sts);
	sts = gdh_GetNextAttrRef(pwr_cClass_Do, &aref, &aref)) {
    if ( i >= iop->DoCount) break;

    sts = gdh_AttrRefToPointer( &aref, (pwr_tAddress *)&rsdo[i].op.dox);
    if ( EVEN(sts)) {
      errh_Error("gdh_AttrRefToPointer Iv, %m", sts);
      return;
    }

    rsdo[i].actval_p.b = rsdo[i].op.dox->ActualValue;
    rsdo[i].validx = rsdo[i].op.dox->ValueIndex;
    i++;
  }
  
  ini_sRestoreSig *rsco = calloc( sizeof(ini_sRestoreSig), iop->CoCount);
  pwr_tInt32 **rscoa = calloc( sizeof(pwr_tInt32*), iop->CoCount);
  i = 0;
  for ( sts = gdh_GetClassListAttrRef(pwr_cClass_Co, &aref);
	ODD(sts);
	sts = gdh_GetNextAttrRef(pwr_cClass_Co, &aref, &aref)) {
    if ( i >= iop->CoCount) break;

    sts = gdh_AttrRefToPointer( &aref, (pwr_tAddress *)&rsco[i].op.co);
    if ( EVEN(sts)) {
      errh_Error("gdh_AttrRefToPointer Iv, %m", sts);
      return;
    }

    rsco[i].actval_p.i = rsco[i].op.co->RawValue;
    rsco[i].validx = rsco[i].op.co->ValueIndex;
    rscoa[i] = rsco[i].op.co->AbsValue;
    i++;
  }
  

  sts = bck_LoadBackup();
  if (EVEN(sts)) {
    errh_Error("bck_LoadBackup, %m", sts);
    return;
  }

  // Set stored ActualValue pointers
  for ( i = 0; i < iop->AvCount; i++) {
    rsav[i].op.av->ActualValue = rsav[i].actval_p.f;
    rsav[i].op.av->ValueIndex = rsav[i].validx;
  }
  free( rsav);

  for ( i = 0; i < iop->DvCount; i++) {
    rsdv[i].op.dv->ActualValue = rsdv[i].actval_p.b;
    rsdv[i].op.dv->ValueIndex = rsdv[i].validx;
  }
  free( rsdv);

  for ( i = 0; i < iop->IvCount; i++) {
    rsiv[i].op.iv->ActualValue = rsiv[i].actval_p.i;
    rsiv[i].op.iv->ValueIndex = rsiv[i].validx;
  }
  free( rsiv);

  for ( i = 0; i < iop->AiCount; i++) {
    rsai[i].op.ai->ActualValue = rsai[i].actval_p.f;
    rsai[i].op.ai->ValueIndex = rsai[i].validx;
  }
  free( rsai);

  for ( i = 0; i < iop->AoCount; i++) {
    rsao[i].op.ao->ActualValue = rsao[i].actval_p.f;
    rsao[i].op.ao->ValueIndex = rsao[i].validx;
  }
  free( rsao);

  for ( i = 0; i < iop->IiCount; i++) {
    rsii[i].op.ii->ActualValue = rsii[i].actval_p.i;
    rsii[i].op.ii->ValueIndex = rsii[i].validx;
  }
  free( rsii);

  for ( i = 0; i < iop->IoCount; i++) {
    rsio[i].op.io->ActualValue = rsio[i].actval_p.i;
    rsio[i].op.io->ValueIndex = rsio[i].validx;
  }
  free( rsio);

  for ( i = 0; i < iop->DiCount; i++) {
    rsdi[i].op.di->ActualValue = rsdi[i].actval_p.b;
    rsdi[i].op.di->ValueIndex = rsdi[i].validx;
  }
  free( rsdi);

  for ( i = 0; i < iop->DoCount; i++) {
    rsdo[i].op.dox->ActualValue = rsdo[i].actval_p.b;
    rsdo[i].op.dox->ValueIndex = rsdo[i].validx;
  }
  free( rsdo);

  for ( i = 0; i < iop->CoCount; i++) {
    rsco[i].op.co->RawValue = rsco[i].actval_p.i;
    rsco[i].op.co->AbsValue = rscoa[i];
    rsco[i].op.co->ValueIndex = rsco[i].validx;
  }
  free( rsco);
  free( rscoa);


  for (i = 0; i < iop->AvCount; i++) {
    pwr_tFloat32 *ifp = gdh_TranslateRtdbPointer(iavp->Value[i]);
    *ifp = avp->Value[i];
  }

  for (i = 0; i < iop->DvCount; i++) {
    pwr_tBoolean *ibp = gdh_TranslateRtdbPointer(idvp->Value[i]);
    *ibp = dvp->Value[i];
  }

  for (i = 0; i < iop->IvCount; i++) {
    pwr_tInt32 *iip = gdh_TranslateRtdbPointer(iivp->Value[i]);
    *iip = ivp->Value[i];
  }
}
Exemplo n.º 29
0
EvAlaGtk::EvAlaGtk( void *ev_parent_ctx,
		    GtkWidget	*ev_parent_wid,
		    char *ala_name,
		    pwr_tObjid ev_user,
		    int ev_eventname_seg,
		    int ev_width,
		    int ev_height,
		    int ev_x,
		    int ev_y,
		    pwr_tObjid ev_view,
		    unsigned int ev_options,
		    void *widget,
		    pwr_tStatus *status) :
  EvAla( ev_parent_ctx, ala_name, ev_user, ev_eventname_seg, 
	 ev_width, ev_height, ev_x, ev_y, ev_view, ev_options, status),
  parent_wid(ev_parent_wid), toplevel(0)
{
  pwr_tStatus sts;
  pwr_sClass_OpPlace *opp;
  pwr_tFileName fname;
  int ala_width = 700;
  int ala_height = 300;

  *status = 1;

  if ( ev_width != 0 && ev_height != 0) {
    ala_width = ev_width;
    ala_height = ev_height;
  }

  // Check user object
  if ( cdh_ObjidIsNull( user)) {
    *status = XNAV__NOUSER;
    return;
  }

  sts = gdh_ObjidToPointer( user, (pwr_tAddress *) &opp);
  if ( EVEN(sts)) {
    *status = XNAV__NOUSER;
    return;
  }
  ala_size = opp->MaxNoOfAlarms;
  // create_aliaslist( opp);

  // Ala Window

  if ( !(options & ev_mAlaOptions_Embedded)) {
    toplevel = (GtkWidget *) g_object_new( GTK_TYPE_WINDOW, 
						 "default-height", ala_height,
						 "default-width", ala_width,
						 "title", CoWowGtk::translate_utf8(ala_name),
						 NULL);
    parent_wid_ala = toplevel;
    g_signal_connect( parent_wid_ala, "delete_event", G_CALLBACK(ala_delete_event), this);
    g_signal_connect( parent_wid_ala, "destroy", G_CALLBACK(ala_destroy_event), this);
    g_signal_connect( parent_wid_ala, "focus-in-event", G_CALLBACK(ala_action_inputfocus), this);

    CoWowGtk::SetWindowIcon( parent_wid_ala);
  }
  else
    parent_wid_ala = (GtkWidget *)widget;

  ala_vbox = gtk_vbox_new( FALSE, 0);

  // Menu
  // Accelerators
  GtkAccelGroup *accel_g = (GtkAccelGroup *) g_object_new(GTK_TYPE_ACCEL_GROUP, NULL);
  gtk_window_add_accel_group(GTK_WINDOW(parent_wid_ala), accel_g);

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

  // File entry
  GtkWidget *file_print = gtk_image_menu_item_new_with_mnemonic(CoWowGtk::translate_utf8("_Print"));
  gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM(file_print), 
				 gtk_image_new_from_stock( "gtk-print", GTK_ICON_SIZE_MENU));
  g_signal_connect(file_print, "activate", G_CALLBACK(ala_activate_print), this);

  GtkWidget *file_close = gtk_image_menu_item_new_with_mnemonic( CoWowGtk::translate_utf8("_Close"));
  gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM(file_close), 
				 gtk_image_new_from_stock( "gtk-close", GTK_ICON_SIZE_MENU));
  g_signal_connect(file_close, "activate", G_CALLBACK(ala_activate_exit), this);
  gtk_widget_add_accelerator( file_close, "activate", accel_g,
			      'w', GdkModifierType(GDK_CONTROL_MASK), GTK_ACCEL_VISIBLE);

  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_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_ack_last = gtk_menu_item_new_with_mnemonic( 
								  CoWowGtk::translate_utf8("_Acknowledge"));
  g_signal_connect( functions_ack_last, "activate", 
		    G_CALLBACK(ala_activate_ack_last), this);
  gtk_widget_add_accelerator( functions_ack_last, "activate", accel_g,
			      'k', GdkModifierType(GDK_CONTROL_MASK), 
			      GTK_ACCEL_VISIBLE);

  GtkWidget *functions_ack_all = gtk_menu_item_new_with_mnemonic( 
								 CoWowGtk::translate_utf8("A_cknowledge All"));
  g_signal_connect( functions_ack_all, "activate", 
		    G_CALLBACK(ala_activate_ack_all), this);

  GtkWidget *functions_open_plc = gtk_menu_item_new_with_mnemonic( 
								  CoWowGtk::translate_utf8("Open _Program"));
  g_signal_connect( functions_open_plc, "activate", 
		    G_CALLBACK(ala_activate_open_plc), this);
  gtk_widget_add_accelerator( functions_open_plc, "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(ala_activate_display_in_xnav), this);
  gtk_widget_add_accelerator( functions_display_object, "activate", accel_g,
			      'd', GdkModifierType(GDK_CONTROL_MASK), 
			      GTK_ACCEL_VISIBLE);

  GtkMenu *func_menu = (GtkMenu *) g_object_new( GTK_TYPE_MENU, NULL);
  gtk_menu_shell_append(GTK_MENU_SHELL(func_menu), functions_ack_last);
  gtk_menu_shell_append(GTK_MENU_SHELL(func_menu), functions_ack_all);
  gtk_menu_shell_append(GTK_MENU_SHELL(func_menu), functions_open_plc);
  gtk_menu_shell_append(GTK_MENU_SHELL(func_menu), functions_display_object);

  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(func_menu));

  // View entry
  GtkWidget *view_shift_view = gtk_image_menu_item_new_with_mnemonic(CoWowGtk::translate_utf8("S_hift View"));
  g_signal_connect( view_shift_view, "activate", 
		    G_CALLBACK(ala_activate_shift_view), this);
  gtk_widget_add_accelerator( view_shift_view, "activate", accel_g,
			      'n', GdkModifierType(GDK_CONTROL_MASK), 
			      GTK_ACCEL_VISIBLE);

  GtkWidget *view_zoom_in = gtk_image_menu_item_new_with_mnemonic(CoWowGtk::translate_utf8("Zoom _In"));
  gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM(view_zoom_in), 
				 gtk_image_new_from_stock( "gtk-zoom-in", GTK_ICON_SIZE_MENU));
  g_signal_connect( view_zoom_in, "activate", 
		    G_CALLBACK(ala_activate_zoom_in), 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_with_mnemonic(CoWowGtk::translate_utf8("Zoom _Out"));
  gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM(view_zoom_out), 
				 gtk_image_new_from_stock( "gtk-zoom-out", GTK_ICON_SIZE_MENU));
  g_signal_connect( view_zoom_out, "activate", 
		    G_CALLBACK(ala_activate_zoom_out), 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_with_mnemonic(CoWowGtk::translate_utf8("Zoom _Reset"));
  gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM(view_zoom_reset), 
				 gtk_image_new_from_stock( "gtk-zoom-100", GTK_ICON_SIZE_MENU));
  g_signal_connect( view_zoom_reset, "activate", 
		    G_CALLBACK(ala_activate_zoom_reset), this);
  gtk_widget_add_accelerator( view_zoom_reset, "activate", accel_g,
			      'b', GdkModifierType(GDK_CONTROL_MASK), 
			      GTK_ACCEL_VISIBLE);

  GtkWidget *view_disp_hundredth = gtk_check_menu_item_new_with_mnemonic( 
									 CoWowGtk::translate_utf8("_Display hundredth"));
  g_signal_connect( view_disp_hundredth, "activate", 
		    G_CALLBACK(ala_activate_disp_hundredth), this);

  GtkWidget *view_hide_object = gtk_check_menu_item_new_with_mnemonic( 
								      CoWowGtk::translate_utf8("_Hide Event Name"));
  g_signal_connect( view_hide_object, "activate", 
		    G_CALLBACK(ala_activate_hide_object), this);

  GtkWidget *view_hide_text = gtk_check_menu_item_new_with_mnemonic( 
								    CoWowGtk::translate_utf8("Hide _Event Text"));
  g_signal_connect( view_hide_text, "activate", 
		    G_CALLBACK(ala_activate_hide_text), this);

  // Submenu Select View
  GtkWidget *view_select_flat = gtk_menu_item_new_with_mnemonic( "_Flat");
  g_signal_connect( view_select_flat, "activate", 
		    G_CALLBACK(ala_activate_select_flat), this);


  GtkWidget *view_select = gtk_menu_item_new_with_mnemonic( "_Select View");
  GtkMenu *view_select_menu = (GtkMenu *) g_object_new( GTK_TYPE_MENU, NULL);
  gtk_menu_shell_append(GTK_MENU_SHELL(view_select_menu), view_select_flat);

  for ( unsigned int i = 0; i < sizeof(opp->AlarmViews)/sizeof(opp->AlarmViews[0]); i++) {
    pwr_sClass_AlarmView *viewp;

    if ( cdh_ObjidIsNull( opp->AlarmViews[i]))
      break;
      
    sts = gdh_ObjidToPointer( opp->AlarmViews[i], (void **)&viewp);
    if ( ODD(sts)) {
      alarm_views[i] = opp->AlarmViews[i];
      GtkWidget *view_select_view = gtk_menu_item_new_with_mnemonic( CoWowGtk::translate_utf8(viewp->Name));
      switch ( i) {
      case 0: g_signal_connect( view_select_view, "activate", G_CALLBACK(ala_activate_select_view1), this); break;
      case 1: g_signal_connect( view_select_view, "activate", G_CALLBACK(ala_activate_select_view2), this); break;
      case 2: g_signal_connect( view_select_view, "activate", G_CALLBACK(ala_activate_select_view3), this); break;
      case 3: g_signal_connect( view_select_view, "activate", G_CALLBACK(ala_activate_select_view4), this); break;
      case 4: g_signal_connect( view_select_view, "activate", G_CALLBACK(ala_activate_select_view5), this); break;
      case 5: g_signal_connect( view_select_view, "activate", G_CALLBACK(ala_activate_select_view6), this); break;
      case 6: g_signal_connect( view_select_view, "activate", G_CALLBACK(ala_activate_select_view7), this); break;
      case 7: g_signal_connect( view_select_view, "activate", G_CALLBACK(ala_activate_select_view8), this); break;
      case 8: g_signal_connect( view_select_view, "activate", G_CALLBACK(ala_activate_select_view9), this); break;
      case 9: g_signal_connect( view_select_view, "activate", G_CALLBACK(ala_activate_select_view10), this); break;
      case 10: g_signal_connect( view_select_view, "activate", G_CALLBACK(ala_activate_select_view11), this); break;
      case 11: g_signal_connect( view_select_view, "activate", G_CALLBACK(ala_activate_select_view12), this); break;
      case 12: g_signal_connect( view_select_view, "activate", G_CALLBACK(ala_activate_select_view13), this); break;
      case 13: g_signal_connect( view_select_view, "activate", G_CALLBACK(ala_activate_select_view14), this); break;
      case 14: g_signal_connect( view_select_view, "activate", G_CALLBACK(ala_activate_select_view15), this); break;
      case 15: g_signal_connect( view_select_view, "activate", G_CALLBACK(ala_activate_select_view16), this); break;
      case 16: g_signal_connect( view_select_view, "activate", G_CALLBACK(ala_activate_select_view17), this); break;
      case 17: g_signal_connect( view_select_view, "activate", G_CALLBACK(ala_activate_select_view18), this); break;
      case 18: g_signal_connect( view_select_view, "activate", G_CALLBACK(ala_activate_select_view19), this); break;
      case 19: g_signal_connect( view_select_view, "activate", G_CALLBACK(ala_activate_select_view20), this); break;
      case 20: g_signal_connect( view_select_view, "activate", G_CALLBACK(ala_activate_select_view21), this); break;
      case 21: g_signal_connect( view_select_view, "activate", G_CALLBACK(ala_activate_select_view22), this); break;
      case 22: g_signal_connect( view_select_view, "activate", G_CALLBACK(ala_activate_select_view23), this); break;
      case 23: g_signal_connect( view_select_view, "activate", G_CALLBACK(ala_activate_select_view24), this); break;
      case 24: g_signal_connect( view_select_view, "activate", G_CALLBACK(ala_activate_select_view25), this); break;
      }
      gtk_menu_shell_append(GTK_MENU_SHELL(view_select_menu), view_select_view);
    }
  }

    gtk_menu_item_set_submenu(GTK_MENU_ITEM(view_select),
			      GTK_WIDGET(view_select_menu));

    GtkMenu *view_menu = (GtkMenu *) g_object_new( GTK_TYPE_MENU, NULL);
    gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), view_shift_view);
    gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), view_select);
    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_disp_hundredth);
    gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), view_hide_object);
    gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), view_hide_text);

    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));

    // Help entry
    GtkWidget *help_help = gtk_image_menu_item_new_with_mnemonic( 
                              CoWowGtk::translate_utf8("_Help"));
    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(ala_activate_help), this);
    gtk_widget_add_accelerator( help_help, "activate", accel_g,
				'h', GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);

    GtkWidget *help_helpevent = gtk_menu_item_new_with_mnemonic( 
                                         CoWowGtk::translate_utf8("Help Selected Event"));
    g_signal_connect( help_helpevent, "activate", 
		      G_CALLBACK(ala_activate_helpevent), 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_helpevent);

    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));

    // Create ala evlist
    ala = new EvListGtk( this, ala_vbox, ev_eType_AlarmList, ala_size, eventname_seg, 
			 &ala_widget, ala_init_cb);
    ala->start_trace_cb = &ala_start_trace_cb;
    ala->display_in_xnav_cb =&ala_display_in_xnav_cb;
    ala->name_to_alias_cb = &ala_name_to_alias_cb;
    ala->popup_menu_cb = &ala_popup_menu_cb;
    ala->sound_cb = &ala_sound_cb;
    ala->help_event_cb = &help_event_cb;
    ala->selection_changed_cb = &ala_selection_changed_cb;
  
    // Toolbar
    GtkToolbar *tools = (GtkToolbar *) g_object_new(GTK_TYPE_TOOLBAR, NULL);

    GtkWidget *tools_ack = gtk_button_new();
    dcli_translate_filename( fname, "$pwr_exe/xtt_acknowledge.png");
    gtk_container_add( GTK_CONTAINER( tools_ack), gtk_image_new_from_file( fname));
    g_signal_connect(tools_ack, "clicked", G_CALLBACK(ala_activate_ack_last), this);
    g_object_set( tools_ack, "can-focus", FALSE, NULL);
    gtk_toolbar_append_widget( tools, tools_ack, CoWowGtk::translate_utf8("Acknowledge"), "");
    
    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(ala_activate_zoom_in), this);
    g_object_set( tools_zoom_in, "can-focus", FALSE, NULL);
    gtk_toolbar_append_widget( tools, tools_zoom_in,CoWowGtk::translate_utf8("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(ala_activate_zoom_out), this);
    g_object_set( tools_zoom_out, "can-focus", FALSE, NULL);
    gtk_toolbar_append_widget( tools, tools_zoom_out,CoWowGtk::translate_utf8("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(ala_activate_zoom_reset), this);
    g_object_set( tools_zoom_reset, "can-focus", FALSE, NULL);
    gtk_toolbar_append_widget( tools, tools_zoom_reset,CoWowGtk::translate_utf8("Zoom reset"), "");
    
    ala_methodtoolbar = new XttMethodToolbarGtk(0, 0, ~0, "");
    GtkToolbar *tools_meth = (GtkToolbar *) ((XttMethodToolbarGtk *)ala_methodtoolbar)->build();

    ala_methodtoolbar->m_xnav = (XNav *)((Ev *)parent_ctx)->parent_ctx;
    ala_methodtoolbar->m_parent_ctx = ala;
    ala_methodtoolbar->get_select_cb = ala->get_select;

    ala_sup_methodtoolbar = new XttMethodToolbarGtk(0, 0, mt_mMethod_OpenPlc | mt_mMethod_RtNavigator, 
						    " for supervisory object");
    GtkToolbar *tools_sup = (GtkToolbar *) ((XttMethodToolbarGtk *)ala_sup_methodtoolbar)->build();
    ala_sup_methodtoolbar->m_xnav = (XNav *)((Ev *)parent_ctx)->parent_ctx;
    ala_sup_methodtoolbar->m_parent_ctx = ala;
    ala_sup_methodtoolbar->get_select_cb = ala->get_select_supobject;

    GtkWidget *ala_toolsbox = gtk_hbox_new( FALSE, 0);
    gtk_box_pack_start( GTK_BOX(ala_toolsbox), GTK_WIDGET(tools), FALSE, FALSE, 0);
    gtk_box_pack_start( GTK_BOX(ala_toolsbox), GTK_WIDGET(gtk_separator_tool_item_new()), FALSE, FALSE, 4);
    gtk_box_pack_start( GTK_BOX(ala_toolsbox), GTK_WIDGET(tools_sup), FALSE, FALSE, 0);
    gtk_box_pack_start( GTK_BOX(ala_toolsbox), GTK_WIDGET(gtk_separator_tool_item_new()), FALSE, FALSE, 4);
    gtk_box_pack_start( GTK_BOX(ala_toolsbox), GTK_WIDGET(tools_meth), FALSE, FALSE, 0);

    gtk_box_pack_start( GTK_BOX(ala_vbox), GTK_WIDGET(menu_bar), FALSE, FALSE, 0);
    gtk_box_pack_start( GTK_BOX(ala_vbox), GTK_WIDGET(ala_toolsbox), FALSE, FALSE, 0);
    gtk_box_pack_end( GTK_BOX(ala_vbox), GTK_WIDGET(ala_widget), TRUE, TRUE, 0);

    if ( !(options & ev_mAlaOptions_Embedded)) {
      gtk_container_add( GTK_CONTAINER(parent_wid_ala), ala_vbox);
    }
    // gtk_widget_show_all( parent_wid_ala);

    ala_methodtoolbar->set_sensitive();
    ala_sup_methodtoolbar->set_sensitive();
    // }


  if ( !(options & ev_mAlaOptions_Embedded)) {
    gtk_widget_show_all( parent_wid_ala);
    if ( !(x == 0 && y == 0)) {
      // Set position
      gtk_window_move( GTK_WINDOW(parent_wid_ala), x, y);
    }
  }
  else
    gtk_widget_set_size_request( ala_vbox, ala_width, ala_height);

  ala_displayed = 1;


  wow = new CoWowGtk( parent_wid_ala);

  *status = 1;
}
Exemplo n.º 30
0
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;    
  }
}