From 6abcbd28e1e231e0bbdd85cc08808512521297bd Mon Sep 17 00:00:00 2001 From: Bryan Biedenkapp Date: Sun, 15 Nov 2026 11:38:46 -0500 Subject: [PATCH] remove dependancy on std::thread for callsim, this causes problems with some dev environments; add support for steering the WACN and SysId; --- tools/callsim/CallSimMain.cpp | 151 +++++++++++++++++++++++++++++++--- tools/callsim/README.md | 6 +- 2 files changed, 146 insertions(+), 11 deletions(-) diff --git a/tools/callsim/CallSimMain.cpp b/tools/callsim/CallSimMain.cpp index 2f38ddb1..28f10aab 100644 --- a/tools/callsim/CallSimMain.cpp +++ b/tools/callsim/CallSimMain.cpp @@ -54,8 +54,8 @@ using namespace network; #include #include #include +#include #include -#include #include // --------------------------------------------------------------------------- @@ -125,6 +125,8 @@ struct Options { uint32_t durationSeconds = DEFAULT_CALL_DURATION_SECONDS; //!< Duration of each call in seconds. uint32_t gapMs = DEFAULT_CALL_GAP_MS; //!< Delay between completed calls in milliseconds. uint32_t srcId = 100001U; //!< Source ID used by the first call; incremented per call. + uint32_t p25WACN = P25DEF::WACN_STD_DEFAULT; //!< P25 WACN encoded in generated calls. + uint32_t p25SysId = P25DEF::SID_STD_DEFAULT; //!< P25 system ID encoded in generated calls. std::vector talkgroups; //!< Destination IDs selected round-robin by call index. std::vector slots; //!< DMR slots selected round-robin by call index. @@ -192,6 +194,8 @@ static void usage(const char* message, const char* arg) " --source First source radio ID (default 100001)\n" " --talkgroups Comma-separated destination IDs\n" " --slots DMR slots, one per TG or cycled (default 1)\n" + " --wacn P25 WACN (default BB800)\n" + " --sys-id P25 system ID (default 001)\n" " --grant-demand Send an FNE grant request before each call\n" " --simultaneous Emit all configured TGs concurrently per repetition\n" " --debug Enable network debug logging\n" @@ -222,6 +226,29 @@ static bool parseUnsigned(const char* text, uint32_t minimum, uint32_t maximum, return true; } +/** + * @brief Parses and range-checks an unsigned hexadecimal command-line value. + * @param text The string containing the hexadecimal value to parse. + * @param minimum The minimum allowed value. + * @param maximum The maximum allowed value. + * @param value The variable to store the parsed value. + * @return true if the value was successfully parsed and within range, false otherwise. + */ +static bool parseHexUnsigned(const char* text, uint32_t minimum, uint32_t maximum, uint32_t& value) +{ + if (text == nullptr || text[0U] == '\0') + return false; + + errno = 0; + char* end = nullptr; + unsigned long parsed = ::strtoul(text, &end, 16); + if (errno != 0 || end == text || *end != '\0' || parsed < minimum || parsed > maximum) + return false; + + value = static_cast(parsed); + return true; +} + /** * @brief Parses a comma-separated list of range-checked unsigned decimal values. * @param text The comma-separated list of values as a string. @@ -364,6 +391,22 @@ static bool parseOptions(int argc, char** argv, Options& options) usage("error: %s", "invalid --source"); return false; } + } else if (arg == "--wacn") { + value = requireValue("--wacn"); + if (value == nullptr || !parseHexUnsigned(value, 1U, 0xFFFFEU, options.p25WACN)) { + usage("error: %s", "invalid --wacn"); + return false; + } + if (options.p25WACN >= 0xBEE00U && options.p25WACN <= 0xBEEFFU) { + usage("error: %s", "--wacn must not be in the reserved BEE00-BEEFF range"); + return false; + } + } else if (arg == "--sys-id") { + value = requireValue("--sys-id"); + if (value == nullptr || !parseHexUnsigned(value, 1U, 0xFFEU, options.p25SysId)) { + usage("error: %s", "invalid --sys-id"); + return false; + } } else { usage("error: %s", (std::string("unknown option: ") + arg).c_str()); return false; @@ -480,16 +523,21 @@ static void fillP25Tone(uint8_t* data) * @param srcId The source ID of the call. * @param dstId The destination ID of the call. * @param durationMs The duration of the call in milliseconds. + * @param wacn The P25 wide area communications network ID. + * @param sysId The P25 system ID. * @param stream The call stream state. * @return true if the frames were successfully emitted, false otherwise. */ -static bool emitP25(CallSimNetwork& network, uint32_t srcId, uint32_t dstId, uint32_t durationMs, CallStreamState& stream) +static bool emitP25(CallSimNetwork& network, uint32_t srcId, uint32_t dstId, uint32_t durationMs, + uint32_t wacn, uint32_t sysId, CallStreamState& stream) { p25::lc::LC control; control.setLCO(P25DEF::LCO::GROUP); control.setGroup(true); control.setSrcId(srcId); control.setDstId(dstId); + control.setNetId(wacn); + control.setSysId(sysId); control.setPriority(4U); p25::data::LowSpeedData lsd; @@ -704,7 +752,7 @@ static bool emitCall(CallSimNetwork& network, const Options& options, uint32_t c bool success = false; switch (options.mode) { case Mode::P25: - success = emitP25(network, srcId, dstId, durationMs, stream); + success = emitP25(network, srcId, dstId, durationMs, options.p25WACN, options.p25SysId, stream); break; case Mode::DMR: success = emitDMR(network, srcId, dstId, slot, durationMs, stream); @@ -723,6 +771,83 @@ static bool emitCall(CallSimNetwork& network, const Options& options, uint32_t c return true; } +// --------------------------------------------------------------------------- +// Class Declaration +// --------------------------------------------------------------------------- + +/** + * @brief Runs one simulated call through the project's thread abstraction. + * @ingroup callsim + */ +class CallWorker : public Thread { +public: + /** + * @brief Initializes a worker for one simulated call. + * @param[in] network Network connection shared by the simulated calls. + * @param[in] options Simulator options shared by the workers. + * @param callNumber One-based call number. + * @param totalCalls Total calls scheduled for this simulator run. + * @param srcId Source subscriber ID. + * @param dstId Destination talkgroup ID. + * @param slot DMR slot, or ignored for FDMA protocols. + * @param durationMs Call duration in milliseconds. + * @param[out] result Receives one when the call succeeds, or zero on failure. + * @param[in,out] remaining Number of running workers. + */ + CallWorker(CallSimNetwork& network, const Options& options, uint32_t callNumber, uint32_t totalCalls, + uint32_t srcId, uint32_t dstId, uint8_t slot, uint32_t durationMs, uint8_t& result, + std::atomic& remaining); + + /** + * @brief Emits the configured call and records its result. + */ + void entry() override; + +private: + CallSimNetwork& m_network; //!< Network connection shared by the simulated calls. + const Options& m_options; //!< Simulator options shared by the workers. + uint32_t m_callNumber; //!< One-based call number. + uint32_t m_totalCalls; //!< Total calls scheduled for this simulator run. + uint32_t m_srcId; //!< Source subscriber ID. + uint32_t m_dstId; //!< Destination talkgroup ID. + uint8_t m_slot; //!< DMR slot, or ignored for FDMA protocols. + uint32_t m_durationMs; //!< Call duration in milliseconds. + uint8_t& m_result; //!< Result storage owned by the scheduler. + std::atomic& m_remaining; //!< Number of running workers. +}; + +// --------------------------------------------------------------------------- +// Public Class Members +// --------------------------------------------------------------------------- + +/* Initializes a worker for one simulated call. */ + +CallWorker::CallWorker(CallSimNetwork& network, const Options& options, uint32_t callNumber, uint32_t totalCalls, + uint32_t srcId, uint32_t dstId, uint8_t slot, uint32_t durationMs, uint8_t& result, + std::atomic& remaining) : + m_network(network), + m_options(options), + m_callNumber(callNumber), + m_totalCalls(totalCalls), + m_srcId(srcId), + m_dstId(dstId), + m_slot(slot), + m_durationMs(durationMs), + m_result(result), + m_remaining(remaining) +{ + /* stub */ +} + +/* Emits the configured call and records its result. */ + +void CallWorker::entry() +{ + m_result = emitCall(m_network, m_options, m_callNumber, m_totalCalls, m_srcId, m_dstId, m_slot, + m_durationMs) ? 1U : 0U; + m_remaining--; +} + // --------------------------------------------------------------------------- // Program Entry Point // --------------------------------------------------------------------------- @@ -747,6 +872,8 @@ int main(int argc, char** argv) CallSimNetwork network(options.address, options.port, 0U, options.peerId, options.password, true, options.debug, true, true, true, false, true, true, false, false, false, false); + p25::lc::LC::setSiteData(p25::SiteData(options.p25WACN, options.p25SysId, 1U, 1U, 0U, 1U, 1U, + P25DEF::ServiceClass::VOICE | P25DEF::ServiceClass::DATA, 0)); network.setMetadata(options.identity, 0U, 0U, 0.0F, 0.0F, 0U, 0U, 0U, 0.0F, 0.0F, 0, ""); network.enable(true); if (!network.open()) { @@ -779,9 +906,9 @@ int main(int argc, char** argv) // iterate over the number of call repetitions, spawning and managing worker threads for each call for (uint32_t repetition = 0U; repetition < options.callCount && !g_stop; repetition++) { - std::atomic remaining(callsPerRepetition); + std::atomic remaining(0U); std::vector results(callsPerRepetition, 0U); - std::vector workers; + std::vector> workers; workers.reserve(callsPerRepetition); // spawn worker threads for each call in the current repetition @@ -792,10 +919,14 @@ int main(int argc, char** argv) const uint8_t slot = options.slots[scheduleIndex % options.slots.size()]; const uint32_t srcId = options.srcId + callIndex; - workers.emplace_back([&, member, callIndex, srcId, dstId, slot]() { - results[member] = emitCall(network, options, callIndex + 1U, totalCalls, srcId, dstId, slot, durationMs) ? 1U : 0U; + workers.push_back(std::make_unique(network, options, callIndex + 1U, totalCalls, + srcId, dstId, slot, durationMs, results[member], remaining)); + remaining++; + if (!workers.back()->run()) { remaining--; - }); + break; + } + workers.back()->setName("callsim-worker"); } auto lastClock = std::chrono::steady_clock::now(); @@ -811,8 +942,8 @@ int main(int argc, char** argv) } // join all worker threads for the current repetition before proceeding - for (std::thread& worker : workers) - worker.join(); + for (const std::unique_ptr& worker : workers) + worker->wait(); // determine if all calls in the current repetition were successful success = std::find(results.begin(), results.end(), 0U) == results.end(); diff --git a/tools/callsim/README.md b/tools/callsim/README.md index d91c55b8..d7113c4b 100644 --- a/tools/callsim/README.md +++ b/tools/callsim/README.md @@ -59,6 +59,8 @@ by one for every generated call. | `--gap ` | Delay between calls or batches in milliseconds. The default is `500`. | | `--source ` | Source radio ID for the first call. The default is `100001`. | | `--slots ` | Comma-separated DMR slots (`1` or `2`), cycled as needed. The default is slot `1`. | +| `--wacn ` | P25 WACN in hexadecimal. The default is `BB800`. | +| `--sys-id ` | P25 system ID in hexadecimal. The default is `001`. | | `--grant-demand` | Sends an FNE group-call grant request before every call. | | `--simultaneous` | Starts one call per configured talkgroup in each batch. | | `--debug` | Enables verbose network logging. | @@ -66,7 +68,9 @@ by one for every generated call. P25 and DMR source and destination IDs may be up to 24 bits. NXDN source and destination IDs must not exceed `65535`. The `--slots` setting is used only for -DMR; P25 and NXDN are FDMA modes. +DMR; P25 and NXDN are FDMA modes. P25 WACN values range from `00001` through +`FFFFE`, excluding the reserved `BEE00` through `BEEFF` range. P25 system IDs +range from `001` through `FFE`. ## Multiple talkgroups