int main( void ) { halInit(); printf("\r\n****************************************************\r\n"); printf("Simple Application Example - COORDINATOR - using AFZDO\r\n"); HAL_ENABLE_INTERRUPTS(); startZnp(COORDINATOR); printf("On Network!\r\n"); /* On network, display info about this network */ getNetworkConfigurationParameters(); getDeviceInformation(); /* Now the network is running - wait for any received messages from the ZNP */ #ifdef VERBOSE_MESSAGE_DISPLAY printAfIncomingMsgHeaderNames(); #endif while (1) { while (SRDY_IS_HIGH()); //wait until SRDY goes low indicating a message has been received. displayMessages(); } }
void LoggingHandler::handleRequest(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response) { bool reauth = true; if (request.hasCredentials()) { std::string cred; std::string scheme; try { Poco::Net::HTTPBasicCredentials cred(request); std::string user = cred.getUsername(); std::istringstream istr(cred.getPassword(), std::ios::binary); Poco::MD5Engine md5; Poco::DigestOutputStream dos(md5); Poco::StreamCopier::copyStream(istr, dos); dos.close(); std::string pwd = Poco::DigestEngine::digestToHex(md5.digest()); reauth = (pwd != _pwdHash || _user != user); } catch (...) { reauth = true; } } if (reauth) { response.requireAuthentication(TITLE); response.send(); return; } Poco::Net::HTMLForm form(request); std::string offsetStr; Poco::Net::NameValueCollection::ConstIterator it = form.find(OFFSET); if (it != form.end()) offsetStr = it->second; int offset(0); Poco::NumberParser::tryParse(offsetStr, offset); std::string numEntriesStr; it = form.find(NUMENTRIES); if (it != form.end()) numEntriesStr = it->second; int numEntries = DEFAULT_NUMENTRIES; Poco::NumberParser::tryParse(numEntriesStr, numEntries); std::vector<Poco::Message> messages; _channel.getMessages(messages, offset, numEntries); displayMessages(messages, offset, numEntries, _channel.getCurrentSize(), response); }
void SqlScanResultProcessor::scanSucceeded() { DEBUG_BLOCK; // we are blocking the updated signal for maximum of one second. m_blockedTime = QDateTime::currentDateTime(); blockUpdates(); urlsCacheInit(); // -- call the base implementation AbstractScanResultProcessor::scanSucceeded(); // -- error reporting m_messages.append( m_collection->sqlStorage()->getLastErrors() ); if( !m_messages.isEmpty() && QApplication::type() != QApplication::Tty ) QTimer::singleShot(0, this, SLOT(displayMessages())); // do in the UI thread unblockUpdates(); }
static void stateMachine() { while (1) { if (zigbeeNetworkStatus == NWK_ONLINE) { if(moduleHasMessageWaiting()) //wait until SRDY goes low indicating a message has been received. displayMessages(); } switch (state) { case STATE_IDLE: { /* process command line commands only if not doing anything else: */ if (command != NO_CHARACTER_RECEIVED) { /* parse the command entered, and go to the required state */ state = processCommand(command); command = NO_CHARACTER_RECEIVED; } /* note: other flags (for different messages or events) can be added here */ break; } case STATE_INIT: { printf("Starting State Machine\r\n"); state = STATE_GET_DEVICE_TYPE; break; } /* A button press during startup will cause the application to prompt for device type */ case STATE_GET_DEVICE_TYPE: { //printf("Current Configured DeviceType: %s\r\n", getDeviceTypeName()); set_type: /* if saving device type to flash memory: printf("Any other key to exit. Timeout in 5 seconds.\r\n"); / long wait = 0; long timeout = TICKS_IN_ONE_MS * 5000l; while ((command == NO_CHARACTER_RECEIVED) && (wait != timeout)) wait++; */ while (command == NO_CHARACTER_RECEIVED) { printf("Setting Device Type: Press C for Coordinator, R for Router, or E for End Device.\r\n"); delayMs(2000); } switch (command) { case 'C': case 'c': printf("Coordinator it is...\r\n"); zigbeeDeviceType = COORDINATOR; break; case 'R': case 'r': printf("Router it is...\r\n"); zigbeeDeviceType = ROUTER; break; case 'E': case 'e': printf("End Device it is...\r\n"); zigbeeDeviceType = END_DEVICE; break; default: command = NO_CHARACTER_RECEIVED; goto set_type; } command = NO_CHARACTER_RECEIVED; state = STATE_MODULE_STARTUP; break; } case STATE_MODULE_STARTUP: { #define MODULE_START_DELAY_IF_FAIL_MS 5000 moduleResult_t result; /* Start with the default module configuration */ struct moduleConfiguration defaultConfiguration = DEFAULT_MODULE_CONFIGURATION_COORDINATOR; /* Make any changes needed here (channel list, PAN ID, etc.) We Configure the Zigbee Device Type (Router, Coordinator, End Device) based on what user selected */ defaultConfiguration.deviceType = zigbeeDeviceType; while ((result = startModule(&defaultConfiguration, GENERIC_APPLICATION_CONFIGURATION)) != MODULE_SUCCESS) { printf("Module start unsuccessful. Error Code 0x%02X. Retrying...\r\n", result); delayMs(MODULE_START_DELAY_IF_FAIL_MS); } printf("Success\r\n"); state = STATE_DISPLAY_NETWORK_INFORMATION; zigbeeNetworkStatus = NWK_ONLINE; break; } case STATE_DISPLAY_NETWORK_INFORMATION: { printf("Module Information:\r\n"); /* On network, display info about this network */ displayNetworkConfigurationParameters(); displayDeviceInformation(); displayCommandLineInterfaceHelp(); state = STATE_IDLE; //startup is done! break; } case STATE_VALID_SHORT_ADDRESS_ENTERED: //command line processor has a valid shortAddressEntered { printf("Valid Short Address Entered\r\n"); state = pendingState; break; } case STATE_VALID_LONG_ADDRESS_ENTERED: { /* flip byte order */ int8_t temp[8]; int i; for (i=0; i<8; i++) temp[7-i] = longAddressEntered[i]; memcpy(longAddressEntered, temp, 8); //Store LSB first since that is how it will be sent: state = pendingState; break; } case STATE_SEND_MESSAGE_VIA_SHORT_ADDRESS: { printf("Send via short address to %04X\r\n", shortAddressEntered); moduleResult_t result = afSendData(DEFAULT_ENDPOINT,DEFAULT_ENDPOINT,shortAddressEntered, TEST_CLUSTER, testMessage, 5); if (result == MODULE_SUCCESS) { printf("Success\r\n"); } else { printf("Could not send to that device (Error Code 0x%02X)\r\n", result); #ifdef RESTART_AFTER_ZM_FAILURE printf("\r\nRestarting\r\n"); state = STATE_MODULE_STARTUP; continue; #endif } state = STATE_IDLE; break; } case STATE_SEND_MESSAGE_VIA_LONG_ADDRESS: { printf("Send via long address to (LSB first)"); printHexBytes(longAddressEntered, 8); moduleResult_t result = afSendDataExtended(DEFAULT_ENDPOINT, DEFAULT_ENDPOINT, longAddressEntered, DESTINATION_ADDRESS_MODE_LONG, TEST_CLUSTER, testMessage, 5); if (result == MODULE_SUCCESS) { printf("Success\r\n"); } else { printf("Could not send to that device (Error Code 0x%02X)\r\n", result); #ifdef RESTART_AFTER_ZM_FAILURE printf("\r\nRestarting\r\n"); state = STATE_MODULE_STARTUP; continue; #endif } state = STATE_IDLE; break; } case STATE_FIND_VIA_SHORT_ADDRESS: { printf("Looking for that device...\r\n"); moduleResult_t result = zdoRequestIeeeAddress(shortAddressEntered, SINGLE_DEVICE_RESPONSE, 0); if (result == MODULE_SUCCESS) { #ifndef ZDO_NWK_ADDR_RSP_HANDLED_BY_APPLICATION displayZdoAddressResponse(zmBuf + SRSP_PAYLOAD_START); #endif } else { printf("Could not locate that device (Error Code 0x%02X)\r\n", result); } state = STATE_IDLE; break; } case STATE_FIND_VIA_LONG_ADDRESS: { printf("Looking for that device...\r\n"); moduleResult_t result = zdoNetworkAddressRequest(longAddressEntered, SINGLE_DEVICE_RESPONSE, 0); if (result == MODULE_SUCCESS) { #ifndef ZDO_NWK_ADDR_RSP_HANDLED_BY_APPLICATION displayZdoAddressResponse(zmBuf + SRSP_PAYLOAD_START); #endif } else { printf("Could not locate that device (Error Code 0x%02X)\r\n", result); } state = STATE_IDLE; break; } default: //should never happen { printf("UNKNOWN STATE (%u)\r\n", state); state = STATE_IDLE; } break; } } }
int clientSide(const char *nodeMasterHostname) { int serverFd, portno, bytes, end; struct sockaddr_in serv_addr; struct hostent *server; struct message *temp; char *buffer = (char *)malloc(strlen(CONNECT_REQUEST_MESSAGE) + 1); /* Initializing*/ snprintf(buffer, strlen(CONNECT_REQUEST_MESSAGE) + 1, CONNECT_REQUEST_MESSAGE); portno = 5101; end = 0; /* Opening Socket */ if ((serverFd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { perror("ERROR opening socket"); exit(1); } /* Validating Server existence*/ server = gethostbyname(nodeMasterHostname); if (server == NULL) { fprintf(stderr,"ERROR, no such host\n"); exit(0); } /* Initializing Internet structures*/ memset((char *) &serv_addr, 0, sizeof(serv_addr)); memcpy(&serv_addr.sin_addr, server->h_addr, server->h_length); serv_addr.sin_family = AF_INET; serv_addr.sin_port = htons(portno); printf("Establishing connection with %s at port %d\n", nodeMasterHostname, portno); if (connect(serverFd, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0) { perror("ERROR connecting"); exit(1); } else { printf("Connected succesfuly through socket file descriptor %d\n", serverFd); } printf("Sending CONNECT_REQUEST_MESSAGE: %s.\n", buffer); bytes = writeSocket(serverFd, buffer, 2, 1); while (1) { bytes = 0; buffer = readSocket(serverFd, 1, 1, &bytes); if (strcmp(buffer, START_MESSAGE) == 0) { end = 1; printf("received START_MESSAGE\n"); controllerBenchmarking(); displayMessages(myreport, VALUES); displayMessages(myreport, AVGS); displayMessages(myreport, RESULTS); snprintf(buffer, strlen(REPORT_MESSAGE) + 1, REPORT_MESSAGE); writeSocket(serverFd, buffer, 2 , 1); printf("sent REPORT_MESSAGE\n"); //Sending Values temp = myreport->queues[VALUES].first; while (temp != NULL) { bytes = writeSocket(serverFd, temp->buffer, strlen(temp->buffer), strlen(temp->buffer)); temp = temp->back; } //Sending Partials temp = myreport->queues[AVGS].first; while (temp != NULL) { bytes = writeSocket(serverFd, temp->buffer, strlen(temp->buffer), strlen(temp->buffer)); temp = temp->back; } //Sending Results temp = myreport->queues[RESULTS].first; while (temp != NULL) { bytes = writeSocket(serverFd, temp->buffer, strlen(temp->buffer), strlen(temp->buffer)); temp = temp->back; } //free(myreport); printf("End of transmission\n"); } else { printf("received: '%s'\n",buffer); perror("Uknown message for distributed mode"); exit(1); } buffer = NULL; if (end) break; } //TODO: Replace this way to ensure data sending, at least remove this for and // remove end = 1 breaking sentence for (;;){ } shutdown(serverFd, SHUT_WR); return 0; }
void MainWindow::updateMain(MainWindowStates state) { switch (state) { case UPDATE: displayMessages(); break; case NOTHING: userExtraActions ->setEnabled(false); menu_Exercise ->setEnabled(false); bar_Exercise ->setEnabled(false); exerciseExtraActions->setEnabled(false); menu_Try ->setEnabled(false); bar_Try ->setEnabled(false); statusBar()->showMessage(tr("Need User")); displayMessages(); break; case USER: userExtraActions ->setEnabled(true); menu_Exercise ->setEnabled(true); exerciseExtraActions->setEnabled(false); bar_Exercise ->setEnabled(true); menu_Try ->setEnabled(false); bar_Try ->setEnabled(false); tempoDisplay->clear(); statusBar()->showMessage(tr("Need Exercise")); displayMessages(); break; case EXERCISE: menu_Exercise ->setEnabled(true); exerciseExtraActions->setEnabled(true); menu_Try ->setEnabled(true); bar_Try ->setEnabled(true); // shouldn't be necessary, but it is. :( metro_ ->setEnabled(true); tempoDisplay ->setEnabled(true); statusBar()->showMessage(tr("Ready")); displayMessages(); break; case PAUSED: action_Toggle_Try->setIcon(QIcon(":/icons/player_play.png")); action_Toggle_Try->setStatusTip(tr("Start")); menu_User ->setEnabled(true); menu_Exercise ->setEnabled(true); bar_User ->setEnabled(true); bar_Exercise ->setEnabled(true); tryExtraActions ->setEnabled(true); statusBar()->showMessage(tr("Ready")); displayMessages(); break; case RUNNING: action_Toggle_Try->setIcon(QIcon(":/icons/player_pause.png")); action_Toggle_Try->setStatusTip(tr("Stop")); menu_User ->setEnabled(false); bar_User ->setEnabled(false); menu_Exercise ->setEnabled(false); bar_Exercise ->setEnabled(false); tryExtraActions ->setEnabled(false); statusBar()->showMessage(tr("Running Exercise")); displayMessages(); break; } }