Commit ecefd771 authored by claes's avatar claes

ChanId with Diag_ prefix feches value from diagnostic area

parent f83e0fac
/*
* Proview $Id: rt_io_m_pb_dp_slave.c,v 1.7 2007-04-30 09:41:31 claes Exp $
* Proview $Id: rt_io_m_pb_dp_slave.c,v 1.8 2007-10-08 13:43:10 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
......@@ -50,6 +50,29 @@
#include "rt_io_profiboard.h"
#include "rt_pb_msg.h"
/* Check if channel should be fetched from diagnostic area,
i.e. channel name starts with "Diag_" */
static int is_diag( pwr_tAttrRef *aref)
{
pwr_tStatus sts;
pwr_tOName name;
char *s;
sts = gdh_AttrrefToName( aref, name, sizeof(name),
cdh_mName_object | cdh_mName_attribute);
if ( EVEN(sts)) return 0;
if ( (s = strrchr( name, '.'))) {
if ( strncmp( s+1, "Diag_", 5) == 0)
return 1;
}
else if ( strncmp( name, "Diag_", 5) == 0)
return 1;
return 0;
}
pwr_tInt32 GetChanSize(pwr_eDataRepEnum rep)
{
switch (rep) {
......@@ -82,6 +105,7 @@ pwr_tInt32 GetChanSize(pwr_eDataRepEnum rep)
/*----------------------------------------------------------------------------*\
Init method for the Pb DP slave
\*----------------------------------------------------------------------------*/
static pwr_tStatus IoRackInit (
io_tCtx ctx,
io_sAgent *ap,
......@@ -204,6 +228,19 @@ static pwr_tStatus IoRackInit (
for (i=0; i<cardp->ChanListSize; i++) {
chanp = &cardp->chanlist[i];
if ( is_diag( &chanp->ChanAref)) {
chanp->udata |= PB_UDATA_DIAG;
switch (chanp->ChanClass) {
case pwr_cClass_ChanIi:
chanp->offset = ((pwr_sClass_ChanIi *)chanp)->Number;
chanp->size = GetChanSize( ((pwr_sClass_ChanIi *)chanp)->Representation);
break;
default:
errh_Error( "Diagnostic channel class, card %s", cardp->Name);
}
continue;
}
if (chanp->ChanClass != pwr_cClass_ChanDi) {
input_counter += latent_input_count;
latent_input_count = 0;
......
/*
* Proview $Id: rt_io_m_pb_module.c,v 1.7 2007-04-30 10:59:56 claes Exp $
* Proview $Id: rt_io_m_pb_module.c,v 1.8 2007-10-08 13:43:10 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
......@@ -307,6 +307,8 @@ static pwr_tStatus IoCardRead (
chan_ii = (pwr_sClass_ChanIi *) chanp->cop;
sig_ii = (pwr_sClass_Ii *) chanp->sop;
if (chan_ii && sig_ii) {
if ( (chanp->udata & PB_UDATA_DIAG) == 0) {
/* Fetch data from input area */
switch (chan_ii->Representation) {
case pwr_eDataRepEnum_Int8:
......@@ -365,6 +367,69 @@ static pwr_tStatus IoCardRead (
}
}
else {
/* Fetch value from diagnostic area */
pwr_tUInt8 *diag_area = ((pwr_sClass_Pb_DP_Slave *)rp->op)->Diag;
switch (chan_ii->Representation) {
case pwr_eDataRepEnum_Int8:
memcpy(&data8, diag_area + chanp->offset, 1);
*(pwr_tInt32 *) chanp->vbp = (pwr_tInt32) data8;
break;
case pwr_eDataRepEnum_UInt8:
memcpy(&udata8, diag_area + chanp->offset, 1);
*(pwr_tInt32 *) chanp->vbp = (pwr_tInt32) udata8;
break;
case pwr_eDataRepEnum_Int16:
memcpy(&data16, diag_area + chanp->offset, 2);
if (slave->ByteOrdering == pwr_eByteOrdering_BigEndian) data16 = swap16(data16);
*(pwr_tInt32 *) chanp->vbp = (pwr_tInt32) data16;
break;
case pwr_eDataRepEnum_UInt16:
memcpy(&udata16, diag_area + chanp->offset, 2);
if (slave->ByteOrdering == pwr_eByteOrdering_BigEndian) udata16 = swap16(udata16);
*(pwr_tInt32 *) chanp->vbp = (pwr_tInt32) udata16;
break;
case pwr_eDataRepEnum_Int24:
data32 = 0;
memcpy(&data32, diag_area + chanp->offset, 3);
if (slave->ByteOrdering == pwr_eByteOrdering_BigEndian) {
data32 = swap32(data32);
data32 = data32 >> 8;
}
*(pwr_tInt32 *) chanp->vbp = (pwr_tInt32) data32;
break;
case pwr_eDataRepEnum_UInt24:
udata32 = 0;
memcpy(&udata32, diag_area + chanp->offset, 3);
if (slave->ByteOrdering == pwr_eByteOrdering_BigEndian) {
udata32 = swap32(udata32);
udata32 = udata32 >> 8;
}
*(pwr_tInt32 *) chanp->vbp = (pwr_tInt32) udata32;
break;
case pwr_eDataRepEnum_Int32:
memcpy(&data32, diag_area + chanp->offset, 4);
if (slave->ByteOrdering == pwr_eByteOrdering_BigEndian) data32 = swap32(data32);
*(pwr_tInt32 *) chanp->vbp = data32;
break;
case pwr_eDataRepEnum_UInt32:
memcpy(&udata32, diag_area + chanp->offset, 4);
if (slave->ByteOrdering == pwr_eByteOrdering_BigEndian) udata32 = swap32(udata32);
*(pwr_tInt32 *) chanp->vbp = (pwr_tInt32) udata32;
break;
}
}
}
break;
}
}
......
/*
* Proview $Id: rt_io_pb_locals.h,v 1.5 2007-05-18 12:00:52 claes Exp $
* Proview $Id: rt_io_pb_locals.h,v 1.6 2007-10-08 13:43:10 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
......@@ -51,6 +51,8 @@
#define PB_ORIENTATION_WORD 16
#define PB_ORIENTATION_DWORD 32
#define PB_UDATA_DIAG 1
typedef struct {
int hServiceReadDevice; // Handle for Service device
int hServiceWriteDevice; // Handle for Service device
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment