diff src/cs/services/vibr/vibr_api.c @ 294:e17bdedfbf2b

VIBR SWE initial implementation
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 27 Mar 2022 08:46:10 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/cs/services/vibr/vibr_api.c	Sun Mar 27 08:46:10 2022 +0000
@@ -0,0 +1,64 @@
+/*
+ * The implementation of our external API functions lives here.
+ */
+
+#include "vibr/vibr_api.h"
+#include "vibr/vibr_env.h"
+#include "vibr/vibr_messages_i.h"
+#include "rv/rv_general.h"
+#include "rvf/rvf_api.h"
+#include "rvm/rvm_use_id_list.h"
+
+T_RV_RET vibr_pulse_train_start(UINT8 num_pulses, UINT8 vibr_level)
+{
+	struct vibr_start_msg *msg;
+
+	if (!vibr_env)
+		return RV_NOT_READY;
+	if (rvf_get_buf(vibr_env->prim_id, sizeof(struct vibr_start_msg),
+			(T_RVF_BUFFER **)&msg) == RVF_RED) {
+		rvf_send_trace(
+			"rvf_get_buf() failed in vibr_pulse_train_start()", 48,
+			NULL_PARAM, RV_TRACE_LEVEL_ERROR, VIBR_USE_ID);
+		return RV_MEMORY_ERR;
+	}
+	msg->hdr.msg_id        = VIBR_START_REQ;
+	msg->hdr.src_addr_id   = vibr_env->addr_id;
+	msg->hdr.dest_addr_id  = vibr_env->addr_id;
+	msg->hdr.callback_func = NULL;
+	msg->num_pulses = num_pulses;
+	msg->vibr_level = vibr_level;
+	if (rvf_send_msg(vibr_env->addr_id, msg) != RV_OK) {
+		rvf_send_trace("vibr_pulse_train_start(): Send failed!", 38,
+				NULL_PARAM, RV_TRACE_LEVEL_ERROR, VIBR_USE_ID);
+		rvf_free_buf(msg);
+		return RV_INTERNAL_ERR;
+	}
+	return RV_OK;
+}
+
+T_RV_RET vibr_pulse_train_stop(void)
+{
+	struct vibr_stop_msg *msg;
+
+	if (!vibr_env)
+		return RV_NOT_READY;
+	if (rvf_get_buf(vibr_env->prim_id, sizeof(struct vibr_stop_msg),
+			(T_RVF_BUFFER **)&msg) == RVF_RED) {
+		rvf_send_trace(
+			"rvf_get_buf() failed in vibr_pulse_train_stop()", 47,
+			NULL_PARAM, RV_TRACE_LEVEL_ERROR, VIBR_USE_ID);
+		return RV_MEMORY_ERR;
+	}
+	msg->hdr.msg_id        = VIBR_STOP_REQ;
+	msg->hdr.src_addr_id   = vibr_env->addr_id;
+	msg->hdr.dest_addr_id  = vibr_env->addr_id;
+	msg->hdr.callback_func = NULL;
+	if (rvf_send_msg(vibr_env->addr_id, msg) != RV_OK) {
+		rvf_send_trace("vibr_pulse_train_stop(): Send failed!", 37,
+				NULL_PARAM, RV_TRACE_LEVEL_ERROR, VIBR_USE_ID);
+		rvf_free_buf(msg);
+		return RV_INTERNAL_ERR;
+	}
+	return RV_OK;
+}