fix channel num
This commit is contained in:
59
main.cpp
59
main.cpp
@ -636,6 +636,17 @@ Config parse_args(int argc, char** argv) {
|
|||||||
cfg.live_update_period_ms = std::max<uint32_t>(cfg.live_update_period_ms, 1000U);
|
cfg.live_update_period_ms = std::max<uint32_t>(cfg.live_update_period_ms, 1000U);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (cfg.tty_path && cfg.di1_group_average) {
|
||||||
|
if (!cfg.recv_block_specified) {
|
||||||
|
cfg.recv_block_words = std::max<uint32_t>(cfg.recv_block_words, 65536U);
|
||||||
|
}
|
||||||
|
if (!cfg.input_step_specified) {
|
||||||
|
cfg.input_step_words = std::max<uint32_t>(cfg.input_step_words, 65536U);
|
||||||
|
}
|
||||||
|
if (!cfg.input_buffer_specified) {
|
||||||
|
cfg.input_buffer_words = std::max<uint32_t>(cfg.input_buffer_words, 16U * 1024U * 1024U);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (cfg.recv_block_words == 0) {
|
if (cfg.recv_block_words == 0) {
|
||||||
fail("recv_block must be > 0");
|
fail("recv_block must be > 0");
|
||||||
}
|
}
|
||||||
@ -897,6 +908,8 @@ void expect_ok(const Api& api, int32_t err, const std::string& what) {
|
|||||||
constexpr uint32_t kE502DiSyn2Mask =
|
constexpr uint32_t kE502DiSyn2Mask =
|
||||||
(static_cast<uint32_t>(1U) << 13U) | (static_cast<uint32_t>(1U) << 17U);
|
(static_cast<uint32_t>(1U) << 13U) | (static_cast<uint32_t>(1U) << 17U);
|
||||||
constexpr uint32_t kE502Digital1Mask = (static_cast<uint32_t>(1U) << 0U);
|
constexpr uint32_t kE502Digital1Mask = (static_cast<uint32_t>(1U) << 0U);
|
||||||
|
constexpr uint32_t kStreamInputAdcFlag = 0x80000000U;
|
||||||
|
constexpr uint32_t kStreamInputCalibratedAdcFlag = 0x40000000U;
|
||||||
|
|
||||||
using TickMs = uint64_t;
|
using TickMs = uint64_t;
|
||||||
|
|
||||||
@ -1056,6 +1069,30 @@ int16_t pack_raw_code_to_int16(double avg_raw_code) {
|
|||||||
return static_cast<int16_t>(clamped);
|
return static_cast<int16_t>(clamped);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool try_extract_raw_adc_code(uint32_t word, double& raw_code) {
|
||||||
|
if ((word & kStreamInputAdcFlag) == 0U) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t value = 0;
|
||||||
|
if ((word & kStreamInputCalibratedAdcFlag) != 0U) {
|
||||||
|
const uint32_t payload = word & 0x00FFFFFFU;
|
||||||
|
value = static_cast<int32_t>(payload);
|
||||||
|
if ((payload & 0x00800000U) != 0U) {
|
||||||
|
value |= static_cast<int32_t>(0xFF000000U);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const uint32_t payload = word & 0x0000FFFFU;
|
||||||
|
value = static_cast<int32_t>(payload);
|
||||||
|
if ((payload & 0x00008000U) != 0U) {
|
||||||
|
value |= static_cast<int32_t>(0xFFFF0000U);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
raw_code = static_cast<double>(value);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
struct ConsoleCtrlGuard {
|
struct ConsoleCtrlGuard {
|
||||||
bool installed = false;
|
bool installed = false;
|
||||||
|
|
||||||
@ -1653,18 +1690,18 @@ int run(const Config& cfg) {
|
|||||||
|
|
||||||
uint32_t raw_adc_count = 0;
|
uint32_t raw_adc_count = 0;
|
||||||
if (tty_writer) {
|
if (tty_writer) {
|
||||||
raw_adc_count = static_cast<uint32_t>(adc_raw_buffer.size());
|
for (std::size_t i = 0; i < static_cast<std::size_t>(recvd); ++i) {
|
||||||
const int32_t raw_process_err = api.ProcessData(device.hnd,
|
double raw_code = 0.0;
|
||||||
raw.data(),
|
if (!try_extract_raw_adc_code(raw[i], raw_code)) {
|
||||||
static_cast<uint32_t>(recvd),
|
continue;
|
||||||
0,
|
}
|
||||||
adc_raw_buffer.data(),
|
if (raw_adc_count >= adc_raw_buffer.size()) {
|
||||||
&raw_adc_count,
|
fail("Raw ADC parsing overflowed the temporary buffer");
|
||||||
nullptr,
|
}
|
||||||
nullptr);
|
adc_raw_buffer[raw_adc_count++] = raw_code;
|
||||||
expect_ok(api, raw_process_err, "Process raw ADC data");
|
}
|
||||||
if (raw_adc_count != adc_count) {
|
if (raw_adc_count != adc_count) {
|
||||||
fail("Raw ADC processing returned a different sample count than voltage processing");
|
fail("Raw ADC parsing returned a different sample count than voltage processing");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!tty_di1_group_average) {
|
if (!tty_di1_group_average) {
|
||||||
|
|||||||
Reference in New Issue
Block a user