static sNode * init_node ( pwr_tObjid oid, sNode *np, pwr_tBoolean new_sub ) { pwr_tStatus sts; pwr_sAttrRef aref; pwr_sClass_NodeLinkSup *o; gdh_tDlid dlid = pwr_cNDlid; pwr_tBoolean is_alias = 0; cdh_uTypeId tid; sts = gdh_IsAlias(oid, &is_alias); if (is_alias) return NULL; /* Allocate and initiate NodeLink control block */ if (np == NULL) { tid.pwr = pwr_cClass_NodeLinkSup; tid.c.bix = 1; aref.Objid = oid; aref.Offset = 0; aref.Size = sizeof(pwr_sClass_NodeLinkSup); aref.Body = tid.pwr; aref.Flags.m = 0; sts = gdh_DLRefObjectInfoAttrref(&aref, (pwr_tAddress *)&o, &dlid); if (EVEN(sts)) { errh_Error("Couldn't get direct link to NodeLink object, %m", sts); return NULL; } np = (sNode*) calloc(1, sizeof(sNode)); if (np == NULL) { if (cdh_DlidIsNotNull (dlid)) gdh_DLUnrefObjectInfo (dlid); errh_Error("Error calloc, sNode"); return NULL; } memcpy (&np->node, o, sizeof (np->node)); np->dlid = dlid; np->o = o; np->oid = oid; np->timer = (void *)&o->TimerFlag; } /* Setup subscription to supervised Node object's attribute CurVersion. */ if (new_sub) { int dt; int tmo; dt = MAX(1, (int)(o->SubscriptionInterval * 1000)); tmo = MAX(2 * dt/100, 100); /* 10 s */ sts = gdh_SetSubscriptionDefaults (dt, tmo); tid.pwr = pwr_eClass_Node; tid.c.bix = 1; aref.Objid = o->Node; sts = gdh_ClassAttrToAttrref(pwr_eClass_Node, ".SystemStatus", &aref); sts = gdh_SubRefObjectInfoAttrref(&aref, &o->SubId); if ( EVEN(sts)) { errh_Error("Couldn't get link to Node object, %m", sts); o->SystemStatus = PWR__NETTIMEOUT; } else gdh_SubAssociateBuffer(o->SubId, (void **)&np->subvalue, sizeof(pwr_tStatus)); } return np; }
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; }