...
 
Commits (2)
Citation Notice version 1.0
This Citation Notice is part of the LOFAR software suite.
Parties that use ASTRON Software resulting in papers and/or publications are requested to
refer to the DOI(s) that correspond(s) to the version(s) of the ASTRON Software used:
<List of DOIs>
Parties that use ASTRON Software for purposes that do not result in publications (e.g.
commercial parties) are asked to inform ASTRON about their use of ASTRON Software, by
sending an email to including the DOIs mentioned above in the message.
If you use (part of) this software please attribute the use to ASTRON as indicated in the
file NOTICE in the root of the source code repository.
# In brief:
in case of missing automake/ autoconf:
......
This diff is collapsed.
/*
* Copyright 2020 Stichting Nederlandse Wetenschappelijk Onderzoek Instituten,
* ASTRON Netherlands Institute for Radio Astronomy
* Licensed under the Apache License, Version 2.0 (the "License");
*
* you may not use this file except in compliance with the License.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* See ../LICENSE.txt for more info.
*/
#ifndef CMD_H
#define CMD_H 1
......@@ -15,6 +31,7 @@
#define CMD_EMPTY -2
#define CMD_REQUEST_BINARY 2
#define CMD_REQUEST_QUIT 3
typedef struct {
int status;
uint extra__blocksize;
......
/*
* Copyright 2020 Stichting Nederlandse Wetenschappelijk Onderzoek Instituten,
* ASTRON Netherlands Institute for Radio Astronomy
* Licensed under the Apache License, Version 2.0 (the "License");
*
* you may not use this file except in compliance with the License.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* See ../LICENSE.txt for more info.
*/
#ifndef _REENTRANT
#error ACK! You need to compile with _REENTRANT defined since this uses threads
#endif
......@@ -31,7 +47,7 @@ using namespace std;
Common::Common(list<class Node*>& nodelist)
{
NODE=nodelist;
NODE = nodelist;
}
Common::~Common()
......@@ -55,7 +71,8 @@ void Common::print_node_id(ostringstream& strs, Node *node)
std::string Common::string_node_id(int node)
{
auto n = select_node(node);
return "/unb" + to_string(n->GetUniboardNr()) + "/" + n->GetType() + to_string(n->GetLocalNr()) + "/";
return "/unb" + to_string(n->GetUniboardNr()) + "/" + n->GetType() +
to_string(n->GetLocalNr()) + "/";
}
std::vector<int> Common::get_nodes(void)
......@@ -69,8 +86,8 @@ std::vector<int> Common::get_nodes(void)
bool Common::get_system_info(TermOutput& termout, std::vector<int> nodes, const string what)
{
bool retval=false;
uint retcnt=0;
bool retval = false;
uint retcnt = 0;
for(auto n : nodes) {
auto node = select_node(n);
......@@ -94,25 +111,24 @@ bool Common::read(TermOutput& termout, const string addr, const uint offs, const
std::vector<int> nodes = path_to_node(addr);
std::string relative_addr = addr_to_relative_addr(addr);
std::string type = addr_to_type(addr);
std::string peripheral = addr_to_peripheral(addr);
std::string type = addr_to_type(addr);
std::string peripheral = addr_to_peripheral(addr);
for(uint idx=0;idx<nodes.size();idx++) {
auto node = select_node(nodes[idx]);
print_node_id(termout.strout,node);
if(idx>0) termout.strout << ",";
//termout.strout << "[" << node->GetGlobalNr() << "],";
if(idx > 0) termout.strout << ",";
termout.strout << "[";
if(type == "mm") {
RegisterMap *regmap = node->get_RegisterMap(termout.strout);
uint32_t nvalues = (len<0 ? (regmap->getSpan(relative_addr) / 4) : len);
uint32_t nvalues = (len<0 ? (regmap->getSpan(relative_addr) / sizeof(uint32_t)) : len);
std::vector<int> datavec;
if(node->mread(termout.strout,relative_addr,offs,datavec,nvalues)) {
if(node->mread(termout.strout, relative_addr, offs, datavec, nvalues)) {
retcnt++;
}
} else if(type == "dev") {
if(node->get_system_info(termout.strout,peripheral)) {
if(node->get_system_info(termout.strout, peripheral)) {
retcnt++;
} else {
termout.strerr << "no such peripheral: " << peripheral;
......@@ -129,25 +145,25 @@ bool Common::read(TermOutput& termout, const string addr, const uint offs, const
bool Common::mwrite(TermOutput& termout, const string addr,
const uint offs, const std::vector<int>& data)
{
bool retval=false;
uint retcnt=0;
bool retval = false;
uint retcnt = 0;
std::vector<int> nodes;
for(uint idx=0;idx<nodes.size();idx++) {
for(uint idx = 0; idx<nodes.size(); idx++) {
auto node = select_node(nodes[idx]);
print_node_id(termout.strout,node);
print_node_id(termout.strout, node);
if(idx>0) termout.strout << ",";
if(idx > 0) termout.strout << ",";
termout.strout << "[" << node->GetGlobalNr() << "],";
termout.strout << "[";
for(uint i=0;i<data.size();i++) {
if(i>0) termout.strout << ",";
for(uint i = 0; i < data.size(); i++) {
if(i > 0) termout.strout << ",";
termout.strout << data[i];
}
termout.strout << "]";
if(node->mwrite(termout.strout,addr,offs,data)) retcnt++;
if(node->mwrite(termout.strout,addr, offs, data)) retcnt++;
}
retval = (retcnt==nodes.size());
return retval;
......@@ -166,14 +182,9 @@ std::vector<int> Common::unb_pn__to__nodes(std::vector<int> unbs, std::vector<in
std::vector<int> nodes;
for(auto unb : unbs) {
for(auto pn : pns) {
nodes.push_back(pn+(4*unb));
nodes.push_back(pn + (c_NOF_PN_on_UNB * unb));
}
}
// cout << "unb_pn__to__nodes:";
// for(auto n : nodes) {
// cout << n << " ";
// }
// cout << endl;
return nodes;
}
......@@ -192,34 +203,29 @@ uint Common::ipaddr_to_id(const string ipaddr)
*/
uint8_t node = (uint8_t)(ip&0xf)-1;
uint8_t unb = (uint8_t)(ip>>8); // unb number is stored in 2nd least significant tuble
return (unb*8+node);
return (unb*8 + node);
}
std::vector<int> Common::unb_name_to_number(const std::string unb_name)
{
std::vector<int> unbs;
cout << "Common::unb_name_to_number: unb_name=" << unb_name << endl;
//cout << "Common::unb_name_to_number: unb_name=" << unb_name << endl;
if(unb_name.length() >= 4) {
if(unb_name.length() > strlen("unb")) {
if(unb_name[0] == 'u' && unb_name[1] == 'n' && unb_name[2] == 'b') {
std::string unb_range = unb_name.substr(3);
cout << "unb_range=" << unb_range << endl;
try {
unbs.push_back(std::stoi(unb_range,nullptr));
unbs.push_back(std::stoi(unb_range, nullptr));
} catch (const std::invalid_argument& ia) {
cerr << "Common::unb_name_to_number: Invalid argument: " << ia.what() << " - but trying vector..." << endl;
cerr << "Common::unb_name_to_number: Invalid argument: "
<< ia.what() << " - but trying vector..." << endl;
istringstream vecstr(unb_range);
unbs=parse_int_vector_range(vecstr);
}
}
}
// cout << "Common::unb_name_to_number: found unb:" << endl;
// for(auto u : unbs) {
// cout << u << " ";;
// }
// cout << endl;
return unbs;
}
......@@ -227,56 +233,55 @@ std::vector<int> Common::pn_name_to_number(const std::string pn_name)
{
std::vector<int> pns;
if(pn_name.length() >= 3) {
if(pn_name.length() > strlen("pn")) {
if(pn_name[0] == 'p' && pn_name[1] == 'n') {
std::string pn_range = pn_name.substr(2);
cout << "pn_range=" << pn_range << endl;
try {
pns.push_back(std::stoi(pn_range,nullptr));
} catch (const std::invalid_argument& ia) {
cerr << "Common::pn_name_to_number: Invalid argument: " << ia.what() << " - but trying vector..." << endl;
cerr << "Common::pn_name_to_number: Invalid argument: "
<< ia.what() << " - but trying vector..." << endl;
istringstream vecstr(pn_range);
pns=parse_int_vector_range(vecstr);
}
}
}
// cout << "Common::pn_name_to_number: found pns:" << endl;
// for(auto p : pns) {
// cout << p << " ";;
// }
// cout << endl;
return pns;
}
// "/unb0/pn3/mm/addr"
// 0 1 2 3 4
#define c_PATH_root 0
#define c_PATH_unb 1
#define c_PATH_pn 2
#define c_PATH_type 3
#define c_PATH_addr 4
std::vector<int> Common::path_to_node(std::string path_str)
{
std::vector<int> nodes;
std::stringstream ss(path_str);
std::string token;
std::vector<std::string> tokens;
while (std::getline(ss, token, '/')) {
tokens.push_back(token);
}
if(tokens.size() >= 3) {
if(tokens[0] == "") {
if(tokens.size() > c_PATH_pn) {
if(tokens[c_PATH_root] == "") {
// ok, is absolute path starting with '/'
std::vector<int> unb = unb_name_to_number(tokens[1]);
std::vector<int> pn = pn_name_to_number(tokens[2]);
std::vector<int> unb = unb_name_to_number(tokens[c_PATH_unb]);
std::vector<int> pn = pn_name_to_number(tokens[c_PATH_pn]);
for(auto u : unb) {
for(auto p : pn) {
if(u>=0 && p>=0) {
nodes.push_back(p+(4*u));
nodes.push_back(p + (c_NOF_PN_on_UNB * u));
}
}
}
}
}
// cout << "Common::path_to_node: found nodes:" << endl;
// for(auto n : nodes) {
// cout << n << " ";;
// }
// cout << endl;
return nodes;
}
......@@ -291,11 +296,8 @@ std::string Common::addr_to_relative_addr(std::string addr)
tokens.push_back(token);
}
// "/unb0/pn3/mm/addr"
// 0 1 2 3 4
for(uint i=3;i<tokens.size();i++) {
if(i>3) rel_addr += "/";
for(uint i=c_PATH_type; i < tokens.size(); i++) {
if(i>c_PATH_type) rel_addr += "/";
rel_addr += tokens[i];
}
return rel_addr;
......@@ -312,11 +314,8 @@ std::string Common::addr_to_type(std::string addr)
tokens.push_back(token);
}
// "/unb0/pn3/dev/peripheral"
// 0 1 2 3 4
if(tokens.size() >= 4) {
type = tokens[3];
if(tokens.size() > c_PATH_type) {
type = tokens[c_PATH_type];
}
return type;
}
......@@ -332,11 +331,8 @@ std::string Common::addr_to_peripheral(std::string addr)
tokens.push_back(token);
}
// "/unb0/pn3/dev/peripheral"
// 0 1 2 3 4
if(tokens.size() >= 5) {
peripheral = tokens[4];
if(tokens.size() > c_PATH_addr) {
peripheral = tokens[c_PATH_addr];
}
return peripheral;
}
/*
* Copyright 2020 Stichting Nederlandse Wetenschappelijk Onderzoek Instituten,
* ASTRON Netherlands Institute for Radio Astronomy
* Licensed under the Apache License, Version 2.0 (the "License");
*
* you may not use this file except in compliance with the License.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* See ../LICENSE.txt for more info.
*/
#ifndef COMMON_H
#define COMMON_H 1
......@@ -15,6 +31,7 @@
namespace ublas = boost::numeric::ublas;
#define c_NOF_PN_on_UNB 4
class Common
{
......@@ -53,8 +70,6 @@ public:
std::string addr_to_relative_addr(std::string addr);
std::string addr_to_peripheral(std::string addr);
std::string addr_to_type(std::string addr);
};
#endif
//
// Copyright (c) 2009 G.W. Kant, Astron, The Netherlands
// E. van der Wal, Astron, The Netherlands
//
/*
* Copyright 2020 Stichting Nederlandse Wetenschappelijk Onderzoek Instituten,
* ASTRON Netherlands Institute for Radio Astronomy
* Licensed under the Apache License, Version 2.0 (the "License");
*
* you may not use this file except in compliance with the License.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* See ../../LICENSE.txt for more info.
*/
#include <unistd.h>
#include <stdlib.h>
......@@ -26,39 +37,28 @@
*/
TCPSSocket::TCPSSocket(uint16_t p, const char* iface, int maxservers) throw(const char *)
{
port = p;
MaxServers = maxservers;
sock = socket(PF_INET, SOCK_STREAM, 0);
if (sock < 0)
throw "TCPSSocket: socket creation error";
int val = 1;
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
&val, sizeof(val)) < 0) {
close(sock);
cerr << "Error: " << strerror(errno) << endl;
throw "TCPSSocket: cannot set socket option SO_REUSEADDR";
}
// this requires root permission:
// if (setsockopt(sock, SOL_SOCKET, SO_BINDTODEVICE,
// (void*) iface, strlen(iface)) < 0) {
// close(sock);
// cerr << "Error: " << strerror(errno) << endl;
//
// throw "TCPSSocket: cannot set socket option SO_BINDTODEVICE";
// }
/* Give the socket a name. */
name.sin_family = AF_INET;
name.sin_port = htons (port);
name.sin_addr.s_addr = htonl (INADDR_ANY);
if (bind (sock, (struct sockaddr *) &name, sizeof (name)) < 0) {
close(sock);
cerr << "Error: " << strerror(errno) << endl;
throw "TCPSSocket: cannot bind socket";
}
port = p;
MaxServers = maxservers;
sock = socket(PF_INET, SOCK_STREAM, 0);
if (sock < 0)
throw "TCPSSocket: socket creation error";
int val = 1;
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val)) < 0) {
close(sock);
cerr << "Error: " << strerror(errno) << endl;
throw "TCPSSocket: cannot set socket option SO_REUSEADDR";
}
/* Give the socket a name. */
name.sin_family = AF_INET;
name.sin_port = htons (port);
name.sin_addr.s_addr = htonl (INADDR_ANY);
if (bind (sock, (struct sockaddr *) &name, sizeof (name)) < 0) {
close(sock);
cerr << "Error: " << strerror(errno) << endl;
throw "TCPSSocket: cannot bind socket";
}
}
TCPSSocket::~TCPSSocket()
......@@ -68,74 +68,32 @@ TCPSSocket::~TCPSSocket()
int TCPSSocket::listen(void) throw(const char *)
{
#define USE_NO_FORK
#ifdef USE_NO_FORK
ostringstream strs;
#else
int Servers=1, status;
#endif
syslog(LOG_INFO,"Listening to tcp port %d\n",port);
if (::listen (sock, 1) < 0)
throw "TCPSSocket::listen: cannot put socket into listening state";
#ifdef USE_NO_FORK
/* Block until input arrives on the server socket. */
int nsock;
struct sockaddr_in clientname;
socklen_t size = sizeof (clientname);
nsock = accept (sock,(struct sockaddr *) &clientname,&size);
if (nsock < 0) {
cerr << "Error TCPSSocket::listen() accept(): " << strerror(errno) << endl;
exit(-1);
}
ostringstream strs;
syslog(LOG_INFO,"Listening to tcp port %d\n",port);
if (::listen (sock, 1) < 0)
throw "TCPSSocket::listen: cannot put socket into listening state";
/* Block until input arrives on the server socket. */
int nsock;
struct sockaddr_in clientname;
socklen_t size = sizeof (clientname);
nsock = accept (sock,(struct sockaddr *) &clientname,&size);
if (nsock < 0) {
cerr << "Error TCPSSocket::listen() accept(): " << strerror(errno) << endl;
exit(-1);
}
struct hostent *he;
he = gethostbyaddr(&clientname.sin_addr, sizeof clientname.sin_addr, AF_INET);
strs << "Server: Client connect from host "
<< (he ? he->h_name : inet_ntoa (clientname.sin_addr)) << " (" << inet_ntoa (clientname.sin_addr)
<< "):" << ntohs(clientname.sin_port) << endl;
struct hostent *he;
he = gethostbyaddr(&clientname.sin_addr, sizeof clientname.sin_addr, AF_INET);
strs << "Server: Client connect from host "
<< (he ? he->h_name : inet_ntoa (clientname.sin_addr)) << " (" << inet_ntoa (clientname.sin_addr)
<< "):" << ntohs(clientname.sin_port) << endl;
syslog(LOG_INFO,strs.str().c_str());
return nsock;
#else
while (1) {
/* Block until input arrives on the server socket. */
int nsock;
struct sockaddr_in clientname;
socklen_t size = sizeof (clientname);
pid_t pid = fork();
if (pid < 0)
throw "TCPSSocket::listen: cannot fork a child process";
else if (pid) { // We are the parent
++Servers;
cerr << "Child " << pid << endl;
if (Servers>MaxServers) {
cerr << "Maximum number of servers (" << MaxServers << ") reached" << endl;
int cpid = wait(&status);
cerr << "Child " << cpid << " terminated" << endl;
--Servers;
}
}
else { // We are child
nsock = accept (sock,
(struct sockaddr *) &clientname,
&size);
if (nsock < 0)
exit(-1);
cerr << "Server: Client connect from host "
<< inet_ntoa (clientname.sin_addr)
<< ":" << ntohs (clientname.sin_port)
<< endl;
return nsock;
}
}
#endif
syslog(LOG_INFO,strs.str().c_str());
return nsock;
}
TCPCSSocket::TCPCSSocket(int s)
......@@ -155,28 +113,28 @@ size_t TCPCSSocket::rx(unsigned char *buf, size_t len) throw(const char*)
number of actual received bytes
*/
{
size_t nrx = 0;
ssize_t ret;
do {
fd_set readfds;
FD_ZERO(&readfds);
FD_SET(sock, &readfds);
// No time out
if(select(sock + 1, &readfds, NULL, NULL, NULL) == -1) {
throw "TCPCSSocket::rx: select error";
}
if FD_ISSET(sock, &readfds) {
ret = recvfrom(sock, buf, len, 0, NULL, NULL);
if(ret == -1) {
throw "TCPCSSocket::rx(): recvfrom=-1 error";
} else if(ret == 0) {
throw "TCPCSSocket::rx(): recvfrom=0 peer orderly shutdown";
size_t nrx = 0;
ssize_t ret;
do {
fd_set readfds;
FD_ZERO(&readfds);
FD_SET(sock, &readfds);
// No time out
if(select(sock + 1, &readfds, NULL, NULL, NULL) == -1) {
throw "TCPCSSocket::rx: select error";
}
nrx += ret;
break;
}
} while (1);
return nrx;
if FD_ISSET(sock, &readfds) {
ret = recvfrom(sock, buf, len, 0, NULL, NULL);
if(ret == -1) {
throw "TCPCSSocket::rx(): recvfrom=-1 error";
} else if(ret == 0) {
throw "TCPCSSocket::rx(): recvfrom=0 peer orderly shutdown";
}
nrx += ret;
break;
}
} while (1);
return nrx;
}
size_t TCPCSSocket::_rx(unsigned char *buf, size_t len) throw(const char*)
......@@ -184,41 +142,41 @@ size_t TCPCSSocket::_rx(unsigned char *buf, size_t len) throw(const char*)
Receive len bytes from a TCP socket
*/
{
size_t nrx = 0;
ssize_t ret;
//struct timeval timeout;
//timeout.tv_sec = timeoutms / 1000;
//timeout.tv_usec = ( timeoutms % 1000 ) * 1000;
// Receive a datagram from a tx source
do {
fd_set readfds;
FD_ZERO(&readfds);
FD_SET(sock, &readfds);
// No time out
if(select(sock + 1, &readfds, NULL, NULL, NULL) == -1) {
throw "TCPCSSocket::_rx: select error";
}
if FD_ISSET(sock, &readfds) {
ret = recvfrom(sock, &buf[nrx], len-nrx, 0, NULL, NULL);
if(ret == -1) {
throw "TCPCSSocket::_rx(): recvfrom=-1 error";
} else if(ret == 0) {
throw "TCPCSSocket::_rx(): recvfrom=0 peer orderly shutdown";
size_t nrx = 0;
ssize_t ret;
//struct timeval timeout;
//timeout.tv_sec = timeoutms / 1000;
//timeout.tv_usec = ( timeoutms % 1000 ) * 1000;
// Receive a datagram from a tx source
do {
fd_set readfds;
FD_ZERO(&readfds);
FD_SET(sock, &readfds);
// No time out
if(select(sock + 1, &readfds, NULL, NULL, NULL) == -1) {
throw "TCPCSSocket::_rx: select error";
}
nrx += ret;
}
if (nrx==len)
break;
} while (1);
return nrx;
if FD_ISSET(sock, &readfds) {
ret = recvfrom(sock, &buf[nrx], len-nrx, 0, NULL, NULL);
if(ret == -1) {
throw "TCPCSSocket::_rx(): recvfrom=-1 error";
} else if(ret == 0) {
throw "TCPCSSocket::_rx(): recvfrom=0 peer orderly shutdown";
}
nrx += ret;
}
if (nrx==len)
break;
} while (1);
return nrx;
}
size_t TCPCSSocket::tx(const unsigned char* mes, size_t len) throw(const char*)
{
int ntxbytes = write(sock, mes, len);
if (ntxbytes < 0)
throw "TCPCSSocket::tx(): could not send message";
return ntxbytes;
int ntxbytes = write(sock, mes, len);
if (ntxbytes < 0)
throw "TCPCSSocket::tx(): could not send message";
return ntxbytes;
}
/*
* Copyright 2020 Stichting Nederlandse Wetenschappelijk Onderzoek Instituten,
* ASTRON Netherlands Institute for Radio Astronomy
* Licensed under the Apache License, Version 2.0 (the "License");
*
* you may not use this file except in compliance with the License.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* See ../../LICENSE.txt for more info.
*/
#ifndef TCPSOCKET_H
#define TCPSOCKET_H
//
// $Id$
//
// Copyright (c) 2009 G.W. Kant, Astron, The Netherlands
// E. van der Wal, Astron, The Netherlands
//
#include <sys/socket.h>
#include <stdio.h>
......
/*
* Copyright 2020 Stichting Nederlandse Wetenschappelijk Onderzoek Instituten,
* ASTRON Netherlands Institute for Radio Astronomy
* Licensed under the Apache License, Version 2.0 (the "License");
*
* you may not use this file except in compliance with the License.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* See ../../LICENSE.txt for more info.
*/
#include <stdlib.h>
#include <unistd.h>
#include <sys/ioctl.h>
......
/*
* Copyright 2020 Stichting Nederlandse Wetenschappelijk Onderzoek Instituten,
* ASTRON Netherlands Institute for Radio Astronomy
* Licensed under the Apache License, Version 2.0 (the "License");
*
* you may not use this file except in compliance with the License.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* See ../../LICENSE.txt for more info.
*/
#ifndef __UDPSOCKET_H__
#define __UDPSOCKET_H__
......
/*
* Copyright 2020 Stichting Nederlandse Wetenschappelijk Onderzoek Instituten,
* ASTRON Netherlands Institute for Radio Astronomy
* Licensed under the Apache License, Version 2.0 (the "License");
*
* you may not use this file except in compliance with the License.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* See ../../LICENSE.txt for more info.
*/
#ifndef _REENTRANT
#error ACK! You need to compile with _REENTRANT defined since this uses threads
#endif
......@@ -135,7 +151,7 @@ bool UNBos::TransmitWrite(const uint32_t opcode, const uint32_t addr, const uint
unb->hdr.opcode = opcode;
unb->hdr.nvalues = nvalues;
unb->hdr.addr = addr;
memcpy(unb->data,buf,nvalues*sizeof(uint32_t));
memcpy(unb->data, buf, nvalues*sizeof(uint32_t));
//print_cmd_packet(pkt, pktlength);
size_t retval = commdev->tx(pkt, pktlength);
......@@ -202,17 +218,17 @@ void UNBos::print_cmd_packet(const uint8_t *pkt, const int len)
{
printf("\x1b[31;1mUNBos::print_cmd_packet\x1b[0m\n");
UnbosCmdPacket *pkt_ptr=(UnbosCmdPacket *)pkt;
printf("hdr.psn=%d ",pkt_ptr->hdr.psn);
printf("hdr.opcode=%d ",pkt_ptr->hdr.opcode);
printf("hdr.nvalues=%d ",pkt_ptr->hdr.nvalues);
printf("hdr.addr=%d\n",pkt_ptr->hdr.addr);
printf("hdr.psn=%d ", pkt_ptr->hdr.psn);
printf("hdr.opcode=%d ", pkt_ptr->hdr.opcode);
printf("hdr.nvalues=%d ", pkt_ptr->hdr.nvalues);
printf("hdr.addr=%d\n", pkt_ptr->hdr.addr);
const uint8_t *bufptr=pkt;
printf(" ");
for(int i=0;i<16;i++) printf("%2x ",i);
for(int i=0;i<len;i++) {
if ((i%16)==0) printf("\n%02x: ",i);
printf("%02x ",bufptr[i]);
printf("%02x ", bufptr[i]);
}
printf("\n");
}
......@@ -220,16 +236,16 @@ void UNBos::print_cmd_packet(const uint8_t *pkt, const int len)
void UNBos::print_reply_packet(const uint8_t *pkt, const int len)
{
printf("\x1b[32;1mUNBos::print_reply_packet\x1b[0m\n");
UnbosReadAckPacket *pkt_ptr=(UnbosReadAckPacket *)pkt;
printf("hdr.psn=%d ",pkt_ptr->hdr.psn);
printf("hdr.addr=%d\n",pkt_ptr->hdr.addr);
UnbosReadAckPacket *pkt_ptr = (UnbosReadAckPacket *)pkt;
printf("hdr.psn=%d ", pkt_ptr->hdr.psn);
printf("hdr.addr=%d\n", pkt_ptr->hdr.addr);
const uint8_t *bufptr=pkt;
const uint8_t *bufptr = pkt;
printf(" ");
for(int i=0;i<16;i++) printf("%2x ",i);
for(int i=0;i<len;i++) {
for(int i=0; i<16; i++) printf("%2x ",i);
for(int i=0; i<len; i++) {
if ((i%16)==0) printf("\n%02x: ",i);
printf("%02x ",bufptr[i]);
printf("%02x ", bufptr[i]);
}
printf("\n");
}
......@@ -237,12 +253,12 @@ void UNBos::print_reply_packet(const uint8_t *pkt, const int len)
bool UNBos::readRegister(uint32_t addr, uint32_t nvalues, uint32_t *data_ptr)
{
if(data_ptr==NULL) throw runtime_error("UNBos::readRegister data_ptr=NULL");
return Read(UNBOS_OPCODE_MEMORY_READ,addr,nvalues,data_ptr);
return Read(UNBOS_OPCODE_MEMORY_READ, addr, nvalues, data_ptr);
}
bool UNBos::writeRegister(uint32_t addr, uint32_t nvalues, const uint32_t *data_ptr)
{
if(data_ptr==NULL) throw runtime_error("UNBos::writeRegister data_ptr=NULL");
return Write(UNBOS_OPCODE_MEMORY_WRITE,addr,nvalues,data_ptr);
return Write(UNBOS_OPCODE_MEMORY_WRITE, addr, nvalues, data_ptr);
}
/*
* Copyright 2020 Stichting Nederlandse Wetenschappelijk Onderzoek Instituten,
* ASTRON Netherlands Institute for Radio Astronomy
* Licensed under the Apache License, Version 2.0 (the "License");
*
* you may not use this file except in compliance with the License.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* See ../../LICENSE.txt for more info.
*/
#ifndef __UNBOS_H__
#define __UNBOS_H__
......
/*
* Copyright 2020 Stichting Nederlandse Wetenschappelijk Onderzoek Instituten,
* ASTRON Netherlands Institute for Radio Astronomy
* Licensed under the Apache License, Version 2.0 (the "License");
*
* you may not use this file except in compliance with the License.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* See ../LICENSE.txt for more info.
*/
#include <iostream>
#include <sstream>
#include <iomanip>
......
/*
* Copyright 2020 Stichting Nederlandse Wetenschappelijk Onderzoek Instituten,
* ASTRON Netherlands Institute for Radio Astronomy
* Licensed under the Apache License, Version 2.0 (the "License");
*
* you may not use this file except in compliance with the License.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* See ../LICENSE.txt for more info.
*/
#ifndef UNIBOARD_MAP_H
#define UNIBOARD_MAP_H 1
......
/*
* Copyright 2020 Stichting Nederlandse Wetenschappelijk Onderzoek Instituten,
* ASTRON Netherlands Institute for Radio Astronomy
* Licensed under the Apache License, Version 2.0 (the "License");
*
* you may not use this file except in compliance with the License.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* See ../LICENSE.txt for more info.
*/
#ifndef _REENTRANT
#error ACK! You need to compile with _REENTRANT defined since this uses threads
#endif
......@@ -26,14 +42,12 @@ using namespace std;
extern int debug;
Node::Node(const string ipaddr, const uint unb, const uint localnr, const std::string type,
const string firmware)
: unbos(ipaddr)
const string firmware) : unbos(ipaddr)
{
myIPaddr=ipaddr;
myIPaddr = ipaddr;
periph_system = new Periph_system(unbos, firmware);
myFirmware=periph_system->read_design_name();
myFirmware = periph_system->read_design_name();
if(myFirmware != firmware) {
cerr << "Warning: Node configuration mismatch!! (read_design_name=" << myFirmware
<< ", config=" << firmware << ")" << endl;
......@@ -41,14 +55,14 @@ Node::Node(const string ipaddr, const uint unb, const uint localnr, const std::s
myFirmware.c_str(),firmware.c_str());
}
UniboardNr=unb;
LocalNr=localnr;
GlobalNr=localnr+4*unb;
UniboardNr = unb;
LocalNr = localnr;
GlobalNr = localnr + 4*unb;
if(type!="pn") throw runtime_error("invalid node type: \"" + type + "\"");
Type=type;
syslog(LOG_INFO,"Uniboard=%d New node IP=%s type=%s localnr=%d globalnr=%d\n",
UniboardNr,myIPaddr.c_str(),Type.c_str(),LocalNr,GlobalNr);
UniboardNr, myIPaddr.c_str(), Type.c_str(), LocalNr, GlobalNr);
}
Node::~Node()
......@@ -57,17 +71,17 @@ Node::~Node()
}
bool Node::get_system_info(ostringstream& strs,const string what) {
if(what=="system") {
if(what == "system") {
return periph_system->read_system_info(strs);
} else if(what=="name") {
strs << "read_design_name:" << periph_system->read_design_name(); // << endl;
} else if(what == "name") {
strs << "read_design_name:" << periph_system->read_design_name();
return true;
} else if(what=="stamps") {
} else if(what == "stamps") {
return periph_system->read_stamps(strs);
} else if(what=="note") {
strs << "read_design_note:" << periph_system->read_design_note(); // << endl;
} else if(what == "note") {
strs << "read_design_note:" << periph_system->read_design_note();
return true;
} else if(what=="sensors") {
} else if(what == "sensors") {
return periph_system->read_unb_sensors(strs,LocalNr);
}
else return false;
......@@ -81,10 +95,10 @@ RegisterMap * Node::get_RegisterMap(std::ostringstream& strs)
bool Node::mread(std::ostringstream& strs,const std::string addr, const uint offs,
std::vector<int>& data, const uint len) {
return periph_system->mread(strs,addr,offs,data,len);
return periph_system->mread(strs, addr, offs, data, len);
}
bool Node::mwrite(std::ostringstream& strs,const std::string addr, const uint offs,
const std::vector<int>& data) {
return periph_system->mwrite(strs,addr,offs,data);
return periph_system->mwrite(strs, addr, offs, data);
}
/*
* Copyright 2020 Stichting Nederlandse Wetenschappelijk Onderzoek Instituten,
* ASTRON Netherlands Institute for Radio Astronomy
* Licensed under the Apache License, Version 2.0 (the "License");
*
* you may not use this file except in compliance with the License.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* See ../LICENSE.txt for more info.
*/
#ifndef NODE_H
#define NODE_H
......@@ -77,5 +93,4 @@ class Node {
RegisterMap * get_RegisterMap(std::ostringstream& strs);
};
#endif /* NODE_H */
/*
* Copyright 2020 Stichting Nederlandse Wetenschappelijk Onderzoek Instituten,
* ASTRON Netherlands Institute for Radio Astronomy
* Licensed under the Apache License, Version 2.0 (the "License");
*
* you may not use this file except in compliance with the License.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* See ../../LICENSE.txt for more info.
*/
#include <open62541/plugin/log_stdout.h>
#include <open62541/server.h>
#include <open62541/server_config_default.h>
......@@ -22,7 +38,7 @@ string p_termout(TermOutput& termout)
static void updateVariable(UA_Server *server)
{
UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND,"updateVariable()");
UA_Int32 my_integer = 30;
UA_Int32 my_integer = 30; // FIXME: this is example code, remove later
UA_Variant value;
UA_Variant_setScalar(&value, &my_integer, &UA_TYPES[UA_TYPES_INT32]);
UA_NodeId currentNodeId = UA_NODEID_STRING(1, (char *)"sensors");
......@@ -34,7 +50,7 @@ static void addVariable(UA_Server *server)
UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND,"addVariable()");
/* Define the attribute of the myInteger variable node */
UA_VariableAttributes attr = UA_VariableAttributes_default;
UA_Int32 myInteger = 42;
UA_Int32 myInteger = 42; // FIXME: this is example code, remove later
UA_Variant_setScalar(&attr.value, &myInteger, &UA_TYPES[UA_TYPES_INT32]);
attr.description = UA_LOCALIZEDTEXT((char *)"en-US",(char *)"sensors");
attr.displayName = UA_LOCALIZEDTEXT((char *)"en-US",(char *)"sensors");
......@@ -92,25 +108,25 @@ static UA_StatusCode UNB_MethodCallback(UA_Server *server,
static void add_UNB_Method(UA_Server *server, std::string regname)
{
UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND,"add_UNB_Method: %s",(char *)regname.c_str());
UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND, "add_UNB_Method: %s", (char *)regname.c_str());
UA_Argument inputArgument;
UA_Argument_init(&inputArgument);
inputArgument.description = UA_LOCALIZEDTEXT((char *)"en-US",(char *) "A String");
inputArgument.description = UA_LOCALIZEDTEXT((char *)"en-US", (char *) "A String");
inputArgument.name = UA_STRING((char *)"MyInput");
inputArgument.dataType = UA_TYPES[UA_TYPES_STRING].typeId;
inputArgument.valueRank = UA_VALUERANK_SCALAR;
UA_Argument outputArgument;
UA_Argument_init(&outputArgument);
outputArgument.description = UA_LOCALIZEDTEXT((char *)"en-US",(char *) "A String");
outputArgument.description = UA_LOCALIZEDTEXT((char *)"en-US", (char *) "A String");
outputArgument.name = UA_STRING((char *)"MyOutput");
outputArgument.dataType = UA_TYPES[UA_TYPES_STRING].typeId;
outputArgument.valueRank = UA_VALUERANK_SCALAR;
UA_MethodAttributes helloAttr = UA_MethodAttributes_default;
helloAttr.description = UA_LOCALIZEDTEXT((char *)"en-US",(char *)"UNB file");
helloAttr.displayName = UA_LOCALIZEDTEXT((char *)"en-US",(char *)"UNB file");
helloAttr.description = UA_LOCALIZEDTEXT((char *)"en-US", (char *)"UNB file");
helloAttr.displayName = UA_LOCALIZEDTEXT((char *)"en-US", (char *)"UNB file");
helloAttr.executable = true;
helloAttr.userExecutable = true;
UA_Server_addMethodNode(server, UA_NODEID_STRING(1, (char *)regname.c_str()),
......@@ -146,7 +162,7 @@ int ua_server(Serverdat *sd) {
UA_StatusCode retval = UA_Server_run(mUaServer, &ServerRunning);
UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND,"UA Server Stopped");
UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND, "UA Server Stopped");
UA_Server_delete(mUaServer);
return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE;
}
......
/*
* Copyright 2020 Stichting Nederlandse Wetenschappelijk Onderzoek Instituten,
* ASTRON Netherlands Institute for Radio Astronomy
* Licensed under the Apache License, Version 2.0 (the "License");
*
* you may not use this file except in compliance with the License.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* See ../../LICENSE.txt for more info.
*/
#ifndef UA_SERVER_H
#define UA_SERVER_H
......
This diff is collapsed.
/*
* Copyright 2020 Stichting Nederlandse Wetenschappelijk Onderzoek Instituten,
* ASTRON Netherlands Institute for Radio Astronomy
* Licensed under the Apache License, Version 2.0 (the "License");
*
* you may not use this file except in compliance with the License.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* See ../../LICENSE.txt for more info.
*/
#ifndef __PERIPH_SYSTEM_H__
#define __PERIPH_SYSTEM_H__
......@@ -30,7 +46,6 @@ public:
std::string read_design_name(void);
std::string read_design_note(void);
bool read_stamps(ostringstream& strs);
bool read_use_phy(ostringstream& strs);
bool read_unb_sensor(uint32_t *sensor, const uint nodeNr);
bool read_unb_sensors(ostringstream& strs, const uint nodeId);
bool read_temp_high(ostringstream& strs);
......@@ -38,7 +53,7 @@ public:
bool write_wdi_override(ostringstream& strs);
RegisterMap read_reg_map(void);
RegisterMap * getRegisterMap(void) { return registerMap; };
void print_regmap(ostringstream& strs, std::string prefix) { registerMap->print(strs,prefix); };
void print_regmap(ostringstream& strs, std::string prefix) { registerMap->print(strs, prefix); };
};
#endif // __PERIPH_SYSTEM_H__
/*
* Copyright 2020 Stichting Nederlandse Wetenschappelijk Onderzoek Instituten,
* ASTRON Netherlands Institute for Radio Astronomy
* Licensed under the Apache License, Version 2.0 (the "License");
*
* you may not use this file except in compliance with the License.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* See ../LICENSE.txt for more info.
*/
#include <iostream>
#include <iomanip>
#include <sstream>
#include <string>
#include <map>
......@@ -12,7 +29,7 @@ void RegisterMap::add_register(const std::string name, const uint32_t base,
const uint32_t shift, const std::string access)
{
register_info r={base, span, mask, shift, access};
reg.insert(reg.end(),std::pair<std::string,register_info>(name,r));
reg.insert(reg.end(), std::pair<std::string, register_info>(name, r));
}
void RegisterMap::print(ostringstream& strs, std::string prefix)
......@@ -50,9 +67,18 @@ std::vector<std::string> RegisterMap::getRegnames(std::string prefix)
std::vector<std::string> RegisterMap::getRegnames_full(std::string prefix)
{
std::ostringstream ss;
std::vector<std::string> regnames;
for(auto m : reg) {
regnames.push_back(m.second.access + " " + to_string(m.second.span) + " " + prefix + m.first);
ss.str("");
ss.clear();
ss << m.second.access << " "
<< "0x" << std::setfill('0') << std::hex << std::setw(8) << m.second.base << " "
<< std::setfill(' ') << std::dec << std::setw(4) << m.second.span << " "
<< prefix << m.first;
regnames.push_back(ss.str());
}
return regnames;
}
......
/*
* Copyright 2020 Stichting Nederlandse Wetenschappelijk Onderzoek Instituten,
* ASTRON Netherlands Institute for Radio Astronomy
* Licensed under the Apache License, Version 2.0 (the "License");
*
* you may not use this file except in compliance with the License.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* See ../LICENSE.txt for more info.
*/
#ifndef __REGISTERMAP_H__
#define __REGISTERMAP_H__
......
This diff is collapsed.
/*
* Copyright 2020 Stichting Nederlandse Wetenschappelijk Onderzoek Instituten,
* ASTRON Netherlands Institute for Radio Astronomy
* Licensed under the Apache License, Version 2.0 (the "License");
*
* you may not use this file except in compliance with the License.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* See ../LICENSE.txt for more info.
*/
#ifndef SDPUNB_H
#define SDPUNB_H 1
......@@ -13,7 +29,9 @@ using namespace std;
#include "map.h"
#include "io/tcpsocket.h"
#define c_MAX_CONTROL_SERVERS 3
#define c_MAX_CONTROL_SERVERS 3
#define c_TCP_CONTROL_SOCKET 3335
#define c_TCP_CONTROL_BUFFERSIZE 1000
class Serverdat {
public:
......
/*
* Copyright 2020 Stichting Nederlandse Wetenschappelijk Onderzoek Instituten,
* ASTRON Netherlands Institute for Radio Astronomy
* Licensed under the Apache License, Version 2.0 (the "License");
*
* you may not use this file except in compliance with the License.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* See ../../LICENSE.txt for more info.
*/
#include <iostream>
#include <sstream>
#include <iomanip>
......
/*
* Copyright 2020 Stichting Nederlandse Wetenschappelijk Onderzoek Instituten,
* ASTRON Netherlands Institute for Radio Astronomy
* Licensed under the Apache License, Version 2.0 (the "License");
*
* you may not use this file except in compliance with the License.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* See ../../LICENSE.txt for more info.
*/
#ifndef CCFG_H
#define CCFG_H
......
/*
* Copyright 2020 Stichting Nederlandse Wetenschappelijk Onderzoek Instituten,
* ASTRON Netherlands Institute for Radio Astronomy
* Licensed under the Apache License, Version 2.0 (the "License");
*
* you may not use this file except in compliance with the License.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* See ../../LICENSE.txt for more info.
*/
#include <math.h>
#include <string.h>
#include <iostream>
......@@ -23,7 +39,7 @@ int parse_int(istringstream& vecstr)
int num;
vecstr >> num;
if(debug&0xe) cout << "parse_int:" << num << endl;
if(debug) cout << "parse_int:" << num << endl;
if (vecstr.fail() || vecstr.bad()) {
syslog(LOG_ERR,"parse_int parse error\n");
throw runtime_error("Invalid string");
......@@ -36,7 +52,7 @@ int parse_uint_nothrow(istringstream& vecstr)
int num;
vecstr >> num;
if(debug&0xe) cout << "parse_int_nothrow:" << num << endl;
if(debug) cout << "parse_int_nothrow:" << num << endl;
if (vecstr.fail() || vecstr.bad()) {
//syslog(LOG_ERR,"parse_int_nothrow no input: assume -1\n");
return -1;
......@@ -49,7 +65,7 @@ double parse_double(istringstream& vecstr)
double num;
vecstr >> num;
if(debug&0xe) cout << "parse_double:" << num << endl;
if(debug) cout << "parse_double:" << num << endl;
if (vecstr.fail() || vecstr.bad()) {
syslog(LOG_ERR,"parse_double parse error\n");
......@@ -63,7 +79,7 @@ double parse_double_nothrow(istringstream& vecstr)
double num;
vecstr >> num;
if(debug&0xe) cout << "parse_double_nothrow:" << num << endl;
if(debug) cout << "parse_double_nothrow:" << num << endl;
if (vecstr.fail() || vecstr.bad()) {
//syslog(LOG_INFO,"parse_double_nothrow no input: assume NAN\n");
......@@ -76,7 +92,7 @@ std::complex<double> parse_complex_double(istringstream& vecstr)
{
complex<double> num;
vecstr >> num;
if(debug&0xe) cout << "parse_complex_double:" << num << endl;
if(debug) cout << "parse_complex_double:" << num << endl;
if (vecstr.fail() || vecstr.bad()) {
syslog(LOG_ERR,"parse_complex_double parse error\n");
......@@ -98,7 +114,7 @@ std::vector<int> parse_int_vector(istringstream& vecstr)
c=vecstr.peek();
if(c==']' || c==0) {
if(debug&0xe) cout << "parse_int_vector: empty vector" << endl;
if(debug) cout << "parse_int_vector: empty vector" << endl;
vecstr >> c; // flush it from istringstream
return v;
}
......@@ -120,7 +136,7 @@ std::vector<int> parse_int_vector(istringstream& vecstr)
syslog(LOG_ERR,"parse_int_vector error\n");
throw runtime_error("parse_int_vector error");
}
if(debug&0xe) {
if(debug) {
cout << "parse_int_vector result: ";
for(int i=0;i<(int)v.size();i++) {
cout << v[i] << " ";
......@@ -142,7 +158,7 @@ std::vector<int> parse_int_vector_range(istringstream& vecstr)
c=vecstr.peek();
if(c==']' || c==0) {
if(debug&0xe) cout << "parse_int_vector_range: empty vector" << endl;
if(debug) cout << "parse_int_vector_range: empty vector" << endl;
vecstr >> c; // flush it from istringstream
return v;
}
......@@ -181,7 +197,7 @@ std::vector<int> parse_int_vector_range(istringstream& vecstr)
syslog(LOG_ERR,"parse_int_vector_range error\n");
throw runtime_error("parse_int_vector_range error");
}
if(debug&0xe) {
if(debug) {
cout << "parse_int_vector_range result: ";
for(int i=0;i<(int)v.size();i++) {
cout << v[i] << " ";
......@@ -213,7 +229,7 @@ std::vector<int64_t> parse_int64_vector_range(istringstream& vecstr)
c=vecstr.peek();
if(c==']' || c==0) {
if(debug&0xe) cout << "parse_int64_vector_range: empty vector" << endl;
if(debug) cout << "parse_int64_vector_range: empty vector" << endl;
vecstr >> c; // flush it from istringstream
return v;
}
......@@ -252,7 +268,7 @@ std::vector<int64_t> parse_int64_vector_range(istringstream& vecstr)
syslog(LOG_ERR,"parse_int64_vector_range error\n");
throw runtime_error("parse_int64_vector_range error");
}
if(debug&0xe) {
if(debug) {
cout << "parse_int64_vector_range result: ";
for(int i=0;i<(int)v.size();i++) {
cout << v[i] << " ";
......@@ -298,7 +314,7 @@ std::vector<double> parse_double_vector(istringstream& vecstr)
syslog(LOG_ERR,"parse_double_vector error\n");
throw runtime_error("parse_double_vector error");
}
if(debug&0xe) {
if(debug) {
cout << "parse_double_vector result: ";
for(int i=0;i<(int)v.size();i++) {
cout << v[i] << " ";
......@@ -343,7 +359,7 @@ std::vector< complex<double> > parse_complex_vector(istringstream& vecstr)
syslog(LOG_ERR,"parse_complex_vector error\n");
throw runtime_error("parse_complex_vector error");
}
if(debug&0xe) {
if(debug) {
cout << "parse_complex_vector result: ";
for(int i=0;i<(int)v.size();i++) {
cout << v[i] << " ";
......@@ -358,7 +374,7 @@ ublas::matrix< complex<double> > parse_complex_matrix(istringstream& vecstr)
{
ublas::matrix< complex<double> > m;
vecstr >> m;
if(debug&0xe) cout << "parse_complex_matrix result:" << m << endl;
if(debug) cout << "parse_complex_matrix result:" << m << endl;
if (vecstr.fail() || vecstr.bad()) {
syslog(LOG_ERR,"error parse_complex_matrix\n");
throw runtime_error("error parse_complex_matrix");
......@@ -370,7 +386,7 @@ ublas::matrix<double> parse_double_matrix(istringstream& vecstr)
{
ublas::matrix<double> m;
vecstr >> m;
if(debug&0xe) cout << "parse_double_matrix result:" << m << endl;
if(debug) cout << "parse_double_matrix result:" << m << endl;
if (vecstr.fail() || vecstr.bad()) {
syslog(LOG_ERR,"error parse_double_matrix\n");
throw runtime_error("error parse_double_matrix");
......
/*
* Copyright 2020 Stichting Nederlandse Wetenschappelijk Onderzoek Instituten,
* ASTRON Netherlands Institute for Radio Astronomy
* Licensed under the Apache License, Version 2.0 (the "License");
*
* you may not use this file except in compliance with the License.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* See ../../LICENSE.txt for more info.
*/
#ifndef PARSE_H
#define PARSE_H 1
......
/*
* Copyright 2020 Stichting Nederlandse Wetenschappelijk Onderzoek Instituten,
* ASTRON Netherlands Institute for Radio Astronomy
* Licensed under the Apache License, Version 2.0 (the "License");
*
* you may not use this file except in compliance with the License.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* See ../../LICENSE.txt for more info.
*/
#include <math.h>
#include <vector>
#include <algorithm>
......
/*
* Copyright 2020 Stichting Nederlandse Wetenschappelijk Onderzoek Instituten,
* ASTRON Netherlands Institute for Radio Astronomy
* Licensed under the Apache License, Version 2.0 (the "License");
*
* you may not use this file except in compliance with the License.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* See ../../LICENSE.txt for more info.
*/
#ifndef __UTIL_H__
#define __UTIL_H__