void md5Animation::load(const char* animationFile) { // Open file string fileToOpen = Import::GetResourcesFolder() + "Res/models/" ; fileToOpen += animationFile; LOGE("[MD5ANIMATION][Load] Loading %s", fileToOpen.c_str()); FILE* fp = fopen (fileToOpen.c_str(), "rb"); if (!fp) { printf("Error: could not open file '%s'!\n", fileToOpen.c_str()); return ; } readVersion(fp); //CHECK_LOADING_STATUS; readCommandline(fp); //CHECK_LOADING_STATUS; readNumFrames(fp); //CHECK_LOADING_STATUS; readNumJoints(fp); //CHECK_LOADING_STATUS; readFrameRate(fp); //CHECK_LOADING_STATUS; readNumAnimatedComponents(fp); //CHECK_LOADING_STATUS; readHierarchy(fp); //CHECK_LOADING_STATUS; readBounds(fp); /// CHECK_LOADING_STATUS; readBaseFrame(fp); //CHECK_LOADING_STATUS; readFrames(fp); //CHECK_LOADING_STATUS; fclose(fp); loadingErrors = false; }
/// Append the rid set to the name file. Return the number of rids /// written. This function can be called after ibis::ridHandler::write has /// been called to write a file. It can be called many times. The /// function ibis::ridHandler::read will concatenate all rid sets into one. int ibis::ridHandler::append(const ibis::RIDSet& rids, const char* fname) const { if (fname == 0 || *fname == 0) return -1; ibis::util::mutexLock lock(&mutex, "ridHandler::append"); std::fstream to(fname, std::ios::in | std::ios::out); if (! to) { LOGGER(ibis::gVerbose >= 0) << "ridHandler cannot open input/output file " << fname; return -2; } if (0 != readVersion(to)) { LOGGER(ibis::gVerbose >= 0) << fname << " is not a recognized RidFile"; return -3; } if (0 != matchDBName(to)) { LOGGER(ibis::gVerbose >= 0) << "The name in file " << fname << " must be \"" << _dbName << "\" in order to append a new rid set"; return -4; } // ready to write at the end of file to.seekg(std::ios::end); const unsigned int nr = rids.size(); to << _prefix << "*RidCount " << nr << "\n"; for (unsigned int i = 0; i < nr; ++ i) to << rids[i] << "\n"; to.close(); return nr; } // ibis::ridHandler::append
void Beatmap::LoadBeatmap(std::string BeatmapPath) { BeatmapFile.clear(); HitObjects.clear(); MsPBs.clear(); MapPath = BeatmapPath; std::vector<std::string> BeatPath; SplitString::tokenize(MapPath, BeatPath, "\\"); MapName = BeatPath[BeatPath.size() - 1]; std::cout << "Mapname: " << MapName << std::endl; Error = 0; BeatmapLoaded = false; readBeatmap(); readVersion(); readMode(); if(MapMode != 0 && MapVersion > 5) { Error = 1; std::cerr << "Not a valid Osu!:Beatmap." << std::endl; } else { readDifficulty(); readMsPBs(); readHitObjects(); BeatmapLoaded = true; } }
NLPacket::NLPacket(Packet&& packet) : Packet(std::move(packet)) { readType(); readVersion(); readSourceID(); adjustPayloadStartAndCapacity(NLPacket::localHeaderSize(_type), _payloadSize > 0); }
frmAbout::frmAbout(QWidget *parent) : QDialog(parent) { setupUi(this); setWindowFlags(windowFlags()&~Qt::WindowContextHelpButtonHint); readVersion(); btnAboutQT->setVisible(true); }
// Reads the input file into memory returning 1 if it // was read unsuccessfully, otherwise 0. DataSetInitStatus readFile(char* fileName) { DataSetInitStatus status = DATA_SET_INIT_STATUS_SUCCESS; FILE *inputFilePtr; // Open the file and hold on to the pointer. inputFilePtr = fopen(fileName, "rb"); // If the file didn't open return -1. if (inputFilePtr == NULL) { return DATA_SET_INIT_STATUS_FILE_NOT_FOUND; } // Read the various data segments if the version is // one we can read. status = readVersion(inputFilePtr); if (status != DATA_SET_INIT_STATUS_SUCCESS) { fclose(inputFilePtr); return status; } status = readCopyright(inputFilePtr); if (status != DATA_SET_INIT_STATUS_SUCCESS) { fclose(inputFilePtr); return status; } status = readStrings(inputFilePtr); if (status != DATA_SET_INIT_STATUS_SUCCESS) { fclose(inputFilePtr); return status; } status = readProperties(inputFilePtr); if (status != DATA_SET_INIT_STATUS_SUCCESS) { fclose(inputFilePtr); return status; } status = readDevices(inputFilePtr); if (status != DATA_SET_INIT_STATUS_SUCCESS) { fclose(inputFilePtr); return status; } status = readLookupList(inputFilePtr); if (status != DATA_SET_INIT_STATUS_SUCCESS) { fclose(inputFilePtr); return status; } status = readNodes(inputFilePtr); if (status != DATA_SET_INIT_STATUS_SUCCESS) { fclose(inputFilePtr); return status; } fclose(inputFilePtr); return status; }
BitMatrixParser::BitMatrixParser(Ref<BitMatrix> bitMatrix) : bitMatrix_(NULL), parsedVersion_(NULL), readBitMatrix_(NULL) { size_t dimension = bitMatrix->getDimension(); if (dimension < 8 || dimension > 144 || (dimension & 0x01) != 0) throw ReaderException("Dimension must be even, > 8 < 144"); parsedVersion_ = readVersion(bitMatrix); bitMatrix_ = extractDataRegion(bitMatrix); readBitMatrix_ = new BitMatrix(bitMatrix_->getWidth(), bitMatrix_->getHeight()); }
Packet::Packet(std::unique_ptr<char[]> data, qint64 size, const HifiSockAddr& senderSockAddr) : _packetSize(size), _packet(std::move(data)), _senderSockAddr(senderSockAddr) { _type = readType(); _version = readVersion(); _payloadCapacity = _packetSize - localHeaderSize(_type); _payloadSize = _payloadCapacity; _payloadStart = _packet.get() + (_packetSize - _payloadCapacity); }
size_t HTTPFetchHeadParser::readFirstLine() { size_t endLinePos = headerString.find_first_of("\r\n"); if(endLinePos == std::string::npos) throw HTTPFetchHeadParserException(); size_t pos = 0; pos = readVersion(pos); pos = readStatusCode(pos); pos = readReasonPhrase(pos, endLinePos); return pos; }
NLPacket::NLPacket(std::unique_ptr<char[]> data, qint64 size, const HifiSockAddr& senderSockAddr) : Packet(std::move(data), size, senderSockAddr) { // sanity check before we decrease the payloadSize with the payloadCapacity Q_ASSERT(_payloadSize == _payloadCapacity); readType(); readVersion(); readSourceID(); adjustPayloadStartAndCapacity(NLPacket::localHeaderSize(_type), _payloadSize > 0); }
std::shared_ptr<OneSixVersion> OneSixVersion::fromJson(QJsonObject root) { std::shared_ptr<OneSixVersion> readVersion(new OneSixVersion()); int launcher_ver = readVersion->minimumLauncherVersion = root.value("minimumLauncherVersion").toDouble(); // ADD MORE HERE :D if (launcher_ver > 0 && launcher_ver <= 13) return fromJsonV4(root, readVersion); else { return std::shared_ptr<OneSixVersion>(); } }
/// This function is capable of reading a file written with one write /// command and multiple append commands. All rids are placed in @c rids /// in the order they appear in the file. The member varialbe @c _dbName /// will be set to the name stored in the file. int ibis::ridHandler::read(ibis::RIDSet& rids, const char* fname) { if (fname == 0 || *fname == 0) return -1; ibis::util::mutexLock lock(&mutex, "ridHandler::read"); std::ifstream from(fname); if (!from) { LOGGER(ibis::gVerbose >= 0) << "ridHandler cannot open input file " << fname; return -2; } if (0 != readVersion(from)) { LOGGER(ibis::gVerbose >= 0) << fname << " is not a recognized RidFile"; return -3; } if (0 != readDBName(from)) { LOGGER(ibis::gVerbose >= 0) << "ridHandler cannot determine the name of the RID set in " << fname; return -4; } int nr = 0; while (0 == readRidCount(from, nr)) { if (nr <= 0) break; LOGGER(ibis::gVerbose > 1) << "ridHandler to read " << nr << (nr>1 ? " rids" : " rid") << " from " << fname; rids.reserve(rids.size()+nr); for (int i = 0; i < nr && !from.fail(); ++i) { ibis::rid_t tmp; from >> tmp; rids.push_back(tmp); LOGGER(ibis::gVerbose > 2) << rids.size()-1 << ":\t" << rids.back(); } } from.close(); nr = rids.size(); LOGGER(ibis::gVerbose > 0) << "ridHandler read " << nr << (nr > 1 ? " rids" : " rid") << " from " << _dbName << " in file " << fname; return nr; } // ibis::ridHandler::read
bool NIImporter_DlrNavteq::ProhibitionHandler::report(const std::string& result) { // # NAME_ID Name if (result[0] == '#') { if (myVersion == 0) { const double version = readVersion(result, myFile); if (version > 0) { myVersion = version; } } return true; } StringTokenizer st(result, StringTokenizer::TAB); if (st.size() == 1) { return true; // one line with the number of data containing lines in it (also starts with a comment # since ersion 6.5) } if (myVersion >= 6) { assert(st.size() >= 7); const std::string id = st.next(); const std::string permanent = st.next(); const std::string validityPeriod = st.next(); const std::string throughTraffic = st.next(); const std::string vehicleType = st.next(); if (validityPeriod != UNDEFINED) { WRITE_WARNING("Ignoring temporary prohibited manoeuvre (" + validityPeriod + ")"); return true; } } const std::string startEdge = st.next(); const std::string endEdge = st.get(st.size() - 1); NBEdge* from = myEdgeCont.retrieve(startEdge); if (from == nullptr) { WRITE_WARNING("Ignoring prohibition from unknown start edge '" + startEdge + "'"); return true; } NBEdge* to = myEdgeCont.retrieve(endEdge); if (to == nullptr) { WRITE_WARNING("Ignoring prohibition from unknown end edge '" + endEdge + "'"); return true; } from->removeFromConnections(to, -1, -1, true); return true; }
bool CMMDVMController::openModem() { bool ret = m_serial.open(); if (!ret) return false; ret = readVersion(); if (!ret) { m_serial.close(); return false; } ret = setConfig(); if (!ret) { m_serial.close(); return false; } return true; }
bool CModem::open() { ::LogMessage("Opening the MMDVM"); bool ret = m_serial.open(); if (!ret) return false; ret = readVersion(); if (!ret) { m_serial.close(); return false; } ret = setConfig(); if (!ret) { m_serial.close(); return false; } m_statusTimer.start(); return true; }
bool NIImporter_DlrNavteq::EdgesHandler::report(const std::string& result) { // parse version number from first comment line and initialize column definitions if (result[0] == '#') { if (!myColumns.empty()) { return true; } const double version = readVersion(result, myFile); if (version > 0) { myVersion = version; // init columns const int NUM_COLUMNS = 25; // @note arrays must match this size! const int MC = MISSING_COLUMN; if (myVersion < 3) { const int columns[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, MC, 12, 13, 14, 15, 16, 17, 18, 19, 20, MC, MC, -21}; myColumns = std::vector<int>(columns, columns + NUM_COLUMNS); } else if (myVersion < 6) { const int columns[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, MC, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, -23}; myColumns = std::vector<int>(columns, columns + NUM_COLUMNS); } else { const int columns[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24}; myColumns = std::vector<int>(columns, columns + NUM_COLUMNS); } } return true; } if (myColumns.empty()) { throw ProcessError("Missing version string in file '" + myFile + "'."); } // interpret link attributes StringTokenizer st(result, StringTokenizer::WHITECHARS); const std::string id = getColumn(st, LINK_ID); // form of way (for priority and permissions) int form_of_way; try { form_of_way = StringUtils::toInt(getColumn(st, FORM_OF_WAY)); } catch (NumberFormatException&) { throw ProcessError("Non-numerical value for form_of_way of link '" + id + "'."); } // brunnel type (bridge/tunnel/ferry (for permissions) int brunnel_type; try { brunnel_type = StringUtils::toInt(getColumn(st, BRUNNEL_TYPE)); } catch (NumberFormatException&) { throw ProcessError("Non-numerical value for brunnel_type of link '" + id + "'."); } // priority based on street_type / frc int priority; try { priority = -StringUtils::toInt(getColumn(st, FUNCTIONAL_ROAD_CLASS)); // lower priority using form_of_way if (form_of_way == 11) { priority -= 1; // frontage road, very often with lowered curb } else if (form_of_way > 11) { priority -= 2; // parking/service access assume lowered curb } } catch (NumberFormatException&) { throw ProcessError("Non-numerical value for street_type of link '" + id + "')."); } // street name std::string streetName = getStreetNameFromIDs( getColumn(st, NAME_ID1_REGIONAL), getColumn(st, NAME_ID2_LOCAL)); // try to get the nodes const std::string fromID = getColumn(st, NODE_ID_FROM); const std::string toID = getColumn(st, NODE_ID_TO); NBNode* from = myNodeCont.retrieve(fromID); NBNode* to = myNodeCont.retrieve(toID); if (from == nullptr) { throw ProcessError("The from-node '" + fromID + "' of link '" + id + "' could not be found"); } if (to == nullptr) { throw ProcessError("The to-node '" + toID + "' of link '" + id + "' could not be found"); } // speed double speed; try { speed = StringUtils::toInt(getColumn(st, SPEED_RESTRICTION, "-1")) / 3.6; } catch (NumberFormatException&) { throw ProcessError("Non-numerical value for the SPEED_RESTRICTION of link '" + id + "'."); } if (speed < 0) { // speed category as fallback speed = NINavTeqHelper::getSpeed(id, getColumn(st, SPEED_CATEGORY)); } // number of lanes int numLanes; try { // EXTENDED_NUMBER_OF_LANES is prefered but may not be defined numLanes = StringUtils::toInt(getColumn(st, EXTENDED_NUMBER_OF_LANES, "-1")); if (numLanes == -1) { numLanes = NINavTeqHelper::getLaneNumber(id, getColumn(st, NUMBER_OF_LANES), speed); } } catch (NumberFormatException&) { throw ProcessError("Non-numerical value for the number of lanes of link '" + id + "'."); } const std::string navTeqTypeId = getColumn(st, VEHICLE_TYPE) + "_" + getColumn(st, FORM_OF_WAY); // build the edge NBEdge* e = nullptr; const std::string interID = getColumn(st, BETWEEN_NODE_ID); if (interID == "-1") { e = new NBEdge(id, from, to, myTypeCont.knows(navTeqTypeId) ? navTeqTypeId : "", speed, numLanes, priority, NBEdge::UNSPECIFIED_WIDTH, NBEdge::UNSPECIFIED_OFFSET, streetName); } else { PositionVector geoms = myGeoms[interID]; if (getColumn(st, CONNECTION, "0") == "1") { geoms = geoms.reverse(); } geoms.insert(geoms.begin(), from->getPosition()); geoms.push_back(to->getPosition()); const std::string origID = OptionsCont::getOptions().getBool("output.original-names") ? id : ""; e = new NBEdge(id, from, to, myTypeCont.knows(navTeqTypeId) ? navTeqTypeId : "", speed, numLanes, priority, NBEdge::UNSPECIFIED_WIDTH, NBEdge::UNSPECIFIED_OFFSET, geoms, streetName, origID, LANESPREAD_CENTER); } // NavTeq imports can be done with a typemap (if supplied), if not, the old defaults are used if (myTypeCont.knows(navTeqTypeId)) { e->setPermissions(myTypeCont.getPermissions(navTeqTypeId)); } else { // add vehicle type information to the edge if (myVersion < 6.0) { NINavTeqHelper::addVehicleClasses(*e, getColumn(st, VEHICLE_TYPE)); } else { NINavTeqHelper::addVehicleClassesV6(*e, getColumn(st, VEHICLE_TYPE)); } if (e->getPermissions() == SVCAll) { e->setPermissions(myTypeCont.getPermissions("")); } // permission modifications based on form_of_way if (form_of_way == 14) { // pedestrian area (fussgaengerzone) // unfortunately, the veh_type string is misleading in this case e->disallowVehicleClass(-1, SVC_PASSENGER); } // permission modifications based on brunnel_type if (brunnel_type == 10) { // ferry e->setPermissions(SVC_SHIP, -1); } } // insert the edge to the network if (!myEdgeCont.insert(e)) { delete e; throw ProcessError("Could not add edge '" + id + "'."); } return true; }
void FileHeader::read(io::SeekableInputStream& inStream) { if (!isCPHD(inStream)) { throw except::Exception(Ctxt("Not a CPHD file")); } // Read mVersion first mVersion = readVersion(inStream); // Block read the header for more efficient IO KeyValuePair headerEntry; std::string headerBlock; blockReadHeader(inStream, 1024, headerBlock); // Read each line with its tokens if (!headerBlock.empty()) { std::vector<std::string> headerLines = str::split(headerBlock, "\n"); for (size_t ii = 0; ii < headerLines.size(); ++ii) { // Determine our header entry tokenize(headerLines[ii], KVP_DELIMITER, headerEntry); if (headerEntry.first == "XML_DATA_SIZE") { mXmlDataSize = str::toType<sys::Off_T>(headerEntry.second); } else if (headerEntry.first == "XML_BYTE_OFFSET") { mXmlByteOffset = str::toType<sys::Off_T>(headerEntry.second); } else if (headerEntry.first == "VB_DATA_SIZE") { mVbDataSize = str::toType<sys::Off_T>(headerEntry.second); } else if (headerEntry.first == "VB_BYTE_OFFSET") { mVbByteOffset = str::toType<sys::Off_T>(headerEntry.second); } else if (headerEntry.first == "CPHD_DATA_SIZE") { mCphdDataSize = str::toType<sys::Off_T>(headerEntry.second); } else if (headerEntry.first == "CPHD_BYTE_OFFSET") { mCphdByteOffset = str::toType<sys::Off_T>(headerEntry.second); } else if (headerEntry.first == "CLASSIFICATION") { mClassification = headerEntry.second; } else if (headerEntry.first == "RELEASE_INFO") { mReleaseInfo = headerEntry.second; } else { throw except::Exception(Ctxt( "Invalid CPHD header entry '" + headerEntry.first)); } } } // check for any required values that are uninitialized if (mXmlDataSize == 0 || mXmlByteOffset == 0 || mVbDataSize == 0 || mVbByteOffset == 0 || mCphdDataSize == 0 || mCphdByteOffset == 0) { throw except::Exception(Ctxt("CPHD header information is incomplete")); } }
/** * 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 connectToRhost( rcComm_t *conn, int connectCnt, int reconnFlag ) { int status; conn->sock = connectToRhostWithRaddr( &conn->remoteAddr, conn->windowSize, 1 ); if ( conn->sock < 0 ) { rodsLogError( LOG_NOTICE, conn->sock, "connectToRhost: connect to host %s on port %d failed, status = %d", conn->host, conn->portNum, conn->sock ); return conn->sock; } setConnAddr( conn ); status = sendStartupPack( conn, connectCnt, reconnFlag ); if ( status < 0 ) { rodsLogError( LOG_ERROR, status, "connectToRhost: sendStartupPack to %s failed, status = %d", conn->host, status ); close( conn->sock ); return status; } // =-=-=-=-=-=-=- // create a network object irods::network_object_ptr net_obj; irods::error ret = irods::network_factory( conn, net_obj ); if ( !ret.ok() ) { irods::log( PASS( ret ) ); return ret.code(); } // =-=-=-=-=-=-=- // if the client requests the connection negotiation then wait for a // response here from the Agent if ( irods::do_client_server_negotiation_for_client() ) { // =-=-=-=-=-=-=- // politely do the negotiation std::string results; ret = irods::client_server_negotiation_for_client( net_obj, results ); if ( !ret.ok() ) { irods::log( PASS( ret ) ); return ret.code(); } // =-=-=-=-=-=-=- // enable SSL if requested // NOTE:: this is disabled in rcDisconnect if the conn->ssl_on flag is set if ( irods::CS_NEG_USE_SSL == irods::CS_NEG_FAILURE ) { printf( "connectToRhost - failed in client-server negotiations\n" ); } // =-=-=-=-=-=-=- // copy results to connection for network object factory snprintf( conn->negotiation_results, MAX_NAME_LEN, "%s", results.c_str() ); } ret = readVersion( net_obj, &conn->svrVersion ); if ( !ret.ok() ) { rodsLogError( LOG_ERROR, ret.code(), "connectToRhost: readVersion to %s failed, status = %d", conn->host, ret.code() ); close( conn->sock ); return ret.code(); } if ( conn->svrVersion->status < 0 ) { rodsLogError( LOG_ERROR, conn->svrVersion->status, "connectToRhost: error returned from host %s status = %d", conn->host, conn->svrVersion->status ); if ( conn->svrVersion->status == SYS_EXCEED_CONNECT_CNT ) rodsLog( LOG_ERROR, "It is likely %s is a localhost but not recognized by this server. A line can be added to the server/config/irodsHost file to fix the problem", conn->host ); close( conn->sock ); return conn->svrVersion->status; } // =-=-=-=-=-=-=- // call initialization for network plugin as negotiated irods::network_object_ptr new_net_obj; ret = irods::network_factory( conn, new_net_obj ); if ( !ret.ok() ) { irods::log( PASS( ret ) ); return ret.code(); } // =-=-=-=-=-=-=- // get rods env to pass to client start for policy decisions rodsEnv rods_env; status = getRodsEnv( &rods_env ); ret = sockClientStart( new_net_obj, &rods_env ); if ( !ret.ok() ) { irods::log( PASS( ret ) ); return ret.code(); } new_net_obj->to_client( conn ); return 0; } // connectToRhost