Skip to content

Commit

Permalink
Merge pull request KITmedical#7 from KITmedical/issue5
Browse files Browse the repository at this point in the history
Fixing issue KITmedical#5
  • Loading branch information
thk1 committed Mar 3, 2018
2 parents 5e628d0 + fa50e0d commit befa914
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 3 additions & 1 deletion master/include/transmit_pdo_mapping.h
Expand Up @@ -90,7 +90,9 @@ namespace kaco {

/// The transmitter thread
/// \note This is a unique pointer because transmitter is optional.
std::unique_ptr<std::thread> transmitter;
std::unique_ptr<std::thread> periodic_transmitter{nullptr};

bool run_periodic_transmitter{false};

/// Sends the PDO
void send() const;
Expand Down
5 changes: 3 additions & 2 deletions master/src/device.cpp
Expand Up @@ -233,9 +233,10 @@ void Device::add_transmit_pdo_mapping(uint16_t cob_id, const std::vector<Mapping
WARN("[Device::add_transmit_pdo_mapping] Repeat time is 0. This could overload the bus.");
}

pdo.transmitter = std::unique_ptr<std::thread>(new std::thread([&pdo, repeat_time](){
pdo.run_periodic_transmitter = true;
pdo.periodic_transmitter = std::unique_ptr<std::thread>(new std::thread([&pdo, repeat_time](){

while (true) {
while (pdo.run_periodic_transmitter) {
DEBUG_LOG("[Timer thread] Sending periodic PDO.");
pdo.send();
std::this_thread::sleep_for(repeat_time);
Expand Down
5 changes: 3 additions & 2 deletions master/src/transmit_pdo_mapping.cpp
Expand Up @@ -53,8 +53,9 @@ TransmitPDOMapping::TransmitPDOMapping(Core& core, const std::unordered_map<Addr
}

TransmitPDOMapping::~TransmitPDOMapping() {
if (transmitter) {
transmitter->detach();
if (periodic_transmitter) {
run_periodic_transmitter = false;
periodic_transmitter->join();
}
}

Expand Down

0 comments on commit befa914

Please sign in to comment.