Skip to content

Commit

Permalink
Merge pull request #42 from modelica/revert-36-refactor
Browse files Browse the repository at this point in the history
Revert "[WIP] Split source files"
  • Loading branch information
martinkrammer authored Dec 9, 2020
2 parents e2e858b + 92fc74e commit 402264a
Show file tree
Hide file tree
Showing 27 changed files with 6,244 additions and 6,758 deletions.
44 changes: 17 additions & 27 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.12)
cmake_minimum_required(VERSION 3.5)

# Project
project(DCPLib VERSION 0.1)
Expand All @@ -20,13 +20,11 @@ option(BUILD_ZIP "Build neccessary parts for handling slave zip files" OFF)
add_definitions(-DDEBUG)

##dcplib core
set(CORE_SRC logic/AbstractDcpManagerSlave.cpp logic/AbstractDcpManager.cpp model/pdu/DcpPduFactory.cpp model/MultiDimValue.cpp xml/DcpSlaveDescriptionElements.cpp)
list(TRANSFORM CORE_SRC PREPEND ${PROJECT_SOURCE_DIR}/include/core/dcp/)
add_library(Core STATIC ${CORE_SRC})
add_library(Core INTERFACE)
add_library(DCPLib::Core ALIAS Core)


target_include_directories(Core PUBLIC
target_include_directories(Core INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include/core>
$<INSTALL_INTERFACE:include/DCPLib/core>
)
Expand All @@ -45,18 +43,16 @@ if(BUILD_ALL OR BUILD_ETHERNET)
find_package(ASIO REQUIRED )

##dcplib ethernet
set(ETHER_SRC udp/helper/UdpHelper.cpp udp/UdpDriver.cpp)
list(TRANSFORM ETHER_SRC PREPEND ${PROJECT_SOURCE_DIR}/include/ethernet/dcp/driver/ethernet/)
add_library(Ethernet STATIC ${ETHER_SRC})
add_library(Ethernet INTERFACE)
add_library(DCPLib::Ethernet ALIAS Ethernet)

target_link_libraries(Ethernet PUBLIC Threads::Threads ASIO::ASIO)
target_link_libraries(Ethernet PUBLIC DCPLib::Core)
target_link_libraries(Ethernet INTERFACE Threads::Threads ASIO::ASIO)
target_link_libraries(Ethernet INTERFACE DCPLib::Core)
if(WIN32)
target_link_libraries(Ethernet INTERFACE wsock32 ws2_32)
endif()

target_include_directories(Ethernet PUBLIC
target_include_directories(Ethernet INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include/ethernet>
$<INSTALL_INTERFACE:include/DCPLib/ethernet>
)
Expand Down Expand Up @@ -96,17 +92,15 @@ endif(BUILD_ALL OR BUILD_BLUETOOTH)

if(BUILD_ALL OR BUILD_MASTER)
##dcplib master
set(MASTER_SRC logic/DcpManagerMaster.cpp)
list(TRANSFORM MASTER_SRC PREPEND ${PROJECT_SOURCE_DIR}/include/master/dcp/)
add_library(Master STATIC ${MASTER_SRC})
add_library(Master INTERFACE)
add_library(DCPLib::Master ALIAS Master)

target_link_libraries(Master PUBLIC DCPLib::Core)
target_link_libraries(Master INTERFACE DCPLib::Core)
if(WIN32)
target_link_libraries(Master INTERFACE wsock32 ws2_32)
endif()

target_include_directories(Master PUBLIC
target_include_directories(Master INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include/master>
$<INSTALL_INTERFACE:include/DCPLib/master>
)
Expand All @@ -123,17 +117,15 @@ endif(BUILD_ALL OR BUILD_MASTER)

if(BUILD_ALL OR BUILD_SLAVE)
##dcplib slave
set(SLAVE_SRC logic/DcpManagerSlave.cpp)
list(TRANSFORM SLAVE_SRC PREPEND ${PROJECT_SOURCE_DIR}/include/slave/dcp/)
add_library(Slave STATIC ${SLAVE_SRC})
add_library(Slave INTERFACE)
add_library(DCPLib::Slave ALIAS Slave)

target_link_libraries(Slave PUBLIC DCPLib::Core)
target_link_libraries(Slave INTERFACE DCPLib::Core)
if(WIN32)
target_link_libraries(Slave INTERFACE wsock32 ws2_32)
endif()

target_include_directories(Slave PUBLIC
target_include_directories(Slave INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include/slave>
$<INSTALL_INTERFACE:include/DCPLib/slave>
)
Expand All @@ -151,15 +143,13 @@ endif(BUILD_ALL OR BUILD_SLAVE)
if(BUILD_ALL OR BUILD_XML)
find_package(XercesC REQUIRED)

set(XML_SRC DcpSlaveDescriptionWriter.cpp DcpSlaveDescriptionReader.cpp)
list(TRANSFORM XML_SRC PREPEND ${PROJECT_SOURCE_DIR}/include/xml/dcp/xml/)
add_library(Xml STATIC ${XML_SRC})
add_library(Xml INTERFACE)
add_library(DCPLib::Xml ALIAS Xml)

target_link_libraries(Xml PUBLIC DCPLib::Core)
target_link_libraries(Xml PUBLIC XercesC::XercesC)
target_link_libraries(Xml INTERFACE DCPLib::Core)
target_link_libraries(Xml INTERFACE XercesC::XercesC)

target_include_directories(Xml PUBLIC
target_include_directories(Xml INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include/xml>
$<INSTALL_INTERFACE:include/DCPLib/xml>
)
Expand Down
4 changes: 1 addition & 3 deletions include/core/dcp/helper/LogHelper.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019, FG Simulation und Modellierung, Leibniz Universit�t Hannover, Germany
* Copyright (C) 2019, FG Simulation und Modellierung, Leibniz Universität Hannover, Germany
*
* All rights reserved.
*
Expand All @@ -26,8 +26,6 @@
#include <dcp/model/constant/DcpTransportProtocol.hpp>
#include <dcp/model/LogTemplate.hpp>

#include <iostream>

#ifdef __GNUG__ // gnu C++ compiler

#include <cxxabi.h>
Expand Down
102 changes: 0 additions & 102 deletions include/core/dcp/logic/AbstractDcpManager.cpp

This file was deleted.

94 changes: 80 additions & 14 deletions include/core/dcp/logic/AbstractDcpManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
#include <dcp/helper/LogHelper.hpp>
#endif

class LogEntry;

/**
* General interface for the AciLogic.
*
Expand All @@ -37,12 +35,23 @@ class AbstractDcpManager
~AbstractDcpManager() {}

void DAT_input_output(const uint16_t dataId, uint8_t *payload,
const uint16_t payloadSize);
const uint16_t payloadSize) {
DcpPduDatInputOutput data = {getNextDataSeqNum(dataId), dataId, payload, payloadSize};
driver.send(data);
}

void start();
void start() {
driver.setDcpManager(getDcpManager());
#if defined(DEBUG) || defined(LOGGING)
driver.setLogManager(logManager);
#endif
driver.startReceiving();
}

void stop() {
driver.stopReceiving();
}

void stop();

virtual void receive(DcpPdu &msg) = 0;

void addLogListener(std::function<void(const LogEntry &)> fct) {
Expand Down Expand Up @@ -97,27 +106,84 @@ class AbstractDcpManager
uint8_t masterId;

protected:
AbstractDcpManager();
AbstractDcpManager() {
#if defined(DEBUG) || defined(LOGGING)
setLogManager({[this](const LogTemplate &logTemplate, uint8_t *payload, size_t size) {
consume(logTemplate, payload, size);
}, [this](size_t size) { return alloc(size); }});
#endif
}

/**
* Returns the next sequence number for an given acuId
* @param acuId acuId for which the seq. id. will be returned
*/
uint16_t getNextSeqNum(const uint8_t acuId);
uint16_t getNextSeqNum(const uint8_t acuId) {
int nextSeq = segNumsOut[acuId];
segNumsOut[acuId] += 1;
return nextSeq;
}

uint16_t getNextDataSeqNum(const uint16_t data_id);
uint16_t getNextDataSeqNum(const uint16_t data_id) {
int nextSeq = dataSegNumsOut[data_id];
dataSegNumsOut[data_id] += 1;
return nextSeq;
}

uint16_t checkSeqId(const uint8_t acuId, const uint16_t seqId);
uint16_t checkSeqId(const uint8_t acuId, const uint16_t seqId) {
uint16_t old = segNumsIn[acuId];
if (seqId == (uint16_t)(old + 1)) {
segNumsIn[acuId] = seqId;
}
return seqId - old;
}

uint16_t checkSeqIdInOut(const uint16_t dataId,
const uint16_t seqId);
const uint16_t seqId) {
if (dataSegNumsIn.count(dataId)){
uint16_t old = dataSegNumsIn[dataId];
if (seqId > old) {
dataSegNumsIn[dataId] = seqId;
}
return seqId - old;
}
else {
dataSegNumsIn[dataId] = seqId;
return 1;
}
}

uint16_t checkSeqIdParam(const uint16_t parameterId,
const uint16_t seqId);
const uint16_t seqId) {
if (parameterSegNumsIn.count(parameterId)){
uint16_t old = parameterSegNumsIn[parameterId];
if (seqId > old) {
parameterSegNumsIn[parameterId] = seqId;
}
return seqId - old;
}
else {
parameterSegNumsIn[parameterId] = seqId;
return 1;
}
}

uint16_t getNextParameterSeqNum(const uint16_t parameterId);
uint16_t getNextParameterSeqNum(const uint16_t parameterId) {
int nextSeq = parameterSegNumsOut[parameterId];
parameterSegNumsOut[parameterId] += 1;
return nextSeq;
}

virtual void consume(const LogTemplate &logTemplate, uint8_t *payload, size_t size);
virtual void consume(const LogTemplate &logTemplate, uint8_t *payload, size_t size) {
LogEntry logEntry(logTemplate, payload, size);
if (generateLogString) {
logEntry.applyPayloadToString();
}
for (const std::function<void(const LogEntry &)> &logListener: logListeners) {
logListener(logEntry);
}
delete[] payload;
}

virtual uint8_t *alloc(size_t size) {
return new uint8_t[size];
Expand Down
Loading

0 comments on commit 402264a

Please sign in to comment.