Permalink
Browse files

Ooops... missing files on ModBus GIP driver 1.2.0

  • Loading branch information...
mlouiset committed Oct 6, 2014
1 parent 994942c commit 2d737102efbd3c2f68c9cd7ca486503f50e8ff67
@@ -0,0 +1,72 @@
#ifndef __MODBUS__
#define __MODBUS__
/*
* Overwrite drvcommon define
*/
#define CMN_IEEE_SIZE 128
#include <time.h>
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
#include <poll.h>
#include <unistd.h>
#include <errno.h>
#include "rtlbase.h"
#include "rtllist.h"
#include "rtlimsg.h"
#include "cmnstruct.h"
#include "cmndefine.h"
#include "modbus-def.h"
#include "modbus-type.h"
#define XO_APRES_2_1
#include "xo.h"
#include "xo-helpers.h"
#include "dIa.h"
#include "cmnproto.h"
#include "speccproto.h"
#include "specextern.h"
#include "value_t.h"
#include "attr_t.h"
#include "point_t.h"
#include "libmodbus-acy.h"
#include "cproto.h"
/*
* Global from drvcommon / supervisor
*/
extern t_cli *TbCli[];
extern char *rootactPath;
extern int TraceDebug;
extern int TraceLevel;
extern int TraceProto;
extern int PseudoOng;
extern int WithDia;
extern int DiaTraceRequest;
extern void *MainIQ;
extern void *MainTbPoll;
extern void *MdlCfg;
extern dia_context_t *DiaCtxt;
extern int DiaNbReqPending;
extern int DiaMaxReqPending;
extern int DiaConsecutiveTimeout;
extern unsigned int DiaSendCount;
extern unsigned int DiaRecvCount;
extern unsigned int DiaRtryCount;
extern unsigned int DiaTimeCount;
extern unsigned int DiaIpuOk;
extern unsigned int DiaNetOk;
extern unsigned int DiaIpuTmt;
extern unsigned int DiaNetTmt;
extern unsigned int DiaIpuErr;
extern unsigned int DiaNetErr;
extern unsigned int DiaRepDrp;
extern struct list_head NetworkInternalList;
#endif /* __MODBUS__ */
View
@@ -0,0 +1,197 @@
/*
* Copyright (C) Actility, SA. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version
* 2 only, as published by the Free Software Foundation.
*
* 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 version 2 for more details (a copy is
* included at /legal/license.txt).
*
* You should have received a copy of the GNU General Public License
* version 2 along with this work; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*
* Please contact Actility, SA., 4, rue Ampere 22300 LANNION FRANCE
* or visit www.actility.com if you need additional
* information or have any questions.
*/
//************************************************************************
//************************************************************************
//**
//** File : attr_t.c
//**
//** Description :
//**
//**
//** Date : 2014-09-08
//** Author : Mathias Louiset, Actility (c), 2014.
//**
//************************************************************************
//************************************************************************
#include "modbus-acy.h"
/*****************************************************************************/
/* Prototypes for local functions */
static void Attr_t_init(Attr_t *This);
/*****************************************************************************/
/* Constructors / destructor */
/* static allocation */
/**
* @brief Initialize the Attr_t struct
* @param This the class instance
*/
static void Attr_t_init(Attr_t *This)
{
RTL_TRDBG(TRACE_DETAIL, "Attr_t::init\n");
/* Assign the pointers on functions */
This->buildXoFromProductDescriptor = Attr_t_buildXoFromProductDescriptor;
/* Initialize the members */
INIT_LIST_HEAD(&(This->list));
This->modbusType = NULL;
This->modbusTypeID = ACCESS_VOID;
This->modbusAccess = NULL;
This->isReadable = false;
This->isWritable = false;
This->mask = 0;
This->bytes = 0;
This->reg = 0;
This->map = 0;
This->xoModelAttr = NULL;
}
/* dynamic allocation */
/**
* @brief do dynamic allocation of a Attr_t.
* @return the copy of the object
*/
Attr_t *new_Attr_t()
{
Attr_t *This = malloc(sizeof(Attr_t));
if (!This)
{
return NULL;
}
Attr_t_init(This);
This->free = Attr_t_newFree;
RTL_TRDBG(TRACE_DETAIL, "new Attr_t\n");
return This;
}
/**
* @brief Destructor for dynamic allocation
* @anchor Attr_t_newFree
*/
void Attr_t_newFree(Attr_t *This)
{
RTL_TRDBG(TRACE_DETAIL, "Attr_t::newFree (type:%s) (access:%s)\n",
This->modbusType, This->modbusAccess);
// do not free xoModelAttr, modbusType and modbusAccess,
// as it is references to product catalog
free(This);
}
/* implementation methods */
/**
* Build the XO buffer for the oBIX representation of a attribute of type "array".
* @param This the attribute.
* @param array the read raw data to represent.
* @param size number on read registers.
* @return the built XO buffer.
*/
void *Attr_t_buildXoFromProductDescriptor(Attr_t *This, uint16_t *array, uint16_t size)
{
void *obixReport = NULL;
void *obixAttr = NULL;
int nbSubAttrs, iSubAttrs;
void *subAttr;
int modbusType;
void *param;
unsigned int offsetBeg = 0, offsetEnd = 0;
uint8_t valArray[256];
uint16_t valSize;
char strVal[256];
int i;
void *xoModel;
if (!This->xoModelAttr) return NULL;
xoModel = This->xoModelAttr;
obixReport = XoNmNew("o:obj");
nbSubAttrs = XoNmNbInAttr(xoModel, "modbus:subattributes", 0);
for (iSubAttrs = 0; iSubAttrs < nbSubAttrs; iSubAttrs++) {
subAttr = XoNmGetAttr(xoModel, "modbus:subattributes[%d]", 0, iSubAttrs);
CONTINUE_IF_NULL(subAttr);
param = XoNmGetAttr(subAttr, "modbus:type", NULL, 0);
CONTINUE_IF_NULL(param);
obixAttr = XoNmNew(obixTypeFromModbus(param, &modbusType));
CONTINUE_IF_NULL(param);
param = XoNmGetAttr(subAttr, "modbus:name", NULL, 0);
if (param) {
XoNmSetAttr(obixAttr, "name", param, 0);
} else {
RTL_TRDBG(TRACE_ERROR, "Attr_t::buildXoFromProductDescriptor: Unable to extract "
"name (type:%s) (access:%s)\n", This->modbusType, This->modbusAccess);
XoFree(obixAttr, 1);
continue;
}
param = XoNmGetAttr(subAttr, "modbus:offset", NULL, 0);
if ((param) &&
(2 == sscanf(param, "/beginbyte/%u/endbyte/%u/", &(offsetBeg), &(offsetEnd))) &&
(offsetBeg <= offsetEnd) &&
(offsetEnd < (size*2))) {
memset(valArray, 0, sizeof(valArray));
valSize = (offsetEnd - offsetBeg) + 1;
for (i = 0; i < valSize; i += 2) {
// modbus has big-endian encoding for registers (2-bytes blocks) but little endian
// inside a register.
// put modbus words into uint8_t array in the rights order
// (little endian, for all targets?)
uint16_t value = array[(offsetBeg + i)/2];
if ((valSize == 1) && (offsetBeg % 2)) {
value = value >> 8;
}
memcpy(valArray + i, &value, 2);
}
modbusValueToString(valArray, valSize, modbusType, strVal);
XoNmSetAttr(obixAttr, "val", strVal, 0);
} else {
RTL_TRDBG(TRACE_ERROR, "Attr_t::buildXoFromProductDescriptor: Unable to extract "
"value, no offset (type:%d) (access:%s) (offset:%s) (offsetBeg:%u) (offsetEnd:%u) "
"(size:%u)\n", This->modbusType, This->modbusAccess, param,
offsetBeg, offsetEnd, size);
XoFree(obixAttr, 1);
continue;
}
XoNmAddInAttr(obixReport, "[]", obixAttr, 0, 0);
}
return obixReport;
}
@@ -0,0 +1,81 @@
/*
* Copyright (C) Actility, SA. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version
* 2 only, as published by the Free Software Foundation.
*
* 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 version 2 for more details (a copy is
* included at /legal/license.txt).
*
* You should have received a copy of the GNU General Public License
* version 2 along with this work; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*
* Please contact Actility, SA., 4, rue Ampere 22300 LANNION FRANCE
* or visit www.actility.com if you need additional
* information or have any questions.
*/
//************************************************************************
//************************************************************************
//**
//** File : attr_t.h
//**
//** Description :
//**
//**
//** Date : 09/08/2014
//** Author : Mathias Louiset, Actility (c), 201r4
//**
//************************************************************************
//************************************************************************
#ifndef _ATTR_T__H_
#define _ATTR_T__H_
/**
* @file attr_t.h
* @brief The file gives the definition of a Attr in retargeting config
* @author mlouiset
* @date 2014-09-08
*/
typedef struct Attr_t
{
/* methods */
void *(*buildXoFromProductDescriptor) (struct Attr_t *, uint16_t *array, uint16_t size);
/** @ref Attr_t_newFree */
void (*free) (struct Attr_t *);
/* members */
struct list_head list;
char *modbusType; // ref to product
int modbusTypeID;
char *modbusAccess; // ref to product
bool isReadable;
bool isWritable;
// Decoded version of modbusAccess
uint16_t mask;
uint16_t bytes;
int reg, map;
void *xoModelAttr; // ref to product "<subattributes>"
} Attr_t;
/* dynamic allocation */
Attr_t *new_Attr_t();
void Attr_t_newFree(Attr_t *This);
void *Attr_t_buildXoFromProductDescriptor(Attr_t *This, uint16_t *array, uint16_t size);
#endif
Oops, something went wrong.

0 comments on commit 2d73710

Please sign in to comment.