mirror of
https://github.com/wjwwood/serial.git
synced 2026-01-22 19:54:57 +08:00
use static casts rather than C-style casting
C-style casting can result in undesired reinterpret_casts So we should avoid them, see: http://stackoverflow.com/questions/332030/when-should-static-cast-dynamic-cast-and-reinterpret-cast-be-used
This commit is contained in:
parent
3f2ed36849
commit
cfac5bbcc9
@ -60,8 +60,8 @@ MillisecondTimer::MillisecondTimer (const uint32_t millis)
|
|||||||
{
|
{
|
||||||
int64_t tv_nsec = expiry.tv_nsec + (millis * 1e6);
|
int64_t tv_nsec = expiry.tv_nsec + (millis * 1e6);
|
||||||
if (tv_nsec > 1e9) {
|
if (tv_nsec > 1e9) {
|
||||||
int64_t sec_diff = tv_nsec / (int)1e6;
|
int64_t sec_diff = tv_nsec / static_cast<int> (1e6);
|
||||||
expiry.tv_nsec = tv_nsec - (int)(1e6 * sec_diff);
|
expiry.tv_nsec = tv_nsec - static_cast<int> (1e6 * sec_diff);
|
||||||
expiry.tv_sec += sec_diff;
|
expiry.tv_sec += sec_diff;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -301,7 +301,7 @@ Serial::SerialImpl::reconfigurePort ()
|
|||||||
// other than those specified by POSIX. The driver for the underlying serial hardware
|
// other than those specified by POSIX. The driver for the underlying serial hardware
|
||||||
// ultimately determines which baud rates can be used. This ioctl sets both the input
|
// ultimately determines which baud rates can be used. This ioctl sets both the input
|
||||||
// and output speed.
|
// and output speed.
|
||||||
speed_t new_baud = static_cast<speed_t>(baudrate_);
|
speed_t new_baud = static_cast<speed_t> (baudrate_);
|
||||||
if (-1 == ioctl (fd_, IOSSIOSPEED, &new_baud, 1)) {
|
if (-1 == ioctl (fd_, IOSSIOSPEED, &new_baud, 1)) {
|
||||||
THROW (IOException, errno);
|
THROW (IOException, errno);
|
||||||
}
|
}
|
||||||
@ -314,7 +314,7 @@ Serial::SerialImpl::reconfigurePort ()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// set custom divisor
|
// set custom divisor
|
||||||
ser.custom_divisor = ser.baud_base / (int) baudrate_;
|
ser.custom_divisor = ser.baud_base / static_cast<int> (baudrate_);
|
||||||
// update flags
|
// update flags
|
||||||
ser.flags &= ~ASYNC_SPD_MASK;
|
ser.flags &= ~ASYNC_SPD_MASK;
|
||||||
ser.flags |= ASYNC_SPD_CUST;
|
ser.flags |= ASYNC_SPD_CUST;
|
||||||
@ -464,7 +464,7 @@ Serial::SerialImpl::read (uint8_t *buf, size_t size)
|
|||||||
|
|
||||||
// Calculate total timeout in milliseconds t_c + (t_m * N)
|
// Calculate total timeout in milliseconds t_c + (t_m * N)
|
||||||
long total_timeout_ms = timeout_.read_timeout_constant;
|
long total_timeout_ms = timeout_.read_timeout_constant;
|
||||||
total_timeout_ms += timeout_.read_timeout_multiplier*static_cast<long>(size);
|
total_timeout_ms += timeout_.read_timeout_multiplier * static_cast<long> (size);
|
||||||
MillisecondTimer total_timeout(total_timeout_ms);
|
MillisecondTimer total_timeout(total_timeout_ms);
|
||||||
|
|
||||||
while (bytes_read < size) {
|
while (bytes_read < size) {
|
||||||
@ -476,7 +476,7 @@ Serial::SerialImpl::read (uint8_t *buf, size_t size)
|
|||||||
|
|
||||||
// Timeout for the next select is whichever is less of the remaining
|
// Timeout for the next select is whichever is less of the remaining
|
||||||
// total read timeout and the inter-byte timeout.
|
// total read timeout and the inter-byte timeout.
|
||||||
timespec timeout(timespec_from_ms(std::min((uint32_t)timeout_remaining_ms,
|
timespec timeout(timespec_from_ms(std::min(static_cast<uint32_t> (timeout_remaining_ms),
|
||||||
timeout_.inter_byte_timeout)));
|
timeout_.inter_byte_timeout)));
|
||||||
|
|
||||||
FD_ZERO (&readfds);
|
FD_ZERO (&readfds);
|
||||||
@ -552,7 +552,7 @@ Serial::SerialImpl::write (const uint8_t *data, size_t length)
|
|||||||
|
|
||||||
// Calculate total timeout in milliseconds t_c + (t_m * N)
|
// Calculate total timeout in milliseconds t_c + (t_m * N)
|
||||||
long total_timeout_ms = timeout_.write_timeout_constant;
|
long total_timeout_ms = timeout_.write_timeout_constant;
|
||||||
total_timeout_ms += timeout_.write_timeout_multiplier*static_cast<long>(length);
|
total_timeout_ms += timeout_.write_timeout_multiplier * static_cast<long> (length);
|
||||||
MillisecondTimer total_timeout(total_timeout_ms);
|
MillisecondTimer total_timeout(total_timeout_ms);
|
||||||
|
|
||||||
while (bytes_written < length) {
|
while (bytes_written < length) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user