ruuvi.drivers.c  ${PROJECT_VERSION}
Drivers for external sensors and peripherals on embedded systems.
ruuvi_interface_communication_radio_test.c
Go to the documentation of this file.
2 #if RUUVI_RUN_TESTS
3 #include "ruuvi_driver_error.h"
4 #include "ruuvi_driver_test.h"
9 #include <stdbool.h>
10 #include <string.h>
11 #include <stdio.h>
12 
26 static bool ri_radio_init_test (const rd_test_print_fp printfp)
27 {
28  rd_status_t err_code = RD_SUCCESS;
29  bool status = false;
30  ri_radio_modulation_t modulation = 0;
31  printfp ("\"init\":");
32  err_code |= ri_radio_init (RI_RADIO_BLE_1MBPS);
33 
34  if (RD_SUCCESS != err_code)
35  {
36  status = true;
37  }
38  else
39  {
40  err_code |= ri_radio_init (RI_RADIO_BLE_1MBPS);
41 
42  if (RD_ERROR_INVALID_STATE != err_code)
43  {
44  status = true;
45  }
46  else
47  {
48  err_code = ri_radio_uninit();
49  err_code |= ri_radio_init (RI_RADIO_BLE_1MBPS);
50  err_code |= ri_radio_get_modulation (&modulation);
51 
52  if ( (RD_SUCCESS != err_code)
53  || !ri_radio_is_init()
54  || RI_RADIO_BLE_1MBPS != modulation)
55  {
56  status = true;
57  }
58  }
59  }
60 
61  if (status)
62  {
63  printfp ("\"fail\",\r\n");
64  }
65  else
66  {
67  printfp ("\"pass\",\r\n");
68  }
69 
70  (void) ri_radio_uninit();
71  return status;
72 }
73 
84 static bool ri_radio_address_test (const rd_test_print_fp printfp)
85 {
86  rd_status_t err_code = RD_SUCCESS;
87  bool status = false;
88  const uint64_t addr_set = 0xCFEDAABBCCDDU;
89  uint64_t addr_old = 0;
90  uint64_t addr_new = 0;
91  printfp ("\"address_set_get\":");
92  err_code |= ri_radio_init (RI_RADIO_BLE_1MBPS);
93 
94  if (RD_SUCCESS != err_code)
95  {
96  status = true;
97  }
98  else
99  {
100  err_code |= ri_radio_address_get (&addr_old);
101  err_code |= ri_radio_address_set (addr_set);
102  err_code |= ri_radio_address_get (&addr_new);
103 
104  if ( (RD_SUCCESS != err_code)
105  || (addr_set != addr_new)
106  || (addr_old == addr_new))
107  {
108  status = true;
109  }
110  }
111 
112  if (status)
113  {
114  printfp ("\"fail\"\r\n");
115  }
116  else
117  {
118  printfp ("\"pass\"\r\n");
119  }
120 
121  (void) ri_radio_uninit();
122  return status;
123 }
124 
125 void print_modulation (const rd_test_print_fp printfp,
126  const ri_radio_modulation_t modulation)
127 {
128  switch (modulation)
129  {
131  printfp ("coded");
132  break;
133 
134  case RI_RADIO_BLE_1MBPS:
135  printfp ("1_mbit");
136  break;
137 
138  case RI_RADIO_BLE_2MBPS:
139  printfp ("2_mbit");
140  break;
141 
142  default:
143  printfp ("error");
144  break;
145  }
146 }
147 
148 
149 
151 {
152  bool status = false;
153  printfp ("\"radio\":{\r\n");
154  status |= ri_radio_init_test (printfp);
155  status |= ri_radio_address_test (printfp);
156  printfp ("},\r\n");
157  return status;
158 }
159 
160 /* @} */
161 #endif
uint32_t rd_status_t
bitfield for representing errors
#define RD_SUCCESS
Internal Error.
#define RD_ERROR_INVALID_STATE
Invalid state, operation disallowed in this state.
void print_modulation(const rd_test_print_fp printfp, const ri_radio_modulation_t modulation)
Print used modulation to printfp.
rd_status_t ri_radio_get_modulation(ri_radio_modulation_t *const p_modulation)
Get the modulation used by application.
bool ri_communication_radio_run_integration_test(const rd_test_print_fp printfp)
bool ri_radio_is_init()
Check if radio is initialized.
rd_status_t ri_radio_init(const ri_radio_modulation_t modulation)
Enable radio stack for an user. This function also starts radio activity callbacks internally.
rd_status_t ri_radio_uninit()
Release radio stack.
rd_status_t ri_radio_address_get(uint64_t *const address)
ri_radio_modulation_t
type of radio modulation to be used.
rd_status_t ri_radio_address_set(uint64_t const address)
@ RI_RADIO_BLE_1MBPS
"Normal" BLE 4 modulation
@ RI_RADIO_BLE_2MBPS
"Fast BLE". Advertising uses 1MBPS primary advertisement followed by 2 MBit/s extended advertisement.
@ RI_RADIO_BLE_125KBPS
Also known as BLE Long Range S=8.
void(* rd_test_print_fp)(const char *const msg)
function pointer to print test information
Header to enable and disable module compilation.
Ruuvi error codes and error check function.
Functions for testing drivers.