4 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
23 #include <sensor_internal.h>
28 #define SHUB_INST_LIB_ADD ((char)-79)
29 #define SHUB_INST_LIB_REMOVE ((char)-78)
30 #define SHUB_LOOP_BACK_LIB 12
31 #define DEFAULT_COMMAND_SIZE 3
32 #define MAX_COMMAND_SIZE 82
33 #define MAX_DATA_SIZE 84 /* -79, 12, 4byte Delaytime + 78 bytes data */
35 static void int_to_bytes(int32_t value, int length, char cmd[])
37 /* Convert to Big-endian */
38 for (int i = length - 1; i >= 0; i--) {
39 cmd[i] = (value & 0xff);
44 bool loopback_manager::run(int argc, char *argv[])
46 if (argc < DEFAULT_COMMAND_SIZE || argc > MAX_COMMAND_SIZE) {
51 if (!strcmp(argv[2], "start")) {
54 sensor = sensord_get_sensor(CONTEXT_SENSOR);
55 handle = sensord_connect(sensor);
58 * sensorhub (bytes) command [0~1] delaytime [2~5] data[6~83]
59 * shell (argv) command [0~2] delaytime [3] data[4~81]
61 char test_data[MAX_DATA_SIZE] = {SHUB_INST_LIB_ADD, SHUB_LOOP_BACK_LIB, };
62 int_to_bytes(atoi(argv[3]), sizeof(int), &(test_data[2]));
64 for (int i = 4; i < argc; i++)
65 test_data[i+2] = atoi(argv[i]);
67 sensord_set_attribute_str(handle, 0, test_data, sizeof(test_data));
68 sensord_disconnect(handle);
72 if (!strcmp(argv[2], "stop")) {
75 sensor = sensord_get_sensor(CONTEXT_SENSOR);
76 handle = sensord_connect(sensor);
78 char test_data[4] = {SHUB_INST_LIB_REMOVE, SHUB_LOOP_BACK_LIB, };
80 sensord_set_attribute_str(handle, 0, test_data, sizeof(test_data));
81 sensord_disconnect(handle);
90 void loopback_manager::usage(void)
92 _N("usage: sensorctl loopback [start/stop] [14byte sensor char data]\n");
93 _N("ex: sensorctl loopback start 15000 1 1 19 1 (after 15000ms, wrist up event)\n");
94 _N("ex: sensorctl loopback stop\n");
95 _N(" * if not enought 14byte, remain bytes are filled with 0\n");