This is the initial working base code on raspberry pi2 with tizen 3.0.
This repo is created using the following JIRA request:
https://bugs.tizen.org/browse/SO-605
It contains 2 different package for different mode of communication.
The current mode of communication is Bluetooth or Wi-Fi.
Thus we have:
- bt-robot-server: for bluetooth communication over HC-05.
- wifi-robot-server: for TCP/IP based socket communication over Wi-Fi.
Similarly, it can be extended further for other modes.
For more detailed explanation please see the README file.
Change-Id: I8cbcab9fcd34ab664498bab6650cc4ddecd54bdf
Signed-off-by: Pintu Kumar <pintu_agarwal@yahoo.com>
--- /dev/null
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+
+ADD_SUBDIRECTORY(bt-robot-server)
+ADD_SUBDIRECTORY(wifi-robot-server)
--- /dev/null
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Lesser General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program 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 2 of the License, or
+ (at your option) any later version.
+
+ This program 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 this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) year name of author
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ <signature of Ty Coon>, 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Lesser General
+Public License instead of this License.
--- /dev/null
+AUTHOR: Pintu Kumar
+Email: pintu_agarwal@yahoo.com
+
+OBJECTIVE:
+----------
+To develop a Tizen based obstacle sensing robot and control its movement
+using Tizen mobile phone.
+Develop Wi-Fi and Bluetooth communication based backend service using
+normal Linux socket for raspberry pi2 running Tizen platform.
+
+INTRODUCTION:
+-------------
+Last year (2016), I wanted to create my own robot using Raspberry pi2
+but with Tizen 3.0 platform.
+So, first I have done Tizen 3.0 common profile bring up (headless)
+on pi2. This also includes pi2 kernel customization for Tizen.
+It also includes bluetooth and wi-fi related customization to make
+these communication works from shell.
+I have presented a talk about this in Embedded Linux Conference-2016.
+You can find the paper here:
+http://events.linuxfoundation.org/sites/events/files/slides/ELC2016-TIZEN-RC-CAR.pdf
+
+Now, once the Tizen platform is up on pi2, I created a robotics kit
+using all the hardware as described in the paper.
+But the problem started when we were looking for a simple generic interface
+to communicate with our robot using Tizen mobile phone. Here, when I say
+generic I mean, it should work in Tizen as well as any system having Linux
+running into it. the communication interface could be either bluetooth or
+wi-fi. But unfortunately there was not simple interface available.
+So, we thought to create our own generic interface using both these modes
+and release it to Tizen so that others can also contribute and improve it.
+
+Another problem was that we wanted to use generic Linux API on the server
+side to communicate with the raspberry pi and at the same time get connects
+with the Tizen Application using the Tizen API. So that the server part of
+the interface is not dependent on Tizen.
+This interface will also work with Raspbian OS in pi2 and with the same
+Tizen application.
+We have verified this with both Tizen OS as well as Raspbian OS on both pi1
+and pi2 without any modofication.
+The respective Tizen App was also developed using Tizen 2.4 SDK and verified
+by installing on Samsung Z2 device.
+The Tizen app is not part of this repository. It will be released to Tizen
+App Store separately, or you can easily develop your own after reading these
+description.
+
+To connect to wi-fi, a wi-fi USB dongle can be used and then wi-fi should be
+configured as described in the ELC paper.
+To connect to bluetooth, we have use HC-05 bluetooth module for pi2
+and connect over the TX/RX interface of raspberry pi.
+You can also use the bluetooth USB dongle to connect over bluez interface
+and using the bluetoothctl command. But these requires some changes in bluez
+to support the headless (no display) unit.
+Also the existing bt-robot-server initialization part needs to be changed to
+call the respective bluetooth-capi-network API.
+
+
+WHAT IS THIS REPOSITORY?
+------------------------
+This repository contains only the server part which can be installed on the
+raspberry pi. Once installed it will be running as part of systemd boot up
+service. The main purpose of these server is to listen on various commands
+from the application, then communicates with the raspberry pi and the
+peripherals connected to it using the GPIO interface.
+
+This repository contains two subpackages, once is based on bluetooth
+hc-05 and serial communication and another is based on wi-fi based socket
+communication.
+
+1) bt-robot-server:
+This is the bluetooth server part based on HC-05 bluetooth module interface.
+This requires existing serial access to be disabled in the system.
+When installed and working, you can see a [bt-robot-server] daemon running
+on your system after the login shell.
+
+2) wifi-robot-server:
+This is the wi-fi server part which uses normal TCP/IP based socket interface.
+When installed and working, you can see a [wifi-robot-server] daemon running
+on your system after the login shell.
+To communicate using this, wi-fi or tethering setup is required using
+connmanctl settings.
+
+Please note that only one mode of communication should be used while
+communicating with the robot. However both packages can be installed together.
+
+It also contains various interface that is described below:
+- bt-robot-server.c: This is the main file for bluetooth server.
+ It does various initialization and receives data from the client over the
+ serial port.
+- wifi-robot-server.c: This is the main file for wi-fi server.
+ It does various initialization and receives data from the client over the
+ TCP/IP port.
+- bt_serial.c: It contains the serial interface for HC-05 module.
+- gpioutils.c: It contains various APIs for GPIO read/write operation using
+ the sysfs interface.
+- motor_control.c: It contains API to control the DC motor movement.
+- led_control.c: It contains API to turn LED ON or OFF.
+- switch_control.c: It contains interface to power OFF the raspberry pi.
+- proxi_sensor.c: It contains interface to detect the obstacle by reading
+ the value from IR sensor.
+ This is designed using multi-thread to capture the response in parallel
+ while the robot movement is in progress.
+
+Every interface is designed here in the form of init/uninit/read/write to
+make it simple and portable. To create a new interface for any new peripheral
+simply copy the exisiting interface and change accordingly.
+
+
+HOW IT WORKS:
+-------------
+Once installed, both these service daemon will be running as part of
+systemd boot-up service under multi-users.target.
+bt-robot will configure the serial port and just waits for the data to be
+received over serial port.
+wifi-robot will configure socket interface and waits for the connection
+and accept signal from the client.
+Once it receive the data, it sents the value to the respective peripheral
+using the GPIO interface.
+A separate Tizen application is developed using the Tizen 2.4 SDK.
+This will act as a client.
+The app will send various commands to the server.
+C: This means Connect.
+When a char 'c' is sent the server will be connected to accept data.
+
+D: This means Disconnect.
+When 'd' is sent, the server will be disconnected and no more data
+will be accepted.
+
+F: This means Forward.
+When 'F' is received, the server will enable GPIO to move robot Forward.
+
+B: This means Back.
+When 'B' is received, the server will enable GPIO to move robot Back.
+
+L: This means Left.
+When 'L' is received, the server will enable GPIO to move robot Left.
+
+R: This means Right.
+When 'R' is received, the server will enable GPIO to move robot Right.
+
+S: This means Stop.
+When 'S' is received, the server will enable GPIO to stop the robot.
+
+The complete flow is described in the chart below:
+
+Systemd booting
+ |
+BT/Wi-Fi robot Server Start -> Turn on RED LED
+ |
+Is Connected to Client -> No -> Wait for connection
+ |
+Tizen App -> Press Connect -> Send character 'C'
+ |
+Is Connected -> Yes -> Turn on GREEN LED
+ |
+Wait for other commands -> No -> sleep
+ |
+Tizen App -> Press Forward -> Send character 'F'
+ |
+Send command {1,0,1,0} to motor using GPIO
+(Robot will be moving Forward)
+ |
+Is obstacle detected by robot -> No -> Keep reading GPIO status in separate thread
+ |
+Obstacle detected -> Yes
+ |
+Send command {0,1,0,1} to move robot backward
+ |
+Tizen App -> Press disconnect -> Send character 'D'
+ |
+Stop the robot and disconnect from the client
+ |
+Turn on RED LED
+
+
+COMPILATION AND INSTALLATION
+----------------------------
+To compile both the subpackages together on 32-bit x86 PC, use this:
+# ./build.sh tizen_common
+This will build both the packages and generates the .rpm package.
+This rpm package can be installed on raspberry pi using the following command:
+# rpm -Uvh --force --nodeps bt-robot-server-0.0.0.1.rpm
+Reboot the raspberry pi and check if [bt-robot-server] service is running.
+
+For building it on x86 PC, some more changes are required in your
+configuration file.
+Please refer to the comment section in build.sh script.
+
+For building it on 64-bit x86_64 just follow the normal gbs command.
+# gbs build -A armv7l --include-all --profile=tizen_common
+
+Here, tizen_common is the profile secction defined in ~/.gbs.conf file.
+Please choose the respective profile tag according to your gbs conf file.
+
+Follow exactly the same steps to compile and install the wi-fi server.
+
+
+TO DO LIST
+----------
+1) The bluetooth part can be extended to make it work with USB bluetooth
+ dongle using the bluez interface.
+2) The wi-fi package can be improved automatically configure tethering
+ and passkey setup using the connmanctl command during boot up itself
+ instead of manually configuring it.
+3) Create separate branch for raspberry pi.
+4) Verify it on raspberry pi 3 and raspberry pi 0 as well.
+5) Verify it on Beagle bone and other hardware using Linux.
+6) If possible make single package for both bluetooth & wi-fi and only
+ change the initialization part.
+
+
+CREDIT
+------
+This work is actually part of college intern project 2017 @ Samsung
+R&D India - Bangalore center.
+Below were the 2 interns also involved to make this successful.
+1) Akshit K Gandhi : <akshitgandhi999@gmail.com>
+2) Vivek Jain : NIT Warangal, India : < >
+
+We hope to contribute more in the future.
+
+
--- /dev/null
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+SET (this_target bt-robot-server)
+
+INCLUDE(FindPkgConfig)
+
+SET(bt-robot-server-required-pkgs
+ glib-2.0
+ dlog
+)
+
+pkg_check_modules(${this_target} REQUIRED "${bt-robot-server-required-pkgs}")
+
+FOREACH(flag ${${this_target}_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wl,-zdefs" )
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden")
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fPIE")
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fdata-sections -ffunction-sections -Wl,--gc-sections")
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -D_FILE_OFFSET_BITS=64")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
+SET(CMAKE_C_FLAGS_RELEASE "-O2")
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
+SET(CMAKE_SKIP_BUILD_RPATH TRUE)
+
+SET(BT_ROBOT_SERVER "bt-robot-server")
+
+SET(${BT_ROBOT_SERVER}_SOURCE_FILES
+ src/bt-robot-server.c
+ src/gpioutils.c
+ src/motor_control.c
+ src/bt_serial.c
+ src/proxi_sensor.c
+ src/led_control.c
+ src/switch_control.c
+ src/ldr_control.c
+ )
+ADD_EXECUTABLE(${BT_ROBOT_SERVER} ${${BT_ROBOT_SERVER}_SOURCE_FILES})
+
+TARGET_LINK_LIBRARIES(${BT_ROBOT_SERVER} ${${this_target}_LDFLAGS} "-pie" "-lpthread")
+
+SET_TARGET_PROPERTIES(${BT_ROBOT_SERVER}
+ PROPERTIES SKIP_BUILD_RPATH TRUE
+ ) # remove rpath option that is automatically generated by cmake.
+
+INSTALL(TARGETS ${BT_ROBOT_SERVER} DESTINATION bin)
--- /dev/null
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Lesser General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program 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 2 of the License, or
+ (at your option) any later version.
+
+ This program 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 this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) year name of author
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ <signature of Ty Coon>, 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Lesser General
+Public License instead of this License.
--- /dev/null
+<manifest>
+ <request>
+ <domain name="_"/>
+ </request>
+</manifest>
--- /dev/null
+[Unit]
+Description=Bluetooth Server daemon for remote control devices
+After=default.target
+
+[Service]
+Type=simple
+ExecStart=/usr/bin/bt-robot-server
+Restart=always
+RestartSec=0
+RemainAfterExit=yes
+
+[Install]
+WantedBy=multi-user.target
--- /dev/null
+/* bt-robot-server.c
+ *
+ * Copyright (c) 2017 Samsung Electronics, Inc.
+ *
+ * This program 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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.
+ */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <termios.h>
+#include <unistd.h>
+#include "motor_control.h"
+#include "bt_serial.h"
+#include "proxi_sensor.h"
+#include "led_control.h"
+#include "switch_control.h"
+#include "ldr_control.h"
+
+void disconnect(void)
+{
+ motor_uninit();
+ proxi_uninit();
+ //ldr_uninit();
+}
+
+void connect(void)
+{
+ motor_init();
+ proxi_init();
+// ldr_init();
+}
+
+int main(void)
+{
+ int fd = -1;
+ char data[255];
+ struct termios old;
+ int ret = -1;
+ int isconnected = 0;
+
+ serial_init(&fd, &old);
+ if (fd < 0) {
+ fprintf(stderr, "ERROR: serial_init failed\n");
+ return -1;
+ }
+
+ led_init();
+ switch_init();
+ //ldr_init();
+
+ /* Turn on RED LED */
+ led_write(LED_RED_PIN, 1);
+ led_write(LED_GREEN_PIN, 0);
+
+ while (1) {
+ char val;
+
+ ret = read(fd, &data, 255);
+ if (ret < 0) {
+ fprintf(stderr, "ERROR: %s: read failed\n", __func__);
+ continue;
+ }
+
+ val = data[0];
+ if ((val == 'c' || val == 'C') && isconnected == 0) {
+ printf("Robot connected....\n");
+ connect();
+ isconnected = 1;
+ /* Turn on GREEN LED */
+ led_write(LED_RED_PIN, 0);
+ led_write(LED_GREEN_PIN, 1);
+ } else if ((val == 'd' || val == 'D') && isconnected == 1) {
+ printf("Robot disconnected....\n");
+ disconnect();
+ isconnected = 0;
+ /* Turn on RED LED */
+ led_write(LED_RED_PIN, 1);
+ led_write(LED_GREEN_PIN, 0);
+ } else {
+ if (isconnected == 1 && val != 'd' && val != 'c') {
+ printf("Command send to motor : %c\n", val);
+ send_to_motor(val);
+ }
+ }
+ }
+ led_uninit();
+ switch_uninit();
+ serial_uninit(fd, old);
+ return 0;
+}
--- /dev/null
+/* bt_serial.c
+ *
+ * Copyright (c) 2017 Samsung Electronics, Inc.
+ *
+ * This program 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <termios.h>
+#include <unistd.h>
+#include "bt_serial.h"
+
+
+void serial_init(int *fd, struct termios *old)
+{
+ struct termios newtio;
+
+ *fd = open(DEV_NAME, O_RDWR | O_NOCTTY);
+ if (*fd < 0) {
+ fprintf(stderr, "ERROR: %s: open failed: %s\n",
+ __func__, strerror(errno));
+ return;
+ }
+ tcgetattr(*fd, old);
+ bzero(&newtio, sizeof(newtio));
+ newtio.c_cflag = BAUDRATE | CRTSCTS | CS8 | CLOCAL | CREAD;
+ newtio.c_iflag = IGNPAR;
+ newtio.c_oflag = 0;
+ newtio.c_lflag = 0;
+ newtio.c_cc[VTIME] = 0;
+ newtio.c_cc[VMIN] = 1;
+ tcflush(*fd, TCIFLUSH);
+ tcsetattr(*fd, TCSANOW, &newtio);
+}
+
+void serial_uninit(int fd, struct termios old)
+{
+ tcsetattr(fd, TCSANOW, &old);
+ close(fd);
+}
--- /dev/null
+/* bt_serial.h
+ *
+ * Copyright (c) 2017 Samsung Electronics, Inc.
+ *
+ * This program 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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.
+ */
+
+#ifndef __BT_SERIAL_H
+#define __BT_SERIAL_H
+
+#include <termios.h>
+
+#define DEV_NAME "/dev/ttyAMA0"
+#define BAUDRATE B9600
+
+void serial_init(int *fd, struct termios *old);
+void serial_uninit(int fd, struct termios old);
+
+
+#endif
+
--- /dev/null
+/* gpioutils.c
+ *
+ * Copyright (c) 2017 Samsung Electronics, Inc.
+ *
+ * This program 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 PARTI
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+
+int gpio_export(int num)
+{
+ char buf[64];
+ int fd;
+ int ret;
+
+ fd = open("/sys/class/gpio/export", O_WRONLY);
+ if (fd < 0) {
+ fprintf(stderr, "Failed to export gpio: %d\n", num);
+ return -1;
+ }
+ sprintf(buf, "%d", num);
+ ret = write(fd, buf, strlen(buf));
+ if (ret < 0) {
+ fprintf(stderr, "%s: Failed to write\n", __func__);
+ close(fd);
+ return -1;
+ }
+ close(fd);
+
+ return 0;
+}
+
+int gpio_unexport(int num)
+{
+ char buf[255];
+ int fd;
+ int ret;
+
+ fd = open("/sys/class/gpio/unexport", O_WRONLY);
+ if (fd < 0) {
+ fprintf(stderr, "Failed to unexport gpio: %d\n", num);
+ return -1;
+ }
+ sprintf(buf, "%d", num);
+ ret = write(fd, buf, strlen(buf));
+ if (ret < 0) {
+ fprintf(stderr, "%s: Failed to write\n", __func__);
+ close(fd);
+ return -1;
+ }
+ close(fd);
+
+ return 0;
+}
+
+int gpio_direction(int num, int dir)
+{
+ char path[64];
+ int fd;
+ int ret;
+
+ sprintf(path, "/sys/class/gpio/gpio%d/direction", num);
+ fd = open(path, O_WRONLY);
+ if (fd < 0) {
+ fprintf(stderr, "Failed to set dir: %d for gpio: %d\n",
+ dir, num);
+ return -1;
+ }
+ if (dir == 0) {
+ ret = write(fd, "in", 2);
+ if (ret < 0) {
+ fprintf(stderr, "%s: Failed to write\n", __func__);
+ close(fd);
+ return -1;
+ }
+ } else {
+ ret = write(fd, "out", 3);
+ if (ret < 0) {
+ fprintf(stderr, "%s: Failed to write\n", __func__);
+ close(fd);
+ return -1;
+ }
+ }
+
+ close(fd);
+
+ return 0;
+}
+
+int gpio_set_value(int num, int value)
+{
+ char path[64];
+ char buf[255];
+ int fd;
+ int ret;
+
+ sprintf(path, "/sys/class/gpio/gpio%d/value", num);
+ fd = open(path, O_WRONLY);
+ if (fd < 0) {
+ fprintf(stderr, "Failed to set value: %d for gpio: %d\n",
+ value, num);
+ return -1;
+ }
+ sprintf(buf, "%d", value);
+ ret = write(fd, buf, strlen(buf));
+ if (ret < 0) {
+ fprintf(stderr, "%s: Failed to write\n", __func__);
+ close(fd);
+ return -1;
+ }
+
+ close(fd);
+
+ return 0;
+}
+
+int gpio_get_value(int num, int *value)
+{
+ char path[64];
+ char buf[255];
+ int fd;
+ int ret;
+
+ sprintf(path, "/sys/class/gpio/gpio%d/value", num);
+ fd = open(path, O_RDONLY);
+ if (fd < 0) {
+ fprintf(stderr, "Failed to get value for gpio: %d\n", num);
+ fprintf(stderr, "%s: ERROR: %s\n", __func__, strerror(errno));
+ return -1;
+ }
+ ret = read(fd, buf, 255);
+ if (ret < 0) {
+ fprintf(stderr, "%s: Failed to read\n", __func__);
+ close(fd);
+ return -1;
+ }
+ *value = atoi(buf);
+ close(fd);
+
+ return 0;
+}
+
--- /dev/null
+/* gpioutils.h
+ *
+ * Copyright (c) 2017 Samsung Electronics, Inc.
+ *
+ * This program 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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.
+ */
+
+#ifndef __GPIOUTILS_H
+#define __GPIOUTILS_H
+
+
+int gpio_export(int num);
+int gpio_unexport(int num);
+int gpio_direction(int num, int dir);
+int gpio_set_value(int num, int value);
+int gpio_get_value(int num, int *value);
+
+#endif
--- /dev/null
+/* ldr_control.c
+ *
+ * Copyright (c) 2017 Samsung Electronics, Inc.
+ *
+ * This program 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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.
+ */
+
+#include <stdio.h>
+#include <errno.h>
+#include <pthread.h>
+#include <unistd.h>
+#include <string.h>
+#include "gpioutils.h"
+#include "ldr_control.h"
+
+#define LDR_DARK_THRESHOLD 2000
+
+volatile int terminate_ldr = 0;
+
+void *ldr_read_func(void *arg)
+{
+ int v = 0;
+
+ while (!terminate_ldr) {
+ ldr_read(&v);
+ if (v > LDR_DARK_THRESHOLD)
+ fprintf(stderr, "Too dark: %d\n",v);
+ sleep(1);
+ }
+ usleep(100 * 1000);
+
+ return NULL;
+}
+
+void ldr_init(void)
+{
+ int ret;
+
+ terminate_ldr = 0;
+
+ gpio_export(LDR_PIN);
+ ret = pthread_create(&ldr_tid, NULL, ldr_read_func, NULL);
+ if (ret < 0) {
+ fprintf(stderr, "%s: pthread_create error: %s\n",
+ __func__, (char *)strerror(errno));
+ }
+
+}
+
+void ldr_uninit(void)
+{
+ terminate_ldr = 1;
+ pthread_detach(ldr_tid);
+ gpio_unexport(LDR_PIN);
+}
+
+void ldr_read(int *s)
+{
+ int count = 0;
+ gpio_direction(LDR_PIN, 1);
+ gpio_set_value(LDR_PIN, 0);
+ usleep(100000);
+ gpio_direction(LDR_PIN, 0);
+ while (1) {
+ int v = 0;
+ gpio_get_value(LDR_PIN, &v);
+ if (v == 0)
+ count++;
+ else
+ break;
+ }
+ *s = count;
+}
--- /dev/null
+/* ldr_control.h
+ *
+ * Copyright (c) 2017 Samsung Electronics, Inc.
+ *
+ * This program 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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.
+ */
+
+#ifndef __LDR_CONTROL_H
+#define __LDR_CONTROL_H
+#include <pthread.h>
+
+pthread_t ldr_tid;
+
+#define LDR_PIN 4
+
+void ldr_init(void);
+void ldr_uninit(void);
+void ldr_read(int *v);
+
+
+#endif
--- /dev/null
+/* led_control.c
+ *
+ * Copyright (c) 2017 Samsung Electronics, Inc.
+ *
+ * This program 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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.
+ */
+
+#include <stdio.h>
+#include <errno.h>
+#include "gpioutils.h"
+#include "led_control.h"
+
+
+void led_init(void)
+{
+ gpio_export(LED_RED_PIN);
+ gpio_direction(LED_RED_PIN, 1);
+
+ gpio_export(LED_GREEN_PIN);
+ gpio_direction(LED_GREEN_PIN, 1);
+}
+
+void led_uninit(void)
+{
+ gpio_unexport(LED_RED_PIN);
+ gpio_unexport(LED_GREEN_PIN);
+}
+
+void led_write(int num, int value)
+{
+ gpio_set_value(num, value);
+}
+
--- /dev/null
+/* led_control.h
+ *
+ * Copyright (c) 2017 Samsung Electronics, Inc.
+ *
+ * This program 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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.
+ */
+
+#ifndef __LED_CONTROL_H
+#define __LED_CONTROL_H
+
+
+#define LED_RED_PIN 20
+#define LED_GREEN_PIN 21
+
+
+void led_init(void);
+void led_uninit(void);
+void led_write(int num, int value);
+
+
+#endif
--- /dev/null
+/* motor_control.c
+ *
+ * Copyright (c) 2017 Samsung Electronics, Inc.
+ *
+ * This program 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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.
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include "gpioutils.h"
+#include "motor_control.h"
+
+void motor_stop(void)
+{
+ gpio_set_value(MOTORA_1, 0);
+ gpio_set_value(MOTORA_2, 0);
+ gpio_set_value(MOTORB_1, 0);
+ gpio_set_value(MOTORB_2, 0);
+ printf("Motor Stopped....\n");
+}
+
+void send_to_motor(char c)
+{
+ switch (c) {
+ case 'F':
+ case 'f':
+ motor_stop();
+ gpio_set_value(MOTORA_1, 1);
+ gpio_set_value(MOTORA_2, 0);
+ gpio_set_value(MOTORB_1, 1);
+ gpio_set_value(MOTORB_2, 0);
+ printf("Moving Forward....\n");
+ break;
+
+ case 'B':
+ case 'b':
+ motor_stop();
+ gpio_set_value(MOTORA_1, 0);
+ gpio_set_value(MOTORA_2, 1);
+ gpio_set_value(MOTORB_1, 0);
+ gpio_set_value(MOTORB_2, 1);
+ printf("Moving Back....\n");
+ break;
+
+ case 'L':
+ case 'l':
+ motor_stop();
+ gpio_set_value(MOTORA_1, 0);
+ gpio_set_value(MOTORA_2, 0);
+ gpio_set_value(MOTORB_1, 1);
+ gpio_set_value(MOTORB_2, 0);
+ printf("Moving Left....\n");
+ //Delay for 200ms after left movement and then stop
+ usleep(200 * 1000);
+ motor_stop();
+ break;
+
+ case 'R':
+ case 'r':
+ motor_stop();
+ gpio_set_value(MOTORA_1, 1);
+ gpio_set_value(MOTORA_2, 0);
+ gpio_set_value(MOTORB_1, 0);
+ gpio_set_value(MOTORB_2, 0);
+ printf("Moving Right....\n");
+ //Delay for 200ms after right movement and then stop
+ usleep(200 * 1000);
+ motor_stop();
+ break;
+
+ case 'S':
+ case 's':
+ printf("Stopping....\n");
+ motor_stop();
+ break;
+ }
+}
+
+void motor_init()
+{
+ gpio_export(MOTORA_1);
+ gpio_direction(MOTORA_1, 1);
+
+ gpio_export(MOTORA_2);
+ gpio_direction(MOTORA_2, 1);
+
+ gpio_export(MOTORB_1);
+ gpio_direction(MOTORB_1, 1);
+
+ gpio_export(MOTORB_2);
+ gpio_direction(MOTORB_2, 1);
+
+ printf("motor init - done\n");
+}
+
+
+void motor_uninit()
+{
+ motor_stop();
+
+ gpio_unexport(MOTORA_1);
+
+ gpio_unexport(MOTORA_2);
+
+ gpio_unexport(MOTORB_1);
+
+ gpio_unexport(MOTORB_2);
+ printf("motor uninit - done\n");
+}
+
--- /dev/null
+/* motor_control.h
+ *
+ * Copyright (c) 2017 Samsung Electronics, Inc.
+ *
+ * This program 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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.
+ */
+
+#ifndef __MOTOR_CONTROL_H
+#define __MOTOR_CONTROL_H
+
+#define MOTORA_1 17
+#define MOTORA_2 18
+#define MOTORB_1 22
+#define MOTORB_2 23
+
+void motor_init(void);
+void motor_uninit(void);
+void motor_stop(void);
+void send_to_motor(char c);
+
+
+#endif
--- /dev/null
+/* proxi_sensor.c
+ *
+ * Copyright (c) 2017 Samsung Electronics, Inc.
+ *
+ * This program 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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.
+ */
+
+#include <stdio.h>
+#include <pthread.h>
+#include <errno.h>
+#include <unistd.h>
+#include <string.h>
+#include "gpioutils.h"
+#include "proxi_sensor.h"
+#include "motor_control.h"
+#include "led_control.h"
+
+
+volatile int terminate_proxi = 0;
+
+void *proxi_read_func(void *arg)
+{
+ int v = -1;
+ char val = 'b';
+
+ while (!terminate_proxi) {
+ proxi_read(&v);
+ if (v == 0) {
+ fprintf(stderr, "obstacle detected by robot: v: %d\n", v);
+ send_to_motor(val);
+ v = 1;
+ sleep(1);
+ }
+ usleep(100 * 1000);
+ }
+ return NULL;
+}
+
+
+void proxi_init()
+{
+ int ret;
+
+ gpio_export(PROXI_PORT);
+ gpio_direction(PROXI_PORT, 0);
+
+ terminate_proxi = 0;
+
+ ret = pthread_create(&proxi_tid, NULL, proxi_read_func, NULL);
+ if (ret < 0) {
+ fprintf(stderr, "%s: pthread_create error: %s\n",
+ __func__, (char *)strerror(errno));
+ }
+}
+
+void proxi_uninit()
+{
+ terminate_proxi = 1;
+ pthread_detach(proxi_tid);
+ gpio_unexport(PROXI_PORT);
+}
+
+void proxi_read(int *v)
+{
+ gpio_get_value(PROXI_PORT, v);
+}
+
--- /dev/null
+/* proxi_sensor.h
+ *
+ * Copyright (c) 2017 Samsung Electronics, Inc.
+ *
+ * This program 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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.
+ */
+
+#ifndef __PROXI_SENSOR_H
+#define __PROXI_SENSOR_H
+
+#include <pthread.h>
+
+
+#define PROXI_PORT 27
+
+pthread_t proxi_tid;
+
+void proxi_init(void);
+void proxi_uninit(void);
+void proxi_read(int *v);
+
+
+#endif
--- /dev/null
+/* switch_control.c
+ *
+ * Copyright (c) 2017 Samsung Electronics, Inc.
+ *
+ * This program 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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.
+ */
+
+#include <stdio.h>
+#include <errno.h>
+#include <unistd.h>
+#include <string.h>
+#include <pthread.h>
+#include <linux/reboot.h>
+#include <sys/reboot.h>
+#include "gpioutils.h"
+#include "switch_control.h"
+#include "motor_control.h"
+#include "led_control.h"
+#include "proxi_sensor.h"
+
+
+volatile int terminate_switch = 0;
+
+void *switch_read_func(void *arg)
+{
+ int v = 0;
+
+ while (!terminate_switch) {
+ switch_read(&v);
+ if (v == 1) {
+ fprintf(stderr,"Switch enabled, turning off robot\n");
+ sync();
+ led_uninit();
+ reboot(LINUX_REBOOT_CMD_POWER_OFF);
+ printf("after reboot\n");
+ }
+ sleep(1);
+ }
+
+ return NULL;
+}
+
+void switch_init(void)
+{
+ int ret;
+
+ terminate_switch = 0;
+
+ gpio_export(SWITCH_PIN);
+ gpio_direction(SWITCH_PIN, 0);
+ ret = pthread_create(&switch_tid, NULL, switch_read_func, NULL);
+ if (ret < 0) {
+ fprintf(stderr, "%s: pthread_create error: %s\n",
+ __func__, (char *)strerror(errno));
+ }
+
+}
+
+void switch_uninit(void)
+{
+ terminate_switch = 1;
+ pthread_detach(switch_tid);
+ gpio_unexport(SWITCH_PIN);
+}
+
+void switch_read(int *s)
+{
+ gpio_get_value(SWITCH_PIN, s);
+}
--- /dev/null
+/* switch_control.h
+ *
+ * Copyright (c) 2017 Samsung Electronics, Inc.
+ *
+ * This program 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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.
+ */
+
+#ifndef __SWITCH_CONTROL_H
+#define __SWITCH_CONTROL_H
+#include <pthread.h>
+
+pthread_t switch_tid;
+
+#define SWITCH_PIN 12
+
+
+void switch_init(void);
+void switch_uninit(void);
+void switch_read(int *s);
+
+
+#endif
+
--- /dev/null
+#!/bin/bash
+
+if [ "$1" = "" ]
+then
+ echo "Please specify the profile to build..."
+ echo "./build.sh tizen_common"
+ exit
+fi
+
+# Now tizen common profile can be build only on Linux 64-bit machine
+# To build it on 32-bit machine, we need to change the <profile>.conf file under:
+# /home/pintu/GBS-ROOT/local/BUILD-ROOTS/scratch.armv7l.0/tizen_common.conf
+# Change: build_hostarch x86_64 => to x86, at all place in this conf file
+# Then copy this file locally and use -D option to build
+
+gbs build -A armv7l --include-all --profile=$1 -D ./tizen_common.conf
+rc=$?
+if [ $rc -ne 0 ]
+then
+ echo "build failed..."
+else
+ echo "build success....copy the rpm"
+ rm -f *.rpm
+ cp -f ~/GBS-ROOT/local/repos/$1/armv7l/RPMS/bt-robot-server-*.armv7l.rpm .
+ cp -f ~/GBS-ROOT/local/repos/$1/armv7l/RPMS/wifi-robot-server-*.armv7l.rpm .
+fi
+
--- /dev/null
+Name: robotics
+Summary: robotics server application
+Version: 0.0.0.1
+Release: 0
+Group: Network & Connectivity/Service
+License: GPL-2.0
+URL: www.tizen.org
+Source0: %{name}-%{version}.tar.gz
+
+BuildRequires: cmake
+BuildRequires: pkgconfig(dlog)
+BuildRequires: pkgconfig(glib-2.0)
+
+Requires(post): /sbin/ldconfig
+Requires(post): /usr/bin/systemctl
+Requires(postun): /sbin/ldconfig
+Requires(postun): /usr/bin/systemctl
+Requires(preun): /usr/bin/systemctl
+
+%description
+Robotics Remote Control Server Application
+
+%package -n bt-robot-server
+Summary: Bluetooth remote server app (devel)
+Group: Development/Libraries
+Requires: %{name} = %{version}-%{release}
+%description -n bt-robot-server
+Bluetooth Remote Control Server Application (devel)
+
+%package -n wifi-robot-server
+Summary: WIFI remote server app (devel)
+Group: Development/Libraries
+Requires: %{name} = %{version}-%{release}
+%description -n wifi-robot-server
+Wi-Fi Remote Control Server Application (devel)
+
+%prep
+%setup -q
+
+%build
+export CFLAGS="$CFLAGS -DTIZEN_DEBUG_ENABLE"
+export CXXFLAGS="$CXXFLAGS -DTIZEN_DEBUG_ENABLE"
+export FFLAGS="$FFLAGS -DTIZEN_DEBUG_ENABLE"
+
+cmake -DCMAKE_INSTALL_PREFIX=%{_prefix}
+make %{?jobs:-j%jobs}
+
+%install
+rm -rf %{buildroot}
+%make_install
+mkdir -p %{buildroot}/usr/share/license
+cp LICENSE %{buildroot}/usr/share/license/%{name}
+
+mkdir -p %{buildroot}%{_libdir}/systemd/system/default.target.wants
+install -m 644 bt-robot-server/bt-robot-server.service %{buildroot}%{_libdir}/systemd/system/bt-robot-server.service
+install -m 644 wifi-robot-server/wifi-robot-server.service %{buildroot}%{_libdir}/systemd/system/wifi-robot-server.service
+
+%post -n bt-robot-server
+/usr/bin/systemctl daemon-reload
+/usr/bin/systemctl enable bt-robot-server.service
+
+%post -n wifi-robot-server
+/usr/bin/systemctl daemon-reload
+/usr/bin/systemctl enable wifi-robot-server.service
+
+%preun -n bt-robot-server
+/usr/bin/systemctl disable bt-robot-server.service
+
+%preun -n wifi-robot-server
+/usr/bin/systemctl disable wifi-robot-server.service
+
+%files
+%doc README
+%license LICENSE
+
+%files -n bt-robot-server
+%manifest bt-robot-server/bt-robot-server.manifest
+%license bt-robot-server/LICENSE
+%{_prefix}/share/license/%{name}
+%attr(0700,root,root) %{_bindir}/bt-robot-server
+%{_libdir}/systemd/system/bt-robot-server.service
+
+%files -n wifi-robot-server
+%manifest wifi-robot-server/wifi-robot-server.manifest
+%license wifi-robot-server/LICENSE
+%{_prefix}/share/license/%{name}
+%attr(0700,root,root) %{_bindir}/wifi-robot-server
+%{_libdir}/systemd/system/wifi-robot-server.service
--- /dev/null
+%define _project Tizen:Common
+
+### from Tizen:Base
+%define _repository arm
+
+Macros:
+%vendor obs://build.tizen.org/Tizen:Common
+%_project Tizen:Common
+
+### from Tizen:Base
+
+%_repository arm
+:Macros
+
+################################################################################
+# OBS Project config for Tizen:Base
+#
+# RE contacts:
+#
+#
+# vim: set syntax=spec:
+################################################################################
+
+Patterntype: rpm-md comps
+Release: <CI_CNT>.<B_CNT>
+Support: build
+Support: build-compare build-mkbaselibs
+# Support: rpmlint-mini rpmlint-tizen
+
+############################# conflicts resolution #############################
+
+Prefer: util-linux
+Prefer: mono-wcf
+Prefer: monodoc
+Prefer: mono-extras
+Prefer: mono-web
+Prefer: mono-data
+Prefer: mono-mvc
+Prefer: mono-winforms
+Prefer: mono-data-sqlite
+
+# Set a preference for ambiguous libs to use *-64bit libs
+# *-64bit libs on 32bit build environment are required for .Net build (e.g., coreclr, corefx)
+# But when building 64bit target, they could make 'have choice' error with original libs in 64bit repository.
+# e.g., libstdc++ and libstdc++-64bit provides same libs. It's ambiguous to choose appropriate one.
+# Owner : Jiyoung Yun (jy910.yun@samsung.com)
+Prefer: libgcc libstdc++ libunwind libuuid zlib libopenssl
+
+############################# base definition ###############################
+
+Macros:
+%vendor tizen
+%_vendor tizen
+%_with_tizen 1
+
+%check exit 0
+%run_check_section 0
+%opensuse_bs 1
+%_default_patch_fuzz 2
+
+%_binary_payload w5T.xzdio
+:Macros
+
+
+############################# build config #####################################
+
+%define gcc_version 62
+Macros:
+%gcc_version 62
+:Macros
+
+########## targets ##########
+
+%ifarch i586
+Target: i686-tizen-linux
+%endif
+
+%ifarch armv7hl
+Target: armv7hl-tizen-linux
+%endif
+
+%ifarch armv7l
+Target: armv7l-tizen-linux
+%endif
+
+%ifarch aarch64
+Target: aarch64-tizen-linux
+%endif
+
+########## cross build ##########
+
+%define build_hostarch x86
+Macros:
+%build_hostarch x86
+:Macros
+
+%ifarch %arm armv7l aarch64
+Hostarch: x86_64
+# cross build support for the build hosts
+Preinstall: qemu-linux-user-%{build_hostarch}-cross
+Runscripts: qemu-linux-user-%{build_hostarch}-cross
+Keep: qemu-linux-user-%{build_hostarch}-cross
+%endif
+
+%ifarch armv7l
+Preinstall: qemu-accel-%{build_hostarch}-armv7l
+Runscripts: qemu-accel-%{build_hostarch}-armv7l
+Preinstall: libmount libblkid libuuid
+%endif
+
+%ifarch aarch64
+Preinstall: qemu-accel-%{build_hostarch}-aarch64
+Runscripts: qemu-accel-%{build_hostarch}-aarch64
+Preinstall: libmount libblkid libuuid
+%endif # aarch64
+
+Substitute: python-accel-armv7l-cross-arm python-accel-%{build_hostarch}-armv7l
+Substitute: python-accel-aarch64-cross-aarch64 python-accel-%{build_hostarch}-aarch64
+
+########## exports for different architectures ##########
+
+ExportFilter: \.armv7l\.rpm$ armv7l
+ExportFilter: \.aarch64\.rpm$ aarch64
+ExportFilter: \.i586\.rpm$ i586
+ExportFilter: \.x86_64\.rpm$ x86_64
+
+########## buildroot config ##########
+
+Preinstall: setup filesystem
+RunScripts: setup
+
+Preinstall: bash bzip2 coreutils diffutils grep rpm
+Preinstall: glibc libacl libattr
+Preinstall: libcap
+Preinstall: libgcc
+Preinstall: libpopt sed tar zlib
+Preinstall: libncurses libreadline
+Preinstall: libelf libbz2
+Preinstall: liblzma
+Preinstall: nss nspr libfreebl3 libsoftokn3
+Preinstall: libmagic
+Preinstall: liblua
+Preinstall: smack libsmack libxml2 libmagic libmagic-data
+Preinstall: libsqlite
+#Preinstall: rpm-security-plugin
+Preinstall: util-linux util-linux-su
+
+VMinstall: perl libmount libblkid libext2fs libuuid grep libpcre util-linux libsmartcols procps-ng
+
+Required: binutils gcc glibc rpm-build libtool
+Required: gcc-c++
+
+Support: glibc-locale
+Support: perl
+Support: hostname
+Support: cpio findutils
+Support: file findutils zlib bzip2
+Support: gzip hostname net-tools
+Support: make patch sed gawk tar grep coreutils pkg-config
+Support: m4 tzdata
+Support: util-linux
+Support: less
+Support: which elfutils
+Support: update-alternatives
+Support: libstdc++-devel
+Support: cpp
+Support: libatomic
+Support: libgomp
+Support: libitm
+
+Keep: libstdc++-devel
+Keep: cpp gcc libstdc++
+Keep: pam
+Keep: binutils cpp libmagic-data file findutils gawk gcc gcc-c++
+Keep: gdbm gzip libada libunwind glibc-devel libpcre xz-lzma-compat
+Keep: make gmp libcap groff cpio
+Keep: patch rpm-build nss nspr elfutils python grep libgcc gcc-c++
+Keep: kernel-headers perl-libs perl
+Keep: pkgconfig glib2 tizen-rpm-config
+Keep: libmpc libmpfr libppl libgmp libppl_c
+Keep: libcloog libppl libgmpxx
+Keep: nss-softokn-freebl libmagic libmagic-data
+Keep: setup
+Keep: update-alternatives
+Keep: cpp
+Keep: gcc-c++
+Keep: libatomic
+Keep: libgomp
+Keep: libitm
+
+Substitute: gettext gettext-tools
+
+%ifarch x86_64
+Substitute: glibc-devel-32bit glibc-devel-32bit glibc-32bit
+Substitute: libgcc_s1-32bit libgcc-32bit
+%else
+Substitute: glibc-devel-32bit
+%endif
+
+########## compilation flags ##########
+%define __global_cflags -O2 -g2 -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector -Wformat-security -fmessage-length=0 -Wl,--as-needed
+
+Optflags: armv7l %{__global_cflags} --param=ssp-buffer-size=4 -march=armv7-a -mtune=cortex-a8 -mlittle-endian -mfpu=neon -mfloat-abi=softfp -mthumb -Wp,-D__SOFTFP__ -Wl,-O1 -Wl,--hash-style=gnu -Wa,-mimplicit-it=thumb
+Optflags: aarch64 %{__global_cflags} -feliminate-unused-debug-types -Wformat -march=armv8-a+fp+simd+crc+crypto -mtune=cortex-a57.cortex-a53
+Optflags: i686 %{__global_cflags} -feliminate-unused-debug-types --param=ssp-buffer-size=4 -fdiagnostics-color=never -m32 -march=i686 -mtune=i686 -msse4.2 -mfpmath=sse -fasynchronous-unwind-tables -fno-omit-frame-pointer
+Optflags: x86_64 %{__global_cflags} -feliminate-unused-debug-types --param=ssp-buffer-size=4 -fdiagnostics-color=never -m64 -march=corei7 -msse4.2 -mtune=corei7-avx -mfpmath=sse -fasynchronous-unwind-tables -fno-omit-frame-pointer
+### from Tizen:Common
+%define _repository arm-wayland
+
+Macros:
+
+%distribution Tizen:Common / arm-wayland
+%_project Tizen:Common
+
+### from Tizen:Common
+
+%_repository arm-wayland
+:Macros
+
+################################################################################
+# OBS Project config for Tizen:Common
+#
+# RE contacts:
+# Maciej Wereski <m.wereski@partner.samsung.com>
+# Pawel Wieczorek <p.wieczorek2@samsung.com>
+#
+# Git mirror for OBS config: review.tizen.org:scm/meta/build-config / branch tizen_common
+#
+# vim: set syntax=spec:
+################################################################################
+
+############################# conflicts resolution #############################
+
+FileProvides: /etc/default/useradd shadow-utils
+FileProvides: /usr/sbin/useradd shadow-utils
+FileProvides: /etc/login.defs shadow-utils
+FileProvides: /usr/sbin/chpasswd shadow-utils
+FileProvides: /usr/sbin/groupadd shadow-utils
+FileProvides: /usr/sbin/groupdel shadow-utils
+FileProvides: /usr/sbin/groupmod shadow-utils
+FileProvides: /usr/sbin/userdel shadow-utils
+FileProvides: /usr/sbin/usermod shadow-utils
+Prefer: shadow-utils
+
+Prefer: libtapi-devel
+Prefer: libpci-devel
+Prefer: bluetooth-tools-no-firmware
+
+Prefer: vconf-buxton
+Prefer: vconf-buxton-devel
+Prefer: vconf-buxton-keys-devel
+
+############################# profile definition ###############################
+
+%define profile common
+%define _with_tizen 1
+
+# %release_name and %tizen_full_version are used in platform/upstream/tizen-release
+
+Macros:
+%profile common
+%release_name Tizen3/Common
+
+%tizen_version_major 3
+%tizen_version_minor 0
+%tizen_version_patch 0
+
+%tizen_version %{tizen_version_major}.%{tizen_version_minor}
+%tizen_full_version %{tizen_version}.%{tizen_version_patch}
+%tizen %tizen_version
+%vendor tizen
+%_vendor tizen
+%_with_tizen 1
+
+%check exit 0
+%run_check_section 0
+%opensuse_bs 1
+%_default_patch_fuzz 2
+:Macros
+
+########## RDP flag ##########
+
+# enable/disable RDP (remote desktop protocol) for wayland
+# flag: _with_rdp, used in repositories
+# Affects: weston, freerdp
+# Owner: Manuel <manuel.bachmann@open.eurogiciel.org>
+
+########## mesa activation ##########
+
+%define _with_mesa 1
+Macros:
+%_with_mesa 1
+:Macros
+
+Substitute: mesa-devel pkgconfig(glesv2)
+Substitute: pkgconfig(gles20) pkgconfig(egl) pkgconfig(glesv2)
+Substitute: pkgconfig(gles11) pkgconfig(egl) pkgconfig(glesv1) pkgconfig(gl)
+
+############################# common config ####################################
+
+Prefer: coregl coregl-devel
+Prefer: libwayland-egl libwayland-egl-devel
+
+%define _with_wayland 1
+Macros:
+%_with_wayland 1
+:Macros
+
+############################# wayland repositories #############################
+
+%if "%_repository" == "arm-wayland" || "%_repository" == "arm64-wayland" || "%_repository" == "ia32-wayland" || "%_repository" == "x86_64-wayland"
+
+Prefer: mesa libgbm
+Substitute: mesa-libGLESv2 coregl
+Substitute: mesa-libEGL coregl
+
+%define _with_rdp 1
+Macros:
+%_with_rdp 1
+:Macros
+
+%endif
+
+############################# emulator repositories ############################
+
+%if "%_repository" == "emulator32-wayland"
+
+Prefer: libgbm
+Prefer: emulator-yagl emulator-yagl-devel
+
+%define _with_emulator 1
+Macros:
+%_with_emulator 1
+:Macros
+
+%endif
+
+
+############################# misc config flags ################################
+
+########## USAGE ##########
+#
+# IMPORTANT: please follow the following rules when playing with flags
+# ********************************************************************
+#
+# In spec file, call %bcond_with macro at the beginning and test with %with:
+# -------------------------
+# | %bcond_with myfeature
+# | [...]
+# | %if %{with myfeature}
+# | [...]
+# | %endif
+# | [...]
+# -------------------------
+#
+# To activate an option, use:
+# -------------------------
+# | %define _with_myfeature 1
+# | Macros:
+# | %_with_myfeature 1
+# | :Macros
+# -------------------------
+#
+# To disable an option, DON'T set the values to 0, as the option would still be defined
+# but simply comment the lines: this will undefine the option.
+# -------------------------
+# | #%define _with_myfeature 1
+# | #Macros:
+# | #%_with_myfeature 1
+# | #:Macros
+# -------------------------
+#
+# More information here:
+# https://en.opensuse.org/openSUSE:Build_Service_prjconf#.25bcond
+#
+
+########## flags ##########
+
+# This build macro controls the libdlog output. If enabled,
+# libdlog writes to Systemd Journal. If disabled, libdlog writes to kernel Android
+# logger FIFO. Affects: dlog.
+# Owner: Mikko <mikko.ylinen@intel.com>
+Macros:
+%_with_dlog_to_systemd_journal 1
+:Macros
+
+# Macro used for testing gstreamer 1.X API
+# Used: qt*
+# Owner: Philippe Coval <philippe.coval@open.eurogiciel.org>
+%define _with_gstreamer1 1
+Macros:
+%_with_gstreamer1 1
+:Macros
+
+# Macro used for testing libva availability
+# Used: weston
+# Owner: Philippe Coval <philippe.coval@open.eurogiciel.org>
+%ifarch x86_64 i586
+%define _with_libva 1
+Macros:
+%_with_libva 1
+:Macros
+%endif
+
+# Macro used for testing Input methods
+# Used: qt*
+# Owner: Philippe Coval <philippe.coval@open.eurogiciel.org>
+#%define _with_tizenscim 1
+#Macros:
+#%_with_tizenscim 1
+#:Macros
+
+# Activate introspection
+# This is needed on GuPNP to build Rygel correctly in IVI
+# Impacts potentially packages that use gobject-introspection
+# Owner: Mikko <mikko.ylinen@intel.com>
+Macros:
+%_with_introspection 1
+:Macros
+
+# Activate KDBUS
+# This configuration flag enables the support of KDBUS
+# Used: platform/upstream/setup
+# Owner: Stephane Desneux <stephane.desneux@open.eurogiciel.org>
+#%define _with_kdbus 1
+#Macros:
+#%_with_kdbus 1
+#:Macros
+
+############################# build config #####################################
+# derived from Tizen:Base
+################################################################################
+
+########## compilation flags ##########
+# derived from Tizen:Base
+#######################################
--- /dev/null
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+SET (this_target wifi-robot-server)
+
+INCLUDE(FindPkgConfig)
+
+SET(wifi-robot-server-required-pkgs
+ glib-2.0
+ dlog
+)
+
+pkg_check_modules(${this_target} REQUIRED "${wifi-robot-server-required-pkgs}")
+
+FOREACH(flag ${${this_target}_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wl,-zdefs" )
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden")
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fPIE")
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fdata-sections -ffunction-sections -Wl,--gc-sections")
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -D_FILE_OFFSET_BITS=64")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
+SET(CMAKE_C_FLAGS_RELEASE "-O2")
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
+SET(CMAKE_SKIP_BUILD_RPATH TRUE)
+
+SET(WIFI_ROBOT_SERVER "wifi-robot-server")
+
+SET(${WIFI_ROBOT_SERVER}_SOURCE_FILES
+ src/wifi-robot-server.c
+ src/gpioutils.c
+ src/motor_control.c
+ src/proxi_sensor.c
+ src/led_control.c
+ src/switch_control.c
+ src/ldr_control.c
+ )
+ADD_EXECUTABLE(${WIFI_ROBOT_SERVER} ${${WIFI_ROBOT_SERVER}_SOURCE_FILES})
+
+TARGET_LINK_LIBRARIES(${WIFI_ROBOT_SERVER} ${${this_target}_LDFLAGS} "-pie" "-lpthread")
+
+SET_TARGET_PROPERTIES(${WIFI_ROBOT_SERVER}
+ PROPERTIES SKIP_BUILD_RPATH TRUE
+ ) # remove rpath option that is automatically generated by cmake.
+
+INSTALL(TARGETS ${WIFI_ROBOT_SERVER} DESTINATION bin)
--- /dev/null
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Lesser General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program 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 2 of the License, or
+ (at your option) any later version.
+
+ This program 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 this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) year name of author
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ <signature of Ty Coon>, 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Lesser General
+Public License instead of this License.
--- /dev/null
+/* gpioutils.c
+ *
+ * Copyright (c) 2017 Samsung Electronics, Inc.
+ *
+ * This program 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 PARTI
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+
+int gpio_export(int num)
+{
+ char buf[64];
+ int fd;
+ int ret;
+
+ fd = open("/sys/class/gpio/export", O_WRONLY);
+ if (fd < 0) {
+ fprintf(stderr, "Failed to export gpio: %d\n", num);
+ return -1;
+ }
+ sprintf(buf, "%d", num);
+ ret = write(fd, buf, strlen(buf));
+ if (ret < 0) {
+ fprintf(stderr, "%s: Failed to write\n", __func__);
+ close(fd);
+ return -1;
+ }
+ close(fd);
+
+ return 0;
+}
+
+int gpio_unexport(int num)
+{
+ char buf[255];
+ int fd;
+ int ret;
+
+ fd = open("/sys/class/gpio/unexport", O_WRONLY);
+ if (fd < 0) {
+ fprintf(stderr, "Failed to unexport gpio: %d\n", num);
+ return -1;
+ }
+ sprintf(buf, "%d", num);
+ ret = write(fd, buf, strlen(buf));
+ if (ret < 0) {
+ fprintf(stderr, "%s: Failed to write\n", __func__);
+ close(fd);
+ return -1;
+ }
+ close(fd);
+
+ return 0;
+}
+
+int gpio_direction(int num, int dir)
+{
+ char path[64];
+ int fd;
+ int ret;
+
+ sprintf(path, "/sys/class/gpio/gpio%d/direction", num);
+ fd = open(path, O_WRONLY);
+ if (fd < 0) {
+ fprintf(stderr, "Failed to set dir: %d for gpio: %d\n",
+ dir, num);
+ return -1;
+ }
+ if (dir == 0) {
+ ret = write(fd, "in", 2);
+ if (ret < 0) {
+ fprintf(stderr, "%s: Failed to write\n", __func__);
+ close(fd);
+ return -1;
+ }
+ } else {
+ ret = write(fd, "out", 3);
+ if (ret < 0) {
+ fprintf(stderr, "%s: Failed to write\n", __func__);
+ close(fd);
+ return -1;
+ }
+ }
+
+ close(fd);
+
+ return 0;
+}
+
+int gpio_set_value(int num, int value)
+{
+ char path[64];
+ char buf[255];
+ int fd;
+ int ret;
+
+ sprintf(path, "/sys/class/gpio/gpio%d/value", num);
+ fd = open(path, O_WRONLY);
+ if (fd < 0) {
+ fprintf(stderr, "Failed to set value: %d for gpio: %d\n",
+ value, num);
+ return -1;
+ }
+ sprintf(buf, "%d", value);
+ ret = write(fd, buf, strlen(buf));
+ if (ret < 0) {
+ fprintf(stderr, "%s: Failed to write\n", __func__);
+ close(fd);
+ return -1;
+ }
+
+ close(fd);
+
+ return 0;
+}
+
+int gpio_get_value(int num, int *value)
+{
+ char path[64];
+ char buf[255];
+ int fd;
+ int ret;
+
+ sprintf(path, "/sys/class/gpio/gpio%d/value", num);
+ fd = open(path, O_RDONLY);
+ if (fd < 0) {
+ fprintf(stderr, "Failed to get value for gpio: %d\n", num);
+ fprintf(stderr, "%s: ERROR: %s\n", __func__, strerror(errno));
+ return -1;
+ }
+ ret = read(fd, buf, 255);
+ if (ret < 0) {
+ fprintf(stderr, "%s: Failed to read\n", __func__);
+ close(fd);
+ return -1;
+ }
+ *value = atoi(buf);
+ close(fd);
+
+ return 0;
+}
+
--- /dev/null
+/* gpioutils.h
+ *
+ * Copyright (c) 2017 Samsung Electronics, Inc.
+ *
+ * This program 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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.
+ */
+
+#ifndef __GPIOUTILS_H
+#define __GPIOUTILS_H
+
+
+int gpio_export(int num);
+int gpio_unexport(int num);
+int gpio_direction(int num, int dir);
+int gpio_set_value(int num, int value);
+int gpio_get_value(int num, int *value);
+
+#endif
--- /dev/null
+/* ldr_control.c
+ *
+ * Copyright (c) 2017 Samsung Electronics, Inc.
+ *
+ * This program 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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.
+ */
+
+#include <stdio.h>
+#include <errno.h>
+#include <pthread.h>
+#include <unistd.h>
+#include <string.h>
+#include "gpioutils.h"
+#include "ldr_control.h"
+
+#define LDR_DARK_THRESHOLD 2000
+
+volatile int terminate_ldr = 0;
+
+void *ldr_read_func(void *arg)
+{
+ int v = 0;
+
+ while (!terminate_ldr) {
+ ldr_read(&v);
+ if (v > LDR_DARK_THRESHOLD)
+ fprintf(stderr, "Too dark: %d\n",v);
+ sleep(1);
+ }
+ usleep(100 * 1000);
+
+ return NULL;
+}
+
+void ldr_init(void)
+{
+ int ret;
+
+ terminate_ldr = 0;
+
+ gpio_export(LDR_PIN);
+ ret = pthread_create(&ldr_tid, NULL, ldr_read_func, NULL);
+ if (ret < 0) {
+ fprintf(stderr, "%s: pthread_create error: %s\n",
+ __func__, (char *)strerror(errno));
+ }
+
+}
+
+void ldr_uninit(void)
+{
+ terminate_ldr = 1;
+ pthread_detach(ldr_tid);
+ gpio_unexport(LDR_PIN);
+}
+
+void ldr_read(int *s)
+{
+ int count = 0;
+ gpio_direction(LDR_PIN, 1);
+ gpio_set_value(LDR_PIN, 0);
+ usleep(100000);
+ gpio_direction(LDR_PIN, 0);
+ while (1) {
+ int v = 0;
+ gpio_get_value(LDR_PIN, &v);
+ if (v == 0)
+ count++;
+ else
+ break;
+ }
+ *s = count;
+}
--- /dev/null
+/* ldr_control.h
+ *
+ * Copyright (c) 2017 Samsung Electronics, Inc.
+ *
+ * This program 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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.
+ */
+
+#ifndef __LDR_CONTROL_H
+#define __LDR_CONTROL_H
+#include <pthread.h>
+
+pthread_t ldr_tid;
+
+#define LDR_PIN 4
+
+void ldr_init(void);
+void ldr_uninit(void);
+void ldr_read(int *v);
+
+
+#endif
--- /dev/null
+/* led_control.c
+ *
+ * Copyright (c) 2017 Samsung Electronics, Inc.
+ *
+ * This program 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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.
+ */
+
+#include <stdio.h>
+#include <errno.h>
+#include "gpioutils.h"
+#include "led_control.h"
+
+
+void led_init(void)
+{
+ gpio_export(LED_RED_PIN);
+ gpio_direction(LED_RED_PIN, 1);
+
+ gpio_export(LED_GREEN_PIN);
+ gpio_direction(LED_GREEN_PIN, 1);
+}
+
+void led_uninit(void)
+{
+ gpio_unexport(LED_RED_PIN);
+ gpio_unexport(LED_GREEN_PIN);
+}
+
+void led_write(int num, int value)
+{
+ gpio_set_value(num, value);
+}
+
--- /dev/null
+/* led_control.h
+ * Copyright (c) 2017 Samsung Electronics, Inc.
+ *
+ * This program 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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.
+ */
+
+#ifndef __LED_CONTROL_H
+#define __LED_CONTROL_H
+
+
+#define LED_RED_PIN 20
+#define LED_GREEN_PIN 21
+
+
+void led_init(void);
+void led_uninit(void);
+void led_write(int num, int value);
+
+
+#endif
--- /dev/null
+/* motor_control.c
+ *
+ * Copyright (c) 2017 Samsung Electronics, Inc.
+ *
+ * This program 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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.
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include "gpioutils.h"
+#include "motor_control.h"
+
+void motor_stop(void)
+{
+ gpio_set_value(MOTORA_1, 0);
+ gpio_set_value(MOTORA_2, 0);
+ gpio_set_value(MOTORB_1, 0);
+ gpio_set_value(MOTORB_2, 0);
+ printf("Motor Stopped....\n");
+}
+
+void send_to_motor(char c)
+{
+ switch (c) {
+ case 'F':
+ case 'f':
+ motor_stop();
+ gpio_set_value(MOTORA_1, 1);
+ gpio_set_value(MOTORA_2, 0);
+ gpio_set_value(MOTORB_1, 1);
+ gpio_set_value(MOTORB_2, 0);
+ printf("Moving Forward....\n");
+ break;
+
+ case 'B':
+ case 'b':
+ motor_stop();
+ gpio_set_value(MOTORA_1, 0);
+ gpio_set_value(MOTORA_2, 1);
+ gpio_set_value(MOTORB_1, 0);
+ gpio_set_value(MOTORB_2, 1);
+ printf("Moving Back....\n");
+ break;
+
+ case 'L':
+ case 'l':
+ motor_stop();
+ gpio_set_value(MOTORA_1, 0);
+ gpio_set_value(MOTORA_2, 0);
+ gpio_set_value(MOTORB_1, 1);
+ gpio_set_value(MOTORB_2, 0);
+ printf("Moving Left....\n");
+ //Delay for 200ms after left movement and then stop
+ usleep(200 * 1000);
+ motor_stop();
+ break;
+
+ case 'R':
+ case 'r':
+ motor_stop();
+ gpio_set_value(MOTORA_1, 1);
+ gpio_set_value(MOTORA_2, 0);
+ gpio_set_value(MOTORB_1, 0);
+ gpio_set_value(MOTORB_2, 0);
+ printf("Moving Right....\n");
+ //Delay for 200ms after right movement and then stop
+ usleep(200 * 1000);
+ motor_stop();
+ break;
+
+ case 'S':
+ case 's':
+ printf("Stopping....\n");
+ motor_stop();
+ break;
+ }
+}
+
+void motor_init()
+{
+ gpio_export(MOTORA_1);
+ gpio_direction(MOTORA_1, 1);
+
+ gpio_export(MOTORA_2);
+ gpio_direction(MOTORA_2, 1);
+
+ gpio_export(MOTORB_1);
+ gpio_direction(MOTORB_1, 1);
+
+ gpio_export(MOTORB_2);
+ gpio_direction(MOTORB_2, 1);
+
+ printf("motor init - done\n");
+}
+
+
+void motor_uninit()
+{
+ motor_stop();
+
+ gpio_unexport(MOTORA_1);
+
+ gpio_unexport(MOTORA_2);
+
+ gpio_unexport(MOTORB_1);
+
+ gpio_unexport(MOTORB_2);
+ printf("motor uninit - done\n");
+}
+
--- /dev/null
+/* motor_control.h
+ *
+ * Copyright (c) 2017 Samsung Electronics, Inc.
+ *
+ * This program 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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.
+ */
+
+#ifndef __MOTOR_CONTROL_H
+#define __MOTOR_CONTROL_H
+
+#define MOTORA_1 17
+#define MOTORA_2 18
+#define MOTORB_1 22
+#define MOTORB_2 23
+
+void motor_init(void);
+void motor_uninit(void);
+void motor_stop(void);
+void send_to_motor(char c);
+
+
+#endif
--- /dev/null
+/* proxi_sensor.c
+ *
+ * Copyright (c) 2017 Samsung Electronics, Inc.
+ *
+ * This program 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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.
+ */
+
+#include <stdio.h>
+#include <pthread.h>
+#include <errno.h>
+#include <unistd.h>
+#include <string.h>
+#include "gpioutils.h"
+#include "proxi_sensor.h"
+#include "motor_control.h"
+#include "led_control.h"
+
+
+volatile int terminate_proxi = 0;
+
+void *proxi_read_func(void *arg)
+{
+ int v = -1;
+ char val = 'b';
+
+ while (!terminate_proxi) {
+ proxi_read(&v);
+ if (v == 0) {
+ fprintf(stderr, "obstacle detected by robot: v: %d\n", v);
+ send_to_motor(val);
+ v = 1;
+ sleep(1);
+ }
+ usleep(100 * 1000);
+ }
+ return NULL;
+}
+
+
+void proxi_init()
+{
+ int ret;
+
+ gpio_export(PROXI_PORT);
+ gpio_direction(PROXI_PORT, 0);
+
+ terminate_proxi = 0;
+
+ ret = pthread_create(&proxi_tid, NULL, proxi_read_func, NULL);
+ if (ret < 0) {
+ fprintf(stderr, "%s: pthread_create error: %s\n",
+ __func__, (char *)strerror(errno));
+ }
+}
+
+void proxi_uninit()
+{
+ terminate_proxi = 1;
+ pthread_detach(proxi_tid);
+ gpio_unexport(PROXI_PORT);
+}
+
+void proxi_read(int *v)
+{
+ gpio_get_value(PROXI_PORT, v);
+}
+
--- /dev/null
+/* proxi_sensor.h
+ *
+ * Copyright (c) 2017 Samsung Electronics, Inc.
+ *
+ * This program 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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.
+ */
+
+#ifndef __PROXI_SENSOR_H
+#define __PROXI_SENSOR_H
+
+#include <pthread.h>
+
+
+#define PROXI_PORT 27
+
+pthread_t proxi_tid;
+
+void proxi_init(void);
+void proxi_uninit(void);
+void proxi_read(int *v);
+
+
+#endif
--- /dev/null
+/* switch_control.c
+ *
+ * Copyright (c) 2017 Samsung Electronics, Inc.
+ *
+ * This program 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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.
+ */
+
+#include <stdio.h>
+#include <errno.h>
+#include <unistd.h>
+#include <string.h>
+#include <pthread.h>
+#include <linux/reboot.h>
+#include <sys/reboot.h>
+#include "gpioutils.h"
+#include "switch_control.h"
+#include "motor_control.h"
+#include "led_control.h"
+#include "proxi_sensor.h"
+
+
+volatile int terminate_switch = 0;
+
+void *switch_read_func(void *arg)
+{
+ int v = 0;
+
+ while (!terminate_switch) {
+ switch_read(&v);
+ if (v == 1) {
+ fprintf(stderr,"Switch enabled, turning off robot\n");
+ sync();
+ led_uninit();
+ reboot(LINUX_REBOOT_CMD_POWER_OFF);
+ printf("after reboot\n");
+ }
+ sleep(1);
+ }
+
+ return NULL;
+}
+
+void switch_init(void)
+{
+ int ret;
+
+ terminate_switch = 0;
+
+ gpio_export(SWITCH_PIN);
+ gpio_direction(SWITCH_PIN, 0);
+ ret = pthread_create(&switch_tid, NULL, switch_read_func, NULL);
+ if (ret < 0) {
+ fprintf(stderr, "%s: pthread_create error: %s\n",
+ __func__, (char *)strerror(errno));
+ }
+
+}
+
+void switch_uninit(void)
+{
+ terminate_switch = 1;
+ pthread_detach(switch_tid);
+ gpio_unexport(SWITCH_PIN);
+}
+
+void switch_read(int *s)
+{
+ gpio_get_value(SWITCH_PIN, s);
+}
--- /dev/null
+/* switch_control.h
+ *
+ * Copyright (c) 2017 Samsung Electronics, Inc.
+ *
+ * This program 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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.
+ */
+
+#ifndef __SWITCH_CONTROL_H
+#define __SWITCH_CONTROL_H
+#include <pthread.h>
+
+pthread_t switch_tid;
+
+#define SWITCH_PIN 12
+
+
+void switch_init(void);
+void switch_uninit(void);
+void switch_read(int *s);
+
+
+#endif
+
--- /dev/null
+/* wifi-robot-server.c
+ *
+ * Copyright (c) 2017 Samsung Electronics, Inc.
+ *
+ * This program 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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.
+ */
+
+#include <stdio.h>
+#include <sys/socket.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <unistd.h>
+#include <netinet/in.h>
+#include "motor_control.h"
+#include "proxi_sensor.h"
+#include "led_control.h"
+#include "switch_control.h"
+#include "ldr_control.h"
+
+#define PORT 8080
+
+
+void wifi_disconnect(void)
+{
+ motor_uninit();
+ proxi_uninit();
+ //ldr_uninit();
+}
+
+
+void wifi_connect(void)
+{
+ motor_init();
+ proxi_init();
+ //ldr_init();
+}
+
+
+void wifi_init(int *server_fd)
+{
+ struct sockaddr_in address;
+ int opt = 1;
+ int bind_cb;
+ int listen_cb;
+
+ *server_fd = socket(AF_INET, SOCK_STREAM, 0);
+ if (*server_fd <= 0) {
+ fprintf(stderr, "%s: socket failed: %s\n",
+ __func__, strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+ if (setsockopt(*server_fd, SOL_SOCKET, SO_REUSEADDR | SO_REUSEPORT,
+ &opt, sizeof(opt))) {
+ fprintf(stderr, "%s: setsockopt failed: %s\n",
+ __func__, strerror(errno));
+ close(*server_fd);
+ exit(EXIT_FAILURE);
+ }
+ address.sin_family = AF_INET;
+ address.sin_addr.s_addr = INADDR_ANY;
+ address.sin_port = htons(PORT);
+
+ bind_cb = bind(*server_fd, (struct sockaddr *)&address, sizeof(address));
+ if (bind_cb < 0) {
+ fprintf(stderr, "%s: bind failed: %s\n",
+ __func__, strerror(errno));
+ close(*server_fd);
+ exit(EXIT_FAILURE);
+ }
+ listen_cb = listen(*server_fd, 1);
+ if (listen_cb < 0) {
+ fprintf(stderr, "%s: listen failed: %s\n",
+ __func__, strerror(errno));
+ close(*server_fd);
+ exit(EXIT_FAILURE);
+ }
+}
+
+void wifi_uninit(int server_fd)
+{
+ if (server_fd)
+ close(server_fd);
+}
+
+int main(int argc, char const *argv[])
+{
+ int sockfd;
+ char data[255];
+ int ret = -1;
+ int isconnected = 0;
+
+ wifi_init(&sockfd);
+ if (sockfd < 0) {
+ fprintf(stderr,"wifi_init failed\n");
+ exit(EXIT_FAILURE);
+ }
+
+ led_init();
+ switch_init();
+ //ldr_init();
+
+ /* Turn on RED LED */
+ led_write(LED_RED_PIN, 1);
+ led_write(LED_GREEN_PIN, 0);
+
+ while (1) {
+ char val;
+ int newsockfd;
+ int addrlen = 0;
+ struct sockaddr_in address;
+
+ if (isconnected == 0) {
+ newsockfd = accept(sockfd, (struct sockaddr *)&address, (socklen_t *)&addrlen);
+ if (newsockfd < 0) {
+ fprintf(stderr, "Error: accept failed : %s\n",
+ strerror(errno));
+ continue;
+ }
+ }
+ ret = read(newsockfd, &data, 255);
+ if (ret < 0) {
+ fprintf(stderr, "ERROR: %s: read failed\n", __func__);
+ continue;
+ }
+ val = data[0];
+ printf("Got: %c\n",val);
+ if ((val == 'c' || val == 'C') && isconnected == 0) {
+ printf("Robot connected....\n");
+ wifi_connect();
+ isconnected = 1;
+ /* Turn on GREEN LED */
+ led_write(LED_RED_PIN, 0);
+ led_write(LED_GREEN_PIN, 1);
+ } else if ((val == 'd' || val == 'D') && isconnected == 1) {
+ printf("Robot disconnected....\n");
+ wifi_disconnect();
+ isconnected = 0;
+ /* Turn on RED LED */
+ led_write(LED_RED_PIN, 1);
+ led_write(LED_GREEN_PIN, 0);
+ } else {
+ if (isconnected == 1 && val != 'd' && val != 'c') {
+ printf("Command send to motor : %c\n", val);
+ send_to_motor(val);
+ }
+ }
+ }
+ led_uninit();
+ switch_uninit();
+ wifi_uninit(sockfd);
+
+ return 0;
+}
--- /dev/null
+<manifest>
+ <request>
+ <domain name="_"/>
+ </request>
+</manifest>
--- /dev/null
+[Unit]
+Description=Wifi Server daemon for remote control devices
+After=default.target
+
+[Service]
+Type=simple
+ExecStart=/usr/bin/wifi-robot-server
+Restart=always
+RestartSec=0
+RemainAfterExit=yes
+
+[Install]
+WantedBy=multi-user.target