bool CMMDVMCal::setTransmit() { m_transmit = !m_transmit; unsigned char buffer[50U]; buffer[0U] = 0xE0U; buffer[1U] = 4U; buffer[2U] = 0x08U; buffer[3U] = m_transmit ? 0x01U : 0x00U; int ret = m_serial.write(buffer, 4U); if (ret <= 0) return false; sleep(10U); ret = readModem(buffer, 50U); if (ret <= 0) return false; if (buffer[2U] == 0x7FU) { ::fprintf(stderr, "Got a NAK from the modem" EOL); return false; } if (buffer[2U] != 0x70U) { CUtils::dump("Invalid response", buffer, ret); return false; } return true; }
bool CMMDVMCal::writeConfig() { unsigned char buffer[50U]; buffer[0U] = 0xE0U; buffer[1U] = 10U; buffer[2U] = 0x02U; buffer[3U] = 0x00U; if (m_rxInvert) buffer[3U] |= 0x01U; if (m_txInvert) buffer[3U] |= 0x02U; if (m_pttInvert) buffer[3U] |= 0x04U; buffer[4U] = 0x00U; buffer[5U] = 0U; buffer[6U] = 99U; buffer[7U] = (m_rxLevel * 256U) / 100U; buffer[8U] = (m_txLevel * 256U) / 100U; buffer[9U] = 0U; int ret = m_serial.write(buffer, 10U); if (ret <= 0) return false; sleep(10U); ret = readModem(buffer, 50U); if (ret <= 0) return false; if (buffer[2U] == 0x7FU) { ::fprintf(stderr, "Got a NAK from the modem" EOL); return false; } if (buffer[2U] != 0x70U) { CUtils::dump("Invalid response", buffer, ret); return false; } return true; }
bool CMMDVMCal::initModem() { unsigned char buffer[150U]; sleep(2000U); int ret = 0; for (unsigned int i = 0U; i < 5U && ret <= 0; i++) { buffer[0U] = 0xE0U; buffer[1U] = 3U; buffer[2U] = 0x00U; ret = m_serial.write(buffer, 3U); if (ret <= 0) return false; sleep(100U); ret = readModem(buffer, 50U); if (ret < 0) return false; if (ret == 0) sleep(1000U); } if (ret <= 0) { ::fprintf(stderr, "No response from the modem" EOL); return false; } if (buffer[2U] != 0x00U) { CUtils::dump("Invalid response", buffer, ret); return false; } ::fprintf(stdout, "Version: %u \"%.*s\"" EOL, buffer[3U], buffer[1U] - 4, buffer + 4U); return writeConfig(); }
RESP_TYPE_V3 CDVRPTRV3Controller::getResponse(unsigned char *buffer, unsigned int& length) { // Get the start of the frame or nothing at all int ret = readModem(buffer + 0U, 5U); if (ret < 0) { wxLogError(wxT("Error when reading from the DV-RPTR")); return RT3_ERROR; } if (ret == 0) return RT3_TIMEOUT; while (::memcmp(buffer + 0U, "HEAD", 4U) != 0) { buffer[0U] = buffer[1U]; buffer[1U] = buffer[2U]; buffer[2U] = buffer[3U]; buffer[3U] = buffer[4U]; ret = readModem(buffer + 4U, 1U); if (ret < 0) { wxLogError(wxT("Error when reading from the DV-RPTR")); return RT3_ERROR; } if (ret == 0) return RT3_TIMEOUT; } switch (buffer[4U]) { case 'X': length = 105U; break; case 'Y': length = 10U; break; case 'Z': length = 20U; break; default: wxLogError(wxT("DV-RPTR frame type is incorrect - 0x%02X"), buffer[4U]); return RT3_UNKNOWN; } unsigned int offset = 5U; while (offset < length) { int ret = readModem(buffer + offset, length - offset); if (ret < 0) { wxLogError(wxT("Error when reading from the DV-RPTR")); return RT3_ERROR; } if (ret > 0) offset += ret; if (ret == 0) Sleep(5UL); } // CUtils::dump(wxT("Received"), buffer, length); if (::memcmp(buffer + 0U, "HEADZ", 5U) == 0) { return RT3_DATA; } else if (::memcmp(buffer + 5U, "0001", 4U) == 0) { if (buffer[104U] == 0x01U) return RT3_HEADER; } else if (::memcmp(buffer + 5U, "9900", 4U) == 0) { return RT3_QUERY; } else if (::memcmp(buffer + 5U, "9001", 4U) == 0) { return RT3_CONFIG; } else if (::memcmp(buffer + 5U, "9011", 4U) == 0) { return RT3_SPACE; } else if (::memcmp(buffer + 5U, "9021", 4U) == 0) { return RT3_TIMEOUT; } return RT3_UNKNOWN; }
int CMMDVMCal::run() { bool ret = m_serial.open(); if (!ret) return 1; ret = initModem(); if (!ret) { m_serial.close(); return 1; } ret = m_console.open(); if (!ret) { m_serial.close(); return 1; } displayHelp(); bool end = false; while (!end) { int c = m_console.getChar(); switch (c) { case 'H': case 'h': displayHelp(); break; case 'T': setTXLevel(1); break; case 't': setTXLevel(-1); break; case 'R': setRXLevel(1); break; case 'r': setRXLevel(-1); break; case ' ': setTransmit(); break; case 'I': setTXInvert(); break; case 'i': setRXInvert(); break; case 'P': case 'p': setPTTInvert(); break; case 'Q': case 'q': end = true; break; case 'V': case 'v': ::fprintf(stdout, "MMDVMCal 20151008" EOL); break; case -1: break; default: ::fprintf(stderr, "Unknown command - %c (H/h for help)" EOL, c); break; } unsigned char buffer[130U]; int n = readModem(buffer, 130U); if (n > 0) displayModem(buffer, n); sleep(5U); } if (m_transmit) setTransmit(); m_serial.close(); m_console.close(); ::fprintf(stdout, "PTT Invert: %s, RX Invert: %s, TX Invert: %s, RX Level: %u, TX Level: %u" EOL, m_pttInvert ? "yes" : "no", m_rxInvert ? "yes" : "no", m_txInvert ? "yes" : "no", m_rxLevel, m_txLevel); return 0; }
RESP_TYPE_V2 CDVRPTRControllerV2::getResponse(unsigned char *buffer, unsigned int& length) { // Get the start of the frame or nothing at all int ret = readModem(buffer, 5U); if (ret < 0) { wxLogError(wxT("Error when reading from the DV-RPTR")); return RT2_ERROR; } if (ret == 0) return RT2_TIMEOUT; if (::memcmp(buffer + 0U, "HEAD", 4U) != 0) { wxLogError(wxT("DV-RPTR frame start is incorrect - 0x%02X 0x%02X 0x%02X 0x%02X"), buffer[0U], buffer[1U], buffer[2U], buffer[3U]); return RT2_UNKNOWN; } if (buffer[4U] == 'X') { length = 105U; } else if (buffer[4U] == 'Y') { length = 10U; } else if (buffer[4U] == 'Z') { length = 20U; } else { wxLogError(wxT("DV-RPTR frame type is incorrect - 0x%02X"), buffer[4U]); return RT2_UNKNOWN; } unsigned int offset = 5U; while (offset < length) { int ret = readModem(buffer + offset, length - offset); if (ret < 0) { wxLogError(wxT("Error when reading from the DV-RPTR")); return RT2_ERROR; } if (ret > 0) offset += ret; if (ret == 0) Sleep(5UL); } // CUtils::dump(wxT("Received"), buffer, length); if (::memcmp(buffer + 0U, "HEADZ", 5U) == 0) { return RT2_DATA; } else if (::memcmp(buffer + 5U, "0001", 4U) == 0) { if (buffer[104U] == 0x01U) return RT2_HEADER; } else if (::memcmp(buffer + 5U, "9900", 4U) == 0) { return RT2_QUERY; } else if (::memcmp(buffer + 5U, "9001", 4U) == 0) { return RT2_CONFIG; } else if (::memcmp(buffer + 5U, "9011", 4U) == 0) { return RT2_SPACE; } wxLogError(wxT("DV-RPTR frame type number is incorrect - 0x%02X 0x%02X 0x%02X 0x%02X"), buffer[5U], buffer[6U], buffer[7U], buffer[8U]); return RT2_UNKNOWN; }