summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
inline | side by side (from parent 1:
dca683e)
Store the most recent successfully applied set of parameters for serial
communication. Re-use these values as a fallback to calculate timeouts,
when the underlying transport fails to provide the current settings.
char *port;
/** Comm params for serial_set_paramstr(). */
char *serialcomm;
char *port;
/** Comm params for serial_set_paramstr(). */
char *serialcomm;
+ struct {
+ int bit_rate;
+ int data_bits;
+ int parity_bits;
+ int stop_bits;
+ } comm_params;
/** libserialport port handle */
struct sp_port *sp_data;
};
/** libserialport port handle */
struct sp_port *sp_data;
};
+ serial->comm_params.bit_rate = baudrate;
+ serial->comm_params.data_bits = bits;
+ serial->comm_params.parity_bits = parity ? 1 : 0;
+ serial->comm_params.stop_bits = stopbits;
+ sr_dbg("DBG: %s() rate %d, %d%s%d", __func__,
+ baudrate, bits,
+ (parity == 0) ? "n" : "x",
+ stopbits);
+
if (sp_new_config(&config) < 0)
return timeout_ms;
if (sp_new_config(&config) < 0)
return timeout_ms;
+ /* Get the bitrate and frame length. */
bits = baud = 0;
do {
if (sp_get_config(port->sp_data, config) < 0)
bits = baud = 0;
do {
if (sp_get_config(port->sp_data, config) < 0)
break;
baud = tmp;
} while (FALSE);
break;
baud = tmp;
} while (FALSE);
+ if (!bits || !baud) {
+ baud = port->comm_params.bit_rate;
+ bits = 1 + port->comm_params.data_bits +
+ port->comm_params.parity_bits +
+ port->comm_params.stop_bits;
+ }
+ /* Derive the timeout. */
if (bits && baud) {
/* Throw in 10ms for misc OS overhead. */
timeout_ms = 10;
if (bits && baud) {
/* Throw in 10ms for misc OS overhead. */
timeout_ms = 10;