ping.c
Go to the documentation of this file.
1 // Copyright (c) 2020 The YP-Spur Authors, except where otherwise indicated.
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to
5 // deal in the Software without restriction, including without limitation the
6 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7 // sell copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 // SOFTWARE.
20 
21 #include <param.h>
22 #include <utility.h>
23 #include <odometry.h>
24 #include <shvel-param.h>
25 #include <yprintf.h>
26 
27 int ping()
28 {
29  const int data = 0x123456;
30  yprintf(OUTPUT_LV_INFO, "Ping request: 0x%08x\n", data);
31 
33  int i;
34  for (i = 0; i < YP_PARAM_MAX_MOTOR_NUM + 1; i++)
35  odom->ping_response[i] = 0;
36 
37  const char target = MOTOR_ID_BROADCAST;
38  parameter_set(PARAM_servo, target, 0);
39  parameter_set(PARAM_ping, target, data);
41 
42  int ret = 1;
43  for (i = 0; i < YP_PARAM_MAX_MOTOR_NUM; i++)
44  {
45  if (odom->ping_response[i] == data)
46  {
47  ret = 0;
48  yprintf(OUTPUT_LV_INFO, "Ping response from ID: %d\n", i);
49  }
50  }
51  if (odom->ping_response[i] == data)
52  {
53  ret = 0;
54  yprintf(OUTPUT_LV_INFO, "Ping response from device without ID\n");
55  }
56  if (ret)
57  {
58  yprintf(OUTPUT_LV_ERROR, "No ping response!\n");
59  }
60 
61  return 1;
62 }
#define MOTOR_ID_BROADCAST
Definition: shvel-param.h:128
int odometry_receive_loop(void)
Definition: odometry.c:649
int parameter_set(char param, char id, long long int value64)
Definition: param.c:384
int ping_response[YP_PARAM_MAX_MOTOR_NUM+1]
Definition: odometry.h:46
#define YP_PARAM_MAX_MOTOR_NUM
Definition: ypparam.h:456
void yprintf(ParamOutputLv level, const char *format,...)
Definition: yprintf.c:32
int ping()
Definition: ping.c:27
OdometryPtr get_odometry_ptr()
Definition: odometry.c:361


yp-spur
Author(s):
autogenerated on Fri May 7 2021 02:12:17