void CGMSKModemWinUSB::writeHeader(const CHeaderData& header) { unsigned char myCall1[LONG_CALLSIGN_LENGTH]; unsigned char myCall2[SHORT_CALLSIGN_LENGTH]; unsigned char yourCall[LONG_CALLSIGN_LENGTH]; unsigned char rptCall1[LONG_CALLSIGN_LENGTH]; unsigned char rptCall2[LONG_CALLSIGN_LENGTH]; for (unsigned int i = 0U; i < LONG_CALLSIGN_LENGTH; i++) myCall1[i] = header.getMyCall1().GetChar(i); for (unsigned int i = 0U; i < SHORT_CALLSIGN_LENGTH; i++) myCall2[i] = header.getMyCall2().GetChar(i); for (unsigned int i = 0U; i < LONG_CALLSIGN_LENGTH; i++) yourCall[i] = header.getYourCall().GetChar(i); for (unsigned int i = 0U; i < LONG_CALLSIGN_LENGTH; i++) rptCall1[i] = header.getRptCall1().GetChar(i); for (unsigned int i = 0U; i < LONG_CALLSIGN_LENGTH; i++) rptCall2[i] = header.getRptCall2().GetChar(i); io(SET_MyCALL2, 0x40U, 0U, myCall2, SHORT_CALLSIGN_LENGTH); io(SET_MyCALL, 0x40U, 0U, myCall1, LONG_CALLSIGN_LENGTH); io(SET_YourCALL, 0x40U, 0U, yourCall, LONG_CALLSIGN_LENGTH); io(SET_RPT1CALL, 0x40U, 0U, rptCall1, LONG_CALLSIGN_LENGTH); io(SET_RPT2CALL, 0x40U, 0U, rptCall2, LONG_CALLSIGN_LENGTH); unsigned char flags[3U]; flags[0U] = header.getFlag1(); flags[1U] = header.getFlag2(); flags[2U] = header.getFlag3(); io(SET_FLAGS, 0x40U, 0U, flags, 3U); setPTT(true); }
bool CGMSKModemLibUsb::open() { wxASSERT(m_context != NULL); wxASSERT(m_handle == NULL); m_handle = ::libusb_open_device_with_vid_pid(m_context, VENDOR_ID, m_address); if (m_handle == NULL) { wxLogError(wxT("Cannot open the GMSK Modem with address: 0x%04X"), m_address); return false; } wxLogInfo(wxT("Found the GMSK Modem with address: 0x%04X"), m_address); ::libusb_set_configuration(m_handle, 1); unsigned char c; int ret = ::libusb_control_transfer(m_handle, 0x40, SET_AD_INIT, 0, 0, &c, 0, USB_TIMEOUT); if (ret < 0) { wxLogError(wxT("SET_AD_INIT, err=%d"), ret); close(); return false; } wxString version; do { unsigned char buffer[GMSK_MODEM_DATA_LENGTH]; ret = ::libusb_control_transfer(m_handle, 0xC0, GET_VERSION, 0, 0, buffer, GMSK_MODEM_DATA_LENGTH, USB_TIMEOUT); if (ret > 0) { wxString text((char*)buffer, wxConvLocal, ret); version.Append(text); } else if (ret < 0) { wxLogError(wxT("GET_VERSION, err=%d"), ret); close(); return false; } } while (ret == int(GMSK_MODEM_DATA_LENGTH)); wxLogInfo(wxT("Firmware version: %s"), version.c_str()); // Trap firmware version 0.1.00 of DUTCH*Star and complain loudly if (version.Find(wxT("DUTCH*Star")) != wxNOT_FOUND && version.Find(wxT("0.1.00")) != wxNOT_FOUND) { wxLogWarning(wxT("This modem firmware is not fully supported by the GMSK Repeater")); wxLogWarning(wxT("Please upgrade to a newer version if possible")); m_broken = true; } setPTT(false); return true; }
bool CGMSKModemLibUsb::openModem() { if (!m_loaded) return false; m_usbInit(); m_usbFindBusses(); m_usbFindDevices(); for (struct usb_bus* bus = m_usbGetBusses(); bus != NULL; bus = bus->next) { for (struct usb_device* dev = bus->devices; dev != NULL; dev = dev->next) { if (dev->descriptor.idVendor == VENDOR_ID && dev->descriptor.idProduct == m_address) { m_dev = m_usbOpen(dev); break; } } } if (m_dev == NULL) return false; m_usbSetConfiguration(m_dev, 1); char c; int ret1 = io(0x40, SET_AD_INIT, 0, 0, &c, 0, USB_TIMEOUT); if (ret1 < 0) { wxString error(m_usbStrerror(), wxConvLocal); wxLogError(wxT("SET_AD_INIT, ret: %d, err=%s"), ret1, error.c_str()); close(); return false; } bool ret2 = setPTT(false); if (!ret2) { close(); return false; } return true; }
bool CGMSKModemLibUsb::openModem() { m_handle = ::libusb_open_device_with_vid_pid(m_context, VENDOR_ID, m_address); if (m_handle == NULL) return false; ::libusb_set_configuration(m_handle, 1); unsigned char c; int ret1 = io(0x40, SET_AD_INIT, 0, 0, &c, 0, USB_TIMEOUT); if (ret1 < 0) { wxLogError(wxT("SET_AD_INIT, err=%d"), ret1); close(); return false; } bool ret2 = setPTT(false); if (!ret2) { close(); return false; } return true; }
bool CGMSKModemWinUSB::openModem() { WCHAR id1[15U], id2[15U]; ::swprintf(id1, L"pid_%04x", m_address); ::swprintf(id2, L"pid_%04X", m_address); wxString wxId1(id1, wxConvLocal); wxString wxId2(id2, wxConvLocal); CLSID clsId; LPOLESTR str = OLESTR("{136C76EF-3F4E-4030-A7E3-E1003EF0A715}"); HRESULT result = ::CLSIDFromString(str, &clsId); if (result != NOERROR) { wxLogError(wxT("Error from CLSIDFromString: err=%lu"), ::GetLastError()); return false; } HDEVINFO devInfo = ::SetupDiGetClassDevs(&clsId, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); if (devInfo == INVALID_HANDLE_VALUE) { wxLogError(wxT("Error from SetupDiGetClassDevs: err=%lu"), ::GetLastError()); return false; } SP_DEVICE_INTERFACE_DATA devInfoData; devInfoData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA); for (unsigned int index = 0U; ::SetupDiEnumDeviceInterfaces(devInfo, NULL, &clsId, index, &devInfoData); index++) { DWORD length; ::SetupDiGetDeviceInterfaceDetail(devInfo, &devInfoData, NULL, 0U, &length, NULL); PSP_DEVICE_INTERFACE_DETAIL_DATA detailData = PSP_DEVICE_INTERFACE_DETAIL_DATA(::malloc(length)); detailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA); DWORD required; BOOL ret1 = ::SetupDiGetDeviceInterfaceDetail(devInfo, &devInfoData, detailData, length, &required, NULL); if (!ret1) { wxLogError(wxT("Error from SetupDiGetDeviceInterfaceDetail: err=%lu"), ::GetLastError()); ::SetupDiDestroyDeviceInfoList(devInfo); ::free(detailData); return false; } // Check the name to see if it's the correct vendor id and address if (::wcsstr(detailData->DevicePath, id1) == NULL && ::wcsstr(detailData->DevicePath, id2) == NULL) { ::free(detailData); continue; } m_file = ::CreateFile(detailData->DevicePath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); if (m_file == INVALID_HANDLE_VALUE) { wxLogError(wxT("Error from CreateFile: err=%lu"), ::GetLastError()); ::SetupDiDestroyDeviceInfoList(devInfo); ::free(detailData); return false; } ret1 = ::WinUsb_Initialize(m_file, &m_handle); if (!ret1) { wxLogError(wxT("Error from WinUsb_Initialize: err=%lu"), ::GetLastError()); ::SetupDiDestroyDeviceInfoList(devInfo); ::CloseHandle(m_file); ::free(detailData); return false; } ::SetupDiDestroyDeviceInfoList(devInfo); ::free(detailData); unsigned char c; io(SET_AD_INIT, 0x40U, 0U, &c, 0U); setPTT(false); return true; } ::SetupDiDestroyDeviceInfoList(devInfo); return false; }
bool CGMSKModemWinUSB::writeHeader(const CHeaderData& header) { unsigned char myCall1[LONG_CALLSIGN_LENGTH]; unsigned char myCall2[SHORT_CALLSIGN_LENGTH]; unsigned char yourCall[LONG_CALLSIGN_LENGTH]; unsigned char rptCall1[LONG_CALLSIGN_LENGTH]; unsigned char rptCall2[LONG_CALLSIGN_LENGTH]; for (unsigned int i = 0U; i < LONG_CALLSIGN_LENGTH; i++) myCall1[i] = header.getMyCall1().GetChar(i); for (unsigned int i = 0U; i < SHORT_CALLSIGN_LENGTH; i++) myCall2[i] = header.getMyCall2().GetChar(i); for (unsigned int i = 0U; i < LONG_CALLSIGN_LENGTH; i++) yourCall[i] = header.getYourCall().GetChar(i); for (unsigned int i = 0U; i < LONG_CALLSIGN_LENGTH; i++) rptCall1[i] = header.getRptCall1().GetChar(i); for (unsigned int i = 0U; i < LONG_CALLSIGN_LENGTH; i++) rptCall2[i] = header.getRptCall2().GetChar(i); int ret = io(SET_MyCALL2, 0x40U, 0U, myCall2, SHORT_CALLSIGN_LENGTH); if (ret < 0) { wxLogError(wxT("SET_MyCALL2 returned %d"), -ret); return false; } ret = io(SET_MyCALL, 0x40U, 0U, myCall1, LONG_CALLSIGN_LENGTH); if (ret < 0) { wxLogError(wxT("SET_MyCALL returned %d"), -ret); return false; } ret = io(SET_YourCALL, 0x40U, 0U, yourCall, LONG_CALLSIGN_LENGTH); if (ret < 0) { wxLogError(wxT("SET_YourCALL returned %d"), -ret); return false; } ret = io(SET_RPT1CALL, 0x40U, 0U, rptCall1, LONG_CALLSIGN_LENGTH); if (ret < 0) { wxLogError(wxT("SET_RPT1CALL returned %d"), -ret); return false; } ret = io(SET_RPT2CALL, 0x40U, 0U, rptCall2, LONG_CALLSIGN_LENGTH); if (ret < 0) { wxLogError(wxT("SET_RPT2CALL returned %d"), -ret); return false; } unsigned char flags[3U]; flags[0U] = header.getFlag1(); flags[1U] = header.getFlag2(); flags[2U] = header.getFlag3(); ret = io(SET_FLAGS, 0x40U, 0U, flags, 3U); if (ret < 0) { wxLogError(wxT("SET_FLAGS returned %d"), -ret); return false; } return setPTT(true); }
bool CGMSKModemLibUsb::open() { if (!m_loaded) return false; wxASSERT(m_dev == NULL); m_usbInit(); m_usbFindBusses(); m_usbFindDevices(); for (struct usb_bus* bus = m_usbGetBusses(); bus != NULL; bus = bus->next) { for (struct usb_device* dev = bus->devices; dev != NULL; dev = dev->next) { if (dev->descriptor.idVendor == VENDOR_ID && dev->descriptor.idProduct == m_address) { m_dev = m_usbOpen(dev); break; } } } if (m_dev == NULL) { wxLogError(wxT("Cannot find the GMSK Modem with address: 0x%04X"), m_address); return false; } wxLogInfo(wxT("Found the GMSK Modem with address: 0x%04X"), m_address); m_usbSetConfiguration(m_dev, 1); char c; m_usbControlMsg(m_dev, 0x40, SET_AD_INIT, 0, 0, &c, 0, USB_TIMEOUT); wxString version; int ret; do { char buffer[GMSK_MODEM_DATA_LENGTH]; ret = m_usbControlMsg(m_dev, 0xC0, GET_VERSION, 0, 0, buffer, GMSK_MODEM_DATA_LENGTH, USB_TIMEOUT); if (ret > 0) { wxString text(buffer, wxConvLocal, ret); version.Append(text); } else if (ret < 0) { wxString error(m_usbStrerror(), wxConvLocal); wxLogError(wxT("GET_VERSION, ret: %d, err=%s"), ret, error.c_str()); m_usbClose(m_dev); m_dev = NULL; return false; } } while (ret == int(GMSK_MODEM_DATA_LENGTH)); wxLogInfo(wxT("Firmware version: %s"), version.c_str()); // Trap firmware version 0.1.00 of DUTCH*Star and complain loudly if (version.Find(wxT("DUTCH*Star")) != wxNOT_FOUND && version.Find(wxT("0.1.00")) != wxNOT_FOUND) { wxLogWarning(wxT("This modem firmware is not fully supported by the GMSK Repeater")); wxLogWarning(wxT("Please upgrade to a newer version if possible")); m_broken = true; } setPTT(false); return true; }
/** * Main routine. Parse commandline args and trigger actions. */ int main(int argc, char **argv) { usb_dev_handle *handle = NULL; char * usbSerialID = NULL; int c; // moved this malloc() here instead of within the while(1) loop // to prevent memory leakage problem // as *args is not free'ed. char **args = malloc(MAX_COMMAND_ARGS * sizeof(char *)); int port = 19004; int daemon = 0; // Read options while ( (c = getopt(argc, argv, "adhi:m:p:s:u:vx:")) != -1) { switch (c) { case 'i': i2cAddress = atoi(optarg); break; case 'a': setByValue = 1; break; case 'd': daemon = 1; break; case 'h': firmware_PTT = 1; break; case 'm': multiplier = atof(optarg); break; case 'p': port = atoi(optarg); break; case 's': startupFreq = atof(optarg); break; case 'x': fXtall = atof(optarg); break; case 'u': usbSerialID = optarg; break; case 'v': verbose++; break; default: /* '?' */ usage(argv[0]); exit(EXIT_FAILURE); } } if (verbose) { printf("I2C Address = %X\n", i2cAddress); printf("fXtall = %f\n", fXtall); printf("multiplier = %f\n", multiplier); printf("startupFreq = %f\n", startupFreq); } if((argc <= optind) && (daemon == 0)){ usage(argv[0]); exit(1); } usb_init(); char attempt=0, error=0; do { attempt++; error=usbOpenDevice(&handle, USBDEV_SHARED_VENDOR, VENDOR_NAME, USBDEV_SHARED_PRODUCT, PRODUCT_NAME, usbSerialID); if(error != 0){ fprintf(stderr, "Could not open USB device \"%s\" with vid=0x%x pid=0x%x, retrying\n", PRODUCT_NAME, USBDEV_SHARED_VENDOR, USBDEV_SHARED_PRODUCT); sleep(2*attempt); } } while (error && attempt < USB_MAX_RETRIES); if (error) { fprintf(stderr, "Permanent problem opening usb device. Giving up.\n"); exit(1); } unsigned short version = readVersion(handle); major = (version & 0xFF00) >> 8; minor = (version & 0xFF); /* Relocate lower later */ if (daemon) { printf("Starting daemon...\n"); int socket_desc; socket_desc=socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP); if (socket_desc==-1) perror("Create socket"); struct sockaddr_in address; /* type of socket created in socket() */ address.sin_family = AF_INET; address.sin_addr.s_addr = INADDR_ANY; address.sin_port = htons(port); /* bind the socket to the port specified above */ int retval; if (bind(socket_desc,(struct sockaddr *)&address,sizeof(address)) != 0) { fprintf(stderr, "Error binding to port %d\n", port); exit(0); } while (1) { ssize_t bytes; char buffer[1024]; struct sockaddr_in clnt; socklen_t clnt_len; clnt_len = sizeof(clnt); bytes = recvfrom (socket_desc, buffer, sizeof(buffer) - 1, 0, (struct sockaddr *)&clnt, &clnt_len); if (bytes > 0) { buffer[bytes] = 0; if (verbose >= 2) printf("Returned %d bytes from %s: %s\n", bytes, inet_ntoa(clnt.sin_addr), buffer); if (strncmp(buffer, "quit", 4) == 0) { if (verbose) printf("Quit command received\n"); exit(0); } char *saveptr; char *token; int argn = 0; for (int i=0; i < MAX_COMMAND_ARGS;i++) args[i] = NULL; token = strtok_r(buffer, " ", &saveptr); while (token != NULL) { args[argn] = strcpy(malloc(strlen(token) + 1), token); argn++; token = strtok_r(NULL, " ", &saveptr); } // Execute command here char result[100]; do_command(handle, args, argn, result); // Cleanup for (int i=0; i < MAX_COMMAND_ARGS;i++) { if (args[i] != NULL) free(args[i]); } int retlen = strlen(result); if (sendto(socket_desc, result, retlen,0, (struct sockaddr *) &clnt, clnt_len) != retlen) { perror("Failed to send ack"); exit(1); } } else { fprintf(stderr, "recvfrom returned %d\n", bytes); } } close(socket_desc); exit(0); } /* Device has been opened - perform the requested operation */ if (strcmp(argv[optind], "getregisters") == 0) { getRegisters(handle); } else if(strcmp(argv[optind], "getfreq") == 0){ double freq; if (setByValue) freq = readFrequencyByValue(handle); else freq = getFrequency(handle); if (freq != 0.00) printf("Frequency : %f (x %.2f)\n", freq / multiplier, multiplier); #ifdef HAVE_LIBNCURSES } else if (strcmp(argv[optind], "interactive") == 0) { run_interactive(handle); #endif } else if (strcmp(argv[optind], "getptt") == 0){ if (firmware_PTT) PTT = getPTT(handle); printf("PTT : %d\n", PTT); } else if (strcmp(argv[optind], "getkeys") == 0){ keys = getkeys(handle); printf("Paddles: %d\n", keys); } else if (strcmp(argv[optind], "gettone") == 0){ printf("CW Tone: %d\n", CW_tone); } else if ((strcmp(argv[optind], "ptt") == 0) && (argc >= optind + 1)) { PTT = (strcmp(argv[optind+1],"on") == 0) ? 1: 0; setPTT(handle, PTT); printf("PTT set to %d\n", PTT); } else if (strcmp(argv[optind], "calibrate") == 0) { calibrate(handle); } else if ((strcmp(argv[optind], "set") == 0) && (argc >= optind + 2)) { if ((strcmp(argv[optind+1], "bpf_addr") == 0) && (argc >= optind + 3)) { // set bpf_addr index value setBPFAddress(handle, atoi(argv[optind+2]), atoi(argv[optind+3])); } else if ((strcmp(argv[optind+1], "bpf_point") == 0) && (argc >= optind + 3)) { // set bpf_point index (int) value (float) setBPFCrossOver(handle, atoi(argv[optind+2]), atof(argv[optind+3])); } else if ((strcmp(argv[optind+1], "bpf") == 0) && (argc >= optind + 2)) { setBPF(handle, (strcmp(argv[optind+2],"on") == 0) ? 1 : 0); } else if ((strcmp(argv[optind+1], "lpf") == 0) && (argc >= optind + 2)) { setLPF(handle, (strcmp(argv[optind+2],"on") == 0) ? 1 : 0); } else if ((strcmp(argv[optind+1], "lpf_addr") == 0) && (argc >= optind + 3)) { // set bpf_addr index value setBPFAddress(handle, atoi(argv[optind+2]), atoi(argv[optind+3])); displayLPFs(handle); } else if ((strcmp(argv[optind+1], "lpf_point") == 0) && (argc >= optind + 3)) { // set lpf_point index (int) value (float) setLPFCrossOver(handle, atoi(argv[optind+2]), atof(argv[optind+3])); } else if (strcmp(argv[optind+1], "freq") == 0) { if (setByValue) setFreqByValue(handle, atof(argv[optind+2])); else setFrequency(handle, atof(argv[optind+2])); } else if ((strcmp(argv[optind+1], "registers") == 0 || strcmp(argv[optind+1], "regs") == 0) && argc == optind+8) { unsigned char regs[6]; int i; for (i = 0; i < 6; i += 1) regs[i] = strtol(argv[optind+2+i], NULL, 0); setRegisters(handle, regs); } else if ((strcmp(argv[optind+1], "si570_addr") == 0) && (argc >= optind + 2)) { setSi570Address(handle, atoi(argv[optind+2])); } else if (strcmp(argv[optind+1], "si570_multiplier") == 0) { int index = 0; int valueIndex = optind+2; // If there are 2 args after the variable name, one is index if (argc >= optind + 3) { index = atoi(argv[optind+2]); valueIndex++; } double sub, mul; readMultiplyLO(handle, index, &mul, &sub); mul = atof(argv[valueIndex]); setMultiplyLo(handle, index, mul, sub); if (verbose) printf("Set multiply [%d] to : %f\n", index, mul); } else if (strcmp(argv[optind+1], "xtall") == 0) { setXtallFrequency(handle, atof(argv[optind+2])); } else if (strcmp(argv[optind+1], "startup") == 0) { setStartupFrequency(handle, atof(argv[optind+2])); } else { usage(argv[0]); exit(1); } } else if (strcmp(argv[optind], "solutions") == 0) { solveRegisters(handle); } else if (strcmp(argv[optind], "status") == 0) { printf("USB SerialID: %s\n", serialNumberString); if (major >= 15) { readFrequencyByValue(handle); readStartupFreq(handle); readXtallFreq(handle); readSmoothTunePPM(handle); if (major >= 16 || minor >= 12) { readSi570Address(handle); } displayBands(handle); displayLPFs(handle); /* if (major >= 16 || ((major >= 15) && (minor >= 12))) { displayBands(handle); } else if (minor >= 10) { double sub, mul; readMultiplyLO(handle, 0, &mul, &sub); printf("LO Subtract : %f\n", sub); printf("Multiply : %f\n", mul); } //displayBPFFilters(handle); //displayLPFFilters(handle);*/ } } else if (strcmp(argv[optind], "tweak") == 0) { tweakRegisters(handle); } else { usage(argv[0]); exit(1); } usb_close(handle); return 0; }
int do_command(usb_dev_handle *handle, char **argv, int argc, char *result) { sprintf(result, "ok"); if (strcmp(argv[0], "get") == 0) { if(argv[1][0] == 'p'){ if (firmware_PTT) PTT = getPTT(handle); // this reads the PTT status from the connected Mobo sprintf(result, "ok %d", PTT); } else if (argv[1][0] == 'k'){ keys = getkeys(handle); sprintf(result, "ok %d", keys); } else if(argv[1][0] == 'f'){ double freq; if (setByValue) freq = readFrequencyByValue(handle); else freq = getFrequency(handle); if (freq != 0.00) { if (verbose >= 2) printf("Frequency : %f (x %.2f)\n", freq / multiplier, multiplier); sprintf(result, "ok %f", freq / multiplier); } else { sprintf(result, "error"); return -1; } } else if(argv[1][0] == 't'){ sprintf(result, "ok %d", CW_tone); } else if (strcmp(argv[1], "si570_multiplier") == 0) { double sub, mul; // Just works for non per-band multipliers if (readMultiplyLO(handle, 0, &mul, &sub) == 0) sprintf(result, "ok %f", mul); else { sprintf(result, "error"); return -1; } } else if (strcmp(argv[1], "local_multiplier") == 0) { sprintf(result, "ok %f", multiplier); } else { sprintf(result, "error"); return -1; } // end if "local multiplier" } // end if "get" else if ((strcmp(argv[0], "set") == 0) && (argc >= 2)) { if ((strcmp(argv[1], "ptt") == 0) && (argc >= 1)) { PTT = (strncmp(argv[2],"on",2) == 0) ? 1 : 0; setPTT(handle, PTT); } else if ((strcmp(argv[1], "bpf") == 0)) { setBPF(handle, (strncmp(argv[2],"on",2) == 0) ? 1 : 0); } else if (strcmp(argv[1], "freq") == 0) { if (setByValue) setFreqByValue(handle, atof(argv[2])); else setFrequency(handle, atof(argv[2])); } else if (strcmp(argv[1], "tone") == 0) { CW_tone = atof(argv[2]); } else if (strcmp(argv[1], "local_multiplier") == 0) { multiplier = atof(argv[2]); } else if (strcmp(argv[1], "registers") == 0 || strcmp(argv[1], "regs") == 0 && argc == 8) { unsigned char regs[6]; int i; for (i = 0; i < 6; i += 1) regs[i] = strtol(argv[2+i], NULL, 0); setRegisters(handle, regs); } else if (strcmp(argv[1], "tweak") == 0) { tweakRegisters(handle); } else { sprintf(result, "error"); return -1; } } else { sprintf(result, "error"); return -1; } return 0; }
int do_command(usb_dev_handle *handle, char **argv, int argc, char *result) { sprintf(result, "ok"); if ((strcmp(argv[0], "get") == 0) && (argc >= 1)) { if(strcmp(argv[1], "freq") == 0){ double freq; if (setByValue) freq = readFrequencyByValue(handle); else freq = getFrequency(handle); if (freq != 0.00) { if (verbose >= 2) printf("Frequency : %f (x %.2f)\n", freq / multiplier, multiplier); sprintf(result, "ok %f", freq / multiplier); } else { sprintf(result, "error"); return -1; } } else if (strcmp(argv[1], "si570_multiplier") == 0) { double sub, mul; // Just works for non per-band multipliers if (readMultiplyLO(handle, 0, &mul, &sub) == 0) sprintf(result, "ok %f", mul); else sprintf(result, "error"); } else if (strcmp(argv[1], "local_multiplier")) { sprintf(result, "ok %f", multiplier); } else { sprintf(result, "error"); } } else if ((strcmp(argv[0], "set") == 0) && (argc >= 2)) { if ((strcmp(argv[1], "ptt") == 0) && (argc >= 1)) { setPTT(handle, (strncmp(argv[2],"on",2) == 0) ? 1 : 0); } else if ((strcmp(argv[1], "bpf") == 0)) { setBPF(handle, (strncmp(argv[2],"on",2) == 0) ? 1 : 0); } else if (strcmp(argv[1], "freq") == 0) { if (setByValue) setFreqByValue(handle, atof(argv[2])); else setFrequency(handle, atof(argv[2])); } else if (strcmp(argv[1], "local_multiplier")) { multiplier = atof(argv[2]); } else { sprintf(result, "error"); return -1; } } else { sprintf(result, "error"); return -1; } return 0; }