-
Notifications
You must be signed in to change notification settings - Fork 0
Add modem control and configuration interfaces #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5e937c7
Add modem control and configuration interfaces
Katze719 1635249
Refactor serial interface for line settings management
Katze719 e1fbaef
Update status codes in status_codes.h to correct the position of kMon…
Katze719 b8341fa
refactor: remove serialMonitorPorts from this branch
Katze719 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| #pragma once | ||
| #include "../error_callback.h" | ||
| #include "../module_api.h" | ||
| #include <cstdint> | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" | ||
| { | ||
| #endif | ||
|
|
||
| /** | ||
| * @brief Query the current baud rate of an open serial port. | ||
| * | ||
| * Reads back the baud rate that the OS driver is currently using. Useful for | ||
| * verifying that serialOpen() or serialSetBaudrate() applied the requested | ||
| * value. | ||
| * | ||
| * @param handle Port handle obtained from serialOpen(). | ||
| * @param error_callback [optional] Callback to invoke on error. Defined in error_callback.h. Default is `nullptr`. | ||
| * @return Current baud rate in bit/s (>= 300) or a negative error code from ::cpp_core::StatusCodes. | ||
| */ | ||
| MODULE_API auto serialGetBaudrate(int64_t handle, ErrorCallbackT error_callback = nullptr) -> int; | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| #pragma once | ||
| #include "../error_callback.h" | ||
| #include "../module_api.h" | ||
| #include <cstdint> | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" | ||
| { | ||
| #endif | ||
|
|
||
| /** | ||
| * @brief Read the current state of the Clear To Send (CTS) input line. | ||
| * | ||
| * CTS is asserted by the remote device to indicate it is ready to receive | ||
| * data. Polling this line is useful when manual flow-control logic is | ||
| * required instead of (or in addition to) automatic RTS/CTS flow control. | ||
| * | ||
| * @param handle Port handle obtained from serialOpen(). | ||
| * @param error_callback [optional] Callback to invoke on error. Defined in error_callback.h. Default is `nullptr`. | ||
| * @return 1 if asserted (HIGH), 0 if de-asserted (LOW), or a negative error code from ::cpp_core::StatusCodes. | ||
| */ | ||
| MODULE_API auto serialGetCts(int64_t handle, ErrorCallbackT error_callback = nullptr) -> int; | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| #pragma once | ||
| #include "../error_callback.h" | ||
| #include "../module_api.h" | ||
| #include <cstdint> | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" | ||
| { | ||
| #endif | ||
|
|
||
| /** | ||
| * @brief Query the current number of data bits of an open serial port. | ||
| * | ||
| * @param handle Port handle obtained from serialOpen(). | ||
| * @param error_callback [optional] Callback to invoke on error. Defined in error_callback.h. Default is `nullptr`. | ||
| * @return Current data bits (5-8) or a negative error code from ::cpp_core::StatusCodes. | ||
| */ | ||
| MODULE_API auto serialGetDataBits(int64_t handle, ErrorCallbackT error_callback = nullptr) -> int; | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| #pragma once | ||
| #include "../error_callback.h" | ||
| #include "../module_api.h" | ||
| #include <cstdint> | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" | ||
| { | ||
| #endif | ||
|
|
||
| /** | ||
| * @brief Read the current state of the Data Carrier Detect (DCD) input line. | ||
| * | ||
| * DCD is asserted by a modem when a carrier signal has been detected on the | ||
| * telephone line. For direct serial links it can serve as a general-purpose | ||
| * "connection alive" indicator. | ||
| * | ||
| * @param handle Port handle obtained from serialOpen(). | ||
| * @param error_callback [optional] Callback to invoke on error. Defined in error_callback.h. Default is `nullptr`. | ||
| * @return 1 if asserted (HIGH), 0 if de-asserted (LOW), or a negative error code from ::cpp_core::StatusCodes. | ||
| */ | ||
| MODULE_API auto serialGetDcd(int64_t handle, ErrorCallbackT error_callback = nullptr) -> int; | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| #pragma once | ||
| #include "../error_callback.h" | ||
| #include "../module_api.h" | ||
| #include <cstdint> | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" | ||
| { | ||
| #endif | ||
|
|
||
| /** | ||
| * @brief Read the current state of the Data Set Ready (DSR) input line. | ||
| * | ||
| * DSR is asserted by the remote device to indicate it is powered on and | ||
| * ready to communicate. It is the counterpart to DTR. | ||
| * | ||
| * @param handle Port handle obtained from serialOpen(). | ||
| * @param error_callback [optional] Callback to invoke on error. Defined in error_callback.h. Default is `nullptr`. | ||
| * @return 1 if asserted (HIGH), 0 if de-asserted (LOW), or a negative error code from ::cpp_core::StatusCodes. | ||
| */ | ||
| MODULE_API auto serialGetDsr(int64_t handle, ErrorCallbackT error_callback = nullptr) -> int; | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| #pragma once | ||
| #include "../error_callback.h" | ||
| #include "../module_api.h" | ||
| #include <cstdint> | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" | ||
| { | ||
| #endif | ||
|
|
||
| /** | ||
| * @brief Query the current flow-control mode of an open serial port. | ||
| * | ||
| * @param handle Port handle obtained from serialOpen(). | ||
| * @param error_callback [optional] Callback to invoke on error. Defined in error_callback.h. Default is `nullptr`. | ||
| * @return 0 = none, 1 = RTS/CTS, 2 = XON/XOFF, or a negative error code from ::cpp_core::StatusCodes. | ||
| */ | ||
| MODULE_API auto serialGetFlowControl(int64_t handle, ErrorCallbackT error_callback = nullptr) -> int; | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| #pragma once | ||
| #include "../error_callback.h" | ||
| #include "../module_api.h" | ||
| #include <cstdint> | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" | ||
| { | ||
| #endif | ||
|
|
||
| /** | ||
| * @brief Query the current parity setting of an open serial port. | ||
| * | ||
| * @param handle Port handle obtained from serialOpen(). | ||
| * @param error_callback [optional] Callback to invoke on error. Defined in error_callback.h. Default is `nullptr`. | ||
| * @return 0 = none, 1 = even, 2 = odd, or a negative error code from ::cpp_core::StatusCodes. | ||
| */ | ||
| MODULE_API auto serialGetParity(int64_t handle, ErrorCallbackT error_callback = nullptr) -> int; | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| #pragma once | ||
| #include "../error_callback.h" | ||
| #include "../module_api.h" | ||
| #include <cstdint> | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" | ||
| { | ||
| #endif | ||
|
|
||
| /** | ||
| * @brief Read the current state of the Ring Indicator (RI) input line. | ||
| * | ||
| * RI is asserted by a modem to signal an incoming call. On non-modem | ||
| * hardware it can be repurposed as a general-purpose input signal. | ||
| * | ||
| * @param handle Port handle obtained from serialOpen(). | ||
| * @param error_callback [optional] Callback to invoke on error. Defined in error_callback.h. Default is `nullptr`. | ||
| * @return 1 if asserted (HIGH), 0 if de-asserted (LOW), or a negative error code from ::cpp_core::StatusCodes. | ||
| */ | ||
| MODULE_API auto serialGetRi(int64_t handle, ErrorCallbackT error_callback = nullptr) -> int; | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| #pragma once | ||
| #include "../error_callback.h" | ||
| #include "../module_api.h" | ||
| #include <cstdint> | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" | ||
| { | ||
| #endif | ||
|
|
||
| /** | ||
| * @brief Query the current stop-bit setting of an open serial port. | ||
| * | ||
| * @param handle Port handle obtained from serialOpen(). | ||
| * @param error_callback [optional] Callback to invoke on error. Defined in error_callback.h. Default is `nullptr`. | ||
| * @return 0 = 1 stop bit, 2 = 2 stop bits, or a negative error code from ::cpp_core::StatusCodes. | ||
| */ | ||
| MODULE_API auto serialGetStopBits(int64_t handle, ErrorCallbackT error_callback = nullptr) -> int; | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| #pragma once | ||
| #include "../error_callback.h" | ||
| #include "../module_api.h" | ||
| #include <cstdint> | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" | ||
| { | ||
| #endif | ||
|
|
||
| /** | ||
| * @brief Send a break condition on the serial line. | ||
| * | ||
| * A break is a sustained logic-LOW that lasts longer than a normal | ||
| * character frame. Many protocols rely on it: | ||
| * | ||
| * - **DMX512**: A break of >= 88 us marks the start of a new frame. | ||
| * - **LIN bus**: The master starts each frame with a 13-bit break. | ||
| * - **MODBUS RTU**: Some implementations use break for frame sync. | ||
| * | ||
| * The @p duration_ms parameter is a *minimum* - the actual break may be | ||
| * slightly longer due to OS scheduling. | ||
| * | ||
| * @param handle Port handle obtained from serialOpen(). | ||
| * @param duration_ms Break duration in milliseconds (> 0). | ||
| * @param error_callback [optional] Callback to invoke on error. Defined in error_callback.h. Default is `nullptr`. | ||
| * @return 0 on success or a negative error code from ::cpp_core::StatusCodes on error. | ||
| */ | ||
| MODULE_API auto serialSendBreak(int64_t handle, int duration_ms, ErrorCallbackT error_callback = nullptr) -> int; | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif |
Katze719 marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| #pragma once | ||
| #include "../error_callback.h" | ||
| #include "../module_api.h" | ||
| #include <cstdint> | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" | ||
| { | ||
| #endif | ||
|
|
||
| /** | ||
| * @brief Change the baud rate of an already-open serial port. | ||
| * | ||
| * The new rate takes effect immediately without closing and re-opening the | ||
| * port. All other line settings (data bits, parity, stop bits, flow control) | ||
| * remain unchanged. | ||
| * | ||
| * Typical use-case: a bootloader handshake starts at a safe 9600 baud and | ||
| * then both sides switch to a higher speed for the actual data transfer. | ||
| * | ||
| * @param handle Port handle obtained from serialOpen(). | ||
| * @param baudrate New baud rate in bit/s (>= 300). | ||
| * @param error_callback [optional] Callback to invoke on error. Defined in error_callback.h. Default is `nullptr`. | ||
| * @return 0 on success or a negative error code from ::cpp_core::StatusCodes on error. | ||
| */ | ||
| MODULE_API auto serialSetBaudrate(int64_t handle, int baudrate, | ||
| ErrorCallbackT error_callback = nullptr) -> int; | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| #pragma once | ||
| #include "../error_callback.h" | ||
| #include "../module_api.h" | ||
| #include <cstdint> | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" | ||
| { | ||
| #endif | ||
|
|
||
| /** | ||
| * @brief Change the number of data bits on an already-open serial port. | ||
| * | ||
| * Takes effect immediately. All other line settings remain unchanged. | ||
| * | ||
| * @param handle Port handle obtained from serialOpen(). | ||
| * @param data_bits Number of data bits (5-8). | ||
| * @param error_callback [optional] Callback to invoke on error. Defined in error_callback.h. Default is `nullptr`. | ||
| * @return 0 on success or a negative error code from ::cpp_core::StatusCodes on error. | ||
| */ | ||
| MODULE_API auto serialSetDataBits(int64_t handle, int data_bits, | ||
| ErrorCallbackT error_callback = nullptr) -> int; | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| #pragma once | ||
| #include "../error_callback.h" | ||
| #include "../module_api.h" | ||
| #include <cstdint> | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" | ||
| { | ||
| #endif | ||
|
|
||
| /** | ||
| * @brief Set or clear the Data Terminal Ready (DTR) modem control line. | ||
| * | ||
| * DTR is commonly used for: | ||
| * - Signalling readiness to the remote device. | ||
| * - Triggering a board reset on Arduino-compatible hardware. | ||
| * - Half-duplex direction control on RS-485 adapters. | ||
| * | ||
| * @param handle Port handle obtained from serialOpen(). | ||
| * @param state Non-zero to assert (HIGH), zero to de-assert (LOW). | ||
| * @param error_callback [optional] Callback to invoke on error. Defined in error_callback.h. Default is `nullptr`. | ||
| * @return 0 on success or a negative error code from ::cpp_core::StatusCodes on error. | ||
| */ | ||
| MODULE_API auto serialSetDtr(int64_t handle, int state, ErrorCallbackT error_callback = nullptr) -> int; | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| #pragma once | ||
| #include "../error_callback.h" | ||
| #include "../module_api.h" | ||
| #include <cstdint> | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" | ||
| { | ||
| #endif | ||
|
|
||
| /** | ||
| * @brief Configure the flow-control mode for an open serial port. | ||
| * | ||
| * Flow control prevents buffer overruns when one side is slower than the | ||
| * other. Three modes are supported: | ||
| * | ||
| * | @p mode | Meaning | | ||
| * |---------|-----------------------------------------------| | ||
| * | 0 | None - no flow control (default after open). | | ||
| * | 1 | Hardware (RTS/CTS) - the UART automatically | | ||
| * | | de-asserts RTS when the RX buffer is full and | | ||
| * | | pauses TX when CTS is de-asserted. | | ||
| * | 2 | Software (XON/XOFF) - in-band control chars | | ||
| * | | `0x11` (XON) and `0x13` (XOFF) are sent to | | ||
| * | | pause/resume the remote transmitter. | | ||
| * | ||
| * Changing the mode on an already-open port takes effect immediately. | ||
| * | ||
| * @param handle Port handle obtained from serialOpen(). | ||
| * @param mode Flow-control mode: 0 = none, 1 = RTS/CTS, 2 = XON/XOFF. | ||
| * @param error_callback [optional] Callback to invoke on error. Defined in error_callback.h. Default is `nullptr`. | ||
| * @return 0 on success or a negative error code from ::cpp_core::StatusCodes on error. | ||
| */ | ||
| MODULE_API auto serialSetFlowControl(int64_t handle, int mode, ErrorCallbackT error_callback = nullptr) -> int; | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.