Skip to content

Conversation

@hallard
Copy link
Contributor

@hallard hallard commented Feb 11, 2016

Permit use bit config avoiding test/compare all "hard-coded" values.
example:

if (section & CFG_HLP_MODBUS) {
DebuglnF("\r\n===== Modbus");
DebugF("Speed       : "); Debug(config.modbus.baud);

switch (config.modbus.proto & UART_NB_BIT_MASK) {
  case UART_NB_BIT_5: Debug(" 5"); break;
  case UART_NB_BIT_6: Debug(" 6"); break;
  case UART_NB_BIT_7: Debug(" 7"); break;
  case UART_NB_BIT_8: Debug(" 8"); break;
  default : Debug(" ?"); break;
}
switch (config.modbus.proto & UART_PARITY_MASK) {
  case UART_PARITY_NONE: Debug("N"); break;
  case UART_PARITY_EVEN: Debug("E"); break;
  case UART_PARITY_ODD : Debug("O"); break;
  default : Debug("?"); break;
}
switch (config.modbus.proto & UART_NB_STOP_BIT_MASK) {
  case UART_NB_STOP_BIT_0: Debug("0"); break;
  case UART_NB_STOP_BIT_1: Debug("1"); break;
  case UART_NB_STOP_BIT_15: Debug("15"); break;
  case UART_NB_STOP_BIT_2 : Debug("2"); break;
  default : Debug("?"); break;
}

DebugF("\r\nSlave Addr  : "); Debugln(config.modbus.slave);
DebugF("Holding Reg : 0x"); Debugln2(config.modbus.hr_addr,HEX);
DebugF("Enable Pin  : "); Debugln(config.modbus.en_pin);
}

Permit use bit config avoiding test/compare all "hard-coded" values.
example
```arduino
if (section & CFG_HLP_MODBUS) {
DebuglnF("\r\n===== Modbus");
DebugF("Speed       : "); Debug(config.modbus.baud);

switch (config.modbus.proto & UART_NB_BIT_MASK) {
case UART_NB_BIT_5: Debug(" 5"); break;
case UART_NB_BIT_6: Debug(" 6"); break;
case UART_NB_BIT_7: Debug(" 7"); break;
case UART_NB_BIT_8: Debug(" 8"); break;
default : Debug(" ?"); break;
}
switch (config.modbus.proto & UART_PARITY_MASK) {
case UART_PARITY_NONE: Debug("N"); break;
case UART_PARITY_EVEN: Debug("E"); break;
case UART_PARITY_ODD : Debug("O"); break;
default : Debug("?"); break;
}
switch (config.modbus.proto & UART_NB_STOP_BIT_MASK) {
case UART_NB_STOP_BIT_0: Debug("0"); break;
case UART_NB_STOP_BIT_1: Debug("1"); break;
case UART_NB_STOP_BIT_15: Debug("15"); break;
case UART_NB_STOP_BIT_2 : Debug("2"); break;
default : Debug("?"); break;
}

DebugF("\r\nSlave Addr  : "); Debugln(config.modbus.slave);
DebugF("Holding Reg : 0x"); Debugln2(config.modbus.hr_addr,HEX);
DebugF("Enable Pin  : "); Debugln(config.modbus.en_pin);
}
```
igrr added a commit that referenced this pull request Feb 13, 2016
Added bit mask and constant for SerialConfig parameter
@igrr igrr merged commit 4f5f003 into esp8266:master Feb 13, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants