From 98a3c74e3b6bfc0d2af0bf2456ede4f4fc26cd35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=A4rkl?= Date: Wed, 12 Jun 2019 18:41:32 +0200 Subject: [PATCH] Begin Discovery --- lib/CMakeLists.txt | 6 ++-- lib/include/chiaki/discovery.h | 53 ++++++++++++++++++++++++++++++++++ lib/src/discovery.c | 42 +++++++++++++++++++++++++++ 3 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 lib/include/chiaki/discovery.h create mode 100644 lib/src/discovery.c diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 9dcc0f1..c256b0e 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -21,7 +21,8 @@ set(HEADER_FILES include/chiaki/video.h include/chiaki/videoreceiver.h include/chiaki/frameprocessor.h - include/chiaki/seqnum.h) + include/chiaki/seqnum.h + include/chiaki/discovery.h) set(SOURCE_FILES src/common.c @@ -45,7 +46,8 @@ set(SOURCE_FILES src/audio.c src/audioreceiver.c src/videoreceiver.c - src/frameprocessor.c) + src/frameprocessor.c + src/discovery.c) add_subdirectory(protobuf) include_directories("${NANOPB_SOURCE_DIR}") diff --git a/lib/include/chiaki/discovery.h b/lib/include/chiaki/discovery.h new file mode 100644 index 0000000..51835d7 --- /dev/null +++ b/lib/include/chiaki/discovery.h @@ -0,0 +1,53 @@ +/* + * This file is part of Chiaki. + * + * Chiaki is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Chiaki is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Chiaki. If not, see . + */ + +#ifndef CHIAKI_DISCOVERY_H +#define CHIAKI_DISCOVERY_H + +#include "common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define CHIAKI_DISCOVERY_PORT 987 +#define CHIAKI_DISCOVERY_PROTOCOL_VERSION "00020020" + +typedef enum chiaki_discovery_cmd_t +{ + CHIAKI_DISCOVERY_CMD_SRCH +} ChiakiDiscoveryCmd; + +typedef struct chiaki_discovery_packet_t +{ + ChiakiDiscoveryCmd cmd; + char *protocol_version; +} ChiakiDiscoveryPacket; + +typedef struct chiaki_discovery_t +{ + int socket; +} ChiakiDiscovery; + +CHIAKI_EXPORT ChiakiErrorCode chiaki_discovery_init(ChiakiDiscovery *discovery); +CHIAKI_EXPORT void chiaki_discovery_fini(ChiakiDiscovery *discovery); + +#ifdef __cplusplus +} +#endif + +#endif // CHIAKI_VIDEORECEIVER_H diff --git a/lib/src/discovery.c b/lib/src/discovery.c new file mode 100644 index 0000000..09d7479 --- /dev/null +++ b/lib/src/discovery.c @@ -0,0 +1,42 @@ +/* + * This file is part of Chiaki. + * + * Chiaki is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Chiaki is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Chiaki. If not, see . + */ + +#include + +#include + +#include +#include + + +static const char *packet_srch_template = + "SRCH * HTTP/1.1\n" + "device-discovery-protocol-version:%s\n"; + + +CHIAKI_EXPORT ChiakiErrorCode chiaki_discovery_init(ChiakiDiscovery *discovery) +{ + discovery->socket = socket(AF_INET, SOCK_DGRAM, 0); + if(discovery->socket < 0) + return CHIAKI_ERR_UNKNOWN; + return CHIAKI_ERR_SUCCESS; +} + +CHIAKI_EXPORT void chiaki_discovery_fini(ChiakiDiscovery *discovery) +{ + close(discovery->socket); +} \ No newline at end of file