void main() { mode = MODE_LEGACY; //Init the chip ID initId(); //Init the led and set the leds until the usb is not ready #ifndef CRPA ledInit(CR_LED_RED, CR_LED_GREEN); #else ledInit(CRPA_LED_RED, CRPA_LED_GREEN); #endif ledSet(LED_GREEN | LED_RED, true); // Initialise the radio #ifdef CRPA // Enable LNA (PA RX) P0DIR &= ~(1<<CRPA_PA_RXEN); P0 |= (1<<CRPA_PA_RXEN); #endif radioInit(RADIO_MODE_PTX); #ifdef PPM_JOYSTICK // Initialise the PPM acquisition ppmInit(); #endif //PPM_JOYSTICK // Initialise and connect the USB usbInit(); //Globally activate the interruptions IEN0 |= 0x80; //Wait for the USB to be addressed while (usbGetState() != ADDRESS); //Reset the LEDs ledSet(LED_GREEN | LED_RED, false); //Wait for the USB to be ready while (usbGetState() != CONFIGURED); //Activate OUT1 OUT1BC=0xFF; while(1) { if (mode == MODE_LEGACY) { // Run legacy mode legacyRun(); } else if (mode == MODE_CMD) { // Run cmd mode cmdRun(); } else if (mode == MODE_PRX) { // Run PRX mode prxRun(); } //USB vendor setup handling if(usbIsVendorSetup()) handleUsbVendorSetup(); } }
void UI::run() { string word; string inputline; // user validate commands //while (printf("\033[35mUsername for 'tinyFTP': \033[0m"), getline(std::cin, inputline)) while (printf("Username for 'tinyFTP': "), getline(std::cin, inputline)) { // clear cmdVector each time when user input this->cmdVector.clear(); std::istringstream is(inputline); while(is >> word) this->cmdVector.push_back(word); // if user enter nothing, assume special anonymous user if (this->cmdVector.empty()) { this->cmdVector.push_back("anonymous"); this->cmdVector.push_back("anonymous"); if (!cliPI.cmdPASS(this->cmdVector)) { continue; } else { break; } } if (!cliPI.cmdUSER(this->cmdVector)) { continue; } else { char *password = getpass("\033[35mPassword for 'tinyFTP': \033[0m"); // printf("\033[35mPassword for 'tinyFTP': \033[0m"); // getline(std::cin, inputline); // std::istringstream isPass(inputline); // while(isPass >> word) // { // this->cmdVector.push_back(word); // //std::cout << word << endl; // } this->cmdVector.push_back(password); if (!cliPI.cmdPASS(this->cmdVector)) { continue; } else { break; } } } this->username = this->cmdVector[0]; int maxfdp1; fd_set rset; int connfd = cliPI.getConnfd(); FD_ZERO(&rset); printf("%s@tinyFTP> ", username.c_str()); while(1) { fflush(stdout); FD_SET(connfd, &rset); FD_SET(fileno(stdin), &rset); maxfdp1 = connfd + 1; if (select(maxfdp1, &rset, NULL, NULL, NULL) < 0) Error::sys("select error"); if (FD_ISSET(connfd, &rset)) { /* socket is readable */ cliPI.recvOnePacket(); } if (FD_ISSET(fileno(stdin), &rset)) /* input is readable */ { getline(std::cin, inputline); cmdRun(inputline); printf("%s@tinyFTP> ", username.c_str()); } } // other ftp commands: first cout prompt (use "," operator) // while (printf("%s@tinyFTP> ", username.c_str()), getline(std::cin, inputline)) // { // cmdRun(inputline); // } }