ROVER - RoverUtils API added
Signed-off-by: Mustafa Ozcelikors <mozcelikors@gmail.com>
diff --git a/rover/include/roverapi/rover_utils.hpp b/rover/include/roverapi/rover_utils.hpp
new file mode 100644
index 0000000..26c261f
--- /dev/null
+++ b/rover/include/roverapi/rover_utils.hpp
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2017 FH Dortmund and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Description:
+ * Rover Utils API - Interfaces for Rover utilities application development - Header file
+ *
+ * Usage Note:
+ * read_core_usage.py must be installed to /opt/rover-app/scripts/read_core_usage.py
+ *
+ * Contributors:
+ * M.Ozcelikors <mozcelikors@gmail.com>, created API 17.11.2017
+ *
+ */
+
+#ifndef API_ROVER_UTILS_HPP_
+#define API_ROVER_UTILS_HPP_
+
+#include <stdint.h>
+#include <stdio.h>
+#include <unistd.h>
+
+namespace rover
+{
+ /**
+ * @brief RoverUtils contains member functions to retrieve connectivity status and core utilization of the rover. This class wraps status_library lib, developed for the rover-app.
+ */
+ class RoverUtils
+ {
+ public:
+ /**
+ * @brief Returns a float array that contains core utilization of each core in rover's Raspberry Pi. Uses an external script called read_core_usage.py which must be installed within rover-app.
+ * @return core_util (float) is an array that contains core usage of each core in rover's Raspberry Pi.
+ */
+ float * getCoreUtilization (void);
+
+ /**
+ * @brief Returns whether the wlan0 interface is on (1) or off (0).
+ * @return status wlan0 interface status : on (1) or off (0)
+ */
+ int getWlanStatus (void);
+
+ /**
+ * @brief Returns whether the eth0 interface is on (1) or off (0).
+ * @return status eth0 interface status : on (1) or off (0)
+ */
+ int getEthernetStatus (void);
+
+ /**
+ * @brief Returns whether the internet is on (1) or off (0).
+ * @return status internet status : on (1) or off (0)
+ */
+ int getInternetStatus (void);
+
+ /**
+ * @brief Returns whether the bluetooth is on (1) or off (0).
+ * @return status bluetooth status : on (1) or off (0)
+ */
+ int getBluetoothStatus (void);
+
+ /**
+ * @brief Returns whether the remote Eclipse Hono instance is on (1) or off (0).
+ * @return status remote Eclipse Hono instance status : on (1) or off (0)
+ */
+ int getHonoCloudStatus (char * host_name, int port, char * tenant_name, char * device_id, char * user, char * password);
+ };
+}
+
+
+#endif /* API_ROVER_UTILS_HPP_ */
diff --git a/rover/src/roverapi/rover_utils.cpp b/rover/src/roverapi/rover_utils.cpp
new file mode 100644
index 0000000..0907098
--- /dev/null
+++ b/rover/src/roverapi/rover_utils.cpp
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2017 FH Dortmund and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Description:
+ * Rover Utils API - Interfaces for Rover utilities application development
+ *
+ * Contributors:
+ * M.Ozcelikors <mozcelikors@gmail.com>, created API 17.11.2017
+ *
+ */
+
+#include <roverapi/rover_utils.hpp>
+
+#include <libraries/status_library/status_library.h>
+
+float * rover::RoverUtils::getCoreUtilization (void)
+{
+ FILE *fp;
+ char buffer[128];
+ float util[5];
+ size_t bytes_read;
+
+ /* Execute the command */
+ fp = popen("python /opt/rover-app/scripts/read_core_usage.py ","r");
+
+ /* Read to buffer */
+ bytes_read = fread(buffer, 1, sizeof(buffer), fp);
+
+ if (bytes_read == 0 || bytes_read == sizeof(buffer))
+ perror("Can't read from /opt/rover-app/scripts/read_core_usage.py");
+
+ buffer[bytes_read] = '\0';
+
+ //printf("buf:%s\n",buffer);
+
+ /* Parse */
+ sscanf(buffer,"[%f, %f, %f, %f]",&util[0], &util[1], &util[2], &util[3]);
+
+ /* Return */
+ return util;
+}
+
+int rover::RoverUtils::getWlanStatus (void)
+{
+ return retrieveWLANStatus ();
+}
+
+int rover::RoverUtils::getEthernetStatus (void)
+{
+ return retrieveETHStatus ();
+}
+
+int rover::RoverUtils::getInternetStatus (void)
+{
+ return retrieveINTERNETStatus ();
+}
+
+int rover::RoverUtils::getBluetoothStatus (void)
+{
+ return retrieveBLUETOOTHStatus ();
+}
+
+int rover::RoverUtils::getHonoCloudStatus (char * host_name, int port, char * tenant_name, char * device_id, char * user, char * password)
+{
+ return retrieveHONOStatus (host_name, port, tenant_name, device_id, user, password);
+}