bool CIPICOMConnectionV6::receive_internal(std::string& output, int expect_unsolicited) { int recv_result; int dummy; recv_result = receive_wrapp(socket_shared, output, dummy); // Remove newlines in the string //std::string::size_type pos_line = output.find("\r\n"); //while(pos_line != std::string::npos) //{ // output.replace(pos_line, 2, " "); // pos_line = output.find("\r\n"); //} if (recv_result == 0) // Means OK { if (output.find("OK") != std::string::npos) { LOGER((CLogger::DEBUG_INFO,"Recv on %s OK: '%s'", get_channel_name(shared_channel).c_str(),process_for_log(output).c_str())); return true; } else { LOGER((CLogger::DEBUG_INFO,"Recv on %s ERROR: '%s'", get_channel_name(shared_channel).c_str(),process_for_log(output).c_str())); return false; } } else if (recv_result > 0) // means unsolicited data is received { if (expect_unsolicited) { return true; } output.clear(); return receive_internal(output, expect_unsolicited); } else if (recv_result == -1) // Error from ipicom { return false; } else if (recv_result == -2) // Error from target { return false; } else if (recv_result == -3) // Received partial response { std::string incomplete_output; if (receive_internal(incomplete_output, expect_unsolicited)) { output += incomplete_output; return true; } return false; } return false; }
bool CIPICOMConnectionV6::query(std::string input, std::string& output, int expect_unsolicited) { int retry = 5; if (!opened) { LOGER((CLogger::DEBUG_ERROR,"Query Error, No Session!")); return false; } bool retval = false; if (active_channel == shared_channel) { send_internal(input); retval = receive_internal(output, expect_unsolicited); while (--retry > 0 && !retval) { LOGER((CLogger::DEBUG_INFO,"Retrying query")); send_internal(input); retval = receive_internal(output, expect_unsolicited); } return retval; } else { int nof_commands = 0; int id = 0; send_tid_internal(input, nof_commands, id, channel_to_socket()); retval = receive_tid_internal(id, nof_commands, output, channel_to_socket(), expect_unsolicited); while (--retry > 0 && !retval) { LOGER((CLogger::DEBUG_INFO,"Retrying query")); send_tid_internal(input, nof_commands, id, channel_to_socket()); // clear response cache for any incoherency if (id > 0 && !expect_unsolicited) { for (int i = id; i < id + nof_commands; ++i) { response_map.erase(id); } } Sleep(200); retval = receive_tid_internal(id, nof_commands, output, channel_to_socket(), expect_unsolicited); } return retval; } return retval; }
int CIPICOMConnectionV6::receive(std::string& output, int tx_id, int nof_exp_resp, int expect_unsolicited, channel_type channel) { if (!opened) { LOGER((CLogger::DEBUG_ERROR,"Recv Error, No Session!")); return 0; } int retval = 0; if ((active_channel == shared_channel && channel == default_channel) || channel == shared_channel) { retval = receive_internal(output, expect_unsolicited); } else { retval = receive_tid_internal(tx_id, nof_exp_resp, output, channel_to_socket(channel), expect_unsolicited); } if (retval) { LOGER((CLogger::DEBUG_INFO,"Recv on %s OK: '%s'",get_channel_name(channel).c_str(),output.c_str())); } else { LOGER((CLogger::DEBUG_ERROR,"Recv on %s ERROR: '%s'",get_channel_name(channel).c_str(),output.c_str())); } return retval; }
bool CIPICOMConnectionV6::check(bool bGTIPort) { timeout(1000); timeout_count = 0; if (bGTIPort) { #if TOOL_ENABLE_ON if (!CheckServiceReady("cp")) #else if (!CheckServiceReady()) #endif { LOGER((CLogger::DEBUG_ERROR,"Failed to check USB conntection")); return false; } } else Sleep(2000); std::string output; send_internal("ate0"); if (!receive_internal(output, 0)) return false; output.clear(); if (!query("at@", output)) return false; timeout_count = 0; timeout(0); return TRUE; }
uint8_t i2c_master::receive(uint8_t address, uint8_t* data, uint8_t length) { return receive_internal(address, nullptr, data, length); }
uint8_t i2c_master::receive(uint8_t address, uint8_t register_address, uint8_t* data, uint8_t length) { return receive_internal(address, ®ister_address, data, length); }