mirror of
https://github.com/wjwwood/serial.git
synced 2026-01-22 19:54:57 +08:00
[style] white space clean up
This commit is contained in:
parent
d06b2f94dd
commit
32b3631285
@ -10,7 +10,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright (c) 2012 William Woodall, John Harrison
|
* Copyright (c) 2012 William Woodall, John Harrison
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
* copy of this software and associated documentation files (the "Software"),
|
* copy of this software and associated documentation files (the "Software"),
|
||||||
* to deal in the Software without restriction, including without limitation
|
* to deal in the Software without restriction, including without limitation
|
||||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||||
@ -24,8 +24,8 @@
|
|||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
* DEALINGS IN THE SOFTWARE.
|
* DEALINGS IN THE SOFTWARE.
|
||||||
*
|
*
|
||||||
* \section DESCRIPTION
|
* \section DESCRIPTION
|
||||||
|
|||||||
@ -88,9 +88,9 @@ typedef enum {
|
|||||||
} flowcontrol_t;
|
} flowcontrol_t;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Structure for setting the timeout of the serial port, times are
|
* Structure for setting the timeout of the serial port, times are
|
||||||
* in milliseconds.
|
* in milliseconds.
|
||||||
*
|
*
|
||||||
* In order to disable the interbyte timeout, set it to Timeout::max().
|
* In order to disable the interbyte timeout, set it to Timeout::max().
|
||||||
*/
|
*/
|
||||||
struct Timeout {
|
struct Timeout {
|
||||||
@ -102,7 +102,7 @@ struct Timeout {
|
|||||||
* Convenience function to generate Timeout structs using a
|
* Convenience function to generate Timeout structs using a
|
||||||
* single absolute timeout.
|
* single absolute timeout.
|
||||||
*
|
*
|
||||||
* \param timeout A long that defines the time in milliseconds until a
|
* \param timeout A long that defines the time in milliseconds until a
|
||||||
* timeout occurs after a call to read or write is made.
|
* timeout occurs after a call to read or write is made.
|
||||||
*
|
*
|
||||||
* \return Timeout struct that represents this simple timeout provided.
|
* \return Timeout struct that represents this simple timeout provided.
|
||||||
@ -115,13 +115,13 @@ struct Timeout {
|
|||||||
uint32_t inter_byte_timeout;
|
uint32_t inter_byte_timeout;
|
||||||
/*! A constant number of milliseconds to wait after calling read. */
|
/*! A constant number of milliseconds to wait after calling read. */
|
||||||
uint32_t read_timeout_constant;
|
uint32_t read_timeout_constant;
|
||||||
/*! A multiplier against the number of requested bytes to wait after
|
/*! A multiplier against the number of requested bytes to wait after
|
||||||
* calling read.
|
* calling read.
|
||||||
*/
|
*/
|
||||||
uint32_t read_timeout_multiplier;
|
uint32_t read_timeout_multiplier;
|
||||||
/*! A constant number of milliseconds to wait after calling write. */
|
/*! A constant number of milliseconds to wait after calling write. */
|
||||||
uint32_t write_timeout_constant;
|
uint32_t write_timeout_constant;
|
||||||
/*! A multiplier against the number of requested bytes to wait after
|
/*! A multiplier against the number of requested bytes to wait after
|
||||||
* calling write.
|
* calling write.
|
||||||
*/
|
*/
|
||||||
uint32_t write_timeout_multiplier;
|
uint32_t write_timeout_multiplier;
|
||||||
@ -145,7 +145,7 @@ struct Timeout {
|
|||||||
class Serial {
|
class Serial {
|
||||||
public:
|
public:
|
||||||
/*!
|
/*!
|
||||||
* Creates a Serial object and opens the port if a port is specified,
|
* Creates a Serial object and opens the port if a port is specified,
|
||||||
* otherwise it remains closed until serial::Serial::open is called.
|
* otherwise it remains closed until serial::Serial::open is called.
|
||||||
*
|
*
|
||||||
* \param port A std::string containing the address of the serial port,
|
* \param port A std::string containing the address of the serial port,
|
||||||
@ -154,7 +154,7 @@ public:
|
|||||||
*
|
*
|
||||||
* \param baudrate An unsigned 32-bit integer that represents the baudrate
|
* \param baudrate An unsigned 32-bit integer that represents the baudrate
|
||||||
*
|
*
|
||||||
* \param timeout A serial::Timeout struct that defines the timeout
|
* \param timeout A serial::Timeout struct that defines the timeout
|
||||||
* conditions for the serial port. \see serial::Timeout
|
* conditions for the serial port. \see serial::Timeout
|
||||||
*
|
*
|
||||||
* \param bytesize Size of each byte in the serial transmission of data,
|
* \param bytesize Size of each byte in the serial transmission of data,
|
||||||
@ -221,55 +221,55 @@ public:
|
|||||||
*
|
*
|
||||||
* The read function will return in one of three cases:
|
* The read function will return in one of three cases:
|
||||||
* * The number of requested bytes was read.
|
* * The number of requested bytes was read.
|
||||||
* * In this case the number of bytes requested will match the size_t
|
* * In this case the number of bytes requested will match the size_t
|
||||||
* returned by read.
|
* returned by read.
|
||||||
* * A timeout occurred, in this case the number of bytes read will not
|
* * A timeout occurred, in this case the number of bytes read will not
|
||||||
* match the amount requested, but no exception will be thrown. One of
|
* match the amount requested, but no exception will be thrown. One of
|
||||||
* two possible timeouts occurred:
|
* two possible timeouts occurred:
|
||||||
* * The inter byte timeout expired, this means that number of
|
* * The inter byte timeout expired, this means that number of
|
||||||
* milliseconds elapsed between receiving bytes from the serial port
|
* milliseconds elapsed between receiving bytes from the serial port
|
||||||
* exceeded the inter byte timeout.
|
* exceeded the inter byte timeout.
|
||||||
* * The total timeout expired, which is calculated by multiplying the
|
* * The total timeout expired, which is calculated by multiplying the
|
||||||
* read timeout multiplier by the number of requested bytes and then
|
* read timeout multiplier by the number of requested bytes and then
|
||||||
* added to the read timeout constant. If that total number of
|
* added to the read timeout constant. If that total number of
|
||||||
* milliseconds elapses after the initial call to read a timeout will
|
* milliseconds elapses after the initial call to read a timeout will
|
||||||
* occur.
|
* occur.
|
||||||
* * An exception occurred, in this case an actual exception will be thrown.
|
* * An exception occurred, in this case an actual exception will be thrown.
|
||||||
*
|
*
|
||||||
* \param buffer An uint8_t array of at least the requested size.
|
* \param buffer An uint8_t array of at least the requested size.
|
||||||
* \param size A size_t defining how many bytes to be read.
|
* \param size A size_t defining how many bytes to be read.
|
||||||
*
|
*
|
||||||
* \return A size_t representing the number of bytes read as a result of the
|
* \return A size_t representing the number of bytes read as a result of the
|
||||||
* call to read.
|
* call to read.
|
||||||
*/
|
*/
|
||||||
size_t
|
size_t
|
||||||
read (uint8_t *buffer, size_t size);
|
read (uint8_t *buffer, size_t size);
|
||||||
|
|
||||||
/*! Read a given amount of bytes from the serial port into a give buffer.
|
/*! Read a given amount of bytes from the serial port into a give buffer.
|
||||||
*
|
*
|
||||||
* \param buffer A reference to a std::vector of uint8_t.
|
* \param buffer A reference to a std::vector of uint8_t.
|
||||||
* \param size A size_t defining how many bytes to be read.
|
* \param size A size_t defining how many bytes to be read.
|
||||||
*
|
*
|
||||||
* \return A size_t representing the number of bytes read as a result of the
|
* \return A size_t representing the number of bytes read as a result of the
|
||||||
* call to read.
|
* call to read.
|
||||||
*/
|
*/
|
||||||
size_t
|
size_t
|
||||||
read (std::vector<uint8_t> &buffer, size_t size = 1);
|
read (std::vector<uint8_t> &buffer, size_t size = 1);
|
||||||
|
|
||||||
/*! Read a given amount of bytes from the serial port into a give buffer.
|
/*! Read a given amount of bytes from the serial port into a give buffer.
|
||||||
*
|
*
|
||||||
* \param buffer A reference to a std::string.
|
* \param buffer A reference to a std::string.
|
||||||
* \param size A size_t defining how many bytes to be read.
|
* \param size A size_t defining how many bytes to be read.
|
||||||
*
|
*
|
||||||
* \return A size_t representing the number of bytes read as a result of the
|
* \return A size_t representing the number of bytes read as a result of the
|
||||||
* call to read.
|
* call to read.
|
||||||
*/
|
*/
|
||||||
size_t
|
size_t
|
||||||
read (std::string &buffer, size_t size = 1);
|
read (std::string &buffer, size_t size = 1);
|
||||||
|
|
||||||
/*! Read a given amount of bytes from the serial port and return a string
|
/*! Read a given amount of bytes from the serial port and return a string
|
||||||
* containing the data.
|
* containing the data.
|
||||||
*
|
*
|
||||||
* \param size A size_t defining how many bytes to be read.
|
* \param size A size_t defining how many bytes to be read.
|
||||||
*
|
*
|
||||||
* \return A std::string containing the data read from the port.
|
* \return A std::string containing the data read from the port.
|
||||||
@ -308,7 +308,7 @@ public:
|
|||||||
* timeout occurs and return a list of strings.
|
* timeout occurs and return a list of strings.
|
||||||
*
|
*
|
||||||
* \param size A maximum length of combined lines, defaults to 65536 (2^16)
|
* \param size A maximum length of combined lines, defaults to 65536 (2^16)
|
||||||
*
|
*
|
||||||
* \param eol A string to match against for the EOL.
|
* \param eol A string to match against for the EOL.
|
||||||
*
|
*
|
||||||
* \return A vector<string> containing the lines.
|
* \return A vector<string> containing the lines.
|
||||||
@ -321,7 +321,7 @@ public:
|
|||||||
* \param data A const reference containing the data to be written
|
* \param data A const reference containing the data to be written
|
||||||
* to the serial port.
|
* to the serial port.
|
||||||
*
|
*
|
||||||
* \param size A size_t that indicates how many bytes should be written from
|
* \param size A size_t that indicates how many bytes should be written from
|
||||||
* the given data buffer.
|
* the given data buffer.
|
||||||
*
|
*
|
||||||
* \return A size_t representing the number of bytes actually written to
|
* \return A size_t representing the number of bytes actually written to
|
||||||
@ -376,34 +376,34 @@ public:
|
|||||||
*
|
*
|
||||||
* There are two timeout conditions described here:
|
* There are two timeout conditions described here:
|
||||||
* * The inter byte timeout:
|
* * The inter byte timeout:
|
||||||
* * The inter_byte_timeout component of serial::Timeout defines the
|
* * The inter_byte_timeout component of serial::Timeout defines the
|
||||||
* maximum amount of time, in milliseconds, between receiving bytes on
|
* maximum amount of time, in milliseconds, between receiving bytes on
|
||||||
* the serial port that can pass before a timeout occurs. Setting this
|
* the serial port that can pass before a timeout occurs. Setting this
|
||||||
* to zero will prevent inter byte timeouts from occurring.
|
* to zero will prevent inter byte timeouts from occurring.
|
||||||
* * Total time timeout:
|
* * Total time timeout:
|
||||||
* * The constant and multiplier component of this timeout condition,
|
* * The constant and multiplier component of this timeout condition,
|
||||||
* for both read and write, are defined in serial::Timeout. This
|
* for both read and write, are defined in serial::Timeout. This
|
||||||
* timeout occurs if the total time since the read or write call was
|
* timeout occurs if the total time since the read or write call was
|
||||||
* made exceeds the specified time in milliseconds.
|
* made exceeds the specified time in milliseconds.
|
||||||
* * The limit is defined by multiplying the multiplier component by the
|
* * The limit is defined by multiplying the multiplier component by the
|
||||||
* number of requested bytes and adding that product to the constant
|
* number of requested bytes and adding that product to the constant
|
||||||
* component. In this way if you want a read call, for example, to
|
* component. In this way if you want a read call, for example, to
|
||||||
* timeout after exactly one second regardless of the number of bytes
|
* timeout after exactly one second regardless of the number of bytes
|
||||||
* you asked for then set the read_timeout_constant component of
|
* you asked for then set the read_timeout_constant component of
|
||||||
* serial::Timeout to 1000 and the read_timeout_multiplier to zero.
|
* serial::Timeout to 1000 and the read_timeout_multiplier to zero.
|
||||||
* This timeout condition can be used in conjunction with the inter
|
* This timeout condition can be used in conjunction with the inter
|
||||||
* byte timeout condition with out any problems, timeout will simply
|
* byte timeout condition with out any problems, timeout will simply
|
||||||
* occur when one of the two timeout conditions is met. This allows
|
* occur when one of the two timeout conditions is met. This allows
|
||||||
* users to have maximum control over the trade-off between
|
* users to have maximum control over the trade-off between
|
||||||
* responsiveness and efficiency.
|
* responsiveness and efficiency.
|
||||||
*
|
*
|
||||||
* Read and write functions will return in one of three cases. When the
|
* Read and write functions will return in one of three cases. When the
|
||||||
* reading or writing is complete, when a timeout occurs, or when an
|
* reading or writing is complete, when a timeout occurs, or when an
|
||||||
* exception occurs.
|
* exception occurs.
|
||||||
*
|
*
|
||||||
* \param timeout A serial::Timeout struct containing the inter byte
|
* \param timeout A serial::Timeout struct containing the inter byte
|
||||||
* timeout, and the read and write timeout constants and multipliers.
|
* timeout, and the read and write timeout constants and multipliers.
|
||||||
*
|
*
|
||||||
* \see serial::Timeout
|
* \see serial::Timeout
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
@ -423,7 +423,7 @@ public:
|
|||||||
|
|
||||||
/*! Gets the timeout for reads in seconds.
|
/*! Gets the timeout for reads in seconds.
|
||||||
*
|
*
|
||||||
* \return A Timeout struct containing the inter_byte_timeout, and read
|
* \return A Timeout struct containing the inter_byte_timeout, and read
|
||||||
* and write timeout constants and multipliers.
|
* and write timeout constants and multipliers.
|
||||||
*
|
*
|
||||||
* \see Serial::setTimeout
|
* \see Serial::setTimeout
|
||||||
@ -565,14 +565,14 @@ public:
|
|||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Blocks until CTS, DSR, RI, CD changes or something interrupts it.
|
* Blocks until CTS, DSR, RI, CD changes or something interrupts it.
|
||||||
*
|
*
|
||||||
* Can throw an exception if an error occurs while waiting.
|
* Can throw an exception if an error occurs while waiting.
|
||||||
* You can check the status of CTS, DSR, RI, and CD once this returns.
|
* You can check the status of CTS, DSR, RI, and CD once this returns.
|
||||||
* Uses TIOCMIWAIT via ioctl if available (mostly only on Linux) with a
|
* Uses TIOCMIWAIT via ioctl if available (mostly only on Linux) with a
|
||||||
* resolution of less than +-1ms and as good as +-0.2ms. Otherwise a
|
* resolution of less than +-1ms and as good as +-0.2ms. Otherwise a
|
||||||
* polling method is used which can give +-2ms.
|
* polling method is used which can give +-2ms.
|
||||||
*
|
*
|
||||||
* \return Returns true if one of the lines changed, false if something else
|
* \return Returns true if one of the lines changed, false if something else
|
||||||
* occurred.
|
* occurred.
|
||||||
*
|
*
|
||||||
* \throw SerialException
|
* \throw SerialException
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
// This header is from the v8 google project:
|
// This header is from the v8 google project:
|
||||||
// http://code.google.com/p/v8/source/browse/trunk/include/v8stdint.h
|
// http://code.google.com/p/v8/source/browse/trunk/include/v8stdint.h
|
||||||
|
|
||||||
// Copyright 2012 the V8 project authors. All rights reserved.
|
// Copyright 2012 the V8 project authors. All rights reserved.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user