Skip to content

Commit

Permalink
Merge branch 'develop' into LuaWebPort
Browse files Browse the repository at this point in the history
  • Loading branch information
neilstephens committed Nov 23, 2024
2 parents f5a72cc + 3fe8101 commit 5ecb8e1
Show file tree
Hide file tree
Showing 24 changed files with 272 additions and 252 deletions.
373 changes: 142 additions & 231 deletions .github/workflows/opendatacon.yml

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,12 @@ else()
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic")
if(NOT APPLE)
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--no-undefined")
#only export API symbols
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--no-undefined")

if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm" OR CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64")
link_libraries(atomic)
endif()
endif()
# tell asio to only compile once (where <asio/impl/src.hpp> is included)
# use CXX_FLAGS (instead of add_definitions) so we can use it for external libraries too
Expand Down
9 changes: 8 additions & 1 deletion Code/Libs/LuaWrappers/IOTypeWrappers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,17 +451,24 @@ std::shared_ptr<odc::EventInfo> EventInfoFromLua(lua_State* const L, const std::
if(idx < 0)
idx = lua_gettop(L) + (idx+1);

if(lua_isnil(L,idx))
return nullptr;

if(!lua_istable(L,idx))
{
if(auto log = odc::spdlog_get(LogName))
log->error("{}: EventInfo table argument not found.",Name);
log->error("{}: EventInfo argument is not a table.",Name);
return nullptr;
}

//EventType
lua_getfield(L, idx, "EventType");
if(!lua_isinteger(L,-1))
{
if(auto log = odc::spdlog_get(LogName))
log->error("{}: EventInfo has invalid EventType.",Name);
return nullptr;
}
auto et = static_cast<odc::EventType>(lua_tointeger(L,-1));
auto event = std::make_shared<odc::EventInfo>(et);

Expand Down
2 changes: 1 addition & 1 deletion Code/Ports/DNP3Port/DNP3MasterPort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ void DNP3MasterPort::Build()
StackConfig.master.timeSyncMode = pConf->pPointConf->MasterRespondTimeSync ?
(pConf->pPointConf->LANModeTimeSync ? opendnp3::TimeSyncMode::LAN : opendnp3::TimeSyncMode::NonLAN)
: opendnp3::TimeSyncMode::None;
StackConfig.master.disableUnsolOnStartup = !pConf->pPointConf->DoUnsolOnStartup;
StackConfig.master.disableUnsolOnStartup = pConf->pPointConf->DisableUnsolOnStartup;
StackConfig.master.unsolClassMask = pConf->pPointConf->GetUnsolClassMask();

//set the internal sizes of the ADPU buffers - we make it symetric by using MaxTxFragSize for both
Expand Down
10 changes: 8 additions & 2 deletions Code/Ports/DNP3Port/DNP3PointConf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ DNP3PointConf::DNP3PointConf(const std::string& FileName, const Json::Value& Con
MasterResponseTimeoutms(5000), /// Application layer response timeout
MasterRespondTimeSync(true), /// If true, the master will do time syncs when it sees the time IIN bit from the outstation
LANModeTimeSync(false), /// If true, the master will use the LAN time sync mode
DoUnsolOnStartup(true),
DisableUnsolOnStartup(true),
SetQualityOnLinkStatus(true),
FlagsToSetOnLinkStatus(odc::QualityFlags::COMM_LOST),
FlagsToClearOnLinkStatus(odc::QualityFlags::ONLINE),
Expand Down Expand Up @@ -229,7 +229,13 @@ void DNP3PointConf::ProcessElements(const Json::Value& JSONRoot)
if (JSONRoot.isMember("LANModeTimeSync"))
LANModeTimeSync = JSONRoot["LANModeTimeSync"].asBool();
if (JSONRoot.isMember("DoUnsolOnStartup"))
DoUnsolOnStartup = JSONRoot["DoUnsolOnStartup"].asBool();
{
if(auto log = odc::spdlog_get("DNP3Port"))
log->warn("DoUnsolOnStartup is deprecated because it had a non-compliant default, use DisableUnsolOnStartup=false if you really want non-compliant behaviour");
}
/// If true, the master will disable unsol on startup (warning: setting false produces non-compliant behaviour)
if (JSONRoot.isMember("DisableUnsolOnStartup"))
DisableUnsolOnStartup = JSONRoot["DisableUnsolOnStartup"].asBool();
if (JSONRoot.isMember("SetQualityOnLinkStatus"))
SetQualityOnLinkStatus = JSONRoot["SetQualityOnLinkStatus"].asBool();
if (JSONRoot.isMember("FlagsToSetOnLinkStatus"))
Expand Down
2 changes: 1 addition & 1 deletion Code/Ports/DNP3Port/DNP3PointConf.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class DNP3PointConf: public ConfigParser
uint32_t MasterResponseTimeoutms; /// Application layer response timeout
bool MasterRespondTimeSync; /// If true, the master will do time syncs when it sees the time IIN bit from the outstation
bool LANModeTimeSync; /// If true, the master will use the LAN time sync mode
bool DoUnsolOnStartup; /// If true, the master will enable unsol on startup
bool DisableUnsolOnStartup; /// If true, the master will disable unsol on startup (warning: setting false produces non-compliant behaviour)
bool SetQualityOnLinkStatus; /// Whether to set point quality when link down
odc::QualityFlags FlagsToSetOnLinkStatus; /// The flags to Set when SetQualityOnLinkStatus is true
odc::QualityFlags FlagsToClearOnLinkStatus; /// The flags to Clear when SetQualityOnLinkStatus is true
Expand Down
4 changes: 4 additions & 0 deletions Code/Ports/SimPort/SimPort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,8 @@ void SimPort::ResetPoints()

void SimPort::PortUp()
{
PublishEvent(ConnectState::PORT_UP);
PublishEvent(ConnectState::CONNECTED);
auto now = msSinceEpoch();

for(const auto& type : {odc::EventType::Analog,odc::EventType::Binary})
Expand Down Expand Up @@ -420,6 +422,8 @@ void SimPort::PortUp()
void SimPort::PortDown()
{
pSimConf->CancelTimers();
PublishEvent(ConnectState::DISCONNECTED);
PublishEvent(ConnectState::PORT_DOWN);
}

bool SimPort::TryStartEventsFromDB(const EventType type, const size_t index, const msSinceEpoch_t now, const ptimer_t ptimer)
Expand Down
2 changes: 1 addition & 1 deletion Code/submodules/dnp3
2 changes: 1 addition & 1 deletion Code/tests/DNP3Port_tests/TestDNP3EventHandling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ std::pair<std::shared_ptr<DataPort>,std::shared_ptr<DataPort>> MakePorts(const m
conf["UnsolClass1"] = true;
conf["UnsolClass2"] = true;
conf["UnsolClass3"] = true;
conf["DoUnsolOnStartup"] = true;
conf["DisableUnsolOnStartup"] = true;
conf["IntegrityScanRatems"] = Json::UInt(0);
conf["EventClass1ScanRatems"] = Json::UInt(0);
conf["EventClass2ScanRatems"] = Json::UInt(0);
Expand Down
2 changes: 1 addition & 1 deletion Code/tests/DNP3Port_tests/TestDNP3PortLinkFailure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ inline port_pair_t PortPair(module_ptr portlib, size_t os_addr, size_t ms_addr =
conf["UnsolClass1"] = true;
conf["UnsolClass2"] = true;
conf["UnsolClass3"] = true;
conf["DoUnsolOnStartup"] = true;
conf["DisableUnsolOnStartup"] = true;

//make an outstation port
auto OPUT = std::shared_ptr<DataPort>(newOutstation("Outstation"+std::to_string(os_addr), "", conf), delOutstation);
Expand Down
23 changes: 23 additions & 0 deletions DockerFiles/Debian12Bookworm
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# syntax=docker/dockerfile:1.2

ARG DOCKER_ARCH=

FROM ${DOCKER_ARCH}debian:bookworm as builder

RUN apt-get update
RUN apt-get install -y g++ make cmake git libmodbus-dev libssl-dev socat python3-dev file

RUN git clone --recurse-submodules https://github.com/neilstephens/opendatacon.git
ARG BUILD_COMMIT=develop
RUN git -C opendatacon checkout $BUILD_COMMIT

ARG BUILD_TYPE=Release
ARG CMAKE_OPTIONS=
RUN mkdir opendatacon-build
RUN cmake -DFULL=ON -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_SYSTEM_VERSION=Debian12 -S opendatacon -B opendatacon-build
RUN cmake --build opendatacon-build --parallel 8
RUN cmake --build opendatacon-build --target install
RUN cmake --build opendatacon-build --target package

FROM scratch AS export-stage
COPY --from=builder opendatacon-build/opendatacon*.sh /
42 changes: 42 additions & 0 deletions DockerFiles/OEL7
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# syntax=docker/dockerfile:1.2

FROM library/oraclelinux:7.6 as builder

RUN yum install -y oracle-softwarecollection-release-el7
RUN /usr/bin/ol_yum_configure.sh
RUN yum install -y scl-utils glibc-devel iso-codes redhat-rpm-config socat psmisc make devtoolset-8-gcc-c++ cmake3 file openssl11 openssl11-devel openssl11-static libmodbus libmodbus-devel
RUN ln -s /usr/bin/cmake3 /bin/cmake
RUN mkdir -p /opt/openssl-root
RUN ln -s /usr/include/openssl11 /opt/openssl-root/include
RUN ln -s /usr/lib64/openssl11 /opt/openssl-root/lib
# To get Python3.6 we need scl-util-build tools
RUN curl -O https://public-yum.oracle.com/repo/OracleLinux/OL7/optional/developer/x86_64/getPackage/scl-utils-build-20130529-19.el7.x86_64.rpm
RUN rpm -i scl-utils-build-20130529-19.el7.x86_64.rpm
RUN yum install -y rh-python36 rh-python36-python-devel rh-git218
RUN echo '#!/bin/bash' > $HOME/run.sh
RUN echo 'source scl_source enable devtoolset-8' >> $HOME/run.sh
RUN echo 'source scl_source enable rh-git218' >> $HOME/run.sh
RUN echo '#!/bin/bash' >> /bin/git
RUN echo "$HOME/run.sh git \"\$@\"" >> /bin/git
RUN chmod +x /bin/git
RUN echo 'exec "$@"' >> $HOME/run.sh
RUN chmod +x $HOME/run.sh

RUN git clone --recurse-submodules https://github.com/neilstephens/opendatacon.git
ARG BUILD_COMMIT=develop
RUN git -C opendatacon checkout $BUILD_COMMIT

ARG BUILD_TYPE=Release
ARG CMAKE_OPTIONS=
RUN mkdir opendatacon-build

RUN $HOME/run.sh cmake -DFULL=ON -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_SYSTEM_VERSION=oel7 \
-DPYTHON_HOME=/opt/rh/rh-python36/root/usr -DOPENSSL_ROOT_DIR=/opt/openssl-root -DADD_LIBS=z \
-S opendatacon -B opendatacon-build

RUN $HOME/run.sh cmake --build opendatacon-build --parallel 8
RUN $HOME/run.sh cmake --build opendatacon-build --target install
RUN $HOME/run.sh cmake --build opendatacon-build --target package

FROM scratch AS export-stage
COPY --from=builder opendatacon-build/opendatacon*.sh /
23 changes: 23 additions & 0 deletions DockerFiles/RaspbianBookworm
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# syntax=docker/dockerfile:1.2

FROM 2000cubits/raspbian:bookworm as builder

RUN apt-get update
RUN apt-get install -y g++ make cmake git libmodbus-dev libc6-dev openssl libssl-dev python3 python3-dev

RUN git clone --recurse-submodules https://github.com/neilstephens/opendatacon.git
ARG BUILD_COMMIT=develop
RUN git -C opendatacon checkout $BUILD_COMMIT

ARG BUILD_TYPE=Release
ARG CMAKE_OPTIONS=

RUN mkdir opendatacon-build

RUN cmake -DFULL=ON -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_SYSTEM_VERSION=RaspbianBookworm -S opendatacon -B opendatacon-build
RUN cmake --build opendatacon-build --parallel 8
RUN cmake --build opendatacon-build --target install
RUN cmake --build opendatacon-build --target package

FROM scratch AS export-stage
COPY --from=builder opendatacon-build/opendatacon*.sh /
2 changes: 1 addition & 1 deletion ExampleConfig/ConfigReload/DNP3_A.conf
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"UnsolClass1": true,
"UnsolClass2": true,
"UnsolClass3": true,
"DoUnsolOnStartup" : true,
"DisableUnsolOnStartup" : true,
"StartupIntegrityClass0" : true,
"StartupIntegrityClass1" : true,
"StartupIntegrityClass2" : true,
Expand Down
2 changes: 1 addition & 1 deletion ExampleConfig/ConfigReload/DNP3_B.conf
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"UnsolClass1": true,
"UnsolClass2": true,
"UnsolClass3": true,
"DoUnsolOnStartup" : true,
"DisableUnsolOnStartup" : true,
"StartupIntegrityClass0" : true,
"StartupIntegrityClass1" : true,
"StartupIntegrityClass2" : true,
Expand Down
2 changes: 1 addition & 1 deletion ExampleConfig/DMC/DMCDNP3_Master.conf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
//-------Master Stack conf--------#
"MasterResponseTimeoutms" : 5000,
"MasterRespondTimeSync" : true,
"DoUnsolOnStartup" : true,
"DisableUnsolOnStartup" : true,
"StartupIntegrityClass0" : true,
"StartupIntegrityClass1" : true,
"StartupIntegrityClass2" : true,
Expand Down
2 changes: 1 addition & 1 deletion ExampleConfig/DNP3-JSON/opendatacon.conf
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
"UnsolClass1": true,
"UnsolClass2": true,
"UnsolClass3": true,
"DoUnsolOnStartup" : true,
"DisableUnsolOnStartup" : true,
"StartupIntegrityClass0" : true,
"StartupIntegrityClass1" : true,
"StartupIntegrityClass2" : true,
Expand Down
2 changes: 1 addition & 1 deletion ExampleConfig/DNP3PointsEg.conf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
//-------Master Stack conf--------#
"MasterResponseTimeoutms" : 5000,
"MasterRespondTimeSync" : true,
"DoUnsolOnStartup" : true,
"DisableUnsolOnStartup" : true,
"StartupIntegrityClass0" : true,
"StartupIntegrityClass1" : true,
"StartupIntegrityClass2" : true,
Expand Down
2 changes: 1 addition & 1 deletion ExampleConfig/FileTX-DNP3-FileRX/opendatacon.conf
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"UnsolClass1": true,
"UnsolClass2": true,
"UnsolClass3": true,
"DoUnsolOnStartup" : true,
"DisableUnsolOnStartup" : true,
"StartupIntegrityClass0" : false,
"StartupIntegrityClass1" : false,
"StartupIntegrityClass2" : false,
Expand Down
2 changes: 1 addition & 1 deletion ExampleConfig/FileTransferTestEtoE/transfer.conf
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"UnsolClass1": true,
"UnsolClass2": true,
"UnsolClass3": true,
"DoUnsolOnStartup" : true,
"DisableUnsolOnStartup" : true,
"StartupIntegrityClass0" : false,
"StartupIntegrityClass1" : false,
"StartupIntegrityClass2" : false,
Expand Down
2 changes: 1 addition & 1 deletion ExampleConfig/JSON-DNP3-JSON/opendatacon.conf
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
"UnsolClass1": true,
"UnsolClass2": true,
"UnsolClass3": true,
"DoUnsolOnStartup" : true,
"DisableUnsolOnStartup" : true,
"StartupIntegrityClass0" : true,
"StartupIntegrityClass1" : true,
"StartupIntegrityClass2" : true,
Expand Down
2 changes: 1 addition & 1 deletion ExampleConfig/multiplex/DMCDNP3_Master.conf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
//-------Master Stack conf--------#
"MasterResponseTimeoutms" : 30000,
"MasterRespondTimeSync" : true,
"DoUnsolOnStartup" : true,
"DisableUnsolOnStartup" : true,
"StartupIntegrityClass0" : true,
"StartupIntegrityClass1" : true,
"StartupIntegrityClass2" : true,
Expand Down
2 changes: 1 addition & 1 deletion ExampleConfig/p2p_multidrop/DNP3_Master.conf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
//-------Master Stack conf--------#
"MasterResponseTimeoutms" : 30000,
"MasterRespondTimeSync" : true,
"DoUnsolOnStartup" : true,
"DisableUnsolOnStartup" : true,
"StartupIntegrityClass0" : true,
"StartupIntegrityClass1" : true,
"StartupIntegrityClass2" : true,
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ A DNP3 port is configured by setting the "Type" of a port to either "DNP3Master"
//-------Master Stack conf--------#
"MasterResponseTimeoutms" : 30000,
"MasterRespondTimeSync" : true,
"DoUnsolOnStartup" : true,
"DisableUnsolOnStartup" : true,
"StartupIntegrityClass0" : true,
"StartupIntegrityClass1" : true,
"StartupIntegrityClass2" : true,
Expand Down Expand Up @@ -561,7 +561,7 @@ A DNP3 port is configured by setting the "Type" of a port to either "DNP3Master"
|-----|------------|-------------|-----------|---------------|
| MasterResponseTimeoutms | number | Application layer response timeout. | No | 5000 |
| MasterRespondTimeSync | boolean | If true, the master will do time syncs when it sees the time IIN bit from the outstation. | No | true |
| DoUnsolOnStartup | boolean | If true, the master will enable unsol on startup. | No | true |
| DisableUnsolOnStartup | boolean | If true, the master will disable unsol on startup (warning: setting false produces non-compliant behaviour) | No | true |
| StartupIntegrityClass0 | boolean | If true, the master will perform a Class 0 scan on startup. | No | true |
| StartupIntegrityClass1 | boolean | If true, the master will perform a Class 1 scan on startup. | No | true |
| StartupIntegrityClass2 | boolean | If true, the master will perform a Class 2 scan on startup. | No | true |
Expand Down

0 comments on commit 5ecb8e1

Please sign in to comment.