• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

OpenLightingProject / ola / 13823257993

12 Mar 2025 11:07PM UTC coverage: 45.572% (-0.2%) from 45.742%
13823257993

Pull #1718

github

web-flow
Merge 363e59409 into e8c755cdb
Pull Request #1718: Sigrok based RDM sniffer

7823 of 18064 branches covered (43.31%)

0 of 57 new or added lines in 2 files covered. (0.0%)

22403 of 49160 relevant lines covered (45.57%)

54.24 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/libs/sniffer/BaseSnifferReader.cpp
1
/*
2
 * This program is free software; you can redistribute it and/or modify
3
 * it under the terms of the GNU General Public License as published by
4
 * the Free Software Foundation; either version 2 of the License, or
5
 * (at your option) any later version.
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU Library General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15
 *
16
 * BaseSnifferReader.cpp
17
 * Common RDM Sniffer code for logic analyzer based sniffers.
18
 * Copyright (C) 2021 Peter Newman
19
 */
20

21
#include <ola/base/Flags.h>
22
#include <ola/Callback.h>
23
#include <ola/Constants.h>
24
#include <ola/Clock.h>
25
#include <ola/io/SelectServer.h>
26
#include <ola/Logging.h>
27
#include <ola/rdm/CommandPrinter.h>
28
#include <ola/rdm/PidStoreHelper.h>
29
#include <ola/rdm/RDMCommand.h>
30
#include <ola/rdm/RDMPacket.h>
31
#include <ola/rdm/RDMResponseCodes.h>
32
#include <ola/StringUtils.h>
33

34
#include <iostream>
35
#include <memory>
36

37
#include "libs/sniffer/BaseSnifferReader.h"
38

39
using std::auto_ptr;
40
using std::cerr;
41
using std::cout;
42
using std::endl;
43
using ola::io::SelectServer;
44
using ola::rdm::CommandPrinter;
45
using ola::rdm::PidStoreHelper;
46
using ola::rdm::RDMCommand;
47
using ola::strings::ToHex;
48

49
using ola::NewSingleCallback;
50

51
DEFINE_default_bool(display_asc, false,
52
                    "Display non-RDM alternate start code frames.");
53
DEFINE_s_default_bool(full_rdm, r, false, "Unpack RDM parameter data.");
54
// TODO(Peter): Implement this!
55
// DEFINE_s_default_bool(timestamp, t, false, "Include timestamps.");
56
DEFINE_s_default_bool(display_dmx, d, false,
57
                      "Display DMX Frames. Defaults to false.");
58
DEFINE_uint16(dmx_slot_limit, ola::DMX_UNIVERSE_SIZE,
59
              "Only display the first N slots of DMX data.");
60
DEFINE_string(pid_location, "",
61
              "The directory containing the PID definitions.");
62

NEW
63
BaseSnifferReader::BaseSnifferReader(SelectServer *ss,
×
NEW
64
                                     unsigned int sample_rate)
×
NEW
65
  : m_ss(ss),
×
NEW
66
    m_signal_processor(
×
67
        ola::NewCallback(this, &BaseSnifferReader::FrameReceived),
68
        sample_rate),
NEW
69
    m_pid_helper(FLAGS_pid_location.str(), 4),
×
NEW
70
    m_command_printer(&cout, &m_pid_helper) {
×
NEW
71
  if (!m_pid_helper.Init()) {
×
NEW
72
    OLA_WARN << "Failed to init PidStore";
×
73
  }
NEW
74
}
×
75

76

NEW
77
BaseSnifferReader::~BaseSnifferReader() {
×
NEW
78
  m_ss->DrainCallbacks();
×
NEW
79
}
×
80

NEW
81
void BaseSnifferReader::FrameReceived(const uint8_t *data,
×
82
                                      unsigned int length) {
NEW
83
  if (!length) {
×
84
    return;
85
  }
86

NEW
87
  switch (data[0]) {
×
NEW
88
    case ola::DMX512_START_CODE:
×
NEW
89
      DisplayDMXFrame(data + 1, length - 1);
×
NEW
90
      break;
×
NEW
91
    case ola::rdm::START_CODE:
×
NEW
92
      DisplayRDMFrame(data + 1, length - 1);
×
NEW
93
      break;
×
NEW
94
    default:
×
NEW
95
      DisplayAlternateFrame(data, length);
×
96
  }
97
}
98

NEW
99
void BaseSnifferReader::DisplayDMXFrame(const uint8_t *data,
×
100
                                        unsigned int length) {
NEW
101
  if (!FLAGS_display_dmx) {
×
102
    return;
103
  }
104

NEW
105
  cout << "DMX " << std::dec;
×
NEW
106
  cout << length << ":" << std::hex;
×
NEW
107
  DisplayRawData(data, length);
×
108
}
109

NEW
110
void BaseSnifferReader::DisplayRDMFrame(const uint8_t *data,
×
111
                                        unsigned int length) {
NEW
112
  auto_ptr<RDMCommand> command(RDMCommand::Inflate(data, length));
×
NEW
113
  if (command.get()) {
×
NEW
114
    if (FLAGS_full_rdm) {
×
NEW
115
      cout << "---------------------------------------" << endl;
×
116
    }
NEW
117
    command->Print(&m_command_printer, !FLAGS_full_rdm, true);
×
118
  } else {
NEW
119
    cout << "RDM " << std::dec;
×
NEW
120
    cout << length << ":" << std::hex;
×
NEW
121
    DisplayRawData(data, length);
×
122
  }
NEW
123
}
×
124

125

NEW
126
void BaseSnifferReader::DisplayAlternateFrame(const uint8_t *data,
×
127
                                              unsigned int length) {
NEW
128
  if (!FLAGS_display_asc || length == 0) {
×
129
    return;
130
  }
131

NEW
132
  unsigned int slot_count = length - 1;
×
NEW
133
  cout << "SC " << ToHex(static_cast<int>(data[0]))
×
NEW
134
       << " " << slot_count << ":";
×
NEW
135
  DisplayRawData(data + 1, slot_count);
×
136
}
137

138

139
/**
140
 * Dump out the raw data if we couldn't parse it correctly.
141
 */
NEW
142
void BaseSnifferReader::DisplayRawData(const uint8_t *data,
×
143
                                       unsigned int length) {
NEW
144
  for (unsigned int i = 0; i < length; i++) {
×
NEW
145
    cout << std::hex << std::setw(2) << std::setfill('0')
×
NEW
146
         << static_cast<int>(data[i]) << " ";
×
147
  }
NEW
148
  cout << endl;
×
NEW
149
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc