Hi Vincent,
On 05/16/2017 03:38 AM, Vincent Cesson wrote:
Use Gemalto commands ^SCTM and ^SBV to monitor temperature and voltage.
Use a single method GetStatistics to read and return both values.
---
plugins/gemalto.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 93 insertions(+), 1 deletion(-)
diff --git a/plugins/gemalto.c b/plugins/gemalto.c
index 3798e09..9f67f17 100644
--- a/plugins/gemalto.c
+++ b/plugins/gemalto.c
@@ -53,6 +53,8 @@
#define HARDWARE_MONITOR_INTERFACE OFONO_SERVICE ".cinterion.HardwareMonitor"
static const char *none_prefix[] = { NULL };
+static const char *sctm_prefix[] = { "^SCTM:", NULL };
+static const char *sbv_prefix[] = { "^SBV:", NULL };
struct gemalto_hardware_monitor {
DBusMessage *msg;
@@ -155,13 +157,103 @@ static void cfun_enable(gboolean ok, GAtResult *result,
gpointer user_data)
NULL);
}
+static void gemalto_sctm_cb(gboolean ok, GAtResult *result, gpointer user_data)
+{
+ DBusConnection *conn = ofono_dbus_get_connection();
+ struct gemalto_data *data = user_data;
+ GAtResultIter iter;
+ DBusMessageIter dbus_iter;
+ DBusMessageIter dbus_dict;
+
+ if (!ok)
+ goto error;
+
+ g_at_result_iter_init(&iter, result);
+
+ if (!g_at_result_iter_next(&iter, "^SCTM:"))
+ goto error;
+
+ if (!g_at_result_iter_skip_next(&iter))
+ goto error;
+
+ if (!g_at_result_iter_skip_next(&iter))
+ goto error;
+
+ if (!g_at_result_iter_next_number(&iter, &(data->hm->temperature)))
'()' are not needed around data->hm->temperature
+ goto error;
+
+ dbus_message_iter_init_append(data->hm->msg, &dbus_iter);
+
+ dbus_message_iter_open_container(&dbus_iter, DBUS_TYPE_ARRAY,
+ OFONO_PROPERTIES_ARRAY_SIGNATURE,
+ &dbus_dict);
+
+ ofono_dbus_dict_append(&dbus_dict, "Temperature",
+ DBUS_TYPE_INT32, &data->hm->temperature);
+
+ ofono_dbus_dict_append(&dbus_dict, "Voltage",
+ DBUS_TYPE_UINT32, &data->hm->voltage);
+
+ dbus_message_iter_close_container(&dbus_iter, &dbus_dict);
+
+ g_dbus_send_message(conn, data->hm->msg);
+
+ data->hm->msg = NULL;
or use __ofono_dbus_pending_reply to save a few steps.
+
+ return;
+
+error:
+ g_dbus_send_error(conn, data->hm->msg, DBUS_ERROR_FAILED,
+ "Unable to read temperature");
+}
+
+static void gemalto_sbv_cb(gboolean ok, GAtResult *result, gpointer user_data)
+{
+ DBusConnection *conn = ofono_dbus_get_connection();
+ struct gemalto_data *data = user_data;
+ GAtResultIter iter;
+
+ if (!ok)
+ goto error;
+
+ g_at_result_iter_init(&iter, result);
+
+ if (!g_at_result_iter_next(&iter, "^SBV:"))
+ goto error;
+
+ if (!g_at_result_iter_next_number(&iter, &(data->hm->voltage)))
'()' around data->hm->voltage are not needed
+ goto error;
+
+ if (!g_at_chat_send(data->app, "AT^SCTM?", sctm_prefix, gemalto_sctm_cb,
+ data, NULL))
+ g_dbus_send_error(conn, data->hm->msg, DBUS_ERROR_FAILED,
+ "Unable to read temperature");
+
+ return;
+
I'm not sure distinguishing between voltage and temperature errors is
useful. So why why not:
if (g_at_chat_send(...) > 0)
return;
+error:
+ g_dbus_send_error(conn, data->hm->msg, DBUS_ERROR_FAILED,
+ "Unable to read voltage");
and change this to a generic failed message. You can use
__ofono_dbus_pending_reply. This will have the benefit of setting
hm->msg to NULL so that subsequent GetStatistics calls don't return 'busy'.
+}
+
static DBusMessage *hardware_monitor_get_statistics(DBusConnection *conn,
DBusMessage *msg,
void *user_data)
{
+ struct gemalto_data *data = user_data;
+
DBG("");
- return __ofono_error_not_implemented(msg);
+ if (data->hm->msg != NULL)
+ return __ofono_error_busy(msg);
+
+ if (!g_at_chat_send(data->app, "AT^SBV", sbv_prefix, gemalto_sbv_cb,
+ data, NULL))
+ return __ofono_error_failed(msg);
+
+ data->hm->msg = dbus_message_new_method_return(msg);
+
+ return NULL;
}
static const GDBusMethodTable hardware_monitor_methods[] = {
Regards,
-Denis
_______________________________________________
ofono mailing list
[email protected]
https://lists.ofono.org/mailman/listinfo/ofono