/** Called when asyn clients call pasynOctet->write(). * This function performs actions for some parameters, including NDAttributesFile. * For all parameters it sets the value in the parameter library and calls any registered callbacks.. * \param[in] pasynUser pasynUser structure that encodes the reason and address. * \param[in] value Address of the string to write. * \param[in] nChars Number of characters to write. * \param[out] nActual Number of characters actually written. */ asynStatus asynNDArrayDriver::writeOctet(asynUser *pasynUser, const char *value, size_t nChars, size_t *nActual) { int addr=0; int function = pasynUser->reason; asynStatus status = asynSuccess; const char *functionName = "writeOctet"; status = getAddress(pasynUser, &addr); if (status != asynSuccess) return(status); /* Set the parameter in the parameter library. */ status = (asynStatus)setStringParam(addr, function, (char *)value); if (function == NDAttributesFile) { this->readNDAttributesFile(value); } else if (function == NDFilePath) { status = this->checkPath(); if (status == asynError) { // If the directory does not exist then try to create it int pathDepth; getIntegerParam(NDFileCreateDir, &pathDepth); status = createFilePath(value, pathDepth); status = this->checkPath(); } } /* Do callbacks so higher layers see any changes */ status = (asynStatus)callParamCallbacks(addr, addr); if (status) epicsSnprintf(pasynUser->errorMessage, pasynUser->errorMessageSize, "%s:%s: status=%d, function=%d, value=%s", driverName, functionName, status, function, value); else asynPrint(pasynUser, ASYN_TRACEIO_DRIVER, "%s:%s: function=%d, value=%s\n", driverName, functionName, function, value); *nActual = nChars; return status; }
/* testLine * Tests a single line in an input file for .yo format correctness. * proper format is: * 0xADDR: INSTRUCTION | * 1234567890123456789012 * Params: char *line - a pointer to the line to test * Returns int - status code of test (-1 bad line, 0 comment, 1 good line) * Modifies: addr, numBytes, prevAddr, prevBytes */ int testLine(char *line) { int i; // this loop tests for commentness for (i=0; i<22; i++) { if (line[i] != ' ') break; if (i == 21) return LINE_COMMENT; } // this tests for a lot of things, see above. if ((line[0] != ' ' && line[0] != 1) || line[1] != ' ' || line[2] != '0' || line[3] != 'x' || line[7] != ':'|| line[8] != ' ' || line[21]!= ' ' || line[22]!= '|') { return LINE_ERROR; } int numBits = strcspn(&line[9], " ");\ // cant have a nibble instruction if ((numBits & 1) != 0) return LINE_ERROR; addr = getAddress(line); // cant go backwards in addressing if (addr < prevAddr) return LINE_ERROR; numBytes = numBits >> 1; // need enough room for instructions if (lineNum > 1 && (prevAddr + prevBytes > addr)) return LINE_ERROR; // line is GOOD prevBytes = numBytes; prevAddr = addr; return LINE_GOOD; }
uint8_t RF24Mesh::update() { uint8_t type = network.update(); if(mesh_address == MESH_DEFAULT_ADDRESS) { return type; } #if !defined (RF24_TINY) && !defined(MESH_NOMASTER) if(type == NETWORK_REQ_ADDRESS) { doDHCP = 1; } if( (type == MESH_ADDR_LOOKUP || type == MESH_ID_LOOKUP) && !getNodeID()) { RF24NetworkHeader& header = *(RF24NetworkHeader*)network.frame_buffer; header.to_node = header.from_node; if(type==MESH_ADDR_LOOKUP) { int16_t returnAddr = getAddress(network.frame_buffer[sizeof(RF24NetworkHeader)]); network.write(header,&returnAddr,sizeof(returnAddr)); } else { int16_t returnAddr = getNodeID(network.frame_buffer[sizeof(RF24NetworkHeader)]); network.write(header,&returnAddr,sizeof(returnAddr)); } //printf("Returning lookup 0%o to 0%o \n",returnAddr,header.to_node); //network.write(header,&returnAddr,sizeof(returnAddr)); } else if(type == MESH_ADDR_RELEASE && !getNodeID() ) { uint16_t *fromAddr = (uint16_t*)network.frame_buffer; for(uint8_t i=0; i<addrListTop; i++) { if(addrList[i].address == *fromAddr) { addrList[i].address = 0; } } } #endif return type; }
/** Called when asyn clients call pasynOctet->write(). * Catch parameter changes. If the user changes the path or name of the template file * load the new template file. * \param[in] pasynUser pasynUser structure that encodes the reason and address. * \param[in] value Address of the string to write. * \param[in] nChars Number of characters to write. * \param[out] nActual Number of characters actually written. */ asynStatus NDFileNexus::writeOctet(asynUser *pasynUser, const char *value, size_t nChars, size_t *nActual) { int addr=0; int function = pasynUser->reason; asynStatus status = asynSuccess; static const char *functionName = "writeOctet"; status = getAddress(pasynUser, &addr); if (status != asynSuccess) return(status); /* Set the parameter in the parameter library. */ status = (asynStatus)setStringParam(addr, function, (char *)value); if (function == NDFileNexusTemplatePath) { loadTemplateFile(); } if (function == NDFileNexusTemplateFile) { loadTemplateFile(); } else { /* If this parameter belongs to a base class call its method */ if (function < FIRST_NDFILE_NEXUS_PARAM) status = NDPluginFile::writeOctet(pasynUser, value, nChars, nActual); } /* Do callbacks so higher layers see any changes */ status = (asynStatus)callParamCallbacks(addr, addr); if (status) epicsSnprintf(pasynUser->errorMessage, pasynUser->errorMessageSize, "%s:%s: status=%d, function=%d, value=%s", driverName, functionName, status, function, value); else asynPrint(pasynUser, ASYN_TRACEIO_DRIVER, "%s:%s: function=%d, value=%s\n", driverName, functionName, function, value); *nActual = nChars; return status; }
void Side::print() { for(int r = 0; r < nrRows; ++r) { std::cout << " "; for(int c = 0; c < nrCols; ++c) { int addr = getAddress(r, c); if(addr < 0) std::cout << " -1 "; else if(addr < 10) std::cout << " " << addr << " "; else if(addr < 100) std::cout << " " << addr << " "; else if(addr < 1000) std::cout << " " << addr << " "; else std::cout << addr << " "; } std::cout << std::endl; } }
asynStatus mk3Driver::writeInt32(asynUser *pasynUser, epicsInt32 value) { //std::cout << "writeInt32" << std::endl; int function = pasynUser->reason; asynStatus status = asynSuccess; const char *paramName; static const char *functionName = "writeInt32"; getParamName(function, ¶mName); int channel; getAddress(pasynUser, &channel); int errCode; if (function == P_NominalDirection) { int result; errCode = m_interface->putNominalDirection(channel, (bool) value, &result); checkErrorCode(errCode); } return status; }
Blob CCanSimpleSwitchActor::getActorStatus(SDeviceDescription device, Blob params) { // cout << "action getSensorSwitch SENSOR "<<to_string(device)<<endl; CCanBuffer buffer; Blob b; string response; vector<long long> values; buffer.insertCommand(CMD_READ_ACTOR); buffer.insertId((unsigned char) getDeviceCategory()); buffer << (unsigned char) getAddress(device); buffer.buildBuffer(); buffer = getProtocol()->request(buffer); if (buffer.getLength() > 0) { response = "OK"; values.push_back(buffer[OFFSET_DATA]); b[BLOB_RESPONSE_INT_VALUES].put<vector<long long>>(values); log->info("Device " + to_string(device) + " OUTPUT STATE: " + to_string(values[0]) ); }else{ response = "SimpleSwitchActor->getActorStatus->Receiving CAN frame failed"; } b[BLOB_TXT_RESPONSE_RESULT].put<string>(response); return b; }
static void fiberEntryPoint(void*) { // Load up the context set up by the InitialiseThreadEntry method. wakeCurrentContext(); // The following code must follow the conventions set by reschedule/ // InitialiseThreadState as this method is technically emulating // a PPC method (__crt_init). It is worth mentioning that this // fiberEntryPoint method essentially assumes that we are always // called only when a thread is first started. If this assumption // ever needs to be broken, we will need to update InitThreadState // so it calls an internal PPC function which does the behaviour. // We grab these before invoking the exception handler setup // since it is plausible that it might damage the GPR's. auto core = cpu::this_core::state(); auto entryPoint = coreinit::OSThreadEntryPointFn(core->nia); auto argc = core->gpr[3]; auto argv = mem::translate<void>(core->gpr[4]); // Entrypoint is actually supposed to be adjusted to the __crt_init // when you call OSCreateThread rather than having it called always // but it doesn't hurt to have this set up on default threads. coreinit::internal::ghsInitExceptions(); auto thread = coreinit::internal::getCurrentThread(); gLog->info("Thread Starting: ptr {:08X}, id {:x} entry {:08X}", mem::untranslate(thread), thread->id, entryPoint.getAddress()); auto exitValue = entryPoint(argc, argv); gLog->info("Thread Exiting: ptr {:08X}, id {:x}, exitValue {}", mem::untranslate(thread), thread->id, exitValue); coreinit::OSExitThread(exitValue); }
TEST(AsyncSocketTest, REUSEPORT) { EventBase base; auto serverSocket = AsyncServerSocket::newSocket(&base); serverSocket->bind(0); serverSocket->listen(0); serverSocket->startAccepting(); try { serverSocket->setReusePortEnabled(true); } catch (...) { LOG(INFO) << "Reuse port probably not supported"; return; } SocketAddress address; serverSocket->getAddress(&address); int port = address.getPort(); auto serverSocket2 = AsyncServerSocket::newSocket(&base); serverSocket2->setReusePortEnabled(true); serverSocket2->bind(port); serverSocket2->listen(0); serverSocket2->startAccepting(); }
int64_t SSLSocket::readImpl(char *buffer, int64_t length) { int64_t nr_bytes = 0; if (m_data->m_ssl_active) { IOStatusHelper io("sslsocket::recv", getAddress().c_str(), getPort()); bool retry = true; do { if (m_data->m_is_blocked) { waitForData(); if (timedOut()) { break; } // could get here and we only have parts of an SSL packet } nr_bytes = SSL_read(m_data->m_handle, buffer, length); if (nr_bytes > 0) break; /* we got the data */ retry = handleError(nr_bytes, false); setEof(!retry && errno != EAGAIN && !SSL_pending(m_data->m_handle)); } while (retry); } else { nr_bytes = Socket::readImpl(buffer, length); } return nr_bytes < 0 ? 0 : nr_bytes; }
WP::err Contact::writeConfig() { WP::err error = WP::kOk; if (privateKeyStore) { privateKeyStore = true; error = write("keystore_type", QString("private")); if (error != WP::kOk) return error; } keys->setTo(database, getKeysDirectory()); error = keys->writeConfig(); if (error != WP::kOk) return error; error = write("uid", uid); if (error != WP::kOk) return error; error = write("address", getAddress()); if (error != WP::kOk) return error; return error; }
void _initService() { if( !servus::Servus::isAvailable( )) { ZEROEQTHROW( std::runtime_error( "No zeroconf implementation available" )); return; } _service.set( KEY_INSTANCE, detail::Sender::getUUID().getString( )); _service.set( KEY_USER, getUserName( )); _service.set( KEY_APPLICATION, _getApplicationName( )); if( !_session.empty( )) _service.set( KEY_SESSION, _session ); const servus::Servus::Result& result = _service.announce( uri.getPort(), getAddress( )); if( !result ) { ZEROEQTHROW( std::runtime_error( "Zeroconf announce failed: " + result.getString( ))); } }
int TCPconnect0(char *bindAddress,int bindPort,int block) { struct in_addr iaddr; struct sockaddr_in saddr; int sd,j; int nodelay; if (!getAddress(bindAddress, &iaddr)) { error2("Host %s could not be resolved\n",bindAddress); return -1; } sd = socket(PF_INET, SOCK_STREAM, 0); if (sd < 0) { error("Couldn't create server socket!\n"); return -1; } saddr.sin_family = AF_INET; memcpy(&saddr.sin_addr, &iaddr, sizeof(iaddr)); saddr.sin_port = htons(bindPort); if (setsockopt(sd,IPPROTO_TCP,TCP_NODELAY,&nodelay,sizeof(nodelay))<0) error("TCP_NODELAY failed\n"); if (block==0) { j=0; setsockopt(sd, SOL_SOCKET, SO_LINGER, &j, sizeof(j)); fcntl(sd, F_SETFL, O_NONBLOCK); } if (connect(sd, (struct sockaddr *)&saddr, sizeof(saddr)) < 0) { error3("Couldn't connect to address %s port %d\n", bindAddress, bindPort); return -1; } return(sd); }
Blob CCanPWMActor::setAllPWM(SDeviceDescription device, Blob params) { Params values = params[BLOB_ACTION_PARAMETER].get<Params>(); Blob b; string response; CCanBuffer buffer; if (values.size() == 0) { response = "PWMActor->setAllPWM->Incorrect params"; log->error(response); b[BLOB_TXT_RESPONSE_RESULT].put<string>(response); return b; } buffer.insertCommand(CMD_SET_PWM_ALL); buffer.insertId((unsigned char) getDeviceCategory()); buffer << (unsigned char) getAddress(device); for (unsigned char val : values) { buffer << (unsigned char) (val); } buffer.buildBuffer(); response = (getProtocol()->send(buffer)) ? "OK" : "PWMActor->setAllPWM->Sending CAN frame failed"; b[BLOB_TXT_RESPONSE_RESULT].put<string>(response); return b; }
void AddressBookPluginWidget::reinitialize() { readConfig(); getAddress(); }
void sendNack(bufferStruct buffer){ state = STATE_SENDING_DATA; rfm12_tx (OVERHEAD, encode(NO_ACK, NACK, getAddress(buffer.bufferLength, buffer.buffer), 0, 0x00)); }
void sendAck(bufferStruct buffer){ rfm12_tx (OVERHEAD, encode(ACK, NO_DATA, getAddress(buffer.bufferLength, buffer.buffer), 0, 0x00)); }
Socket::Ptr ServerSocket::accept() const { AcceptedSocketData data = lowLevelAccept(getLowLevelSocket(), getAddress()); return Socket::create(data.address, data.lowLevelSocket); }
ossia::net::address_base*Metabots::MetabotNode::createAddress(ossia::val_type) { return getAddress(); }
/** Called when asyn clients call pasynInt32->write(). * For other parameters it calls NDPluginDriver::writeInt32 to see if that method understands the parameter. * For all parameters it sets the value in the parameter library and calls any registered callbacks. * \param[in] pasynUser pasynUser structure that encodes the reason and address. * \param[in] value The value to write. * \return asynStatus */ asynStatus NDPluginROIStat::writeInt32(asynUser *pasynUser, epicsInt32 value) { int function = pasynUser->reason; asynStatus status = asynSuccess; bool stat = true; int roi = 0; const char* functionName = "NDPluginROIStat::writeInt32"; status = getAddress(pasynUser, &roi); if (status != asynSuccess) { return status; } /* Set parameter and readback in parameter library */ stat = (setIntegerParam(roi, function, value) == asynSuccess) && stat; if (function == NDPluginROIStatReset) { stat = (clear(roi) == asynSuccess) && stat; } else if (function == NDPluginROIStatResetAll) { for (int i=0; i<maxROIs_; ++i) { stat = (clear(i) == asynSuccess) && stat; } } else if (function == NDPluginROIStatTSNumPoints) { free(timeSeries_); numTSPoints_ = value; timeSeries_ = (double *)calloc(MAX_TIME_SERIES_TYPES*maxROIs_*numTSPoints_, sizeof(double)); } else if (function == NDPluginROIStatTSControl) { switch (value) { case TSEraseStart: currentTSPoint_ = 0; setIntegerParam(NDPluginROIStatTSCurrentPoint, currentTSPoint_); setIntegerParam(NDPluginROIStatTSAcquiring, 1); memset(timeSeries_, 0, maxROIs_*MAX_TIME_SERIES_TYPES*numTSPoints_*sizeof(double)); break; case TSStart: if (currentTSPoint_ < numTSPoints_) { setIntegerParam(NDPluginROIStatTSAcquiring, 1); } break; case TSStop: setIntegerParam(NDPluginROIStatTSAcquiring, 0); doTimeSeriesCallbacks(); break; case TSRead: doTimeSeriesCallbacks(); break; } } else if (function < FIRST_NDPLUGIN_ROISTAT_PARAM) { stat = (NDPluginDriver::writeInt32(pasynUser, value) == asynSuccess) && stat; } /* Do callbacks so higher layers see any changes */ stat = (callParamCallbacks(roi) == asynSuccess) && stat; stat = (callParamCallbacks() == asynSuccess) && stat; if (!stat) { epicsSnprintf(pasynUser->errorMessage, pasynUser->errorMessageSize, "%s: status=%d, function=%d, value=%d", functionName, status, function, value); status = asynError; } else { asynPrint(pasynUser, ASYN_TRACEIO_DRIVER, "%s: function=%d, roi=%d, value=%d\n", functionName, function, roi, value); } return status; }
int main(void) { uint8_t cmdBuf[128]; uint8_t i; // Init peripherals. // Clock is set to 32MHz. clockInit(); // This UART is connected to the UC3 device and provides connectivity // via USB. uartInit(&UARTC0, 8); // 115,200 BAUD // This UART will be connected to the RadioBlocks device. uartInit(&UARTF0, 8); // 115,200 BAUD // Init the globals. isrLen = 0; cmdLen = 0; cmdFlag = 0; testCmd = 0; wakeCmd = 0; isrCmd = 0; ackStatus = 0; // Fun! ledFlag = 0; // These are used to help in debug. Used to print strings // to USARTC0 which is connected to the xplained-a1 usb // port through the on-board UC3. userEnd = 0; userStart = 0; // DEBUG - Create delay timer. //startTimer(1000); // One millisecond test. // Configure PORTA as output to measure delay timer... // These pins are on Xplained header J2 PORT_SetPinsAsOutput( &PORTA, 0xFF ); // Use one of the Xplained-A1 pins. SW4 - PD4 PORT_SetPinsAsInput( &PORTD, 0x10 ); // Check UART operation //testUartTx(); // Enable global interrupts. sei(); // Create a function pointer to use with the user uart (UARTC0). void (*puartBuf)(uint8_t* , uint8_t); // Assign that function pointer to the send data to RadioBlocks. puartBuf = &sendUARTF0; /////////////////////// TEST CODE ////////////////// #if 0 for(uint16_t i=0; i<CIRCSIZE; i++) sniffBuff[i] = 255; toggleLed(puartBuf, LED_TOGGLE, uartBuf); testRequest(puartBuf, uartBuf); setAddress(puartBuf, 0x1234, uartBuf); getAddress(puartBuf, uartBuf); sleepRequest(puartBuf, 1000, uartBuf); settingsRequest(puartBuf, uartBuf, RESTORE_CURRENT_SETTINGS); configureUART(puartBuf, DATA_BITS_8, PARITY_NONE, STOP_BITS_1, BAUD_115200, uartBuf); setPanid(puartBuf, 0x5678, uartBuf); getPanid(puartBuf, uartBuf); setChannel(puartBuf, CHANNEL_16, uartBuf); getChannel(puartBuf,uartBuf); setTRXState(puartBuf, TX_ON, uartBuf); getTRXState(puartBuf, uartBuf); dataRequest(puartBuf, 0x0001, DATA_OPTION_NONE, 0x42, 6, testBuf, uartBuf); setTxPower(puartBuf, TX_POWER_2_8_DBM, uartBuf); getTxPower(puartBuf, uartBuf); //setSecurityKey(puartBuf, uint8_t* key, uartBuf); // max 16 bytes. #endif toggleLed(puartBuf, LED_TOGGLE, uartBuf); processResponse(); usartUartPrint(); testRequest(puartBuf, uartBuf); processResponse(); usartUartPrint(); processResponse(); usartUartPrint(); setAddress(puartBuf, 0x1234, uartBuf); processResponse(); usartUartPrint(); getAddress(puartBuf, uartBuf); processResponse(); usartUartPrint(); processResponse(); usartUartPrint(); setPanid(puartBuf, 0x5678, uartBuf); processResponse(); usartUartPrint(); getPanid(puartBuf, uartBuf); processResponse(); usartUartPrint(); processResponse(); usartUartPrint(); setChannel(puartBuf, CHANNEL_16, uartBuf); processResponse(); usartUartPrint(); getChannel(puartBuf,uartBuf); processResponse(); usartUartPrint(); processResponse(); usartUartPrint(); // setTRXState(puartBuf, TX_ON, uartBuf); // processResponse(); // getTRXState(puartBuf, uartBuf); // processResponse(); // processResponse(); setTxPower(puartBuf, TX_POWER_2_8_DBM, uartBuf); processResponse(); usartUartPrint(); getTxPower(puartBuf, uartBuf); processResponse(); usartUartPrint(); processResponse(); usartUartPrint(); dataRequest(puartBuf, 0x0001, DATA_OPTION_NONE, 0x42, 6, testBuf, uartBuf); processResponse(); usartUartPrint(); setTRXState(puartBuf, RX_ON, uartBuf); processResponse(); usartUartPrint(); getTRXState(puartBuf, uartBuf); processResponse(); usartUartPrint(); processResponse(); usartUartPrint(); while(1) { processResponse(); usartUartPrint(); // Fun. // toggleLed(puartBuf, LED_TOGGLE, uartBuf); // timerLoop(100); // WARNING, can BLOCK a loooong time. // processResponse(); // testBuf[5]++; // setTRXState(puartBuf, TX_ON, uartBuf); // processResponse(); // dataRequest(puartBuf, 0x0001, DATA_OPTION_NONE, 0x42, 6, testBuf, uartBuf); // processResponse(); // setTRXState(puartBuf, RX_ON, uartBuf); // processResponse(); /* USER CODE HERE! */ } }
const QString &map::getTableText(bool colour) { QStringList tableTextList; double min = getZValues()->at(0); double max = getZValues()->at(getZValues()->length() - 1); double diff = max - min; int yAxisWidth = 0; if (axes[1]) { yAxisWidth = axes[1]->getWidth(); } int xAxisWidth = axes[0]->getWidth(); int valWidth = getWidth(); if (xAxisWidth > valWidth) { valWidth = xAxisWidth; } if (isDTC()) { valWidth = 2 * getWordSize() + 2; } QString mapText = "<b>Map " + formatHex(getAddress(), false, true) + ": " + label; if (units.length() != 0) { mapText += " (" + units + ")"; } mapText += "</b>"; tableTextList << mapText; if (!axes[0]->isFixed()) { QString axis1Text = "<b>X-Axis " + formatHex(axes[0]->getAddress(), false, true) + ": " + axes[0]->getLabel(); if (axes[0]->getUnits().length() != 0) { axis1Text += " (" + axes[0]->getUnits() + ")"; } axis1Text += "</b>"; tableTextList << axis1Text; } if (axes[1]) { QString axis2Text = "<b>Y-Axis " + formatHex(axes[1]->getAddress(), false, true) + ": " + axes[1]->getLabel(); if (axes[0]->getUnits().length() != 0) { axis2Text += " (" + axes[1]->getUnits() + ")"; } axis2Text += "</b>"; tableTextList << axis2Text; } tableTextList << ""; QString xLabels; if (yAxisWidth > 0) { xLabels.fill(QChar(' '), yAxisWidth + 1); } for (int i = 0; i < getXDim(); i++) { xLabels += QString("%1 ").arg(axisValue(0, i), valWidth, 'f', axes[0]->getDecimalPoints(), QChar(' ')); } xLabels = "<span style=\"text-decoration:underline; font-weight:bold;\">" + xLabels + "</span>"; tableTextList << xLabels; for (int y = 0; y < getYDim(); y++) { QString row; if (axes[1]) { int dp = axes[1]->getDecimalPoints(); row = QString("%1 ").arg(axisValue(1, y), yAxisWidth, 'f', dp, QChar(' ')); row = "<span style=\"font-weight:bold\">" + row + "</span>"; } for (int x = 0; x < getXDim(); x++) { int dp = getDecimalPoints(); if (isDTC()) { int val = getValue(x,y); row += "0x" + QString("%1 ").arg(val, valWidth-2, 16, QChar('0')).toUpper(); } else { double val = getValue(x, y); if (colour) { double temp = val - min; if (diff == 0) { temp = 1.0; } else { temp /= diff; } int red = 255*temp; int green = 255-255*temp; row += "<span style=\"background-color: rgb(" + QString::number(red) + "," + QString::number(green) + ",0);\">"; } else { row += "<span>"; } row += QString("%1 </span>").arg(val, valWidth, 'f', dp, QChar(' ')); } } tableTextList << row; } tableText = "<pre style=\"font-size:16px; color:black\">" + tableTextList.join("\n") + "</pre>"; return tableText; }
void Pololu::Interface::write(std::ostream& stream) const { stream << getAddress(); }
void secondPass(void) { /* Second pass */ /* While there is a command */ while(hasMoreCommands()) { /* Read the current command */ advance(); /* If there is a current command */ if(currentCommand[0] != '\0') { char string[LENGTH_MAX]; int returnCommandType; int bits[16]; int stringAddress; int indexBit; /* Get the type of the command */ returnCommandType = commandType(); /* If it is a A_COMMAND */ if(returnCommandType == A_COMMAND) { /* Get the symbol */ symbol(string); /* If the symbol is not a number */ if(isalpha(string[0])) { /* If string is already in the symbol table */ if(contains(string)) /* Get string's address */ stringAddress = getAddress(string); /* Else it is a new symbol */ else { /* Get the address */ stringAddress = RAMaddress; /* Add string to the symbol table */ addEntry(string, RAMaddress); /* Increment the next available RAM address */ ++RAMaddress; } } /* Else it is a number */ else /* Get string's address */ stringAddress = atoi(string); /* Transform it into binairy */ symbolBinary(stringAddress, bits); /* Put it into the hack file */ for(indexBit = 0; indexBit < 16; ++indexBit) fprintf(hackFile, "%d", bits[indexBit]); fprintf(hackFile, "\n"); } /* Else if it is a C_COMMAND */ else if(returnCommandType == C_COMMAND) { /* Put the 3 first bits to 1 in the hack file */ for(indexBit = 0; indexBit < 3; ++indexBit) fprintf(hackFile, "1"); /* Get the comp part */ compParser(string); /* Get the binairy */ comp(string, bits); /* Write the comp part into the hack file */ for(indexBit = 0; indexBit < 7; ++indexBit) fprintf(hackFile, "%d", bits[indexBit]); /* Get the dest part */ destParser(string); /* Get the binairy */ dest(string, bits); /* Write the dest part into the hack file */ for(indexBit = 0; indexBit < 3; ++indexBit) fprintf(hackFile, "%d", bits[indexBit]); /* Get the jump part */ jumpParser(string); /* Get the binairy */ jump(string, bits); /* Write the jump part into the hack file */ for(indexBit = 0; indexBit < 3; ++indexBit) fprintf(hackFile, "%d", bits[indexBit]); fprintf(hackFile, "\n"); } } } }
void decodeCommand(FlashBuffer *fb, uint8 *ptrTLV) { bufferHandler(getAddress(ptrTLV), getData(ptrTLV), getLength(ptrTLV), fb); }
int main(int argc, char **argv) { char *config = NULL; char *cmd = strrchr(argv[0], '/'); char *single = NULL; int status = 1; if(cmd == NULL) { cmd = argv[0]; } else { cmd++; } ServerRoot[0] = '\0'; while(argc >= 1) { if(strcmp(*argv,"-c") == 0) { if (--argc >= 1) { config = *(++argv); } } else if(strcmp(*argv,"-i") == 0) { if (--argc >= 1) { single = *(++argv); } } else if(strcmp(*argv,"-v") == 0) { m_verbose = 1; } argc--; argv++; } if(single) { char *hostName = single; char *portNumber = strchr(single, ':'); if(portNumber) { unsigned long addr; int prt; portNumber[0] = '\0'; portNumber++; addr = getAddress(hostName); prt = atoi(portNumber); if(addr && prt) { if(ping(addr, prt)) { if(m_verbose) { printf("[%s]: %s:%d Up\n", cmd, hostName, prt); } status = 1; } else { printf("[%s]: %s:%d Down\n", cmd, hostName, prt); status = 0; } } else { // could not resolve fprintf(stderr,"[%s]: ERROR, unknown host/port\n", cmd); status = 0; } } else { // invalid input fprintf(stderr,"[%s]: ERROR, invalid format\n", cmd); status = 0; } } else { if(config == NULL) { usage(cmd); } status = checkFile(cmd, config); } if(status == 0) { fprintf(stderr,"[%s]: ERROR, check failed\n", cmd); exit(1); } printf("[%s]: OK, check successful\n", cmd); return 0; }
void AddressBookPluginWidget::refresh( const Opie::OPimContactAccess* ) { owarn << " AddressBookPluginWidget::Database was changed externally ! " << oendl; m_contactdb->reload(); getAddress(); }
// sends command for one device to perform a temp conversion by index bool DallasTemperature::requestTemperaturesByIndex(uint8_t deviceIndex) { DeviceAddress deviceAddress; getAddress(deviceAddress, deviceIndex); return requestTemperaturesByAddress(deviceAddress); }
// Fetch temperature for device index float DallasTemperature::getTempCByIndex(uint8_t deviceIndex) { DeviceAddress deviceAddress; getAddress(deviceAddress, deviceIndex); return getTempC((uint8_t*)deviceAddress); }
/* * Checks a single host (parse host string, resolve address, ping). */ static int checkHost(const char *cmd, const char *filename, int ln, char *abs_url) { int status = 1; char *schema = abs_url; char *host = NULL; char *ports = NULL; int port = 0; char hp[1024]; unsigned long address; char *x = strstr(abs_url, "://"); if(x == NULL) { if(m_verbose) { fprintf(stderr,"[%s]: ERROR, wrong syntax <%s> in %s on line %d\n", cmd, abs_url, filename, ln); } return 0; } x[0] = '\0'; x = x + strlen("://"); host = x; ports = strchr(x, ':'); if(ports != NULL) { ports[0] = '\0'; ports++; x = strchr(ports, '/'); if(x == NULL) { int i; x = ports; for(i=0;(x[i] != ' ') && (x[i] != '\t') && (x[i] != '\0'); i++); x[i] = '\0'; } else { x[0] = '\0'; } port = atoi(ports); } else { ports = strchr(x, '/'); if(ports == NULL) { int i; for(i=0;(x[i] != ' ') && (x[i] != '\t') && (x[i] != '\0'); i++); x[i] = '\0'; } else { ports[0] = '\0'; } if(strcmp(schema, "http") == 0) { port = 80; } else { port = 443; } } /* check each host only once */ snprintf(hp, sizeof(hp), "#%s:%d#", host, port); if(checkedHosts && strstr(checkedHosts, hp) != NULL) { /* already checked */ return 1; } if(checkedHosts == NULL) { checkedHosts = calloc(1, strlen(hp) + 1); strcpy(checkedHosts, hp); } else { int pl = strlen(checkedHosts) +strlen(hp) + 1; char *p = calloc(1, pl); snprintf(p, pl, "%s%s", checkedHosts, hp); free(checkedHosts); checkedHosts = p; } /* resolve address */ address = getAddress(host); if(address == 0L) { fprintf(stderr,"[%s]: ERROR, could not resolve hostname %s\n", cmd, host); return -1; } /* check connection */ if(ping(address, port)) { if(m_verbose) { printf("[%s]: %s:%d Up\n", cmd, host, port); } return 1; } else { printf("[%s]: %s:%d Down\n", cmd, host, port); return 0; } }