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.
22 struct __message_type_s {
23 unsigned long long int seq_num;
27 unsigned long long int time; /* to be used to order messages */
30 static unsigned long long int sequence_number = 0;
32 static unsigned long long int __message_get_monotonic_time(void)
34 unsigned long long int c_time = 0;
38 ret = clock_gettime(CLOCK_MONOTONIC, &ts);
40 _E("failed to get monotonic time");
42 c_time = (((unsigned long long int)ts.tv_sec) * 1000000)
43 + (ts.tv_nsec / 1000);
48 int message_new(message_cmd_e cmd, int servo, int speed, message_s *new_msg)
50 retv_if(!new_msg, -1);
52 new_msg->seq_num = sequence_number++;
54 new_msg->servo = servo;
55 new_msg->speed = speed;
56 new_msg->time = __message_get_monotonic_time();
58 if (new_msg->seq_num >= ULLONG_MAX) {
59 /* maybe never reach here */
60 _W("seq number reachs max value, reset it to 0");
67 void message_reset_seq_num(void)
74 int message_get_seq_num(message_s *msg, unsigned long long int *seq_num)
78 *seq_num = msg->seq_num;
83 int message_get_cmd(message_s *msg, message_cmd_e *cmd)
92 int message_get_speed_value(message_s *msg, int *speed)
101 int message_get_servo_value(message_s *msg, int *servo)