2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
4 * Licensed under the Flora License, Version 1.1 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
25 static unsigned long long int sequence_number = 0;
26 static GQueue inqueue = G_QUEUE_INIT;
27 static GQueue outqueue = G_QUEUE_INIT;
29 static unsigned long long int __message_get_monotonic_time(void)
31 unsigned long long int c_time = 0;
35 ret = clock_gettime(CLOCK_MONOTONIC, &ts);
37 _E("failed to get monotonic time");
39 c_time = (((unsigned long long int)ts.tv_sec) * 1000000)
40 + (ts.tv_nsec / 1000);
45 int message_new(message_cmd_e cmd, int servo, int speed, message_s *new_msg)
47 retv_if(!new_msg, -1);
49 new_msg->seq_num = sequence_number++;
51 new_msg->servo = servo;
52 new_msg->speed = speed;
53 new_msg->time = __message_get_monotonic_time();
55 if (new_msg->seq_num >= ULLONG_MAX) {
56 /* maybe never reach here */
57 _W("seq number reachs max value, reset it to 0");
64 void message_reset_seq_num(void)
71 int message_get_seq_num(message_s *msg, unsigned long long int *seq_num)
75 *seq_num = msg->seq_num;
80 int message_get_cmd(message_s *msg, message_cmd_e *cmd)
89 int message_get_speed_value(message_s *msg, int *speed)
98 int message_get_servo_value(message_s *msg, int *servo)