-4

readme.txt file:

To use the program you should compile the file "main.cpp" and subsequently run the executable passing as the first argument the port number to which the application will listen for incoming data points (the incomplete data set that is used to approximate the original signal), (argv[1]=port number).

Incoming packets should adhere to the following format:

0|numSensors(int32_t)|numMeasures(int32_t)|ToM(int32_t)|
3|sensorId(int16_t)|value(float)|timestamp(int64_t)|
3|sensorId(int16_t)|value(float)|timestamp(int64_t)|
3|sensorId(int16_t)|value(float)|timestamp(int64_t)|
3|sensorId(int16_t)|value(float)|timestamp(int64_t)|
....
2|

"numMeasures" is the number of measures for taken for each sensor (you must provide at least 3 measures per sensor as otherwise you cannot build the training set).

"ToM" indicates the type of measurement, specifically:

0 for TEMPERATURE
1 for HUMIDITY
2 for LUMINOSITY1 

"sensorID": is the unique ID for the sensor that is sending the data

"value": is the sensor reading

"timestamp": you guess ...

This is the format of the packets returned by the signal reconstruction algorithm:

4|next_p_tx(float)|
3|sensorId(int16_t)|value(float)|timestamp(int64_t)|
3|sensorId(int16_t)|value(float)|timestamp(int64_t)|
3|sensorId(int16_t)|value(float)|timestamp(int64_t)|
3|sensorId(int16_t)|value(float)|timestamp(int64_t)|
....
2|

"next_p_tx": is the transmission probability for the sensors, for the next data gathering round, see our publications for further info on the approach.

my question: how to run this program on Ubuntu ? (via commandline or any IDE)

int main(int argc, char *argv[]) {
    initMeasures = (sensorMeasures*) malloc(sizeof(sensorMeasures));
    fprintf(stdout, "Starting...\n");

    int serversock, clientsock;
    struct sockaddr_in server, client;

    if (argc != 2) {
        fprintf(stderr, "USAGE: echoserver <port>\n");
        exit(1);
    }

    /* Create the TCP socket */
    if ((serversock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
        Die("Failed to create socket");
    }

    /* Construct the server sockaddr_in structure */
    memset(&server, 0, sizeof(server)); /* Clear struct */
    server.sin_family = AF_INET; /* Internet/IP */
    server.sin_addr.s_addr = htonl(INADDR_ANY); /* Incoming addr */
    server.sin_port = htons(atoi(argv[1])); /* server port */
    /* Bind the server socket */
    if (bind(serversock, (struct sockaddr *) &server, sizeof(server)) < 0) {
        Die("Failed to bind the server socket");
    } else {
        fprintf(stdout, "Bind successful...\n");
    }
    /* Listen on the server socket */
    if (listen(serversock, MAXPENDING) < 0) {
        Die("Failed to listen on server socket");
    } else {
        fprintf(stdout, "Listen successful...\n");
    }
    /*
     * Initialization of  "last"
     */
    for (int i = 0; i < 5; i++) {
        last[i].Phi_prec = new Matrix(1, 1);
        (*last[i].Phi_prec)(1, 1) = 0;
        last[i].x_prec = new ColumnVector(1);
        (*last[i].x_prec)(1) = 0;
        last[i].y_prec = new ColumnVector(1);
        (*last[i].y_prec)(1) = 0;
        last[i].p_tx = 1.0;
        last[i].depth = 0;
    }
    /* Run until cancelled */
    while (1) {
        unsigned int clientlen = sizeof(client);
        printf("Wait for client connection...\n");
        if ((clientsock = accept(serversock, (struct sockaddr *) &client,
                &clientlen)) < 0) {
            Die("Failed to accept client connection");
        }
        fprintf(stdout, "Client connected: %s:%d\n",
                inet_ntoa(client.sin_addr), ntohs(client.sin_port));

        now = time(NULL);
        receiveData(clientsock); // receive socket data
        reconstruct(); // reconstruct received data
        sendResults(clientsock); // return reconstructed data to web application
        printf("All operations successfully completed...\n");
    }
    free(initMeasures);
    exit(EXIT_SUCCESS);
}
Kjuly
  • 34,476
  • 22
  • 104
  • 118
  • 2
    It says it right there in the readme. What part of "compile and run this program" do you not understand? – user657267 Apr 10 '15 at 08:50
  • Normally, stackoverflow users are not interested in all your program --only on the specific problem. For future posts, try to be more compact and simplify everything. – MariusSiuram Apr 10 '15 at 09:19

1 Answers1

2

To use the program you should compile the file "main.cpp"

That's g++ -Wall -Wextra -o echoserver main.cpp

and subsequently run the executable passing as the first argument the port number

That's ./echoserver 12345 replacing the number with whichever port you want to listen to.

Mike Seymour
  • 249,747
  • 28
  • 448
  • 644
  • Pretty please enable compiler warnings? Otherwise we'll have to swat off the next fifty questions about trivial stuff that the compiler would have happily spelled out. – Kerrek SB Apr 12 '15 at 01:49
  • @KerrekSB: OK. Now we'll get questions about what the warnings mean instead. – Mike Seymour Apr 12 '15 at 09:47
  • That's fine, I'd be a hundred times happier with people asking about configuring warnings :-) Thanks! – Kerrek SB Apr 12 '15 at 11:30