Commit 8dfdfe27 authored by Holger Witsch's avatar Holger Witsch

adapt to docker use

parent ab0b1341
......@@ -2,15 +2,15 @@ static char RcsId[] = "@(#) $Header: /users/chaize/newsvn/cvsroot/Communication/
//+*********************************************************************
//
// File: CacheThread.cpp
// File: CacheThread.cpp
//
// Project: Device Servers in C++
// Project: Device Servers in C++
//
// Description: Code for implementing the Modbus data cache thread
// Description: Code for implementing the Modbus data cache thread
//
// Author(s); Emmanuel Taurel
// Author(s); Emmanuel Taurel
//
// Original: March 2008
// Original: March 2008
//
// $Log: not supported by cvs2svn $
// Revision 1.1 2009/02/25 13:58:40 buteau
......@@ -38,7 +38,7 @@ static char RcsId[] = "@(#) $Header: /users/chaize/newsvn/cvsroot/Communication/
//
//
//
// Copyright (c) 2001 by European Synchrotron Radiation Facility,
// Copyright (c) 2001 by European Synchrotron Radiation Facility,
// Grenoble, France
//
//
......@@ -46,13 +46,13 @@ static char RcsId[] = "@(#) $Header: /users/chaize/newsvn/cvsroot/Communication/
//-*********************************************************************
#include <tango.h>
#include <tango/tango.h>
#include <CacheThread.h>
#include <Modbus.h>
#ifdef _TG_WINDOWS_
#include <sys/types.h>
#include <sys/timeb.h>
#include <sys/types.h>
#include <sys/timeb.h>
#endif
namespace Modbus_ns
......@@ -61,146 +61,146 @@ namespace Modbus_ns
//+======================================================================
// Method: CacheThread::run_undetached()
//
// Description: create the instance of the thread used to fill up the
// cahce
// Description: create the instance of the thread used to fill up the
// cahce
//
// Arg(s) In: - cdb : list of data to be cached
// - c_mut : mutex used to protect the thread command area
// - cmd : Pointer to the command area
// - s_time : Thread loop sleeping time
// - d_name : Modbus device name
// - c_mut : mutex used to protect the thread command area
// - cmd : Pointer to the command area
// - s_time : Thread loop sleeping time
// - d_name : Modbus device name
//
//-=====================================================================
CacheThread::CacheThread(vector<CacheDataBlock> &cdb,omni_mutex &c_mut,ThreadCmd *cmd,long s_time,Modbus *d):
data_blocks(cdb),cmd_mutex(c_mut),th_cmd(cmd),the_dev(d)
{
sleeping_time_s = s_time / 1000;
sleeping_time_ns = (s_time % 1000) * 1000000;
sleeping_time_s = s_time / 1000;
sleeping_time_ns = (s_time % 1000) * 1000000;
}
//+======================================================================
// Method: CacheThread::run_undetached()
//
// Description: create a ModbusCore object
// Description: create a ModbusCore object
//
// Arg(s) In:
// Arg(s) In:
//
// Arg(s) Out:
// Arg(s) Out:
//-=====================================================================
void *CacheThread::run_undetached(void *ptr)
{
bool exit = false;
unsigned long nb_block = data_blocks.size();
struct timeval when;
bool exit = false;
unsigned long nb_block = data_blocks.size();
struct timeval when;
//
// Thread loop
//
try
{
while (exit == false)
{
//cout << "In cache Thread loop" << endl;
try
{
while (exit == false)
{
//cout << "In cache Thread loop" << endl;
//
// Read thread command
//
ThreadCmd the_cmd;
{
omni_mutex_lock sync(cmd_mutex);
the_cmd = *th_cmd;
}
if (the_cmd == SUICIDE)
{
exit = true;
continue;
}
ThreadCmd the_cmd;
{
omni_mutex_lock sync(cmd_mutex);
the_cmd = *th_cmd;
}
for (unsigned long loop = 0;loop < nb_block;loop++)
{
// cout << "Cmd = " << data_blocks[loop].cmd_name << endl;
// cout << "Adr = " << data_blocks[loop].in_args[0] << endl;
// cout << "nb_data = " << data_blocks[loop].in_args[1] << endl;
if (the_cmd == SUICIDE)
{
exit = true;
continue;
}
for (unsigned long loop = 0;loop < nb_block;loop++)
{
// cout << "Cmd = " << data_blocks[loop].cmd_name << endl;
// cout << "Adr = " << data_blocks[loop].in_args[0] << endl;
// cout << "nb_data = " << data_blocks[loop].in_args[1] << endl;
#ifdef _TG_WINDOWS_
struct _timeb now_win;
_ftime(&now_win);
when.tv_sec = (unsigned long)now_win.time;
when.tv_usec = (long)now_win.millitm * 1000;
struct _timeb now_win;
_ftime(&now_win);
when.tv_sec = (unsigned long)now_win.time;
when.tv_usec = (long)now_win.millitm * 1000;
#else
gettimeofday(&when,NULL);
gettimeofday(&when,NULL);
#endif
//
// Read the data and copy them
// Do not use command_inout on a DeviceProxy, because this will take
// the device monitor and therefore blocks other commands during the
// reading.
try
{
if (data_blocks[loop].cmd_name == "readholdingregisters")
{
Tango::DevVarShortArray *dvsa = the_dev->read_holding_registers(&data_blocks[loop].in_args);
{
omni_mutex_lock sync(*(data_blocks[loop].data_block_mutex));
::memcpy((void *)data_blocks[loop].short_data_cache_ptr,(void *)dvsa->get_buffer(),(size_t)dvsa->length() * 2);
data_blocks[loop].err = false;
data_blocks[loop].nb_sec = when.tv_sec;
}
delete dvsa;
}
else if (data_blocks[loop].cmd_name == "readmultiplecoilsstatus")
{
Tango::DevVarShortArray *dvsa = the_dev->read_multiple_coils_status(&data_blocks[loop].in_args);
{
omni_mutex_lock sync(*(data_blocks[loop].data_block_mutex));
::memcpy((void *)data_blocks[loop].short_data_cache_ptr,(void *)dvsa->get_buffer(),(size_t)dvsa->length() * 2);
data_blocks[loop].err = false;
data_blocks[loop].nb_sec = when.tv_sec;
}
delete dvsa;
}
else
{
Tango::DevVarShortArray *dvsa = the_dev->read_input_registers(&data_blocks[loop].in_args);
{
omni_mutex_lock sync(*(data_blocks[loop].data_block_mutex));
::memcpy((void *)data_blocks[loop].short_data_cache_ptr,(void *)dvsa->get_buffer(),(size_t)dvsa->length() * 2);
data_blocks[loop].err = false;
data_blocks[loop].nb_sec = when.tv_sec;
}
delete dvsa;
}
}
catch (Tango::DevFailed &e)
{
Tango::Except::print_exception(e);
{
omni_mutex_lock sync(*(data_blocks[loop].data_block_mutex));
data_blocks[loop].err = true;
data_blocks[loop].errors = e.errors;
data_blocks[loop].nb_sec = when.tv_sec;
}
}
}
omni_thread::sleep(sleeping_time_s,sleeping_time_ns);
}
}
catch (omni_thread_fatal &otf)
{
cout << "omni_thread_fatal......." << endl;
}
return NULL;
try
{
if (data_blocks[loop].cmd_name == "readholdingregisters")
{
Tango::DevVarShortArray *dvsa = the_dev->read_holding_registers(&data_blocks[loop].in_args);
{
omni_mutex_lock sync(*(data_blocks[loop].data_block_mutex));
::memcpy((void *)data_blocks[loop].short_data_cache_ptr,(void *)dvsa->get_buffer(),(size_t)dvsa->length() * 2);
data_blocks[loop].err = false;
data_blocks[loop].nb_sec = when.tv_sec;
}
delete dvsa;
}
else if (data_blocks[loop].cmd_name == "readmultiplecoilsstatus")
{
Tango::DevVarShortArray *dvsa = the_dev->read_multiple_coils_status(&data_blocks[loop].in_args);
{
omni_mutex_lock sync(*(data_blocks[loop].data_block_mutex));
::memcpy((void *)data_blocks[loop].short_data_cache_ptr,(void *)dvsa->get_buffer(),(size_t)dvsa->length() * 2);
data_blocks[loop].err = false;
data_blocks[loop].nb_sec = when.tv_sec;
}
delete dvsa;
}
else
{
Tango::DevVarShortArray *dvsa = the_dev->read_input_registers(&data_blocks[loop].in_args);
{
omni_mutex_lock sync(*(data_blocks[loop].data_block_mutex));
::memcpy((void *)data_blocks[loop].short_data_cache_ptr,(void *)dvsa->get_buffer(),(size_t)dvsa->length() * 2);
data_blocks[loop].err = false;
data_blocks[loop].nb_sec = when.tv_sec;
}
delete dvsa;
}
}
catch (Tango::DevFailed &e)
{
Tango::Except::print_exception(e);
{
omni_mutex_lock sync(*(data_blocks[loop].data_block_mutex));
data_blocks[loop].err = true;
data_blocks[loop].errors = e.errors;
data_blocks[loop].nb_sec = when.tv_sec;
}
}
}
omni_thread::sleep(sleeping_time_s,sleeping_time_ns);
}
}
catch (omni_thread_fatal &otf)
{
cout << "omni_thread_fatal......." << endl;
}
return NULL;
}
} // End of namespace
......@@ -12,20 +12,20 @@ static const char *RcsId = "$Id: $";
// project : Modbus
//
// This file is part of Tango device class.
//
//
// Tango 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 3 of the License, or
// (at your option) any later version.
//
//
// Tango 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 Tango. If not, see <http://www.gnu.org/licenses/>.
//
//
// $Author: $
//
// $Revision: $
......@@ -38,25 +38,25 @@ static const char *RcsId = "$Id: $";
// (Program Obviously used to Generate tango Object)
//=============================================================================
#include <tango.h>
#include <tango/tango.h>
#ifndef NOSERIAL
#include <SerialClass.h>
#endif
#include <ModbusClass.h>
// Add class header files if needed
// Add class header files if needed
/**
* Create Modbus Class singleton and store it in DServer object.
* Create Modbus Class singleton and store it in DServer object.
*/
void Tango::DServer::class_factory()
{
// Add method class init if needed
// Add method class init if needed
#ifndef NOSERIAL
add_class(Serial_ns::SerialClass::init("Serial"));
add_class(Serial_ns::SerialClass::init("Serial"));
#endif
add_class(Modbus_ns::ModbusClass::init("Modbus"));
add_class(Modbus_ns::ModbusClass::init("Modbus"));
}
/*----- PROTECTED REGION END -----*/ // Modbus::ClassFactory.cpp
/*----- PROTECTED REGION END -----*/ // Modbus::ClassFactory.cpp
......@@ -12,20 +12,20 @@ static const char *RcsId = "$Id: $";
// project : Modbus
//
// This file is part of Tango device class.
//
//
// Tango 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 3 of the License, or
// (at your option) any later version.
//
//
// Tango 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 Tango. If not, see <http://www.gnu.org/licenses/>.
//
//
// $Author: $
//
// $Revision: $
......@@ -37,7 +37,7 @@ static const char *RcsId = "$Id: $";
// This file is generated by POGO
// (Program Obviously used to Generate tango Object)
//=============================================================================
#include <tango.h>
#include <tango/tango.h>
// Check if crash reporting is used.
#if defined(ENABLE_CRASH_REPORT)
......@@ -51,37 +51,37 @@ DECLARE_CRASH_HANDLER;
int main(int argc,char *argv[])
{
INSTALL_CRASH_HANDLER
try
{
// Initialise the device server
//----------------------------------------
Tango::Util *tg = Tango::Util::init(argc,argv);
INSTALL_CRASH_HANDLER
try
{
// Initialise the device server
//----------------------------------------
Tango::Util *tg = Tango::Util::init(argc,argv);
// Create the device server singleton
// which will create everything
//----------------------------------------
tg->server_init(false);
// Create the device server singleton
// which will create everything
//----------------------------------------
tg->server_init(false);
// Run the endless loop
//----------------------------------------
cout << "Ready to accept request" << endl;
tg->server_run();
}
catch (bad_alloc &)
{
cout << "Can't allocate memory to store device object !!!" << endl;
cout << "Exiting" << endl;
}
catch (CORBA::Exception &e)
{
Tango::Except::print_exception(e);
// Run the endless loop
//----------------------------------------
cout << "Ready to accept request" << endl;
tg->server_run();
}
catch (bad_alloc &)
{
cout << "Can't allocate memory to store device object !!!" << endl;
cout << "Exiting" << endl;
}
catch (CORBA::Exception &e)
{
Tango::Except::print_exception(e);
cout << "Received a CORBA_Exception" << endl;
cout << "Exiting" << endl;
}
Tango::Util::instance()->server_cleanup();
return(0);
cout << "Received a CORBA_Exception" << endl;
cout << "Exiting" << endl;
}
Tango::Util::instance()->server_cleanup();
return(0);
}
/*----- PROTECTED REGION END -----*/ // Modbus::main.cpp
/*----- PROTECTED REGION END -----*/ // Modbus::main.cpp
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment