-4

readme.txt 文件:

要使用该程序,您应该编译文件“main.cpp”,然后运行可执行文件作为第一个参数传递应用程序将侦听传入数据点的端口号(用于近似原始信号的不完整数据集), (argv[1]=端口号)。

传入的数据包应遵循以下格式:

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”是为每个传感器采取的措施数量(您必须为每个传感器提供至少 3 个措施,否则您无法构建训练集)。

“ToM”表示测量的类型,具体为:

0 for TEMPERATURE
1 for HUMIDITY
2 for LUMINOSITY1 

“sensorID”:是发送数据的传感器的唯一 ID

“值”:是传感器读数

“时间戳”:你猜...

这是信号重构算法返回的数据包格式:

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”:是传感器的传输概率,对于下一轮数据收集,请参阅我们的出版物以获取有关该方法的更多信息。

我的问题:如何在 Ubuntu 上运行这个程序?(通过命令行或任何 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);
}
4

1 回答 1

2

要使用该程序,您应该编译文件“main.cpp”

那是g++ -Wall -Wextra -o echoserver main.cpp

然后运行可执行文件作为第一个参数传递端口号

那就是./echoserver 12345用您想收听的任何端口替换数字。

于 2015-04-10T08:57:52.513 回答