44 *
55 * @file chirp_connect.h
66 *
7+ * @brief Chirp C SDK implementation header.
8+ *
79 * All contents are strictly proprietary, and not for copying, resale,
810 * or use outside of the agreed license.
911 *
10- * Copyright © 2011-2018 , Asio Ltd.
12+ * Copyright © 2011-2019 , Asio Ltd.
1113 * All rights reserved.
1214 *
1315 *----------------------------------------------------------------------------*/
1416
15- #ifndef __CHIRP_CONNECT_H__
16- #define __CHIRP_CONNECT_H__
17-
18- #ifdef __cplusplus
19- extern "C" {
20- #endif
17+ #ifndef CHIRP_CONNECT_H
18+ #define CHIRP_CONNECT_H
2119
2220#include <stdbool.h>
2321#include <stdint.h>
24- #include <time.h>
22+
23+ /**
24+ * Mark the function as public. Any attempt to call a function without this
25+ * marker will fail.
26+ */
27+ #if defined(__WIN32 ) || defined(_WIN32 ) || defined(WIN32 )
28+ #define PUBLIC_SYM __declspec(dllexport)
29+ #else
30+ #define PUBLIC_SYM __attribute__ ((visibility ("default")))
31+ #endif
2532
2633#include "chirp_connect_callbacks.h"
27- #include "chirp_sdk_defines.h"
2834#include "chirp_connect_errors.h"
2935#include "chirp_connect_states.h"
36+ #include "chirp_connect_version.h"
37+
38+ #ifdef __cplusplus
39+ extern "C" {
40+ #endif
3041
3142/**
3243 * Typedef exposing the SDK structure to the API.
@@ -46,8 +57,8 @@ typedef struct _chirp_connect_t chirp_connect_t;
4657PUBLIC_SYM chirp_connect_t * new_chirp_connect (const char * key , const char * secret );
4758
4859/**
49- * Free the memory of the SDK. This function should be the last one to be called
50- * among all the API functions.
60+ * Release the SDK. This function should be the last one to be called among all
61+ * the API functions.
5162 *
5263 * During the program life time, this function should be called only one time.
5364 *
@@ -59,6 +70,7 @@ PUBLIC_SYM chirp_connect_error_code_t del_chirp_connect(chirp_connect_t **connec
5970
6071/**
6172 * Free some memory previously allocated and returned by the SDK.
73+ *
6274 * @param ptr The pointer to the memory to be freed.
6375 */
6476PUBLIC_SYM void chirp_connect_free (void * ptr );
@@ -71,7 +83,7 @@ PUBLIC_SYM void chirp_connect_free(void *ptr);
7183 *
7284 * @param connect A pointer to the SDK structure which needs the config to be
7385 * set.
74- * @param config The config string which will be set.
86+ * @param config The config string which will be set.
7587 * @return An error code resulting from the call. CHIRP_CONNECT_OK will
7688 * be returned if everything went well.
7789 */
@@ -111,21 +123,6 @@ PUBLIC_SYM chirp_connect_error_code_t chirp_connect_set_callbacks(chirp_connect_
111123 */
112124PUBLIC_SYM chirp_connect_error_code_t chirp_connect_start (chirp_connect_t * connect );
113125
114- /**
115- * Pause the SDK and the audio processing. No more data can be sent or received.
116- * If this is called when sending data, the rest of the audio will resume when
117- * leaving the pause state. On the contrary of `chirp_connect_stop`, this function
118- * doesn't free any internal memory.
119- *
120- * @param connect A pointer to the SDK structure.
121- * @param pause A boolean indicating the SDK's `pause` status. If true, the
122- * SDK will pause the audio processing. If false, the SDK will
123- * resume the audio processing.
124- * @return An error code resulting from the call. CHIRP_CONNECT_OK will
125- * be returned if everything went well.
126- */
127- PUBLIC_SYM chirp_connect_error_code_t chirp_connect_pause (chirp_connect_t * connect , bool pause );
128-
129126/**
130127 * Stop the SDK and the audio processing. Once this function is called, some
131128 * internal structures will be reset and any data being sent won't be
@@ -137,31 +134,26 @@ PUBLIC_SYM chirp_connect_error_code_t chirp_connect_pause(chirp_connect_t *conne
137134 */
138135PUBLIC_SYM chirp_connect_error_code_t chirp_connect_stop (chirp_connect_t * connect );
139136
140- /**
141- * Allocate a new empty payload which will later be filled with the data to send.
142- * To release the memory, call `chirp_connect_free` on the data pointer.
143- *
144- * @param connect A pointer to the SDK structure.
145- * @param length The length, in bytes, of the new payload.
146- * @return A pointer to the newly created data payload.
147- */
148- PUBLIC_SYM uint8_t * chirp_connect_new_payload (chirp_connect_t * connect , size_t length );
149-
150137/**
151138 * Get the maximum payload length allowed by the current config set for the SDK.
152139 *
140+ *
153141 * @param connect A pointer to the SDK structure.
154142 * @return The maximum payload length that can be sent. A length of 0 is
155- * invalid.
143+ * invalid. If the config hasn't been set yet when this function
144+ * is called 0 is returned.
156145 */
157146PUBLIC_SYM size_t chirp_connect_get_max_payload_length (chirp_connect_t * connect );
158147
159148/**
160149 * Get the duration, in seconds, for a given payload length.
161150 *
162151 * @param connect A pointer to the SDK structure.
163- * @param length The length, in bytes, of the payload we want to know the duration.
164- * @return The duration, in second, of the given length.
152+ * @param length The length, in bytes, of the payload we want to know the
153+ * duration. You can get the maximum allowed length with
154+ * `chirp_connect_get_max_payload_length`.
155+ * @return The duration, in second, of the given length, -1 if the payload
156+ * is too short or -2 if the payload is too long.
165157 */
166158PUBLIC_SYM float chirp_connect_get_duration_for_payload_length (chirp_connect_t * connect , size_t length );
167159
@@ -184,7 +176,8 @@ PUBLIC_SYM chirp_connect_error_code_t chirp_connect_is_valid(chirp_connect_t *co
184176 * @param length A pointer containing the length, in bytes, of the payload to be
185177 * generated. If the length is 0, the SDK will randomise both the
186178 * length of the payload and its content. The length pointer will
187- * then be updated with the random length.
179+ * then be updated with the random length. You can get the
180+ * maximum allowed length with `chirp_connect_get_max_payload_length`.
188181 * @return A pointer to the newly created random data payload.The user
189182 * has to free this pointer once they doesn't need it anymore using
190183 * `chirp_connect_free`.
@@ -193,10 +186,11 @@ PUBLIC_SYM uint8_t *chirp_connect_random_payload(chirp_connect_t *connect, size_
193186
194187/**
195188 * Convert the payload to an hexadecimal string representation to offer a quick
196- * and easy human readable way to represent the data.
189+ * and easy human readable way to represent the data. The result string is
190+ * deprived of any "0x" marker thus converting the byte "B" would give "42".
197191 *
198192 * @param connect A pointer to the SDK structure.
199- * @param bytes A pointer to the payload to be validated .
193+ * @param bytes A pointer to the payload to be converted .
200194 * @param length The length, in bytes, of the data payload.
201195 * @return The string representation of the payload. The user has to free
202196 * this pointer once they doesn't need it anymore using
@@ -205,7 +199,21 @@ PUBLIC_SYM uint8_t *chirp_connect_random_payload(chirp_connect_t *connect, size_
205199PUBLIC_SYM char * chirp_connect_as_string (chirp_connect_t * connect , uint8_t * bytes , size_t length );
206200
207201/**
208- * Send a payload.
202+ * Convert an hexadecimal string to the payload it represents. The input must be
203+ * an hexadecimal string without the "0x" prefix. Very few checks are done on
204+ * the input and it is up to the user to ensure then input string is correct.
205+ *
206+ * @param connect A pointer to the SDK structure.
207+ * @param hex_string A pointer to the hexadecimal string to be converted.
208+ * @return The payload corresponding to the input string. The user has
209+ * to free this pointer once they doesn't need it anymore using
210+ * `chirp_connect_free`.
211+ */
212+ PUBLIC_SYM uint8_t * chirp_connect_from_string (chirp_connect_t * connect , char * hex_string );
213+
214+ /**
215+ * Send a payload. A valid length is between 1 and the value returned by
216+ * `chirp_connect_get_max_payload_length`.
209217 *
210218 * @param connect A pointer to the SDK structure.
211219 * @param bytes A pointer to the payload that will be sent.
@@ -302,9 +310,10 @@ PUBLIC_SYM chirp_connect_state_t chirp_connect_get_state_for_channel(chirp_conne
302310 * which the data is sent.
303311 *
304312 * @param connect A pointer to the SDK structure.
305- * @return The channel on which the data is sent.
313+ * @return The channel on which the data is sent (including 0) or -1 if
314+ * the SDK hasn't been initialised.
306315 */
307- PUBLIC_SYM uint8_t chirp_connect_get_transmission_channel (chirp_connect_t * connect );
316+ PUBLIC_SYM int8_t chirp_connect_get_transmission_channel (chirp_connect_t * connect );
308317
309318/**
310319 * Set the channel on which the data will be sent. Allowed values are between 0
@@ -341,7 +350,7 @@ PUBLIC_SYM chirp_connect_state_t chirp_connect_get_state(chirp_connect_t *connec
341350 * audio volume.
342351 *
343352 * @param connect A pointer to the SDK structure.
344- * @return The volume of the output of SDK.
353+ * @return The volume of the output of the SDK or -1 if an error happened .
345354 */
346355PUBLIC_SYM float chirp_connect_get_volume (chirp_connect_t * connect );
347356
@@ -407,18 +416,18 @@ PUBLIC_SYM chirp_connect_error_code_t chirp_connect_set_output_sample_rate(chirp
407416 * @return False: The SDK will attempt to decode the payloads it sends.
408417 * True: The SDK will ignore the payloads it sends.
409418 */
410- PUBLIC_SYM bool chirp_connect_get_auto_mute (chirp_connect_t * connect );
419+ PUBLIC_SYM bool chirp_connect_get_listen_to_self (chirp_connect_t * connect );
411420
412421/**
413- * Set the auto mute status of the SDK.
422+ * Set the listen to self status of the SDK.
414423 *
415- * @param connect A pointer to the SDK structure.
416- * @param auto_mute False : The SDK will attempt to decode the payloads it sends.
417- * True : The SDK will ignore the payloads it sends.
418- * @return An error code resulting from the call. CHIRP_CONNECT_OK will
419- * be returned if everything went well.
424+ * @param connect A pointer to the SDK structure.
425+ * @param listen_to_self True : The SDK will attempt to decode the payloads it sends.
426+ * False : The SDK will ignore the payloads it sends.
427+ * @return An error code resulting from the call. CHIRP_CONNECT_OK will
428+ * be returned if everything went well.
420429 */
421- PUBLIC_SYM chirp_connect_error_code_t chirp_connect_set_auto_mute (chirp_connect_t * connect , bool auto_mute );
430+ PUBLIC_SYM chirp_connect_error_code_t chirp_connect_set_listen_to_self (chirp_connect_t * connect , bool listen_to_self );
422431
423432/**
424433 * Set the pointer which is accessible in the callbacks. This function doesn't
@@ -449,15 +458,15 @@ PUBLIC_SYM chirp_connect_error_code_t chirp_connect_set_callback_ptr(chirp_conne
449458PUBLIC_SYM chirp_connect_error_code_t chirp_connect_set_frequency_correction (chirp_connect_t * connect , float correction );
450459
451460/**
452- * Get the version number of the SDK. This function doesn't rely at all on the
453- * SDK creation and can be called at any time.
461+ * Return the current heap usage of the SDK, in bytes.
454462 *
455- * @return The version number of the SDK in the MAJOR.MINOR.PATCH string
456- * representation .
463+ * @param connect A pointer to the SDK structure.
464+ * @return The heap usage in bytes of the SDK .
457465 */
458- PUBLIC_SYM const char * chirp_connect_get_version ( void );
466+ PUBLIC_SYM int32_t chirp_connect_get_heap_usage ( chirp_connect_t * connect );
459467
460468#ifdef __cplusplus
461469}
462470#endif
463- #endif // __CHIRP_CONNECT_H__
471+
472+ #endif /* !CHIRP_CONNECT_H */
0 commit comments