MC Protocol Serial C++ 0.2.3
MC protocol serial library for MCU-oriented environments
Loading...
Searching...
No Matches
host_sync.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <array>
4#include <cstddef>
5#include <cstdint>
6
11
17
18namespace mcprotocol::serial {
19
33 public:
34 PosixSyncClient() = default;
35
38
40 [[nodiscard]] Status open(
41 const PosixSerialConfig& serial_config,
42 const ProtocolConfig& protocol_config) noexcept;
43
45 void close() noexcept;
46
48 [[nodiscard]] bool is_open() const noexcept;
49
51 [[nodiscard]] const ProtocolConfig& protocol_config() const noexcept;
52
54 [[nodiscard]] Status read_cpu_model(CpuModelInfo& out_info) noexcept;
55
57 [[nodiscard]] Status remote_run(
59 RemoteRunClearMode clear_mode = RemoteRunClearMode::DoNotClear) noexcept;
60
62 [[nodiscard]] Status remote_stop() noexcept;
63
65 [[nodiscard]] Status remote_pause(
67
69 [[nodiscard]] Status remote_latch_clear() noexcept;
70
72 [[nodiscard]] Status unlock_remote_password(std::string_view remote_password) noexcept;
73
75 [[nodiscard]] Status lock_remote_password(std::string_view remote_password) noexcept;
76
78 [[nodiscard]] Status clear_error_information() noexcept;
79
84 [[nodiscard]] Status remote_reset() noexcept;
85
87 [[nodiscard]] Status read_user_frame(
88 const UserFrameReadRequest& request,
89 UserFrameRegistrationData& out_data) noexcept;
90
92 [[nodiscard]] Status write_user_frame(
93 const UserFrameWriteRequest& request) noexcept;
94
97 const UserFrameDeleteRequest& request) noexcept;
98
101 const GlobalSignalControlRequest& request) noexcept;
102
105
107 [[nodiscard]] Status deregister_cpu_monitoring() noexcept;
108
110 [[nodiscard]] Status read_words(
111 std::string_view head_device,
112 std::uint16_t points,
113 std::span<std::uint16_t> out_words) noexcept;
114
116 [[nodiscard]] Status read_words(
117 std::string_view head_device,
118 std::span<std::uint16_t> out_words) noexcept;
119
123 std::span<std::uint16_t> out_words) noexcept;
124
128 std::span<std::uint16_t> out_words) noexcept;
129
131 [[nodiscard]] Status read_bits(
132 std::string_view head_device,
133 std::uint16_t points,
134 std::span<BitValue> out_bits) noexcept;
135
137 [[nodiscard]] Status read_bits(
138 std::string_view head_device,
139 std::span<BitValue> out_bits) noexcept;
140
142 [[nodiscard]] Status write_words(
143 std::string_view head_device,
144 std::span<const std::uint16_t> words) noexcept;
145
148 const ExtendedFileRegisterBatchWriteWordsRequest& request) noexcept;
149
153
155 [[nodiscard]] Status write_bits(
156 std::string_view head_device,
157 std::span<const BitValue> bits) noexcept;
158
160 [[nodiscard]] Status random_read(
161 std::span<const highlevel::RandomReadSpec> items,
162 std::span<std::uint32_t> out_values) noexcept;
163
165 [[nodiscard]] Status random_read(
166 std::string_view device,
167 std::uint32_t& out_value,
168 bool double_word = false) noexcept;
169
172 std::span<const highlevel::RandomWriteWordSpec> items) noexcept;
173
176 std::span<const ExtendedFileRegisterRandomWriteWordItem> items) noexcept;
177
180 std::string_view device,
181 std::uint32_t value,
182 bool double_word = false) noexcept;
183
186 std::span<const highlevel::RandomWriteBitSpec> items) noexcept;
187
190 std::string_view device,
191 BitValue value) noexcept;
192
195 std::span<const highlevel::RandomReadSpec> items) noexcept;
196
199 std::string_view device,
200 bool double_word = false) noexcept;
201
204 const ExtendedFileRegisterMonitorRegistration& request) noexcept;
205
207 [[nodiscard]] Status read_monitor(std::span<std::uint32_t> out_values) noexcept;
208
210 [[nodiscard]] Status read_monitor(std::uint32_t& out_value) noexcept;
211
214 std::span<std::uint16_t> out_words) noexcept;
215
216 private:
217 struct CompletionState {
218 bool done = false;
219 Status status {};
220 };
221
222 static void on_request_complete(void* user, Status status) noexcept;
223 [[nodiscard]] Status run_until_complete() noexcept;
224
225 PosixSerialPort port_ {};
226 MelsecSerialClient client_ {};
227 ProtocolConfig protocol_config_ {};
229 CompletionState completion_ {};
230};
231
232} // namespace mcprotocol::serial
Minimal blocking host-side serial-port wrapper used by the CLI tools.
Host-side synchronous convenience wrapper built on PosixSerialPort and MelsecSerialClient.
Definition host_sync.hpp:32
Status register_extended_file_register_monitor(const ExtendedFileRegisterMonitorRegistration &request) noexcept
Registers extended file-register monitor data synchronously.
Status direct_read_extended_file_register_words(const ExtendedFileRegisterDirectBatchReadWordsRequest &request, std::span< std::uint16_t > out_words) noexcept
Reads direct extended file-register words synchronously.
const ProtocolConfig & protocol_config() const noexcept
Returns the currently configured protocol settings.
Status read_cpu_model(CpuModelInfo &out_info) noexcept
Reads the remote CPU model synchronously.
Status initialize_c24_transmission_sequence() noexcept
Initializes C24 format-5 transmission sequence synchronously (1615).
Status register_monitor(std::span< const highlevel::RandomReadSpec > items) noexcept
Registers a sparse monitor synchronously from string-address specs.
PosixSyncClient & operator=(const PosixSyncClient &)=delete
Status random_write_bits(std::span< const highlevel::RandomWriteBitSpec > items) noexcept
Writes sparse bit items synchronously from string-address specs.
Status read_monitor(std::span< std::uint32_t > out_values) noexcept
Reads the most recently registered monitor items synchronously.
Status random_read(std::span< const highlevel::RandomReadSpec > items, std::span< std::uint32_t > out_values) noexcept
Reads sparse word/dword items synchronously from string-address specs.
Status remote_stop() noexcept
Issues remote STOP (1002) synchronously.
Status control_global_signal(const GlobalSignalControlRequest &request) noexcept
Controls C24 global signal ON/OFF synchronously (1618).
Status write_bits(std::string_view head_device, std::span< const BitValue > bits) noexcept
Writes contiguous bits synchronously to a string address such as M100.
Status random_write_words(std::span< const highlevel::RandomWriteWordSpec > items) noexcept
Writes sparse word/dword items synchronously from string-address specs.
Status random_write_word(std::string_view device, std::uint32_t value, bool double_word=false) noexcept
Writes one sparse word/dword item synchronously from a string address.
Status write_words(std::string_view head_device, std::span< const std::uint16_t > words) noexcept
Writes contiguous words synchronously to a string address such as D100.
Status write_user_frame(const UserFrameWriteRequest &request) noexcept
Writes user-frame registration data synchronously (1610, subcommand 0000).
Status write_extended_file_register_words(const ExtendedFileRegisterBatchWriteWordsRequest &request) noexcept
Writes extended file-register words synchronously.
PosixSyncClient(const PosixSyncClient &)=delete
Status direct_write_extended_file_register_words(const ExtendedFileRegisterDirectBatchWriteWordsRequest &request) noexcept
Writes direct extended file-register words synchronously.
bool is_open() const noexcept
Returns whether the underlying serial port is open.
Status read_extended_file_register_words(const ExtendedFileRegisterBatchReadWordsRequest &request, std::span< std::uint16_t > out_words) noexcept
Reads extended file-register words synchronously.
Status delete_user_frame(const UserFrameDeleteRequest &request) noexcept
Deletes user-frame registration data synchronously (1610, subcommand 0001).
Status unlock_remote_password(std::string_view remote_password) noexcept
Unlocks remote-password-protected access (1630) synchronously.
Status remote_pause(RemoteOperationMode mode=RemoteOperationMode::DoNotExecuteForcibly) noexcept
Issues remote PAUSE (1003) synchronously.
Status random_write_extended_file_register_words(std::span< const ExtendedFileRegisterRandomWriteWordItem > items) noexcept
Writes extended file-register words randomly.
Status remote_run(RemoteOperationMode mode=RemoteOperationMode::DoNotExecuteForcibly, RemoteRunClearMode clear_mode=RemoteRunClearMode::DoNotClear) noexcept
Issues remote RUN (1001) synchronously.
void close() noexcept
Closes the serial port and clears any in-flight request state.
Status remote_reset() noexcept
Issues remote RESET (1006) synchronously.
Status open(const PosixSerialConfig &serial_config, const ProtocolConfig &protocol_config) noexcept
Opens the serial port and configures the underlying MC protocol client.
Status read_user_frame(const UserFrameReadRequest &request, UserFrameRegistrationData &out_data) noexcept
Reads user-frame registration data synchronously (0610).
Status clear_error_information() noexcept
Clears serial/C24 error information (1617) synchronously.
Status random_write_bit(std::string_view device, BitValue value) noexcept
Writes one sparse bit item synchronously from a string address.
Status remote_latch_clear() noexcept
Issues remote latch clear (1005) synchronously.
Status read_bits(std::string_view head_device, std::uint16_t points, std::span< BitValue > out_bits) noexcept
Reads contiguous bits synchronously from a string address such as M100.
Status read_extended_file_register_monitor(std::span< std::uint16_t > out_words) noexcept
Reads the most recently registered extended file-register monitor items synchronously.
Status read_words(std::string_view head_device, std::uint16_t points, std::span< std::uint16_t > out_words) noexcept
Reads contiguous words synchronously from a string address such as D100.
Status deregister_cpu_monitoring() noexcept
Deregisters programmable-controller CPU monitoring synchronously (0631).
Status lock_remote_password(std::string_view remote_password) noexcept
Locks remote-password-protected access (1631) synchronously.
Asynchronous request-execution state machine for serial MC protocol traffic.
Optional string-address helpers and protocol presets for common library entry paths.
RemoteOperationMode
Conflict-handling mode for remote RUN / PAUSE.
Definition types.hpp:249
BitValue
Logical single-bit value used by bit read/write APIs.
Definition types.hpp:243
RemoteRunClearMode
Clear scope applied during remote RUN initialization.
Definition types.hpp:255
Extended file-register batch write (EW on 1C ACPU-common, chapter-18 block path on 1E).
Definition types.hpp:420
Direct extended file-register batch read (NR on 1C QnA-common, chapter-18 direct path on 1E).
Definition types.hpp:412
Direct extended file-register batch write (NW on 1C QnA-common, chapter-18 direct path on 1E).
Definition types.hpp:428
Extended file-register monitor registration (EM on 1C, chapter-18 on 1E).
Definition types.hpp:444
One item inside extended file-register random write (ET on 1C, chapter-18 on 1E).
Definition types.hpp:436
C24 global-signal ON/OFF request (1618).
Definition types.hpp:579
Host-side serial-port configuration used by PosixSerialPort.
Top-level protocol configuration shared by codecs and client requests.
Definition types.hpp:323
Result object returned by most public APIs.
Definition status.hpp:26
User-frame registration-data delete request (1610, subcommand 0001).
Definition types.hpp:573
User-frame registration-data payload returned by 0610.
Definition types.hpp:553
User-frame registration-data write request (1610, subcommand 0000).
Definition types.hpp:563