Skip to content

Commit

Permalink
Add vlbi server shared library
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilia Platone committed Nov 13, 2024
1 parent 20953cd commit 85d0a22
Show file tree
Hide file tree
Showing 9 changed files with 615 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: 2
jobs:
build:
machine:
image: ubuntu-2004:202101-01
image: ubuntu-2004:current
working_directory: ~/OpenVLBI
steps:
- checkout
Expand Down
25 changes: 20 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 2.8...3.8)

PROJECT(OpenVLBI C CXX)
LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/")
Expand All @@ -14,14 +14,15 @@ find_package(Threads REQUIRED)
option(CMAKE_BUILD_RPATH_USE_ORIGIN "rpath issue fix" ON)
option(WITH_VLBI_SERVER "Add OpenVLBI servers" ON)
option(WITH_INDI_SERVER "Add INDI server for OpenVLBI" ON)
option(WITH_SHARED_SERVER "Add shared server library for OpenVLBI" ON)
option(WITH_DUMMY_SERVER "Add dummy server for OpenVLBI" ON)
option(WITH_JSON_SERVER "Add JSON server for OpenVLBI" ON)

set (CMAKE_CXX_STANDARD 11)
set (CMAKE_C_STANDARD 11)
set (VLBI_VERSION_MAJOR 3)
set (VLBI_VERSION_MINOR 0)
set (VLBI_VERSION_RELEASE 2)
set (VLBI_VERSION_RELEASE 3)
set (VLBI_VERSION_STRING "${VLBI_VERSION_MAJOR}.${VLBI_VERSION_MINOR}.${VLBI_VERSION_RELEASE}")
set(LIB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
set(DATA_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}")
Expand Down Expand Up @@ -101,11 +102,13 @@ install(TARGETS opendsp LIBRARY DESTINATION ${LIB_INSTALL_DIR})

if(WITH_VLBI_SERVER)
add_library(openvlbi_server STATIC ${CMAKE_CURRENT_SOURCE_DIR}/vlbi_server.cpp ${CMAKE_CURRENT_SOURCE_DIR}/vlbi/instancecollection.cpp ${CMAKE_CURRENT_SOURCE_DIR}/vlbi/collection.cpp ${CMAKE_CURRENT_SOURCE_DIR}/vlbi/base64.c)
target_link_libraries(openvlbi_server ${CFITSIO_LIBRARIES} ${M_LIB} ${ZLIB_LIBRARY} openvlbi opendsp)
install(TARGETS openvlbi_server ARCHIVE DESTINATION ${LIB_INSTALL_DIR})

if(WITH_JSON_SERVER)
add_executable(vlbi_server_json ${CMAKE_CURRENT_SOURCE_DIR}/mjs.h ${CMAKE_CURRENT_SOURCE_DIR}/mjs.c ${CMAKE_CURRENT_SOURCE_DIR}/json.h ${CMAKE_CURRENT_SOURCE_DIR}/json.c ${CMAKE_CURRENT_SOURCE_DIR}/vlbi_server_json.cpp)
target_link_libraries(vlbi_server_json openvlbi_server openvlbi ${CFITSIO_LIBRARIES} ${M_LIB} ${ZLIB_LIBRARY} ${CMAKE_DL_LIBS})
target_link_libraries(vlbi_server_json openvlbi ${CFITSIO_LIBRARIES} ${M_LIB} ${ZLIB_LIBRARY} ${CMAKE_DL_LIBS})
target_link_libraries(vlbi_server_json openvlbi_server)
install(TARGETS vlbi_server_json RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
endif(WITH_JSON_SERVER)

Expand All @@ -115,14 +118,26 @@ if(INDI_LIBRARIES AND INDICLIENT_LIBRARIES)
find_package(Nova REQUIRED)
include_directories( ${INDI_INCLUDE_DIR})
add_executable(vlbi_server_indi ${CMAKE_CURRENT_SOURCE_DIR}/vlbi_server_indi.cpp)
target_link_libraries(vlbi_server_indi openvlbi_server openvlbi indiclient stdc++fs ${CFITSIO_LIBRARIES} ${M_LIB} ${ZLIB_LIBRARY})
target_link_libraries(vlbi_server_indi openvlbi indiclient stdc++fs ${CFITSIO_LIBRARIES} ${M_LIB} ${ZLIB_LIBRARY})
target_link_libraries(vlbi_server_indi openvlbi_server)
install(TARGETS vlbi_server_indi RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
endif(INDI_LIBRARIES AND INDICLIENT_LIBRARIES)
endif(WITH_INDI_SERVER)

if(WITH_DUMMY_SERVER)
add_executable(vlbi_server_dummy ${CMAKE_CURRENT_SOURCE_DIR}/vlbi_server_dummy.cpp)
target_link_libraries(vlbi_server_dummy openvlbi_server openvlbi ${M_LIB} ${ZLIB_LIBRARY})
target_link_libraries(vlbi_server_dummy openvlbi ${CFITSIO_LIBRARIES} ${M_LIB} ${ZLIB_LIBRARY})
target_link_libraries(vlbi_server_dummy openvlbi_server)
install(TARGETS vlbi_server_dummy RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
endif(WITH_DUMMY_SERVER)

if(WITH_SHARED_SERVER)
add_library(vlbi_server SHARED ${CMAKE_CURRENT_SOURCE_DIR}/vlbi_server_shared.cpp)
add_definitions(-fPIC)
target_link_libraries(vlbi_server openvlbi ${CFITSIO_LIBRARIES} ${M_LIB} ${ZLIB_LIBRARY})
target_link_libraries(vlbi_server openvlbi_server)
set_target_properties(vlbi_server PROPERTIES VERSION ${VLBI_VERSION_STRING} SOVERSION ${VLBI_VERSION_MAJOR})
install(TARGETS vlbi_server LIBRARY DESTINATION ${LIB_INSTALL_DIR})
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/vlbi_server.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include/OpenVLBI)
endif(WITH_SHARED_SERVER)
endif(WITH_VLBI_SERVER)
1 change: 0 additions & 1 deletion vlbi/base64.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
#include "base64.h"
#include "base64_luts.h"
#include <stdio.h>
#include <dsp.h>

/* convert inlen raw bytes at in to base64 string (NUL-terminated) at out.
* out size should be at least 4*inlen/3 + 4.
Expand Down
76 changes: 61 additions & 15 deletions vlbi/baselinecollection.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/* OpenVLBI - Open Source Very Long Baseline Interferometry
* Copyright © 2017-2023 Ilia Platone
* Copyright © 2017-2022 Ilia Platone
*
* 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 free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 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.
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

#include <cstdio>
Expand Down Expand Up @@ -50,16 +50,14 @@ void BaselineCollection::update()
for(int i = 0; i < getNodes()->count() * (getNodes()->count() - 1) / 2; i++)
{
VLBINode** nodes = (VLBINode**)malloc(sizeof(VLBINode*) * getCorrelationOrder());
char name[DSP_NAME_SIZE * getCorrelationOrder() + getCorrelationOrder()];
char name[150] = "";
for(int o = 0; o < getCorrelationOrder(); o++) {
int idx = (i + o * (i / getNodes()->count() + 1)) % getNodes()->count();
nodes[o] = getNodes()->at(idx);
if(o == 0)
sprintf(name, "%s", nodes[o]->getName());
else {
strcat(name, "*");
strcat(name, nodes[o]->getName());
}
else
sprintf(name, "%s_%s", name, nodes[o]->getName());
}
VLBIBaseline *b = new VLBIBaseline(nodes, getCorrelationOrder());
if(!this->contains(name))
Expand Down Expand Up @@ -108,6 +106,54 @@ bool BaselineCollection::contains(const char* element)
return VLBICollection::contains(element);
}

bool BaselineCollection::contains(const char** elements)
{
return get(elements) != nullptr;
}

bool BaselineCollection::contains(VLBINode** elements)
{
return get(elements) != nullptr;
}

VLBIBaseline *BaselineCollection::get(const char** elements)
{
VLBIBaseline *b = nullptr;
int x = 0;
for(x = 0; x < count(); x++) {
b = at(x);
int match = 0;
for(int y = 0; y < getCorrelationOrder(); y++) {
for(int z = 0; z < getCorrelationOrder(); z++) {
if(!strcmp(b->getNode(y)->getName(), elements[z])) match ++;
}
}
if(match < getCorrelationOrder()) continue;
break;
}
if(x == count() || b == nullptr) return nullptr;
return b;
}

VLBIBaseline *BaselineCollection::get(VLBINode **nodes)
{
VLBIBaseline *b = nullptr;
int x = 0;
for(x = 0; x < count(); x++) {
b = at(x);
int match = 0;
for(int y = 0; y < getCorrelationOrder(); y++) {
for(int z = 0; z < getCorrelationOrder(); z++) {
if(!strcmp(b->getNode(y)->getName(), nodes[z]->getName())) match ++;
}
}
if(match < getCorrelationOrder()) continue;
break;
}
if(x == count() || b == nullptr) return nullptr;
return b;
}

void BaselineCollection::setTarget(double *target)
{
memcpy(Stream->target, target, sizeof(double) * 3);
Expand Down
4 changes: 4 additions & 0 deletions vlbi/baselinecollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,14 @@ class BaselineCollection : public VLBICollection
void add(VLBIBaseline *element);
void removeAt(int index);
VLBIBaseline *get(const char* name);
VLBIBaseline *get(const char** names);
VLBIBaseline *get(VLBINode **nodes);
void remove(const char* element);
void clear();
VLBIBaseline * at(int index);
bool contains(const char *element);
bool contains(const char** elements);
bool contains(VLBINode** elements);
int indexOf(VLBIBaseline *element);
void setTarget(double *target);
void setRa(double ra);
Expand Down
28 changes: 13 additions & 15 deletions vlbi/nodecollection.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/* OpenVLBI - Open Source Very Long Baseline Interferometry
* Copyright © 2017-2023 Ilia Platone
* Copyright © 2017-2022 Ilia Platone
*
* 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 free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 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.
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

#include <cstdio>
Expand Down Expand Up @@ -74,12 +74,10 @@ bool NodeCollection::contains(const char* element)
void NodeCollection::setRelative(bool value)
{
relative = value;
if(value)
baselines->setRelative(value);
for(int x = 0; x < count(); x++)
{
for(int x = 0; x < count(); x++)
{
memcpy(at(x)->stationLocation().coordinates, station.coordinates, sizeof(dsp_location));
}
memcpy(at(x)->stationLocation().coordinates, station.coordinates, sizeof(dsp_location));
}
}

Expand Down
17 changes: 11 additions & 6 deletions vlbi_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ static int is_running = 1;
static InstanceCollection *contexts;
VLBI::Server::Server()
{
input = stdin;
output = stdout;
setInput(fdopen(0, "rb"));
setOutput(fdopen(1, "w+"));
Ra = 0;
Dec = 0;
Freq = 1420000000;
Expand All @@ -52,7 +52,7 @@ VLBI::Server::Server()
if(nullptr == tmpdir)
tmpdir = (char*)"/tmp";
context = (char*)malloc(9);
strcpy(context, "OpenVLBI\0");
memcpy(context, "OpenVLBI\0", 9);
contexts = new InstanceCollection();
}

Expand All @@ -71,6 +71,11 @@ static double coverage_delegate(double x, double y)
return 1.0;
}

static double default_delegate(double x, double y)
{
return x*y;
}

void VLBI::Server::addNode(const char *name, char *b64)
{
char filename[128];
Expand Down Expand Up @@ -154,7 +159,7 @@ void VLBI::Server::Plot(const char *name, int flags)
{
double coords[3] = { Ra, Dec, DBL_MAX };
if((flags & plot_flags_custom_delegate) == 0) {
setDelegate((flags & plot_flags_uv_coverage) != 0 ? coverage_delegate : vlbi_default_delegate);
setDelegate((flags & plot_flags_uv_coverage) != 0 ? coverage_delegate : default_delegate);
}
vlbi_get_uv_plot(getContext(), name, w, h, coords, Freq, SampleRate, (flags & plot_flags_synced) != 0,
(flags & plot_flags_moving_baseline) != 0,
Expand Down Expand Up @@ -725,8 +730,8 @@ int main(int argc, char *argv[])
#endif
int opt;
dsp_set_app_name(argv[0]);
dsp_set_stdout(stderr);
dsp_set_stderr(stderr);
dsp_set_stdout(fdopen(2, "w+"));
dsp_set_stderr(fdopen(2, "w+"));
while ((opt = getopt(argc, argv, "t:f:o:vh")) != -1)
{
switch (opt)
Expand Down
Loading

0 comments on commit 85d0a22

Please sign in to comment.