30 #define GATT_TX_TEST_TIMEOUT_MS (10000U)
34 static volatile bool m_has_connected;
35 static volatile bool m_has_disconnected;
36 static volatile bool m_has_sent;
37 static volatile bool m_has_received;
41 void * p_data,
size_t data_len)
47 m_has_connected =
true;
51 m_has_disconnected =
true;
59 m_has_received =
true;
61 m_channel.
read (&rx_data);
80 static bool ri_gatt_init_null_test (
void)
88 static bool ri_gatt_init_twice_test (
void)
96 static bool ri_gatt_init_norad_test (
void)
108 printfp (
"\"init\":");
109 status |= ri_gatt_init_norad_test();
121 status |= ri_gatt_init_null_test();
122 status |= ri_gatt_init_twice_test();
131 printfp (
"\"fail\",\r\n");
135 printfp (
"\"pass\",\r\n");
147 static bool tx_slow_test (
void)
150 const char test_data[] =
"Test slow tx: ";
152 uint16_t msg_index = 0U;
154 for (uint8_t ii = 0U; ii < 10U; ii++)
160 err_code |= m_channel.
send (&msg);
168 static float tx_throughput_test (
void)
171 const char test_data[] =
"msg: ";
186 err_code |= m_channel.
send (&msg);
199 test_end - test_start)) / 1000.0F);
206 m_has_connected =
false;
207 uint64_t start_time = 0;
208 bool timeout =
false;
210 float throughput = 0;
211 char throughput_string[100];
226 const char test_data[] =
"Lorem Ipsum";
231 err_code |= m_adv.
send (&msg);
235 m_channel.
on_evt = ble_isr;
238 while (! (m_has_connected))
240 if ( (start_time + GATT_TX_TEST_TIMEOUT_MS) <
ri_rtc_millis())
247 if (
false == timeout)
249 status |= tx_slow_test ();
250 throughput = tx_throughput_test();
265 printfp (
"\"timeout\",\r\n");
271 printfp (
"\"fail\",\r\n");
275 printfp (
"\"pass\",\r\n");
279 snprintf (throughput_string,
sizeof (throughput_string),
280 "\"throughput\":\"%.3f bps\"\r\n",
282 printfp (throughput_string);
299 printfp (
"\"ble_gatt_");
301 printfp (
"\":{\r\n");
302 status |= ri_gatt_init_test (printfp, modulation);
303 status |= ri_gatt_tx_test (printfp, modulation);
#define TEST_GATT_PACKET_NUM
Number of packets to send in throughput test.
bool ri_communication_ble_gatt_run_integration_test(const rd_test_print_fp printfp, const ri_radio_modulation_t modulation)
#define TEST_GATT_PACKET_LEN
Bytes of GATT test packet.
#define RD_ERROR_NULL
Null Pointer.
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.
rd_status_t ri_flash_uninit(void)
Unintialize flash. After uninitialization only initialization can be used.
rd_status_t ri_flash_init(void)
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_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.
ri_radio_modulation_t
type of radio modulation to be used.
void(* rd_test_print_fp)(const char *const msg)
function pointer to print test information
rd_status_t ri_timer_uninit(void)
rd_status_t ri_timer_init(void)
Header to enable and disable module compilation.
Ruuvi error codes and error check function.
Functions for testing drivers.
#define RI_COMM_MESSAGE_MAX_LENGTH
The maximum length for the application message for sending over BLE, which depends on whether extende...
ri_comm_evt_t
Communication event type.
@ RI_COMM_CONNECTED
Connection established, OK to send, may receive data.
@ RI_COMM_RECEIVED
New data received, available to read with read function.
@ RI_COMM_SENT
One queued message was sent with all repetitions.
@ RI_COMM_DISCONNECTED
Connection lost, cannot send, may not receive data.
@ CONNECTABLE_SCANNABLE
Connectable, scannable.
rd_status_t ri_adv_init(ri_comm_channel_t *const channel)
Initialize Advertising module and scanning module.
rd_status_t ri_adv_scan_response_setup(const char *const name, const bool advertise_nus)
Configure advertising data with a scan response.
rd_status_t ri_adv_uninit(ri_comm_channel_t *const channel)
rd_status_t ri_adv_type_set(ri_adv_type_t type)
Configure the type of advertisement.
rd_status_t ri_adv_tx_interval_set(const uint32_t ms)
rd_status_t ri_gatt_init(void)
Initializes GATT stack. Uses default values from sdk_config.h, these can be overridden in nrf5_sdk15_...
rd_status_t ri_gatt_nus_uninit(ri_comm_channel_t *const _channel)
Uninitialize Nordic UART Service as a communication channel.
rd_status_t ri_gatt_uninit(void)
Uninitializes GATT stack.
rd_status_t ri_gatt_nus_init(ri_comm_channel_t *const channel)
Initialize Nordic UART Service as a communication channel. ri_communication_radio_init(RI_COMMUNICATI...
Interface functions to persistent flash storage.
rd_status_t ri_rtc_init(void)
Initializes RTC at 0 ms.
rd_status_t ri_rtc_uninit(void)
Stop RTC if applicable.
uint64_t ri_rtc_millis(void)
Get milliseconds since init.
Interface functions to timer.
rd_status_t ri_yield(void)
Function which will release execution.
rd_status_t ri_delay_ms(uint32_t time)
Delay a given number of milliseconds.
rd_status_t ri_yield_low_power_enable(const bool enable)
Initializes yielding functions.
control API for communication via outside world
ri_comm_evt_handler_fp_t on_evt
Callback to application-level event handler, must be set in application.
ri_comm_xfer_fp_t send
Asynchronous send function.
ri_comm_xfer_fp_t read
Asynchronous read function.
Application message structure used for communication.
uint8_t data[RI_COMM_MESSAGE_MAX_LENGTH]
Data payload.
uint8_t repeat_count
Number of times to repeat the message,.
uint8_t data_length
Length of data.