BASIS 2 Driver 0.1.0
API reference
Loading...
Searching...
No Matches
alicat_basis2_request.hpp
Go to the documentation of this file.
1
12#ifndef ALICAT_BASIS2_REQUEST_HPP
13#define ALICAT_BASIS2_REQUEST_HPP
14
15#include <array>
16#include <cstddef>
17#include <cstdint>
18#include <span>
19
21
22namespace alicat_basis2 {
23
81
83inline constexpr std::size_t kMaxRequest = 48;
84
87struct Reply {
88 std::array<char, kMaxLine + 1U> data{};
89 uint16_t length{0};
90};
91
92namespace detail {
93struct RequestBuilder;
94
96struct RequestData {
97 std::array<uint8_t, kMaxRequest> bytes{};
98 uint8_t length{0};
99 Command command{Command::Poll};
100 char id{'\0'};
101 char alt_id{'\0'};
102 bool modbus{false};
103 bool slow{false};
104 bool guarded{false};
105 bool idempotent{true};
106 uint16_t reply_chars{0};
107 uint32_t extra_ms{0};
108 uint32_t holdoff_ms{0};
109 uint8_t function{0};
110};
111} // namespace detail
112
115class Request {
116public:
118 constexpr Request() noexcept = default;
119
121 [[nodiscard]] std::span<const uint8_t> Bytes() const noexcept {
122 return std::span<const uint8_t>{d_.bytes.data(), d_.length};
123 }
125 [[nodiscard]] Command GetCommand() const noexcept {
126 return d_.command;
127 }
129 [[nodiscard]] char Id() const noexcept {
130 return d_.id;
131 }
133 [[nodiscard]] char AltId() const noexcept {
134 return d_.alt_id;
135 }
137 [[nodiscard]] bool IsModbus() const noexcept {
138 return d_.modbus;
139 }
141 [[nodiscard]] bool IsSlow() const noexcept {
142 return d_.slow;
143 }
145 [[nodiscard]] bool IsGuarded() const noexcept {
146 return d_.guarded;
147 }
149 [[nodiscard]] bool IsIdempotent() const noexcept {
150 return d_.idempotent;
151 }
153 [[nodiscard]] uint16_t ReplyChars() const noexcept {
154 return d_.reply_chars;
155 }
157 [[nodiscard]] uint32_t ExtraMs() const noexcept {
158 return d_.extra_ms;
159 }
161 [[nodiscard]] uint32_t HoldoffMs() const noexcept {
162 return d_.holdoff_ms;
163 }
165 [[nodiscard]] uint8_t Function() const noexcept {
166 return d_.function;
167 }
168
175 void SetTiming(uint32_t extra_ms, uint32_t holdoff_ms) noexcept {
176 d_.extra_ms = extra_ms;
177 d_.holdoff_ms = holdoff_ms;
178 }
179
180private:
181 friend struct detail::RequestBuilder;
182 explicit Request(const detail::RequestData& d) noexcept : d_(d) {}
183 detail::RequestData d_{};
184};
185
186namespace detail {
188struct RequestBuilder {
190 static Request Build(const RequestData& d) noexcept {
191 return Request{d};
192 }
193};
194
196[[nodiscard]] constexpr uint32_t CeilDiv(uint64_t a, uint64_t b) noexcept {
197 return static_cast<uint32_t>((a + b - 1U) / b);
198}
200[[nodiscard]] constexpr uint32_t T35Ms(uint32_t baud) noexcept {
201 const uint32_t ms = CeilDiv(35ULL * 1000ULL, baud);
202 return (ms < 1U) ? 1U : ms;
203}
205[[nodiscard]] constexpr uint32_t LineMs(uint32_t chars, uint32_t baud) noexcept {
206 return CeilDiv(static_cast<uint64_t>(chars) * 10ULL * 1000ULL, baud);
207}
210[[nodiscard]] constexpr uint32_t ModbusGapMs(uint32_t baud) noexcept {
211 return (baud <= 19200U) ? CeilDiv(385ULL * 1000ULL, 10ULL * baud) : 2U;
212}
214[[nodiscard]] constexpr uint32_t ModbusFrameMs(uint32_t bytes, uint32_t baud) noexcept {
215 return CeilDiv(static_cast<uint64_t>(bytes) * 11ULL * 1000ULL, baud);
216}
217} // namespace detail
218
221} // namespace alicat_basis2
222
223#endif // ALICAT_BASIS2_REQUEST_HPP
Public types of the ALICAT_BASIS2 driver: errors, Result<T>, configuration, enumerations and the valu...
One validated request. Only the factories of the grammar headers make one that can be sent.
Definition alicat_basis2_request.hpp:115
uint8_t Function() const noexcept
Definition alicat_basis2_request.hpp:165
uint16_t ReplyChars() const noexcept
Definition alicat_basis2_request.hpp:153
char Id() const noexcept
Definition alicat_basis2_request.hpp:129
bool IsIdempotent() const noexcept
Definition alicat_basis2_request.hpp:149
void SetTiming(uint32_t extra_ms, uint32_t holdoff_ms) noexcept
Set the durations that depend on the configuration.
Definition alicat_basis2_request.hpp:175
uint32_t ExtraMs() const noexcept
Definition alicat_basis2_request.hpp:157
uint32_t HoldoffMs() const noexcept
Definition alicat_basis2_request.hpp:161
char AltId() const noexcept
Definition alicat_basis2_request.hpp:133
constexpr Request() noexcept=default
An empty request: it has no bytes and Submit() refuses it.
std::span< const uint8_t > Bytes() const noexcept
Definition alicat_basis2_request.hpp:121
bool IsSlow() const noexcept
Definition alicat_basis2_request.hpp:141
bool IsModbus() const noexcept
Definition alicat_basis2_request.hpp:137
bool IsGuarded() const noexcept
Definition alicat_basis2_request.hpp:145
Command GetCommand() const noexcept
Definition alicat_basis2_request.hpp:125
constexpr std::size_t kMaxRequest
Longest request the driver builds, in bytes.
Definition alicat_basis2_request.hpp:83
Command
The 46 ASCII commands of M pp.10 to 17 (rows C01 to C46 of the coverage map), plus the Modbus kind.
Definition alicat_basis2_request.hpp:32
@ ReadAverages
C22 aDVAA.
@ SwitchToProtocol1
C44 aP 1 (guarded).
@ SetRamp
C07 aSR r t.
@ ReadFullScale
C35 aFPF v.
@ SetSetpointSource
C05 aLSS x.
@ ReadReferenceTemperature
C15 aRT.
@ DisableBatch
C32 aTB 0.
@ ReadSetpointSource
C04 aLSS.
@ StartMeasurement
C21 aDVAS t.
@ SetTotalizerLimit
C34 aTC m.
@ ChangeBaud
C42 aNCB b (guarded).
@ FactoryRestore
C46 aFACTORY RESTORE (guarded).
@ ReadTotalizerLimit
C33 aTC.
@ SetModbusAddress
C40 aMA n (guarded).
@ HoldValve
C11 aHPUR p.
@ Modbus
A Modbus RTU frame (function 3, 6 or 16).
@ SetReferenceTemperature
C16 aRT t.
@ SetAveraging
C18 aDCA t.
@ SetAutotare
C26 aZCA 1 or aZCA 0.
@ ChangeUnitId
C36 a@=b (guarded).
@ SetGains
C14 aLCG p i.
The ALICAT_BASIS2 driver: everything it declares lives here; internals in detail.
Definition alicat_basis2.hpp:39
A reply as received: one ASCII line without its CR, or one Modbus frame (raw bytes as chars).
Definition alicat_basis2_request.hpp:87
uint16_t length
Their number.
Definition alicat_basis2_request.hpp:89
std::array< char, kMaxLine+1U > data
The characters or bytes.
Definition alicat_basis2_request.hpp:88