Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
proview
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Esteban Blanc
proview
Commits
4a587916
Commit
4a587916
authored
Jun 10, 2012
by
U-pluto\Claes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cygwin work
parent
cfd57d5c
Changes
57
Show whitespace changes
Inline
Side-by-side
Showing
57 changed files
with
5955 additions
and
755 deletions
+5955
-755
otherio/lib/rt/src/os_templ/rt_io_m_mb_module.c
otherio/lib/rt/src/os_templ/rt_io_m_mb_module.c
+8
-8
otherio/lib/rt/src/os_templ/rt_io_m_mb_modulereadwrite.c
otherio/lib/rt/src/os_templ/rt_io_m_mb_modulereadwrite.c
+180
-0
otherio/lib/rt/src/os_templ/rt_io_m_mb_rtu_master.c
otherio/lib/rt/src/os_templ/rt_io_m_mb_rtu_master.c
+804
-0
otherio/lib/rt/src/os_templ/rt_io_m_mb_rtu_module.c
otherio/lib/rt/src/os_templ/rt_io_m_mb_rtu_module.c
+180
-0
otherio/lib/rt/src/os_templ/rt_io_m_mb_rtu_server.c
otherio/lib/rt/src/os_templ/rt_io_m_mb_rtu_server.c
+1232
-0
otherio/lib/rt/src/os_templ/rt_io_m_mb_rtu_servermodule.c
otherio/lib/rt/src/os_templ/rt_io_m_mb_rtu_servermodule.c
+168
-0
otherio/lib/rt/src/os_templ/rt_io_m_mb_rtu_slave.c
otherio/lib/rt/src/os_templ/rt_io_m_mb_rtu_slave.c
+275
-0
otherio/lib/rt/src/os_templ/rt_io_m_mb_tcp_server.c
otherio/lib/rt/src/os_templ/rt_io_m_mb_tcp_server.c
+69
-169
otherio/lib/rt/src/os_templ/rt_io_m_mb_tcp_slave.c
otherio/lib/rt/src/os_templ/rt_io_m_mb_tcp_slave.c
+555
-557
otherio/lib/rt/src/os_templ/rt_io_mb_locals.h
otherio/lib/rt/src/os_templ/rt_io_mb_locals.h
+4
-0
otherio/lib/rt/src/os_templ/rt_io_mb_rtu.h
otherio/lib/rt/src/os_templ/rt_io_mb_rtu.h
+261
-0
src/exe/rt_neth_acp/src/rt_neth_acp.c
src/exe/rt_neth_acp/src/rt_neth_acp.c
+13
-0
src/exp/com/src/os_cygwin/pwr_stop.sh
src/exp/com/src/os_cygwin/pwr_stop.sh
+30
-13
src/exp/com/src/os_cygwin/pwrp_env.sh
src/exp/com/src/os_cygwin/pwrp_env.sh
+1
-1
src/lib/rt/src/rt_errh.c
src/lib/rt/src/rt_errh.c
+1
-1
src/lib/rt/src/rt_qini.c
src/lib/rt/src/rt_qini.c
+2
-0
src/tools/pkg/cygwin/pwr/Makefile
src/tools/pkg/cygwin/pwr/Makefile
+25
-0
src/tools/pkg/cygwin/pwr/build.sh
src/tools/pkg/cygwin/pwr/build.sh
+208
-0
src/tools/pkg/cygwin/pwr/changelog
src/tools/pkg/cygwin/pwr/changelog
+1
-0
src/tools/pkg/cygwin/pwr/control
src/tools/pkg/cygwin/pwr/control
+34
-0
src/tools/pkg/cygwin/pwr/copyright
src/tools/pkg/cygwin/pwr/copyright
+8
-0
src/tools/pkg/cygwin/pwr/postinst
src/tools/pkg/cygwin/pwr/postinst
+95
-0
src/tools/pkg/cygwin/pwr/prerm
src/tools/pkg/cygwin/pwr/prerm
+12
-0
src/tools/pkg/cygwin/pwr/proview.cnf
src/tools/pkg/cygwin/pwr/proview.cnf
+18
-0
src/tools/pkg/cygwin/pwr/pwr.1
src/tools/pkg/cygwin/pwr/pwr.1
+28
-0
src/tools/pkg/cygwin/pwr/pwrp_profile
src/tools/pkg/cygwin/pwr/pwrp_profile
+59
-0
src/tools/pkg/cygwin/pwrdemo/build.sh
src/tools/pkg/cygwin/pwrdemo/build.sh
+88
-0
src/tools/pkg/cygwin/pwrdemo/changelog
src/tools/pkg/cygwin/pwrdemo/changelog
+1
-0
src/tools/pkg/cygwin/pwrdemo/changelog.Debian
src/tools/pkg/cygwin/pwrdemo/changelog.Debian
+1
-0
src/tools/pkg/cygwin/pwrdemo/control
src/tools/pkg/cygwin/pwrdemo/control
+10
-0
src/tools/pkg/cygwin/pwrdemo/copyright
src/tools/pkg/cygwin/pwrdemo/copyright
+8
-0
src/tools/pkg/cygwin/pwrdemo/postinst
src/tools/pkg/cygwin/pwrdemo/postinst
+78
-0
src/tools/pkg/cygwin/pwrdemo/prerm
src/tools/pkg/cygwin/pwrdemo/prerm
+15
-0
src/tools/pkg/cygwin/pwrrt/build.sh
src/tools/pkg/cygwin/pwrrt/build.sh
+187
-0
src/tools/pkg/cygwin/pwrrt/changelog
src/tools/pkg/cygwin/pwrrt/changelog
+1
-0
src/tools/pkg/cygwin/pwrrt/control
src/tools/pkg/cygwin/pwrrt/control
+25
-0
src/tools/pkg/cygwin/pwrrt/copyright
src/tools/pkg/cygwin/pwrrt/copyright
+8
-0
src/tools/pkg/cygwin/pwrrt/postinst
src/tools/pkg/cygwin/pwrrt/postinst
+382
-0
src/tools/pkg/cygwin/pwrrt/prerm
src/tools/pkg/cygwin/pwrrt/prerm
+125
-0
src/tools/pkg/cygwin/pwrrt/proview.cnf
src/tools/pkg/cygwin/pwrrt/proview.cnf
+18
-0
src/tools/pkg/cygwin/pwrrt/pwr
src/tools/pkg/cygwin/pwrrt/pwr
+152
-0
src/tools/pkg/cygwin/pwrrt/pwr.1
src/tools/pkg/cygwin/pwrrt/pwr.1
+51
-0
src/tools/pkg/cygwin/pwrrt/pwrp_profile
src/tools/pkg/cygwin/pwrrt/pwrp_profile
+59
-0
src/tools/pkg/cygwin/pwrrt/rt_ini.1
src/tools/pkg/cygwin/pwrrt/rt_ini.1
+98
-0
src/tools/pkg/cygwin/pwrrt/rt_rtt.1
src/tools/pkg/cygwin/pwrrt/rt_rtt.1
+40
-0
src/tools/pkg/cygwin/pwrrt/rt_xtt.1
src/tools/pkg/cygwin/pwrrt/rt_xtt.1
+81
-0
src/tools/pkg/cygwin/src/os_templ/hw_templ/makefile
src/tools/pkg/cygwin/src/os_templ/hw_templ/makefile
+65
-0
src/tools/pkg/cygwin/src/pwr
src/tools/pkg/cygwin/src/pwr
+130
-0
src/tools/pkg/cygwin/user/.bashrc
src/tools/pkg/cygwin/user/.bashrc
+31
-0
src/tools/pkg/cygwin/user/Proview.lnk
src/tools/pkg/cygwin/user/Proview.lnk
+0
-0
src/tools/pkg/cygwin/user/ProviewDemo.lnk
src/tools/pkg/cygwin/user/ProviewDemo.lnk
+0
-0
src/tools/pkg/cygwin/user/proview_icon.ico
src/tools/pkg/cygwin/user/proview_icon.ico
+0
-0
src/tools/pkg/cygwin/user/pwrdemostart
src/tools/pkg/cygwin/user/pwrdemostart
+10
-0
src/tools/pkg/cygwin/user/pwrstart
src/tools/pkg/cygwin/user/pwrstart
+9
-0
src/tools/pwre/src/os_cygwin/pwre_configure.sh
src/tools/pwre/src/os_cygwin/pwre_configure.sh
+2
-0
wb/exp/com/src/wb_wiz_directoryvolume.pwr_com
wb/exp/com/src/wb_wiz_directoryvolume.pwr_com
+1
-1
wb/lib/wb/src/wb_db.h
wb/lib/wb/src/wb_db.h
+8
-5
No files found.
otherio/lib/rt/src/os_templ/rt_io_m_mb_module.c
View file @
4a587916
...
@@ -71,12 +71,12 @@ static pwr_tStatus IoCardInit (
...
@@ -71,12 +71,12 @@ static pwr_tStatus IoCardInit (
io_sCard
*
cp
io_sCard
*
cp
)
)
{
{
io_sCardLocal
*
local
;
io_sCardLocal
Msg
*
local
;
pwr_sClass_Modbus_Module
*
op
;
pwr_sClass_Modbus_Module
*
op
;
int
i
;
int
i
;
op
=
(
pwr_sClass_Modbus_Module
*
)
cp
->
op
;
op
=
(
pwr_sClass_Modbus_Module
*
)
cp
->
op
;
local
=
(
io_sCardLocal
*
)
cp
->
Local
;
local
=
(
(
io_sCardLocal
*
)
cp
->
Local
)
->
msg
;
for
(
i
=
0
;
i
<
IO_MAXCHAN
;
i
++
)
{
for
(
i
=
0
;
i
<
IO_MAXCHAN
;
i
++
)
{
local
->
scancount
[
i
]
=
0
;
local
->
scancount
[
i
]
=
0
;
...
@@ -98,12 +98,12 @@ static pwr_tStatus IoCardRead (
...
@@ -98,12 +98,12 @@ static pwr_tStatus IoCardRead (
io_sCard
*
cp
io_sCard
*
cp
)
)
{
{
io_sCardLocal
*
local
;
io_sCardLocal
Msg
*
local
;
pwr_sClass_Modbus_Module
*
op
;
pwr_sClass_Modbus_Module
*
op
;
pwr_sClass_Modbus_TCP_Slave
*
slave
;
pwr_sClass_Modbus_TCP_Slave
*
slave
;
op
=
(
pwr_sClass_Modbus_Module
*
)
cp
->
op
;
op
=
(
pwr_sClass_Modbus_Module
*
)
cp
->
op
;
local
=
(
io_sCardLocal
*
)
cp
->
Local
;
local
=
(
(
io_sCardLocal
*
)
cp
->
Local
)
->
msg
;
slave
=
(
pwr_sClass_Modbus_TCP_Slave
*
)
rp
->
op
;
slave
=
(
pwr_sClass_Modbus_TCP_Slave
*
)
rp
->
op
;
if
(
op
->
ScanInterval
>
1
)
{
if
(
op
->
ScanInterval
>
1
)
{
...
@@ -118,7 +118,7 @@ static pwr_tStatus IoCardRead (
...
@@ -118,7 +118,7 @@ static pwr_tStatus IoCardRead (
}
}
if
(
slave
->
Status
==
MB__NORMAL
)
{
if
(
slave
->
Status
==
MB__NORMAL
)
{
io_bus_card_read
(
ctx
,
rp
,
cp
,
local
->
input_area
,
NULL
,
pwr_eByteOrderingEnum_BigEndian
,
pwr_eFloatRepEnum_FloatIntel
);
io_bus_card_read
(
ctx
,
rp
,
cp
,
slave
->
Inputs
,
NULL
,
pwr_eByteOrderingEnum_BigEndian
,
pwr_eFloatRepEnum_FloatIntel
);
}
}
// printf("Method Modbus_Module-IoCardRead\n");
// printf("Method Modbus_Module-IoCardRead\n");
return
IO__SUCCESS
;
return
IO__SUCCESS
;
...
@@ -135,13 +135,13 @@ static pwr_tStatus IoCardWrite (
...
@@ -135,13 +135,13 @@ static pwr_tStatus IoCardWrite (
io_sCard
*
cp
io_sCard
*
cp
)
)
{
{
io_sCardLocal
*
local
;
io_sCardLocal
Msg
*
local
;
pwr_sClass_Modbus_Module
*
op
;
pwr_sClass_Modbus_Module
*
op
;
pwr_sClass_Modbus_TCP_Slave
*
slave
;
pwr_sClass_Modbus_TCP_Slave
*
slave
;
op
=
(
pwr_sClass_Modbus_Module
*
)
cp
->
op
;
op
=
(
pwr_sClass_Modbus_Module
*
)
cp
->
op
;
local
=
(
io_sCardLocal
*
)
cp
->
Local
;
local
=
(
(
io_sCardLocal
*
)
cp
->
Local
)
->
msg
;
slave
=
(
pwr_sClass_Modbus_TCP_Slave
*
)
rp
->
op
;
slave
=
(
pwr_sClass_Modbus_TCP_Slave
*
)
rp
->
op
;
if
(
op
->
ScanInterval
>
1
)
{
if
(
op
->
ScanInterval
>
1
)
{
...
@@ -159,7 +159,7 @@ static pwr_tStatus IoCardWrite (
...
@@ -159,7 +159,7 @@ static pwr_tStatus IoCardWrite (
}
}
if
(
slave
->
Status
==
MB__NORMAL
)
{
if
(
slave
->
Status
==
MB__NORMAL
)
{
io_bus_card_write
(
ctx
,
cp
,
local
->
output_area
,
pwr_eByteOrderingEnum_BigEndian
,
pwr_eFloatRepEnum_FloatIntel
);
io_bus_card_write
(
ctx
,
cp
,
slave
->
Outputs
,
pwr_eByteOrderingEnum_BigEndian
,
pwr_eFloatRepEnum_FloatIntel
);
}
}
// printf("Method Modbus_Module-IoCardWrite\n");
// printf("Method Modbus_Module-IoCardWrite\n");
return
IO__SUCCESS
;
return
IO__SUCCESS
;
...
...
otherio/lib/rt/src/os_templ/rt_io_m_mb_modulereadwrite.c
0 → 100644
View file @
4a587916
/*
* Proview Open Source Process Control.
* Copyright (C) 2005-2012 SSAB EMEA AB.
*
* This file is part of Proview.
*
* 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 Proview. If not, see <http://www.gnu.org/licenses/>
*
* Linking Proview statically or dynamically with other modules is
* making a combined work based on Proview. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* Proview give you permission to, from the build function in the
* Proview Configurator, combine Proview with modules generated by the
* Proview PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of Proview (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <math.h>
#include <sys/file.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/socket.h>
#include "pwr.h"
#include "pwr_baseclasses.h"
#include "pwr_basecomponentclasses.h"
#include "pwr_otherioclasses.h"
#include "rt_io_base.h"
#include "rt_io_msg.h"
#include "rt_errh.h"
#include "rt_io_bus.h"
#include "rt_mb_msg.h"
#include "rt_io_mb_locals.h"
/*----------------------------------------------------------------------------*\
Init method for the Modbus module
\*----------------------------------------------------------------------------*/
static
pwr_tStatus
IoCardInit
(
io_tCtx
ctx
,
io_sAgent
*
ap
,
io_sRack
*
rp
,
io_sCard
*
cp
)
{
io_sCardLocal
*
local
;
pwr_sClass_Modbus_ModuleReadWrite
*
op
;
int
i
;
op
=
(
pwr_sClass_Modbus_ModuleReadWrite
*
)
cp
->
op
;
local
=
(
io_sCardLocal
*
)
cp
->
Local
;
for
(
i
=
0
;
i
<
IO_MAXCHAN
;
i
++
)
{
local
->
msg
[
0
].
scancount
[
i
]
=
0
;
local
->
msg
[
1
].
scancount
[
i
]
=
0
;
}
op
->
Read
.
Status
=
pwr_eModbusModule_StatusEnum_StatusUnknown
;
op
->
Write
.
Status
=
pwr_eModbusModule_StatusEnum_StatusUnknown
;
return
IO__SUCCESS
;
}
/*----------------------------------------------------------------------------*\
Read method for the Pb module
\*----------------------------------------------------------------------------*/
static
pwr_tStatus
IoCardRead
(
io_tCtx
ctx
,
io_sAgent
*
ap
,
io_sRack
*
rp
,
io_sCard
*
cp
)
{
io_sCardLocal
*
local
;
pwr_sClass_Modbus_ModuleReadWrite
*
op
;
pwr_sClass_Modbus_TCP_Slave
*
slave
;
op
=
(
pwr_sClass_Modbus_ModuleReadWrite
*
)
cp
->
op
;
local
=
(
io_sCardLocal
*
)
cp
->
Local
;
slave
=
(
pwr_sClass_Modbus_TCP_Slave
*
)
rp
->
op
;
if
(
op
->
Read
.
ScanInterval
>
1
)
{
local
->
msg
[
0
].
has_read_method
=
1
;
if
(
local
->
msg
[
0
].
interval_cnt
!=
0
)
{
local
->
msg
[
0
].
interval_cnt
++
;
if
(
local
->
msg
[
0
].
interval_cnt
>=
op
->
Read
.
ScanInterval
)
local
->
msg
[
0
].
interval_cnt
=
0
;
return
IO__SUCCESS
;
}
local
->
msg
[
0
].
interval_cnt
++
;
}
if
(
slave
->
Status
==
MB__NORMAL
)
{
io_bus_card_read
(
ctx
,
rp
,
cp
,
slave
->
Inputs
,
NULL
,
pwr_eByteOrderingEnum_BigEndian
,
pwr_eFloatRepEnum_FloatIntel
);
}
return
IO__SUCCESS
;
}
/*----------------------------------------------------------------------------*\
Write method for the Pb module
\*----------------------------------------------------------------------------*/
static
pwr_tStatus
IoCardWrite
(
io_tCtx
ctx
,
io_sAgent
*
ap
,
io_sRack
*
rp
,
io_sCard
*
cp
)
{
io_sCardLocal
*
local
;
pwr_sClass_Modbus_ModuleReadWrite
*
op
;
pwr_sClass_Modbus_TCP_Slave
*
slave
;
op
=
(
pwr_sClass_Modbus_ModuleReadWrite
*
)
cp
->
op
;
local
=
(
io_sCardLocal
*
)
cp
->
Local
;
slave
=
(
pwr_sClass_Modbus_TCP_Slave
*
)
rp
->
op
;
if
(
op
->
Write
.
ScanInterval
>
1
)
{
if
(
!
local
->
msg
[
1
].
has_read_method
)
{
if
(
local
->
msg
[
1
].
interval_cnt
!=
0
)
{
local
->
msg
[
1
].
interval_cnt
++
;
if
(
local
->
msg
[
1
].
interval_cnt
>=
op
->
Write
.
ScanInterval
)
local
->
msg
[
1
].
interval_cnt
=
0
;
return
IO__SUCCESS
;
}
local
->
msg
[
1
].
interval_cnt
++
;
}
else
if
(
local
->
msg
[
1
].
interval_cnt
!=
1
)
return
IO__SUCCESS
;
}
if
(
slave
->
Status
==
MB__NORMAL
)
{
io_bus_card_write
(
ctx
,
cp
,
slave
->
Outputs
,
pwr_eByteOrderingEnum_BigEndian
,
pwr_eFloatRepEnum_FloatIntel
);
}
// printf("Method Modbus_Module-IoCardWrite\n");
return
IO__SUCCESS
;
}
/*----------------------------------------------------------------------------*\
Every method to be exported to the workbench should be registred here.
\*----------------------------------------------------------------------------*/
pwr_dExport
pwr_BindIoMethods
(
Modbus_ModuleReadWrite
)
=
{
pwr_BindIoMethod
(
IoCardInit
),
pwr_BindIoMethod
(
IoCardRead
),
pwr_BindIoMethod
(
IoCardWrite
),
pwr_NullMethod
};
otherio/lib/rt/src/os_templ/rt_io_m_mb_rtu_master.c
0 → 100644
View file @
4a587916
/*
* Proview Open Source Process Control.
* Copyright (C) 2005-2012 SSAB EMEA AB.
*
* This file is part of Proview.
*
* 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 Proview. If not, see <http://www.gnu.org/licenses/>
*
* Linking Proview statically or dynamically with other modules is
* making a combined work based on Proview. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* Proview give you permission to, from the build function in the
* Proview Configurator, combine Proview with modules generated by the
* Proview PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of Proview (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
*/
/* rt_io_m_mb_rtu_master.c -- io methods for the Modbus RTU Master object
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>
#if defined OS_LINUX
#include <termio.h>
#endif
#if defined OS_LINUX || defined OS_MACOS
#include <sgtty.h>
#endif
#include <sys/ioctl.h>
#include "pwr.h"
#include "co_cdh.h"
#include "pwr_baseclasses.h"
#include "pwr_basecomponentclasses.h"
#include "pwr_otherioclasses.h"
#include "rt_gdh.h"
#include "rt_io_base.h"
#include "rt_io_bus.h"
#include "rt_io_msg.h"
#include "rt_errh.h"
#include "co_cdh.h"
#include "co_time.h"
#include "rt_mb_msg.h"
#include "rt_io_mb_rtu.h"
#include "rt_io_agent_init.h"
char
rcv_buffer
[
65536
];
static
pwr_tStatus
IoAgentInit
(
io_tCtx
ctx
,
io_sAgent
*
ap
);
static
pwr_tStatus
IoAgentRead
(
io_tCtx
ctx
,
io_sAgent
*
ap
);
static
pwr_tStatus
IoAgentWrite
(
io_tCtx
ctx
,
io_sAgent
*
ap
);
static
pwr_tStatus
IoAgentClose
(
io_tCtx
ctx
,
io_sAgent
*
ap
);
static
void
float_to_timeval
(
struct
timeval
*
tv
,
float
t
)
{
tv
->
tv_sec
=
t
;
tv
->
tv_usec
=
(
t
-
(
float
)
tv
->
tv_sec
)
*
1000000
;
}
static
void
float_to_timespec
(
struct
timespec
*
tv
,
float
t
)
{
tv
->
tv_sec
=
t
;
tv
->
tv_nsec
=
(
t
-
(
float
)
tv
->
tv_sec
)
*
1000000000
;
}
/*----------------------------------------------------------------------------*\
Init method for the Modbus RTU Master agent
\*----------------------------------------------------------------------------*/
static
pwr_tStatus
IoAgentInit
(
io_tCtx
ctx
,
io_sAgent
*
ap
)
{
struct
termios
tty_attributes
;
int
sts
;
io_sAgentLocal
*
local
;
pwr_sClass_Modbus_RTU_Master
*
op
=
(
pwr_sClass_Modbus_RTU_Master
*
)
ap
->
op
;
/* Allocate area for local data structure */
ap
->
Local
=
calloc
(
1
,
sizeof
(
io_sAgentLocal
));
local
=
ap
->
Local
;
local
->
fd
=
open
(
op
->
Device
,
O_RDWR
|
O_NDELAY
|
O_NOCTTY
);
if
(
local
->
fd
==
-
1
)
{
errh_Error
(
"Modbus RTU Master, open device error, %s"
,
ap
->
Name
);
return
IO__ERRINIDEVICE
;
}
tcgetattr
(
local
->
fd
,
&
tty_attributes
);
tty_attributes
.
c_cc
[
VMIN
]
=
1
;
tty_attributes
.
c_cc
[
VTIME
]
=
0
;
tty_attributes
.
c_lflag
&=
~
(
ICANON
|
ISIG
|
ECHO
|
IEXTEN
);
tty_attributes
.
c_cflag
|=
(
CLOCAL
|
CREAD
);
tty_attributes
.
c_oflag
&=
~
(
OPOST
);
tty_attributes
.
c_oflag
&=
~
(
ONLCR
);
tty_attributes
.
c_iflag
&=
~
(
INLCR
|
ICRNL
);
/* Speed */
#if defined OS_LINUX
tty_attributes
.
c_cflag
&=
~
CBAUD
;
#endif
switch
(
op
->
Speed
)
{
case
300
:
tty_attributes
.
c_cflag
|=
B300
;
break
;
case
1200
:
tty_attributes
.
c_cflag
|=
B1200
;
break
;
case
2400
:
tty_attributes
.
c_cflag
|=
B2400
;
break
;
case
4800
:
tty_attributes
.
c_cflag
|=
B4800
;
break
;
case
9600
:
tty_attributes
.
c_cflag
|=
B9600
;
break
;
case
19200
:
tty_attributes
.
c_cflag
|=
B19200
;
break
;
case
38400
:
tty_attributes
.
c_cflag
|=
B38400
;
break
;
case
57600
:
tty_attributes
.
c_cflag
|=
B57600
;
break
;
case
115200
:
tty_attributes
.
c_cflag
|=
B115200
;
break
;
default:
errh_Error
(
"Modbus RTU Master, unsupported speed, %s"
,
ap
->
Name
);
tty_attributes
.
c_cflag
|=
B9600
;
break
;
}
/* DataBits 5, 6, 7 or 8 */
tty_attributes
.
c_cflag
&=
~
CSIZE
;
switch
(
op
->
DataBits
)
{
case
pwr_eDataBitsEnum_5
:
tty_attributes
.
c_cflag
|=
CS5
;
break
;
case
pwr_eDataBitsEnum_6
:
tty_attributes
.
c_cflag
|=
CS6
;
break
;
case
pwr_eDataBitsEnum_7
:
tty_attributes
.
c_cflag
|=
CS7
;
break
;
case
pwr_eDataBitsEnum_8
:
tty_attributes
.
c_cflag
|=
CS8
;
break
;
default:
errh_Error
(
"Modbus RTU Master, unsupported DataBits, %s"
,
ap
->
Name
);
tty_attributes
.
c_cflag
|=
CS8
;
}
//tty_attributes.c_iflag |=ISTRIP;
/* Parity */
switch
(
op
->
Parity
)
{
case
pwr_eParityEnum_Odd
:
case
pwr_eParityEnum_Even
:
tty_attributes
.
c_cflag
|=
PARENB
;
tty_attributes
.
c_iflag
|=
IGNPAR
;
if
(
op
->
Parity
==
pwr_eParityEnum_Even
)
tty_attributes
.
c_cflag
&=
~
PARODD
;
else
tty_attributes
.
c_cflag
|=
PARODD
;
break
;
default:
tty_attributes
.
c_cflag
&=
~
PARENB
;
}
/* stopbitsval */
switch
(
op
->
StopBits
)
{
case
pwr_eStopBitsEnum_2
:
tty_attributes
.
c_cflag
|=
CSTOPB
;
break
;
case
pwr_eStopBitsEnum_1
:
tty_attributes
.
c_cflag
&=~
CSTOPB
;
break
;
case
pwr_eStopBitsEnum_0
:
errh_Error
(
"Modbus RTU Master, unsupported StopBits, %s"
,
ap
->
Name
);
tty_attributes
.
c_cflag
&=~
CSTOPB
;
break
;
}
tty_attributes
.
c_iflag
&=
~
IXON
;
//ingen XON/XOFF in
//tty_attributes.c_iflag &= (V_IGNCR);
//tty_attributes.c_iflag &= (IGNPAR | V_IGNCR);
//tty_attributes.c_iflag &= ~(BRKINT | IXON | V_INLCR | V_ICRNL);
//tty_attributes.c_cflag &= ~(CSIZE | CSTOPB | PARENB); //fippla om vrden lite granna
sts
=
tcsetattr
(
local
->
fd
,
TCSANOW
,
&
tty_attributes
);
if
(
sts
<
0
)
{
errh_Error
(
"Modbus RTU Master, set device attributes error, %s"
,
ap
->
Name
);
return
IO__ERRINIDEVICE
;
}
tcflush
(
local
->
fd
,
TCIOFLUSH
);
// Test
sleep
(
2
);
local
->
initialized
=
TRUE
;
return
IO__SUCCESS
;
}
static
void
generate_crc
(
unsigned
char
*
buf
,
int
size
,
unsigned
char
*
result
)
{
unsigned
short
int
crc
;
unsigned
short
int
gen_polynomial
=
0xA001
;
unsigned
short
int
flag_mask
=
0x0001
;
unsigned
short
int
flag
;
int
i
,
j
;
crc
=
0xFFFF
;
for
(
i
=
0
;
i
<
size
;
i
++
)
{
crc
=
crc
^
buf
[
i
];
for
(
j
=
0
;
j
<
8
;
j
++
)
{
flag
=
crc
&
flag_mask
;
crc
=
crc
>>
1
;
if
(
flag
)
crc
=
crc
^
gen_polynomial
;
}
}
result
[
0
]
=
(
unsigned
char
)
(
crc
&
0x00FF
);
result
[
1
]
=
(
unsigned
char
)
((
crc
>>
8
)
&
0x00FF
);
}
static
pwr_tStatus
rtu_send
(
io_sRack
*
rp
,
io_sAgentLocal
*
local_master
,
io_sRackLocal
*
local_slave
,
io_sCardLocalMsg
*
local_card
,
pwr_sClass_Modbus_RTU_Master
*
masterp
,
pwr_sClass_Modbus_RTU_Slave
*
slavep
,
pwr_sClass_Modbus_RTU_Module
*
modulep
,
unsigned
char
*
buf
,
int
buffer_size
)
{
int
sts
;
rec_buf
*
rb
;
unsigned
char
fc
;
int
data_size
=
0
;
unsigned
char
telegram
[
512
];
unsigned
char
crc
[
2
];
fd_set
read_fd
;
struct
timeval
tv
;
generate_crc
(
buf
,
buffer_size
,
&
buf
[
buffer_size
]);
if
(
masterp
->
Debug
)
{
int
i
;
pwr_tTime
current
;
char
timstr
[
40
];
time_GetTime
(
&
current
);
time_AtoAscii
(
&
current
,
time_eFormat_Time
,
timstr
,
sizeof
(
timstr
));
printf
(
"Snd: %s %2d "
,
timstr
,
buffer_size
+
2
);
for
(
i
=
0
;
i
<
buffer_size
+
2
;
i
++
)
printf
(
"%02d "
,
buf
[
i
]);
printf
(
"
\n
"
);
}
sts
=
write
(
local_master
->
fd
,
buf
,
buffer_size
+
2
);
if
(
sts
<=
0
)
{
slavep
->
ErrorCount
++
;
return
0
;
}
slavep
->
TX_packets
++
;
/* Receive answer */
sts
=
1
;
float_to_timeval
(
&
tv
,
masterp
->
ReceiveTimeout
);
FD_ZERO
(
&
read_fd
);
FD_SET
(
local_master
->
fd
,
&
read_fd
);
sts
=
select
(
local_master
->
fd
+
1
,
&
read_fd
,
NULL
,
NULL
,
&
tv
);
if
(
sts
==
0
)
return
0
;
sts
=
read
(
local_master
->
fd
,
telegram
,
1
);
if
(
sts
<=
0
)
{
if
(
masterp
->
Debug
)
printf
(
"Rcv: Nothing to read
\n
"
);
return
0
;
}
while
(
sts
>
0
)
{
data_size
++
;
float_to_timeval
(
&
tv
,
masterp
->
CharTimeout
);
FD_ZERO
(
&
read_fd
);
FD_SET
(
local_master
->
fd
,
&
read_fd
);
sts
=
select
(
local_master
->
fd
+
1
,
&
read_fd
,
NULL
,
NULL
,
&
tv
);
if
(
sts
==
0
)
{
break
;
}
sts
=
read
(
local_master
->
fd
,
telegram
+
data_size
,
1
);
}
if
(
data_size
<
2
)
{
if
(
masterp
->
Debug
)
printf
(
"Rcv: Data size < 2
\n
"
);
return
0
;
}
if
(
masterp
->
Debug
)
{
int
i
;
pwr_tTime
current
;
char
timstr
[
40
];
time_GetTime
(
&
current
);
time_AtoAscii
(
&
current
,
time_eFormat_Time
,
timstr
,
sizeof
(
timstr
));
printf
(
"Rcv: %s %2d "
,
timstr
,
data_size
);
for
(
i
=
0
;
i
<
data_size
;
i
++
)
printf
(
"%02d "
,
telegram
[
i
]);
printf
(
"
\n
"
);
}
generate_crc
(
telegram
,
data_size
-
2
,
crc
);
if
(
crc
[
0
]
!=
telegram
[
data_size
-
2
]
||
crc
[
1
]
!=
telegram
[
data_size
-
1
])
{
slavep
->
ErrorCount
++
;
return
0
;
}
slavep
->
RX_packets
++
;
rb
=
(
rec_buf
*
)
telegram
;
fc
=
rb
->
fc
;
if
(
fc
!=
modulep
->
FunctionCode
)
{
return
0
;
}
slavep
->
Status
=
MB__NORMAL
;
modulep
->
Status
=
pwr_eModbusModule_StatusEnum_OK
;
switch
(
fc
)
{
case
pwr_eModbus_FCEnum_ReadCoils
:
{
res_read
*
res_r
;
res_r
=
(
res_read
*
)
rb
;
memcpy
(
local_card
->
input_area
,
res_r
->
buf
,
MIN
(
res_r
->
bc
,
local_card
->
input_size
));
break
;
}
case
pwr_eModbus_FCEnum_ReadDiscreteInputs
:
{
res_read
*
res_r
;
res_r
=
(
res_read
*
)
rb
;
memcpy
(
local_card
->
input_area
,
res_r
->
buf
,
MIN
(
res_r
->
bc
,
local_card
->
input_size
));
break
;
}
case
pwr_eModbus_FCEnum_ReadHoldingRegisters
:
{
res_read
*
res_r
;
res_r
=
(
res_read
*
)
rb
;
memcpy
(
local_card
->
input_area
,
res_r
->
buf
,
MIN
(
res_r
->
bc
,
local_card
->
input_size
));
break
;
}
case
pwr_eModbus_FCEnum_ReadInputRegisters
:
{
res_read
*
res_r
;
res_r
=
(
res_read
*
)
rb
;
memcpy
(
local_card
->
input_area
,
res_r
->
buf
,
MIN
(
res_r
->
bc
,
local_card
->
input_size
));
break
;
}
case
pwr_eModbus_FCEnum_WriteMultipleCoils
:
case
pwr_eModbus_FCEnum_WriteMultipleRegisters
:
case
pwr_eModbus_FCEnum_WriteSingleRegister
:
// Nothing good to do here
break
;
}
return
IO__SUCCESS
;
}
static
pwr_tStatus
mb_rtu_send_data
(
io_sRack
*
rp
,
io_sAgentLocal
*
local_master
,
io_sRackLocal
*
local_slave
,
pwr_sClass_Modbus_RTU_Master
*
masterp
,
pwr_sClass_Modbus_RTU_Slave
*
slavep
,
mb_tSendMask
mask
)
{
io_sCardLocalMsg
*
local_card
;
io_sCard
*
cardp
;
pwr_sClass_Modbus_RTU_Module
*
modulep
;
pwr_tStatus
sts
;
pwr_tCid
cid
;
int
modules
;
int
i
;
int
send_error
;
struct
timespec
tf
;
/* Send messages to slave */
cardp
=
rp
->
cardlist
;
while
(
cardp
)
{
cid
=
cardp
->
Class
;
while
(
ODD
(
gdh_GetSuperClass
(
cid
,
&
cid
,
cardp
->
Objid
)))
;
switch
(
cid
)
{
case
pwr_cClass_Modbus_RTU_Module
:
modulep
=
(
pwr_sClass_Modbus_RTU_Module
*
)
cardp
->
op
;
modules
=
1
;
break
;
default:
modules
=
0
;
}
if
(
!
modules
)
{
cardp
=
cardp
->
next
;
continue
;
}
send_error
=
0
;
for
(
i
=
0
;
i
<
modules
;
i
++
)
{
sts
=
1
;
if
(
!
modulep
->
Continous
&&
!
modulep
->
SendOp
)
{
break
;
}
local_card
=
&
((
io_sCardLocal
*
)
cardp
->
Local
)
->
msg
[
i
];
if
(
modulep
->
ScanInterval
>
1
&&
local_card
->
interval_cnt
!=
0
)
{
modulep
++
;
continue
;
}
if
(
mask
&
mb_mSendMask_ReadReq
)
{
switch
(
modulep
->
FunctionCode
)
{
case
pwr_eModbus_FCEnum_ReadCoils
:
case
pwr_eModbus_FCEnum_ReadDiscreteInputs
:
{
read_req
rr
;
modulep
->
SendOp
=
FALSE
;
rr
.
unit_id
=
modulep
->
UnitId
;
rr
.
fc
=
modulep
->
FunctionCode
;
rr
.
addr
=
htons
(
modulep
->
Address
);
rr
.
quant
=
htons
(
local_card
->
no_di
);
// rr.quant = ntohs(local_card->input_size * 8);
sts
=
rtu_send
(
rp
,
local_master
,
local_slave
,
local_card
,
masterp
,
slavep
,
modulep
,
(
unsigned
char
*
)
&
rr
,
sizeof
(
read_req
)
-
2
);
if
(
EVEN
(
sts
))
{
slavep
->
Status
=
MB__CONNDOWN
;
slavep
->
ErrorCount
++
;
send_error
=
1
;
break
;
}
slavep
->
Status
=
MB__NORMAL
;
break
;
}
case
pwr_eModbus_FCEnum_ReadHoldingRegisters
:
case
pwr_eModbus_FCEnum_ReadInputRegisters
:
{
read_req
rr
;
modulep
->
SendOp
=
FALSE
;
rr
.
unit_id
=
modulep
->
UnitId
;
rr
.
fc
=
modulep
->
FunctionCode
;
rr
.
addr
=
htons
(
modulep
->
Address
);
rr
.
quant
=
ntohs
((
local_card
->
input_size
+
1
)
/
2
);
sts
=
rtu_send
(
rp
,
local_master
,
local_slave
,
local_card
,
masterp
,
slavep
,
modulep
,
(
unsigned
char
*
)
&
rr
,
sizeof
(
read_req
)
-
2
);
if
(
EVEN
(
sts
))
{
slavep
->
Status
=
MB__CONNDOWN
;
slavep
->
ErrorCount
++
;
send_error
=
1
;
break
;
}
slavep
->
Status
=
MB__NORMAL
;
break
;
}
}
/* End - switch FC ... */
}
if
(
mask
&
mb_mSendMask_WriteReq
)
{
switch
(
modulep
->
FunctionCode
)
{
case
pwr_eModbus_FCEnum_WriteSingleCoil
:
{
write_single_req
wsr
;
modulep
->
SendOp
=
FALSE
;
wsr
.
unit_id
=
modulep
->
UnitId
;
wsr
.
fc
=
modulep
->
FunctionCode
;
wsr
.
addr
=
htons
(
modulep
->
Address
);
if
(
local_card
->
output_size
==
4
)
{
if
(
*
(
int
*
)
local_card
->
output_area
)
wsr
.
value
=
ntohs
(
0xFF00
);
else
wsr
.
value
=
0
;
}
else
if
(
local_card
->
output_size
==
2
)
{
if
(
*
(
short
int
*
)
local_card
->
output_area
)
wsr
.
value
=
ntohs
(
0xFF00
);
else
wsr
.
value
=
0
;
}
else
if
(
local_card
->
output_size
==
1
)
{
if
(
*
(
char
*
)
local_card
->
output_area
)
wsr
.
value
=
ntohs
(
0xFF00
);
else
wsr
.
value
=
0
;
}
else
wsr
.
value
=
0
;
sts
=
rtu_send
(
rp
,
local_master
,
local_slave
,
local_card
,
masterp
,
slavep
,
modulep
,
(
unsigned
char
*
)
&
wsr
,
sizeof
(
wsr
)
-
2
);
if
(
EVEN
(
sts
))
{
slavep
->
Status
=
MB__CONNDOWN
;
slavep
->
ErrorCount
++
;
send_error
=
1
;
break
;
}
slavep
->
Status
=
MB__NORMAL
;
break
;
}
case
pwr_eModbus_FCEnum_WriteMultipleCoils
:
{
write_coils_req
wcr
;
modulep
->
SendOp
=
FALSE
;
wcr
.
unit_id
=
modulep
->
UnitId
;
wcr
.
fc
=
modulep
->
FunctionCode
;
wcr
.
addr
=
htons
(
modulep
->
Address
);
wcr
.
quant
=
htons
(
local_card
->
no_do
);
// wcr.quant = ntohs((local_card->output_size) * 8);
wcr
.
bc
=
local_card
->
output_size
;
memcpy
(
wcr
.
reg
,
local_card
->
output_area
,
local_card
->
output_size
);
sts
=
rtu_send
(
rp
,
local_master
,
local_slave
,
local_card
,
masterp
,
slavep
,
modulep
,
(
unsigned
char
*
)
&
wcr
,
sizeof
(
wcr
)
-
2
-
sizeof
(
wcr
.
reg
)
+
local_card
->
output_size
);
if
(
EVEN
(
sts
))
{
slavep
->
Status
=
MB__CONNDOWN
;
slavep
->
ErrorCount
++
;
send_error
=
1
;
break
;
}
slavep
->
Status
=
MB__NORMAL
;
break
;
}
case
pwr_eModbus_FCEnum_WriteMultipleRegisters
:
{
write_reg_req
wrr
;
modulep
->
SendOp
=
FALSE
;
wrr
.
unit_id
=
modulep
->
UnitId
;
wrr
.
fc
=
modulep
->
FunctionCode
;
wrr
.
addr
=
htons
(
modulep
->
Address
);
wrr
.
quant
=
ntohs
((
local_card
->
output_size
)
/
2
);
wrr
.
bc
=
local_card
->
output_size
;
memcpy
(
wrr
.
reg
,
local_card
->
output_area
,
local_card
->
output_size
);
sts
=
rtu_send
(
rp
,
local_master
,
local_slave
,
local_card
,
masterp
,
slavep
,
modulep
,
(
unsigned
char
*
)
&
wrr
,
sizeof
(
wrr
)
-
2
-
sizeof
(
wrr
.
reg
)
+
local_card
->
output_size
);
if
(
EVEN
(
sts
))
{
slavep
->
Status
=
MB__CONNDOWN
;
slavep
->
ErrorCount
++
;
send_error
=
1
;
break
;
}
slavep
->
Status
=
MB__NORMAL
;
break
;
}
case
pwr_eModbus_FCEnum_WriteSingleRegister
:
{
write_single_req
wrr
;
modulep
->
SendOp
=
FALSE
;
wrr
.
unit_id
=
modulep
->
UnitId
;
wrr
.
fc
=
modulep
->
FunctionCode
;
wrr
.
addr
=
htons
(
modulep
->
Address
);
memcpy
(
&
wrr
.
value
,
local_card
->
output_area
,
sizeof
(
wrr
.
value
));
sts
=
rtu_send
(
rp
,
local_master
,
local_slave
,
local_card
,
masterp
,
slavep
,
modulep
,
(
unsigned
char
*
)
&
wrr
,
sizeof
(
wrr
)
-
2
);
if
(
EVEN
(
sts
))
{
slavep
->
Status
=
MB__CONNDOWN
;
slavep
->
ErrorCount
++
;
send_error
=
1
;
break
;
}
slavep
->
Status
=
MB__NORMAL
;
break
;
}
}
/* End - switch FC ... */
}
if
(
send_error
&&
cardp
->
next
)
{
/* Time to next frame */
float_to_timespec
(
&
tf
,
masterp
->
FrameTimeout
-
masterp
->
CharTimeout
);
nanosleep
(
&
tf
,
NULL
);
break
;
}
if
(
!
(
i
==
modules
-
1
&&
!
cardp
->
next
))
{
float_to_timespec
(
&
tf
,
masterp
->
FrameTimeout
-
masterp
->
CharTimeout
);
nanosleep
(
&
tf
,
NULL
);
}
modulep
++
;
}
cardp
=
cardp
->
next
;
}
/* End - while cardp ... */
return
IO__SUCCESS
;
}
/*----------------------------------------------------------------------------*\
Read method for the Modbus RTU Master agent
\*----------------------------------------------------------------------------*/
static
pwr_tStatus
IoAgentRead
(
io_tCtx
ctx
,
io_sAgent
*
ap
)
{
io_sAgentLocal
*
local
;
io_sRackLocal
*
local_rack
;
pwr_tUInt16
sts
;
io_sRack
*
rp
;
pwr_tCid
cid
;
pwr_sClass_Modbus_RTU_Slave
*
sp
;
pwr_sClass_Modbus_RTU_Master
*
op
=
(
pwr_sClass_Modbus_RTU_Master
*
)
ap
->
op
;
local
=
(
io_sAgentLocal
*
)
ap
->
Local
;
rp
=
ap
->
racklist
;
while
(
rp
)
{
cid
=
rp
->
Class
;
while
(
ODD
(
gdh_GetSuperClass
(
cid
,
&
cid
,
rp
->
Objid
)))
;
switch
(
cid
)
{
case
pwr_cClass_Modbus_RTU_Slave
:
sp
=
(
pwr_sClass_Modbus_RTU_Slave
*
)
rp
->
op
;
local_rack
=
rp
->
Local
;
/* Request new data */
if
(
/* sp->Status == MB__NORMAL && */
sp
->
DisableSlave
!=
1
)
{
sts
=
mb_rtu_send_data
(
rp
,
local
,
local_rack
,
op
,
sp
,
mb_mSendMask_ReadReq
);
if
(
sp
->
ErrorCount
>=
sp
->
ErrorLimit
)
{
switch
(
sp
->
StallAction
)
{
case
pwr_eStallActionEnum_EmergencyBreak
:
ctx
->
Node
->
EmergBreakTrue
=
1
;
break
;
case
pwr_eStallActionEnum_ResetInputs
:
memset
(
sp
->
Inputs
,
0
,
local_rack
->
input_size
);
local_rack
->
reset_inputs
=
1
;
break
;
default:
;
}
}
else
local_rack
->
reset_inputs
=
0
;
}
break
;
}
rp
=
rp
->
next
;
}
return
IO__SUCCESS
;
}
/*----------------------------------------------------------------------------*\
Write method for the Modbus RTU Master agent
\*----------------------------------------------------------------------------*/
static
pwr_tStatus
IoAgentWrite
(
io_tCtx
ctx
,
io_sAgent
*
ap
)
{
io_sAgentLocal
*
local
;
io_sRackLocal
*
local_rack
;
pwr_tUInt16
sts
;
io_sRack
*
rp
;
pwr_tCid
cid
;
pwr_sClass_Modbus_RTU_Slave
*
sp
;
pwr_sClass_Modbus_RTU_Master
*
op
=
(
pwr_sClass_Modbus_RTU_Master
*
)
ap
->
op
;
local
=
(
io_sAgentLocal
*
)
ap
->
Local
;
rp
=
ap
->
racklist
;
while
(
rp
)
{
cid
=
rp
->
Class
;
while
(
ODD
(
gdh_GetSuperClass
(
cid
,
&
cid
,
rp
->
Objid
)))
;
switch
(
cid
)
{
case
pwr_cClass_Modbus_RTU_Slave
:
sp
=
(
pwr_sClass_Modbus_RTU_Slave
*
)
rp
->
op
;
local_rack
=
rp
->
Local
;
/* Request new data */
if
(
/* sp->Status == MB__NORMAL && */
sp
->
DisableSlave
!=
1
)
{
sts
=
mb_rtu_send_data
(
rp
,
local
,
local_rack
,
op
,
sp
,
mb_mSendMask_WriteReq
);
}
break
;
}
rp
=
rp
->
next
;
}
return
IO__SUCCESS
;
}
/*----------------------------------------------------------------------------*\
\*----------------------------------------------------------------------------*/
static
pwr_tStatus
IoAgentClose
(
io_tCtx
ctx
,
io_sAgent
*
ap
)
{
io_sAgentLocal
*
local
=
(
io_sAgentLocal
*
)
ap
->
Local
;
close
(
local
->
fd
);
return
IO__SUCCESS
;
}
/*----------------------------------------------------------------------------*\
Every method to be exported to the workbench should be registred here.
\*----------------------------------------------------------------------------*/
pwr_dExport
pwr_BindIoMethods
(
Modbus_RTU_Master
)
=
{
pwr_BindIoMethod
(
IoAgentInit
),
pwr_BindIoMethod
(
IoAgentRead
),
pwr_BindIoMethod
(
IoAgentWrite
),
pwr_BindIoMethod
(
IoAgentClose
),
pwr_NullMethod
};
otherio/lib/rt/src/os_templ/rt_io_m_mb_rtu_module.c
0 → 100644
View file @
4a587916
/*
* Proview Open Source Process Control.
* Copyright (C) 2005-2012 SSAB EMEA AB.
*
* This file is part of Proview.
*
* 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 Proview. If not, see <http://www.gnu.org/licenses/>
*
* Linking Proview statically or dynamically with other modules is
* making a combined work based on Proview. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* Proview give you permission to, from the build function in the
* Proview Configurator, combine Proview with modules generated by the
* Proview PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of Proview (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <math.h>
#include <sys/file.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/socket.h>
#include "pwr.h"
#include "pwr_baseclasses.h"
#include "pwr_basecomponentclasses.h"
#include "pwr_otherioclasses.h"
#include "rt_io_base.h"
#include "rt_io_msg.h"
#include "rt_errh.h"
#include "rt_io_bus.h"
#include "rt_mb_msg.h"
#include "rt_io_mb_rtu.h"
/*----------------------------------------------------------------------------*\
Init method for the Modbus module
\*----------------------------------------------------------------------------*/
static
pwr_tStatus
IoCardInit
(
io_tCtx
ctx
,
io_sAgent
*
ap
,
io_sRack
*
rp
,
io_sCard
*
cp
)
{
io_sCardLocalMsg
*
local
;
pwr_sClass_Modbus_RTU_Module
*
op
;
int
i
;
op
=
(
pwr_sClass_Modbus_RTU_Module
*
)
cp
->
op
;
local
=
((
io_sCardLocal
*
)
cp
->
Local
)
->
msg
;
for
(
i
=
0
;
i
<
IO_MAXCHAN
;
i
++
)
{
local
->
scancount
[
i
]
=
0
;
}
op
->
Status
=
pwr_eModbusModule_StatusEnum_StatusUnknown
;
return
IO__SUCCESS
;
}
/*----------------------------------------------------------------------------*\
Read method for the Modbus RTU module
\*----------------------------------------------------------------------------*/
static
pwr_tStatus
IoCardRead
(
io_tCtx
ctx
,
io_sAgent
*
ap
,
io_sRack
*
rp
,
io_sCard
*
cp
)
{
io_sCardLocalMsg
*
local
;
io_sRackLocal
*
local_rack
=
(
io_sRackLocal
*
)
rp
->
Local
;
pwr_sClass_Modbus_RTU_Module
*
op
;
pwr_sClass_Modbus_RTU_Slave
*
slave
;
op
=
(
pwr_sClass_Modbus_RTU_Module
*
)
cp
->
op
;
local
=
((
io_sCardLocal
*
)
cp
->
Local
)
->
msg
;
slave
=
(
pwr_sClass_Modbus_RTU_Slave
*
)
rp
->
op
;
if
(
op
->
ScanInterval
>
1
)
{
local
->
has_read_method
=
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
(
slave
->
Status
==
MB__NORMAL
||
local_rack
->
reset_inputs
)
{
io_bus_card_read
(
ctx
,
rp
,
cp
,
slave
->
Inputs
,
NULL
,
pwr_eByteOrderingEnum_BigEndian
,
pwr_eFloatRepEnum_FloatIntel
);
}
// printf("Method Modbus_RTU_Module-IoCardRead\n");
return
IO__SUCCESS
;
}
/*----------------------------------------------------------------------------*\
Write method for the Modbus RTU module
\*----------------------------------------------------------------------------*/
static
pwr_tStatus
IoCardWrite
(
io_tCtx
ctx
,
io_sAgent
*
ap
,
io_sRack
*
rp
,
io_sCard
*
cp
)
{
io_sCardLocalMsg
*
local
;
pwr_sClass_Modbus_RTU_Module
*
op
;
pwr_sClass_Modbus_RTU_Slave
*
slave
;
op
=
(
pwr_sClass_Modbus_RTU_Module
*
)
cp
->
op
;
local
=
((
io_sCardLocal
*
)
cp
->
Local
)
->
msg
;
slave
=
(
pwr_sClass_Modbus_RTU_Slave
*
)
rp
->
op
;
if
(
op
->
ScanInterval
>
1
)
{
if
(
!
local
->
has_read_method
)
{
if
(
local
->
interval_cnt
!=
0
)
{
local
->
interval_cnt
++
;
if
(
local
->
interval_cnt
>=
op
->
ScanInterval
)
local
->
interval_cnt
=
0
;
return
IO__SUCCESS
;
}
local
->
interval_cnt
++
;
}
else
if
(
local
->
interval_cnt
!=
1
)
return
IO__SUCCESS
;
}
if
(
slave
->
Status
==
MB__NORMAL
)
{
io_bus_card_write
(
ctx
,
cp
,
slave
->
Outputs
,
pwr_eByteOrderingEnum_BigEndian
,
pwr_eFloatRepEnum_FloatIntel
);
}
// printf("Method Modbus_RTU_Module-IoCardWrite\n");
return
IO__SUCCESS
;
}
/*----------------------------------------------------------------------------*\
Every method to be exported to the workbench should be registred here.
\*----------------------------------------------------------------------------*/
pwr_dExport
pwr_BindIoMethods
(
Modbus_RTU_Module
)
=
{
pwr_BindIoMethod
(
IoCardInit
),
pwr_BindIoMethod
(
IoCardRead
),
pwr_BindIoMethod
(
IoCardWrite
),
pwr_NullMethod
};
otherio/lib/rt/src/os_templ/rt_io_m_mb_rtu_server.c
0 → 100644
View file @
4a587916
/*
* Proview Open Source Process Control.
* Copyright (C) 2005-2012 SSAB EMEA AB.
*
* This file is part of Proview.
*
* 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 Proview. If not, see <http://www.gnu.org/licenses/>
*
* Linking Proview statically or dynamically with other modules is
* making a combined work based on Proview. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* Proview give you permission to, from the build function in the
* Proview Configurator, combine Proview with modules generated by the
* Proview PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of Proview (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
*/
/* rt_io_m_mb_rtu_server.c -- io methods for Modbus/RTU Server */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>
#if defined OS_LINUX
#include <termio.h>
#endif
#if defined OS_LINUX || defined OS_MACOS
#include <sgtty.h>
#endif
#include <sys/ioctl.h>
#include "pwr.h"
#include "co_cdh.h"
#include "pwr_baseclasses.h"
#include "pwr_basecomponentclasses.h"
#include "pwr_otherioclasses.h"
#include "pwr_version.h"
#include "rt_gdh.h"
#include "rt_io_base.h"
#include "rt_io_bus.h"
#include "rt_io_msg.h"
#include "rt_errh.h"
#include "co_cdh.h"
#include "co_time.h"
#include "rt_mb_msg.h"
#include "rt_io_mb_rtu.h"
char
rcv_buffer
[
512
];
static
pwr_tStatus
mb_init_channels
(
io_tCtx
ctx
,
io_sAgent
*
ap
,
io_sRack
*
rp
);
static
void
mb_shift_write
(
unsigned
char
*
in
,
unsigned
char
*
out
,
int
sh
,
int
quant
);
static
void
mb_shift_read
(
unsigned
char
*
in
,
unsigned
char
*
out
,
int
sh
,
int
quant
);
typedef
struct
{
io_sRack
*
rp
;
}
mb_sCondata
;
static
void
float_to_timeval
(
struct
timeval
*
tv
,
float
t
)
{
tv
->
tv_sec
=
t
;
tv
->
tv_usec
=
(
t
-
(
float
)
tv
->
tv_sec
)
*
1000000
;
}
static
void
float_to_timespec
(
struct
timespec
*
tv
,
float
t
)
{
tv
->
tv_sec
=
t
;
tv
->
tv_nsec
=
(
t
-
(
float
)
tv
->
tv_sec
)
*
1000000000
;
}
static
void
generate_crc
(
unsigned
char
*
buf
,
int
size
,
unsigned
char
*
result
)
{
unsigned
short
int
crc
;
unsigned
short
int
gen_polynomial
=
0xA001
;
unsigned
short
int
flag_mask
=
0x0001
;
unsigned
short
int
flag
;
int
i
,
j
;
crc
=
0xFFFF
;
for
(
i
=
0
;
i
<
size
;
i
++
)
{
crc
=
crc
^
buf
[
i
];
for
(
j
=
0
;
j
<
8
;
j
++
)
{
flag
=
crc
&
flag_mask
;
crc
=
crc
>>
1
;
if
(
flag
)
crc
=
crc
^
gen_polynomial
;
}
}
result
[
0
]
=
(
unsigned
char
)
(
crc
&
0x00FF
);
result
[
1
]
=
(
unsigned
char
)
((
crc
>>
8
)
&
0x00FF
);
}
static
pwr_tStatus
rtu_send
(
io_sServerLocal
*
local_master
,
pwr_sClass_Modbus_RTU_Server
*
op
,
void
*
bufp
,
int
buffer_size
)
{
int
sts
;
unsigned
char
*
buf
=
(
unsigned
char
*
)
bufp
;
struct
timespec
tf
;
generate_crc
(
buf
,
buffer_size
,
&
buf
[
buffer_size
]);
if
(
op
->
Debug
)
{
int
i
;
pwr_tTime
current
;
char
timstr
[
40
];
time_GetTime
(
&
current
);
time_AtoAscii
(
&
current
,
time_eFormat_Time
,
timstr
,
sizeof
(
timstr
));
printf
(
"Snd: %s %2d "
,
timstr
,
buffer_size
+
2
);
for
(
i
=
0
;
i
<
buffer_size
+
2
;
i
++
)
printf
(
"%02d "
,
buf
[
i
]);
printf
(
"
\n
"
);
}
float_to_timespec
(
&
tf
,
op
->
FrameTimeout
);
nanosleep
(
&
tf
,
NULL
);
sts
=
write
(
local_master
->
fd
,
buf
,
buffer_size
+
2
);
if
(
sts
<=
0
)
{
op
->
ErrorCount
++
;
return
0
;
}
return
1
;
}
static
void
*
mb_receive
(
void
*
data
)
{
io_sRack
*
rp
=
((
mb_sCondata
*
)
data
)
->
rp
;
io_sServerLocal
*
local_master
=
rp
->
Local
;
pwr_sClass_Modbus_RTU_Server
*
op
=
(
pwr_sClass_Modbus_RTU_Server
*
)
rp
->
op
;
int
data_size
=
0
;
rec_buf
*
rb
;
unsigned
char
fc
;
unsigned
char
exception_code
;
ssize_t
ssts
;
struct
timeval
tv
=
{
0
,
0
};
int
sts
;
fd_set
read_fd
;
unsigned
char
crc
[
2
];
unsigned
char
telegram
[
512
];
free
(
data
);
tcflush
(
local_master
->
fd
,
TCIOFLUSH
);
while
(
1
)
{
sts
=
1
;
data_size
=
0
;
float_to_timeval
(
&
tv
,
op
->
CharTimeout
);
FD_ZERO
(
&
read_fd
);
FD_SET
(
local_master
->
fd
,
&
read_fd
);
sts
=
select
(
local_master
->
fd
+
1
,
&
read_fd
,
NULL
,
NULL
,
&
tv
);
if
(
sts
==
0
)
continue
;
sts
=
read
(
local_master
->
fd
,
telegram
,
1
);
if
(
sts
<=
0
)
{
op
->
Status
=
MB__CONNLOST
;
continue
;
}
while
(
sts
>
0
)
{
data_size
++
;
if
(
data_size
>
256
)
{
data_size
=
0
;
break
;
}
float_to_timeval
(
&
tv
,
op
->
CharTimeout
);
FD_ZERO
(
&
read_fd
);
FD_SET
(
local_master
->
fd
,
&
read_fd
);
sts
=
select
(
local_master
->
fd
+
1
,
&
read_fd
,
NULL
,
NULL
,
&
tv
);
if
(
sts
==
0
)
{
break
;
}
sts
=
read
(
local_master
->
fd
,
telegram
+
data_size
,
1
);
}
if
(
data_size
<
2
)
{
op
->
ErrorCount
++
;
continue
;
}
if
(
op
->
Debug
)
{
int
i
;
pwr_tTime
current
;
char
timstr
[
40
];
time_GetTime
(
&
current
);
time_AtoAscii
(
&
current
,
time_eFormat_Time
,
timstr
,
sizeof
(
timstr
));
printf
(
"Rcv: %s %2d "
,
timstr
,
data_size
);
for
(
i
=
0
;
i
<
data_size
;
i
++
)
printf
(
"%02d "
,
telegram
[
i
]);
printf
(
"
\n
"
);
}
generate_crc
(
telegram
,
data_size
-
2
,
crc
);
if
(
crc
[
0
]
!=
telegram
[
data_size
-
2
]
||
crc
[
1
]
!=
telegram
[
data_size
-
1
])
{
op
->
ErrorCount
++
;
continue
;
}
op
->
RX_packets
++
;
rb
=
(
rec_buf
*
)
telegram
;
fc
=
rb
->
fc
;
time_GetTime
(
&
local_master
->
last_req_time
);
exception_code
=
0
;
switch
(
fc
)
{
case
pwr_eModbus_FCEnum_ReadHoldingRegisters
:
{
io_sCard
*
cardp
;
io_sServerModuleLocal
*
local_card
;
pwr_sClass_Modbus_RTU_ServerModule
*
mp
;
read_req
*
rmsg
=
(
read_req
*
)
rb
;
rsp_read
msg
;
int
found
;
short
addr
=
ntohs
(
rmsg
->
addr
);
short
quant
=
ntohs
(
rmsg
->
quant
);
unsigned
char
unit_id
=
rmsg
->
unit_id
;
if
(
quant
<
1
||
quant
>=
0x07d0
)
{
exception_code
=
3
;
break
;
}
/* Check the address */
found
=
0
;
for
(
cardp
=
rp
->
cardlist
;
cardp
;
cardp
=
cardp
->
next
)
{
mp
=
(
pwr_sClass_Modbus_RTU_ServerModule
*
)
cardp
->
op
;
if
(
mp
->
UnitId
==
unit_id
)
{
local_card
=
cardp
->
Local
;
found
=
1
;
break
;
}
}
if
(
!
found
)
{
exception_code
=
2
;
break
;
}
addr
-=
mp
->
ReadAddress
;
if
(
addr
<
0
||
addr
+
quant
*
2
>
local_card
->
output_size
)
{
exception_code
=
2
;
break
;
}
msg
.
fc
=
fc
;
msg
.
bc
=
quant
*
2
;
msg
.
unit_id
=
rmsg
->
unit_id
;
thread_MutexLock
(
&
local_master
->
mutex
);
memcpy
(
msg
.
buf
,
(
char
*
)
local_card
->
output_area
+
addr
,
quant
*
2
);
thread_MutexUnlock
(
&
local_master
->
mutex
);
ssts
=
rtu_send
(
local_master
,
op
,
&
msg
,
sizeof
(
msg
)
-
sizeof
(
msg
.
buf
)
+
quant
*
2
-
2
);
if
(
ssts
<
0
)
{
op
->
Status
=
MB__CONNLOST
;
break
;
}
op
->
Status
=
MB__NORMAL
;
op
->
TX_packets
++
;
break
;
}
case
pwr_eModbus_FCEnum_ReadCoils
:
case
pwr_eModbus_FCEnum_ReadDiscreteInputs
:
{
io_sCard
*
cardp
;
io_sServerModuleLocal
*
local_card
;
pwr_sClass_Modbus_RTU_ServerModule
*
mp
;
read_req
*
rmsg
=
(
read_req
*
)
rb
;
rsp_read
msg
;
int
found
;
unsigned
char
mask
;
unsigned
int
bytes
;
int
i
;
int
offs
;
short
addr
=
ntohs
(
rmsg
->
addr
);
short
quant
=
ntohs
(
rmsg
->
quant
);
unsigned
char
unit_id
=
rmsg
->
unit_id
;
if
(
quant
<
1
||
quant
>=
0x07d0
)
{
exception_code
=
3
;
break
;
}
/* Check the address */
found
=
0
;
for
(
cardp
=
rp
->
cardlist
;
cardp
;
cardp
=
cardp
->
next
)
{
mp
=
(
pwr_sClass_Modbus_RTU_ServerModule
*
)
cardp
->
op
;
if
(
mp
->
UnitId
==
unit_id
)
{
local_card
=
cardp
->
Local
;
found
=
1
;
break
;
}
}
if
(
!
found
)
{
exception_code
=
2
;
break
;
}
offs
=
addr
/
8
;
bytes
=
(
addr
+
quant
)
/
8
+
(((
addr
+
quant
)
%
8
==
0
)
?
0
:
1
)
-
offs
;
if
(
addr
<
0
||
offs
+
bytes
+
local_card
->
do_offset
>
local_card
->
output_size
||
offs
+
bytes
>
local_card
->
do_size
)
{
exception_code
=
2
;
break
;
}
memset
(
&
msg
,
0
,
sizeof
(
msg
));
msg
.
fc
=
fc
;
msg
.
bc
=
bytes
;
msg
.
unit_id
=
rmsg
->
unit_id
;
thread_MutexLock
(
&
local_master
->
mutex
);
if
(
addr
%
8
==
0
)
{
memcpy
(
msg
.
buf
,
(
char
*
)
local_card
->
output_area
+
local_card
->
do_offset
+
addr
/
8
,
bytes
);
mask
=
0
;
for
(
i
=
0
;
i
<
quant
%
8
;
i
++
)
mask
|=
1
<<
i
;
if
(
quant
%
8
!=
0
)
{
unsigned
char
*
b
=
(
unsigned
char
*
)
msg
.
buf
;
b
[
bytes
-
1
]
&=
mask
;
}
}
else
{
mb_shift_read
(
(
unsigned
char
*
)
local_card
->
output_area
+
local_card
->
do_offset
+
addr
/
8
,
(
unsigned
char
*
)
msg
.
buf
,
addr
%
8
,
quant
);
}
thread_MutexUnlock
(
&
local_master
->
mutex
);
ssts
=
rtu_send
(
local_master
,
op
,
&
msg
,
sizeof
(
msg
)
-
sizeof
(
msg
.
buf
)
+
bytes
-
2
);
if
(
ssts
<
0
)
{
op
->
Status
=
MB__CONNLOST
;
break
;
}
op
->
Status
=
MB__NORMAL
;
op
->
TX_packets
++
;
break
;
}
case
pwr_eModbus_FCEnum_WriteSingleRegister
:
{
io_sCard
*
cardp
;
io_sServerModuleLocal
*
local_card
;
pwr_sClass_Modbus_RTU_ServerModule
*
mp
;
write_single_req
*
rmsg
=
(
write_single_req
*
)
rb
;
rsp_single_write
msg
;
int
found
;
short
addr
=
ntohs
(
rmsg
->
addr
);
unsigned
char
unit_id
=
rmsg
->
unit_id
;
/* Check the address */
found
=
0
;
for
(
cardp
=
rp
->
cardlist
;
cardp
;
cardp
=
cardp
->
next
)
{
mp
=
(
pwr_sClass_Modbus_RTU_ServerModule
*
)
cardp
->
op
;
if
(
mp
->
UnitId
==
unit_id
)
{
local_card
=
cardp
->
Local
;
found
=
1
;
break
;
}
}
if
(
!
found
)
{
exception_code
=
2
;
break
;
}
addr
-=
mp
->
WriteAddress
;
if
(
addr
<
0
||
addr
+
2
>
local_card
->
input_size
)
{
exception_code
=
2
;
break
;
}
thread_MutexLock
(
&
local_master
->
mutex
);
memcpy
(
(
char
*
)
local_card
->
input_area
+
addr
,
&
rmsg
->
value
,
2
);
thread_MutexUnlock
(
&
local_master
->
mutex
);
msg
.
fc
=
fc
;
msg
.
addr
=
rmsg
->
addr
;
msg
.
value
=
rmsg
->
value
;
msg
.
unit_id
=
rmsg
->
unit_id
;
ssts
=
rtu_send
(
local_master
,
op
,
&
msg
,
sizeof
(
msg
)
-
2
);
if
(
ssts
<
0
)
{
op
->
Status
=
MB__CONNLOST
;
break
;
}
op
->
Status
=
MB__NORMAL
;
op
->
TX_packets
++
;
break
;
}
case
pwr_eModbus_FCEnum_WriteMultipleRegisters
:
{
io_sCard
*
cardp
;
io_sServerModuleLocal
*
local_card
;
pwr_sClass_Modbus_RTU_ServerModule
*
mp
;
write_reg_req
*
rmsg
=
(
write_reg_req
*
)
rb
;
rsp_write
msg
;
int
found
;
short
addr
=
ntohs
(
rmsg
->
addr
);
short
quant
=
ntohs
(
rmsg
->
quant
);
unsigned
char
unit_id
=
rmsg
->
unit_id
;
if
(
quant
<
1
||
quant
>=
0x07d0
)
{
exception_code
=
3
;
break
;
}
/* Check the address */
found
=
0
;
for
(
cardp
=
rp
->
cardlist
;
cardp
;
cardp
=
cardp
->
next
)
{
mp
=
(
pwr_sClass_Modbus_RTU_ServerModule
*
)
cardp
->
op
;
if
(
mp
->
UnitId
==
unit_id
)
{
local_card
=
cardp
->
Local
;
found
=
1
;
break
;
}
}
if
(
!
found
)
{
exception_code
=
2
;
break
;
}
addr
-=
mp
->
WriteAddress
;
if
(
addr
<
0
||
addr
+
quant
*
2
>
local_card
->
input_size
)
{
exception_code
=
2
;
break
;
}
thread_MutexLock
(
&
local_master
->
mutex
);
memcpy
(
(
char
*
)
local_card
->
input_area
+
addr
,
rmsg
->
reg
,
quant
*
2
);
thread_MutexUnlock
(
&
local_master
->
mutex
);
msg
.
fc
=
fc
;
msg
.
addr
=
rmsg
->
addr
;
msg
.
quant
=
rmsg
->
quant
;
msg
.
unit_id
=
rmsg
->
unit_id
;
ssts
=
rtu_send
(
local_master
,
op
,
&
msg
,
sizeof
(
msg
)
-
2
);
if
(
ssts
<
0
)
{
op
->
Status
=
MB__CONNLOST
;
break
;
}
op
->
Status
=
MB__NORMAL
;
op
->
TX_packets
++
;
break
;
}
case
pwr_eModbus_FCEnum_WriteSingleCoil
:
{
io_sCard
*
cardp
;
io_sServerModuleLocal
*
local_card
;
pwr_sClass_Modbus_RTU_ServerModule
*
mp
;
write_single_req
*
rmsg
=
(
write_single_req
*
)
rb
;
rsp_single_write
msg
;
int
found
;
unsigned
char
mask
;
int
offs
;
short
addr
=
ntohs
(
rmsg
->
addr
);
unsigned
short
value
=
ntohs
(
rmsg
->
value
);
unsigned
char
unit_id
=
rmsg
->
unit_id
;
/* Check the address */
found
=
0
;
for
(
cardp
=
rp
->
cardlist
;
cardp
;
cardp
=
cardp
->
next
)
{
mp
=
(
pwr_sClass_Modbus_RTU_ServerModule
*
)
cardp
->
op
;
if
(
mp
->
UnitId
==
unit_id
)
{
local_card
=
cardp
->
Local
;
found
=
1
;
break
;
}
}
if
(
!
found
)
{
exception_code
=
2
;
break
;
}
offs
=
addr
/
8
;
if
(
addr
<
0
||
offs
+
local_card
->
di_offset
>=
local_card
->
input_size
||
offs
>=
local_card
->
di_size
)
{
exception_code
=
2
;
break
;
}
mask
=
1
<<
(
addr
%
8
);
if
(
value
==
0xFF00
||
value
==
0
)
{
thread_MutexLock
(
&
local_master
->
mutex
);
if
(
value
==
0xFF00
)
*
((
char
*
)
local_card
->
input_area
+
local_card
->
di_offset
+
offs
)
|=
mask
;
else
*
((
char
*
)
local_card
->
input_area
+
local_card
->
di_offset
+
offs
)
&=
~
mask
;
thread_MutexUnlock
(
&
local_master
->
mutex
);
}
msg
.
fc
=
fc
;
msg
.
addr
=
rmsg
->
addr
;
msg
.
value
=
rmsg
->
value
;
msg
.
unit_id
=
rmsg
->
unit_id
;
ssts
=
rtu_send
(
local_master
,
op
,
&
msg
,
sizeof
(
msg
)
-
2
);
if
(
ssts
<
0
)
{
op
->
Status
=
MB__CONNLOST
;
break
;
}
op
->
Status
=
MB__NORMAL
;
op
->
TX_packets
++
;
break
;
}
case
pwr_eModbus_FCEnum_WriteMultipleCoils
:
{
io_sCard
*
cardp
;
io_sServerModuleLocal
*
local_card
;
pwr_sClass_Modbus_RTU_ServerModule
*
mp
;
write_reg_req
*
rmsg
=
(
write_reg_req
*
)
rb
;
rsp_write
msg
;
int
found
;
unsigned
char
mask
;
unsigned
int
bytes
;
int
i
;
int
offs
;
short
addr
=
ntohs
(
rmsg
->
addr
);
short
quant
=
ntohs
(
rmsg
->
quant
);
unsigned
char
unit_id
=
rmsg
->
unit_id
;
if
(
quant
<
1
||
quant
>=
0x07d0
)
{
exception_code
=
3
;
break
;
}
/* Check the address */
found
=
0
;
for
(
cardp
=
rp
->
cardlist
;
cardp
;
cardp
=
cardp
->
next
)
{
mp
=
(
pwr_sClass_Modbus_RTU_ServerModule
*
)
cardp
->
op
;
if
(
mp
->
UnitId
==
unit_id
)
{
local_card
=
cardp
->
Local
;
found
=
1
;
break
;
}
}
if
(
!
found
)
{
exception_code
=
2
;
break
;
}
thread_MutexLock
(
&
local_master
->
mutex
);
offs
=
addr
/
8
;
bytes
=
(
addr
+
quant
)
/
8
+
(((
addr
+
quant
)
%
8
==
0
)
?
0
:
1
)
-
offs
;
if
(
addr
<
0
||
offs
+
bytes
+
local_card
->
di_offset
>
local_card
->
input_size
||
offs
+
bytes
>
local_card
->
di_size
)
{
exception_code
=
2
;
break
;
}
if
(
addr
%
8
==
0
)
{
if
(
quant
%
8
!=
0
)
{
mask
=
0
;
for
(
i
=
0
;
i
<
quant
%
8
;
i
++
)
mask
|=
1
<<
i
;
memcpy
(
(
char
*
)
local_card
->
input_area
+
local_card
->
di_offset
+
addr
/
8
,
rmsg
->
reg
,
bytes
-
1
);
*
((
char
*
)
local_card
->
input_area
+
local_card
->
di_offset
+
addr
/
8
+
bytes
-
1
)
&=
~
mask
;
*
((
char
*
)
local_card
->
input_area
+
local_card
->
di_offset
+
addr
/
8
+
bytes
-
1
)
|=
*
((
char
*
)
rmsg
->
reg
+
bytes
-
1
)
&
mask
;
}
else
memcpy
(
(
char
*
)
local_card
->
input_area
+
local_card
->
di_offset
+
addr
/
8
,
rmsg
->
reg
,
bytes
);
}
else
{
mb_shift_write
(
(
unsigned
char
*
)
rmsg
->
reg
,
(
unsigned
char
*
)
local_card
->
input_area
+
local_card
->
di_offset
+
addr
/
8
,
addr
%
8
,
quant
);
}
thread_MutexUnlock
(
&
local_master
->
mutex
);
msg
.
fc
=
fc
;
msg
.
addr
=
rmsg
->
addr
;
msg
.
quant
=
rmsg
->
quant
;
msg
.
unit_id
=
rmsg
->
unit_id
;
ssts
=
rtu_send
(
local_master
,
op
,
&
msg
,
sizeof
(
msg
)
-
2
);
if
(
ssts
<
0
)
{
op
->
Status
=
MB__CONNLOST
;
break
;
}
op
->
Status
=
MB__NORMAL
;
op
->
TX_packets
++
;
break
;
}
case
43
:
{
/* Encapsulated Interface Transport, Read Device Identification */
read_dev_id_req
*
rmsg
=
(
read_dev_id_req
*
)
rb
;
rsp_dev_id
msg
;
int
i
;
int
len
;
if
(
rmsg
->
mei_type
!=
0x2b
)
{
exception_code
=
1
;
break
;
}
if
(
rmsg
->
id_code
!=
1
)
{
exception_code
=
1
;
break
;
}
if
(
rmsg
->
object_id
!=
0
)
{
exception_code
=
1
;
break
;
}
msg
.
fc
=
rmsg
->
fc
;
msg
.
mei_type
=
rmsg
->
mei_type
;
msg
.
id_code
=
rmsg
->
id_code
;
msg
.
conformity_level
=
1
;
msg
.
more_follows
=
0
;
msg
.
next_object_id
=
0
;
msg
.
number_of_objects
=
3
;
i
=
0
;
/* Vendor name */
msg
.
list
[
i
++
]
=
0
;
len
=
strlen
(
"Proview"
);
msg
.
list
[
i
++
]
=
len
;
strncpy
(
(
char
*
)
&
msg
.
list
[
i
],
"Proview"
,
len
);
i
+=
len
;
/* Product code */
msg
.
list
[
i
++
]
=
0
;
len
=
strlen
(
"-"
);
msg
.
list
[
i
++
]
=
len
;
strncpy
(
(
char
*
)
&
msg
.
list
[
i
],
"-"
,
len
);
i
+=
len
;
/* Major Minor Revision */
msg
.
list
[
i
++
]
=
0
;
len
=
strlen
(
pwrv_cPwrVersionStr
);
msg
.
list
[
i
++
]
=
len
;
strncpy
(
(
char
*
)
&
msg
.
list
[
i
],
pwrv_cPwrVersionStr
,
len
);
i
+=
len
;
msg
.
unit_id
=
rmsg
->
unit_id
;
ssts
=
rtu_send
(
local_master
,
op
,
&
msg
,
sizeof
(
msg
)
-
sizeof
(
msg
.
list
)
+
1
-
2
);
if
(
ssts
<
0
)
{
op
->
Status
=
MB__CONNLOST
;
break
;
}
op
->
Status
=
MB__NORMAL
;
op
->
TX_packets
++
;
break
;
}
default:
exception_code
=
1
;
}
if
(
exception_code
)
{
rsp_fault
rsp_f
;
rsp_f
.
fc
=
fc
+
0x80
;
rsp_f
.
ec
=
exception_code
;
rsp_f
.
unit_id
=
rb
->
unit_id
;
ssts
=
rtu_send
(
local_master
,
op
,
&
rsp_f
,
sizeof
(
rsp_f
)
-
2
);
if
(
ssts
<
0
)
{
op
->
Status
=
MB__CONNLOST
;
break
;
}
op
->
Status
=
MB__NORMAL
;
op
->
TX_packets
++
;
}
}
return
0
;
}
/*----------------------------------------------------------------------------*\
Init method for the Modbus/RTU server
\*----------------------------------------------------------------------------*/
static
pwr_tStatus
IoRackInit
(
io_tCtx
ctx
,
io_sAgent
*
ap
,
io_sRack
*
rp
)
{
struct
termios
tty_attributes
;
io_sServerLocal
*
local
;
pwr_tStatus
sts
;
pwr_sClass_Modbus_RTU_Server
*
op
;
pwr_tOName
name
;
mb_sCondata
*
condata
;
op
=
(
pwr_sClass_Modbus_RTU_Server
*
)
rp
->
op
;
sts
=
gdh_ObjidToName
(
rp
->
Objid
,
(
char
*
)
&
name
,
sizeof
(
name
),
cdh_mNName
);
errh_Info
(
"Init of Modbus RTU Server %s"
,
name
);
rp
->
Local
=
calloc
(
1
,
sizeof
(
io_sServerLocal
));
local
=
rp
->
Local
;
if
(
op
->
DisableServer
)
return
IO__SUCCESS
;
local
->
fd
=
open
(
op
->
Device
,
O_RDWR
|
O_NDELAY
|
O_NOCTTY
);
if
(
local
->
fd
==
-
1
)
{
errh_Error
(
"Modbus RTU Master, open device error, %s"
,
ap
->
Name
);
return
IO__ERRINIDEVICE
;
}
tcgetattr
(
local
->
fd
,
&
tty_attributes
);
tty_attributes
.
c_cc
[
VMIN
]
=
1
;
tty_attributes
.
c_cc
[
VTIME
]
=
0
;
tty_attributes
.
c_lflag
&=
~
(
ICANON
|
ISIG
|
ECHO
|
IEXTEN
);
tty_attributes
.
c_cflag
|=
(
CLOCAL
|
CREAD
);
tty_attributes
.
c_oflag
&=
~
(
OPOST
);
tty_attributes
.
c_oflag
&=
~
(
ONLCR
);
tty_attributes
.
c_iflag
&=
~
(
INLCR
|
ICRNL
);
/* Speed */
#if defined OS_LINUX
tty_attributes
.
c_cflag
&=
~
CBAUD
;
#endif
switch
(
op
->
Speed
)
{
case
300
:
tty_attributes
.
c_cflag
|=
B300
;
break
;
case
1200
:
tty_attributes
.
c_cflag
|=
B1200
;
break
;
case
2400
:
tty_attributes
.
c_cflag
|=
B2400
;
break
;
case
4800
:
tty_attributes
.
c_cflag
|=
B4800
;
break
;
case
9600
:
tty_attributes
.
c_cflag
|=
B9600
;
break
;
case
19200
:
tty_attributes
.
c_cflag
|=
B19200
;
break
;
case
38400
:
tty_attributes
.
c_cflag
|=
B38400
;
break
;
case
57600
:
tty_attributes
.
c_cflag
|=
B57600
;
break
;
case
115200
:
tty_attributes
.
c_cflag
|=
B115200
;
break
;
default:
errh_Error
(
"Modbus RTU Master, unsupported speed, %s"
,
ap
->
Name
);
tty_attributes
.
c_cflag
|=
B9600
;
break
;
}
/* DataBits 5, 6, 7 or 8 */
tty_attributes
.
c_cflag
&=
~
CSIZE
;
switch
(
op
->
DataBits
)
{
case
pwr_eDataBitsEnum_5
:
tty_attributes
.
c_cflag
|=
CS5
;
break
;
case
pwr_eDataBitsEnum_6
:
tty_attributes
.
c_cflag
|=
CS6
;
break
;
case
pwr_eDataBitsEnum_7
:
tty_attributes
.
c_cflag
|=
CS7
;
break
;
case
pwr_eDataBitsEnum_8
:
tty_attributes
.
c_cflag
|=
CS8
;
break
;
default:
errh_Error
(
"Modbus RTU Master, unsupported DataBits, %s"
,
ap
->
Name
);
tty_attributes
.
c_cflag
|=
CS8
;
}
//tty_attributes.c_iflag |=ISTRIP;
/* Parity */
switch
(
op
->
Parity
)
{
case
pwr_eParityEnum_Odd
:
case
pwr_eParityEnum_Even
:
tty_attributes
.
c_cflag
|=
PARENB
;
tty_attributes
.
c_iflag
|=
IGNPAR
;
if
(
op
->
Parity
==
pwr_eParityEnum_Even
)
tty_attributes
.
c_cflag
&=
~
PARODD
;
else
tty_attributes
.
c_cflag
|=
PARODD
;
break
;
default:
tty_attributes
.
c_cflag
&=
~
PARENB
;
}
/* stopbitsval */
switch
(
op
->
StopBits
)
{
case
pwr_eStopBitsEnum_2
:
tty_attributes
.
c_cflag
|=
CSTOPB
;
break
;
case
pwr_eStopBitsEnum_1
:
tty_attributes
.
c_cflag
&=~
CSTOPB
;
break
;
case
pwr_eStopBitsEnum_0
:
errh_Error
(
"Modbus RTU Master, unsupported StopBits, %s"
,
ap
->
Name
);
tty_attributes
.
c_cflag
&=~
CSTOPB
;
break
;
}
tty_attributes
.
c_iflag
&=
~
IXON
;
//ingen XON/XOFF in
//tty_attributes.c_iflag &= (V_IGNCR);
//tty_attributes.c_iflag &= (IGNPAR | V_IGNCR);
//tty_attributes.c_iflag &= ~(BRKINT | IXON | V_INLCR | V_ICRNL);
//tty_attributes.c_cflag &= ~(CSIZE | CSTOPB | PARENB); //fippla om vrden lite granna
sts
=
tcsetattr
(
local
->
fd
,
TCSANOW
,
&
tty_attributes
);
if
(
sts
<
0
)
{
errh_Error
(
"Modbus RTU Master, set device attributes error, %s"
,
ap
->
Name
);
return
IO__ERRINIDEVICE
;
}
sts
=
mb_init_channels
(
ctx
,
ap
,
rp
);
if
(
EVEN
(
sts
))
return
sts
;
/* Create mutex */
sts
=
thread_MutexInit
(
&
local
->
mutex
);
if
(
EVEN
(
sts
))
{
errh_Error
(
"Error creating mutex IO modbus rtu server %s"
,
rp
->
Name
);
return
IO__ERRINIDEVICE
;
}
/* Create a thread for receive */
condata
=
(
mb_sCondata
*
)
malloc
(
sizeof
(
mb_sCondata
));
condata
->
rp
=
rp
;
sts
=
thread_Create
(
&
local
->
receive_thread
,
0
,
mb_receive
,
(
void
*
)
condata
);
if
(
EVEN
(
sts
))
{
errh_Error
(
"Error creating receive thread IO modbus rtu server %s"
,
rp
->
Name
);
free
(
condata
);
return
IO__ERRINIDEVICE
;
}
op
->
Status
=
MB__NORMAL
;
return
IO__SUCCESS
;
}
static
pwr_tStatus
mb_init_channels
(
io_tCtx
ctx
,
io_sAgent
*
ap
,
io_sRack
*
rp
)
{
io_sServerModuleLocal
*
local_card
;
io_sCard
*
cardp
;
io_sServerLocal
*
local
;
short
input_counter
;
short
output_counter
;
short
card_input_counter
;
short
card_output_counter
;
pwr_sClass_Modbus_RTU_Server
*
op
;
pwr_sClass_Modbus_RTU_ServerModule
*
mp
;
char
name
[
196
];
pwr_tStatus
sts
;
pwr_tCid
cid
;
io_sChannel
*
chanp
;
int
i
,
latent_input_counter
,
latent_output_counter
;
pwr_tInt32
chan_size
;
pwr_sClass_ChanDi
*
chan_di
;
pwr_sClass_ChanDo
*
chan_do
;
pwr_sClass_ChanAi
*
chan_ai
;
pwr_sClass_ChanAit
*
chan_ait
;
pwr_sClass_ChanIi
*
chan_ii
;
pwr_sClass_ChanAo
*
chan_ao
;
pwr_sClass_ChanIo
*
chan_io
;
sts
=
gdh_ObjidToName
(
rp
->
Objid
,
(
char
*
)
&
name
,
sizeof
(
name
),
cdh_mNName
);
op
=
(
pwr_sClass_Modbus_RTU_Server
*
)
rp
->
op
;
local
=
rp
->
Local
;
/* Create socket, store in local struct */
/* Do configuration check and initialize modules. */
cardp
=
rp
->
cardlist
;
input_counter
=
0
;
output_counter
=
0
;
card_input_counter
=
0
;
card_output_counter
=
0
;
latent_input_counter
=
0
;
latent_output_counter
=
0
;
while
(
cardp
)
{
local_card
=
calloc
(
1
,
sizeof
(
*
local_card
));
cardp
->
Local
=
local_card
;
input_counter
=
input_counter
+
card_input_counter
+
latent_input_counter
;
output_counter
=
output_counter
+
card_output_counter
+
latent_output_counter
;
local_card
->
input_area
=
(
void
*
)
&
(
op
->
Inputs
)
+
input_counter
;
local_card
->
output_area
=
(
void
*
)
&
(
op
->
Outputs
)
+
output_counter
;
card_input_counter
=
0
;
card_output_counter
=
0
;
latent_input_counter
=
0
;
latent_output_counter
=
0
;
/* From v4.1.3 we can have subclasses, find the super class */
cid
=
cardp
->
Class
;
while
(
ODD
(
gdh_GetSuperClass
(
cid
,
&
cid
,
cardp
->
Objid
)))
;
switch
(
cid
)
{
case
pwr_cClass_Modbus_RTU_ServerModule
:
mp
=
(
pwr_sClass_Modbus_RTU_ServerModule
*
)
cardp
->
op
;
mp
->
Status
=
pwr_eModbusModule_StatusEnum_StatusUnknown
;
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
->
cop
)
->
Number
;
chanp
->
size
=
GetChanSize
(
((
pwr_sClass_ChanIi
*
)
chanp
->
cop
)
->
Representation
);
break
;
default:
errh_Error
(
"Diagnostic channel class, card %s"
,
cardp
->
Name
);
}
continue
;
}
if
(
chanp
->
ChanClass
!=
pwr_cClass_ChanDi
)
{
card_input_counter
+=
latent_input_counter
;
latent_input_counter
=
0
;
}
if
(
chanp
->
ChanClass
!=
pwr_cClass_ChanDo
)
{
card_output_counter
+=
latent_output_counter
;
latent_output_counter
=
0
;
}
switch
(
chanp
->
ChanClass
)
{
case
pwr_cClass_ChanDi
:
chan_di
=
(
pwr_sClass_ChanDi
*
)
chanp
->
cop
;
if
(
chan_di
->
Number
==
0
)
{
card_input_counter
+=
latent_input_counter
;
latent_input_counter
=
0
;
}
chanp
->
offset
=
card_input_counter
;
chanp
->
mask
=
1
<<
chan_di
->
Number
;
if
(
chan_di
->
Representation
==
pwr_eDataRepEnum_Bit16
)
chanp
->
mask
=
swap16
(
chanp
->
mask
);
if
(
chan_di
->
Representation
==
pwr_eDataRepEnum_Bit32
)
chanp
->
mask
=
swap32
((
unsigned
short
)
chanp
->
mask
);
if
(
chan_di
->
Number
==
0
)
latent_input_counter
=
GetChanSize
(
chan_di
->
Representation
);
if
(
local_card
->
di_size
==
0
)
local_card
->
di_offset
=
chanp
->
offset
;
if
(
chan_di
->
Number
==
0
||
local_card
->
di_size
==
0
)
local_card
->
di_size
+=
GetChanSize
(
chan_di
->
Representation
);
// printf("Di channel found in %s, Number %d, Offset %d\n", cardp->Name, chan_di->Number, chanp->offset);
break
;
case
pwr_cClass_ChanAi
:
chan_ai
=
(
pwr_sClass_ChanAi
*
)
chanp
->
cop
;
chanp
->
offset
=
card_input_counter
;
chan_size
=
GetChanSize
(
chan_ai
->
Representation
);
chanp
->
size
=
chan_size
;
chanp
->
mask
=
0
;
card_input_counter
+=
chan_size
;
io_AiRangeToCoef
(
chanp
);
// printf("Ai channel found in %s, Number %d, Offset %d\n", cardp->Name, chan_ai->Number, chanp->offset);
break
;
case
pwr_cClass_ChanAit
:
chan_ait
=
(
pwr_sClass_ChanAit
*
)
chanp
->
cop
;
chanp
->
offset
=
card_input_counter
;
chan_size
=
GetChanSize
(
chan_ait
->
Representation
);
chanp
->
size
=
chan_size
;
chanp
->
mask
=
0
;
card_input_counter
+=
chan_size
;
io_AiRangeToCoef
(
chanp
);
break
;
case
pwr_cClass_ChanIi
:
chan_ii
=
(
pwr_sClass_ChanIi
*
)
chanp
->
cop
;
chanp
->
offset
=
card_input_counter
;
chan_size
=
GetChanSize
(
chan_ii
->
Representation
);
chanp
->
size
=
chan_size
;
chanp
->
mask
=
0
;
card_input_counter
+=
chan_size
;
// printf("Ii channel found in %s, Number %d, Offset %d\n", cardp->Name, chan_ii->Number, chanp->offset);
break
;
case
pwr_cClass_ChanDo
:
chan_do
=
(
pwr_sClass_ChanDo
*
)
chanp
->
cop
;
if
(
chan_do
->
Number
==
0
)
{
card_output_counter
+=
latent_output_counter
;
latent_output_counter
=
0
;
}
chanp
->
offset
=
card_output_counter
;
chan_size
=
GetChanSize
(
chan_do
->
Representation
);
chanp
->
mask
=
1
<<
chan_do
->
Number
;
if
(
chan_do
->
Representation
==
pwr_eDataRepEnum_Bit16
)
chanp
->
mask
=
swap16
(
chanp
->
mask
);
if
(
chan_do
->
Representation
==
pwr_eDataRepEnum_Bit32
)
chanp
->
mask
=
swap32
((
unsigned
short
)
chanp
->
mask
);
if
(
chan_do
->
Number
==
0
)
latent_output_counter
=
GetChanSize
(
chan_do
->
Representation
);
if
(
local_card
->
do_size
==
0
)
local_card
->
do_offset
=
chanp
->
offset
;
if
(
chan_do
->
Number
==
0
||
local_card
->
do_size
==
0
)
local_card
->
do_size
+=
GetChanSize
(
chan_do
->
Representation
);
// printf("Do channel found in %s, Number %d, Offset %d\n", cardp->Name, chan_do->Number, chanp->offset);
break
;
case
pwr_cClass_ChanAo
:
chan_ao
=
(
pwr_sClass_ChanAo
*
)
chanp
->
cop
;
chanp
->
offset
=
card_output_counter
;
chan_size
=
GetChanSize
(
chan_ao
->
Representation
);
chanp
->
size
=
chan_size
;
chanp
->
mask
=
0
;
card_output_counter
+=
chan_size
;
io_AoRangeToCoef
(
chanp
);
// printf("Ao channel found in %s, Number %d, Offset %d\n", cardp->Name, chan_ao->Number, chanp->offset);
break
;
case
pwr_cClass_ChanIo
:
chan_io
=
(
pwr_sClass_ChanIo
*
)
chanp
->
cop
;
chanp
->
offset
=
card_output_counter
;
chan_size
=
GetChanSize
(
chan_io
->
Representation
);
chanp
->
size
=
chan_size
;
chanp
->
mask
=
0
;
card_output_counter
+=
chan_size
;
// printf("Io channel found in %s, Number %d, Offset %d\n", cardp->Name, chan_io->Number, chanp->offset);
break
;
}
}
/* End - for ... */
break
;
}
/* End - switch ... */
local_card
->
input_size
=
card_input_counter
+
latent_input_counter
;
local_card
->
output_size
=
card_output_counter
+
latent_output_counter
;
cardp
=
cardp
->
next
;
}
local
->
input_size
=
input_counter
+
card_input_counter
+
latent_input_counter
;
local
->
output_size
=
output_counter
+
card_output_counter
+
latent_output_counter
;
return
IO__SUCCESS
;
}
static
void
mb_shift_write
(
unsigned
char
*
in
,
unsigned
char
*
out
,
int
sh
,
int
quant
)
{
int
i
;
if
(
sh
+
quant
<=
8
)
{
unsigned
char
mask
=
0
;
for
(
i
=
sh
;
i
<
sh
+
quant
;
i
++
)
mask
|=
1
<<
i
;
out
[
0
]
&=
~
mask
;
out
[
0
]
|=
mask
&
(
in
[
0
]
<<
sh
);
return
;
}
for
(
i
=
0
;
i
<
(
quant
+
sh
)
/
8
;
i
++
)
{
if
(
i
==
0
)
{
unsigned
char
mask
=
~
0
<<
sh
;
out
[
0
]
&=
~
mask
;
out
[
0
]
|=
mask
&
(
in
[
0
]
<<
sh
);
}
else
{
out
[
i
]
=
in
[
i
]
<<
sh
;
out
[
i
]
|=
in
[
i
-
1
]
>>
(
8
-
sh
);
}
}
if
(
(
quant
+
sh
)
%
8
!=
0
)
{
unsigned
char
mask
=
~
0
<<
((
quant
+
sh
)
%
8
);
mask
=
~
mask
;
out
[
i
]
&=
~
mask
;
out
[
i
]
|=
mask
&
(
in
[
i
]
<<
sh
);
out
[
i
]
|=
mask
&
(
in
[
i
-
1
]
>>
(
8
-
sh
));
}
}
void
mb_shift_read
(
unsigned
char
*
in
,
unsigned
char
*
out
,
int
sh
,
int
quant
)
{
int
i
;
if
(
sh
+
quant
<=
8
)
{
unsigned
char
mask
=
~
0
;
mask
=
mask
>>
(
8
-
quant
);
out
[
0
]
=
mask
&
(
in
[
0
]
>>
sh
);
return
;
}
for
(
i
=
0
;
i
<
quant
/
8
;
i
++
)
{
out
[
i
]
=
in
[
i
]
>>
sh
;
out
[
i
]
|=
in
[
i
+
1
]
<<
(
8
-
sh
);
}
out
[
i
]
=
in
[
i
]
>>
sh
;
if
(
(
quant
+
sh
)
/
8
>
quant
/
8
)
out
[
i
]
|=
in
[
i
+
1
]
<<
(
8
-
sh
);
if
(
quant
%
8
!=
0
)
{
unsigned
char
mask
=
~
0
;
mask
=
mask
>>
(
8
-
(
quant
%
8
));
out
[
i
]
&=
mask
;
}
}
/*----------------------------------------------------------------------------*\
Read method for the Modbus RTU server
\*----------------------------------------------------------------------------*/
static
pwr_tStatus
IoRackRead
(
io_tCtx
ctx
,
io_sAgent
*
ap
,
io_sRack
*
rp
)
{
return
IO__SUCCESS
;
}
/*----------------------------------------------------------------------------*\
Write method for the Modbus_RTU server
\*----------------------------------------------------------------------------*/
static
pwr_tStatus
IoRackWrite
(
io_tCtx
ctx
,
io_sAgent
*
ap
,
io_sRack
*
rp
)
{
return
IO__SUCCESS
;
}
/*----------------------------------------------------------------------------*\
\*----------------------------------------------------------------------------*/
static
pwr_tStatus
IoRackClose
(
io_tCtx
ctx
,
io_sAgent
*
ap
,
io_sRack
*
rp
)
{
io_sServerLocal
*
local
=
rp
->
Local
;
close
(
local
->
fd
);
return
IO__SUCCESS
;
}
/*----------------------------------------------------------------------------*\
Every method to be exported to the workbench should be registred here.
\*----------------------------------------------------------------------------*/
pwr_dExport
pwr_BindIoMethods
(
Modbus_RTU_Server
)
=
{
pwr_BindIoMethod
(
IoRackInit
),
pwr_BindIoMethod
(
IoRackRead
),
pwr_BindIoMethod
(
IoRackWrite
),
pwr_BindIoMethod
(
IoRackClose
),
pwr_NullMethod
};
otherio/lib/rt/src/os_templ/rt_io_m_mb_rtu_servermodule.c
0 → 100644
View file @
4a587916
/*
* Proview Open Source Process Control.
* Copyright (C) 2005-2012 SSAB EMEA AB.
*
* This file is part of Proview.
*
* 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 Proview. If not, see <http://www.gnu.org/licenses/>
*
* Linking Proview statically or dynamically with other modules is
* making a combined work based on Proview. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* Proview give you permission to, from the build function in the
* Proview Configurator, combine Proview with modules generated by the
* Proview PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of Proview (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <math.h>
#include <sys/file.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <unistd.h>
#include "pwr.h"
#include "pwr_baseclasses.h"
#include "pwr_basecomponentclasses.h"
#include "pwr_otherioclasses.h"
#include "rt_io_base.h"
#include "rt_io_msg.h"
#include "rt_errh.h"
#include "rt_io_bus.h"
#include "rt_mb_msg.h"
#include "rt_io_mb_rtu.h"
#include "co_time.h"
/*----------------------------------------------------------------------------*\
Init method for the Modbus server module
\*----------------------------------------------------------------------------*/
static
pwr_tStatus
IoCardInit
(
io_tCtx
ctx
,
io_sAgent
*
ap
,
io_sRack
*
rp
,
io_sCard
*
cp
)
{
io_sServerModuleLocal
*
local
;
pwr_sClass_Modbus_RTU_ServerModule
*
op
;
int
i
;
op
=
(
pwr_sClass_Modbus_RTU_ServerModule
*
)
cp
->
op
;
local
=
(
io_sServerModuleLocal
*
)
cp
->
Local
;
for
(
i
=
0
;
i
<
IO_MAXCHAN
;
i
++
)
{
local
->
scancount
[
i
]
=
0
;
}
op
->
Status
=
pwr_eModbusModule_StatusEnum_StatusUnknown
;
return
IO__SUCCESS
;
}
/*----------------------------------------------------------------------------*\
Read method for the Modbus RTU server module
\*----------------------------------------------------------------------------*/
static
pwr_tStatus
IoCardRead
(
io_tCtx
ctx
,
io_sAgent
*
ap
,
io_sRack
*
rp
,
io_sCard
*
cp
)
{
io_sServerModuleLocal
*
local
;
io_sServerLocal
*
local_server
;
pwr_sClass_Modbus_RTU_ServerModule
*
op
;
pwr_sClass_Modbus_RTU_Server
*
server
;
op
=
(
pwr_sClass_Modbus_RTU_ServerModule
*
)
cp
->
op
;
local
=
(
io_sServerModuleLocal
*
)
cp
->
Local
;
server
=
(
pwr_sClass_Modbus_RTU_Server
*
)
rp
->
op
;
local_server
=
(
io_sServerLocal
*
)
rp
->
Local
;
if
(
server
->
DisableServer
||
!
local
)
return
IO__SUCCESS
;
if
(
server
->
Status
==
MB__NORMAL
)
{
thread_MutexLock
(
&
local_server
->
mutex
);
io_bus_card_read
(
ctx
,
rp
,
cp
,
local
->
input_area
,
NULL
,
pwr_eByteOrderingEnum_BigEndian
,
pwr_eFloatRepEnum_FloatIntel
);
thread_MutexUnlock
(
&
local_server
->
mutex
);
}
// printf("Method Modbus_Module-IoCardRead\n");
return
IO__SUCCESS
;
}
/*----------------------------------------------------------------------------*\
Write method for the Modbus RTU server module
\*----------------------------------------------------------------------------*/
static
pwr_tStatus
IoCardWrite
(
io_tCtx
ctx
,
io_sAgent
*
ap
,
io_sRack
*
rp
,
io_sCard
*
cp
)
{
io_sServerModuleLocal
*
local
;
io_sServerLocal
*
local_server
;
pwr_sClass_Modbus_RTU_ServerModule
*
op
;
pwr_sClass_Modbus_RTU_Server
*
server
;
op
=
(
pwr_sClass_Modbus_RTU_ServerModule
*
)
cp
->
op
;
local
=
(
io_sServerModuleLocal
*
)
cp
->
Local
;
server
=
(
pwr_sClass_Modbus_RTU_Server
*
)
rp
->
op
;
local_server
=
(
io_sServerLocal
*
)
rp
->
Local
;
if
(
server
->
DisableServer
||
!
local
)
return
IO__SUCCESS
;
if
(
server
->
Status
==
MB__NORMAL
)
{
thread_MutexLock
(
&
local_server
->
mutex
);
io_bus_card_write
(
ctx
,
cp
,
local
->
output_area
,
pwr_eByteOrderingEnum_BigEndian
,
pwr_eFloatRepEnum_FloatIntel
);
thread_MutexUnlock
(
&
local_server
->
mutex
);
}
// printf("Method Modbus_Module-IoCardWrite\n");
return
IO__SUCCESS
;
}
/*----------------------------------------------------------------------------*\
Every method to be exported to the workbench should be registred here.
\*----------------------------------------------------------------------------*/
pwr_dExport
pwr_BindIoMethods
(
Modbus_RTU_ServerModule
)
=
{
pwr_BindIoMethod
(
IoCardInit
),
pwr_BindIoMethod
(
IoCardRead
),
pwr_BindIoMethod
(
IoCardWrite
),
pwr_NullMethod
};
otherio/lib/rt/src/os_templ/rt_io_m_mb_rtu_slave.c
0 → 100644
View file @
4a587916
/*
* Proview Open Source Process Control.
* Copyright (C) 2005-2012 SSAB EMEA AB.
*
* This file is part of Proview.
*
* 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 Proview. If not, see <http://www.gnu.org/licenses/>
*
* Linking Proview statically or dynamically with other modules is
* making a combined work based on Proview. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* Proview give you permission to, from the build function in the
* Proview Configurator, combine Proview with modules generated by the
* Proview PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of Proview (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
*/
/* rt_io_m_mb_rtu_slave.c -- io methods for a Modbus RTU slave */
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <sys/file.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include "pwr.h"
#include "co_cdh.h"
#include "pwr_baseclasses.h"
#include "pwr_basecomponentclasses.h"
#include "pwr_otherioclasses.h"
#include "rt_gdh.h"
#include "rt_io_base.h"
#include "rt_io_bus.h"
#include "rt_io_msg.h"
#include "rt_errh.h"
#include "co_cdh.h"
#include "co_time.h"
#include "rt_mb_msg.h"
#include "rt_io_mb_rtu.h"
/*----------------------------------------------------------------------------*\
Init method for the Modbus_TCP slave
\*----------------------------------------------------------------------------*/
static
pwr_tStatus
IoRackInit
(
io_tCtx
ctx
,
io_sAgent
*
ap
,
io_sRack
*
rp
)
{
io_sCardLocal
*
local_card
;
io_sCard
*
cardp
;
io_sRackLocal
*
local
;
int
no_di
;
int
no_do
;
pwr_sClass_Modbus_RTU_Slave
*
op
;
char
name
[
196
];
pwr_tStatus
sts
;
pwr_tCid
cid
;
io_sChannel
*
chanp
;
int
i
;
sts
=
gdh_ObjidToName
(
rp
->
Objid
,
(
char
*
)
&
name
,
sizeof
(
name
),
cdh_mNName
);
errh_Info
(
"Init of Modbus TCP Slave and Modules %s"
,
name
);
op
=
(
pwr_sClass_Modbus_RTU_Slave
*
)
rp
->
op
;
rp
->
Local
=
calloc
(
1
,
sizeof
(
io_sRackLocal
));
local
=
rp
->
Local
;
op
->
Status
=
MB__NORMAL
;
/* Do configuration check and initialize modules. */
cardp
=
rp
->
cardlist
;
unsigned
int
prev_input_area_offset
=
0
;
unsigned
int
prev_output_area_offset
=
0
;
unsigned
int
input_area_offset
=
0
;
unsigned
int
output_area_offset
=
0
;
unsigned
int
input_area_chansize
=
0
;
unsigned
int
output_area_chansize
=
0
;
while
(
cardp
)
{
local_card
=
calloc
(
1
,
sizeof
(
*
local_card
));
cid
=
cardp
->
Class
;
/* Find the super class */
while
(
ODD
(
gdh_GetSuperClass
(
cid
,
&
cid
,
cardp
->
Objid
)))
;
switch
(
cid
)
{
case
pwr_cClass_Modbus_RTU_Module
:
{
pwr_sClass_Modbus_RTU_Module
*
modulep
;
cardp
->
Local
=
local_card
;
no_di
=
0
;
no_do
=
0
;
local_card
->
msg
[
0
].
input_area
=
(
void
*
)
&
(
op
->
Inputs
)
+
input_area_offset
+
input_area_chansize
;
local_card
->
msg
[
0
].
output_area
=
(
void
*
)
&
(
op
->
Outputs
)
+
output_area_offset
+
output_area_chansize
;
modulep
=
(
pwr_sClass_Modbus_RTU_Module
*
)
cardp
->
op
;
modulep
->
Status
=
pwr_eModbusModule_StatusEnum_StatusUnknown
;
io_bus_card_init
(
ctx
,
cardp
,
&
input_area_offset
,
&
input_area_chansize
,
&
output_area_offset
,
&
output_area_chansize
,
pwr_eByteOrderingEnum_BigEndian
);
/* Count number of di and do */
for
(
i
=
0
;
i
<
cardp
->
ChanListSize
;
i
++
)
{
chanp
=
&
cardp
->
chanlist
[
i
];
switch
(
chanp
->
ChanClass
)
{
case
pwr_cClass_ChanDi
:
no_di
++
;
break
;
case
pwr_cClass_ChanDo
:
no_do
++
;
break
;
}
}
local_card
->
msg
[
0
].
input_size
=
input_area_offset
+
input_area_chansize
-
prev_input_area_offset
;
local_card
->
msg
[
0
].
output_size
=
output_area_offset
+
output_area_chansize
-
prev_output_area_offset
;
local_card
->
msg
[
0
].
no_di
=
no_di
;
local_card
->
msg
[
0
].
no_do
=
no_do
;
break
;
}
}
/* End - switch ... */
prev_input_area_offset
=
input_area_offset
+
input_area_chansize
;
prev_output_area_offset
=
output_area_offset
+
output_area_chansize
;
cardp
=
cardp
->
next
;
}
local
->
input_size
=
input_area_offset
+
input_area_chansize
;
local
->
output_size
=
output_area_offset
+
output_area_chansize
;
return
IO__SUCCESS
;
}
/*----------------------------------------------------------------------------*\
Read method for the Modbus_TCP slave
\*----------------------------------------------------------------------------*/
static
pwr_tStatus
IoRackRead
(
io_tCtx
ctx
,
io_sAgent
*
ap
,
io_sRack
*
rp
)
{
#if 0
io_sRackLocal *local;
pwr_sClass_Modbus_TCP_Slave *sp;
pwr_tStatus sts;
pwr_tTime now;
pwr_tDeltaTime dt;
local = rp->Local;
sp = (pwr_sClass_Modbus_TCP_Slave *) rp->op;
/* Receive data */
if ((sp->Status == MB__NORMAL) && !sp->SingleOp) {
sts = mb_recv_data(local, rp, sp);
}
if (sp->DisableSlave != 1) {
if (sp->Status == MB__NORMAL) {
sp->ErrorCount = 0;
}
else {
sp->ErrorCount++;
}
if (sp->ErrorCount > sp->ErrorLimit) {
memset(&sp->Inputs, 0, local->input_size);
}
}
else {
sp->ErrorCount = 0;
sp->Status = MB__DISABLED;
}
#endif
return
IO__SUCCESS
;
}
/*----------------------------------------------------------------------------*\
Write method for the Modbus_TCP slave
\*----------------------------------------------------------------------------*/
static
pwr_tStatus
IoRackWrite
(
io_tCtx
ctx
,
io_sAgent
*
ap
,
io_sRack
*
rp
)
{
#if 0
io_sRackLocal *local;
pwr_sClass_Modbus_TCP_Slave *sp;
pwr_tStatus sts;
local = rp->Local;
sp = (pwr_sClass_Modbus_TCP_Slave *) rp->op;
local->expected_msgs = 0;
if (sp->Status == MB__NORMAL && sp->DisableSlave != 1) {
sts = mb_send_data( rp, ap->Local, local, ap->op, sp, mb_mSendMask_WriteReq);
}
if (sp->DisableSlave == 1) sp->Status = MB__DISABLED;
#endif
return
IO__SUCCESS
;
}
/*----------------------------------------------------------------------------*\
\*----------------------------------------------------------------------------*/
static
pwr_tStatus
IoRackClose
(
io_tCtx
ctx
,
io_sAgent
*
ap
,
io_sRack
*
rp
)
{
return
IO__SUCCESS
;
}
/*----------------------------------------------------------------------------*\
Every method to be exported to the workbench should be registred here.
\*----------------------------------------------------------------------------*/
pwr_dExport
pwr_BindIoMethods
(
Modbus_RTU_Slave
)
=
{
pwr_BindIoMethod
(
IoRackInit
),
pwr_BindIoMethod
(
IoRackRead
),
pwr_BindIoMethod
(
IoRackWrite
),
pwr_BindIoMethod
(
IoRackClose
),
pwr_NullMethod
};
otherio/lib/rt/src/os_templ/rt_io_m_mb_tcp_server.c
View file @
4a587916
...
@@ -852,26 +852,12 @@ static pwr_tStatus mb_init_channels( io_tCtx ctx, io_sAgent *ap, io_sRack *rp)
...
@@ -852,26 +852,12 @@ static pwr_tStatus mb_init_channels( io_tCtx ctx, io_sAgent *ap, io_sRack *rp)
io_sServerModuleLocal
*
local_card
;
io_sServerModuleLocal
*
local_card
;
io_sCard
*
cardp
;
io_sCard
*
cardp
;
io_sServerLocal
*
local
;
io_sServerLocal
*
local
;
short
input_counter
;
short
output_counter
;
short
card_input_counter
;
short
card_output_counter
;
pwr_sClass_Modbus_TCP_Server
*
op
;
pwr_sClass_Modbus_TCP_Server
*
op
;
pwr_sClass_Modbus_TCP_ServerModule
*
mp
;
char
name
[
196
];
char
name
[
196
];
pwr_tStatus
sts
;
pwr_tStatus
sts
;
pwr_tCid
cid
;
io_sChannel
*
chanp
;
io_sChannel
*
chanp
;
int
i
,
latent_input_counter
,
latent_output_counter
;
int
i
;
pwr_tInt32
chan_size
;
pwr_sClass_ChanDi
*
chan_di
;
pwr_sClass_ChanDo
*
chan_do
;
pwr_sClass_ChanAi
*
chan_ai
;
pwr_sClass_ChanAit
*
chan_ait
;
pwr_sClass_ChanIi
*
chan_ii
;
pwr_sClass_ChanAo
*
chan_ao
;
pwr_sClass_ChanIo
*
chan_io
;
sts
=
gdh_ObjidToName
(
rp
->
Objid
,
(
char
*
)
&
name
,
sizeof
(
name
),
cdh_mNName
);
sts
=
gdh_ObjidToName
(
rp
->
Objid
,
(
char
*
)
&
name
,
sizeof
(
name
),
cdh_mNName
);
...
@@ -885,169 +871,83 @@ static pwr_tStatus mb_init_channels( io_tCtx ctx, io_sAgent *ap, io_sRack *rp)
...
@@ -885,169 +871,83 @@ static pwr_tStatus mb_init_channels( io_tCtx ctx, io_sAgent *ap, io_sRack *rp)
cardp
=
rp
->
cardlist
;
cardp
=
rp
->
cardlist
;
input_counter
=
0
;
unsigned
int
prev_input_area_offset
=
0
;
output_counter
=
0
;
unsigned
int
prev_output_area_offset
=
0
;
card_input_counter
=
0
;
unsigned
int
input_area_offset
=
0
;
card_output_counter
=
0
;
unsigned
int
output_area_offset
=
0
;
latent_input_counter
=
0
;
unsigned
int
input_area_chansize
=
0
;
latent_output_counter
=
0
;
unsigned
int
output_area_chansize
=
0
;
while
(
cardp
)
{
while
(
cardp
)
{
local_card
=
calloc
(
1
,
sizeof
(
*
local_card
));
local_card
=
calloc
(
1
,
sizeof
(
*
local_card
));
cardp
->
Local
=
local_card
;
cardp
->
Local
=
local_card
;
input_counter
=
input_counter
+
card_input_counter
+
latent_input_counter
;
output_counter
=
output_counter
+
card_output_counter
+
latent_output_counter
;
local_card
->
input_area
=
(
void
*
)
&
(
op
->
Inputs
)
+
input_counter
;
local_card
->
output_area
=
(
void
*
)
&
(
op
->
Outputs
)
+
output_counter
;
card_input_counter
=
0
;
card_output_counter
=
0
;
latent_input_counter
=
0
;
latent_output_counter
=
0
;
/* From v4.1.3 we can have subclasses, find the super class */
local_card
->
input_area
=
(
void
*
)
&
(
op
->
Inputs
)
+
input_area_offset
+
input_area_chansize
;
local_card
->
output_area
=
(
void
*
)
&
(
op
->
Outputs
)
+
output_area_offset
+
output_area_chansize
;
cid
=
cardp
->
Class
;
while
(
ODD
(
gdh_GetSuperClass
(
cid
,
&
cid
,
cardp
->
Objid
)))
;
switch
(
cid
)
{
io_bus_card_init
(
ctx
,
cardp
,
&
input_area_offset
,
&
input_area_chansize
,
&
output_area_offset
,
&
output_area_chansize
,
pwr_eByteOrderingEnum_BigEndian
);
case
pwr_cClass_Modbus_TCP_ServerModule
:
mp
=
(
pwr_sClass_Modbus_TCP_ServerModule
*
)
cardp
->
op
;
mp
->
Status
=
pwr_eModbusModule_StatusEnum_StatusUnknown
;
for
(
i
=
0
;
i
<
cardp
->
ChanListSize
;
i
++
)
{
for
(
i
=
0
;
i
<
cardp
->
ChanListSize
;
i
++
)
{
chanp
=
&
cardp
->
chanlist
[
i
];
chanp
=
&
cardp
->
chanlist
[
i
];
if
(
is_diag
(
&
chanp
->
ChanAref
))
{
chanp
->
udata
|=
PB_UDATA_DIAG
;
switch
(
chanp
->
ChanClass
)
{
switch
(
chanp
->
ChanClass
)
{
case
pwr_cClass_ChanIi
:
case
pwr_cClass_ChanDi
:
{
chanp
->
offset
=
((
pwr_sClass_ChanIi
*
)
chanp
->
cop
)
->
Number
;
pwr_sClass_ChanDi
*
chan_di
=
(
pwr_sClass_ChanDi
*
)
chanp
->
cop
;
chanp
->
size
=
GetChanSize
(
((
pwr_sClass_ChanIi
*
)
chanp
->
cop
)
->
Representation
);
break
;
default:
errh_Error
(
"Diagnostic channel class, card %s"
,
cardp
->
Name
);
}
continue
;
}
if
(
chanp
->
ChanClass
!=
pwr_cClass_ChanDi
)
{
card_input_counter
+=
latent_input_counter
;
latent_input_counter
=
0
;
}
if
(
chanp
->
ChanClass
!=
pwr_cClass_ChanDo
)
{
card_output_counter
+=
latent_output_counter
;
latent_output_counter
=
0
;
}
switch
(
chanp
->
ChanClass
)
{
case
pwr_cClass_ChanDi
:
chan_di
=
(
pwr_sClass_ChanDi
*
)
chanp
->
cop
;
if
(
chan_di
->
Number
==
0
)
{
card_input_counter
+=
latent_input_counter
;
latent_input_counter
=
0
;
}
chanp
->
offset
=
card_input_counter
;
chanp
->
mask
=
1
<<
chan_di
->
Number
;
if
(
chan_di
->
Representation
==
pwr_eDataRepEnum_Bit16
)
chanp
->
mask
=
swap16
(
chanp
->
mask
);
if
(
chan_di
->
Representation
==
pwr_eDataRepEnum_Bit32
)
chanp
->
mask
=
swap32
((
unsigned
short
)
chanp
->
mask
);
if
(
chan_di
->
Number
==
0
)
latent_input_counter
=
GetChanSize
(
chan_di
->
Representation
);
if
(
local_card
->
di_size
==
0
)
if
(
local_card
->
di_size
==
0
)
local_card
->
di_offset
=
chanp
->
offset
;
local_card
->
di_offset
=
chanp
->
offset
;
if
(
chan_di
->
Number
==
0
||
local_card
->
di_size
==
0
)
if
(
chan_di
->
Number
==
0
||
local_card
->
di_size
==
0
)
local_card
->
di_size
+=
GetChanSize
(
chan_di
->
Representation
);
local_card
->
di_size
+=
GetChanSize
(
chan_di
->
Representation
);
// printf("Di channel found in %s, Number %d, Offset %d\n", cardp->Name, chan_di->Number, chanp->offset);
break
;
case
pwr_cClass_ChanAi
:
chan_ai
=
(
pwr_sClass_ChanAi
*
)
chanp
->
cop
;
chanp
->
offset
=
card_input_counter
;
chan_size
=
GetChanSize
(
chan_ai
->
Representation
);
chanp
->
size
=
chan_size
;
chanp
->
mask
=
0
;
card_input_counter
+=
chan_size
;
io_AiRangeToCoef
(
chanp
);
// printf("Ai channel found in %s, Number %d, Offset %d\n", cardp->Name, chan_ai->Number, chanp->offset);
break
;
case
pwr_cClass_ChanAit
:
chan_ait
=
(
pwr_sClass_ChanAit
*
)
chanp
->
cop
;
chanp
->
offset
=
card_input_counter
;
chan_size
=
GetChanSize
(
chan_ait
->
Representation
);
chanp
->
size
=
chan_size
;
chanp
->
mask
=
0
;
card_input_counter
+=
chan_size
;
io_AiRangeToCoef
(
chanp
);
break
;
case
pwr_cClass_ChanIi
:
chan_ii
=
(
pwr_sClass_ChanIi
*
)
chanp
->
cop
;
chanp
->
offset
=
card_input_counter
;
chan_size
=
GetChanSize
(
chan_ii
->
Representation
);
chanp
->
size
=
chan_size
;
chanp
->
mask
=
0
;
card_input_counter
+=
chan_size
;
// printf("Ii channel found in %s, Number %d, Offset %d\n", cardp->Name, chan_ii->Number, chanp->offset);
break
;
break
;
}
case
pwr_cClass_ChanDo
:
{
pwr_sClass_ChanDo
*
chan_do
=
(
pwr_sClass_ChanDo
*
)
chanp
->
cop
;
case
pwr_cClass_ChanDo
:
chan_do
=
(
pwr_sClass_ChanDo
*
)
chanp
->
cop
;
if
(
chan_do
->
Number
==
0
)
{
card_output_counter
+=
latent_output_counter
;
latent_output_counter
=
0
;
}
chanp
->
offset
=
card_output_counter
;
chan_size
=
GetChanSize
(
chan_do
->
Representation
);
chanp
->
mask
=
1
<<
chan_do
->
Number
;
if
(
chan_do
->
Representation
==
pwr_eDataRepEnum_Bit16
)
chanp
->
mask
=
swap16
(
chanp
->
mask
);
if
(
chan_do
->
Representation
==
pwr_eDataRepEnum_Bit32
)
chanp
->
mask
=
swap32
((
unsigned
short
)
chanp
->
mask
);
if
(
chan_do
->
Number
==
0
)
latent_output_counter
=
GetChanSize
(
chan_do
->
Representation
);
if
(
local_card
->
do_size
==
0
)
if
(
local_card
->
do_size
==
0
)
local_card
->
do_offset
=
chanp
->
offset
;
local_card
->
do_offset
=
chanp
->
offset
;
if
(
chan_do
->
Number
==
0
||
local_card
->
do_size
==
0
)
if
(
chan_do
->
Number
==
0
||
local_card
->
do_size
==
0
)
local_card
->
do_size
+=
GetChanSize
(
chan_do
->
Representation
);
local_card
->
do_size
+=
GetChanSize
(
chan_do
->
Representation
);
// printf("Do channel found in %s, Number %d, Offset %d\n", cardp->Name, chan_do->Number, chanp->offset);
break
;
case
pwr_cClass_ChanAo
:
chan_ao
=
(
pwr_sClass_ChanAo
*
)
chanp
->
cop
;
chanp
->
offset
=
card_output_counter
;
chan_size
=
GetChanSize
(
chan_ao
->
Representation
);
chanp
->
size
=
chan_size
;
chanp
->
mask
=
0
;
card_output_counter
+=
chan_size
;
io_AoRangeToCoef
(
chanp
);
// printf("Ao channel found in %s, Number %d, Offset %d\n", cardp->Name, chan_ao->Number, chanp->offset);
break
;
break
;
}
case
pwr_cClass_ChanIo
:
case
pwr_cClass_ChanD
:
{
chan_io
=
(
pwr_sClass_ChanIo
*
)
chanp
->
cop
;
pwr_sClass_ChanD
*
chan_d
=
(
pwr_sClass_ChanD
*
)
chanp
->
cop
;
chanp
->
offset
=
card_output_counter
;
if
(
chan_d
->
Type
==
pwr_eDChanTypeEnum_Di
)
{
chan_size
=
GetChanSize
(
chan_io
->
Representation
);
if
(
local_card
->
di_size
==
0
)
chanp
->
size
=
chan_size
;
local_card
->
di_offset
=
chanp
->
offset
;
chanp
->
mask
=
0
;
if
(
chan_d
->
Number
==
0
||
local_card
->
di_size
==
0
)
card_output_counter
+=
chan_size
;
local_card
->
di_size
+=
GetChanSize
(
chan_d
->
Representation
);
// printf("Io channel found in %s, Number %d, Offset %d\n", cardp->Name, chan_io->Number, chanp->offset);
}
else
{
if
(
local_card
->
do_size
==
0
)
local_card
->
do_offset
=
chanp
->
offset
;
if
(
chan_d
->
Number
==
0
||
local_card
->
do_size
==
0
)
local_card
->
do_size
+=
GetChanSize
(
chan_d
->
Representation
);
}
break
;
break
;
}
}
}
/* End - for ... */
}
}
break
;
local_card
->
input_size
=
input_area_offset
+
input_area_chansize
-
}
/* End - switch ... */
prev_input_area_offset
;
local_card
->
output_size
=
output_area_offset
+
output_area_chansize
-
prev_output_area_offset
;
local_card
->
input_size
=
card_input_counter
+
latent_input_counter
;
prev_input_area_offset
=
input_area_offset
+
input_area_chansize
;
local_card
->
output_size
=
card_output_counter
+
latent_output_counter
;
prev_output_area_offset
=
output_area_offset
+
output_area_chansize
;
cardp
=
cardp
->
next
;
cardp
=
cardp
->
next
;
}
}
local
->
input_size
=
input_counter
+
card_input_counter
+
latent_input_counter
;
local
->
input_size
=
input_area_offset
+
input_area_chansize
;
local
->
output_size
=
output_counter
+
card_output_counter
+
latent_output_counter
;
local
->
output_size
=
output_area_offset
+
output_area_chansize
;
return
IO__SUCCESS
;
return
IO__SUCCESS
;
}
}
...
...
otherio/lib/rt/src/os_templ/rt_io_m_mb_tcp_slave.c
View file @
4a587916
...
@@ -58,13 +58,14 @@
...
@@ -58,13 +58,14 @@
#include "rt_io_bus.h"
#include "rt_io_bus.h"
#include "rt_io_msg.h"
#include "rt_io_msg.h"
#include "rt_errh.h"
#include "rt_errh.h"
#include "rt_net.h"
#include "co_cdh.h"
#include "co_cdh.h"
#include "co_time.h"
#include "co_time.h"
#include "rt_mb_msg.h"
#include "rt_mb_msg.h"
#include "rt_io_mb_locals.h"
#include "rt_io_mb_locals.h"
char
rcv_buffer
[
65536
];
//
char rcv_buffer[65536];
/* Check if channel should be fetched from diagnostic area,
/* Check if channel should be fetched from diagnostic area,
i.e. channel name starts with "Diag_" */
i.e. channel name starts with "Diag_" */
...
@@ -103,7 +104,13 @@ static int connect_slave( io_sRackLocal *local, io_sRack *rp)
...
@@ -103,7 +104,13 @@ static int connect_slave( io_sRackLocal *local, io_sRack *rp)
local
->
rem_addr
.
sin_family
=
AF_INET
;
local
->
rem_addr
.
sin_family
=
AF_INET
;
local
->
rem_addr
.
sin_port
=
htons
(
port
);
local
->
rem_addr
.
sin_port
=
htons
(
port
);
local
->
rem_addr
.
sin_addr
.
s_addr
=
inet_addr
((
char
*
)
&
(
op
->
Address
));
// local->rem_addr.sin_addr.s_addr = inet_addr((char *) &(op->Address));
sts
=
net_StringToAddr
(
op
->
Address
,
&
local
->
rem_addr
.
sin_addr
);
if
(
EVEN
(
sts
))
{
errh_Error
(
"Address error for IO modbus tcp slave %s %s"
,
rp
->
Name
,
op
->
Address
);
return
sts
;
}
local
->
rem_addr
.
sin_addr
.
s_addr
=
ntohl
(
local
->
rem_addr
.
sin_addr
.
s_addr
);
/* Connect to remote address */
/* Connect to remote address */
...
@@ -125,7 +132,7 @@ static int connect_slave( io_sRackLocal *local, io_sRack *rp)
...
@@ -125,7 +132,7 @@ static int connect_slave( io_sRackLocal *local, io_sRack *rp)
tv
.
tv_usec
=
200000
;
tv
.
tv_usec
=
200000
;
}
}
sts
=
select
(
32
,
&
fdr
,
&
fdw
,
NULL
,
&
tv
);
sts
=
select
(
(
int
)
local
->
s
+
1
,
&
fdr
,
&
fdw
,
NULL
,
&
tv
);
if
(
sts
<=
0
)
{
if
(
sts
<=
0
)
{
close
(
local
->
s
);
close
(
local
->
s
);
...
@@ -143,53 +150,46 @@ pwr_tStatus mb_recv_data(io_sRackLocal *local,
...
@@ -143,53 +150,46 @@ pwr_tStatus mb_recv_data(io_sRackLocal *local,
io_sRack
*
rp
,
io_sRack
*
rp
,
pwr_sClass_Modbus_TCP_Slave
*
sp
)
pwr_sClass_Modbus_TCP_Slave
*
sp
)
{
{
io_sCardLocal
*
local_card
;
io_sCardLocal
Msg
*
local_card
;
io_sCard
*
cardp
;
io_sCard
*
cardp
;
pwr_sClass_Modbus_Module
*
mp
;
pwr_sClass_Modbus_Module
Msg
*
mp
;
pwr_tStatus
sts
;
pwr_tStatus
sts
;
fd_set
fdr
;
/* For select call */
fd_set
fdr
;
/* For select call */
fd_set
fde
;
/* For select call */
fd_set
fdw
;
/* For select call */
struct
timeval
tv
;
struct
timeval
tv
;
pwr_tBoolean
found
;
pwr_tBoolean
found
;
int
data_size
;
int
data_size
;
rec_buf
*
rb
;
rec_buf
*
rb
;
char
rcv_buffer
[
260
];
pwr_tCid
cid
;
pwr_tCid
cid
;
unsigned
char
fc
;
unsigned
char
fc
;
short
int
trans_id
;
short
int
trans_id
;
short
int
size_of_msg
;
short
int
size_of_msg
;
int
modules
;
int
i
;
/* Receive answer */
short
int
remaining_data
;
// Data we have to get from the socket.
short
int
received_data
;
// Data that has been received.
sts
=
1
;
sts
=
1
;
rb
=
(
rec_buf
*
)
rcv_buffer
;
while
(
sts
>
0
)
{
while
(
sts
>
0
)
{
/* Receive answer */
FD_ZERO
(
&
fdr
);
FD_ZERO
(
&
fdw
);
FD_ZERO
(
&
fde
);
FD_SET
(
local
->
s
,
&
fdr
);
FD_SET
(
local
->
s
,
&
fdw
);
FD_SET
(
local
->
s
,
&
fde
);
size_of_msg
=
0
;
size_of_msg
=
0
;
tv
.
tv_sec
=
0
;
remaining_data
=
sizeof
(
mbap_header
);
tv
.
tv_usec
=
0
;
received_data
=
0
;
/*
First read at least the MBAP header, and no more.
Then, read the remaining bytes indicaterd in the header, but no more.
We control the amount of data because could be more than one message in the socket buffer or
only the first bytes of a packet.
*/
sts
=
select
(
32
,
&
fdr
,
&
fdw
,
&
fde
,
&
tv
);
while
(
(
remaining_data
>
0
)
&&
(
sts
>
0
)
)
{
// if there is data to read and everything is ok, receive.
if
(
sts
<
0
)
{
FD_ZERO
(
&
fdr
);
sp
->
Status
=
MB__CONNLOST
;
FD_SET
(
local
->
s
,
&
fdr
);
close
(
local
->
s
);
errh_Error
(
"Connection lost to modbus slave, %s"
,
rp
->
Name
);
return
IO__SUCCESS
;
}
if
(
!
(
FD_ISSET
(
local
->
s
,
&
fdw
)))
{
sp
->
Status
=
MB__CONNDOWN
;
close
(
local
->
s
);
errh_Error
(
"Connection down to modbus slave, %s"
,
rp
->
Name
);
return
IO__SUCCESS
;
}
if
(
local
->
expected_msgs
>
0
)
{
if
(
local
->
expected_msgs
>
0
)
{
tv
.
tv_sec
=
0
;
tv
.
tv_sec
=
0
;
...
@@ -199,65 +199,71 @@ pwr_tStatus mb_recv_data(io_sRackLocal *local,
...
@@ -199,65 +199,71 @@ pwr_tStatus mb_recv_data(io_sRackLocal *local,
tv
.
tv_usec
=
0
;
tv
.
tv_usec
=
0
;
}
}
FD_ZERO
(
&
fdr
);
sts
=
select
((
int
)
local
->
s
+
1
,
&
fdr
,
NULL
,
NULL
,
&
tv
);
FD_ZERO
(
&
fde
);
FD_SET
(
local
->
s
,
&
fdr
);
FD_SET
(
local
->
s
,
&
fde
);
sts
=
select
(
32
,
&
fdr
,
NULL
,
&
fde
,
&
tv
);
if
(
sts
<=
0
)
{
// Timeout or error.
if
((
sts
==
0
)
&&
(
local
->
expected_msgs
>
0
))
{
// Timeout but there are messages pending
if
(
sts
<
0
)
{
sp
->
Status
=
MB__CONNLOST
;
close
(
local
->
s
);
errh_Error
(
"Connection lost to modbus slave, %s"
,
rp
->
Name
);
return
IO__SUCCESS
;
}
if
((
sts
==
0
)
&&
(
local
->
expected_msgs
>
0
))
{
local
->
msgs_lost
++
;
local
->
msgs_lost
++
;
if
(
local
->
msgs_lost
>
MAX_MSGS_LOST
)
{
if
(
local
->
msgs_lost
>
MAX_MSGS_LOST
)
{
sp
->
Status
=
MB__CONNDOWN
;
sp
->
Status
=
MB__CONNDOWN
;
close
(
local
->
s
);
close
(
local
->
s
);
errh_Error
(
"
Connection down to modbus slave, %s"
,
rp
->
Name
);
errh_Error
(
"Data expected but timeout.
Connection down to modbus slave, %s"
,
rp
->
Name
);
}
}
return
IO__SUCCESS
;
return
IO__SUCCESS
;
}
}
if
(
sts
>
0
&&
FD_ISSET
(
local
->
s
,
&
fdr
))
{
if
(
sts
<
0
)
{
// Error in the socket
data_size
=
recv
(
local
->
s
,
rcv_buffer
,
sizeof
(
rec_buf
),
0
);
sp
->
Status
=
MB__CONNLOST
;
close
(
local
->
s
);
errh_Error
(
"Socket Error. Connection lost to modbus slave, %s"
,
rp
->
Name
);
return
IO__SUCCESS
;
}
}
else
{
// There are something to read (no timeout and no error). Could be a closed socket too, so we have to check later anyway.
data_size
=
recv
(
local
->
s
,
&
rcv_buffer
[
received_data
],
remaining_data
,
0
);
if
(
data_size
<
0
)
{
if
(
data_size
<
0
)
{
sp
->
Status
=
MB__CONNLOST
;
sp
->
Status
=
MB__CONNLOST
;
close
(
local
->
s
);
close
(
local
->
s
);
errh_Error
(
"
Connection lost to modbus slave, %s"
,
rp
->
Name
);
errh_Error
(
"Error reading data.
Connection lost to modbus slave, %s"
,
rp
->
Name
);
return
IO__SUCCESS
;
return
IO__SUCCESS
;
}
}
if
(
data_size
==
0
)
{
if
(
data_size
==
0
)
{
sp
->
Status
=
MB__CONNDOWN
;
sp
->
Status
=
MB__CONNDOWN
;
close
(
local
->
s
);
close
(
local
->
s
);
errh_Error
(
"
Connection down to modbus slave, %s"
,
rp
->
Name
);
errh_Error
(
"Error reading data.
Connection down to modbus slave, %s"
,
rp
->
Name
);
return
IO__SUCCESS
;
return
IO__SUCCESS
;
}
}
while
(
data_size
>
0
)
{
remaining_data
=
remaining_data
-
data_size
;
received_data
=
received_data
+
data_size
;
local
->
msgs_lost
=
0
;
sp
->
RX_packets
++
;
local
->
expected_msgs
--
;
if
(
(
received_data
>=
sizeof
(
mbap_header
))
&&
(
size_of_msg
==
0
))
{
// Compute the complete header
trans_id
=
ntohs
(
rb
->
head
.
trans_id
);
size_of_msg
=
ntohs
(
rb
->
head
.
length
)
+
6
;
cardp
=
rp
->
cardlist
;
// Check header data
if
((
ntohs
(
rb
->
head
.
proto_id
)
!=
0
)
||
(
size_of_msg
>
260
))
{
// Invalid modbus packet
sp
->
Status
=
MB__CONNDOWN
;
close
(
local
->
s
);
errh_Error
(
"Invalid Modbus packet. Connection down to modbus slave, %s"
,
rp
->
Name
);
return
IO__SUCCESS
;
}
if
(
data_size
<
sizeof
(
mbap_header
))
// Update remaining data
break
;
remaining_data
=
size_of_msg
-
received_data
;
}
}
}
// while
rb
=
(
rec_buf
*
)
&
rcv_buffer
[
size_of_msg
];
if
(
sts
>
0
)
{
// processing packet...
trans_id
=
ntohs
(
rb
->
head
.
trans_id
);
local
->
msgs_lost
=
0
;
size_of_msg
+=
ntohs
(
rb
->
head
.
length
)
+
6
;
sp
->
RX_packets
++
;
data_size
-=
ntohs
(
rb
->
head
.
length
)
+
6
;
local
->
expected_msgs
--
;
cardp
=
rp
->
cardlist
;
while
(
cardp
)
{
while
(
cardp
)
{
/* From v4.1.3 we can have subclasses, find the super class */
/* From v4.1.3 we can have subclasses, find the super class */
...
@@ -266,11 +272,26 @@ pwr_tStatus mb_recv_data(io_sRackLocal *local,
...
@@ -266,11 +272,26 @@ pwr_tStatus mb_recv_data(io_sRackLocal *local,
while
(
ODD
(
gdh_GetSuperClass
(
cid
,
&
cid
,
cardp
->
Objid
)))
;
while
(
ODD
(
gdh_GetSuperClass
(
cid
,
&
cid
,
cardp
->
Objid
)))
;
switch
(
cid
)
{
switch
(
cid
)
{
case
pwr_cClass_Modbus_Module
:
mp
=
(
pwr_sClass_Modbus_ModuleMsg
*
)
&
((
pwr_sClass_Modbus_Module
*
)
cardp
->
op
)
->
FunctionCode
;
modules
=
1
;
local_card
=
((
io_sCardLocal
*
)
cardp
->
Local
)
->
msg
;
break
;
case
pwr_cClass_Modbus_ModuleReadWrite
:
mp
=
&
((
pwr_sClass_Modbus_ModuleReadWrite
*
)
cardp
->
op
)
->
Read
;
modules
=
2
;
local_card
=
((
io_sCardLocal
*
)
cardp
->
Local
)
->
msg
;
break
;
default:
modules
=
0
;
}
case
pwr_cClass_Modbus_Module
:
{
if
(
!
modules
)
{
mp
=
(
pwr_sClass_Modbus_Module
*
)
cardp
->
op
;
cardp
=
cardp
->
next
;
continue
;
}
local_card
=
cardp
->
Local
;
for
(
i
=
0
;
i
<
modules
;
i
++
)
{
if
(
local_card
->
trans_id
==
trans_id
)
{
if
(
local_card
->
trans_id
==
trans_id
)
{
...
@@ -279,12 +300,16 @@ pwr_tStatus mb_recv_data(io_sRackLocal *local,
...
@@ -279,12 +300,16 @@ pwr_tStatus mb_recv_data(io_sRackLocal *local,
res_fault
*
res_f
;
res_fault
*
res_f
;
res_f
=
(
res_fault
*
)
rb
->
buf
;
res_f
=
(
res_fault
*
)
rb
->
buf
;
mp
->
Status
=
res_f
->
ec
;
mp
->
Status
=
res_f
->
ec
;
break
;
mp
++
;
local_card
++
;
continue
;
}
}
if
(
fc
!=
mp
->
FunctionCode
)
{
if
(
fc
!=
mp
->
FunctionCode
)
{
mp
->
Status
=
pwr_eModbusModule_StatusEnum_StatusUnknown
;
mp
->
Status
=
pwr_eModbusModule_StatusEnum_StatusUnknown
;
break
;
mp
++
;
local_card
++
;
continue
;
}
}
mp
->
Status
=
pwr_eModbusModule_StatusEnum_OK
;
mp
->
Status
=
pwr_eModbusModule_StatusEnum_OK
;
...
@@ -326,18 +351,15 @@ pwr_tStatus mb_recv_data(io_sRackLocal *local,
...
@@ -326,18 +351,15 @@ pwr_tStatus mb_recv_data(io_sRackLocal *local,
}
}
found
=
TRUE
;
found
=
TRUE
;
}
}
break
;
mp
++
;
}
local_card
++
;
default:
}
// for ( i = 0; i < modules; i++)
break
;
}
/* End - switch (cid) ... */
if
(
found
)
if
(
found
)
break
;
break
;
cardp
=
cardp
->
next
;
cardp
=
cardp
->
next
;
}
/* End - while(cardp) ... */
}
/* End - while(cardp) ... */
}
/* End - data_size > 0 ... */
}
// if (sts > 0) processing packet...
}
/* End - if received message ... */
}
// while (sts > 0) Receive answer
}
/* End - receive messages ... */
return
IO__SUCCESS
;
return
IO__SUCCESS
;
}
}
...
@@ -347,11 +369,13 @@ pwr_tStatus mb_send_data(io_sRackLocal *local,
...
@@ -347,11 +369,13 @@ pwr_tStatus mb_send_data(io_sRackLocal *local,
pwr_sClass_Modbus_TCP_Slave
*
sp
,
pwr_sClass_Modbus_TCP_Slave
*
sp
,
mb_tSendMask
mask
)
mb_tSendMask
mask
)
{
{
io_sCardLocal
*
local_card
;
io_sCardLocal
Msg
*
local_card
;
io_sCard
*
cardp
;
io_sCard
*
cardp
;
pwr_sClass_Modbus_Module
*
mp
;
pwr_sClass_Modbus_Module
Msg
*
mp
;
pwr_tStatus
sts
;
pwr_tStatus
sts
;
pwr_tCid
cid
;
pwr_tCid
cid
;
int
modules
;
int
i
;
/* Send messages to slave */
/* Send messages to slave */
...
@@ -365,13 +389,30 @@ pwr_tStatus mb_send_data(io_sRackLocal *local,
...
@@ -365,13 +389,30 @@ pwr_tStatus mb_send_data(io_sRackLocal *local,
switch
(
cid
)
{
switch
(
cid
)
{
case
pwr_cClass_Modbus_Module
:
case
pwr_cClass_Modbus_Module
:
mp
=
(
pwr_sClass_Modbus_Module
*
)
cardp
->
op
;
mp
=
(
pwr_sClass_Modbus_ModuleMsg
*
)
&
((
pwr_sClass_Modbus_Module
*
)
cardp
->
op
)
->
FunctionCode
;
modules
=
1
;
break
;
case
pwr_cClass_Modbus_ModuleReadWrite
:
mp
=
&
((
pwr_sClass_Modbus_ModuleReadWrite
*
)
cardp
->
op
)
->
Read
;
modules
=
2
;
break
;
default:
modules
=
0
;
}
if
(
!
modules
)
{
cardp
=
cardp
->
next
;
continue
;
}
for
(
i
=
0
;
i
<
modules
;
i
++
)
{
sts
=
1
;
if
(
!
mp
->
Continous
&&
!
mp
->
SendOp
)
{
if
(
!
mp
->
Continous
&&
!
mp
->
SendOp
)
{
break
;
break
;
}
}
local_card
=
cardp
->
Local
;
local_card
=
&
((
io_sCardLocal
*
)
cardp
->
Local
)
->
msg
[
i
]
;
if
(
mp
->
ScanInterval
>
1
&&
local_card
->
interval_cnt
!=
0
)
{
if
(
mp
->
ScanInterval
>
1
&&
local_card
->
interval_cnt
!=
0
)
{
cardp
=
cardp
->
next
;
cardp
=
cardp
->
next
;
continue
;
continue
;
...
@@ -575,6 +616,11 @@ pwr_tStatus mb_send_data(io_sRackLocal *local,
...
@@ -575,6 +616,11 @@ pwr_tStatus mb_send_data(io_sRackLocal *local,
}
}
}
/* End - switch FC ... */
}
/* End - switch FC ... */
}
}
if
(
sts
<
0
)
break
;
mp
++
;
}
if
(
sts
<
0
)
{
if
(
sts
<
0
)
{
sp
->
Status
=
MB__CONNDOWN
;
sp
->
Status
=
MB__CONNDOWN
;
close
(
local
->
s
);
close
(
local
->
s
);
...
@@ -587,9 +633,6 @@ pwr_tStatus mb_send_data(io_sRackLocal *local,
...
@@ -587,9 +633,6 @@ pwr_tStatus mb_send_data(io_sRackLocal *local,
if
(
sp
->
Status
!=
MB__NORMAL
)
return
IO__SUCCESS
;
if
(
sp
->
Status
!=
MB__NORMAL
)
return
IO__SUCCESS
;
break
;
}
/* End - switch cid ... */
cardp
=
cardp
->
next
;
cardp
=
cardp
->
next
;
}
/* End - while cardp ... */
}
/* End - while cardp ... */
...
@@ -609,28 +652,15 @@ static pwr_tStatus IoRackInit (
...
@@ -609,28 +652,15 @@ static pwr_tStatus IoRackInit (
io_sCardLocal
*
local_card
;
io_sCardLocal
*
local_card
;
io_sCard
*
cardp
;
io_sCard
*
cardp
;
io_sRackLocal
*
local
;
io_sRackLocal
*
local
;
short
input_counter
;
int
no_di
;
short
output_counter
;
int
no_do
;
short
card_input_counter
;
short
card_output_counter
;
short
no_di
;
short
no_do
;
pwr_sClass_Modbus_TCP_Slave
*
op
;
pwr_sClass_Modbus_TCP_Slave
*
op
;
pwr_sClass_Modbus_Module
*
mp
;
char
name
[
196
];
char
name
[
196
];
pwr_tStatus
sts
;
pwr_tStatus
sts
;
pwr_tCid
cid
;
pwr_tCid
cid
;
io_sChannel
*
chanp
;
io_sChannel
*
chanp
;
int
i
,
latent_input_counter
,
latent_output_counter
;
int
i
;
pwr_tInt32
chan_size
;
pwr_sClass_ChanDi
*
chan_di
;
pwr_sClass_ChanDo
*
chan_do
;
pwr_sClass_ChanAi
*
chan_ai
;
pwr_sClass_ChanAit
*
chan_ait
;
pwr_sClass_ChanIi
*
chan_ii
;
pwr_sClass_ChanAo
*
chan_ao
;
pwr_sClass_ChanIo
*
chan_io
;
sts
=
gdh_ObjidToName
(
rp
->
Objid
,
(
char
*
)
&
name
,
sizeof
(
name
),
cdh_mNName
);
sts
=
gdh_ObjidToName
(
rp
->
Objid
,
(
char
*
)
&
name
,
sizeof
(
name
),
cdh_mNName
);
errh_Info
(
"Init of Modbus TCP Slave and Modules %s"
,
name
);
errh_Info
(
"Init of Modbus TCP Slave and Modules %s"
,
name
);
...
@@ -654,167 +684,135 @@ static pwr_tStatus IoRackInit (
...
@@ -654,167 +684,135 @@ static pwr_tStatus IoRackInit (
cardp
=
rp
->
cardlist
;
cardp
=
rp
->
cardlist
;
input_counter
=
0
;
unsigned
int
prev_input_area_offset
=
0
;
output_counter
=
0
;
unsigned
int
prev_output_area_offset
=
0
;
card_input_counter
=
0
;
unsigned
int
input_area_offset
=
0
;
card_output_counter
=
0
;
unsigned
int
output_area_offset
=
0
;
latent_input_counter
=
0
;
unsigned
int
input_area_chansize
=
0
;
latent_output_counter
=
0
;
unsigned
int
output_area_chansize
=
0
;
while
(
cardp
)
{
while
(
cardp
)
{
local_card
=
calloc
(
1
,
sizeof
(
*
local_card
));
local_card
=
calloc
(
1
,
sizeof
(
*
local_card
));
cardp
->
Local
=
local_card
;
input_counter
=
input_counter
+
card_input_counter
+
latent_input_counter
;
output_counter
=
output_counter
+
card_output_counter
+
latent_output_counter
;
local_card
->
input_area
=
(
void
*
)
&
(
op
->
Inputs
)
+
input_counter
;
local_card
->
output_area
=
(
void
*
)
&
(
op
->
Outputs
)
+
output_counter
;
card_input_counter
=
0
;
card_output_counter
=
0
;
latent_input_counter
=
0
;
latent_output_counter
=
0
;
no_di
=
0
;
no_do
=
0
;
/* From v4.1.3 we can have subclasses, find the super class */
cid
=
cardp
->
Class
;
cid
=
cardp
->
Class
;
/* Find the super class */
while
(
ODD
(
gdh_GetSuperClass
(
cid
,
&
cid
,
cardp
->
Objid
)))
;
while
(
ODD
(
gdh_GetSuperClass
(
cid
,
&
cid
,
cardp
->
Objid
)))
;
switch
(
cid
)
{
switch
(
cid
)
{
case
pwr_cClass_Modbus_Module
:
{
pwr_sClass_Modbus_Module
*
mp
;
cardp
->
Local
=
local_card
;
no_di
=
0
;
no_do
=
0
;
local_card
->
msg
[
0
].
input_area
=
(
void
*
)
&
(
op
->
Inputs
)
+
input_area_offset
+
input_area_chansize
;
local_card
->
msg
[
0
].
output_area
=
(
void
*
)
&
(
op
->
Outputs
)
+
output_area_offset
+
output_area_chansize
;
case
pwr_cClass_Modbus_Module
:
mp
=
(
pwr_sClass_Modbus_Module
*
)
cardp
->
op
;
mp
=
(
pwr_sClass_Modbus_Module
*
)
cardp
->
op
;
mp
->
Status
=
pwr_eModbusModule_StatusEnum_StatusUnknown
;
mp
->
Status
=
pwr_eModbusModule_StatusEnum_StatusUnknown
;
io_bus_card_init
(
ctx
,
cardp
,
&
input_area_offset
,
&
input_area_chansize
,
&
output_area_offset
,
&
output_area_chansize
,
pwr_eByteOrderingEnum_BigEndian
);
/* Count number of di and do */
for
(
i
=
0
;
i
<
cardp
->
ChanListSize
;
i
++
)
{
for
(
i
=
0
;
i
<
cardp
->
ChanListSize
;
i
++
)
{
chanp
=
&
cardp
->
chanlist
[
i
];
chanp
=
&
cardp
->
chanlist
[
i
];
if
(
is_diag
(
&
chanp
->
ChanAref
))
{
chanp
->
udata
|=
PB_UDATA_DIAG
;
switch
(
chanp
->
ChanClass
)
{
switch
(
chanp
->
ChanClass
)
{
case
pwr_cClass_ChanIi
:
case
pwr_cClass_ChanDi
:
chanp
->
offset
=
((
pwr_sClass_ChanIi
*
)
chanp
->
cop
)
->
Number
;
no_di
++
;
chanp
->
size
=
GetChanSize
(
((
pwr_sClass_ChanIi
*
)
chanp
->
cop
)
->
Representation
);
break
;
case
pwr_cClass_ChanDo
:
no_do
++
;
break
;
case
pwr_cClass_ChanD
:
if
(
((
pwr_sClass_ChanD
*
)
chanp
->
cop
)
->
Type
==
pwr_eDChanTypeEnum_Di
)
no_di
++
;
else
no_do
++
;
break
;
break
;
default:
errh_Error
(
"Diagnostic channel class, card %s"
,
cardp
->
Name
);
}
}
continue
;
}
}
local_card
->
msg
[
0
].
input_size
=
input_area_offset
+
input_area_chansize
-
prev_input_area_offset
;
local_card
->
msg
[
0
].
output_size
=
output_area_offset
+
output_area_chansize
-
prev_output_area_offset
;
local_card
->
msg
[
0
].
no_di
=
no_di
;
local_card
->
msg
[
0
].
no_do
=
no_do
;
if
(
chanp
->
ChanClass
!=
pwr_cClass_ChanDi
)
{
break
;
card_input_counter
+=
latent_input_counter
;
latent_input_counter
=
0
;
}
}
case
pwr_cClass_Modbus_ModuleReadWrite
:
{
pwr_sClass_Modbus_ModuleReadWrite
*
mp
;
if
(
chanp
->
ChanClass
!=
pwr_cClass_ChanDo
)
{
cardp
->
Local
=
local_card
;
card_output_counter
+=
latent_output_counter
;
no_di
=
0
;
latent_output_counter
=
0
;
no_do
=
0
;
}
switch
(
chanp
->
ChanClass
)
{
local_card
->
msg
[
0
].
input_area
=
(
void
*
)
&
(
op
->
Inputs
)
+
input_area_offset
+
input_area_chansize
;
local_card
->
msg
[
0
].
output_area
=
(
void
*
)
&
(
op
->
Outputs
)
+
output_area_offset
+
output_area_chansize
;
local_card
->
msg
[
1
].
input_area
=
(
void
*
)
&
(
op
->
Inputs
)
+
input_area_offset
+
input_area_chansize
;
local_card
->
msg
[
1
].
output_area
=
(
void
*
)
&
(
op
->
Outputs
)
+
output_area_offset
+
output_area_chansize
;
case
pwr_cClass_ChanDi
:
chan_di
=
(
pwr_sClass_ChanDi
*
)
chanp
->
cop
;
if
(
chan_di
->
Number
==
0
)
{
card_input_counter
+=
latent_input_counter
;
latent_input_counter
=
0
;
}
chanp
->
offset
=
card_input_counter
;
chanp
->
mask
=
1
<<
chan_di
->
Number
;
if
(
chan_di
->
Representation
==
pwr_eDataRepEnum_Bit16
)
chanp
->
mask
=
swap16
(
chanp
->
mask
);
if
(
chan_di
->
Representation
==
pwr_eDataRepEnum_Bit32
)
chanp
->
mask
=
swap32
((
unsigned
short
)
chanp
->
mask
);
if
(
chan_di
->
Number
==
0
)
latent_input_counter
=
GetChanSize
(
chan_di
->
Representation
);
no_di
++
;
// printf("Di channel found in %s, Number %d, Offset %d\n", cardp->Name, chan_di->Number, chanp->offset);
break
;
case
pwr_cClass_ChanAi
:
mp
=
(
pwr_sClass_Modbus_ModuleReadWrite
*
)
cardp
->
op
;
chan_ai
=
(
pwr_sClass_ChanAi
*
)
chanp
->
cop
;
mp
->
Read
.
Status
=
pwr_eModbusModule_StatusEnum_StatusUnknown
;
chanp
->
offset
=
card_input_counter
;
mp
->
Write
.
Status
=
pwr_eModbusModule_StatusEnum_StatusUnknown
;
chan_size
=
GetChanSize
(
chan_ai
->
Representation
);
chanp
->
size
=
chan_size
;
chanp
->
mask
=
0
;
card_input_counter
+=
chan_size
;
io_AiRangeToCoef
(
chanp
);
// printf("Ai channel found in %s, Number %d, Offset %d\n", cardp->Name, chan_ai->Number, chanp->offset);
break
;
case
pwr_cClass_ChanAit
:
io_bus_card_init
(
ctx
,
cardp
,
&
input_area_offset
,
&
input_area_chansize
,
chan_ait
=
(
pwr_sClass_ChanAit
*
)
chanp
->
cop
;
&
output_area_offset
,
&
output_area_chansize
,
chanp
->
offset
=
card_input_counter
;
pwr_eByteOrderingEnum_BigEndian
);
chan_size
=
GetChanSize
(
chan_ait
->
Representation
);
chanp
->
size
=
chan_size
;
chanp
->
mask
=
0
;
card_input_counter
+=
chan_size
;
io_AiRangeToCoef
(
chanp
);
break
;
case
pwr_cClass_ChanIi
:
/* Count number of di and do */
chan_ii
=
(
pwr_sClass_ChanIi
*
)
chanp
->
cop
;
for
(
i
=
0
;
i
<
cardp
->
ChanListSize
;
i
++
)
{
chanp
->
offset
=
card_input_counter
;
chanp
=
&
cardp
->
chanlist
[
i
];
chan_size
=
GetChanSize
(
chan_ii
->
Representation
);
switch
(
chanp
->
ChanClass
)
{
chanp
->
size
=
chan_size
;
case
pwr_cClass_ChanDi
:
chanp
->
mask
=
0
;
no_di
++
;
card_input_counter
+=
chan_size
;
// printf("Ii channel found in %s, Number %d, Offset %d\n", cardp->Name, chan_ii->Number, chanp->offset);
break
;
break
;
case
pwr_cClass_ChanDo
:
case
pwr_cClass_ChanDo
:
chan_do
=
(
pwr_sClass_ChanDo
*
)
chanp
->
cop
;
if
(
chan_do
->
Number
==
0
)
{
card_output_counter
+=
latent_output_counter
;
latent_output_counter
=
0
;
}
chanp
->
offset
=
card_output_counter
;
chan_size
=
GetChanSize
(
chan_do
->
Representation
);
chanp
->
mask
=
1
<<
chan_do
->
Number
;
if
(
chan_do
->
Representation
==
pwr_eDataRepEnum_Bit16
)
chanp
->
mask
=
swap16
(
chanp
->
mask
);
if
(
chan_do
->
Representation
==
pwr_eDataRepEnum_Bit32
)
chanp
->
mask
=
swap32
((
unsigned
short
)
chanp
->
mask
);
if
(
chan_do
->
Number
==
0
)
latent_output_counter
=
GetChanSize
(
chan_do
->
Representation
);
no_do
++
;
no_do
++
;
// printf("Do channel found in %s, Number %d, Offset %d\n", cardp->Name, chan_do->Number, chanp->offset);
break
;
case
pwr_cClass_ChanAo
:
chan_ao
=
(
pwr_sClass_ChanAo
*
)
chanp
->
cop
;
chanp
->
offset
=
card_output_counter
;
chan_size
=
GetChanSize
(
chan_ao
->
Representation
);
chanp
->
size
=
chan_size
;
chanp
->
mask
=
0
;
card_output_counter
+=
chan_size
;
io_AoRangeToCoef
(
chanp
);
// printf("Ao channel found in %s, Number %d, Offset %d\n", cardp->Name, chan_ao->Number, chanp->offset);
break
;
break
;
case
pwr_cClass_ChanD
:
if
(
((
pwr_sClass_ChanD
*
)
chanp
->
cop
)
->
Type
==
pwr_eDChanTypeEnum_Di
)
no_di
++
;
else
no_do
++
;
}
}
local_card
->
msg
[
0
].
input_size
=
input_area_offset
+
input_area_chansize
-
prev_input_area_offset
;
local_card
->
msg
[
0
].
output_size
=
0
;
local_card
->
msg
[
0
].
no_di
=
no_di
;
local_card
->
msg
[
0
].
no_do
=
0
;
local_card
->
msg
[
1
].
input_size
=
0
;
local_card
->
msg
[
1
].
output_size
=
output_area_offset
+
output_area_chansize
-
prev_output_area_offset
;
local_card
->
msg
[
1
].
no_di
=
0
;
local_card
->
msg
[
1
].
no_do
=
no_do
;
case
pwr_cClass_ChanIo
:
chan_io
=
(
pwr_sClass_ChanIo
*
)
chanp
->
cop
;
chanp
->
offset
=
card_output_counter
;
chan_size
=
GetChanSize
(
chan_io
->
Representation
);
chanp
->
size
=
chan_size
;
chanp
->
mask
=
0
;
card_output_counter
+=
chan_size
;
// printf("Io channel found in %s, Number %d, Offset %d\n", cardp->Name, chan_io->Number, chanp->offset);
break
;
break
;
}
}
}
/* End - for ... */
break
;
}
/* End - switch ... */
}
/* End - switch ... */
local_card
->
input_size
=
card_input_counter
+
latent_input_counter
;
local_card
->
output_size
=
card_output_counter
+
latent_output_counter
;
prev_input_area_offset
=
input_area_offset
+
input_area_chansize
;
local_card
->
no_di
=
no_di
;
prev_output_area_offset
=
output_area_offset
+
output_area_chansize
;
local_card
->
no_do
=
no_do
;
cardp
=
cardp
->
next
;
cardp
=
cardp
->
next
;
}
}
local
->
input_size
=
input_
counter
+
card_input_counter
+
latent_input_counter
;
local
->
input_size
=
input_
area_offset
+
input_area_chansize
;
local
->
output_size
=
output_
counter
+
card_output_counter
+
latent_output_counter
;
local
->
output_size
=
output_
area_offset
+
output_area_chansize
;
return
IO__SUCCESS
;
return
IO__SUCCESS
;
}
}
...
...
otherio/lib/rt/src/os_templ/rt_io_mb_locals.h
View file @
4a587916
...
@@ -112,6 +112,10 @@ typedef struct {
...
@@ -112,6 +112,10 @@ typedef struct {
short
int
no_do
;
short
int
no_do
;
int
interval_cnt
;
int
interval_cnt
;
int
has_read_method
;
int
has_read_method
;
}
io_sCardLocalMsg
;
typedef
struct
{
io_sCardLocalMsg
msg
[
2
];
}
io_sCardLocal
;
}
io_sCardLocal
;
typedef
struct
{
typedef
struct
{
...
...
otherio/lib/rt/src/os_templ/rt_io_mb_rtu.h
0 → 100644
View file @
4a587916
/*
* Proview Open Source Process Control.
* Copyright (C) 2005-2012 SSAB EMEA AB.
*
* This file is part of Proview.
*
* 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 Proview. If not, see <http://www.gnu.org/licenses/>
*
* Linking Proview statically or dynamically with other modules is
* making a combined work based on Proview. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* Proview give you permission to, from the build function in the
* Proview Configurator, combine Proview with modules generated by the
* Proview PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of Proview (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
*/
#ifndef pwr_class_h
#include "pwr_class.h"
#endif
#define IO_MAXCHAN 96
#define MAX_MSGS_LOST 5
// These constants are obsolete from V4.1, except for the old style
// (Pb_Di, Pb_Do etc)
#define PB_MODULE_STATE_NOTINIT 0
#define PB_MODULE_STATE_OPERATE 1
#define PB_NUMREP_UNSIGNEDINT 0
#define PB_NUMREP_SIGNEDINT 1
#define PB_NUMREP_FLOATIEEE 2
#define PB_NUMREP_FLOATVAX 3
#define PB_NUMREP_FLOATINTEL 4
#define PB_ORIENTATION_BYTE 8
#define PB_ORIENTATION_WORD 16
#define PB_ORIENTATION_DWORD 32
#define PB_UDATA_DIAG 1
#define MB_MAX_CONNECTIONS 20
typedef
pwr_tMask
mb_tSendMask
;
typedef
enum
{
mb_mSendMask_ReadReq
=
1
,
mb_mSendMask_WriteReq
=
2
,
}
mb_mSendMask
;
typedef
struct
{
int
initialized
;
int
fd
;
}
io_sAgentLocal
;
typedef
struct
{
int
initialized
;
short
int
trans_id
;
int
input_size
;
int
output_size
;
int
msgs_lost
;
pwr_tTime
last_try_connect_time
;
int
reset_inputs
;
}
io_sRackLocal
;
typedef
struct
{
void
*
input_area
;
void
*
output_area
;
int
scancount
[
IO_MAXCHAN
];
int
trans_id
;
int
input_size
;
int
output_size
;
short
int
no_di
;
short
int
no_do
;
int
interval_cnt
;
int
has_read_method
;
}
io_sCardLocalMsg
;
typedef
struct
{
io_sCardLocalMsg
msg
[
2
];
}
io_sCardLocal
;
typedef
struct
{
int
initialized
;
int
fd
;
int
input_size
;
int
output_size
;
pwr_tTime
last_req_time
;
thread_sMutex
mutex
;
thread_s
receive_thread
;
}
io_sServerLocal
;
typedef
struct
{
void
*
input_area
;
void
*
output_area
;
int
scancount
[
IO_MAXCHAN
];
int
trans_id
;
int
input_size
;
int
output_size
;
int
no_di
;
int
no_do
;
int
di_offset
;
int
do_offset
;
int
di_size
;
int
do_size
;
}
io_sServerModuleLocal
;
#pragma pack(1)
typedef
struct
_read_req
{
unsigned
char
unit_id
;
unsigned
char
fc
;
short
int
addr
;
short
int
quant
;
short
int
crc
;
}
read_req
;
typedef
struct
_rec_buf
{
unsigned
char
unit_id
;
unsigned
char
fc
;
unsigned
char
buf
[
255
];
}
rec_buf
;
typedef
struct
_write_single_req
{
unsigned
char
unit_id
;
unsigned
char
fc
;
short
int
addr
;
short
int
value
;
short
int
crc
;
}
write_single_req
;
typedef
struct
_write_reg_req
{
unsigned
char
unit_id
;
unsigned
char
fc
;
short
int
addr
;
short
int
quant
;
unsigned
char
bc
;
short
int
reg
[
125
];
short
int
crc
;
}
write_reg_req
;
typedef
struct
_write_coils_req
{
unsigned
char
unit_id
;
unsigned
char
fc
;
short
int
addr
;
short
int
quant
;
unsigned
char
bc
;
unsigned
char
reg
[
247
];
short
int
crc
;
}
write_coils_req
;
typedef
struct
_read_dev_id_req
{
unsigned
char
unit_id
;
unsigned
char
fc
;
unsigned
char
mei_type
;
unsigned
char
id_code
;
unsigned
char
object_id
;
short
int
crc
;
}
read_dev_id_req
;
typedef
struct
_res_write
{
unsigned
char
unit_id
;
unsigned
char
fc
;
short
int
addr
;
short
int
quant
;
unsigned
char
buf
[
248
];
short
int
crc
;
}
res_write
;
typedef
struct
_res_read
{
unsigned
char
unit_id
;
unsigned
char
fc
;
unsigned
char
bc
;
unsigned
char
buf
[
251
];
short
int
crc
;
}
res_read
;
typedef
struct
_res_fault
{
unsigned
char
unit_id
;
unsigned
char
fc
;
unsigned
char
ec
;
short
int
crc
;
}
res_fault
;
typedef
struct
_rsp_fault
{
unsigned
char
unit_id
;
unsigned
char
fc
;
unsigned
char
ec
;
short
int
crc
;
}
rsp_fault
;
typedef
struct
_rsp_read
{
unsigned
char
unit_id
;
unsigned
char
fc
;
unsigned
char
bc
;
unsigned
char
buf
[
250
];
short
int
crc
;
}
rsp_read
;
typedef
struct
_rsp_write
{
unsigned
char
unit_id
;
unsigned
char
fc
;
short
int
addr
;
short
int
quant
;
short
int
crc
;
}
rsp_write
;
typedef
struct
_rsp_single_write
{
unsigned
char
unit_id
;
unsigned
char
fc
;
short
int
addr
;
short
int
value
;
short
int
crc
;
}
rsp_single_write
;
typedef
struct
_rsp_dev_id
{
unsigned
char
unit_id
;
unsigned
char
fc
;
unsigned
char
mei_type
;
unsigned
char
id_code
;
unsigned
char
conformity_level
;
unsigned
char
more_follows
;
unsigned
char
next_object_id
;
unsigned
char
number_of_objects
;
unsigned
char
list
[
80
];
short
int
crc
;
}
rsp_dev_id
;
#pragma pack(0)
pwr_tStatus
mb_recv_data
(
io_sRackLocal
*
local
,
io_sRack
*
rp
,
pwr_sClass_Modbus_TCP_Slave
*
sp
);
pwr_tStatus
mb_send_data
(
io_sRackLocal
*
local
,
io_sRack
*
rp
,
pwr_sClass_Modbus_TCP_Slave
*
sp
,
mb_tSendMask
mask
);
src/exe/rt_neth_acp/src/rt_neth_acp.c
View file @
4a587916
...
@@ -153,11 +153,24 @@ init (
...
@@ -153,11 +153,24 @@ init (
exit
(
sts
);
exit
(
sts
);
}
}
#if defined OS_CYGWIN
qcom_sQattr
qAttr
;
qcom_sQid
qid
=
qcom_cQnacp
;
qAttr
.
type
=
qcom_eQtype_private
;
qAttr
.
quota
=
100
;
if
(
!
qcom_CreateQ
(
&
sts
,
&
qid
,
&
qAttr
,
"nacp"
))
{
errh_Error
(
"Failed to create QCOM que
\n
%m"
,
sts
);
errh_SetStatus
(
PWR__SRVTERM
);
exit
(
sts
);
}
#else
if
(
!
qcom_AttachQ
(
&
sts
,
&
qcom_cQnacp
))
{
if
(
!
qcom_AttachQ
(
&
sts
,
&
qcom_cQnacp
))
{
errh_Fatal
(
"qcom_AttachQ, %m"
,
sts
);
errh_Fatal
(
"qcom_AttachQ, %m"
,
sts
);
errh_SetStatus
(
PWR__SRVTERM
);
errh_SetStatus
(
PWR__SRVTERM
);
exit
(
sts
);
exit
(
sts
);
}
}
#endif
*
myQid
=
qcom_cQnacp
;
*
myQid
=
qcom_cQnacp
;
if
(
!
qcom_Bind
(
&
sts
,
myQid
,
&
qcom_cQini
))
{
if
(
!
qcom_Bind
(
&
sts
,
myQid
,
&
qcom_cQini
))
{
...
...
src/exp/com/src/os_cygwin/pwr_stop.sh
View file @
4a587916
...
@@ -35,19 +35,36 @@
...
@@ -35,19 +35,36 @@
# General Public License plus this exception.
# General Public License plus this exception.
#
#
kill
-9
`
ps ax |
grep
"rt_neth_acp"
|
awk
'{ print $1}'
`
pwrp_kill_rt
()
kill
-9
`
ps ax |
grep
"rt_neth"
|
awk
'{ print $1}'
`
{
kill
-9
`
ps ax |
grep
"rt_qmon"
|
awk
'{ print $1}'
`
OLD_IFS
=
$IFS
kill
-9
`
ps ax |
grep
"rt_emon"
|
awk
'{ print $1}'
`
IFS
=
$(
echo
-en
"
\n\b
"
)
kill
-9
`
ps ax |
grep
"rt_tmon"
|
awk
'{ print $1}'
`
a
=
`
ps ax |
grep
$1
`
kill
-9
`
ps ax |
grep
"rt_
\|
/pwr/exe/rs"
|
awk
'{ print $1}'
`
kill
-9
`
ps ax |
grep
"
\[
rt_"
|
awk
'{ print $1}'
`
for
b
in
$a
kill
-9
`
ps ax |
grep
"plc_"
|
awk
'{ print $1}'
`
do
kill
-9
`
ps ax |
grep
"jpwr.rt"
|
awk
'{ print $1}'
`
c
=
`
echo
${
b
:1
}
|
awk
'{ print $1}'
`
kill
-9
`
ps ax |
grep
"rs_nmps"
|
awk
'{ print $1}'
`
kill
-9
$c
kill
-9
`
ps ax |
grep
"rs_remote"
|
awk
'{ print $1}'
`
done
kill
-9
`
ps ax |
grep
"sev_server"
|
awk
'{ print $1}'
`
# kill -9 `ps ax | grep "rt_neth_acp" | awk '{ print $2}'`
kill
-9
`
ps ax |
grep
"opc_server"
|
awk
'{ print $1}'
`
IFS
=
$OLD_IFS
}
pwrp_kill_rt
"rt_neth_acp"
pwrp_kill_rt
"rt_neth"
pwrp_kill_rt
"rt_qmon"
pwrp_kill_rt
"rt_emon"
pwrp_kill_rt
"rt_tmon"
pwrp_kill_rt
"exe/rt_"
pwrp_kill_rt
"exe/rs_"
pwrp_kill_rt
"
\[
rt_"
pwrp_kill_rt
"plc_"
pwrp_kill_rt
"jpwr.rt"
pwrp_kill_rt
"rs_nmps"
pwrp_kill_rt
"rs_remote"
pwrp_kill_rt
"sev_server"
pwrp_kill_rt
"opc_server"
if
[
-u
$pwr_exe
/rt_ini
]
;
then
if
[
-u
$pwr_exe
/rt_ini
]
;
then
user
=
`
ls
-al
$pwr_exe
/rt_ini |
awk
'{ print $3}'
`
user
=
`
ls
-al
$pwr_exe
/rt_ini |
awk
'{ print $3}'
`
else
else
...
...
src/exp/com/src/os_cygwin/pwrp_env.sh
View file @
4a587916
...
@@ -491,7 +491,7 @@ pwrc_create_func()
...
@@ -491,7 +491,7 @@ pwrc_create_func()
local proot
local proot
local bname
local bname
local pname
local pname
local platforms="
x86_
linux
x86_64_linux arm_linux x86_64_macos
"
local platforms="
x86_
cygwin
"
let argc=
$#
let argc=
$#
cmd="
project
"
cmd="
project
"
...
...
src/lib/rt/src/rt_errh.c
View file @
4a587916
...
@@ -753,7 +753,7 @@ get_name (char *name, int size)
...
@@ -753,7 +753,7 @@ get_name (char *name, int size)
{
{
int
len
=
strlen
(
UNKNOWN_PROGRAM_NAME
);
int
len
=
strlen
(
UNKNOWN_PROGRAM_NAME
);
strnc
at
(
name
,
UNKNOWN_PROGRAM_NAME
,
MIN
(
size
,
len
));
strnc
py
(
name
,
UNKNOWN_PROGRAM_NAME
,
MIN
(
size
,
len
));
name
[
MIN
(
size
,
len
)]
=
'\0'
;
name
[
MIN
(
size
,
len
)]
=
'\0'
;
...
...
src/lib/rt/src/rt_qini.c
View file @
4a587916
...
@@ -276,7 +276,9 @@ qini_BuildDb (
...
@@ -276,7 +276,9 @@ qini_BuildDb (
addQueue
(
ap
,
qcom_cImhAllOutunits
,
"allOutunits"
,
qdb_eQue_forward
,
qdb_mQue_broadcast
);
addQueue
(
ap
,
qcom_cImhAllOutunits
,
"allOutunits"
,
qdb_eQue_forward
,
qdb_mQue_broadcast
);
addQueue
(
ap
,
qcom_cIhdServer
,
"hdServer"
,
qdb_eQue_forward
,
qdb_mQue_broadcast
);
addQueue
(
ap
,
qcom_cIhdServer
,
"hdServer"
,
qdb_eQue_forward
,
qdb_mQue_broadcast
);
addQueue
(
ap
,
qcom_cIhdClient
,
"hdClient"
,
qdb_eQue_forward
,
qdb_mQue_broadcast
);
addQueue
(
ap
,
qcom_cIhdClient
,
"hdClient"
,
qdb_eQue_forward
,
qdb_mQue_broadcast
);
#if !defined OS_CYGWIN
addQueue
(
NULL
,
qcom_cInacp
,
"nacp"
,
qdb_eQue_private
,
qdb_mQue_system
);
addQueue
(
NULL
,
qcom_cInacp
,
"nacp"
,
qdb_eQue_private
,
qdb_mQue_system
);
#endif
addQueue
(
ap
,
qcom_cIini
,
"ini"
,
qdb_eQue_forward
,
qdb_mQue_system
|
qdb_mQue_event
);
addQueue
(
ap
,
qcom_cIini
,
"ini"
,
qdb_eQue_forward
,
qdb_mQue_system
|
qdb_mQue_event
);
}
qdb_ScopeUnlock
;
}
qdb_ScopeUnlock
;
...
...
src/tools/pkg/cygwin/pwr/Makefile
0 → 100644
View file @
4a587916
# port/package comment, name, category, and maintainer.
COMMENT
=
Proview development and runtime package
DISTNAME
=
pwr48-4.8.3
CATEGORIES
=
misc
MAINTAINER
=
Proview <postmaster@proview.se>
# Mandatory licensing variables.
PERMIT_PACKAGE_CDROM
=
NO
PERMIT_PACKAGE_FTP
=
NO
PERMIT_DISTFILES_CDROM
=
NO
PERMIT_DISTFILES_FTP
=
NO
# Don't build or run regress tests; specify all architectures.
NO_BUILD
=
Yes
NO_REGRESS
=
Yes
PKG_ARCH
=
amd64
# Install under /usr/local/.
do-install
:
${INSTALL_SCRIPT}
${WRKSRC}
/bin/
*
${PREFIX}
/bin/
${INSTALL_DATA_DIR}
${PREFIX}
/share/myscripts/
${INSTALL_DATA}
${WRKSRC}
/share/pwr48/
*
${PREFIX}
/share/pwr48/
# Include the BSD port system.
.
include
<bsd.port.mk>
src/tools/pkg/cygwin/pwr/build.sh
0 → 100755
View file @
4a587916
#!/bin/bash
aroot
=
"/usr/pwrp/adm"
# Get version
if
[
-e
$pwr_inc
/pwr_version.h
]
;
then
ver
=
`
eval cat
$pwr_inc
/pwr_version.h |
grep
"
\b
pwrv_cWbdbVersionShortStr
\b
"
|
awk
'{print $3}'
`
if
[
-z
$ver
]
;
then
echo
"Unable to get pwr version"
ver
=
"V00"
fi
ver
=
${
ver
:2:2
}
fi
# Generate version help file
{
if
[
!
-e
$pwre_sroot
/tools/pkg/cygwin/pwr/control
]
;
then
echo
"Controlfile not found"
exit
1
fi
datfile
=
$pwre_sroot
/tools/pkg/cygwin/pwr/control
echo
"<topic> version"
d
=
`
eval date
+
\"
%F %X
\"
`
{
let
printout
=
0
while
read
line
;
do
if
[
"
${
line
:0:9
}
"
=
"Package: "
]
;
then
package
=
${
line
#Package
:
}
fi
if
[
"
${
line
:0:9
}
"
=
"Version: "
]
;
then
version
=
${
line
#Version
:
}
fi
if
[
"
${
line
:0:14
}
"
=
"Architecture: "
]
;
then
arch
=
${
line
#Architecture
:
}
fi
if
[
"
${
line
:0:12
}
"
=
"Description:"
]
;
then
echo
""
echo
"<image> pwr_logga.gif"
echo
""
echo
""
echo
""
echo
"<b>Proview V
${
version
:0:3
}
"
echo
"Version V
$version
"
echo
""
echo
"Copyright 2004-
${
d
:0:4
}
SSAB Oxelsund AB"
echo
""
echo
"This program is free software; you can redistribute it and/or"
echo
"modify it under the terms of the GNU General Public License as"
echo
"published by the Free Software Foundation, either version 2 of"
echo
"the License, or (at your option) any later version."
echo
""
echo
"This program is distributed in the hope that it will be useful"
echo
"but WITHOUT ANY WARRANTY; without even the implied warranty of"
echo
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
echo
"For more details, see the"
echo
"GNU General Public License. <weblink> http://www.proview.se/gpllicense.html"
echo
""
echo
"E-mail postmaster@proview.se"
echo
"Internet www.proview.se <link> http://www.proview.se/index.html"
echo
""
echo
""
echo
"<b>Package"
echo
"Package
$package
""_""
$version
""_""
$arch
"
echo
"Build date
$d
"
echo
"Package description:"
echo
""
printout
=
1
else
if
[
$printout
-eq
1
]
;
then
echo
$line
fi
fi
done
}
<
$datfile
echo
"</topic>"
}
>
$pwr_eexe
/wtt_version_help.dat
# Convert to html
co_convert
-t
-d
$pwr_doc
$pwr_eexe
/wtt_version_help.dat
{
echo
"<html><head>"
echo
"<meta http-equiv=
\"
Refresh
\"
content=
\"
5;../wtt_version_help_version.html
\"
>"
echo
"</head></html>"
}
>
$pwr_doc
/en_us/package_version.html
if
[
"
$1
"
==
"-v"
]
;
then
exit
fi
pkgroot
=
$pwre_broot
/
$pwre_target
/bld/pkg/pwr
$ver
pkgsrc
=
$pwre_sroot
/tools/pkg/cygwin/pwr
packagename
=
pwr
$ver
-
$version
.tar.gz
echo
"-- Building pwr
$ver
"
# Create directories
mkdir
-p
$pkgroot
/etc/pwr
$ver
mkdir
-p
$pkgroot
/usr/share/doc/pwr
$ver
mkdir
-p
$pkgroot
/usr/pwrp
mkdir
-p
$pkgroot
/etc
find
$pkgroot
-type
d | xargs
chmod
755
# copyright
cp
$pkgsrc
/copyright
$pkgroot
/usr/share/doc/pwr
$ver
# changelog
cp
$pkgsrc
/changelog
$pkgroot
/usr/share/doc/pwr
$ver
gzip
-fq
--best
$pkgroot
/usr/share/doc/pwr
$ver
/changelog
# Man pages
mkdir
-p
$pkgroot
/usr/share/man/man1
cp
$pkgsrc
/pwr.1
$pkgroot
/usr/share/man/man1/pwr.1
gzip
-fq
--best
$pkgroot
/usr/share/man/man1/pwr.1
# Copy proview
mkdir
$pkgroot
/usr/pwr
$ver
currentdir
=
"
`
eval pwd
`
"
tarfile
=
$pwre_broot
/
$pwre_target
/bld/pkg/pwrtmp.tar
cd
$pwre_broot
echo
"-- copy release to package tree"
tar
-cf
$tarfile
$pwre_target
/exp
cd
$pkgroot
/usr/pwr
$ver
tar
-xf
$tarfile
rm
$tarfile
cd
$currentdir
# Remove not needed libraries
rm
$pkgroot
/usr/pwr
$ver
/
$pwre_target
/exp/lib/libpwr_flow.a
rm
$pkgroot
/usr/pwr
$ver
/
$pwre_target
/exp/lib/libpwr_ge.a
rm
$pkgroot
/usr/pwr
$ver
/
$pwre_target
/exp/lib/libpwr_glow.a
rm
$pkgroot
/usr/pwr
$ver
/
$pwre_target
/exp/lib/libpwr_tlog.a
rm
$pkgroot
/usr/pwr
$ver
/
$pwre_target
/exp/lib/libpwr_wb.a
rm
$pkgroot
/usr/pwr
$ver
/
$pwre_target
/exp/lib/libpwr_xtt.a
# Copy configuration files to cnf
cp
$pkgsrc
/proview.cnf
$pkgroot
/usr/pwr
$ver
/
$pwre_target
/exp/cnf
cp
$pkgsrc
/pwrp_profile
$pkgroot
/etc
chmod
a+x
$pkgroot
/etc/pwrp_profile
# Copy adm files to cnf
cp
$pwre_sroot
/tools/pkg/deb/adm/pwr_setup.sh
$pkgroot
/usr/pwr
$ver
/
$pwre_target
/exp/cnf
echo
"pwrp set base V
${
ver
:0:1
}
.
${
ver
:1:1
}
"
>>
$pkgroot
/usr/pwr
$ver
/
$pwre_target
/exp/cnf/pwr_setup.sh
chmod
a+x
$pkgroot
/usr/pwr
$ver
/
$pwre_target
/exp/cnf/pwr_setup.sh
cp
$pwre_sroot
/tools/pkg/deb/adm/pwra_env.sh
$pkgroot
/usr/pwr
$ver
/
$pwre_target
/exp/cnf
chmod
a+x
$pkgroot
/usr/pwr
$ver
/
$pwre_target
/exp/cnf/pwra_env.sh
cp
$pwre_sroot
/tools/pkg/deb/adm/pwr_volumelist.dat
$pkgroot
/usr/pwr
$ver
/
$pwre_target
/exp/cnf
cp
$pwre_sroot
/tools/pkg/deb/adm/pwr_user2.dat
$pkgroot
/usr/pwr
$ver
/
$pwre_target
/exp/cnf
cp
$pwre_sroot
/tools/pkg/deb/adm/proview_icon.png
$pkgroot
/usr/pwr
$ver
/
$pwre_target
/exp/cnf
# Copy user to cnf
mkdir
$pkgroot
/usr/pwr
$ver
/
$pwre_target
/exp/cnf/user
cp
$pwre_sroot
/tools/pkg/cygwin/user/.bashrc
$pkgroot
/usr/pwr
$ver
/
$pwre_target
/exp/cnf/user
echo
"source
$aroot
/db/pwr_setup.sh"
>>
$pkgroot
/usr/pwr
$ver
/
$pwre_target
/exp/cnf/user/.bashrc
cp
$pwre_sroot
/tools/pkg/deb/user/.bash_profile
$pkgroot
/usr/pwr
$ver
/
$pwre_target
/exp/cnf/user
cp
$pwre_sroot
/tools/pkg/deb/user/.rtt_start
$pkgroot
/usr/pwr
$ver
/
$pwre_target
/exp/cnf/user
cp
$pwre_sroot
/tools/pkg/deb/user/.xtt_start
$pkgroot
/usr/pwr
$ver
/
$pwre_target
/exp/cnf/user
cp
$pwre_sroot
/tools/pkg/deb/user/wtt_init.pwr_com
$pkgroot
/usr/pwr
$ver
/
$pwre_target
/exp/cnf/user
cp
$pwre_sroot
/tools/pkg/deb/user/wtt_init1.pwr_com
$pkgroot
/usr/pwr
$ver
/
$pwre_target
/exp/cnf/user
cp
$pwre_sroot
/tools/pkg/cygwin/user/Proview.lnk
$pkgroot
/usr/pwr
$ver
/
$pwre_target
/exp/cnf/user
cp
$pwre_sroot
/tools/pkg/cygwin/user/proview_icon.ico
$pkgroot
/usr/pwr
$ver
/
$pwre_target
/exp/cnf/user
# Generate startscript
{
echo
"#!/bin/bash"
echo
"export PATH=/usr/local/bin:/usr/bin"
echo
"export pwra_db=
$aroot
/db"
echo
"source
\$
pwra_db/pwr_setup.sh"
echo
"source
\$
pwra_db/pwra_env.sh set base V""
${
version
:0:3
}
"""
echo
"source
\$
pwra_db/pwra_env.sh set bus"
echo
"export DISPLAY=127.0.0.1:0"
echo
"wb_gtk -p pwrp pwrp"
}
>
$pkgroot
/usr/pwr
$ver
/
$pwre_target
/exp/cnf/user/pwrstart
# Create package
echo
"-- Building package"
mkdir
-p
$pkgroot
/etc/pwr
$ver
cd
$pkgroot
find
*
-type
f
-exec
echo
"rm -f /{}"
\;
>
$pkgroot
/etc/pwr
$ver
/rmfiles.sh
echo
"rm -r /usr/pwr
$ver
"
>>
$pkgroot
/etc/pwr
$ver
/rmfiles.sh
# control
cp
$pkgsrc
/control
$pkgroot
/etc/pwr
$ver
cp
$pkgsrc
/prerm
$pkgroot
/etc/pwr
$ver
cp
$pkgsrc
/postinst
$pkgroot
/etc/pwr
$ver
tar
-czf
../
$packagename
*
rm
-r
$pkgroot
src/tools/pkg/cygwin/pwr/changelog
0 → 100644
View file @
4a587916
Proview V3.4b (3.4.1-1)
\ No newline at end of file
src/tools/pkg/cygwin/pwr/control
0 → 100644
View file @
4a587916
Package: pwr48
Version: 4.8.6-1
Section: base
Priority: optional
Architecture: i386
Depends: libc6 (>= 2.11.2-7), libgtk2.0-0 (>= 2.20.1-2), libasound2 (>= 1.0.23-2.1), libdb4.8 (>=4.8.30-2), libdb4.8++ (>= 4.8.30-2), libmysql++3 (>= 3.0.9-1+b1), g++ (>= 4:4.4.5-1)
Replaces: pwrrt,pwr34,pwr39,pwr40,pwr41,pwr42,pwr43,pwr44,pwr45,pwr46,pwr47
Maintainer: Proview <postmaster@proview.se>
Description: Proview development and runtime environment package
Proview development and runtime environment
4.8.0-1 Base release
4.8.1-1
- I/O support for Arduino USB board.
- Remote support for Websphere Message Queue.
- Operator event logging and replay.
- Chinese translation in operator environment.
4.8.1-2
- Profinet configurator, ordernumber showed in module enum list.
- Curve window, second mark and export dialog added.
- Profibus/Profinet configurator, default module class setting added, and Appl button added.
- Configurator fix, Delete, Create and Move object menu items were not insensive in view mode.
- Plc link, problem with uppercase nodename for opt-file fixed.
- Xtt, problems with OpPlace and XttGraph objects in SharedVolume fixed.
- Plc compile, problem with compile of component subwindows fixed.
- Wb object editor, Ctrl DoubleClick MB1 didn't work on attribute references.
- Flow alloc color problem fixed.
- wb locale fix for ubuntu.
4.8.2-1
- Support for Hilscher cifX boards.
- Support for Hilscher cifX Profinet Controller.
- UDP communication configured with IO objects.
- Support for USB joystick.
4.8.3-1
- Support for OpenBSD.
src/tools/pkg/cygwin/pwr/copyright
0 → 100644
View file @
4a587916
Proview
Copyright: SSAB Oxelsund AB <ssabox.com>
2003-11-21
The home page of Proview is at:
http://www.proview.se
src/tools/pkg/cygwin/pwr/postinst
0 → 100755
View file @
4a587916
#!/bin/bash
set
-e
# Get version from current path
dname
=
`
eval dirname
$0
`
pwrdir
=
`
eval
bash
-c
"cd
$dname
; pwd"
`
ver
=
"
${
pwrdir
:12:1
}${
pwrdir
:13:1
}
"
echo
$pwrdir
$ver
pwre_target
=
"os_cygwin/hw_x86"
echo
"Here in postinst..."
# Automatically added by dh_installdocs
if
[
"
$1
"
=
"configure"
]
;
then
if
[
-d
/usr/doc
-a
!
-e
/usr/doc/pwrtest
-a
-d
/usr/share/doc/pwrtest
]
;
then
ln
-sf
../share/doc/pwrtest /usr/doc/pwrtest
fi
fi
# End automatically added section
aroot
=
"/usr/pwrp/adm"
cp
/usr/pwr
$ver
/
$pwre_target
/exp/cnf/user/pwrstart ~/
chmod
a+x ~/pwrstart
cp
/usr/pwr
$ver
/
$pwre_target
/exp/cnf/user/Proview.lnk
$USERPROFILE
/Desktop
cp
/usr/pwr
$ver
/
$pwre_target
/exp/cnf/user/proview_icon.ico
$USERPROFILE
/Download
#chmod u+s /usr/pwr$ver/$pwre_target/exp/exe/rt_ini
#chmod u+s /usr/pwr$ver/$pwre_target/exp/exe/rt_rtt
#chmod u+s /usr/pwr$ver/$pwre_target/exp/exe/rt_xtt
#chmod u+s /usr/pwr$ver/$pwre_target/exp/exe/rt_bck
# Copy configuration files
new_cnf
=
0
if
[
!
-e
/etc/proview.cnf
]
;
then
cp
/usr/pwr
$ver
/
$pwre_target
/exp/cnf/proview.cnf /etc
new_cnf
=
1
fi
# Add pwrp_profile to profile
if
!
grep
-q
"/etc/pwrp_profile
\b
"
/etc/profile
;
then
cat
>>
/etc/profile
<<-
EOF
if [ -e /etc/pwrp_profile ]; then
. /etc/pwrp_profile
fi
EOF
fi
# Create and copy adm
if
[
!
-e
$aroot
/db
]
;
then
mkdir
-p
$aroot
/db
fi
cp
/usr/pwr
$ver
/
$pwre_target
/exp/cnf/pwra_env.sh
$aroot
/db
cp
/usr/pwr
$ver
/
$pwre_target
/exp/cnf/pwr_setup.sh
$aroot
/db
cp
/usr/pwr
$ver
/
$pwre_target
/exp/cnf/proview_icon.png
$aroot
/db
if
[
!
-e
$aroot
/db/pwr_volumelist.dat
]
;
then
cp
/usr/pwr
$ver
/
$pwre_target
/exp/cnf/pwr_volumelist.dat
$aroot
/db
fi
if
[
!
-e
$aroot
/db/pwr_user2.dat
]
;
then
cp
/usr/pwr
$ver
/
$pwre_target
/exp/cnf/pwr_user2.dat
$aroot
/db
fi
# Insert base in projectlist
if
[
!
-e
$aroot
/db/pwr_projectlist.dat
]
;
then
echo
"%base V
${
ver
:0:1
}
.
${
ver
:1:1
}
/usr/pwr
$ver
"
>
$aroot
/db/pwr_projectlist.dat
else
set
+e
ptst
=
`
eval grep
"^%base"
$aroot
/db/pwr_projectlist.dat |
grep
"
\b
V
${
ver
:0:1
}
.
${
ver
:1:1
}
\b
"
`
set
-e
if
[
"
$ptst
"
=
""
]
;
then
echo
"%base V
${
ver
:0:1
}
.
${
ver
:1:1
}
/usr/pwr
$ver
"
>>
$aroot
/db/pwr_projectlist.dat
fi
fi
# Change group to pwrp
#chgrp pwrp $aroot
#chmod g+w $aroot
#chgrp -R pwrp $aroot/*
#chmod -R g+w $aroot/*
chmod
a+w /usr/pwr
$ver
/
$pwre_target
/exp/load/
*
.dbs
# Create project root
if
[
!
-e
/usr/local/pwrp
]
;
then
mkdir
/usr/local/pwrp
# chgrp pwrp /usr/local/pwrp
# chmod g+w /usr/local/pwrp
fi
src/tools/pkg/cygwin/pwr/prerm
0 → 100755
View file @
4a587916
#!/bin/bash
set
-e
echo
"Here in prerm..."
# Automatically added by dh_installdocs
if
[
\(
"
$1
"
=
"upgrade"
-o
"
$1
"
=
"remove"
\)
-a
-L
/usr/doc/pwrtest
]
;
then
rm
-f
/usr/doc/pwrtest
fi
# End automatically added section
dname
=
`
eval dirname
$0
`
chmod
a+x
$dname
/rmfiles.sh
$dname
/rmfiles.sh
src/tools/pkg/cygwin/pwr/proview.cnf
0 → 100644
View file @
4a587916
#
# Configuration file for Proview
#
# Default QCOM Bus Id
#
qcomBusId 999
#
# Web directory
#
webDirectory /var/www
#
# Default privileges for SevXtt: Read, Admin or None
#
sevXttDefaultPriv Read
src/tools/pkg/cygwin/pwr/pwr.1
0 → 100644
View file @
4a587916
PWR(1) Proview Manuals PWR(1)
NAME
pwr - start and stop Proview runtime environment
SYNOPSIS
pwr [start][stop]
DESCRIPTION
Start and stop command for Proview runtime environment.
OPTIONS
start Start Proview runtime environment.
stop Stop Proview runtime environment.
FILES
/etc/pwrp_profile
The system wide configuration file..
AUTHOR
Written by CS.
SEE ALSO
pwr(5)
Proview Last change: Nov 2003
src/tools/pkg/cygwin/pwr/pwrp_profile
0 → 100644
View file @
4a587916
bus_id=""
if [ -e /etc/proview.cnf ]; then
bus_id=`eval cat /etc/proview.cnf | grep "\\bqcomBusId\\b" | awk '{print $2}'`
fi
if [ -e /etc/proview.cnf ]; then
web_dir=`eval cat /etc/proview.cnf | grep "\\bwebDirectory\\b" | awk '{print $2}'`
fi
export PWR_BUS_ID=$bus_id
export pwrb_root=/usr/pwrrt
export pwrp_root=/pwrp
export pwr_exe=$pwrb_root/exe
export pwr_lib=$pwrb_root/lib
export pwr_obj=$pwrb_root/obj
export pwr_inc=$pwrb_root/inc
export pwr_load=$pwrb_root/load
export pwr_lis=$pwrb_root/lis
export pwr_doc=$pwrb_root/doc
export pwrp_exe=$pwrp_root/x86_cygwin/exe
export pwrp_lib=$pwrp_root/x86_cygwin/lib
export pwrp_obj=$pwrp_root/x86_cygwin/obj
export pwrp_lis=$pwrp_root/x86_cygwin/lis
export pwrp_inc=$pwrp_root/common/inc
export pwrp_load=$pwrp_root/common/load
export pwrp_log=$pwrp_root/common/log
export pwrp_db=$pwrp_root/common/db
if [ "$web_dir" = "" ]; then
export pwrp_web=$pwrp_root/common/web
else
export pwrp_web=$web_dir
fi
export pwra_db=/usr/pwrp/adm/db
jdk=`eval ls -t /usr/local | grep ^jdk`
if [ "$jdk" == "" ]; then
jdk=`eval ls -t /usr/local | grep ^jre`
fi
export jdk=/usr/local/$jdk
export jdk_home=$jdk/bin
PATH=$PATH:$pwr_exe:$pwrp_exe:$jdk_home
#Set display to remote computer
export DISPLAY=$REMOTEHOST:0.0
#symbols to define start/stop commands for PWR
alias pwr_stop='/etc/pwrrt/pwr stop'
alias pwr_stop.sh="/etc/pwrrt/pwr stop"
alias pwr_start="/etc/pwrrt/pwr start"
alias pwr="/etc/pwrrt/pwr"
alias boot="/usr/bin/sudo /sbin/reboot"
if [ -e $pwrp_exe/profile ]; then
source $pwrp_exe/profile
fi
src/tools/pkg/cygwin/pwrdemo/build.sh
0 → 100755
View file @
4a587916
#!/bin/bash
set
-o
xtrace
aroot
=
"/usr/pwrp/adm"
# Get version
if
[
-e
$pwr_inc
/pwr_version.h
]
;
then
ver
=
`
eval cat
$pwr_inc
/pwr_version.h |
grep
"
\b
pwrv_cWbdbVersionShortStr
\b
"
|
awk
'{print $3}'
`
if
[
-z
$ver
]
;
then
echo
"Unable to get pwr version"
ver
=
"V00"
fi
ver
=
${
ver
:2:2
}
fi
datfile
=
$pwre_sroot
/tools/pkg/cygwin/pwrdemo/control
{
while
read
line
;
do
if
[
"
${
line
:0:9
}
"
=
"Version: "
]
;
then
version
=
${
line
#Version
:
}
fi
done
}
<
$datfile
proot
=
/data0/pwrp/pwrdemo
$ver
pkgroot
=
$pwre_broot
/
$pwre_target
/bld/pkg/pwrdemo
$ver
pkgsrc
=
$pwre_sroot
/tools/pkg/cygwin/pwrdemo
packagename
=
pwrdemo
$ver
-
$version
.tar.gz
echo
"-- Building pwrdemo
$ver
"
# Create directories
mkdir
-p
$pkgroot
/etc/pwrdemo
$ver
# Copy pwrdemo
mkdir
-p
$pkgroot
/usr/pwrp/pwrdemo
$ver
mkdir
-p
$pkgroot
/usr/pwrp/pwrdemo
$ver
/cnf
currentdir
=
"
`
eval pwd
`
"
tarfile
=
$pwre_broot
/
$pwre_target
/bld/pkg/pwrtmp.tar
cd
$proot
cd
..
echo
"-- copy project to package tree"
tar
-cf
$tarfile
pwrdemo
$ver
cd
$pkgroot
/usr/pwrp
tar
-xf
$tarfile
rm
$tarfile
cd
$currentdir
cp
$pwre_sroot
/tools/pkg/cygwin/user/ProviewDemo.lnk
$pkgroot
/usr/pwrp/pwrdemo
$ver
/cnf
cp
$pwre_sroot
/tools/pkg/cygwin/user/proview_icon.ico
$pkgroot
/usr/pwrp/pwrdemo
$ver
/cnf
# Generate startscript
{
echo
"#!/bin/bash"
echo
"export PATH=/usr/local/bin:/usr/bin"
echo
"export pwra_db=
$aroot
/db"
echo
"source
\$
pwra_db/pwr_setup.sh"
echo
"source
\$
pwra_db/pwra_env.sh set base V""
${
version
:0:3
}
"""
echo
"source
\$
pwra_db/pwra_env.sh set bus"
echo
"pwrp set project pwrdemo
$ver
"
echo
"export DISPLAY=127.0.0.1:0"
echo
"pwr_rtmon"
}
>
$pkgroot
/usr/pwrp/pwrdemo
$ver
/cnf/pwrdemostart
# Create package
echo
"-- Building package"
cd
$pkgroot
cp
$pkgsrc
/control
$pkgroot
/etc/pwrdemo
$ver
cp
$pkgsrc
/prerm
$pkgroot
/etc/pwrdemo
$ver
cp
$pkgsrc
/postinst
$pkgroot
/etc/pwrdemo
$ver
tar
-czf
../
$packagename
*
rm
-r
$pkgroot
src/tools/pkg/cygwin/pwrdemo/changelog
0 → 100644
View file @
4a587916
Proview V3.4b (3.4.1-1)
\ No newline at end of file
src/tools/pkg/cygwin/pwrdemo/changelog.Debian
0 → 100644
View file @
4a587916
Proview. See also normal changelog file.
\ No newline at end of file
src/tools/pkg/cygwin/pwrdemo/control
0 → 100644
View file @
4a587916
Package: pwrdemo48
Version: 4.8.5-1
Section: base
Priority: optional
Architecture: i386
Depends: pwr48 (>= 4.8.5-1)
Maintainer: Proview <postmaster@proview.se>
Description: Proview Demo Project package
Proview Demo Project
4.8.0-1 Base release
src/tools/pkg/cygwin/pwrdemo/copyright
0 → 100644
View file @
4a587916
Proview
Copyright: SSAB Oxelsund AB <ssabox.com>
2003-11-21
The home page of Proview is at:
http://www.proview.se
src/tools/pkg/cygwin/pwrdemo/postinst
0 → 100755
View file @
4a587916
#!/bin/bash
set
-e
echo
"Here in postinst..."
# Get version from current path
dname
=
`
eval dirname
$0
`
pwrdir
=
`
eval
bash
-c
"cd
$dname
; pwd"
`
ver
=
"
${
pwrdir
:12:1
}${
pwrdir
:13:1
}
"
aroot
=
"/usr/pwrp/adm"
export
pwra_db
=
$aroot
/db
# Register volume
if
[
-e
$aroot
/db/pwr_volumelist.dat
]
;
then
set
+e
ptst
=
`
eval grep
"'
\b
VolPwrDemo
\b
'"
$aroot
/db/pwr_volumelist.dat |
grep
"
\b
pwrdemo
\b
"
`
set
-e
if
[
"
$ptst
"
=
""
]
;
then
echo
" VolPwrDemo 0.254.254.200 pwrdemo"
>>
$aroot
/db/pwr_volumelist.dat
fi
fi
# Insert base in projectlist
if
[
-e
$aroot
/db/pwr_projectlist.dat
]
;
then
set
+e
ptst
=
`
eval grep
"'
\b
pwrdemo
$ver
\b
'"
$aroot
/db/pwr_projectlist.dat
`
set
-e
if
[
"
$ptst
"
=
""
]
;
then
echo
"pwrdemo
$ver
V
${
ver
:0:1
}
.
${
ver
:1:1
}
/usr/pwrp/pwrdemo
$ver
pwrdemo
$ver
\"\"
"
>>
$aroot
/db/pwr_projectlist.dat
fi
fi
# Insert nodename in DirectoryVolume and create bootfile
nodename
=
`
eval uname
-n
`
initsh
=
/tmp/pwrdemo_init.sh
initpwrc
=
/tmp/pwrdemo_init.pwr_com
# Create a shellscript that attaches to projects and runs wb_cmd
cat
>
$initsh
<<
EOF
#!/bin/bash
source
$aroot
/db/pwr_setup.sh
source
\$
pwr_exe/pwrp_env.sh set project pwrdemo
$ver
wb_cmd_gtk @
$initpwrc
EOF
chmod
a+x
$initsh
# Create a wb_cmd script that inserts nodename and creates bootfile
cat
>
$initpwrc
<<
EOF
set attr/name=Bus999-DemoNode/attr=NodeName/value="
$nodename
"/noconf
save
create boot/node=DemoNode
exit
EOF
# Execute shellscript
$initsh
rm
$initsh
rm
$initpwrc
if
[
-e
$USERPROFILE
/Desktop
]
;
then
cp
/usr/pwrp/pwrdemo
$var
/cnf/pwrdemostart ~/
chmod
a+x ~/pwrdemostart
cp
/usr/pwrp/pwrdemo
$ver
/cnf/ProviewDemo.lnk
$USERPROFILE
/Desktop
cp
/usr/pwrp/pwrdemo
$ver
/cnf/proview_icon.ico
$USERPROFILE
/Download
fi
src/tools/pkg/cygwin/pwrdemo/prerm
0 → 100755
View file @
4a587916
#
# ver='version' is added by build.sh
#
set -e
echo "Here in prerm..."
# Automatically added by dh_installdocs
if [ \( "$1" = "upgrade" -o "$1" = "remove" \) -a -L /usr/doc/pwrtest ]; then
rm -f /usr/doc/pwrtest
fi
# End automatically added section
if [ -e /usr/pwrp/pwrdemo$ver ]; then
rm -r /usr/pwrp/pwrdemo$ver
fi
src/tools/pkg/cygwin/pwrrt/build.sh
0 → 100755
View file @
4a587916
#!/bin/bash
# Get version
if
[
-e
$pwr_inc
/pwr_version.h
]
;
then
ver
=
`
eval cat
$pwr_inc
/pwr_version.h |
grep
"
\b
pwrv_cWbdbVersionShortStr
\b
"
|
awk
'{print $3}'
`
if
[
-z
$ver
]
;
then
echo
"Unable to get pwr version"
ver
=
"V00"
fi
ver
=
${
ver
:2:2
}
fi
# Generate version help file
{
if
[
!
-e
$pwre_sroot
/tools/pkg/cygwin/pwrrt/control
]
;
then
echo
"Controlfile not found"
exit
1
fi
datfile
=
$pwre_sroot
/tools/pkg/cygwin/pwrrt/control
echo
"<topic> version"
d
=
`
eval date
+
\"
%F %X
\"
`
{
let
printout
=
0
while
read
line
;
do
if
[
"
${
line
:0:9
}
"
=
"Package: "
]
;
then
package
=
${
line
#Package
:
}
fi
if
[
"
${
line
:0:9
}
"
=
"Version: "
]
;
then
version
=
${
line
#Version
:
}
fi
if
[
"
${
line
:0:14
}
"
=
"Architecture: "
]
;
then
arch
=
${
line
#Architecture
:
}
fi
if
[
"
${
line
:0:12
}
"
=
"Description:"
]
;
then
echo
""
echo
"<image> pwr_logga.gif"
echo
""
echo
""
echo
""
echo
"<b>Proview V
${
version
:0:3
}
"
echo
"Version V
$version
"
echo
""
echo
"Copyright 2004-
${
d
:0:4
}
SSAB Oxelsund AB"
echo
""
echo
"This program is free software; you can redistribute it and/or"
echo
"modify it under the terms of the GNU General Public License as"
echo
"published by the Free Software Foundation, either version 2 of"
echo
"the License, or (at your option) any later version."
echo
""
echo
"This program is distributed in the hope that it will be useful"
echo
"but WITHOUT ANY WARRANTY; without even the implied warranty of"
echo
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
echo
"For more details, see the"
echo
"GNU General Public License. <weblink> http://www.proview.se/gpllicense.html"
echo
""
echo
"E-mail postmaster@proview.se <weblink> mailto:postmaster@proview.se"
echo
"Internet www.proview.se <weblink> http://www.proview.se"
echo
""
echo
""
echo
"<b>Package"
echo
"Package
$package
""_""
$version
""_""
$arch
"
echo
"Build date
$d
"
echo
"Package description:"
echo
""
printout
=
1
else
if
[
$printout
-eq
1
]
;
then
echo
$line
fi
fi
done
}
<
$datfile
echo
"</topic>"
}
>
$pwr_eexe
/xtt_version_help.dat
# Convert to html
co_convert
-t
-d
$pwr_doc
$pwr_eexe
/xtt_version_help.dat
{
echo
"<html><head>"
echo
"<meta http-equiv=
\"
Refresh
\"
content=
\"
5;../xtt_version_help_version.html
\"
>"
echo
"</head></html>"
}
>
$pwr_doc
/en_us/package_version.html
# Print rt version file
echo
"Version:
$version
"
>
$pwr_eexe
/rt_version.dat
if
[
"
$1
"
==
"-v"
]
;
then
exit
fi
pkgroot
=
$pwre_broot
/
$pwre_target
/bld/pkg/pwrrt
pkgsrc
=
$pwre_sroot
/tools/pkg/cygwin/pwrrt
packagename
=
pwrrt-
$version
.tar.gz
# Create directories
echo
"-- Create package tree"
mkdir
-p
$pkgroot
/etc/pwrrt
mkdir
-p
$pkgroot
/usr/share/doc/pwrrt
mkdir
-p
$pkgroot
/etc/init.d
find
$pkgroot
-type
d | xargs
chmod
755
# copyright
cp
$pkgsrc
/copyright
$pkgroot
/usr/share/doc/pwrrt
# changelog
cp
$pkgsrc
/changelog
$pkgroot
/usr/share/doc/pwrrt
gzip
-fq
--best
$pkgroot
/usr/share/doc/pwrrt/changelog
# Startup files
cp
$pkgsrc
/pwrp_profile
$pkgroot
/etc
chmod
a+x
$pkgroot
/etc/pwrp_profile
cp
$pkgsrc
/pwr
$pkgroot
/etc/init.d
chmod
a+x
$pkgroot
/etc/init.d/pwr
#cp $pkgsrc/gdhserver $pkgroot/etc/init.d
#chmod a+x $pkgroot/etc/init.d/gdhserver
# Man pages
mkdir
-p
$pkgroot
/usr/share/man/man1
cp
$pkgsrc
/pwr.1
$pkgroot
/usr/share/man/man1/pwr.1
gzip
-fq
--best
$pkgroot
/usr/share/man/man1/pwr.1
cp
$pkgsrc
/rt_ini.1
$pkgroot
/usr/share/man/man1/rt_ini.1
gzip
-fq
--best
$pkgroot
/usr/share/man/man1/rt_ini.1
cp
$pkgsrc
/rt_xtt.1
$pkgroot
/usr/share/man/man1/rt_xtt.1
gzip
-fq
--best
$pkgroot
/usr/share/man/man1/rt_xtt.1
cp
$pkgsrc
/rt_rtt.1
$pkgroot
/usr/share/man/man1/rt_rtt.1
gzip
-fq
--best
$pkgroot
/usr/share/man/man1/rt_rtt.1
# Copy proview
mkdir
$pkgroot
/usr/pwrrt
currentdir
=
"
`
eval pwd
`
"
tarfile
=
$pwre_broot
/
$pwre_target
/bld/pkg/pwrtmp.tar
cd
$pwre_broot
/
$pwre_target
/exp
echo
"-- Copy release to package tree"
tar
-cf
$tarfile
*
cd
$pkgroot
/usr/pwrrt
tar
-xf
$tarfile
rm
$tarfile
rm
-r
$pkgroot
/usr/pwrrt/lib/
*
.a
rm
-r
$pkgroot
/usr/pwrrt/exe/wb
*
cp
$pwr_eexe
/wb_distr_keepboot.sh
$pkgroot
/usr/pwrrt/exe
cd
$currentdir
# Copy configuration files to cnf
cp
$pkgsrc
/proview.cnf
$pkgroot
/usr/pwrrt/cnf
# Copy op to cnf
mkdir
$pkgroot
/usr/pwrrt/cnf/op
cp
$pwre_sroot
/tools/pkg/cygwin/op/.bashrc
$pkgroot
/usr/pwrrt/cnf/op
cp
$pwre_sroot
/tools/pkg/deb/op/.bash_profile
$pkgroot
/usr/pwrrt/cnf/op
#cp $pwre_sroot/tools/pkg/deb/op/.mwmrc $pkgroot/usr/pwrrt/cnf/op
cp
$pwre_sroot
/tools/pkg/deb/op/.rtt_start
$pkgroot
/usr/pwrrt/cnf/op
cp
$pwre_sroot
/tools/pkg/deb/op/.xtt_start
$pkgroot
/usr/pwrrt/cnf/op
#cp $pwre_sroot/tools/pkg/deb/op/.xsession $pkgroot/usr/pwrrt/cnf/op
# Copy user to cnf
mkdir
$pkgroot
/usr/pwrrt/cnf/user
cp
$pwre_sroot
/tools/pkg/cygwin/user/.bashrc
$pkgroot
/usr/pwrrt/cnf/user
cp
$pwre_sroot
/tools/pkg/deb/user/.bash_profile
$pkgroot
/usr/pwrrt/cnf/user
#cp $pwre_sroot/tools/pkg/deb/user/.mwmrc $pkgroot/usr/pwrrt/cnf/user
cp
$pwre_sroot
/tools/pkg/deb/user/.rtt_start
$pkgroot
/usr/pwrrt/cnf/user
cp
$pwre_sroot
/tools/pkg/deb/user/.xtt_start
$pkgroot
/usr/pwrrt/cnf/user
#cp $pwre_sroot/tools/pkg/deb/user/.xsession $pkgroot/usr/pwrrt/cnf/user
# Create package
mkdir
-p
$pkgroot
/etc/pwrrt
cd
$pkgroot
find
*
-type
f
-exec
echo
"rm -f /{}"
\;
>
$pkgroot
/etc/pwrrt/rmfiles.sh
echo
"rm -r /usr/pwrrt"
>>
$pkgroot
/etc/pwrrt/rmfiles.sh
# control
cp
$pkgsrc
/control
$pkgroot
/etc/pwrrt
cp
$pkgsrc
/prerm
$pkgroot
/etc/pwrrt
cp
$pkgsrc
/postinst
$pkgroot
/etc/pwrrt
cp
$pkgsrc
/pwr
$pkgroot
/etc/pwrrt
tar
-czf
../
$packagename
*
rm
-r
$pkgroot
src/tools/pkg/cygwin/pwrrt/changelog
0 → 100644
View file @
4a587916
Proview V3.4b (3.4.1-1)
\ No newline at end of file
src/tools/pkg/cygwin/pwrrt/control
0 → 100644
View file @
4a587916
Package: pwrrt
Version: 4.8.6-1
Section: base
Priority: optional
Architecture: i386
Depends: libc6 (>= 2.11.2-7), libgtk2.0-0 (>= 2.20.1-2), libasound2 (>= 1.0.23-2.1), libdb4.8 (>=4.8.30-2)
Replaces: pwr34,pwr39,pwr40,pwr41,pwr42,pwr43,pwr44,pwr45,pwr46,pwr47,pwr48
Maintainer: Proview <postmaster@proview.se>
Description:
Proview runtime environment
4.8.0-1 Base release
4.8.1-1
- I/O support for Arduino USB board.
- Remote support for Websphere Message Queue.
- Operator event logging and replay.
- Chinese translation in operator environment.
4.8.1-2
- Curve window, second mark and export dialog added.
- Xtt, problems with OpPlace and XttGraph objects in SharedVolume fixed.
- Flow alloc color problem fixed.
4.8.2-1
- Support for Hilscher cifX boards.
- Support for Hilscher cifX Profinet Controller.
- UDP communication configured with IO objects.
- Support for USB joystick.
src/tools/pkg/cygwin/pwrrt/copyright
0 → 100644
View file @
4a587916
Proview
Copyright: SSAB Oxelsund AB <ssabox.com>
2003-11-21
The home page of Proview is at:
http://www.proview.se
src/tools/pkg/cygwin/pwrrt/postinst
0 → 100755
View file @
4a587916
#!/usr/local/bin/bash
set
-e
if
[
"
$pwrrt_xtrace
"
!=
""
]
;
then
set
-o
xtrace
fi
if
[
!
-e
/usr/local/bin/bash
]
;
then
echo
"** Error, bash not installed"
exit
fi
if
[
!
-e
/bin/bash
]
;
then
ln
-s
/usr/local/bin/bash /bin/bash
fi
# Automatically added by dh_installdocs
if
[
"
$1
"
=
"configure"
]
;
then
if
[
-d
/usr/doc
-a
!
-e
/usr/doc/pwrtest
-a
-d
/usr/share/doc/pwrtest
]
;
then
ln
-sf
../share/doc/pwrtest /usr/doc/pwrtest
fi
fi
# End automatically added section
proot
=
"/pwrp"
aroot
=
"/usr/pwrp/adm"
# Create users...
new_user
=
0
if
getent group pwrp
>
/dev/null
;
then
echo
"-- group pwrp already exist"
else
if
groupadd pwrp
;
then
echo
"-- group pwrp added"
fi
fi
if
getent group b55
>
/dev/null
;
then
echo
"-- group b55 already exist"
else
if
groupadd b55
;
then
echo
"-- group b55 added"
fi
fi
if
getent group b66
>
/dev/null
;
then
echo
"-- group b66 already exist"
else
if
groupadd b66
;
then
echo
"-- group b66 added"
fi
fi
if
getent group skiftel
>
/dev/null
;
then
echo
"-- group skiftel already exist"
else
if
groupadd skiftel
;
then
echo
"-- group skiftel added"
fi
fi
if
getent passwd pwrp
>
/dev/null
;
then
echo
"-- user pwrp already exist"
else
new_user
=
1
if
useradd
-m
-s
/bin/bash
-p
aaupl/kQs1p3U
-g
pwrp
-G
b55,b66,skiftel
-d
/home/pwrp pwrp
;
then
echo
"-- user pwrp added"
fi
if
[
!
-e
/home/pwrp
]
;
then
mkdir
/home/pwrp
cp
/usr/pwrrt/cnf/user/.bashrc /home/pwrp
cp
/usr/pwrrt/cnf/user/.bash_profile /home/pwrp
# cp /usr/pwrrt/cnf/user/.mwmrc /home/pwrp
cp
/usr/pwrrt/cnf/user/.rtt_start /home/pwrp
chmod
a+x /home/pwrp/.rtt_start
cp
/usr/pwrrt/cnf/user/.xtt_start /home/pwrp
chmod
a+x /home/pwrp/.xtt_start
# cp /usr/pwrrt/cnf/user/.xsession /home/pwrp
chown
-R
pwrp /home/pwrp
chgrp
-R
pwrp /home/pwrp
fi
# Add to group dialout
if
getent group dialout
>
/dev/null
;
then
usermod
-a
-G
dialout pwrp
fi
fi
if
getent passwd skiftel
>
/dev/null
;
then
echo
"-- user skiftel already exist"
else
new_user
=
1
if
useradd
-m
-s
/bin/bash
-p
aa6NzxS/aBgP6
-g
skiftel
-G
pwrp
-d
/home/skiftel skiftel
;
then
echo
"-- user skiftel added"
fi
if
[
!
-e
/home/skiftel
]
;
then
mkdir
/home/skiftel
cp
/usr/pwrrt/cnf/user/.bashrc /home/skiftel
cp
/usr/pwrrt/cnf/user/.bash_profile /home/skiftel
# cp /usr/pwrrt/cnf/user/.mwmrc /home/skiftel
cp
/usr/pwrrt/cnf/user/.rtt_start /home/skiftel
chmod
a+x /home/skiftel/.rtt_start
cp
/usr/pwrrt/cnf/user/.xtt_start /home/skiftel
chmod
a+x /home/skiftel/.xtt_start
# cp /usr/pwrrt/cnf/user/.xsession /home/skiftel
chown
-R
pwrp /home/skiftel
chgrp
-R
pwrp /home/skiftel
fi
fi
if
getent passwd b55
>
/dev/null
;
then
new_user
=
1
# Check if group audio exist
if
getent group audio
>
/dev/null
;
then
groups
=
"pwrp,audio"
else
groups
=
"pwrp"
fi
if
useradd
-m
-s
/bin/bash
-p
aaQPClsglxJP6
-g
b55
-G
$groups
-d
/home/b55 b55
;
then
echo
"-- user b55 added"
fi
if
[
!
-e
/home/b55
]
;
then
mkdir
/home/b55
cp
/usr/pwrrt/cnf/op/.bashrc /home/b55
cp
/usr/pwrrt/cnf/op/.bash_profile /home/b55
# cp /usr/pwrrt/cnf/op/.mwmrc /home/b55
cp
/usr/pwrrt/cnf/op/.rtt_start /home/b55
chmod
a+x /home/b55/.rtt_start
cp
/usr/pwrrt/cnf/op/.xtt_start /home/b55
chmod
a+x /home/b55/.xtt_start
# cp /usr/pwrrt/cnf/op/.xsession /home/b55
chown
-R
b55 /home/b55
chgrp
-R
pwrp /home/b55
chmod
g+rwx /home/b55
fi
fi
if
getent passwd b66
>
/dev/null
;
then
new_user
=
1
# Check if group audio exist
if
getent group audio
>
/dev/null
;
then
groups
=
"pwrp,audio"
else
groups
=
"pwrp"
fi
if
useradd
-m
-s
/bin/bash
-p
aae.nHgHbfUpw
-g
b66
-G
$groups
-d
/home/b66 b66
;
then
echo
"-- user b66 added"
fi
if
[
!
-e
/home/b66
]
;
then
mkdir
/home/b66
cp
/usr/pwrrt/cnf/op/.bashrc /home/b66
cp
/usr/pwrrt/cnf/op/.bash_profile /home/b66
# cp /usr/pwrrt/cnf/op/.mwmrc /home/b66
cp
/usr/pwrrt/cnf/op/.rtt_start /home/b66
chmod
a+x /home/b66/.rtt_start
cp
/usr/pwrrt/cnf/op/.xtt_start /home/b66
chmod
a+x /home/b66/.xtt_start
# cp /usr/pwrrt/cnf/op/.xsession /home/b66
chown
-R
b66 /home/b66
chgrp
-R
pwrp /home/b66
chmod
g+rwx /home/b66
fi
fi
chown
-R
pwrp /usr/pwrrt
chgrp
-R
pwrp /usr/pwrrt
chmod
u+s /usr/pwrrt/exe/rt_ini
chmod
u+s /usr/pwrrt/exe/rt_rtt
#chmod u+s /usr/pwrrt/exe/rt_xtt
chmod
u+s /usr/pwrrt/exe/rt_bck
chmod
u+s /usr/pwrrt/exe/rt_gdhget
#chown root /usr/pwrrt/exe/rs_remote_alcm
#chmod u+s /usr/pwrrt/exe/rs_remote_alcm
if
getent group dialout
>
/dev/null
;
then
chgrp
dialout /usr/pwrrt/exe/rs_remote_serial
chmod
ug+s /usr/pwrrt/exe/rs_remote_serial
chgrp
dialout /usr/pwrrt/exe/rs_remote_3964r
chmod
ug+s /usr/pwrrt/exe/rs_remote_3964r
fi
#chown root /usr/pwrrt/exe/rt_prio
#chmod u+s /usr/pwrrt/exe/rt_prio
chown
root /usr/pwrrt/exe/rt_mozilla
chmod
u+s /usr/pwrrt/exe/rt_mozilla
# Copy configuration files
new_cnf
=
0
if
[
!
-e
/etc/proview.cnf
]
;
then
cp
/usr/pwrrt/cnf/proview.cnf /etc
new_cnf
=
1
fi
# Add pwrp_profile to profile
if
!
grep
-q
"/etc/pwrp_profile[[:>:]]"
/etc/profile
;
then
cat
>>
/etc/profile
<<-
EOF
if [ -e /etc/pwrp_profile ]; then
. /etc/pwrp_profile
fi
EOF
fi
# Create startup link
if
!
grep
-q
"/etc/pwrrt/pwr start"
/etc/rc.local
;
then
cat
>>
/etc/rc.local
<<-
EOF
/etc/pwrrt/pwr start
EOF
fi
# Create project
new_project
=
0
if
[
!
-e
$proot
]
;
then
new_project
=
1
mkdir
$proot
mkdir
$proot
/common
mkdir
$proot
/common/inc
mkdir
$proot
/common/load
mkdir
$proot
/common/log
mkdir
$proot
/common/loghist
mkdir
$proot
/common/db
mkdir
$proot
/common/web
mkdir
$proot
/x86_64_openbsd
mkdir
$proot
/x86_64_openbsd/exe
mkdir
$proot
/x86_64_openbsd/lib
mkdir
$proot
/x86_64_openbsd/obj
mkdir
$proot
/x86_64_openbsd/lis
chown
-R
pwrp
$proot
chgrp
-R
pwrp
$proot
fi
if
[
!
-e
$aroot
/db
]
;
then
mkdir
-p
$aroot
/db
chown
-R
pwrp
$aroot
fi
# Copy jar-files to web directory
if
[
-e
/etc/proview.cnf
]
;
then
set
+e
web_dir
=
`
eval cat
/etc/proview.cnf |
grep
"[[:<:]]webDirectory[[:>:]]"
|
awk
'{print $2}'
`
set
-e
if
[
-e
"
$web_dir
"
]
;
then
cp
/usr/pwrrt/lib/pwr_rt_client.jar
$web_dir
chown
pwrp
$web_dir
/pwr_rt_client.jar
cp
/usr/pwrrt/lib/pwr_jop.jar
$web_dir
chown
pwrp
$web_dir
/pwr_jop.jar
cp
/usr/pwrrt/lib/pwr_jopc.jar
$web_dir
chown
pwrp
$web_dir
/pwr_jopc.jar
fi
fi
#
# Add proview web directories to Apache
#
if
[
-e
/etc/apache2/apache2.conf
]
;
then
if
!
egrep
-q
"Alias[ ]+/pwrp_web/"
/etc/apache2/apache2.conf
;
then
cat
>>
/etc/apache2/apache2.conf
<<-
EOF
#
# Proview alias pwrp_web, added by Proview installation
#
Alias /pwrp_web/ /pwrp/common/web/
<Directory /pwrp/common/web>
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
EOF
fi
if
!
egrep
-q
"Alias[ ]+/pwrp_log/"
/etc/apache2/apache2.conf
;
then
cat
>>
/etc/apache2/apache2.conf
<<-
EOF
#
# Proview alias pwrp_log, added by Proview installation
#
Alias /pwrp_log/ /pwrp/common/log/
<Directory /pwrp/common/log>
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
EOF
fi
if
!
egrep
-q
"Alias[ ]+/pwr_doc/"
/etc/apache2/apache2.conf
;
then
cat
>>
/etc/apache2/apache2.conf
<<-
EOF
#
# Proview alias pwr_doc, added by Proview installation
#
Alias /pwr_doc/ /usr/pwrrt/doc/
<Directory /usr/pwrrt/doc>
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
EOF
fi
fi
#
# Set owner on preinstalled I/O systems
#
if
[
-e
/lib/udev/devices/qbus
]
;
then
chown
pwrp:pwrp /lib/udev/devices/qbus
fi
if
[
-e
/lib/udev/devices/pbus1
]
;
then
chown
pwrp:pwrp /lib/udev/devices/pbus1
fi
if
[
-e
/lib/udev/devices/pbus2
]
;
then
chown
pwrp:pwrp /lib/udev/devices/pbus2
fi
changes
=
0
if
[
$new_user
-eq
1
]
;
then
changes
=
1
elif
[
$new_cnf
-eq
1
]
;
then
changes
=
1
elif
[
$new_project
-eq
1
]
;
then
changes
=
1
fi
if
[
$changes
-ne
0
]
;
then
echo
""
echo
""
echo
"***********************************************************"
echo
" Don't forget to do this :"
echo
""
fi
if
[
$new_cnf
-eq
1
]
;
then
echo
"-- Enter QcomBusId in /etc/proview.cnf"
fi
#if [ $new_user -eq 1 ]; then
# echo "-- Enter OpPlace object as argument to rt_xtt in /home/b55/.xtt_start"
#fi
if
[
$new_project
-eq
1
]
;
then
nodename
=
`
eval uname
-n
`
echo
"-- Distribute project to
$nodename
"
fi
if
[
$changes
-ne
0
]
;
then
echo
""
echo
"***********************************************************"
echo
""
fi
src/tools/pkg/cygwin/pwrrt/prerm
0 → 100755
View file @
4a587916
#!/bin/sh
set
-e
# Automatically added by dh_installdocs
if
[
\(
"
$1
"
=
"upgrade"
-o
"
$1
"
=
"remove"
\)
-a
-L
/usr/doc/pwrtest
]
;
then
rm
-f
/usr/doc/pwrtest
fi
# End automatically added section
proot
=
"/pwrp"
aroot
=
"/usr/pwrp/adm"
echo
""
echo
-n
"Do you wan't to remove project and users (y/n) [n] "
read
remove_all
if
[
"
$remove_all
"
=
"y"
]
;
then
# Check that any user that is to be remoted isn't logged in
set
+e
user_found
=
0
currentusers
=
`
eval users
`
userstr
=
""
checkuser
=
`
eval echo
$currentusers
|
grep
"[[:<:]]b55[[:>:]]"
`
if
[
"
$checkuser
"
!=
""
]
;
then
user_found
=
1
userstr
=
$userstr
" b55"
fi
checkuser
=
`
eval echo
$currentusers
|
grep
"[[:<:]]b66[[:>:]]"
`
if
[
"
$checkuser
"
!=
""
]
;
then
user_found
=
1
userstr
=
$userstr
" b66"
fi
checkuser
=
`
eval echo
$currentusers
|
grep
"[[:<:]]pwrp[[:>:]]"
`
if
[
"
$checkuser
"
!=
""
]
;
then
user_found
=
1
userstr
=
$userstr
" pwrp"
fi
checkuser
=
`
eval echo
$currentusers
|
grep
"[[:<:]]skiftel[[:>:]]"
`
if
[
"
$checkuser
"
!=
""
]
;
then
user_found
=
1
userstr
=
$userstr
" skiftel"
fi
if
[
$user_found
-eq
1
]
;
then
echo
"-- Current users:
$currentusers
"
echo
"** Remove user will fail. Logout user
$userstr
first."
exit
-1
;
fi
set
-e
echo
"-- Remove user b55"
if
grep
-q
"[[:<:]]b55:"
/etc/passwd
;
then
userdel b55
fi
if
[
-e
/home/b55
]
;
then
rm
-r
/home/b55
fi
echo
"-- Remove user b66"
if
grep
-q
"[[:<:]]b66:"
/etc/passwd
;
then
userdel b66
fi
if
[
-e
/home/b66
]
;
then
rm
-r
/home/b66
fi
echo
"-- Remove user pwrp"
if
grep
-q
"[[:<:]]pwrp:"
/etc/passwd
;
then
userdel pwrp
fi
if
[
-e
/home/pwrp
]
;
then
rm
-r
/home/pwrp
fi
echo
"-- Remove user skiftel"
if
grep
-q
"[[:<:]]skiftel:"
/etc/passwd
;
then
userdel skiftel
fi
if
[
-e
/home/skiftel
]
;
then
rm
-r
/home/skiftel
fi
if
grep
-q
"[[:<:]]b55:"
/etc/group
;
then
groupdel b55
fi
if
grep
-q
"[[:<:]]b66:"
/etc/group
;
then
groupdel b66
fi
if
grep
-q
"[[:<:]]pwrp:"
/etc/group
;
then
groupdel pwrp
fi
if
grep
-q
"[[:<:]]skiftel:"
/etc/group
;
then
groupdel skiftel
fi
echo
"-- Remove project
$proot
"
if
[
-e
$proot
]
;
then
rm
-r
$proot
fi
if
[
-e
$aroot
]
;
then
rm
-r
$aroot
fi
fi
# Remove jar-files on web directory
if
[
-e
/etc/proview.cnf
]
;
then
web_dir
=
`
eval cat
/etc/proview.cnf |
grep
"[[:<:]]webDirectory[[:>:]]"
|
awk
'{print $2}'
`
if
[
-e
$web_dir
/pwr_rt_client.jar
]
;
then
rm
$web_dir
/pwr_rt_client.jar
fi
if
[
-e
$web_dir
/pwr_jop.jar
]
;
then
rm
$web_dir
/pwr_jop.jar
fi
fi
dname
=
`
eval dirname
$0
`
chmod
a+x
$dname
/rmfiles.sh
$dname
/rmfiles.sh
src/tools/pkg/cygwin/pwrrt/proview.cnf
0 → 100644
View file @
4a587916
#
# Configuration file for Proview
#
# Default QCOM Bus Id
#
qcomBusId 517
#
# Web directory
#
webDirectory /pwrp/common/web
#
# Default privileges for SevXtt: Read, Admin or None
#
sevXttDefaultPriv Read
src/tools/pkg/cygwin/pwrrt/pwr
0 → 100755
View file @
4a587916
#!/bin/bash
#
# Startscript fr PWR
#
PATH
=
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
wrapper
=
"/tmp/rt_ini_wrapper"
killer
=
"/tmp/pwr_killer"
.
/etc/pwrp_profile
umask
002
create_wrapper
()
{
if
[
!
-e
$wrapper
]
;
then
echo
"#!/bin/bash"
>
$wrapper
echo
"source /etc/pwrp_profile"
>>
$wrapper
echo
"umask 002"
>>
$wrapper
echo
"
\$
pwr_exe/rt_ini
\$
* &"
>>
$wrapper
chmod
a+rx
$wrapper
if
[
!
-e
$wrapper
]
;
then
echo
"
$wrapper
not writable, check permissions"
exit
fi
fi
}
create_killer
()
{
echo
"#!/bin/bash"
>
$killer
echo
"source /etc/pwrp_profile"
>>
$killer
echo
"umask 002"
>>
$killer
echo
"
`
ps ax |
grep
"rt_"
|
awk
'{ print "kill -9 "$1}'
`
"
>>
$killer
echo
"
`
ps ax |
grep
"rs_"
|
awk
'{ print "kill -9 "$1}'
`
"
>>
$killer
echo
"
`
ps ax |
grep
"ra_"
|
awk
'{ print "kill -9 "$1}'
`
"
>>
$killer
echo
"
`
ps ax |
grep
"sev_"
|
awk
'{ print "kill -9 "$1}'
`
"
>>
$killer
echo
"
`
ps ax |
grep
"opc_"
|
awk
'{ print "kill -9 "$1}'
`
"
>>
$killer
echo
"eval
`
ipcs
-s
|grep ^0x|grep
"[
\t
]pwrp[
\t
]"
|awk
'{printf "ipcrm sem %s;", $2}'
`
"
>>
$killer
echo
"eval
`
ipcs
-q
|grep ^0x|grep
"[
\t
]pwrp[
\t
]"
|awk
'{printf "ipcrm msg %s;", $2}'
`
"
>>
$killer
echo
"eval
`
ipcs
-m
|grep ^0x|grep
"[
\t
]pwrp[
\t
]"
|awk
'{printf "ipcrm shm %s;", $2}'
`
"
>>
$killer
echo
"rm /tmp/pwr*
\$
PWR_BUS_ID"
>>
$killer
chmod
a+rx
$killer
if
[
!
-e
$killer
]
;
then
echo
"
$killer
not writable, check permissions"
exit
fi
}
pwr_start
()
{
create_wrapper
if
[
`
whoami
`
==
"pwrp"
]
;
then
$wrapper
else
sudo
-u
pwrp
$wrapper
fi
}
pwr_stop
()
{
create_wrapper
if
[
`
whoami
`
==
"pwrp"
]
;
then
$wrapper
-s
if
[
-e
$pwrp_exe
/pwrp_stop.sh
]
;
then
source
$pwrp_exe
/pwrp_stop.sh
fi
else
sudo
-u
pwrp
$wrapper
-s
if
[
-e
$pwrp_exe
/pwrp_stop.sh
]
;
then
sudo
-u
pwrp
source
$pwrp_exe
/pwrp_stop.sh
fi
fi
while
[
"
`
ps aux |
grep
-v
grep
|
grep
rt_
`
"
!=
""
]
;
do
sleep
1
;
done
}
pwr_reload
()
{
if
[
`
whoami
`
==
"pwrp"
]
;
then
$pwr_exe
/rt_ini_wrapper
-r
else
sudo
-u
pwrp
$pwr_exe
/rt_ini_wrapper
-r
fi
}
pwr_kill
()
{
create_killer
if
[
`
whoami
`
==
"pwrp"
]
;
then
$killer
else
sudo
-u
pwrp
$killer
fi
}
case
"
$1
"
in
start
)
echo
"Start Proview Runtime Environment."
pwr_start
echo
"Done."
;;
stop
)
echo
"Stop Proveiw Runtime Environment."
pwr_stop
echo
"Done."
;;
restart
)
echo
"Restart Proview Runtime Environment."
echo
"Closing down..."
pwr_stop
sleep
1
echo
"Starting..."
pwr_start
echo
"Done."
;;
reload
)
echo
"Reload Proview Runtime Environment"
pwr_reload
echo
"Done."
;;
kill
)
echo
"Remove all processes and resources for Proview Storage Environment"
pwr_kill
echo
"Done."
;;
reset
)
echo
"Remove all processes and resources for Proview Storage Environment"
pwr_kill
echo
"Done."
;;
*
)
echo
" pwrsev Start and stop Proview Storage Environment"
>
&2
echo
""
>
&2
echo
" Usage:"
>
&2
echo
" pwr start|stop|restart|reload|reset"
>
&2
echo
""
>
&2
echo
" start Start Runtime environment"
>
&2
echo
" stop Stop Runtime environment"
>
&2
echo
" restart First stop and then start Runtime environment"
>
&2
echo
" reload Soft restart of Runtime environment"
>
&2
echo
" reset Remove all processes and resources"
>
&2
echo
""
>
&2
exit
1
;;
esac
exit
0
src/tools/pkg/cygwin/pwrrt/pwr.1
0 → 100644
View file @
4a587916
.TH pwr "1" "April 2005" "Proview" "Proview Manual"
.SH NAME
pwr - start and stop Proview runtime environment
.SH SYNOPSIS
.B pwr
[start][stop][restart][reload][reset]
.SH DESCRIPTION
Start and stop command for Proview runtime environment.
.SH OPTIONS
.HP
\fBstart\fR
.IP
Start Proview runtime environment.
.HP
\fBstop\fR
.IP
Stop Proview runtime environment.
.HP
\fBrestart\fR
.IP
First stop and then start the Proview runtime environment.
.HP
\fBreload\fR
.IP
Soft restart of Proview runtime environment.
.HP
\fBreset\fR
.IP
Remove all processes and resources.
.SH FILES
/etc/pwrp_profile
The Proview system wide configuration file.
.SH ENVIRONMENT
.HP
PWR_BUS_ID
.IP
QCOM bus identity.
.SH AUTHOR
Written by UL.
.SH "SEE ALSO"
.BR rt_ini(1)
src/tools/pkg/cygwin/pwrrt/pwrp_profile
0 → 100644
View file @
4a587916
bus_id=""
if [ -e /etc/proview.cnf ]; then
bus_id=`eval cat /etc/proview.cnf | grep "[[:<:]]qcomBusId[[:>:]]" | awk '{print $2}'`
fi
if [ -e /etc/proview.cnf ]; then
web_dir=`eval cat /etc/proview.cnf | grep "[[:<:]]bwebDirectory[[:>:]]" | awk '{print $2}'`
fi
export PWR_BUS_ID=$bus_id
export pwrb_root=/usr/pwrrt
export pwrp_root=/pwrp
export pwr_exe=$pwrb_root/exe
export pwr_lib=$pwrb_root/lib
export pwr_obj=$pwrb_root/obj
export pwr_inc=$pwrb_root/inc
export pwr_load=$pwrb_root/load
export pwr_lis=$pwrb_root/lis
export pwr_doc=$pwrb_root/doc
export pwrp_exe=$pwrp_root/x86_64_openbsd/exe
export pwrp_lib=$pwrp_root/x86_64_openbsd/lib
export pwrp_obj=$pwrp_root/x86_64_openbsd/obj
export pwrp_lis=$pwrp_root/x86_64_openbsd/lis
export pwrp_inc=$pwrp_root/common/inc
export pwrp_load=$pwrp_root/common/load
export pwrp_log=$pwrp_root/common/log
export pwrp_db=$pwrp_root/common/db
if [ "$web_dir" = "" ]; then
export pwrp_web=$pwrp_root/common/web
else
export pwrp_web=$web_dir
fi
export pwra_db=/usr/pwrp/adm/db
jdk=`eval ls -t /usr/local | grep ^jdk`
if [ "$jdk" == "" ]; then
jdk=`eval ls -t /usr/local | grep ^jre`
fi
export jdk=/usr/local/$jdk
export jdk_home=$jdk/bin
PATH=$PATH:$pwr_exe:$pwrp_exe:$jdk_home
#Set display to remote computer
export DISPLAY=$REMOTEHOST:0.0
#symbols to define start/stop commands for PWR
alias pwr_stop='/etc/pwrrt/pwr stop'
alias pwr_stop.sh="/etc/pwrrt/pwr stop"
alias pwr_start="/etc/pwrrt/pwr start"
alias pwr="/etc/pwrrt/pwr"
alias boot="/usr/bin/sudo /sbin/reboot"
if [ -e $pwrp_exe/profile ]; then
source $pwrp_exe/profile
fi
src/tools/pkg/cygwin/pwrrt/rt_ini.1
0 → 100644
View file @
4a587916
.TH rt_ini "1" "April 2005" "Proview" "Proview Manual"
.SH NAME
rt_ini - start, restart or stop the Proview runtime environment
.SH SYNOPSIS
.B rt_ini
[\fIOPTION\fR]
.SH DESCRIPTION
Startup process for the Proview runtime environment.
.SH OPTIONS
.HP
\fB\-a\fR
.IP
Application file. The application file defines the application processes for
the node. The default name is $pwrp_load/ld_appl_'node'_'busid'.txt, where node is
the nodename and busid is the QCOM bus id, for example
$pwrp_load/ld_appl_vwxn1t_507.txt
.HP
\fB\-b\fR
.IP
Boot file. The default bootfile is $pwrp_load/ld_boot_'node'_'busid'.txt, where node
is the nodename and busid the QCOM bus id, for example
$pwrp_load/ld_appl_vwxn1t_0507.txt
.HP
\fB\-c\fR
.IP
Console file. The output of log messages to the console device can be redirected with
the -c option.
.HP
\fB\-d\fR
.IP
Load file directory. Default is $pwrp_load.
.HP
\fB\-e\fR
.IP
Ignore errors.
.HP
\fB\-f\fR
.IP
Ignore fatal errors.
.HP
\fB\-h\fR
.IP
Print help.
.HP
\fB\-i\fR
.IP
Interactive. Print error messages to terminal.
.HP
\fB\-n\fR
.IP
Node name.
.HP
\fB\-p\fR
.IP
Plc file. Default is $pwrp_exe/plc_'node'_'busid' where node id the node name and busid
the QCOM bus id.
.HP
\fB\-q\fR
.IP
QCOM bus id.
.HP
\fB\-r\fR
.IP
Soft restart.
.HP
\fB\-s\fR
.IP
Stop Proview.
.HP
\fB\-v\fR
.IP
Verbose.
.HP
\fB\-w\fR
.IP
Ignore warnings.
.HP
\fB\-A\fR
.IP
Alias file. Default is $pwrp_load/pwrp_alias.dat
.HP
\fB\-?\fR
.IP
Print help.
.SH FILES
/etc/pwrp_profile
The Proview system wide configuration file.
.SH "SEE ALSO"
.BR pwr(1)
src/tools/pkg/cygwin/pwrrt/rt_rtt.1
0 → 100644
View file @
4a587916
.TH rt_rtt "1" "April 2005" "Proview" "Proview Manual"
.SH NAME
rt_rtt - Proview Runtime Terminal Tool
.SH SYNOPSIS
.B rt_rtt
[user] [script] [configuration]
.SH DESCRIPTION
Examine and navigate in the realtime database from a VT100 terminal.
.SH OPTIONS
.HP
\fBuser\fR
.IP
The user of the session. OP for operator, SYS for system manager.
.HP
\fBscript\fR
.IP
A rtt script file.
.HP
\fBconfiguration\fR
.IP
A RttConfig object that configures the session.
.SH AUTHOR
Written by cs.
.SH "SEE ALSO"
.BR rt_xtt(1)
src/tools/pkg/cygwin/pwrrt/rt_xtt.1
0 → 100644
View file @
4a587916
.TH rt_xtt "1" "April 2005" "Proview" "Proview Manual"
.SH NAME
rt_xtt - Proview Operator Environment
.SH SYNOPSIS
.B rt_xtt
[\fIOPTION\fR] [opplace]
.SH DESCRIPTION
The Proview Operator Environment contains a set of utitlities to display information
about the process and the Proview system:
.RS
\- Operator window.
.RE
.RS
\- Process Graphics drawn in the Ge editor.
.RE
.RS
\- Trends and fastcurves.
.RE
.RS
\- Helptexts.
.RE
.RS
\- Navigator for the realtime database.
.RE
.RS
\- Alarms and events.
.RE
.SH OPTIONS
.HP
\fBopplace\fR
.IP
The name of the OpPlace object for the operator place.
.HP
\fB\-l\fR
.IP
Language.
.RS
en_us English
.RE
.RS
sv_se Swedish.
.RE
.RS
de_de German.
.RE
.RS
en_us is default.
.RE
.HP
\fB\-u\fR
.IP
Use opplace object with the same name as the current user.
.HP
\fB\-s\fR
.IP
Show a selection list of available OpPlace objects.
.HP
\fB\-a\fR
.IP
Connect to audio device.
.HP
\fB\-q\fR
.IP
Quiet. Hide license information.
.SH AUTHOR
Written by cs.
.SH "SEE ALSO"
.BR pwr(1),
.BR rt_ini(1)
src/tools/pkg/cygwin/src/os_templ/hw_templ/makefile
0 → 100644
View file @
4a587916
include
$(pwre_dir_symbols)
ifndef
variables_mk
-include
$(pwre_sroot)/tools/bld/src/$(os_name)/$(hw_name)/variables.mk
endif
ifndef
variables_mk
include
$(pwre_sroot)/tools/bld/src/$(os_name)/variables.mk
endif
ifndef
rules_mk
-include
$(pwre_sroot)/tools/bld/src/$(os_name)/$(hw_name)/rules.mk
endif
ifndef
rules_mk
include
$(pwre_sroot)/tools/bld/src/$(os_name)/rules.mk
endif
.SUFFIXES
:
.PHONY
:
all init copy lib exe clean realclean
\
$(clean_ge)
all
:
init copy lib exe
init
:
dirs
copy
:
lib
:
#exe : $(bld_dir)/control_pwrrt $(bld_dir)/control_pwr $(bld_dir)/control_pwrdemo $(bld_dir)/control_pwrsev
exe
:
$(bld_dir)/control_pwr $(bld_dir)/control_pwrdemo
clean
:
realclean
:
dirs
:
$(bld_dir)$(dir_ext)
$(bld_dir)$(dir_ext)
:
@
$(mkdir)
-p
$(mkdirflags)
$(
basename
$@
)
$(bld_dir)/control_pwrrt
:
../../../pwrrt/control
@
echo
"build
$(target)
"
@
../../../pwrrt/build.sh
@
cp
$(source)
$(target)
$(bld_dir)/control_pwr
:
../../../pwr/control
@
echo
"build
$(target)
"
@
../../../pwr/build.sh
@
cp
$(source)
$(target)
$(bld_dir)/control_pwrdemo
:
../../../pwrdemo/control
@
echo
"build
$(target)
"
@
../../../pwrdemo/build.sh
@
cp
$(source)
$(target)
$(bld_dir)/control_pwrsev
:
../../../pwrsev/control
@
echo
"build
$(target)
"
@
../../../pwrsev/build.sh
@
cp
$(source)
$(target)
src/tools/pkg/cygwin/src/pwr
0 → 100644
View file @
4a587916
#!/bin/bash
#
# Startscript fr PWR av Ulf Ljungdahl
#
#test -x /sbin/ipchains || exit 0
#test -x /sbin/ipchains-restore || exit 0
#test -x /sbin/ipchains-save || exit 0
PATH
=
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
.
/etc/pwrp_profile
save
()
{
echo
-n
"Saving IP chains: "
TEMPFILE
=
"
`
tempfile
`
"
echo
"
${
SAVEFILEHEADER
}
"
>
"
${
TEMPFILE
}
"
&&
/sbin/ipchains-save
>>
"
${
TEMPFILE
}
"
2>/dev/null
cat
"
${
TEMPFILE
}
"
>
/etc/ipchains.save
rm
"
${
TEMPFILE
}
"
}
pwr_start
()
{
$pwr_exe
/rt_ini &
sleep
5
/usr/sbin/setrtprio
`
ps ax |
grep
"plc"
|
grep
-v
"grep"
|
awk
'{ print $1}'
`
}
pwr_stop
()
{
kill
-9
`
ps ax |
grep
"rt_neth_acp"
|
awk
'{ print $1}'
`
kill
-9
`
ps ax |
grep
"rt_neth"
|
awk
'{ print $1}'
`
kill
-9
`
ps ax |
grep
"rt_qmon"
|
awk
'{ print $1}'
`
kill
-9
`
ps ax |
grep
"rt_emon"
|
awk
'{ print $1}'
`
kill
-9
`
ps ax |
grep
"rt_tmon"
|
awk
'{ print $1}'
`
kill
-9
`
ps ax |
grep
"rt_
\|
/pwr/exe/rs"
|
awk
'{ print $1}'
`
kill
-9
`
ps ax |
grep
"
\[
rt_"
|
awk
'{ print $1}'
`
kill
-9
`
ps ax |
grep
"plc_"
|
awk
'{ print $1}'
`
kill
-9
`
ps ax |
grep
"jpwr.rt"
|
awk
'{ print $1}'
`
kill
-9
`
ps ax |
grep
"rs_nmps"
|
awk
'{ print $1}'
`
kill
-9
`
ps ax |
grep
"rs_remote"
|
awk
'{ print $1}'
`
if
[
-u
$pwr_exe
/rt_ini
]
;
then
user
=
`
ls
-al
$pwr_exe
/rt_ini |
awk
'{ print $3}'
`
else
user
=
$USER
fi
echo
"User
$user
"
eval
`
ipcs
-s
|grep ^0x|grep
"[
\t
]
$user
[
\t
]"
|awk
'{printf "ipcrm sem %s;", $2
}'
`
# remove message queues
eval
`
ipcs
-q
|grep ^0x|grep
"[
\t
]
$user
[
\t
]"
|awk
'{printf "ipcrm msg %s;", $2
}'
`
# remove shared memory
eval
`
ipcs
-m
|grep ^0x|grep
"[
\t
]
$user
[
\t
]"
|awk
'{printf "ipcrm shm %s;", $2
}'
`
if
[
-e
$pwrp_exe
/pwrp_stop.sh
]
;
then
source
$pwrp_exe
/pwrp_stop.sh
fi
rm
/tmp/pwr
*
$PWR_BUS_ID
#rm -f /tmp/pwr*
#id=`ipcs -s | grep $user | awk '{print $2}'`
#id1=`echo $id | awk '{print $1}'`
#id2=`echo $id | awk '{print $2}'`
#id3=`echo $id | awk '{print $3}'`
#ipcrm sem $id1
#ipcrm sem $id2
#ipcrm sem $id3
#id=`ipcs -q | grep $user | awk '{print $2}'`
#id1=`echo $id | awk '{print $1}'`
#id2=`echo $id | awk '{print $2}'`
#id3=`echo $id | awk '{print $3}'`
#ipcrm msg $id1
#ipcrm msg $id2
#ipcrm msg $id3
}
case
"
$1
"
in
start
)
echo
"Startar PWR..."
#if [ 'test -x ps aux | grep plc | grep -v grep' ]
# then
# echo "PWR kr, stoppar det frst.."
# pwr_stop
# fi
pwr_start
echo
"Klar."
;;
stop
)
echo
"Stoppar PWR..."
pwr_stop
# if [ "${SAVEONCE}" != "yes" ]
# then
# save
# echo -n "ipchains-save"
# else
# echo -n "Clearing IP chains:"
# fi
echo
"Klar"
;;
restart
)
echo
"Startar om PWR."
echo
"Stoppar det frst."
pwr_stop
sleep
1
echo
"Startar igen."
pwr_start
echo
"Klar."
;;
*
)
echo
"Usage:{start|stop|restart}"
>
&2
#echo "Ingen parameter angiven, startar PWR"
#$0 start
exit
1
;;
esac
exit
0
src/tools/pkg/cygwin/user/.bashrc
0 → 100644
View file @
4a587916
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files for examples
source
/etc/pwrp_profile
# If running interactively, then:
if
[
"
$PS1
"
]
;
then
# enable color support of ls and also add handy aliases
eval
`
dircolors
-b
`
#alias ls='ls --color=auto'
#alias ll='ls -l'
#alias la='ls -A'
#alias l='ls -CF'
#alias dir='ls --color=auto --format=vertical'
#alias vdir='ls --color=auto --format=long'
# set a fancy prompt
PS1
=
'\u@\h:\w\$ '
# If this is an xterm set the title to user@host:dir
#case $TERM in
#xterm*)
# PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"'
# ;;
#*)
# ;;
#esac
fi
src/tools/pkg/cygwin/user/Proview.lnk
0 → 100755
View file @
4a587916
File added
src/tools/pkg/cygwin/user/ProviewDemo.lnk
0 → 100755
View file @
4a587916
File added
src/tools/pkg/cygwin/user/proview_icon.ico
0 → 100755
View file @
4a587916
9.44 KB
src/tools/pkg/cygwin/user/pwrdemostart
0 → 100755
View file @
4a587916
#!/bin/bash
export
PATH
=
/usr/local/bin:/usr/bin
export
pwra_db
=
/data0/pwr/adm/db
source
$pwra_db
/pwr_setup.sh
pwrp
set
base X4.8.6
export
PWR_BUS_ID
=
999
export
DISPLAY
=
127.0.0.1:0
pwrp
set
project pwrdemo48
pwr_rtmon
src/tools/pkg/cygwin/user/pwrstart
0 → 100755
View file @
4a587916
#!/bin/bash
export
PATH
=
/usr/local/bin:/usr/bin
export
pwra_db
=
/data0/pwr/adm/db
source
$pwra_db
/pwr_setup.sh
pwrp
set
base X4.8.6
export
PWR_BUS_ID
=
999
export
DISPLAY
=
127.0.0.1:0
wb
-p
src/tools/pwre/src/os_cygwin/pwre_configure.sh
View file @
4a587916
...
@@ -15,6 +15,8 @@ Arguments
...
@@ -15,6 +15,8 @@ Arguments
--reset-version Reset previous version
--reset-version Reset previous version
--updatedir Update makefile directories
EOF
EOF
}
}
...
...
wb/exp/com/src/wb_wiz_directoryvolume.pwr_com
View file @
4a587916
...
@@ -581,7 +581,7 @@ page_4:
...
@@ -581,7 +581,7 @@ page_4:
SetAttribute( attr, 2048);
SetAttribute( attr, 2048);
endif
endif
if ( os == "Cygwin")
if ( os == "Cygwin")
SetAttribute( attr, 409
8
);
SetAttribute( attr, 409
6
);
endif
endif
attr = name + ".Address";
attr = name + ".Address";
...
...
wb/lib/wb/src/wb_db.h
View file @
4a587916
...
@@ -68,6 +68,14 @@ class wb_db_txn;
...
@@ -68,6 +68,14 @@ class wb_db_txn;
class
wb_db_ohead
;
class
wb_db_ohead
;
class
wb_destination
;
class
wb_destination
;
#if defined OS_CYGWIN
#define wb_db_txn DbTxn
#else
class
wb_db_txn
:
public
DbTxn
{
};
#endif
class
wb_db
:
public
wb_import
class
wb_db
:
public
wb_import
{
{
public:
public:
...
@@ -419,9 +427,4 @@ public:
...
@@ -419,9 +427,4 @@ public:
void
iter
(
wb_import
&
i
);
void
iter
(
wb_import
&
i
);
};
};
class
wb_db_txn
:
public
DbTxn
{
};
#endif
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment