From 31964791dcb4df923a9cd4653b848b96df7dde52 Mon Sep 17 00:00:00 2001 From: Jeonghoon Park Date: Thu, 4 Jan 2018 17:21:43 +0900 Subject: [PATCH] add pilot version of receiver module --- CMakeLists.txt | 2 ++ inc/receiver.h | 28 ++++++++++++++++++ inc/receiver_internal.h | 24 +++++++++++++++ src/receiver.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 132 insertions(+) create mode 100644 inc/receiver.h create mode 100644 inc/receiver_internal.h create mode 100644 src/receiver.c diff --git a/CMakeLists.txt b/CMakeLists.txt index c974fd7..f2024a5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,6 +14,7 @@ pkg_check_modules(APP_PKGS REQUIRED capi-appfw-service-application capi-system-peripheral-io glib-2.0 + gio-2.0 ) FOREACH (flag ${APP_PKGS_CFLAGS}) @@ -30,6 +31,7 @@ ADD_EXECUTABLE(${PROJECT_NAME} ${PROJECT_ROOT_DIR}/src/app.c ${PROJECT_ROOT_DIR}/src/log.c ${PROJECT_ROOT_DIR}/src/resource.c + ${PROJECT_ROOT_DIR}/src/receiver.c ${PROJECT_ROOT_DIR}/src/resource/resource_infrared_obstacle_avoidance_sensor.c ${PROJECT_ROOT_DIR}/src/resource/resource_motor_driver_L298N.c ${PROJECT_ROOT_DIR}/src/resource/resource_PCA9685.c diff --git a/inc/receiver.h b/inc/receiver.h new file mode 100644 index 0000000..347bd77 --- /dev/null +++ b/inc/receiver.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __CAR_APP_RECEIVER_H__ +#define __CAR_APP_RECEIVER_H__ + +typedef enum __receiver_type_e { + RECEIVER_TYPE_UDP, + RECEIVER_TYPE_BLUETOOTH, +} receiver_type_e; + +int receiver_init(receiver_type_e type); +void receiver_fini(void); + +#endif /* __CAR_APP_RECEIVER_H__ */ diff --git a/inc/receiver_internal.h b/inc/receiver_internal.h new file mode 100644 index 0000000..05d6602 --- /dev/null +++ b/inc/receiver_internal.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __CAR_APP_RECEIVER_INTERNAL_H__ +#define __CAR_APP_RECEIVER_INTERNAL_H__ + +#include "receiver.h" + +/* TODO */ + +#endif /* __CAR_APP_RECEIVER_INTERNAL_H__ */ diff --git a/src/receiver.c b/src/receiver.c new file mode 100644 index 0000000..a77edd9 --- /dev/null +++ b/src/receiver.c @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "log.h" +#include "receiver_internal.h" + +typedef struct __receiver_h { + receiver_type_e receiver_type; + /* TODO */ +} receiver_h; + +static receiver_h *ghandle = NULL; + +int receiver_init(receiver_type_e type) +{ + int ret = 0; + + if (ghandle) { + _E("receiver is already initialized"); + return -1; + } + + ghandle = (receiver_h *)malloc(sizeof(receiver_h)); + if (!ghandle) { + _E("failed to malloc handle"); + return -1; + } + + switch (type) { + case RECEIVER_TYPE_UDP: + ghandle->receiver_type = type; + ret = receiver_udp_start(); + if (ret) + goto ERROR; + break; + case RECEIVER_TYPE_BLUETOOTH: + /* TODO */ + break; + } + return 0; + +ERROR: + free(ghandle); + ghandle = NULL; + return -1; +} + +void receiver_fini(void) +{ + if (ghandle) { + switch (ghandle->receiver_type) { + case RECEIVER_TYPE_UDP: + receiver_udp_stop(); + break; + case RECEIVER_TYPE_BLUETOOTH: + /* TODO */ + break; + } + + free(ghandle); + ghandle = NULL; + } + return; +} -- 2.7.4