Commit 4526b890 authored by Claes's avatar Claes

OneWire generic ai device added

parent 9a50a70f
......@@ -8,4 +8,9 @@ typedef struct {
int interval_cnt;
} io_sLocalDS18B20;
typedef struct {
FILE *value_fp;
int interval_cnt;
} io_sLocalAiDevice;
#endif
/*
* Proview $Id$
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* rt_io_m_onewire_aidevice.c -- I/O methods for class OneWire_AiDevice. */
#include <float.h>
#include <math.h>
#include "pwr.h"
#include "pwr_basecomponentclasses.h"
#include "pwr_otherioclasses.h"
#include "co_time.h"
#include "rt_io_base.h"
#include "rt_io_card_init.h"
#include "rt_io_card_close.h"
#include "rt_io_card_read.h"
#include "rt_io_msg.h"
#include "rt_io_m_onewire.h"
static pwr_tStatus IoCardInit( io_tCtx ctx,
io_sAgent *ap,
io_sRack *rp,
io_sCard *cp)
{
pwr_sClass_OneWire_AiDevice *op = (pwr_sClass_OneWire_AiDevice *)cp->op;
io_sLocalAiDevice *local;
pwr_tStatus sts;
char name[40];
pwr_tFileName fname, tmp;
int name_len;
char *s;
if ( cp->chanlist[0].cop) {
local = (io_sLocalAiDevice *) calloc( 1, sizeof(io_sLocalAiDevice));
cp->Local = local;
sprintf( name, "%d-%012x", op->Family, op->Super.Address);
name_len = strlen(name);
strncpy( fname, op->DataFile, sizeof(fname));
// Replace all '%s' with 'family-serialnumber'
s = fname;
while ( (s = strstr( s, "%s"))) {
strncpy( tmp, s+2, sizeof(tmp));
strcpy( s, name);
strncat( fname, tmp, sizeof(fname));
}
local->value_fp = fopen( fname, "r");
if (!local->value_fp) {
errh_Error( "OneWire_AiDevice Unable op open %s, '%ux'", cp->Name,
op->Super.Address);
sts = IO__INITFAIL;
op->Status = sts;
return sts;
}
io_AiRangeToCoef( &cp->chanlist[0]);
errh_Info( "Init of OneWire_AiDevice '%s'", cp->Name);
}
return IO__SUCCESS;
}
static pwr_tStatus IoCardClose( io_tCtx ctx,
io_sAgent *ap,
io_sRack *rp,
io_sCard *cp)
{
io_sLocalAiDevice *local = (io_sLocalAiDevice *)cp->Local;
if ( cp->chanlist[0].cop) {
fclose( local->value_fp);
}
free( cp->Local);
return IO__SUCCESS;
}
static pwr_tStatus IoCardRead( io_tCtx ctx,
io_sAgent *ap,
io_sRack *rp,
io_sCard *cp)
{
io_sLocalAiDevice *local = (io_sLocalAiDevice *)cp->Local;
pwr_sClass_OneWire_AiDevice *op = (pwr_sClass_OneWire_AiDevice *)cp->op;
char str[80];
char *s;
pwr_tUInt32 error_count = op->Super.ErrorCount;
if ( op->ScanInterval > 1) {
if ( local->interval_cnt != 0) {
local->interval_cnt++;
if ( local->interval_cnt >= op->ScanInterval)
local->interval_cnt = 0;
return IO__SUCCESS;
}
local->interval_cnt++;
}
if ( cp->chanlist[0].cop && cp->chanlist[0].sop) {
io_sChannel *chanp = &cp->chanlist[0];
pwr_sClass_ChanAi *cop = (pwr_sClass_ChanAi *)chanp->cop;
pwr_sClass_Ai *sop = (pwr_sClass_Ai *)chanp->sop;
pwr_tFloat32 actvalue;
if ( cop->CalculateNewCoef)
// Request to calculate new coefficients
io_AiRangeToCoef( chanp);
fflush( local->value_fp);
fgets( str, sizeof(str), local->value_fp);
fgets( str, sizeof(str), local->value_fp);
rewind( local->value_fp);
if ( strcmp( op->ValueSearchString, "") == 0)
s = str;
else
s = strstr( str, op->ValueSearchString);
if ( s) {
switch ( op->ChAi.Representation) {
case pwr_eDataRepEnum_Float32:
case pwr_eDataRepEnum_Float64: {
pwr_tFloat32 fvalue;
sscanf( s+strlen(op->ValueSearchString), "%f", &fvalue);
if ( op->ErrorValue != 0 && fabs( op->ErrorValue - fvalue) > FLT_EPSILON ) {
/* TODO Check CRC Probably power loss...
op->Super.ErrorCount++; */
}
actvalue = cop->SensorPolyCoef0 + cop->SensorPolyCoef1 * fvalue;
// Filter
if ( sop->FilterType == 1 &&
sop->FilterAttribute[0] > 0 &&
sop->FilterAttribute[0] > ctx->ScanTime) {
actvalue = *(pwr_tFloat32 *)chanp->vbp + ctx->ScanTime / sop->FilterAttribute[0] *
(actvalue - *(pwr_tFloat32 *)chanp->vbp);
}
*(pwr_tFloat32 *)chanp->vbp = actvalue;
sop->SigValue = cop->SigValPolyCoef1 * fvalue + cop->SigValPolyCoef0;
sop->RawValue = fvalue;
break;
}
default: {
pwr_tInt32 ivalue;
sscanf( s+strlen(op->ValueSearchString), "%d", &ivalue);
io_ConvertAi32( cop, ivalue, &actvalue);
if ( op->ErrorValue != 0 && fabs( op->ErrorValue - ivalue) > FLT_EPSILON ) {
/* TODO Check CRC Probably power loss...
op->Super.ErrorCount++; */
}
// Filter
if ( sop->FilterType == 1 &&
sop->FilterAttribute[0] > 0 &&
sop->FilterAttribute[0] > ctx->ScanTime) {
actvalue = *(pwr_tFloat32 *)chanp->vbp + ctx->ScanTime / sop->FilterAttribute[0] *
(actvalue - *(pwr_tFloat32 *)chanp->vbp);
}
*(pwr_tFloat32 *)chanp->vbp = actvalue;
sop->SigValue = cop->SigValPolyCoef1 * ivalue + cop->SigValPolyCoef0;
sop->RawValue = ivalue;
}
}
}
else {
op->Super.ErrorCount++;
}
}
if ( op->Super.ErrorCount >= op->Super.ErrorSoftLimit &&
error_count < op->Super.ErrorSoftLimit) {
errh_Warning( "IO Card ErrorSoftLimit reached, '%s'", cp->Name);
}
if ( op->Super.ErrorCount >= op->Super.ErrorHardLimit) {
errh_Error( "IO Card ErrorHardLimit reached '%s', IO stopped", cp->Name);
ctx->Node->EmergBreakTrue = 1;
return IO__ERRDEVICE;
}
return IO__SUCCESS;
}
/* Every method should be registred here. */
pwr_dExport pwr_BindIoMethods(OneWire_AiDevice) = {
pwr_BindIoMethod(IoCardInit),
pwr_BindIoMethod(IoCardClose),
pwr_BindIoMethod(IoCardRead),
pwr_NullMethod
};
......@@ -9,6 +9,7 @@ Arduino_Uno
#if OS_LINUX
GPIO
GPIO_Module
OneWire_AiDevice
Maxim_DS18B20
USB_Agent
Velleman_K8055_Board
......
Volume OtherIO $ClassVolume 0.0.250.10
Body SysBody 01-JAN-1970 01:00:00.00
Attr NextOix = "_X242"
Attr NextCix = "_X25"
Attr NextOix = "_X247"
Attr NextCix = "_X26"
Attr NextTix[0] = "_X10"
EndBody
Object Type $TypeHier 1 15-NOV-2007 14:35:37.90
......@@ -2069,6 +2069,119 @@ Volume OtherIO $ClassVolume 0.0.250.10
EndBody
EndObject
EndObject
Object OneWire_AiDevice $ClassDef 25 08-JUN-2011 14:15:31.35
Body SysBody 08-JUN-2011 14:01:02.86
Attr Editor = 0
Attr Method = 0
Attr Flags = 51280
EndBody
Object RtBody $ObjBodyDef 1 08-JUN-2011 14:01:02.86
Body SysBody 08-JUN-2011 14:15:37.86
Attr StructName = "OneWire_AiDevice"
Attr NextAix = "_X33"
EndBody
Object Super $Attribute 24 08-JUN-2011 14:01:02.86
Body SysBody 08-JUN-2011 14:01:02.86
Attr PgmName = "Super"
Attr Flags = 393216
Attr TypeRef = "BaseComponent:Class-BaseIOCard"
EndBody
EndObject
Object Status $Attribute 25 08-JUN-2011 14:01:02.86
Body SysBody 08-JUN-2011 14:01:02.86
Attr PgmName = "Status"
Attr TypeRef = "pwrs:Type-$Status"
EndBody
EndObject
Object Family $Attribute 26 08-JUN-2011 14:01:02.86
Body SysBody 08-JUN-2011 14:01:02.86
Attr PgmName = "Family"
Attr TypeRef = "pwrs:Type-$UInt32"
EndBody
EndObject
Object Resolution $Attribute 27 08-JUN-2011 14:01:02.86
Body SysBody 08-JUN-2011 14:01:02.86
Attr PgmName = "Resolution"
Attr TypeRef = "pwrs:Type-$UInt32"
EndBody
EndObject
Object ScanInterval $Attribute 28 08-JUN-2011 14:01:02.86
Body SysBody 08-JUN-2011 14:01:02.86
Attr PgmName = "ScanInterval"
Attr TypeRef = "pwrs:Type-$UInt32"
EndBody
EndObject
Object DataFile $Attribute 31 08-JUN-2011 14:05:03.02
Body SysBody 08-JUN-2011 14:05:27.07
Attr PgmName = "DataFile"
Attr TypeRef = "pwrs:Type-$String256"
EndBody
EndObject
Object ValueSearchString $Attribute 30 08-JUN-2011 14:05:38.41
Body SysBody 08-JUN-2011 14:05:50.55
Attr PgmName = "ValueSearchString"
Attr TypeRef = "pwrs:Type-$String80"
EndBody
EndObject
Object ErrorValue $Attribute 32 08-JUN-2011 14:06:48.22
Body SysBody 08-JUN-2011 14:06:49.35
Attr PgmName = "ErrorValue"
Attr TypeRef = "pwrs:Type-$Float32"
EndBody
EndObject
Object ChAi $Attribute 29 08-JUN-2011 14:01:02.86
Body SysBody 08-JUN-2011 14:01:02.86
Attr PgmName = "ChAi"
Attr Flags = 131072
Attr TypeRef = "pwrb:Class-ChanAi"
EndBody
EndObject
EndObject
Object IoMethods $RtMethod 243 08-JUN-2011 14:01:02.86
Object IoCardInit $Method 244 08-JUN-2011 14:01:02.86
Body SysBody 08-JUN-2011 15:07:24.12
Attr MethodName = "OneWire_AiDevice-IoCardInit"
EndBody
EndObject
Object IoCardClose $Method 245 08-JUN-2011 14:01:02.86
Body SysBody 08-JUN-2011 15:07:33.15
Attr MethodName = "OneWire_AiDevice-IoCardClose"
EndBody
EndObject
Object IoCardRead $Method 246 08-JUN-2011 14:01:02.86
Body SysBody 08-JUN-2011 15:07:43.58
Attr MethodName = "OneWire_AiDevice-IoCardRead"
EndBody
EndObject
EndObject
Object PostCreate $DbCallBack 247 08-JUN-2011 14:01:02.86
Body SysBody 08-JUN-2011 14:01:02.86
Attr MethodName = "BaseIOCard-PostCreate"
EndBody
EndObject
Object Template OneWire_AiDevice 2154266624 01-JAN-1970 01:00:00.00
Body RtBody 08-JUN-2011 14:10:37.59
Attr Super.Process = 1
Attr Super.ErrorSoftLimit = 50
Attr Super.ErrorHardLimit = 100
Attr Super.MaxNoOfChannels = 1
Attr ScanInterval = 1
Attr DataFile = "/sys/bus/w1/devices/w1 bus master/%s/w1_slave"
Attr ValueSearchString = "t="
Attr ErrorValue = 8.500000e+04
Attr ChAi.ConversionOn = 1
Attr ChAi.ScanInterval = 1
Attr ChAi.ChannelSigValRangeLow = -1.000000e+01
Attr ChAi.ChannelSigValRangeHigh = 1.000000e+01
Attr ChAi.SigValueUnit = "V"
Attr ChAi.SensorPolyType = 1
Attr ChAi.SensorSigValRangeLow = -1.000000e+01
Attr ChAi.SensorSigValRangeHigh = 1.000000e+01
Attr ChAi.ActValRangeLow = -1.000000e+02
Attr ChAi.ActValRangeHigh = 1.000000e+02
EndBody
EndObject
EndObject
!/**
! @Version 1.0
! @Group IO
......@@ -3227,8 +3340,8 @@ Volume OtherIO $ClassVolume 0.0.250.10
! The Hilsher cifX boards supports CANopen, CC-Link, DeviceNet, EtherCAT,
! EtherNet/IP, Modbus TCP, Powerlink, Profibus, Profinet and Sercos III.
!
! The bus devices are configured in SYSCON.net configurator on Windows.
! The configution is export to a configuration file, that is copied to
! The bus devices are configured in SYCON.net configurator on Windows.
! The configution is exported to a configuration file, that is copied to
! the process station.
!
! The Alias attribute has to correspond to the alias setting for the
......
......@@ -285,6 +285,7 @@ palette NavigatorPalette
menu Controller
{
class PnControllerSoftingPNAK
class Hilscher_cifX_PnController
}
menu Devices
{
......@@ -314,6 +315,7 @@ palette NavigatorPalette
menu OneWire
{
class OneWire
class OneWire_AiDevice
class Maxim_DS18B20
}
menu USB
......
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