Skip to content
Snippets Groups Projects
Commit ec225437 authored by Pieter Donker's avatar Pieter Donker
Browse files

cleanup

parent 209ec26a
Branches
Tags
No related merge requests found
...@@ -16,8 +16,10 @@ AM_CXXFLAGS = -std=c++11 -ggdb -pedantic -Wall -Woverloaded-virtual -Wwrite-stri ...@@ -16,8 +16,10 @@ AM_CXXFLAGS = -std=c++11 -ggdb -pedantic -Wall -Woverloaded-virtual -Wwrite-stri
# #
############################################################################ ############################################################################
sdptr_SOURCES = sdptr.cpp board.h board.cpp fpga.h fpga.cpp tr.h tr.cpp map.h map.cpp \ # sdptr_SOURCES = sdptr.cpp board.h board.cpp fpga.h fpga.cpp tr.h tr.cpp map.h map.cpp \
node.h node.cpp registers.h registers.cpp config_reader.h config_reader.cpp constants.h node.h node.cpp registers.h registers.cpp config_reader.h config_reader.cpp constants.h
sdptr_SOURCES = sdptr.cpp fpga.h fpga.cpp tr.h tr.cpp node.h node.cpp registers.h registers.cpp \
config_reader.h config_reader.cpp constants.h
sdptr_LDADD = periph/libperiph.a io/libio.a tools/libtools.a opcua/libopcua.a -lpthread -lm -lopen62541 sdptr_LDADD = periph/libperiph.a io/libio.a tools/libtools.a opcua/libopcua.a -lpthread -lm -lopen62541
......
...@@ -45,7 +45,7 @@ using namespace std; ...@@ -45,7 +45,7 @@ using namespace std;
extern int debug; extern int debug;
Fpga::Fpga(list<class Node*>& nodelist, const int32_t n_beamsets): FpgaMap::FpgaMap(list<class Node*>& nodelist, const int32_t n_beamsets):
nBeamsets(n_beamsets), nBeamsets(n_beamsets),
FPGA(nodelist) FPGA(nodelist)
{ {
...@@ -165,14 +165,14 @@ Fpga::Fpga(list<class Node*>& nodelist, const int32_t n_beamsets): ...@@ -165,14 +165,14 @@ Fpga::Fpga(list<class Node*>& nodelist, const int32_t n_beamsets):
pointMap->add_register("FPGA_subband_spectral_inversion_RW", "fpga/subband_spectral_inversion", nodes.size(), 1, "RW", REG_FORMAT_BOOLEAN); pointMap->add_register("FPGA_subband_spectral_inversion_RW", "fpga/subband_spectral_inversion", nodes.size(), 1, "RW", REG_FORMAT_BOOLEAN);
} }
Fpga::~Fpga() FpgaMap::~FpgaMap()
{ {
if (pointMap != NULL) { if (pointMap != NULL) {
delete pointMap; delete pointMap;
} }
} }
Node * Fpga::select_node(const int nr) Node * FpgaMap::select_node(const int nr)
{ {
for (auto node : FPGA) { for (auto node : FPGA) {
if (node->GetGlobalNr() == (uint)nr) { if (node->GetGlobalNr() == (uint)nr) {
...@@ -182,7 +182,7 @@ Node * Fpga::select_node(const int nr) ...@@ -182,7 +182,7 @@ Node * Fpga::select_node(const int nr)
throw runtime_error("select_node: not found"); throw runtime_error("select_node: not found");
} }
vector<int> Fpga::get_all_nodes(void) vector<int> FpgaMap::get_all_nodes(void)
{ {
vector<int> nodes; vector<int> nodes;
for (auto node : FPGA) { for (auto node : FPGA) {
...@@ -191,7 +191,7 @@ vector<int> Fpga::get_all_nodes(void) ...@@ -191,7 +191,7 @@ vector<int> Fpga::get_all_nodes(void)
return nodes; return nodes;
} }
vector<bool> Fpga::get_all_masked_nodes(void) vector<bool> FpgaMap::get_all_masked_nodes(void)
{ {
vector<bool> masked; vector<bool> masked;
for (auto node : FPGA) { for (auto node : FPGA) {
...@@ -200,7 +200,7 @@ vector<bool> Fpga::get_all_masked_nodes(void) ...@@ -200,7 +200,7 @@ vector<bool> Fpga::get_all_masked_nodes(void)
return masked; return masked;
} }
vector<bool> Fpga::get_all_offline_nodes(void) vector<bool> FpgaMap::get_all_offline_nodes(void)
{ {
vector<bool> online; vector<bool> online;
for (auto node : FPGA) { for (auto node : FPGA) {
...@@ -209,7 +209,7 @@ vector<bool> Fpga::get_all_offline_nodes(void) ...@@ -209,7 +209,7 @@ vector<bool> Fpga::get_all_offline_nodes(void)
return online; return online;
} }
void Fpga::set_all_masked_nodes(std::vector<bool> masked) void FpgaMap::set_all_masked_nodes(std::vector<bool> masked)
{ {
vector<int> nodes = get_all_nodes(); vector<int> nodes = get_all_nodes();
for (uint idx = 0; idx<nodes.size(); idx++) { for (uint idx = 0; idx<nodes.size(); idx++) {
...@@ -218,7 +218,7 @@ void Fpga::set_all_masked_nodes(std::vector<bool> masked) ...@@ -218,7 +218,7 @@ void Fpga::set_all_masked_nodes(std::vector<bool> masked)
} }
} }
vector<uint32_t> Fpga::get_all_pps_offset_cnt(void) vector<uint32_t> FpgaMap::get_all_pps_offset_cnt(void)
{ {
vector<uint32_t> pps_offset_cnt; vector<uint32_t> pps_offset_cnt;
for (auto node : FPGA) { for (auto node : FPGA) {
...@@ -228,17 +228,61 @@ vector<uint32_t> Fpga::get_all_pps_offset_cnt(void) ...@@ -228,17 +228,61 @@ vector<uint32_t> Fpga::get_all_pps_offset_cnt(void)
} }
uint Fpga::node_number(Node *node) uint FpgaMap::node_number(Node *node)
{ {
return (node->GetUniboardNr() * 4) + node->GetLocalNr(); return (node->GetUniboardNr() * 4) + node->GetLocalNr();
} }
CPointMap * Fpga::get_pointMap(void) CPointMap * FpgaMap::get_pointMap(void)
{ {
return pointMap; return pointMap;
} }
bool Fpga::point(TermOutput& termout, const char cmd, const string addr, bool FpgaMap::monitor(TermOutput& termout)
{
bool retval=false;
uint retcnt=0;
vector<int> nodes = get_all_nodes();
for (uint idx=0; idx<nodes.size(); idx++) {
auto node = select_node(nodes[idx]);
try {
if (node->monitor(termout)) {
retcnt++;
}
} catch (exception& e) {
cerr << e.what() << endl;
}
}
retval = (retcnt == nodes.size());
return retval;
}
bool FpgaMap::read(TermOutput& termout,
const string addr,
const int nvalues)
{
bool retval = false;
if (is_fpga(addr)) { // addressed with FPGA_...
//cout << "UniboardMap::read fpga application" << endl;
retval = point(termout, 'R', addr, NULL, nvalues);
}
return retval;
}
bool FpgaMap::write(TermOutput& termout,
const string addr,
const char *data,
const int nvalues)
{
bool retval = false;
if (is_fpga(addr)) { // addressed with FPGA_...
//cout << "UniboardMap::write fpga point [" << addr << "]" << endl;
retval = point(termout, 'W', addr, data, nvalues);
}
return retval;
}
bool FpgaMap::point(TermOutput& termout, const char cmd, const string addr,
const char *data, const int nvalues) const char *data, const int nvalues)
{ {
bool ret, retval = false; bool ret, retval = false;
...@@ -259,7 +303,7 @@ bool Fpga::point(TermOutput& termout, const char cmd, const string addr, ...@@ -259,7 +303,7 @@ bool Fpga::point(TermOutput& termout, const char cmd, const string addr,
pointMap->getWritePermission(addr); pointMap->getWritePermission(addr);
} }
} catch (exception& e) { } catch (exception& e) {
cerr << "Fpga::point: " << addr << " error: " << e.what() << endl; cerr << "FpgaMap::point: " << addr << " error: " << e.what() << endl;
return false; return false;
} }
...@@ -414,7 +458,7 @@ bool Fpga::point(TermOutput& termout, const char cmd, const string addr, ...@@ -414,7 +458,7 @@ bool Fpga::point(TermOutput& termout, const char cmd, const string addr,
return retval; return retval;
} }
bool Fpga::is_fpga(const string addr) bool FpgaMap::is_fpga(const string addr)
{ {
bool retval = false; bool retval = false;
stringstream strs(addr); stringstream strs(addr);
......
...@@ -26,8 +26,8 @@ ...@@ -26,8 +26,8 @@
* . class with fpga registers available for opc-ua server * . class with fpga registers available for opc-ua server
* *********************************************************************** */ * *********************************************************************** */
#ifndef FPGA__H #ifndef FPGA_MAP_H
#define FPGA__H 1 #define FPGA_MAP_H 1
#include <string> #include <string>
#include <vector> #include <vector>
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
#include "registers.h" #include "registers.h"
class Fpga class FpgaMap
{ {
private: private:
int32_t nBeamsets; int32_t nBeamsets;
...@@ -46,9 +46,14 @@ private: ...@@ -46,9 +46,14 @@ private:
CPointMap *pointMap; CPointMap *pointMap;
public: public:
Fpga(std::list<class Node*>& nodelist, const int32_t n_beamsets); FpgaMap(std::list<class Node*>& nodelist, const int32_t n_beamsets);
~Fpga(); ~FpgaMap();
bool monitor(TermOutput& termout);
bool write(TermOutput& termout, const std::string addr,
const char *data, const int nvalues);
bool read(TermOutput& termout, const std::string addr,
const int nvalues);
bool point(TermOutput& termout, const char cmd, const std::string addr, bool point(TermOutput& termout, const char cmd, const std::string addr,
const char *data, const int len); const char *data, const int len);
......
...@@ -123,7 +123,7 @@ static UA_StatusCode ua_read_DataSource(UA_Server *server, ...@@ -123,7 +123,7 @@ static UA_StatusCode ua_read_DataSource(UA_Server *server,
} }
else { else {
// UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND,"ua_read_DataSource: for fpga class"); // UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND,"ua_read_DataSource: for fpga class");
SD.unb->read(termout, regname, -1); SD.fpgas->read(termout, regname, -1);
} }
} catch (runtime_error& e) { } catch (runtime_error& e) {
cerr << "ua_read_DataSource error: " << e.what() << endl; cerr << "ua_read_DataSource error: " << e.what() << endl;
...@@ -237,7 +237,7 @@ static UA_StatusCode ua_write_DataSource(UA_Server *server, ...@@ -237,7 +237,7 @@ static UA_StatusCode ua_write_DataSource(UA_Server *server,
} }
else { else {
// UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND,"ua_write_DataSource: for fpga class"); // UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND,"ua_write_DataSource: for fpga class");
SD.unb->write(termout, regname, data_sdp, data->value.arrayLength); SD.fpgas->write(termout, regname, data_sdp, data->value.arrayLength);
} }
} catch (runtime_error& e) { } catch (runtime_error& e) {
cerr << "ua_write_DataSource error: " << e.what() << endl; cerr << "ua_write_DataSource error: " << e.what() << endl;
...@@ -955,7 +955,7 @@ static void ua_add_Variable(UA_Server *server, string regname, int format, unsig ...@@ -955,7 +955,7 @@ static void ua_add_Variable(UA_Server *server, string regname, int format, unsig
/* /*
* ua_server_init(), get all FPGA_ and TR_ poins and add them to the opc-ua server. * ua_server_init(), get all FPGA_ and TR_ poins and add them to the opc-ua server.
* *
* SD.unb->get_pointMap() --> FPGA_* (points defined in src/fpga.cpp) * SD.fpgas->get_pointMap() --> FPGA_* (points defined in src/fpga.cpp)
* SD.tr->getTranslatorMap() --> TR_* (points defined in src/tr.cpp) * SD.tr->getTranslatorMap() --> TR_* (points defined in src/tr.cpp)
*/ */
int ua_server_init(bool warm_start) int ua_server_init(bool warm_start)
...@@ -969,7 +969,7 @@ int ua_server_init(bool warm_start) ...@@ -969,7 +969,7 @@ int ua_server_init(bool warm_start)
mUaLofarNameSpace,UA_LOFAR_NAMESPACE); mUaLofarNameSpace,UA_LOFAR_NAMESPACE);
UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND, "UA Server add pointMap"); UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND, "UA Server add pointMap");
CPointMap *pointmap = SD.unb->get_pointMap(); CPointMap *pointmap = SD.fpgas->get_pointMap();
vector<string> regnames = pointmap->getRegnames(""); vector<string> regnames = pointmap->getRegnames("");
for (auto m : regnames) { for (auto m : regnames) {
int format = pointmap->getFormat(m); int format = pointmap->getFormat(m);
......
...@@ -105,9 +105,9 @@ void monitor() ...@@ -105,9 +105,9 @@ void monitor()
cout << "[" << time_str << " (UTC)] " << "MONITOR THREAD: uptime=" << SD.uptime << " seconds" << endl; cout << "[" << time_str << " (UTC)] " << "MONITOR THREAD: uptime=" << SD.uptime << " seconds" << endl;
if (SD.unb != NULL) { if (SD.fpgas != NULL) {
// cout << "sdptr_monitor start" << endl; // cout << "sdptr_monitor start" << endl;
SD.unb->monitor(termout); SD.fpgas->monitor(termout);
termout.clear(); termout.clear();
} }
} }
...@@ -152,8 +152,8 @@ void server_init(bool warm_start) ...@@ -152,8 +152,8 @@ void server_init(bool warm_start)
cerr << "done, it is mine. Now (re)init all" << endl; cerr << "done, it is mine. Now (re)init all" << endl;
if (warm_start) { if (warm_start) {
if (SD.unb != NULL) delete SD.unb; if (SD.fpgas != NULL) delete SD.fpgas;
SD.unb = NULL; SD.fpgas = NULL;
} }
list<class Node*> nodelist; list<class Node*> nodelist;
...@@ -166,7 +166,7 @@ void server_init(bool warm_start) ...@@ -166,7 +166,7 @@ void server_init(bool warm_start)
Node *node = new Node(nc.ipaddr, uniboardnr, n, type, nc.n_beamsets); Node *node = new Node(nc.ipaddr, uniboardnr, n, type, nc.n_beamsets);
nodelist.push_back(node); nodelist.push_back(node);
} }
SD.unb = new UniboardMap(nodelist, SD.n_beamsets); SD.fpgas = new FpgaMap(nodelist, SD.n_beamsets);
ua_server_init(warm_start); ua_server_init(warm_start);
...@@ -293,7 +293,7 @@ int main (int argc, char **argv) ...@@ -293,7 +293,7 @@ int main (int argc, char **argv)
monitor_thread->join(); monitor_thread->join();
delete monitor_thread; delete monitor_thread;
//closelog(); // close syslog connection //closelog(); // close syslog connection
delete SD.unb; delete SD.fpgas;
delete SD.tr; delete SD.tr;
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
#include <ctime> #include <ctime>
#include <sys/types.h> #include <sys/types.h>
#include "map.h" #include "fpga.h"
#include "tr.h" #include "tr.h"
#include "io/tcpsocket.h" #include "io/tcpsocket.h"
...@@ -45,7 +45,7 @@ ...@@ -45,7 +45,7 @@
class Serverdat { class Serverdat {
public: public:
UniboardMap *unb; FpgaMap *fpgas;
TranslatorMap *tr; TranslatorMap *tr;
std::string configfile; std::string configfile;
......
...@@ -103,7 +103,7 @@ bool TranslatorMap::translator(TermOutput& termout, const char cmd, const string ...@@ -103,7 +103,7 @@ bool TranslatorMap::translator(TermOutput& termout, const char cmd, const string
// else // else
if (addr == "TR_fpga_mask_R") { if (addr == "TR_fpga_mask_R") {
bool *ptr_out = (bool *)termout.val; bool *ptr_out = (bool *)termout.val;
vector<bool> masked = SD.unb->get_all_masked_nodes(); vector<bool> masked = SD.fpgas->get_all_masked_nodes();
for (auto val : masked) { for (auto val : masked) {
*ptr_out = val; *ptr_out = val;
ptr_out++; ptr_out++;
...@@ -117,11 +117,11 @@ bool TranslatorMap::translator(TermOutput& termout, const char cmd, const string ...@@ -117,11 +117,11 @@ bool TranslatorMap::translator(TermOutput& termout, const char cmd, const string
masked.push_back(*ptr_in); masked.push_back(*ptr_in);
ptr_in++; ptr_in++;
} }
SD.unb->set_all_masked_nodes(masked); SD.fpgas->set_all_masked_nodes(masked);
} }
else { else {
bool *ptr_out = (bool *)termout.val; bool *ptr_out = (bool *)termout.val;
vector<bool> masked = SD.unb->get_all_masked_nodes(); vector<bool> masked = SD.fpgas->get_all_masked_nodes();
for (auto val : masked) { for (auto val : masked) {
*ptr_out = val; *ptr_out = val;
ptr_out++; ptr_out++;
...@@ -140,7 +140,7 @@ bool TranslatorMap::translator(TermOutput& termout, const char cmd, const string ...@@ -140,7 +140,7 @@ bool TranslatorMap::translator(TermOutput& termout, const char cmd, const string
} }
else if (addr == "TR_tod_pps_delta_R") { else if (addr == "TR_tod_pps_delta_R") {
double *ptr_out = (double *)termout.val; double *ptr_out = (double *)termout.val;
vector<uint32_t> pps_offset_cnt = SD.unb->get_all_pps_offset_cnt(); vector<uint32_t> pps_offset_cnt = SD.fpgas->get_all_pps_offset_cnt();
double pps_delta = 0.0; double pps_delta = 0.0;
for (uint i=0; i<pps_offset_cnt.size(); i++) { for (uint i=0; i<pps_offset_cnt.size(); i++) {
if (pps_offset_cnt[i] > 0) { if (pps_offset_cnt[i] > 0) {
...@@ -157,7 +157,7 @@ bool TranslatorMap::translator(TermOutput& termout, const char cmd, const string ...@@ -157,7 +157,7 @@ bool TranslatorMap::translator(TermOutput& termout, const char cmd, const string
} }
else if (addr == "TR_fpga_communication_error_R") { else if (addr == "TR_fpga_communication_error_R") {
bool *ptr_out = (bool *)termout.val; bool *ptr_out = (bool *)termout.val;
vector<bool> offline = SD.unb->get_all_offline_nodes(); vector<bool> offline = SD.fpgas->get_all_offline_nodes();
for (auto val : offline) { for (auto val : offline) {
*ptr_out = val; *ptr_out = val;
ptr_out++; ptr_out++;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment