Example #1
0
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;
}
Example #2
0
static int graph_object_PlcThread( Graph *graph, pwr_sAttrRef *arp)
{
    pwr_sAttrRef attrref;
    int sts;
    graph_sObjectPlcThread *od;
    pwr_tClassId	classid;
    pwr_tFloat32 max_limit = 1;
    pwr_tFloat32 min_limit = 0;
    pwr_tObjid objid = arp->Objid;

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

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

    // Get value for ScanTime
    sts = gdh_ClassAttrToAttrref( classid, ".ScanTime", &attrref);
    if ( EVEN(sts)) return sts;

    attrref.Objid = objid;
    sts = gdh_GetObjectInfoAttrref( &attrref, (void *)&max_limit, sizeof(max_limit));
    if ( EVEN(sts)) return sts;

    max_limit = max_limit * 2;

    od->set_max_show_old = max_limit;
    od->set_min_show_old = min_limit;

    // Configure ProcVal and SetVal bar
    sts = grow_FindObjectByName( graph->grow->ctx, "ActualScanTimeBar",
                                 &od->set_bar_object);
    if ( EVEN(sts)) return sts;

    if ( min_limit != max_limit)
        grow_SetBarRange( od->set_bar_object, double(min_limit), double(max_limit));

    // Get pointers to max and min value
    od->set_max_show_p = (float *) graph->localdb_ref_or_create( "MaxShow",
                         pwr_eType_Float32);
    *od->set_max_show_p = od->set_max_show_old;

    od->set_min_show_p = (float *) graph->localdb_ref_or_create( "MinShow",
                         pwr_eType_Float32);
    *od->set_min_show_p = od->set_min_show_old;

    // Configure SetVal  trend
    sts = grow_FindObjectByName( graph->grow->ctx, "ActualScanTimeTrend",
                                 &od->set_trend_object);
    if ( EVEN(sts)) return sts;

    if ( min_limit != max_limit) {
        grow_SetTrendRangeY( od->set_trend_object, 0, double(min_limit), double(max_limit));
        grow_SetTrendRangeY( od->set_trend_object, 1, double(min_limit), double(max_limit));
    }

    // Register scan function
    graph->graph_object_scan = graph_object_PlcThread_scan;

    return 1;
}