44#include <stdlib.h>
55#include <string.h>
66
7- #include "MQTTClient.h"
87#include "src/buffer/synchronous_single_buffer.h"
98#include "src/capture/capture.h"
109#include "src/config/config.h"
@@ -16,61 +15,56 @@ AppConfig app_config;
1615AvailableDevice available_devices ;
1716
1817int input_device_id (const AvailableDevice * devices ) {
19- int c ;
20- printf ("\u25b6 Please enter device #: \n" );
21- while ((c = getchar ()) != EOF && !isspace (c )) {
22- const int n = c - '0' ;
23- if (in_array (devices -> device_ids , devices -> device_count , n )) {
24- return n ;
18+ int c ;
19+ printf ("\u25b6 Please enter device #: \n" );
20+ while ((c = getchar ()) != EOF && !isspace (c )) {
21+ const int n = c - '0' ;
22+ if (in_array (devices -> device_ids , devices -> device_count , n )) {
23+ return n ;
24+ }
2525 }
26- }
27- printf ("Not found. Using default # 0\n" );
28- return 0 ;
26+ printf ("Not found. Using default # 0\n" );
27+ return 0 ;
2928}
3029
3130SynchronousSingleBuffer buffer ;
31+ int16_t storage [SYNCHRONOUS_SINGULAR_BUFFER_SIZE ] = {0 };
3232
3333int main (const int argc , char * argv []) {
34- if (strcmp (argv [1 ], "--help" ) == 0 || strcmp (argv [1 ], "-h" ) == 0 ) {
35- help ();
36- return 0 ;
37- }
38- if (argc <= 1 ) {
39- printf ("Args missing" );
40- return 0 ;
41- }
42- const char * mqtt_topic = argv [2 ];
43- const char * certs_path = argv [3 ];
44- const char * aws_endpoint = argv [4 ];
45- // MQTTConfig mqtt_config;
46- // init_config(mqtt_topic, certs_path, aws_endpoint, &mqtt_config);
47- // MQTTClient client;
48- // init_client(&client, &mqtt_config);
49- // send_message(&client, &mqtt_config, "Device connected");
34+ if (strcmp (argv [1 ], "--help" ) == 0 || strcmp (argv [1 ], "-h" ) == 0 ) {
35+ help ();
36+ return 0 ;
37+ }
38+ if (argc <= 1 ) {
39+ printf ("Args missing" );
40+ return 0 ;
41+ }
42+ const char * mqtt_topic = argv [2 ];
43+ const char * certs_path = argv [3 ];
44+ const char * aws_endpoint = argv [4 ];
45+ MQTTConfig mqtt_config ;
46+ init_config (mqtt_topic , certs_path , aws_endpoint , & mqtt_config );
47+ init_client (& mqtt_config );
48+ send_message (& mqtt_config , "Device connected" );
5049
51- suppress_alsa_errors ();
52- int16_t * storage = calloc (SYNCHRONOUS_SINGULAR_BUFFER_SIZE , sizeof (int16_t ));
53- buffer .storage = storage ;
54- init_buffer (& buffer , storage );
50+ suppress_alsa_errors ();
51+ buffer .storage = storage ;
52+ init_buffer (& buffer , storage );
5553
56- load_ultrasonic_devices (& available_devices );
57- describe_available_ultrasonic_devices (& available_devices );
54+ load_ultrasonic_devices (& available_devices );
55+ describe_available_ultrasonic_devices (& available_devices );
5856
59- const int device_id = input_device_id (& available_devices );
60- (void )getchar ();
61- AudioDevice audio_device = available_devices .devices [device_id ];
57+ const int device_id = input_device_id (& available_devices );
58+ (void ) getchar ();
59+ AudioDevice audio_device = available_devices .devices [device_id ];
6260
63- pthread_t r_thread ;
64- ReaderContext reader_context = {& buffer , SYNCHRONOUS_SINGULAR_BUFFER_SIZE ,
65- audio_device .default_sample_rate_hz };
66- pthread_create (& r_thread , NULL , (void * (* )(void * ))reader_thread ,
67- & reader_context );
61+ pthread_t r_thread ;
62+ ReaderContext reader_context = {& buffer , SYNCHRONOUS_SINGULAR_BUFFER_SIZE , audio_device .default_sample_rate_hz };
63+ pthread_create (& r_thread , NULL , (void * (* ) (void * ) ) reader_thread , & reader_context );
6864
69- start_stream (SYNCHRONOUS_SINGULAR_BUFFER_SIZE , & audio_device , & buffer );
70- pthread_join (r_thread , NULL );
65+ start_stream (SYNCHRONOUS_SINGULAR_BUFFER_SIZE , & audio_device , & buffer );
66+ pthread_join (r_thread , NULL );
7167
72- free (storage );
73- // MQTTClient_disconnect(client, mqtt_config.timeout_ms);
74- // MQTTClient_destroy(&client);
75- return 0 ;
68+ cleanup ();
69+ return 0 ;
7670}
0 commit comments