Skip to content

Commit 08977d9

Browse files
authored
Merge pull request #12 from chirp/feature/update-libs
updated libs and headers
2 parents 50a7586 + 60b6d6b commit 08977d9

9 files changed

+221
-182
lines changed

src/chirp_connect.h

+70-61
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,40 @@
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;
4657
PUBLIC_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
*/
6476
PUBLIC_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
*/
112124
PUBLIC_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
*/
138135
PUBLIC_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
*/
157146
PUBLIC_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
*/
166158
PUBLIC_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_
205199
PUBLIC_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
*/
346355
PUBLIC_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
449458
PUBLIC_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 */

src/chirp_connect_callbacks.h

+23-15
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,28 @@
44
*
55
* @file chirp_connect_callbacks.h
66
*
7+
* @brief Callback implementations of the C SDK.
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_CALLBACK_H__
16-
#define __CHIRP_CONNECT_CALLBACK_H__
17+
#ifndef CHIRP_CONNECT_CALLBACKS_H
18+
#define CHIRP_CONNECT_CALLBACKS_H
19+
20+
#include <stdint.h>
21+
#include <stddef.h>
22+
23+
#include "chirp_connect_states.h"
1724

1825
#ifdef __cplusplus
1926
extern "C" {
2027
#endif
2128

22-
#include "chirp_connect_states.h"
23-
2429
/**
2530
* On_sending, on_sent, on_receiving and on_received callback prototype
2631
* definitions. These callbacks are called if set and respectively if the SDK is
@@ -42,9 +47,10 @@ extern "C" {
4247
typedef void (*chirp_connect_callback_t)(void *ptr, uint8_t *bytes, size_t length, uint8_t channel);
4348

4449
/**
45-
* On_state_changed callback prototype definition. This is called if the callback
46-
* has been set and when the SDK's state is changing. The possibles values are
47-
* the one of the `chirp_connect_state_t` enum located in `chirp_connect_states.h`.
50+
* On_state_changed callback prototype definition. This is called if the
51+
* callback has been set and when the SDK's state is changing.
52+
* The possibles values are the one of the `chirp_connect_state_t` enum
53+
* located in `chirp_connect_states.h`.
4854
*
4955
* @param ptr Pointer of data. It's either the pointer set when calling
5056
* `chirp_connect_set_callback_ptr` or NULL.
@@ -55,17 +61,19 @@ typedef void (*chirp_connect_state_callback_t)(void *ptr, chirp_connect_state_t
5561

5662
/**
5763
* Structure containing the callbacks pointers. It is not necessary to set all
58-
* the fields. This will only implies not being notified on the event omitted.
64+
* the fields. Not setting a callback will only result in not being notified of
65+
* the event.
5966
*/
6067
typedef struct {
61-
chirp_connect_state_callback_t on_state_changed;
62-
chirp_connect_callback_t on_sending;
63-
chirp_connect_callback_t on_sent;
64-
chirp_connect_callback_t on_receiving;
65-
chirp_connect_callback_t on_received;
68+
chirp_connect_state_callback_t on_state_changed; ///< Triggered when the SDK's state is changing.
69+
chirp_connect_callback_t on_sending; ///< Triggered when the SDK starts sending some data.
70+
chirp_connect_callback_t on_sent; ///< Triggered when the SDK has sent the data.
71+
chirp_connect_callback_t on_receiving; ///< Triggered when the SDK starts receiving some data.
72+
chirp_connect_callback_t on_received; ///< Triggered when the SDK has received the data.
6673
} chirp_connect_callback_set_t;
6774

6875
#ifdef __cplusplus
6976
}
7077
#endif
71-
#endif // __CHIRP_CONNECT_CALLBACK_H__
78+
79+
#endif /* !CHIRP_CONNECT_CALLBACKS_H */

0 commit comments

Comments
 (0)