void MainWindow::on_campaign_id_textChanged() { if ( ui->campaign_id->text() != "" ) { // change the global profile vApp->set_id_campaign(ui->campaign_id->text()); fill_links(); ui->btn_add_link->setHidden(false); // call the widget add_campaign *widget = new add_campaign; ui->scrollArea->setWidget(widget); setWindowTitle("Posodobitev obstojece kampanije"); QObject::connect(this, SIGNAL(send(QString)), widget , SLOT(recieve(QString))); send(ui->campaign_id->text()); // id of currently selected profile this->disconnect(); // receive signal to refresh profile combo box QObject::connect(widget, SIGNAL(send(QString)), this , SLOT(recieve(QString))); } else { // clear the widget placeholder vApp->set_id_campaign(""); on_new_campaign_clicked(); fill_links(); ui->btn_add_link->setHidden(true); } }
void SoftwareGatewayEventClient::performService(ConnectionManager* conn){ SimMsg* simMsg = (SimMsg*)buffer; recieve(buffer,TOS_SIM_HEADER_LENGTH); if (recieved != TOS_SIM_HEADER_LENGTH) { printf("WARNING: got incorrect sim message header length: %d\n",recieved); } // Make sure we read the entire payload // Note that we may be reading a payload that is not a tos msg! unsigned char* currentPos = (unsigned char*) &(simMsg->msg); int remainingBytes = ntohs(simMsg->payloadLength); while (remainingBytes > 0) { recieve(currentPos, remainingBytes); remainingBytes -= recieved; currentPos += recieved; } unsigned char ack = 0; this->send(&ack,1); if (simMsg->msgType == RADIO_EVENT){ HexUtil::printHexString("From Sim Radio",(unsigned char *)&(simMsg->msg),TOS_MESSAGE_LENGTH); for (int i = 0; i < conn->connections; i++){ if (NodeClient* node = dynamic_cast<NodeClient*>(conn->deviceList[i])){ node->send((unsigned char*)&(simMsg->msg),RADIO_PACKET_LENGTH); continue; } if (SerialClient* node = dynamic_cast<SerialClient*>(conn->deviceList[i])){ node->send((unsigned char*)&(simMsg->msg),RADIO_PACKET_LENGTH); } } } else if (simMsg->msgType == UART_EVENT){ HexUtil::printHexString("From Sim Uart",(unsigned char *)&(simMsg->msg),TOS_MESSAGE_LENGTH); for (int i = 0; i < conn->connections; i++){ // if (NodeClient* node = dynamic_cast<NodeClient*>(conn->deviceList[i])){ // node->send((unsigned char*)&(simMsg->msg),RADIO_PACKET_LENGTH); // continue; // } if (AppClient* node = dynamic_cast<AppClient*>(conn->deviceList[i])) node->send((unsigned char*)&(simMsg->msg),RADIO_PACKET_LENGTH); } } }
void CanAccess::loop() { CanMessage* msg = recieve(); if (msg == NULL) return; handleMessage(*msg, msg->isRTR(), NULL); }
void MainWindow::on_new_campaign_clicked() { ui->campaign_name->setCurrentIndex(0); add_campaign *widget = new add_campaign; ui->scrollArea->setWidget(widget); setWindowTitle("Vnos nove Kampanije"); QObject::connect(this, SIGNAL(send(QString)), widget , SLOT(recieve(QString))); send("0"); // 0 == new this->disconnect(); // receive signal to refresh profile combo box QObject::connect(widget, SIGNAL(send(QString)), this , SLOT(recieve(QString))); }
int main (void) { struct sockaddr_in server = { AF_INET, 7001 }; /* convert and store the server's IP address */ server.sin_addr.s_addr = inet_addr ("10.100.93.58"); /* set up the transport end point */ if ((sockfd = socket (AF_INET, SOCK_STREAM, 0)) == -1) { perror ("socket call failed"); exit (1); } /* connect the socket to the server's address */ if (connect (sockfd, (struct sockaddr *) &server, SIZE) == -1) { perror ("connect call failed"); exit (1); } firstconn (); /* send and receive information with the server */ //pthread_create(&thrd1, NULL,getmsg ,NULL); // handle data from a client //pthread_join(thrd1, NULL); recieve (); pthread_create (&thrd2, NULL, getmsg, NULL); // handle data from a client pthread_join (thrd2, NULL); }
char ctrl_recieve_state() { char state = '\0'; usart_init(); state = recieve(); return state; }
void MainWindow::on_tbl_links_doubleClicked() { // call the widget AddLink *widget = new AddLink; ui->scrollArea->setWidget(widget); setWindowTitle("Vnos nove povezave"); QObject::connect(this, SIGNAL(send(QString)), widget , SLOT(recieve(QString))); send(ui->tbl_links->selectedItems().takeAt(0)->text()); // id of currently selected profile this->disconnect(); // receive signal to refresh profile combo box QObject::connect(widget, SIGNAL(send(QString)), this , SLOT(recieve(QString))); }
std::string Network::recieve(void) { ssize_t ret; char buf[BUFF_SIZE] = { '\0' }; ret = recv(_socket_connect, buf, BUFF_SIZE - 1, 0); switch (ret) { case -1: std::cout << strerror(errno) << std::endl; break ; case 0: this->close(); break ; default: _client->printDebug(buf); if (!strncmp(buf, MSG_DEATH.c_str(), 5)) _client->hasDied(); else if (!strncmp(buf, MSG_BROADCAST.c_str(), 7)) { _client->recieveBroadcast(buf); _client->printDebug("Broadcast recieved ! Recieving again..."); return recieve(); } return buf; } return MSG_FAILURE; }
void main() { int l,i; P1=0x00; lcdin(); TMOD=0x20; //Enable Timer 1 TH1=0XFD; SCON=0x50; TR1=1; gsmcmdsend(gsm_cmd3); cmm(0x01); gsmcmdsend(gsm_cmd4); cmm(0x01); cmm(0x85); for(i=0;i<5;i++) {dat(header[i]);} cmm(0xc0); while(1) { recieve(); l=0; cmm(0x01); for(l=0;l<count;l++) { if(card_id[l] == '\0') break; dat(card_id[l]); } } }
void Client::msg_grass(char msg) { unsigned char data[17*17]; // Recieve all tiles recieve(data, sizeof(data)); SDL_LockMutex(mutex); // Extrapolate edges /* for (int x = 0; x < 17; ++x) grass[x + 1] = grass[19 + x + 1]; for (int x = 0; x < 17; ++x) grass[18*19 + x + 1] = grass[17*19 + x + 1]; for (int y = 0; y < 19; ++y) grass[y*19] = grass[y*19 + 1]; for (int y = 0; y < 19; ++y) grass[y*19+18] = grass[y*19 + 17]; */ // Write new tiles int i = 0; for (int y = 1; y < 18; ++y) { for (int x = 1; x < 18; ++x) { grass(x, y) = data[i++]; } } SDL_UnlockMutex(mutex); }
void ctrl_recieve_data(unsigned char* container) { char i ; usart_init(); for(i = 0; i < PW_LENGTH; i++) { container[i] = recieve(); } }
float PZEM004T::power(const IPAddress &addr) { uint8_t data[RESPONSE_DATA_SIZE]; send(addr, PZEM_POWER); if(!recieve(RESP_POWER, data)) return PZEM_ERROR_VALUE; return (data[0] << 8) + data[1]; }
float PZEM004T::voltage(const IPAddress &addr) { uint8_t data[RESPONSE_DATA_SIZE]; send(addr, PZEM_VOLTAGE); if(!recieve(RESP_VOLTAGE, data)) return PZEM_ERROR_VALUE; return (data[0] << 8) + data[1] + (data[2] / 10.0); }
void session::recievePacket() { //reads packet size first if(incomingBytes == 0 && sessionSocket->bytesAvailable() >= 4) { QByteArray bArray = sessionSocket->read(4); QDataStream recieve(&bArray, QIODevice::ReadOnly); //recieve.setVersion(QDataStream::Qt_5_1); recieve >> incomingBytes; qDebug() << "incomingBytes: " << incomingBytes; }
float PZEM004T::energy(const IPAddress &addr) { uint8_t data[RESPONSE_DATA_SIZE]; send(addr, PZEM_ENERGY); if(!recieve(RESP_ENERGY, data)) return PZEM_ERROR_VALUE; return ((uint32_t)data[0] << 16) + ((uint16_t)data[1] << 8) + data[2]; }
float PZEM004T::current(const IPAddress &addr) { uint8_t data[RESPONSE_DATA_SIZE]; send(addr, PZEM_CURRENT); if(!recieve(RESP_CURRENT, data)) return PZEM_ERROR_VALUE; return (data[0] << 8) + data[1] + (data[2] / 100.0); }
// Actions void MainWindow::on_profile_id_textChanged() { if ( ui->profile_id->text() != "" ) { // change the global profile vApp->set_id_profile(ui->profile_id->text()); vApp->set_id_campaign(""); // set campaign forms to visible and refresh campaign combo box ui->label_2->setHidden(false); ui->campaign_name->setHidden(false); ui->new_campaign->setHidden(false); // fill campaign combo box fill_campaigns(); // call the widget add_profile *widget = new add_profile; ui->scrollArea->setWidget(widget); setWindowTitle("Posodobitev obstojecega profila"); QObject::connect(this, SIGNAL(send(QString)), widget , SLOT(recieve(QString))); send(ui->profile_id->text()); // id of currently selected profile this->disconnect(); // receive signal to refresh profile combo box QObject::connect(widget, SIGNAL(send(QString)), this , SLOT(recieve(QString))); } else { // clear the widget placeholder on_new_profile_clicked(); // hide all the campaign fields until the profile is not selected ui->label_2->setHidden(true); ui->campaign_name->setHidden(true); ui->new_campaign->setHidden(true); ui->btn_add_link->setHidden(true); ui->campaign_name->clear(); vApp->set_id_campaign(""); vApp->set_id_profile(""); fill_links(); } }
void MainWindow::on_btn_add_link_clicked() { if ( vApp->id_user() != "" && vApp->id_profile() != "" && vApp->id_campaign() != "" ) { // change the global profile vApp->set_id_campaign(ui->campaign_id->text()); fill_links(); // call the widget AddLink *widget = new AddLink; ui->scrollArea->setWidget(widget); setWindowTitle("Vnos nove povezave"); QObject::connect(this, SIGNAL(send(QString)), widget , SLOT(recieve(QString))); send("0"); // id of currently selected profile this->disconnect(); // receive signal to refresh profile combo box QObject::connect(widget, SIGNAL(send(QString)), this , SLOT(recieve(QString))); } else if ( vApp->id_user() == "" ) { QMessageBox msgbox; msgbox.setText("Uporabnisko ime ni nastavljeno!"); msgbox.exec(); } else if ( vApp->id_profile() == "" ) { QMessageBox msgbox; msgbox.setText("Profil strani ni nastavljen!"); msgbox.exec(); } else if ( vApp->id_campaign() == "" ) { QMessageBox msgbox; msgbox.setText("Kampanija ni nastavljena!"); msgbox.exec(); } else { QMessageBox msgbox; msgbox.setText("Prislo je do napake! Postopek se bo prekinil!"); msgbox.exec(); } }
void Client::msg_background_color(char msg) { char data[3]; recieve(data, sizeof(data)); SDL_LockMutex(mutex); bgcolor_r = ((unsigned char)data[0])/255.0f; bgcolor_g = ((unsigned char)data[1])/255.0f; bgcolor_b = ((unsigned char)data[2])/255.0f; SDL_UnlockMutex(mutex); }
void Client::msg_remove(char msg) { Uint16 data[1]; recieve(data, sizeof(data)); SDL_LockMutex(mutex); entities.erase(SDLNet_Read16(data)); SDL_UnlockMutex(mutex); //printf("entity %d with texture %d removed\n", (int)data[0], (int)data[5]); }
int Client::listen() { // map av metod-pekare // Type of callback methods a pointer to a method of Client that recieves a char typedef void (Client::*msg_callback)(char msg); std::map<char, msg_callback> callbacks; //std::map<char, void (Client::*)(char)> callbacks; callbacks['g'] = &Client::msg_grass; callbacks['a'] = &Client::msg_add; callbacks['A'] = &Client::msg_add; callbacks['r'] = &Client::msg_remove; callbacks['R'] = &Client::msg_remove; callbacks['m'] = &Client::msg_move; callbacks['M'] = &Client::msg_move; callbacks['s'] = &Client::msg_scroll; callbacks['S'] = &Client::msg_scroll; callbacks['i'] = &Client::msg_change_image; callbacks['I'] = &Client::msg_change_image; callbacks['b'] = &Client::msg_background_color; callbacks['B'] = &Client::msg_background_color; callbacks['h'] = &Client::msg_hud; callbacks['c'] = &Client::msg_clear; char last_msg = ' '; try { for(;;) { char msg; recieve(&msg, 1); #define CALL_MEMBER_FN(object,ptrToMember) ((object).*(ptrToMember)) typeof(callbacks.begin()) it = callbacks.find(msg); if (it != callbacks.end()) { last_msg = msg; (this->*(it->second))(msg); //CALL_MEMBER_FN(*this, it->second)(msg); } else printf("unknown packet type: %c (%d) after last known command: %c\n", msg, (int)((unsigned char)(msg)), last_msg); } } catch (...) { return 0; } }
HttpResponse HttpClient::send_request(const HttpRequest& http_request) { if(!connected){ connect(); } send(http_request); HttpResponse http_response = recieve(20); if(http_response[Header::CONNECTION] == "close"){ disconnect(); } return http_response; }
bool ClientSocket::recieveSize(int size){ recieve(&buffer[pos],size-pos); pos += recieved; if (pos < size){ return false; } pos = 0; return true; }
void Client::msg_change_image(char msg) { Uint16 data[4]; recieve(data, sizeof(data)); Uint16 id = SDLNet_Read16(data); Sint16 w = (Sint16) SDLNet_Read16(data+1); Sint16 h = (Sint16) SDLNet_Read16(data+2); Sint16 tex = (Sint16) SDLNet_Read16(data+3); SDL_LockMutex(mutex); entities[id].change_image(w, h, tex); SDL_UnlockMutex(mutex); }
void Client::msg_move(char msg) { Uint16 data[4]; recieve(data, sizeof(data)); Uint16 id = SDLNet_Read16(data); Sint16 x = (Sint16) SDLNet_Read16(data+1); Sint16 y = (Sint16) SDLNet_Read16(data+2); Sint16 z = (Sint16) SDLNet_Read16(data+3); SDL_LockMutex(mutex); entities[id].move(x, y, z, msg == 'M'); SDL_UnlockMutex(mutex); }
int main(void) { GPIO_registers(); USART_registers(); send_string("KRSSG\n"); send_string("READY TO RECIEVE\n"); while(1) { data = recieve(); if(data=='A') GPIO_SetBits(GPIOD,GPIO_Pin_12); else if(data=='Z') GPIO_ResetBits(GPIOD,GPIO_Pin_12); } }
void Client::msg_hud(char msg) { Uint16 data[7]; recieve(data, sizeof(data)); Uint16 id = SDLNet_Read16(data); Sprite s((Sint16) SDLNet_Read16(data+1), (Sint16) SDLNet_Read16(data+2), (Sint16) SDLNet_Read16(data+3), (Sint16) SDLNet_Read16(data+4), (Sint16) SDLNet_Read16(data+5), SDLNet_Read16(data+6)); SDL_LockMutex(mutex); hud_sprites[id] = s; SDL_UnlockMutex(mutex); //printf("entity %d with texture %d added on (%d,%d)\n", id, e.tex, e.x, e.y); }
int Game::test_move(int x, int y) { string str; str = "valida_jogada(" + to_string() + ","; str.push_back(pawn[select_pawn].pos[1] + '0'); str.push_back(','); str.push_back(pawn[select_pawn].pos[0] + '0'); str.push_back(','); str.push_back(y + '0'); str.push_back(','); str.push_back(x + '0'); str.push_back(','); str.push_back(pawn[select_pawn].owner + '0'); str += ").\n"; send((char*) str.c_str(), str.size()); char res[256]; int n = recieve(res); if (res[0] == '0') return 0; else return 1; }
std::string Network::send(const std::string &message) { if (_connected) { std::string toSend = message; toSend += "\n"; _client->printDebug(message); if (::send(_socket_connect, toSend.c_str(), toSend.size(), 0) < 0) { std::cout << strerror(errno) << std::endl; return MSG_FAILURE; } return recieve(); } std::cout << "Couldn't send message \"" << message << "\" ! Not connected." << std::endl ; exit(EXIT_FAILURE); return MSG_FAILURE; }
//////////////////////////////////////////////////////////////////////////////////////////////////////// // // Main Task // //////////////////////////////////////////////////////////////////////////////////////////////////////// task main() { // Setup string sFriendlyName; getFriendlyName(sFriendlyName); IAmNXT = sFriendlyName == "HRF2" ? 0 : 1; MaxNXT = 2; setupHighSpeedLink(); // eraseDisplay(); bNxtLCDStatusDisplay = true; // Enable top status line display nxtDisplayTextLine(2, "IAmNXT: %d MAX: %d", IAmNXT, MaxNXT); if ( IAmNXT == 0 ) { send(); } else { recieve(); } }