/* * @brief convert String to integer * * @param value A pointer to string * @return integer */ static t_u32 a2hex_or_atoi(t_s8 * value) { if (value[0] == '0' && (value[1] == 'X' || value[1] == 'x')) { return a2hex(value + 2); } else if (isdigit(*value)) { return atoi(value); } else { return *value; } }
char remote488_device::recv_update(uint8_t& data) { char c; unsigned i; // Do not iterate too much.. for (i = 0; i < 8 && m_stream->input(&c , 1); i++) { int prev_state = m_rx_state; switch (m_rx_state) { case REM_RX_WAIT_CH: if (is_msg_type(c)) { m_rx_ch = c; m_rx_state = REM_RX_WAIT_COLON; } else if (!is_space(c)) { m_rx_state = REM_RX_WAIT_WS; } break; case REM_RX_WAIT_COLON: if (c == ':') { m_rx_state = REM_RX_WAIT_1ST_HEX; } else { m_rx_state = REM_RX_WAIT_WS; } break; case REM_RX_WAIT_1ST_HEX: if (a2hex(c , m_rx_data)) { m_rx_state = REM_RX_WAIT_2ND_HEX; } else { m_rx_state = REM_RX_WAIT_WS; } break; case REM_RX_WAIT_2ND_HEX: { uint8_t tmp; if (a2hex(c , tmp)) { m_rx_data = (m_rx_data << 4) | tmp; m_rx_state = REM_RX_WAIT_SEP; } else { m_rx_state = REM_RX_WAIT_WS; } } break; case REM_RX_WAIT_SEP: if (is_terminator(c) || is_space(c)) { m_rx_state = REM_RX_WAIT_CH; LOG_PARSER("PARSE %02x %d->%d\n" , c , prev_state , m_rx_state); data = m_rx_data; return m_rx_ch; } else { m_rx_state = REM_RX_WAIT_WS; } break; case REM_RX_WAIT_WS: if (is_terminator(c) || is_space(c)) { m_rx_state = REM_RX_WAIT_CH; } break; default: m_rx_state = REM_RX_WAIT_CH; break; } LOG_PARSER("PARSE %02x %d->%d\n" , c , prev_state , m_rx_state); } return 0; }