Пример #1
0
/*** FUNCTION CODE ***/
int main(int argc, char *argv[]) {
    //Setup Signal handler and atexit functions
	signal(SIGINT, INThandler);                     //Interrupts (calls INThandler) when Ctrl+c (?)
    COM1 = open_serialport("/dev/ttyUSB0",500000); //Open USB port
    Time_struct Curr_time;                          //Create time structure
    Curr_time = get_time();                         //Fill it with current time
    char fname[26];                                 //Create space for filename
    sprintf(fname, "%d-%d-%d-%d:%d:%d:%d.csv", Curr_time.year, Curr_time.month, Curr_time.day, Curr_time.hour, Curr_time.minute, Curr_time.second, Curr_time.msecond); //Create filename (date, time)
    fp = fopen(fname,"w");                          //Open file
    struct sockaddr_in outsock;
    int s_out_sensordata, slen = sizeof(struct sockaddr_in);
    initClientSocket(IMU_PORT, &s_out_sensordata, OPC_IP, &outsock);
    //initClientSocket(65100, &s_out_sensordata, "10.0.0.10", &outsock); //fakeclient
    sensor_data data;
    initBuffer();
    while(running) {
        data = receiveSensorData();
        writeToBuffer(&data);
        if (processData(&data))
            sendSensorData(&data, s_out_sensordata, outsock, slen);
    }
    //At end by Ctrl+c
    printf("Fin\n");
    fclose(fp);                                     //Close file
    return 0;
}
int main(void){
	char rcvBuf[255];
	
	commandPacket comPacket;
	int packetId = 1;
	struct sockaddr_in commandInSocket, commandOutSocket;
	socklen_t slen = sizeof(struct sockaddr_in);	
	int s_commandInSocket, s_commandOutSocket;
	
	//setup socket to send to wheel loader
	initClientSocket(CMDO_PORT, &s_commandOutSocket, WL_WIRELESSIP, &commandOutSocket);
//	initClientSocket(CMDO_PORT, &s_commandOutSocket, "127.0.0.1", &commandOutSocket);

	//setup socket to receive packets from simulator
	initServerSocket(CMDI_PORT, &s_commandInSocket, &commandInSocket);
	
	while(1){
		recvfrom(s_commandInSocket, rcvBuf, 255, 0, (struct sockaddr*) &commandInSocket, &slen);
		memcpy(&comPacket, rcvBuf, sizeof(commandPacket));
		
		comPacket.packetId = packetId++;
		clock_gettime(CLOCK_REALTIME, &comPacket.timeSent);
		printf("sending packet\n");
		sendto(s_commandOutSocket, (char*)&comPacket, sizeof(commandPacket), 0, (struct sockaddr*) &commandOutSocket, slen);
	}
	return 0;
}
Пример #3
0
int main(){
    signal(SIGINT, intHandle);
    signal(SIGPIPE, SIG_IGN);

    while(1){
        initClientSocket(&hints, &res, P2host, P12port, &sfd);
        connectClientSocket(res, &sfd, 5);
        fprintf(stderr, "Connected to P2\n");

        while(1){
            int64_t n = rand() % 1024;
            int64_t sign = rand() % 2 ? -1 : 1;
            n *= sign;
            printf("%"PRId64"\n", n);
            //It's 2014 and there's no standard hton64? Am I missing something?
            int64_t data = htobe64(n);
            conStat = send(sfd, (void*)&data, sizeof(int64_t), 0);
            if(conStat <= 0){
                fprintf(stderr, "Error sending data (%d): %s\n", errno, strerror(errno));
                resetState();
                break;
            }
            usleep(250000);
        }
    }
    return 0;
}
Пример #4
0
void NfcPeerToPeer::targetLost(QNearFieldTarget */*target*/)
{
    if (!m_useConnectionLess && m_nfcClientSocket) {
        // Connection-oriented
        m_nfcClientSocket->disconnectFromService();
    } else {
        // Connection-less
#ifdef Q_OS_SYMBIAN
        // Delete and create a new client socket. Otherwise, we'd get an error from
        // the socket and it wouldn't work for new connections anymore.
        initClientSocket();
#endif
    }
    // Don't delete target here, it's owned by NfcInfo
}
Пример #5
0
void NfcPeerToPeer::initAndStartNfc()
{
    qDebug(__PRETTY_FUNCTION__);
    if (!m_appSettings) {
        return;
    }

    // Create the NFC server which will listen for incoming connections
    // (for connection-oriented only, connectionless will bind the client
    // socket to the port).
    if (!m_useConnectionLess && m_connectServerSocket) {
        qDebug() << "Creating LLCP server";
        m_nfcServer = new QLlcpServer(this);
        connect(m_nfcServer, SIGNAL(newConnection()), this, SLOT(handleNewConnection()));

        qDebug() << "Starting to listen to " << m_nfcUri;
        m_nfcServer->listen(m_nfcUri);
    }

    // The NFC client socket
    initClientSocket();
}
Пример #6
0
/*-----------------------------------------------------------------------------*/
int main(int argc, char **argv)
{
  char str[MAX_STR];
  char userID[MAX_USER_NAME];
  char buffer[MAX_BUFF];
  SongType tempSong;
  
  /* Ncurses Menu */
  char *mContent[] = {
                      "Add Song", 
                      "Delete Song", 
                      "View Song(s)",
                      "Quit"
                     };
  
//  dealWithIt();
  printLogo("CLIENT", CLEAR);
  
  /* External Preprocessor commands */
  if (extArguments (argc,argv) == 0) {return 0;}
  
  /* Welcome Screen and ask for username */
  getUserID(userID, (unsigned) sizeof(userID));

  /* Initiats connections */
  initClientSocket();

  /* Display confirmation for user */
  printf(ANSI_COLOR_GREEN
         "Establising connection to server %s:%d \n\n"
         "For further assistance or "
         "help, please visit the help page by simply typing "
         ANSI_COLOR_YELLOW 
         "'/h'"
         ANSI_COLOR_RESET" \n", SERVER_IP, SERVER_PORT);

  /* SEND USER THAT WE GOT FROM THE ABOVE fgets */
  userID[strlen(userID)-1] = '\0'; // add a terminator at the end of the char[]
  strcpy(buffer, userID);
  send(mySocket, buffer, strlen(buffer), 0);

  /* Display Menu - Keep this if not using dup / dup2*/
  dispMenu();

  while (1) {
    /* For eye candy */
    // printLogo("CLIENT", NO_CLEAR);

    /* Display Menu first */
    // dispMenu();
    // initNcursesMenu((sizeof(mContent) / sizeof(char*)),*mContent);
    printf("Please choose from the menu above: ");

    fgets(str, sizeof(str), stdin);
    str[strlen(str)-1] = '\0';
    /* Deprecated 
     * if (strcmp(str, "/h") == 0) {
     *  printf(ANSI_COLOR_CYAN
     *       "Welcome to the help page. This is a beta-help page\n"
     *       "With later releases the help page should be using\n"
     *       "the ncurses library.\n"
     *       "Commands include :\n"
     *       ANSI_COLOR_RED
     *       "\t/h\t: For this lovely page\n"
     *       "\t/q\t: Closes this program.\n"
     *       ANSI_COLOR_RESET
     *      );
     * } else
     */
 
    strcpy(buffer, str);
    /*Encryption - Usually one would use a key, but not in this case.*/
 //   encrypt(buffer);
 //   send(mySocket, buffer, strlen(buffer), 0); 
    encryptSend(mySocket, buffer, strlen(buffer),0);
    if (strcmp(str, "/q") == 0) {
      /* Soft-quiting */
      break;
    } else if (strcmp(str, "a") == 0) {
      /* Add Song */
      printf("You are about to send a song over: Please enter the following: \n"
             ANSI_COLOR_YELLOW 
             "Name  : ");
      fgets(str, sizeof(str), stdin);
      str[strlen(str) - 1] = '\0';
      encryptSend(mySocket, str, strlen(str),0);

      printf("Artist: ");
      fgets(str, sizeof(str), stdin);
      str[strlen(str) - 1] = '\0';
      encryptSend(mySocket, str, strlen(str),0);

      printf("Album : ");
      fgets(str, sizeof(str), stdin);
      str[strlen(str) - 1] = '\0';
      encryptSend(mySocket, str, strlen(str),0);
    
      printf("Duration (mins) : ");
      /* Just to make sure the user will use integars, if it is not the case
       * then he/she will be promted again to repeat their input.
       */
      for(;;){
       short *illegals = 0;
       fgets(str, sizeof(str), stdin);
       /* Check if str contains any non-ints*/
       for (int i = 0; i < strlen(str) - 1; ++i) {
         if(!isdigit(str[i])) ++illegals;
       } 
       /* If everything seems to be good, then exit*/
       if ( illegals == 0) {
         tempSong.duration = atoi(str);
      //   fgets(str, sizeof(str), stdin);
         str[strlen(str) - 1] = '\0';
         encryptSend(mySocket, str, strlen(str),0);

         /* Free illegals ... */
         free(illegals);
         break;
       }
       printf(ANSI_COLOR_RED 
              "EYYY!!! YO CHILL MAN!!"
              ANSI_COLOR_RESET 
              " Only Integar values!\nLet's try that again...\n"
              ANSI_COLOR_YELLOW
              "Duration (mins) : "
             );
      } // end sentinital loop ( I don't know how to spell, don't judge sheesh )
      
      printf(ANSI_COLOR_GREEN 
             "We are all good. Converting your song to send over\n"
             ANSI_COLOR_RESET
            );
    } else if (strcmp(str, "b") == 0) {
      /* Delete Song */
      printf(ANSI_COLOR_YELLOW);
      printf("Which song do you want to delete?\n"
             "Name ? : ");
      fgets(str, sizeof(str), stdin);
      str[strlen(str) - 1] = '\0';
      encryptSend(mySocket, str, strlen(str),0);

      printf("Artist : ");
      fgets(str, sizeof(str), stdin);
      str[strlen(str) - 1] = '\0';
      encryptSend(mySocket, str, strlen(str),0);

      printf("That should be enough info\n");
      printf(ANSI_COLOR_RESET);      
    } else if (strcmp(str, "c") == 0) {
      /* View Song(s) */
      fgets(str, sizeof(str), stdin);
      str[strlen(str) - 1] = '\0';
      encryptSend(mySocket, str, strlen(str),0);
      
    } else if (strcmp(str, "d") == 0) {
      break;
    }
 }
  close(mySocket);
  return 0;
}