/*----------------------------------------------------------------------------*\ Init method for the Pb module Ao \*----------------------------------------------------------------------------*/ static pwr_tStatus IoCardInit ( io_tCtx ctx, io_sAgent *ap, io_sRack *rp, io_sCard *cp ) { io_sCardLocal *local; pwr_sClass_Pb_Ao *op; io_sChannel *chanp; int i; op = (pwr_sClass_Pb_Ao *) cp->op; local = (io_sCardLocal *) cp->Local; if (rp->Class != pwr_cClass_Pb_DP_Slave) { errh_Info( "Illegal object type %s", cp->Name ); return IO__SUCCESS; } if (op->Status >= PB_MODULE_STATE_OPERATE) { // Calculate polycoeff for (i=0; i<cp->ChanListSize; i++) { chanp = &cp->chanlist[i]; if (!chanp->cop) continue; io_AoRangeToCoef(chanp); } } else errh_Info( "Error initializing Pb module Ao %s", cp->Name ); return IO__SUCCESS; }
void sancm_Update ( qcom_sGet *get ) { gdb_sObject *op; int i; int error; net_sSanUpdate *up = get->data; gdb_AssumeUnlocked; gdb_ScopeLock { error = 0; if (0) errh_Info("sancm_Update, recieved %d", up->count); for (i = 0; i < up->count; i++) { op = hash_Search(NULL, gdbroot->oid_ht, &up->data[i].sane.oid); if (op == NULL || cdh_RefIdIsNotEqual(op->u.c.sanid, up->data[i].sane.sid)) { error++; continue; } up->data[i].sane.sid.rix = 0; /* Sid is ok! */ vol_UpdateAlarm(NULL, op, up->data[i].al); } /* Send remove for errors. */ if (error > 0) { net_sSanRemove *rp; int size = sizeof(net_sSanRemove) + (error - 1) * sizeof(rp->sid[0]); int i; gdb_sNode *np = hash_Search(NULL, gdbroot->nid_ht, &up->hdr.nid); qcom_sQid tgt; tgt.nid = np->nid; tgt.qix = net_cProcHandler; rp = calloc(1, size); if (rp != NULL) { rp->count = error; for (i = 0; i < up->count; i++) { if (up->data[i].sane.sid.rix == 0) continue; rp->sid[--error] = up->data[i].sane.sid; } gdb_Unlock; errh_Info("sancm_Update, sent removed count %d", rp->count); net_Put(NULL, &tgt, rp, net_eMsg_sanRemove, 0, size, 0); gdb_Lock; free(rp); } } } gdb_ScopeUnlock; }
static pwr_tStatus IoRackInit( io_tCtx ctx, io_sAgent *ap, io_sRack *rp) { io_sLocalUSB *local; int status; int i; unsigned int snum; int found; io_sCard *cp; pwr_sClass_MotionControl_USB *op = (pwr_sClass_MotionControl_USB *)rp->op; local = (io_sLocalUSB *) calloc( 1, sizeof(io_sLocalUSB)); rp->Local = local; for ( i = 0; i < (int)sizeof(local->USB_Handle); i++) { status = USBIO_Open( &local->USB_Handle[i]); if ( status) { if ( i == 0) op->Status = status; break; } /* Check is this card is configured */ status = USBIO_GetSerialNr( &local->USB_Handle[i], &snum); if ( !status) { found = 0; for ( cp = rp->cardlist; cp; cp = cp->next) { if ( ((pwr_sClass_MotionControl_USBIO *)cp->op)->Super.Address == snum) { local->snum[i] = snum; found = 1; break; } } if ( !found) { errh_Info( "USBIO Serial number %d not configured", snum); op->Status = USBIO_Close( &local->USB_Handle[i]); i--; continue; } } else errh_Error( "USBIO Serial number error '%s'", rp->Name); } errh_Info( "Init of USBIO rack '%s'", rp->Name); return IO__SUCCESS; }
/*----------------------------------------------------------------------------*\ Init method for the Pb module Di \*----------------------------------------------------------------------------*/ static pwr_tStatus IoCardInit ( io_tCtx ctx, io_sAgent *ap, io_sRack *rp, io_sCard *cp ) { io_sCardLocal *local; pwr_sClass_Pb_Di *op; op = (pwr_sClass_Pb_Di *) cp->op; local = (io_sCardLocal *) cp->Local; // Check configuration if (op->NumberOfChannels != 8 && op->NumberOfChannels != 16 && op->NumberOfChannels != 32) op->Status = PB_MODULE_STATE_NOTINIT; if (op->Orientation > op->NumberOfChannels) op->Status = PB_MODULE_STATE_NOTINIT; if (op->Status < PB_MODULE_STATE_OPERATE) errh_Info( "Error initializing Pb module Di %s", cp->Name ); return IO__SUCCESS; }
/**************************************************************************** * Name: exit_hdlr() * * Type void * * Type Parameter IOGF Description * * Description: * Called at exit * **************************************************************************/ void exit_hdlr() { gdh_DLUnrefObjectInfoAll(); errh_Info("Exiting\n"); return; }
static pwr_tStatus init_nodes () { pwr_tStatus sts; LstLink(sNode) *nl; sNode *np; pwr_tObjid oid; nl = LstEnd(&node_l); for ( sts = gdh_GetClassList(pwr_cClass_NodeLinkSup, &oid); ODD(sts); sts = gdh_GetNextObject(oid, &oid) ) { np = init_node(oid, NULL, 1); if (np != NULL) { nl = LstIns(nl, np, node_l); } } if (LstEmp(&node_l)) errh_Info("No NodeLink objects"); return(sts); }
static pwr_tStatus IoAgentInit( io_tCtx ctx, io_sAgent *ap) { io_sLocalUSB_Agent *local; int sts; pwr_sClass_USB_Agent *op = (pwr_sClass_USB_Agent *)ap->op; local = (io_sLocalUSB_Agent *) calloc( 1, sizeof(io_sLocalUSB_Agent)); ap->Local = local; sts = libusb_init( &local->libusb_ctx); if ( sts != 0) { if ( sts == io_cLibDummy) op->Status = IO__DUMMYBUILD; else op->Status = IO__INITFAIL; errh_Error( "Init of USB agent failed '%s', error status %d", ap->Name, sts); local->libusb_ctx = 0; return op->Status; } else { op->Status = IO__SUCCESS; errh_Info( "Init of USBIO agent '%s'", ap->Name); } return IO__SUCCESS; }
pwr_tStatus proc_Start ( proc_sProcess *p ) { pwr_tStatus sts = PROC__SUCCESS; char **argv; p->pid = fork(); if (p->pid) { if (p->pid == -1) { errh_Error("Could not start %s, %m\nfile: %s", p->name, errno_GetStatus(), p->file); } else { errh_Info("Started %s, prio: %d, pid: %d\nfile: %s", p->name, p->p_prio, (int)p->pid, p->file); } } else { sts = proc_SetPriority(p->p_prio); if (EVEN(sts)) errh_Warning("%s: error setprio, %m\nfile: %s", p->name, sts, p->file); argv = co_StrToArgv(p->file, p->arg); execvp(p->file, argv); errh_Error("%s: error execvp, %m\nfile: %s", p->name, errno_GetStatus(), p->file); exit(EXIT_FAILURE); } return sts; }
static pwr_tStatus IoCardInit ( io_tCtx ctx, io_sAgent *ap, io_sRack *rp, io_sCard *cp ) { pwr_sClass_Ai_AI32uP *op; io_sLocal *local; int i; io_sChannel *chanp; op = (pwr_sClass_Ai_AI32uP *) 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 ai card '%s'", cp->Name); /* Caluclate polycoeff */ chanp = cp->chanlist; for ( i = 0; i < cp->ChanListSize; i++) { AiRangeToCoef( chanp); chanp++; } return 1; }
static void cacheTrim ( sTimer *tp ) { static time_tClock cycle; static pwr_tBoolean first = 1; if (first) { #ifdef OS_LINUX cycle = 1 * sysconf(_SC_CLK_TCK); #else cycle = 1 * CLK_TCK; #endif setInterval(&cycle, gdbroot->db->cache_trim_int); first = 0; } if (gdbroot->db->log.b.tmon) errh_Info("cacheTrim: %u", tp->clock); cvolcm_TrimOld(); cvol_Qtrim(&gdbroot->db->cacheNew); setTimer(tp, cycle); insertTimer(tp); }
static pwr_tStatus IoCardInit ( io_tCtx ctx, io_sAgent *ap, io_sRack *rp, io_sCard *cp ) { pwr_sClass_Ssab_BaseACard *op; io_sLocal *local; int i; io_sChannel *chanp; op = (pwr_sClass_Ssab_BaseACard *) 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 ai card '%s'", cp->Name); /* Caluclate polycoeff */ chanp = cp->chanlist; for ( i = 0; i < cp->ChanListSize; i++) { if ( chanp->sop) AiRangeToCoef( chanp); chanp++; } local->ErrReset = 1.0 / ctx->ScanTime + 0.5; if ( local->ErrReset < 2) local->ErrReset = 2; return 1; }
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; }
static void subbCheck ( sTimer *tp ) { sub_sBuffer *bp = (sub_sBuffer *)tp->data; if (gdbroot->db->log.b.tmon) errh_Info("subbCheck: %u", tp->clock); #if 0 if (EXCL_ON) { /* Exclusive mode is on, requeue the buffer for later transmission */ addTime(nowTime(&tp->time), msToTime(NULL, bp->dt)); insertTimer(tp); } #endif if (subsm_SendBuffer(bp)) { setTimer(tp, msToClock(NULL, bp->dt)); insertTimer(tp); } else { freeTimer(tp); } }
static pwr_tStatus IoCardInit ( io_tCtx ctx, io_sAgent *ap, io_sRack *rp, io_sCard *cp ) { pwr_sClass_Ssab_BaseDiCard *op; io_sLocal *local; int i, j; op = (pwr_sClass_Ssab_BaseDiCard *) cp->op; local = calloc( 1, sizeof(*local)); cp->Local = local; errh_Info( "Init of di card '%s'", cp->Name); local->Address[0] = op->RegAddress; local->Address[1] = op->RegAddress + 2; local->Qbus_fp = ((io_sRackLocal *)(rp->Local))->Qbus_fp; /* Init filter */ for ( i = 0; i < 2; i++) { /* The filter handles one 16-bit word */ for ( j = 0; j < 16; j++) local->Filter[i].sop[j] = cp->chanlist[i*16+j].sop; io_InitDiFilter( local->Filter[i].sop, &local->Filter[i].Found, local->Filter[i].Data, ctx->ScanTime); } return 1; }
static pwr_tStatus IoCardInit( io_tCtx ctx, io_sAgent* ap, io_sRack* rp, io_sCard* cp) { pwr_sClass_Ssab_BaseDoCard* op; io_sLocal* local; int i, j; op = (pwr_sClass_Ssab_BaseDoCard*)cp->op; local = calloc(1, sizeof(*local)); cp->Local = local; errh_Info("Init of do card '%s'", cp->Name); local->Address[0] = op->RegAddress; local->Address[1] = op->RegAddress + 2; local->Qbus_fp = ((io_sRackLocal*)(rp->Local))->Qbus_fp; local->FirstScan = 1; /* Init filter for Po signals */ for (i = 0; i < 2; i++) { /* The filter handles one 16-bit word */ for (j = 0; j < 16; j++) { if (cp->chanlist[i * 16 + j].SigClass == pwr_cClass_Po) local->Filter[i].sop[j] = cp->chanlist[i * 16 + j].sop; } io_InitPoFilter(local->Filter[i].sop, &local->Filter[i].Found, local->Filter[i].Data, ctx->ScanTime); } local->ErrReset = 1.0 / ctx->ScanTime + 0.5; if (local->ErrReset < 2) local->ErrReset = 2; return 1; }
/*----------------------------------------------------------------------------*\ Init method for the Pb module \*----------------------------------------------------------------------------*/ static pwr_tStatus IoCardInit( io_tCtx ctx, io_sAgent* ap, io_sRack* rp, io_sCard* cp) { io_sFDLCardLocal* local; pwr_sClass_Pb_FDL_DataTransfer* op = (pwr_sClass_Pb_FDL_DataTransfer*)cp->op; unsigned int input_area_offset = 0; unsigned int input_area_chansize = 0; unsigned int output_area_offset = 0; unsigned int output_area_chansize = 0; local = (io_sFDLCardLocal*)calloc(1, sizeof(io_sFDLCardLocal)); cp->Local = local; /* Initialize remote address structure */ local->byte_ordering = ((pwr_sClass_Pb_FDL_SAP*)rp->op)->ByteOrdering; io_bus_card_init(ctx, cp, &input_area_offset, &input_area_chansize, &output_area_offset, &output_area_chansize, local->byte_ordering, io_eAlignment_Packed); local->input_area_size = input_area_offset + input_area_chansize; local->output_area_size = output_area_offset + output_area_chansize; if (local->input_area_size > 0) local->input_area = calloc(1, local->input_area_size); if (local->output_area_size > 0) local->output_area = calloc(1, local->output_area_size); errh_Info("Init of Profibus FDL Data transfer '%s'", cp->Name); op->Status = PB__NORMAL; return IO__SUCCESS; }
/*----------------------------------------------------------------------------*\ \*----------------------------------------------------------------------------*/ static pwr_tStatus IoCardClose ( io_tCtx ctx, io_sAgent *ap, io_sRack *rp, io_sCard *cp ) { io_sLocal *local; int i; pwr_sClass_Di_DIX2 *op = (pwr_sClass_Di_DIX2 *) cp->op; int words = op->MaxNoOfChannels <= 16 ? 1 : 2; local = (io_sLocal *) cp->Local; errh_Info( "IO closing di card '%s'", cp->Name); /* Free filter data */ for ( i = 0; i < words; i++) { if ( local->Filter[i].Found) io_CloseDiFilter( local->Filter[i].Data); } free( (char *) local); return 1; }
void ini_ProcWait ( pwr_tStatus *status, ini_sContext *cp ) { lst_sEntry *pl; ini_sProc *pp; pid_t pid; pid_t last_pid = 1; qcom_sGet get; int tmo = 1000; pwr_dStatus(sts, status, INI__SUCCESS); #if defined OS_LYNX || defined OS_LINUX for (;;) { int status; get.data = NULL; qcom_Get(sts, &cp->eventQ, &get, tmo); if (*sts == QCOM__TMO || *sts == QCOM__QEMPTY) { errh_Info("Timeout"); } else if (get.data == NULL) { errh_Info("Nulldata"); } else { errh_Info("%d %s", get.size, get.data); qcom_Free(NULL, get.data); } if (lst_Succ(NULL, &cp->proc_lh, &pl) == NULL) break; pid = waitpid(-1, &status, WNOHANG|WUNTRACED); if (pid == 0) continue; if (pid == last_pid) break; for (pp = lst_Succ(NULL, &cp->proc_lh, &pl); pp != NULL; pp = lst_Succ(NULL, pl, &pl)) { if (pp->proc.pid == pid) { errh_Info("Process %s exited with status %d", pp->proc.name, status); break; } } } #else sleep(100000); #endif errh_Info("Ich sterbe!!"); }
static pwr_tStatus IoAgentInit ( io_tCtx ctx, io_sAgent *ap ) { errh_Info( "Init of IO agent %s", ap->Name ); return 1; }
/*_* @aref cyclesup CycleSup */ lst_sEntry * csup_Init ( pwr_tStatus *status, pwr_tObjid tid, float scanTime ) { lst_sEntry *lh; pwr_tObjid cid; pwr_tObjid pid; csup_sObject *cp; int tv_sec; pwr_tFloat32 max_delay; pwr_dStatus(sts, status, CSUP__SUCCESS); lh = calloc(1, sizeof(*lh)); if (lh == NULL) pwr_Return(NULL, sts, CSUP__INSVIRMEM); lst_Init(NULL, lh, NULL); for ( *sts = gdh_GetClassList(pwr_cClass_CycleSup, &cid); ODD(*sts); *sts = gdh_GetNextObject(cid, &cid) ) { cp = calloc(1, sizeof(*cp)); cp->aref.Objid = cid; *sts = gdh_DLRefObjectInfoAttrref(&cp->aref, (void**)&cp->o, &cp->dlid); if (EVEN(*sts)) goto error; if ( ODD(gdh_GetParent( cid, &pid)) && cdh_ObjidIsEqual( pid, tid)) cp->is_owner = 1; lst_InsertSucc(NULL, lh, &cp->le, cp); max_delay = cp->o->MaxDelay; cp->o->DelayLimit.tv_sec = tv_sec = (int)max_delay; cp->o->DelayLimit.tv_nsec = (int)((max_delay - (float)tv_sec + FLT_EPSILON) * 1.0e9); // printf("maxdelay: %f, tv_sec: %d, tv_nsec: %d\n", cp->o->MaxDelay, cp->o->DelayLimit.tv_sec, cp->o->DelayLimit.tv_nsec); errh_Info("maxdelay: %f, tv_sec: %d, tv_nsec: %d", cp->o->MaxDelay, cp->o->DelayLimit.tv_sec, cp->o->DelayLimit.tv_nsec); } if (lst_IsEmpty(NULL, lh)) goto error; return lh; error: csup_Exit(NULL, lh); return NULL; }
/*----------------------------------------------------------------------------*\ Init method for the Pb module Ai \*----------------------------------------------------------------------------*/ static pwr_tStatus IoCardInit ( io_tCtx ctx, io_sAgent *ap, io_sRack *rp, io_sCard *cp ) { io_sCardLocal *local; pwr_sClass_Pb_Ai *op; int i; io_sChannel *chanp; pwr_sClass_Pb_DP_Slave *slave; op = (pwr_sClass_Pb_Ai *) cp->op; local = (io_sCardLocal *) cp->Local; local->byte_swap = 0; if (rp->Class == pwr_cClass_Pb_DP_Slave) { slave = (pwr_sClass_Pb_DP_Slave *) rp->op; /* Little endian, no problem */ if (slave->ByteOrdering == 0) local->byte_swap = 0; /* Big endian, digitala moduler byteorienterade => swappa */ if (slave->ByteOrdering == 1) local->byte_swap = 1; /* Big endian, digitala moduler wordorienterade => swappa */ if (slave->ByteOrdering == 2) local->byte_swap = 1; } else { /* Old style */ if (rp->Class == pwr_cClass_Pb_ET200M) local->byte_swap = 1; if (rp->Class == pwr_cClass_Pb_NPBA12) local->byte_swap = 1; if (rp->Class == pwr_cClass_Pb_Euro2500) local->byte_swap = 1; } if (op->Status >= 1) { // errh_Info( "Init of Pb module Ai %s", cp->Name ); for (i=0; i<IO_MAXCHAN; i++) { local->scancount[i] = 0; } // Calculate polycoeff for (i=0; i<cp->ChanListSize; i++) { chanp = &cp->chanlist[i]; if (!chanp->cop) continue; io_AiRangeToCoef(chanp); } } else errh_Info( "Error initializing Pb module Ai %s", cp->Name ); return 1; }
JNIEXPORT void JNICALL Java_jpwr_rt_Errh_info (JNIEnv *env, jobject object, jstring jmsg) { char *cstr; const char *msg; msg = (*env)->GetStringUTFChars( env, jmsg, 0); cstr = (char *)msg; errh_Info( cstr); (*env)->ReleaseStringUTFChars( env, jmsg, cstr); }
static pwr_tStatus IoAgentInit ( io_tCtx ctx, io_sAgent *ap ) { io_sRack *rp; errh_Info( "Init of agent RTP DIOC %s", ap->Name ); io_dioc_init(); return 1; }
static pwr_tStatus IoAgentClose ( io_tCtx ctx, io_sAgent *ap ) { io_sRack *rp; errh_Info( "Closing agent RTP DIOC %s", ap->Name ); io_dioc_terminated(); return 1; }
static void lockMountServers ( gdb_sNode *np ) { pwr_tStatus sts; pool_sQlink *msl; pool_sQlink *vl; gdb_sVolume *vp; gdb_sMountServer *msp; gdb_sObject *op; gdb_AssumeLocked; for ( vl = pool_Qsucc(NULL, gdbroot->pool, &np->own_lh); vl != &np->own_lh; vl = pool_Qsucc(NULL, gdbroot->pool, vl) ) { vp = pool_Qitem(vl, gdb_sVolume, l.own_ll); if(!vp->l.flags.b.isConnected) { /* !!! Todo !!! How do we make this known ? */ errh_Error("Volume not connected, %s", vp->g.name); continue; } for ( msl = pool_Qsucc(NULL, gdbroot->pool, &vp->l.volms_lh); msl != &vp->l.volms_lh; msl = pool_Qsucc(NULL, gdbroot->pool, msl) ) { msp = pool_Qitem(msl, gdb_sMountServer, volms_ll); op = hash_Search(&sts, gdbroot->oid_ht, &msp->oid); if (op == NULL) { op = cvolc_OidToObject(&sts, vp, msp->oid, vol_mTrans_none, cvol_eHint_none); if (op == NULL) { errh_Error("Can't fetch the mount server's object, %s", cdh_ObjidToString(NULL, msp->oid, 1)); /* !!! Todo !!! How do we make this error known ? */ continue; } } msp->msor = pool_ItemReference(NULL, gdbroot->pool, op); op->l.flags.b.isMountServer = 1; pool_QinsertPred(NULL, gdbroot->pool, &msp->nodms_ll, &np->nodms_lh); if (0) errh_Info("Locking object %s", op->g.f.name.orig); cvolc_LockObject(&sts, op); } } }
static pwr_tStatus IoCardInit ( io_tCtx ctx, io_sAgent *ap, io_sRack *rp, io_sCard *cp ) { pwr_tStatus sts; io_sLocal *local; int i, j; pwr_sClass_Co_7435_33 *op; /* Rtp 12/16 bit single counter */ pwr_sClass_Co_7437_33 *op_7437; /* RTP 4 x16 bit counter crad */ op = (pwr_sClass_Co_7435_33 *) cp->op; local = calloc( 1, sizeof(*local)); local->RackAddress = ((pwr_sClass_Rack_RTP *) rp->op)->RackAddress; local->Address = 1; if ( cp->Class == pwr_cClass_Co_7435_33) local->CardType = RTP_CO_7435_33; else if ( cp->Class == pwr_cClass_Co_7437_33) local->CardType = RTP_CO_7437_33; for ( i = 0; i < IO_MAXCHAN; i++) local->FirstScan[i] = 1; cp->Local = local; if ( op->MaxNoOfCounters == 1) /* If one RTP_CO 7435_33 */ { rtpco_write( 0, local->RackAddress, op->CardAddress, local->CardType); } else { op_7437 = (pwr_sClass_Co_7437_33 *) op; for (i = 0; i < op_7437->MaxNoOfCounters; i++) rtpco_write( (i << 8) | 0x440, local->RackAddress, op_7437->CardAddress, local->CardType); } for ( i = 0; i < op->MaxNoOfCounters; i++) * (pwr_tUInt32 *) cp->chanlist[i].vbp = 0; errh_Info( "Init of co card '%s'", cp->Name); return 1; }
/*----------------------------------------------------------------------------*\ \*----------------------------------------------------------------------------*/ static pwr_tStatus IoRackInitSwap(io_tCtx ctx, io_sAgent* ap, io_sRack* rp) { io_sRackLocal* local; pwr_sClass_Ssab_RemoteRack* op; int sts; op = (pwr_sClass_Ssab_RemoteRack*)rp->op; local = calloc(1, sizeof(*local)); rp->Local = local; /* Create socket, store in local struct */ local->s = socket(AF_INET, SOCK_DGRAM, 0); if (local->s < 0) { errh_Error( "Error creating socket for IO remote rack %s, %d", rp->Name, local->s); op->Status = IO__INITFAIL; return IO__ERRINIDEVICE; } /* Initialize remote address structure */ local->rem_addr.sin_family = AF_INET; local->rem_addr.sin_port = htons(op->RemotePort); local->rem_addr.sin_addr.s_addr = inet_addr((char*)&(op->Address)); /* Connect to remote address */ sts = connect( local->s, (struct sockaddr*)&local->rem_addr, sizeof(local->rem_addr)); if (sts != 0) { errh_Error( "Error binding remote socket for IO remote rack %s, %d", rp->Name, sts); op->Status = IO__INITFAIL; return IO__ERRINIDEVICE; } local->next_read_req_item = 0; local->next_write_req_item = 0; op->RX_packets = 0; op->TX_packets = 0; /* Log initialization */ errh_Info("Init of IO remote rack %s/%s:%d", rp->Name, inet_ntoa(local->rem_addr.sin_addr), ntohs(local->rem_addr.sin_port)); op->Status = IO__NORMAL; return IO__SUCCESS; }
static void event ( qcom_sGet *get ) { static int sav_event = 0; ini_mEvent cur_event; ini_mEvent new_event; qcom_sEvent *ep = (qcom_sEvent*) get->data; if (get->type.s != qcom_cIini) return; cur_event.m = sav_event; new_event.m = ep->mask; if (new_event.b.swapDone & !cur_event.b.swapDone) { errh_Info("Warm restart completed."); reinit_nodes(); if (!LstEmp(&node_l)) { list_state = eListState_Scan; scan_timers(); scan_nodes(); } else { list_state = eListState_NoNodeLink; errh_Info("No NodeLink objects."); } } else if (new_event.b.swapInit & !cur_event.b.swapInit) { list_state = eListState_Wait; errh_Info("Warm restart initiated."); } else if (new_event.b.terminate & !cur_event.b.terminate) { exit(0); } sav_event = ep->mask; }
/*----------------------------------------------------------------------------*\ \*----------------------------------------------------------------------------*/ static pwr_tStatus IoCardClose ( io_tCtx ctx, io_sAgent *ap, io_sRack *rp, io_sCard *cp ) { io_sLocal *local; errh_Info( "IO closing ai card '%s'", cp->Name); local = (io_sLocal *) cp->Local; free( (char *) local); return 1; }
/*----------------------------------------------------------------------------*\ Swap method for the Pb_profiboard agent \*----------------------------------------------------------------------------*/ static pwr_tStatus IoAgentSwap ( io_tCtx ctx, io_sAgent *ap, io_eEvent event ) { switch ( event) { case io_eEvent_IoCommSwapInit: case io_eEvent_IoCommSwap: { pwr_sClass_Pb_Profiboard *op; char DeviceName[64]; io_sAgentLocal *local; if (ap->Local == NULL) { /* Allocate area for local data structure */ ap->Local = calloc(1, sizeof(io_sAgentLocal)); if (!ap->Local) { errh_Error( "ERROR swap init Profibus DP Master %s - %s", ap->Name, "calloc"); return IO__ERRINIDEVICE; } local = (io_sAgentLocal *) ap->Local; errh_Info( "Swap init interface for Profibus DP Master %s", ap->Name); op = (pwr_sClass_Pb_Profiboard *) ap->op; sprintf(DeviceName, "/dev/pbboard%u", op->BusNumber - 1); local->hDpsBoardDevice = open(DeviceName, O_RDONLY | O_NONBLOCK); if (local->hDpsBoardDevice == -1) { errh_Error( "ERROR swap init Profibus DP Master %s - %s", ap->Name, "open"); return IO__ERRINIDEVICE; } } break; } case io_eEvent_EmergencyBreak: case io_eEvent_IoCommEmergencyBreak: IoAgentClose( ctx, ap); break; } return IO__SUCCESS; }