{"action":"created","comment":{"url":"https://api.github.com/repos/01org/mavlink-router/pulls/comments/133630986","pull_request_review_id":56829372,"id":133630986,"diff_hunk":"@@ -0,0 +1,289 @@\n+// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).\n+//\n+// Licensed under the Apache License, Version 2.0 (the \"License\");\n+// you may not use this file except in compliance with the License.\n+// You may obtain a copy of the License at\n+//\n+//     http://www.apache.org/licenses/LICENSE-2.0\n+//\n+// Unless required by applicable law or agreed to in writing, software\n+// distributed under the License is distributed on an \"AS IS\" BASIS,\n+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+// See the License for the specific language governing permissions and\n+// limitations under the License.\n+\n+#include \"RtpsTopics.h\"\n+#include \"UART_node.h\"\n+\n+#include <fastcdr/FastCdr.h>\n+#include <fastcdr/exceptions/Exception.h>\n+#include <fastrtps/Domain.h>\n+#include <fastrtps/utils/eClock.h>\n+\n+#include <arpa/inet.h>\n+#include <errno.h>\n+#include <fcntl.h>\n+#include <getopt.h>\n+#include <stdio.h>\n+#include <sys/epoll.h>\n+#include <sys/socket.h>\n+#include <sys/types.h>\n+#include <unistd.h>\n+\n+#include \"log.h\"\n+#include \"util.h\"\n+\n+#define BUFFER_SIZE 1024\n+#define USLEEP_TIME 500\n+\n+using namespace eprosima;\n+using namespace eprosima::fastrtps;\n+\n+struct options {\n+    const char *device;\n+    unsigned long baudrate;\n+    unsigned long port;\n+    bool report_stats;\n+};\n+\n+static struct options _options\n+    = {.device = \"/dev/ttyS1\", .baudrate = 460800, .port = 13800, .report_stats = false};\n+\n+static struct sockaddr_in _sockaddr;\n+\n+static void help(FILE *fp)\n+{\n+    fprintf(fp, \"%s [OPTIONS]\\n\\n\"\n+                \"  -d <device>              UART device to get RTPS (and MAVLink) messages.\\n\"\n+                \"                           Default '/dev/ttyS1'\\n\"\n+                \"  -b <baudrate>            Baudrate of UART device.\\n\"\n+                \"                           Default '460800'\\n\"\n+                \"  -p <port>                UDP port where to send (or receive) MAVLink packets.\\n\"\n+                \"                           Default '13800'\\n\"\n+                \"  -r                       Report stats each 10 seconds\\n\",\n+            program_invocation_short_name);\n+}\n+\n+static int parse_options(int argc, char *argv[])\n+{\n+    int c;\n+\n+    while ((c = getopt(argc, argv, \"d:b:p:r\")) >= 0) {\n+        switch (c) {\n+        case 'd':\n+            _options.device = optarg;\n+            break;\n+        case 'b':\n+            if (safe_atoul(optarg, &_options.baudrate)) {\n+                log_error(\"Invalid argument for baudrate = %s\", optarg);\n+                help(stderr);\n+                return -EINVAL;\n+            }\n+            break;\n+        case 'p':\n+            if (safe_atoul(optarg, &_options.port)) {\n+                log_error(\"Invalid argument for port = %s\", optarg);\n+                help(stderr);\n+                return -EINVAL;\n+            }\n+            break;\n+        case 'r':\n+            _options.report_stats = true;\n+            break;\n+        case '?':\n+        default:\n+            help(stderr);\n+            return -EINVAL;\n+        }\n+    }\n+\n+    return 0;\n+}\n+\n+static int setup_udp(unsigned port)\n+{\n+    int fd;\n+    const int broadcast_val = 1;\n+\n+    fd = socket(AF_INET, SOCK_DGRAM, 0);\n+    if (fd == -1) {\n+        log_error(\"Could not create socket %d\", errno);\n+        return -1;\n+    }\n+\n+    _sockaddr.sin_family = AF_INET;\n+    _sockaddr.sin_addr.s_addr = inet_addr(\"127.0.0.1\");\n+    _sockaddr.sin_port = htons(port);\n+\n+    if (setsockopt(fd, SOL_SOCKET, SO_BROADCAST, &broadcast_val, sizeof(broadcast_val))) {\n+        log_error(\"Error enabling broadcast %d\", errno);\n+        return -1;\n+    }\n+\n+    if (fcntl(fd, F_SETFL, O_NONBLOCK | FASYNC) < 0) {\n+        log_error(\"Error setting socket fd as non-blocking %d\", errno);\n+        return -1;\n+    }\n+\n+    return fd;\n+}\n+\n+static void loop(int epollfd, int uart_fd, int udp_fd, UART_node uart_node, RtpsTopics &topics)\n+{\n+    unsigned bytes_read = 0, bytes_sent = 0;\n+    char topic_ID = 255;\n+\n+    struct timespec begin;\n+    bool measuring = false;\n+    uint8_t seq;\n+\n+    struct epoll_event events[8];\n+    char data_buffer[BUFFER_SIZE] = {};\n+\n+    // TODO use mavlink-router mainloop (which need to be extracted from it)\n+    do {\n+        if (_options.report_stats && !measuring) {\n+            clock_gettime(0, &begin);\n+            measuring = true;\n+        }\n+\n+        // TODO check if it's possible to add RTPS subscribers on epoll\n+        // or use a thread for them\n+        int r = epoll_wait(epollfd, events, 8, USLEEP_TIME);","path":"src/rtps/main.cpp","position":152,"original_position":152,"commit_id":"1235dea0d99fdc752a2b64eea2d2ca2a9f6bb036","original_commit_id":"2fc638933f2987dbea7b456de74bb08597918cc0","user":{"login":"lucasdemarchi","id":31864,"avatar_url":"https://avatars3.githubusercontent.com/u/31864?v=4","gravatar_id":"","url":"https://api.github.com/users/lucasdemarchi","html_url":"https://github.com/lucasdemarchi","followers_url":"https://api.github.com/users/lucasdemarchi/followers","following_url":"https://api.github.com/users/lucasdemarchi/following{/other_user}","gists_url":"https://api.github.com/users/lucasdemarchi/gists{/gist_id}","starred_url":"https://api.github.com/users/lucasdemarchi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lucasdemarchi/subscriptions","organizations_url":"https://api.github.com/users/lucasdemarchi/orgs","repos_url":"https://api.github.com/users/lucasdemarchi/repos","events_url":"https://api.github.com/users/lucasdemarchi/events{/privacy}","received_events_url":"https://api.github.com/users/lucasdemarchi/received_events","type":"User","site_admin":false},"body":"why USLEEP_TIME? And worse.... why is it 500 usec? You will just wakeup a lot the mainloop to do nothing. ","created_at":"2017-08-17T06:20:28Z","updated_at":"2017-08-17T06:23:09Z","html_url":"https://github.com/01org/mavlink-router/pull/115#discussion_r133630986","pull_request_url":"https://api.github.com/repos/01org/mavlink-router/pulls/115","_links":{"self":{"href":"https://api.github.com/repos/01org/mavlink-router/pulls/comments/133630986"},"html":{"href":"https://github.com/01org/mavlink-router/pull/115#discussion_r133630986"},"pull_request":{"href":"https://api.github.com/repos/01org/mavlink-router/pulls/115"}}},"pull_request":{"url":"https://api.github.com/repos/01org/mavlink-router/pulls/115","id":136175674,"html_url":"https://github.com/01org/mavlink-router/pull/115","diff_url":"https://github.com/01org/mavlink-router/pull/115.diff","patch_url":"https://github.com/01org/mavlink-router/pull/115.patch","issue_url":"https://api.github.com/repos/01org/mavlink-router/issues/115","number":115,"state":"open","locked":false,"title":"RTPS changes","user":{"login":"avinash-palleti","id":362099,"avatar_url":"https://avatars2.githubusercontent.com/u/362099?v=4","gravatar_id":"","url":"https://api.github.com/users/avinash-palleti","html_url":"https://github.com/avinash-palleti","followers_url":"https://api.github.com/users/avinash-palleti/followers","following_url":"https://api.github.com/users/avinash-palleti/following{/other_user}","gists_url":"https://api.github.com/users/avinash-palleti/gists{/gist_id}","starred_url":"https://api.github.com/users/avinash-palleti/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/avinash-palleti/subscriptions","organizations_url":"https://api.github.com/users/avinash-palleti/orgs","repos_url":"https://api.github.com/users/avinash-palleti/repos","events_url":"https://api.github.com/users/avinash-palleti/events{/privacy}","received_events_url":"https://api.github.com/users/avinash-palleti/received_events","type":"User","site_admin":false},"body":"Rebased PR #98 ","created_at":"2017-08-17T05:30:35Z","updated_at":"2017-08-17T06:23:09Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9096a16567e400605fd4051a0dd1c2363ac82960","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/01org/mavlink-router/pulls/115/commits","review_comments_url":"https://api.github.com/repos/01org/mavlink-router/pulls/115/comments","review_comment_url":"https://api.github.com/repos/01org/mavlink-router/pulls/comments{/number}","comments_url":"https://api.github.com/repos/01org/mavlink-router/issues/115/comments","statuses_url":"https://api.github.com/repos/01org/mavlink-router/statuses/1235dea0d99fdc752a2b64eea2d2ca2a9f6bb036","head":{"label":"avinash-palleti:master","ref":"master","sha":"1235dea0d99fdc752a2b64eea2d2ca2a9f6bb036","user":{"login":"avinash-palleti","id":362099,"avatar_url":"https://avatars2.githubusercontent.com/u/362099?v=4","gravatar_id":"","url":"https://api.github.com/users/avinash-palleti","html_url":"https://github.com/avinash-palleti","followers_url":"https://api.github.com/users/avinash-palleti/followers","following_url":"https://api.github.com/users/avinash-palleti/following{/other_user}","gists_url":"https://api.github.com/users/avinash-palleti/gists{/gist_id}","starred_url":"https://api.github.com/users/avinash-palleti/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/avinash-palleti/subscriptions","organizations_url":"https://api.github.com/users/avinash-palleti/orgs","repos_url":"https://api.github.com/users/avinash-palleti/repos","events_url":"https://api.github.com/users/avinash-palleti/events{/privacy}","received_events_url":"https://api.github.com/users/avinash-palleti/received_events","type":"User","site_admin":false},"repo":{"id":100564789,"name":"mavlink-router","full_name":"avinash-palleti/mavlink-router","owner":{"login":"avinash-palleti","id":362099,"avatar_url":"https://avatars2.githubusercontent.com/u/362099?v=4","gravatar_id":"","url":"https://api.github.com/users/avinash-palleti","html_url":"https://github.com/avinash-palleti","followers_url":"https://api.github.com/users/avinash-palleti/followers","following_url":"https://api.github.com/users/avinash-palleti/following{/other_user}","gists_url":"https://api.github.com/users/avinash-palleti/gists{/gist_id}","starred_url":"https://api.github.com/users/avinash-palleti/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/avinash-palleti/subscriptions","organizations_url":"https://api.github.com/users/avinash-palleti/orgs","repos_url":"https://api.github.com/users/avinash-palleti/repos","events_url":"https://api.github.com/users/avinash-palleti/events{/privacy}","received_events_url":"https://api.github.com/users/avinash-palleti/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/avinash-palleti/mavlink-router","description":null,"fork":true,"url":"https://api.github.com/repos/avinash-palleti/mavlink-router","forks_url":"https://api.github.com/repos/avinash-palleti/mavlink-router/forks","keys_url":"https://api.github.com/repos/avinash-palleti/mavlink-router/keys{/key_id}","collaborators_url":"https://api.github.com/repos/avinash-palleti/mavlink-router/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/avinash-palleti/mavlink-router/teams","hooks_url":"https://api.github.com/repos/avinash-palleti/mavlink-router/hooks","issue_events_url":"https://api.github.com/repos/avinash-palleti/mavlink-router/issues/events{/number}","events_url":"https://api.github.com/repos/avinash-palleti/mavlink-router/events","assignees_url":"https://api.github.com/repos/avinash-palleti/mavlink-router/assignees{/user}","branches_url":"https://api.github.com/repos/avinash-palleti/mavlink-router/branches{/branch}","tags_url":"https://api.github.com/repos/avinash-palleti/mavlink-router/tags","blobs_url":"https://api.github.com/repos/avinash-palleti/mavlink-router/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/avinash-palleti/mavlink-router/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/avinash-palleti/mavlink-router/git/refs{/sha}","trees_url":"https://api.github.com/repos/avinash-palleti/mavlink-router/git/trees{/sha}","statuses_url":"https://api.github.com/repos/avinash-palleti/mavlink-router/statuses/{sha}","languages_url":"https://api.github.com/repos/avinash-palleti/mavlink-router/languages","stargazers_url":"https://api.github.com/repos/avinash-palleti/mavlink-router/stargazers","contributors_url":"https://api.github.com/repos/avinash-palleti/mavlink-router/contributors","subscribers_url":"https://api.github.com/repos/avinash-palleti/mavlink-router/subscribers","subscription_url":"https://api.github.com/repos/avinash-palleti/mavlink-router/subscription","commits_url":"https://api.github.com/repos/avinash-palleti/mavlink-router/commits{/sha}","git_commits_url":"https://api.github.com/repos/avinash-palleti/mavlink-router/git/commits{/sha}","comments_url":"https://api.github.com/repos/avinash-palleti/mavlink-router/comments{/number}","issue_comment_url":"https://api.github.com/repos/avinash-palleti/mavlink-router/issues/comments{/number}","contents_url":"https://api.github.com/repos/avinash-palleti/mavlink-router/contents/{+path}","compare_url":"https://api.github.com/repos/avinash-palleti/mavlink-router/compare/{base}...{head}","merges_url":"https://api.github.com/repos/avinash-palleti/mavlink-router/merges","archive_url":"https://api.github.com/repos/avinash-palleti/mavlink-router/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/avinash-palleti/mavlink-router/downloads","issues_url":"https://api.github.com/repos/avinash-palleti/mavlink-router/issues{/number}","pulls_url":"https://api.github.com/repos/avinash-palleti/mavlink-router/pulls{/number}","milestones_url":"https://api.github.com/repos/avinash-palleti/mavlink-router/milestones{/number}","notifications_url":"https://api.github.com/repos/avinash-palleti/mavlink-router/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/avinash-palleti/mavlink-router/labels{/name}","releases_url":"https://api.github.com/repos/avinash-palleti/mavlink-router/releases{/id}","deployments_url":"https://api.github.com/repos/avinash-palleti/mavlink-router/deployments","created_at":"2017-08-17T05:26:14Z","updated_at":"2017-08-17T05:26:15Z","pushed_at":"2017-08-17T05:28:10Z","git_url":"git://github.com/avinash-palleti/mavlink-router.git","ssh_url":"git@github.com:avinash-palleti/mavlink-router.git","clone_url":"https://github.com/avinash-palleti/mavlink-router.git","svn_url":"https://github.com/avinash-palleti/mavlink-router","homepage":null,"size":306,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"01org:master","ref":"master","sha":"6a18ffc3e44be0c96973037f7e8ac8a952d66475","user":{"login":"01org","id":1635439,"avatar_url":"https://avatars1.githubusercontent.com/u/1635439?v=4","gravatar_id":"","url":"https://api.github.com/users/01org","html_url":"https://github.com/01org","followers_url":"https://api.github.com/users/01org/followers","following_url":"https://api.github.com/users/01org/following{/other_user}","gists_url":"https://api.github.com/users/01org/gists{/gist_id}","starred_url":"https://api.github.com/users/01org/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/01org/subscriptions","organizations_url":"https://api.github.com/users/01org/orgs","repos_url":"https://api.github.com/users/01org/repos","events_url":"https://api.github.com/users/01org/events{/privacy}","received_events_url":"https://api.github.com/users/01org/received_events","type":"Organization","site_admin":false},"repo":{"id":75330320,"name":"mavlink-router","full_name":"01org/mavlink-router","owner":{"login":"01org","id":1635439,"avatar_url":"https://avatars1.githubusercontent.com/u/1635439?v=4","gravatar_id":"","url":"https://api.github.com/users/01org","html_url":"https://github.com/01org","followers_url":"https://api.github.com/users/01org/followers","following_url":"https://api.github.com/users/01org/following{/other_user}","gists_url":"https://api.github.com/users/01org/gists{/gist_id}","starred_url":"https://api.github.com/users/01org/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/01org/subscriptions","organizations_url":"https://api.github.com/users/01org/orgs","repos_url":"https://api.github.com/users/01org/repos","events_url":"https://api.github.com/users/01org/events{/privacy}","received_events_url":"https://api.github.com/users/01org/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/01org/mavlink-router","description":null,"fork":false,"url":"https://api.github.com/repos/01org/mavlink-router","forks_url":"https://api.github.com/repos/01org/mavlink-router/forks","keys_url":"https://api.github.com/repos/01org/mavlink-router/keys{/key_id}","collaborators_url":"https://api.github.com/repos/01org/mavlink-router/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/01org/mavlink-router/teams","hooks_url":"https://api.github.com/repos/01org/mavlink-router/hooks","issue_events_url":"https://api.github.com/repos/01org/mavlink-router/issues/events{/number}","events_url":"https://api.github.com/repos/01org/mavlink-router/events","assignees_url":"https://api.github.com/repos/01org/mavlink-router/assignees{/user}","branches_url":"https://api.github.com/repos/01org/mavlink-router/branches{/branch}","tags_url":"https://api.github.com/repos/01org/mavlink-router/tags","blobs_url":"https://api.github.com/repos/01org/mavlink-router/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/01org/mavlink-router/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/01org/mavlink-router/git/refs{/sha}","trees_url":"https://api.github.com/repos/01org/mavlink-router/git/trees{/sha}","statuses_url":"https://api.github.com/repos/01org/mavlink-router/statuses/{sha}","languages_url":"https://api.github.com/repos/01org/mavlink-router/languages","stargazers_url":"https://api.github.com/repos/01org/mavlink-router/stargazers","contributors_url":"https://api.github.com/repos/01org/mavlink-router/contributors","subscribers_url":"https://api.github.com/repos/01org/mavlink-router/subscribers","subscription_url":"https://api.github.com/repos/01org/mavlink-router/subscription","commits_url":"https://api.github.com/repos/01org/mavlink-router/commits{/sha}","git_commits_url":"https://api.github.com/repos/01org/mavlink-router/git/commits{/sha}","comments_url":"https://api.github.com/repos/01org/mavlink-router/comments{/number}","issue_comment_url":"https://api.github.com/repos/01org/mavlink-router/issues/comments{/number}","contents_url":"https://api.github.com/repos/01org/mavlink-router/contents/{+path}","compare_url":"https://api.github.com/repos/01org/mavlink-router/compare/{base}...{head}","merges_url":"https://api.github.com/repos/01org/mavlink-router/merges","archive_url":"https://api.github.com/repos/01org/mavlink-router/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/01org/mavlink-router/downloads","issues_url":"https://api.github.com/repos/01org/mavlink-router/issues{/number}","pulls_url":"https://api.github.com/repos/01org/mavlink-router/pulls{/number}","milestones_url":"https://api.github.com/repos/01org/mavlink-router/milestones{/number}","notifications_url":"https://api.github.com/repos/01org/mavlink-router/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/01org/mavlink-router/labels{/name}","releases_url":"https://api.github.com/repos/01org/mavlink-router/releases{/id}","deployments_url":"https://api.github.com/repos/01org/mavlink-router/deployments","created_at":"2016-12-01T20:32:45Z","updated_at":"2017-08-09T08:24:41Z","pushed_at":"2017-08-17T05:30:36Z","git_url":"git://github.com/01org/mavlink-router.git","ssh_url":"git@github.com:01org/mavlink-router.git","clone_url":"https://github.com/01org/mavlink-router.git","svn_url":"https://github.com/01org/mavlink-router","homepage":null,"size":306,"stargazers_count":15,"watchers_count":15,"language":"C++","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":9,"mirror_url":null,"open_issues_count":15,"forks":9,"open_issues":15,"watchers":15,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/01org/mavlink-router/pulls/115"},"html":{"href":"https://github.com/01org/mavlink-router/pull/115"},"issue":{"href":"https://api.github.com/repos/01org/mavlink-router/issues/115"},"comments":{"href":"https://api.github.com/repos/01org/mavlink-router/issues/115/comments"},"review_comments":{"href":"https://api.github.com/repos/01org/mavlink-router/pulls/115/comments"},"review_comment":{"href":"https://api.github.com/repos/01org/mavlink-router/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/01org/mavlink-router/pulls/115/commits"},"statuses":{"href":"https://api.github.com/repos/01org/mavlink-router/statuses/1235dea0d99fdc752a2b64eea2d2ca2a9f6bb036"}}}}
{"actor":{"display_login":"lucasdemarchi"}}