ant-wireless 0.1.0.pre.20210617213631

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 47f23b13571d44d37275d309e73bf1b3b1d3b4f7e3c952f95fdf5b73321412b1
4
+ data.tar.gz: 6bbccd101666ef42d12eab3d9b3d9e653634d97e19d9042f0c8282d74caf3fcb
5
+ SHA512:
6
+ metadata.gz: 3cfbf1870872f9747df428d3ac4be4dd71b857bf47beb763f3d30fa517134b5d509e895ed975307b26de7936cee40dfc83f7b938e11679e61bf9e002d058acfb
7
+ data.tar.gz: e7831b872fabbd850a946c88d053edc604aff86652e0efc6ffee9e593f92e5c52216a7382520765f2793a1e728b4457335ef3b9a999ec3d3eaa00699fdc89c2a
data/History.md ADDED
@@ -0,0 +1,5 @@
1
+ # Release History for ruby-ant
2
+
3
+ ---
4
+
5
+
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2021 Ravn Group
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,79 @@
1
+ # ant-wireless
2
+
3
+ home
4
+ : https://sr.ht/~ged/ruby-ant-wireless/
5
+
6
+ code
7
+ : https://hg.sr.ht/~ged/ruby-ant-wireless
8
+
9
+ docs
10
+ : https://deveiate.org/code/ant-wireless
11
+
12
+
13
+ ## Description
14
+
15
+ A binding for the [ANT ultra-low power wireless protocol][ant] via the
16
+ [Garmin USB ANT Stick][antstick]. ANT can be used to send information
17
+ wirelessly from one device to another device, in a robust and flexible
18
+ manner.
19
+
20
+
21
+ ## Prerequisites
22
+
23
+ * Ruby
24
+ * Garmin USB ANT Stick (https://buy.garmin.com/en-US/US/p/10997/pn/010-01058-00)
25
+
26
+
27
+ ## Installation
28
+
29
+ $ gem install ant-wireless
30
+
31
+
32
+ ## Development
33
+
34
+ You can check out the current source with Git via Gitlab:
35
+
36
+ $ hg clone https://hg.sr.ht/~ged/ruby-ant-wireless ant-wireless
37
+ $ cd ant-wireless
38
+
39
+ After checking out the source, run:
40
+
41
+ $ gem install -Ng
42
+ $ rake setup
43
+
44
+ This task will install dependencies, and do any other necessary setup for development.
45
+
46
+
47
+ ## Authors
48
+
49
+ - Michael Granger <ged@FaerieMUD.org>
50
+ - Mahlon E. Smith <mahlon@martini.nu>
51
+
52
+
53
+ ## License
54
+
55
+ Copyright (c) 2021, Ravn Group
56
+
57
+ Permission is hereby granted, free of charge, to any person obtaining
58
+ a copy of this software and associated documentation files (the
59
+ "Software"), to deal in the Software without restriction, including
60
+ without limitation the rights to use, copy, modify, merge, publish,
61
+ distribute, sublicense, and/or sell copies of the Software, and to
62
+ permit persons to whom the Software is furnished to do so, subject to
63
+ the following conditions:
64
+
65
+ The above copyright notice and this permission notice shall be
66
+ included in all copies or substantial portions of the Software.
67
+
68
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
69
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
70
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
71
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
72
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
73
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
74
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
75
+
76
+
77
+ [ant]: https://www.thisisant.com/
78
+ [antstick]: https://buy.garmin.com/en-US/US/p/10997/pn/010-01058-00
79
+
@@ -0,0 +1,791 @@
1
+ /*
2
+ * ant_ext.c - Ruby binding for ANT communications
3
+ * $Id$
4
+ *
5
+ * Authors:
6
+ * * Michael Granger <ged@FaerieMUD.org>
7
+ *
8
+ */
9
+
10
+ #include "ant_ext.h"
11
+
12
+ VALUE rant_mAnt;
13
+
14
+ static ID response_callback_ivar;
15
+
16
+
17
+ /* --------------------------------------------------------------
18
+ * Logging Functions
19
+ * -------------------------------------------------------------- */
20
+
21
+ /*
22
+ * Log a message to the given +context+ object's logger.
23
+ */
24
+ void
25
+ #ifdef HAVE_STDARG_PROTOTYPES
26
+ rant_log_obj( VALUE context, const char *level, const char *fmt, ... )
27
+ #else
28
+ rant_log_obj( VALUE context, const char *level, const char *fmt, va_dcl )
29
+ #endif
30
+ {
31
+ char buf[BUFSIZ];
32
+ va_list args;
33
+ VALUE logger = Qnil;
34
+ VALUE message = Qnil;
35
+
36
+ va_init_list( args, fmt );
37
+ vsnprintf( buf, BUFSIZ, fmt, args );
38
+ message = rb_str_new2( buf );
39
+
40
+ logger = rb_funcall( context, rb_intern("log"), 0 );
41
+ rb_funcall( logger, rb_intern(level), 1, message );
42
+
43
+ va_end( args );
44
+ }
45
+
46
+
47
+ /*
48
+ * Log a message to the global logger.
49
+ */
50
+ void
51
+ #ifdef HAVE_STDARG_PROTOTYPES
52
+ rant_log( const char *level, const char *fmt, ... )
53
+ #else
54
+ rant_log( const char *level, const char *fmt, va_dcl )
55
+ #endif
56
+ {
57
+ char buf[BUFSIZ];
58
+ va_list args;
59
+ VALUE logger = Qnil;
60
+ VALUE message = Qnil;
61
+
62
+ va_init_list( args, fmt );
63
+ vsnprintf( buf, BUFSIZ, fmt, args );
64
+ message = rb_str_new2( buf );
65
+
66
+ logger = rb_funcall( rant_mAnt, rb_intern("logger"), 0 );
67
+ rb_funcall( logger, rb_intern(level), 1, message );
68
+
69
+ va_end( args );
70
+ }
71
+
72
+
73
+ /* --------------------------------------------------------------
74
+ * Utility functions
75
+ * -------------------------------------------------------------- */
76
+
77
+
78
+
79
+ /* --------------------------------------------------------------
80
+ * Module methods
81
+ * -------------------------------------------------------------- */
82
+
83
+ /*
84
+ * call-seq:
85
+ * Ant.lib_version -> int
86
+ *
87
+ * Return the version of the underlying libant.
88
+ *
89
+ */
90
+ static VALUE
91
+ rant_s_lib_version( VALUE _module )
92
+ {
93
+ const char *version = ANT_LibVersion();
94
+
95
+ return rb_str_new_cstr( version );
96
+ }
97
+
98
+
99
+ /*
100
+ * call-seq:
101
+ * Ant.device_usb_info( device_num ) -> [ product_string, serial_string ]
102
+ *
103
+ * Get the product and serial info of the USB device +device_num+.
104
+ *
105
+ */
106
+ static VALUE
107
+ rant_s_device_usb_info( VALUE _module, VALUE device_num )
108
+ {
109
+ const unsigned short deviceNum = NUM2SHORT( device_num );
110
+ unsigned char product_string[256];
111
+ unsigned char serial_string[256];
112
+ VALUE rval = rb_ary_new2( 2 );
113
+
114
+ if ( !ANT_GetDeviceUSBInfo( (unsigned char)deviceNum, product_string, serial_string ) ) {
115
+ return Qnil;
116
+ }
117
+
118
+ rant_log_obj( _module, "debug", "Got product string = %s, serial string = %s", product_string, serial_string );
119
+ rb_ary_push( rval, rb_str_new_cstr((const char *)product_string) );
120
+ rb_ary_push( rval, rb_str_new_cstr((const char *)serial_string) );
121
+
122
+ return rval;
123
+ }
124
+
125
+
126
+ /*
127
+ * call-seq:
128
+ * Ant.device_usb_pid -> integer
129
+ *
130
+ * Returns the +pid+ of the USB device.
131
+ *
132
+ */
133
+ static VALUE
134
+ rant_s_device_usb_pid( VALUE _module )
135
+ {
136
+ unsigned short pid;
137
+
138
+ if ( !ANT_GetDeviceUSBPID(&pid) ) {
139
+ rb_sys_fail( "Fetching the USB PID." );
140
+ }
141
+
142
+ return INT2FIX( pid );
143
+ }
144
+
145
+
146
+ /*
147
+ * call-seq:
148
+ * Ant.device_usb_vid -> integer
149
+ *
150
+ * Returns the +vid+ of the USB device.
151
+ *
152
+ */
153
+ static VALUE
154
+ rant_s_device_usb_vid( VALUE _module )
155
+ {
156
+ unsigned short vid;
157
+
158
+ if ( !ANT_GetDeviceUSBVID(&vid) ) {
159
+ rb_sys_fail( "Fetching the USB VID." );
160
+ }
161
+
162
+ return INT2FIX( vid );
163
+ }
164
+
165
+
166
+ /*
167
+ * call-seq:
168
+ * Ant.device_serial_number -> integer
169
+ *
170
+ * Returns the serial number of the ANT device; not implemented on all devices.
171
+ *
172
+ */
173
+ static VALUE
174
+ rant_s_device_serial_number( VALUE _module )
175
+ {
176
+ #ifdef HAVE_ANT_GETDEVICESERIALNUMBER
177
+ const unsigned long serial = ANT_GetDeviceSerialNumber();
178
+ return LONG2FIX( serial );
179
+ #else
180
+ rb_notimplement();
181
+ #endif
182
+ }
183
+
184
+
185
+
186
+ /*
187
+ * call-seq:
188
+ * Ant.init( device_num=0, baud_rate=57600 ) -> true
189
+ *
190
+ * Initialize the ANT library and connect to the ANT module. The +device_num+ is
191
+ * the USB device number of the module to connect to, defaulting to 0. Modules
192
+ * connected to a PC will be assigned USB device numbers starting from 0. N is
193
+ * the number of USB ANT devices that are connected. The +baud_rate+ is the
194
+ * asynchronous baud rate used to connect to the ANT controller. See specific
195
+ * ANT controllers for allowable baud rates.
196
+ *
197
+ */
198
+ static VALUE
199
+ rant_s_init( int argc, VALUE *argv, VALUE _module )
200
+ {
201
+ VALUE device_num = Qnil, baud_rate = Qnil;
202
+ unsigned char ucUSBDeviceNum;
203
+ unsigned int ulBaudrate;
204
+
205
+ rb_scan_args( argc, argv, "02", &device_num, &baud_rate );
206
+
207
+ if ( RTEST(device_num) ) {
208
+ ucUSBDeviceNum = NUM2CHR( device_num );
209
+ } else {
210
+ ucUSBDeviceNum = 0;
211
+ }
212
+
213
+ if ( RTEST(baud_rate) ) {
214
+ ulBaudrate = NUM2UINT( baud_rate );
215
+ } else {
216
+ ulBaudrate = DEFAULT_BAUDRATE;
217
+ }
218
+
219
+ rant_log_obj( rant_mAnt, "info", "Initializing ANT device %d at %d baud", ucUSBDeviceNum, ulBaudrate );
220
+ if ( !ANT_Init(ucUSBDeviceNum, ulBaudrate) ) {
221
+ rb_raise( rb_eRuntimeError, "Initializing the ANT library (no ANT device present?)." );
222
+ }
223
+
224
+ return Qtrue;
225
+ }
226
+
227
+
228
+
229
+ /*
230
+ * call-seq:
231
+ * Ant.close
232
+ *
233
+ * Close the USB connection to the ANT module.
234
+ *
235
+ */
236
+ static VALUE
237
+ rant_s_close( VALUE _module )
238
+ {
239
+ ANT_Close();
240
+
241
+ rant_channel_clear_registry();
242
+
243
+ return Qtrue;
244
+ }
245
+
246
+
247
+ /*
248
+ * call-seq:
249
+ * Ant.reset
250
+ *
251
+ * Reset the system and put it in a known, low-power state. Execution of this
252
+ * command terminates all channels. All information previously configured in the
253
+ * system can no longer be considered valid.
254
+ *
255
+ */
256
+ static VALUE
257
+ rant_s_reset( VALUE _module )
258
+ {
259
+ const struct timeval wait_time = {
260
+ .tv_sec = 0,
261
+ .tv_usec = 500,
262
+ };
263
+ ANT_ResetSystem();
264
+
265
+ rant_channel_clear_registry();
266
+
267
+ // After a Reset System command has been issued, the application should wait
268
+ // 500ms to ensure that ANT is in the proper, “after-reset” state before any
269
+ // further commands are issued from the host.
270
+ rb_thread_wait_for( wait_time );
271
+
272
+ return Qtrue;
273
+ }
274
+
275
+
276
+ /*
277
+ * call-seq:
278
+ * Ant.set_network_key( network_num, network_key )
279
+ *
280
+ * Configures a network address for use by one of the available network numbers.
281
+ *
282
+ */
283
+ static VALUE
284
+ rant_s_set_network_key( VALUE _module, VALUE network_number, VALUE key )
285
+ {
286
+ const unsigned short ucNetNumber = NUM2USHORT( network_number );
287
+ const char *pucKey = StringValuePtr( key );
288
+
289
+ if ( RSTRING_LEN(key) != 8 ) {
290
+ rb_raise( rb_eArgError, "expected an 8-byte key" );
291
+ }
292
+
293
+ if ( !ANT_SetNetworkKey(ucNetNumber, (unsigned char *)pucKey) ) {
294
+ rb_raise( rb_eRuntimeError, "could not set the network key." );
295
+ }
296
+
297
+ return Qtrue;
298
+ }
299
+
300
+
301
+ /*
302
+ * call-seq:
303
+ * Ant.assign_channel( channel, channel_type, network_number=0, extended_options=0x0, timeout=0 ) -> channel
304
+ *
305
+ * Assign a channel and return an Ant::Channel object for it. Channel assignment
306
+ * reserves a channel number and assigns the type and network number to the
307
+ * channel. The optional extended assignment byte allows for the following
308
+ * features to be enabled:
309
+ *
310
+ * +EXT_PARAM_FREQUENCY_AGILITY+:: enable frequency agility
311
+ * +EXT_PARAM_BACKGROUND_SCANNING+:: enable background scanning
312
+ * +EXT_PARAM_FAST_CHANNEL_INIT+:: enable fast channel initiation
313
+ * +EXT_PARAM_ASYNC_TRANSMIT+:: enable asynchronous transmission
314
+ *
315
+ */
316
+ static VALUE
317
+ rant_s_assign_channel( int argc, VALUE *argv, VALUE _module )
318
+ {
319
+ unsigned char ucChannel,
320
+ ucChannelType,
321
+ ucNetworkNumber = 0,
322
+ ucExtend = 0,
323
+ ulResponseTime = 0;
324
+ VALUE channel,
325
+ channel_type,
326
+ network_number,
327
+ extended_options,
328
+ timeout;
329
+ VALUE args[4];
330
+
331
+ rb_scan_args( argc, argv, "23", &channel, &channel_type, &network_number, &extended_options, &timeout );
332
+
333
+ ucChannel = NUM2CHR( channel );
334
+ ucChannelType = NUM2CHR( channel_type );
335
+
336
+ if ( RTEST(network_number) ) {
337
+ ucNetworkNumber = NUM2CHR( network_number );
338
+ }
339
+ if ( RTEST(extended_options) ) {
340
+ ucExtend = NUM2CHR( extended_options );
341
+ }
342
+ if ( RTEST(timeout) ) {
343
+ ulResponseTime = NUM2CHR( timeout );
344
+ }
345
+
346
+ if ( !ANT_AssignChannelExt_RTO(ucChannel, ucChannelType, ucNetworkNumber, ucExtend, ulResponseTime) ) {
347
+ rb_raise( rb_eRuntimeError, "Couldn't assign channel %d", ucChannel );
348
+ }
349
+
350
+ rant_log( "info", "Assigned channel %d (0x%02x) to network %d {0x%02x}.",
351
+ ucChannel, ucChannelType, ucNetworkNumber, ucExtend );
352
+
353
+ args[0] = channel;
354
+ args[1] = channel_type;
355
+ args[2] = network_number;
356
+ args[3] = extended_options;
357
+
358
+ return rb_class_new_instance( 4, args, rant_cAntChannel );
359
+ }
360
+
361
+
362
+ /*
363
+ * call-seq:
364
+ * Ant.use_extended_messages = true or false
365
+ *
366
+ * Enable or disable extended Rx messages. If the device supports it, when
367
+ * ANT will include the channel ID with the data message.
368
+ *
369
+ */
370
+ static VALUE
371
+ rant_s_use_extended_messages_eq( VALUE _module, VALUE true_false )
372
+ {
373
+ // This is documented as an unsigned char and then explicitly cast
374
+ // to a signed char. So this just uses their typedef.
375
+ const BOOL ucEnable = RTEST( true_false ) ? TRUE : FALSE;
376
+
377
+ rant_log( "info", "%s extended messages.", ucEnable ? "Enabling" : "Disabling" );
378
+ ANT_RxExtMesgsEnable( ucEnable );
379
+
380
+ return Qtrue;
381
+ }
382
+
383
+
384
+ // Buffer for response data.
385
+ // static UCHAR pucResponseBuffer[ MESG_RESPONSE_EVENT_SIZE ];
386
+ static UCHAR pucResponseBuffer[ MESG_MAX_SIZE_VALUE ];
387
+
388
+ struct on_response_call {
389
+ UCHAR ucChannel;
390
+ UCHAR ucResponseMessageId;
391
+ };
392
+
393
+
394
+ /*
395
+ * Handle the response callback -- Ruby side.
396
+ */
397
+ static VALUE
398
+ rant_call_response_callback( VALUE callPtr )
399
+ {
400
+ struct on_response_call *call = (struct on_response_call *)callPtr;
401
+ VALUE rb_callback = rb_ivar_get( rant_mAnt, response_callback_ivar );
402
+ VALUE rval = Qnil;
403
+
404
+ if ( RTEST(rb_callback) ) {
405
+ VALUE args[3];
406
+
407
+ args[0] = INT2FIX( call->ucChannel );
408
+ args[1] = INT2FIX( call->ucResponseMessageId );
409
+ args[2] = rb_enc_str_new( (char *)pucResponseBuffer, MESG_MAX_SIZE_VALUE, rb_ascii8bit_encoding() );
410
+
411
+ rval = rb_funcallv_public( rb_callback, rb_intern("call"), 3, args );
412
+ }
413
+
414
+ return rval;
415
+ }
416
+
417
+
418
+ /*
419
+ * Response callback -- call the registered Ruby callback, if one is set.
420
+ */
421
+ static BOOL
422
+ rant_on_response_callback( UCHAR ucChannel, UCHAR ucResponseMesgID )
423
+ {
424
+ rant_callback_t callback;
425
+ struct on_response_call call;
426
+
427
+ call.ucChannel = ucChannel;
428
+ call.ucResponseMessageId = ucResponseMesgID;
429
+
430
+ callback.data = &call;
431
+ callback.fn = rant_call_response_callback;
432
+
433
+ return rant_callback( &callback );
434
+ }
435
+
436
+
437
+ /*
438
+ * call-seq:
439
+ * Ant.on_response {|channel, response_msg_id| ... }
440
+ *
441
+ * Sets the response callback. The callback is called whenever a response
442
+ * message is received from ANT. See #set_response_handlers for a set of default
443
+ * handlers.
444
+ *
445
+ */
446
+ static VALUE
447
+ rant_s_on_response( int argc, VALUE *argv, VALUE module )
448
+ {
449
+ VALUE callback = Qnil;
450
+
451
+ rb_scan_args( argc, argv, "0&", &callback );
452
+
453
+ if ( !RTEST(callback) ) {
454
+ rb_raise( rb_eLocalJumpError, "block required, but not given" );
455
+ }
456
+
457
+ rant_log( "debug", "Callback is: %s", RSTRING_PTR(rb_inspect(callback)) );
458
+ rb_ivar_set( module, response_callback_ivar, callback );
459
+
460
+ ANT_AssignResponseFunction( rant_on_response_callback, pucResponseBuffer );
461
+
462
+ return Qtrue;
463
+ }
464
+
465
+
466
+
467
+ /*
468
+ * call-seq:
469
+ * Ant.log_directory = "path/to/log/dir"
470
+ *
471
+ * Write debugging logs to the specified directory, which should already exist.
472
+ *
473
+ */
474
+ static VALUE
475
+ rant_s_log_directory_eq( VALUE _module, VALUE directory )
476
+ {
477
+ const char *directory_s = StringValueCStr( directory );
478
+ bool rval = ANT_SetDebugLogDirectory( (char *)directory_s );
479
+
480
+ return rval ? Qtrue : Qfalse;
481
+ }
482
+
483
+
484
+ /*
485
+ * Ant extension init function
486
+ */
487
+ void
488
+ Init_ant_ext()
489
+ {
490
+ /*
491
+ * Document-module: Ant
492
+ *
493
+ * This is an extension for using the ANT ultra-low power wireless protocol via
494
+ * the Garmin USB ANT Stick. ANT can be used to send information
495
+ * wirelessly from one device to another device, in a robust and flexible
496
+ * manner.
497
+ *
498
+ */
499
+ rant_mAnt = rb_define_module( "Ant" );
500
+
501
+ response_callback_ivar = rb_intern( "@response_callback" );
502
+
503
+ rb_define_singleton_method( rant_mAnt, "lib_version", rant_s_lib_version, 0 );
504
+
505
+ rb_define_singleton_method( rant_mAnt, "device_usb_info", rant_s_device_usb_info, 1 );
506
+ rb_define_singleton_method( rant_mAnt, "device_usb_pid", rant_s_device_usb_pid, 0 );
507
+ rb_define_singleton_method( rant_mAnt, "device_usb_vid", rant_s_device_usb_vid, 0 );
508
+ rb_define_singleton_method( rant_mAnt, "device_serial_number", rant_s_device_serial_number, 0 );
509
+
510
+ rb_define_singleton_method( rant_mAnt, "init", rant_s_init, -1 );
511
+ // rb_define_singleton_method( rant_mAnt, "init_ext", rant_s_init_ext, 4 );
512
+ rb_define_singleton_method( rant_mAnt, "close", rant_s_close, 0 );
513
+ rb_define_singleton_method( rant_mAnt, "reset", rant_s_reset, 0 );
514
+
515
+ rb_define_singleton_method( rant_mAnt, "set_network_key", rant_s_set_network_key, 2 );
516
+ rb_define_singleton_method( rant_mAnt, "assign_channel", rant_s_assign_channel, -1 );
517
+
518
+ rb_define_singleton_method( rant_mAnt, "use_extended_messages=",
519
+ rant_s_use_extended_messages_eq, 1 );
520
+
521
+ rb_define_singleton_method( rant_mAnt, "on_response", rant_s_on_response, -1 );
522
+ // EXPORT void ANT_UnassignAllResponseFunctions(); //Unassigns all response functions
523
+
524
+
525
+ rb_define_singleton_method( rant_mAnt, "log_directory=", rant_s_log_directory_eq, 1 );
526
+
527
+
528
+ // Constants
529
+ #define EXPOSE_CONST( name ) \
530
+ rb_define_const( rant_mAnt, #name, INT2FIX( (name) ) )
531
+
532
+ EXPOSE_CONST( PORT_TYPE_USB );
533
+ EXPOSE_CONST( PORT_TYPE_COM );
534
+
535
+ EXPOSE_CONST( ANT_STANDARD_DATA_PAYLOAD_SIZE );
536
+ EXPOSE_CONST( ANT_EXT_MESG_DEVICE_ID_FIELD_SIZE );
537
+ EXPOSE_CONST( ANT_EXT_STRING_SIZE );
538
+ EXPOSE_CONST( ANT_EXT_MESG_BITFIELD_DEVICE_ID );
539
+ EXPOSE_CONST( ANT_EXT_MESG_BIFIELD_EXTENSION );
540
+ EXPOSE_CONST( ANT_EXT_MESG_BITFIELD_OVERWRITE_SHARED_ADR );
541
+ EXPOSE_CONST( ANT_EXT_MESG_BITFIELD_TRANSMISSION_TYPE );
542
+
543
+ EXPOSE_CONST( ANT_LIB_CONFIG_MASK_ALL );
544
+ EXPOSE_CONST( ANT_LIB_CONFIG_RADIO_CONFIG_ALWAYS );
545
+ EXPOSE_CONST( ANT_LIB_CONFIG_MESG_OUT_INC_TIME_STAMP );
546
+ EXPOSE_CONST( ANT_LIB_CONFIG_MESG_OUT_INC_RSSI );
547
+ EXPOSE_CONST( ANT_LIB_CONFIG_MESG_OUT_INC_DEVICE_ID );
548
+
549
+ EXPOSE_CONST( ANT_ID_SIZE );
550
+ EXPOSE_CONST( ANT_ID_TRANS_TYPE_OFFSET );
551
+ EXPOSE_CONST( ANT_ID_DEVICE_TYPE_OFFSET );
552
+ EXPOSE_CONST( ANT_ID_DEVICE_NUMBER_HIGH_OFFSET );
553
+ EXPOSE_CONST( ANT_ID_DEVICE_NUMBER_LOW_OFFSET );
554
+ EXPOSE_CONST( ANT_ID_DEVICE_TYPE_PAIRING_FLAG );
555
+
556
+ EXPOSE_CONST( ANT_TRANS_TYPE_SHARED_ADDR_MASK );
557
+ EXPOSE_CONST( ANT_TRANS_TYPE_1_BYTE_SHARED_ADDRESS );
558
+ EXPOSE_CONST( ANT_TRANS_TYPE_2_BYTE_SHARED_ADDRESS );
559
+
560
+ EXPOSE_CONST( PARAMETER_RX_NOT_TX );
561
+ EXPOSE_CONST( PARAMETER_TX_NOT_RX );
562
+ EXPOSE_CONST( PARAMETER_SHARED_CHANNEL );
563
+ EXPOSE_CONST( PARAMETER_NO_TX_GUARD_BAND );
564
+ EXPOSE_CONST( PARAMETER_ALWAYS_RX_WILD_CARD_SEARCH_ID );
565
+ EXPOSE_CONST( PARAMETER_RX_ONLY );
566
+
567
+ EXPOSE_CONST( EXT_PARAM_ALWAYS_SEARCH );
568
+ EXPOSE_CONST( EXT_PARAM_FREQUENCY_AGILITY );
569
+
570
+ // Set up some aliases and values not in ant.h
571
+ rb_define_const( rant_mAnt, "EXT_PARAM_BACKGROUND_SCANNING", INT2FIX(EXT_PARAM_ALWAYS_SEARCH) );
572
+ rb_define_const( rant_mAnt, "EXT_PARAM_FAST_CHANNEL_INIT", INT2FIX(0x10) );
573
+ rb_define_const( rant_mAnt, "EXT_PARAM_ASYNC_TRANSMIT", INT2FIX(0x20) );
574
+
575
+ EXPOSE_CONST( RADIO_TX_POWER_LVL_MASK );
576
+
577
+ EXPOSE_CONST( RADIO_TX_POWER_LVL_0 );
578
+ EXPOSE_CONST( RADIO_TX_POWER_LVL_1 );
579
+ EXPOSE_CONST( RADIO_TX_POWER_LVL_2 );
580
+ EXPOSE_CONST( RADIO_TX_POWER_LVL_3 );
581
+
582
+ EXPOSE_CONST( STATUS_CHANNEL_STATE_MASK );
583
+ EXPOSE_CONST( STATUS_UNASSIGNED_CHANNEL );
584
+ EXPOSE_CONST( STATUS_ASSIGNED_CHANNEL );
585
+ EXPOSE_CONST( STATUS_SEARCHING_CHANNEL );
586
+ EXPOSE_CONST( STATUS_TRACKING_CHANNEL );
587
+
588
+ EXPOSE_CONST( CAPABILITIES_NO_RX_CHANNELS );
589
+ EXPOSE_CONST( CAPABILITIES_NO_TX_CHANNELS );
590
+ EXPOSE_CONST( CAPABILITIES_NO_RX_MESSAGES );
591
+ EXPOSE_CONST( CAPABILITIES_NO_TX_MESSAGES );
592
+ EXPOSE_CONST( CAPABILITIES_NO_ACKD_MESSAGES );
593
+ EXPOSE_CONST( CAPABILITIES_NO_BURST_TRANSFER );
594
+
595
+ EXPOSE_CONST( CAPABILITIES_OVERUN_UNDERRUN );
596
+ EXPOSE_CONST( CAPABILITIES_NETWORK_ENABLED );
597
+ EXPOSE_CONST( CAPABILITIES_AP1_VERSION_2 );
598
+ EXPOSE_CONST( CAPABILITIES_SERIAL_NUMBER_ENABLED );
599
+ EXPOSE_CONST( CAPABILITIES_PER_CHANNEL_TX_POWER_ENABLED );
600
+ EXPOSE_CONST( CAPABILITIES_LOW_PRIORITY_SEARCH_ENABLED );
601
+ EXPOSE_CONST( CAPABILITIES_SCRIPT_ENABLED );
602
+ EXPOSE_CONST( CAPABILITIES_SEARCH_LIST_ENABLED );
603
+
604
+ EXPOSE_CONST( CAPABILITIES_LED_ENABLED );
605
+ EXPOSE_CONST( CAPABILITIES_EXT_MESSAGE_ENABLED );
606
+ EXPOSE_CONST( CAPABILITIES_SCAN_MODE_ENABLED );
607
+ EXPOSE_CONST( CAPABILITIES_RESERVED );
608
+ EXPOSE_CONST( CAPABILITIES_PROX_SEARCH_ENABLED );
609
+ EXPOSE_CONST( CAPABILITIES_EXT_ASSIGN_ENABLED );
610
+ EXPOSE_CONST( CAPABILITIES_FS_ANTFS_ENABLED );
611
+ EXPOSE_CONST( CAPABILITIES_FIT1_ENABLED );
612
+
613
+ EXPOSE_CONST( CAPABILITIES_ADVANCED_BURST_ENABLED );
614
+ EXPOSE_CONST( CAPABILITIES_EVENT_BUFFERING_ENABLED );
615
+ EXPOSE_CONST( CAPABILITIES_EVENT_FILTERING_ENABLED );
616
+ EXPOSE_CONST( CAPABILITIES_HIGH_DUTY_SEARCH_MODE_ENABLED );
617
+ EXPOSE_CONST( CAPABILITIES_ACTIVE_SEARCH_SHARING_MODE_ENABLED );
618
+ EXPOSE_CONST( CAPABILITIES_SELECTIVE_DATA_UPDATE_ENABLED );
619
+ EXPOSE_CONST( CAPABILITIES_ENCRYPTED_CHANNEL_ENABLED );
620
+
621
+ EXPOSE_CONST( CHANNEL_NUMBER_MASK );
622
+ EXPOSE_CONST( SEQUENCE_NUMBER_MASK );
623
+ EXPOSE_CONST( SEQUENCE_NUMBER_ROLLOVER );
624
+ EXPOSE_CONST( SEQUENCE_FIRST_MESSAGE );
625
+ EXPOSE_CONST( SEQUENCE_LAST_MESSAGE );
626
+ EXPOSE_CONST( SEQUENCE_NUMBER_INC );
627
+
628
+ EXPOSE_CONST( ADV_BURST_CONFIG_FREQ_HOP );
629
+
630
+ EXPOSE_CONST( MSG_EXT_ID_MASK );
631
+
632
+ EXPOSE_CONST( BROADCAST_CONTROL_BYTE );
633
+ EXPOSE_CONST( ACKNOWLEDGED_CONTROL_BYTE );
634
+
635
+ EXPOSE_CONST( RESPONSE_NO_ERROR );
636
+ EXPOSE_CONST( NO_EVENT );
637
+
638
+ EXPOSE_CONST( EVENT_RX_SEARCH_TIMEOUT );
639
+ EXPOSE_CONST( EVENT_RX_FAIL );
640
+ EXPOSE_CONST( EVENT_TX );
641
+ EXPOSE_CONST( EVENT_TRANSFER_RX_FAILED );
642
+ EXPOSE_CONST( EVENT_TRANSFER_TX_COMPLETED );
643
+ EXPOSE_CONST( EVENT_TRANSFER_TX_FAILED );
644
+ EXPOSE_CONST( EVENT_CHANNEL_CLOSED );
645
+ EXPOSE_CONST( EVENT_RX_FAIL_GO_TO_SEARCH );
646
+ EXPOSE_CONST( EVENT_CHANNEL_COLLISION );
647
+ EXPOSE_CONST( EVENT_TRANSFER_TX_START );
648
+
649
+ EXPOSE_CONST( EVENT_CHANNEL_ACTIVE );
650
+
651
+ EXPOSE_CONST( EVENT_TRANSFER_TX_NEXT_MESSAGE );
652
+
653
+ EXPOSE_CONST( CHANNEL_IN_WRONG_STATE );
654
+ EXPOSE_CONST( CHANNEL_NOT_OPENED );
655
+ EXPOSE_CONST( CHANNEL_ID_NOT_SET );
656
+ EXPOSE_CONST( CLOSE_ALL_CHANNELS );
657
+
658
+ EXPOSE_CONST( TRANSFER_IN_PROGRESS );
659
+ EXPOSE_CONST( TRANSFER_SEQUENCE_NUMBER_ERROR );
660
+ EXPOSE_CONST( TRANSFER_IN_ERROR );
661
+ EXPOSE_CONST( TRANSFER_BUSY );
662
+
663
+ EXPOSE_CONST( INVALID_MESSAGE_CRC );
664
+ EXPOSE_CONST( MESSAGE_SIZE_EXCEEDS_LIMIT );
665
+ EXPOSE_CONST( INVALID_MESSAGE );
666
+ EXPOSE_CONST( INVALID_NETWORK_NUMBER );
667
+ EXPOSE_CONST( INVALID_LIST_ID );
668
+ EXPOSE_CONST( INVALID_SCAN_TX_CHANNEL );
669
+ EXPOSE_CONST( INVALID_PARAMETER_PROVIDED );
670
+
671
+ EXPOSE_CONST( EVENT_SERIAL_QUE_OVERFLOW );
672
+ EXPOSE_CONST( EVENT_QUE_OVERFLOW );
673
+
674
+ EXPOSE_CONST( EVENT_CLK_ERROR );
675
+ EXPOSE_CONST( EVENT_STATE_OVERRUN );
676
+
677
+ EXPOSE_CONST( EVENT_ENCRYPT_NEGOTIATION_SUCCESS );
678
+ EXPOSE_CONST( EVENT_ENCRYPT_NEGOTIATION_FAIL );
679
+
680
+ EXPOSE_CONST( SCRIPT_FULL_ERROR );
681
+ EXPOSE_CONST( SCRIPT_WRITE_ERROR );
682
+ EXPOSE_CONST( SCRIPT_INVALID_PAGE_ERROR );
683
+ EXPOSE_CONST( SCRIPT_LOCKED_ERROR );
684
+
685
+ EXPOSE_CONST( NO_RESPONSE_MESSAGE );
686
+ EXPOSE_CONST( RETURN_TO_MFG );
687
+
688
+ EXPOSE_CONST( FIT_ACTIVE_SEARCH_TIMEOUT );
689
+ EXPOSE_CONST( FIT_WATCH_PAIR );
690
+ EXPOSE_CONST( FIT_WATCH_UNPAIR );
691
+
692
+ EXPOSE_CONST( USB_STRING_WRITE_FAIL );
693
+
694
+
695
+ EXPOSE_CONST( INTERNAL_ONLY_EVENTS );
696
+ EXPOSE_CONST( EVENT_RX );
697
+ EXPOSE_CONST( EVENT_NEW_CHANNEL );
698
+ EXPOSE_CONST( EVENT_PASS_THRU );
699
+
700
+ EXPOSE_CONST( EVENT_BLOCKED );
701
+
702
+ EXPOSE_CONST( SCRIPT_CMD_FORMAT );
703
+ EXPOSE_CONST( SCRIPT_CMD_DUMP );
704
+ EXPOSE_CONST( SCRIPT_CMD_SET_DEFAULT_SECTOR );
705
+ EXPOSE_CONST( SCRIPT_CMD_END_SECTOR );
706
+ EXPOSE_CONST( SCRIPT_CMD_END_DUMP );
707
+ EXPOSE_CONST( SCRIPT_CMD_LOCK );
708
+
709
+ EXPOSE_CONST( USB_DESCRIPTOR_VID_PID );
710
+ EXPOSE_CONST( USB_DESCRIPTOR_MANUFACTURER_STRING );
711
+ EXPOSE_CONST( USB_DESCRIPTOR_DEVICE_STRING );
712
+ EXPOSE_CONST( USB_DESCRIPTOR_SERIAL_STRING );
713
+
714
+ EXPOSE_CONST( RESET_FLAGS_MASK );
715
+ EXPOSE_CONST( RESET_SUSPEND );
716
+ EXPOSE_CONST( RESET_SYNC );
717
+ EXPOSE_CONST( RESET_CMD );
718
+ EXPOSE_CONST( RESET_WDT );
719
+ EXPOSE_CONST( RESET_RST );
720
+ EXPOSE_CONST( RESET_POR );
721
+
722
+ EXPOSE_CONST( EVENT_RX_BROADCAST );
723
+ EXPOSE_CONST( EVENT_RX_ACKNOWLEDGED );
724
+ EXPOSE_CONST( EVENT_RX_BURST_PACKET );
725
+
726
+ EXPOSE_CONST( EVENT_RX_EXT_BROADCAST );
727
+ EXPOSE_CONST( EVENT_RX_EXT_ACKNOWLEDGED );
728
+ EXPOSE_CONST( EVENT_RX_EXT_BURST_PACKET );
729
+
730
+ EXPOSE_CONST( EVENT_RX_RSSI_BROADCAST );
731
+ EXPOSE_CONST( EVENT_RX_RSSI_ACKNOWLEDGED );
732
+ EXPOSE_CONST( EVENT_RX_RSSI_BURST_PACKET );
733
+
734
+ EXPOSE_CONST( EVENT_RX_FLAG_BROADCAST );
735
+ EXPOSE_CONST( EVENT_RX_FLAG_ACKNOWLEDGED );
736
+ EXPOSE_CONST( EVENT_RX_FLAG_BURST_PACKET );
737
+
738
+ EXPOSE_CONST( MESG_FS_ANTFS_EVENT_PAIR_REQUEST );
739
+ EXPOSE_CONST( MESG_FS_ANTFS_EVENT_DOWNLOAD_START );
740
+ EXPOSE_CONST( MESG_FS_ANTFS_EVENT_UPLOAD_START );
741
+ EXPOSE_CONST( MESG_FS_ANTFS_EVENT_DOWNLOAD_COMPLETE );
742
+ EXPOSE_CONST( MESG_FS_ANTFS_EVENT_UPLOAD_COMPLETE );
743
+ EXPOSE_CONST( MESG_FS_ANTFS_EVENT_ERASE_COMPLETE );
744
+ EXPOSE_CONST( MESG_FS_ANTFS_EVENT_LINK_STATE );
745
+ EXPOSE_CONST( MESG_FS_ANTFS_EVENT_AUTH_STATE );
746
+ EXPOSE_CONST( MESG_FS_ANTFS_EVENT_TRANSPORT_STATE );
747
+ EXPOSE_CONST( MESG_FS_ANTFS_EVENT_CMD_RECEIVED );
748
+ EXPOSE_CONST( MESG_FS_ANTFS_EVENT_CMD_PROCESSED );
749
+
750
+ EXPOSE_CONST( FS_NO_ERROR_RESPONSE );
751
+ EXPOSE_CONST( FS_MEMORY_UNFORMATTED_ERROR_RESPONSE );
752
+ EXPOSE_CONST( FS_MEMORY_NO_FREE_SECTORS_ERROR_RESPONSE );
753
+ EXPOSE_CONST( FS_MEMORY_READ_ERROR_RESPONSE );
754
+ EXPOSE_CONST( FS_MEMORY_WRITE_ERROR_RESPONSE );
755
+ EXPOSE_CONST( FS_MEMORY_ERASE_ERROR_RESPONSE );
756
+ EXPOSE_CONST( FS_TOO_MANY_FILES_OPEN_RESPONSE );
757
+ EXPOSE_CONST( FS_FILE_INDEX_INVALID_ERROR_RESPONSE );
758
+ EXPOSE_CONST( FS_FILE_INDEX_EXISTS_ERROR_RESPONSE );
759
+ EXPOSE_CONST( FS_AUTO_INDEX_FAILED_TRY_AGAIN_ERROR_RESPONSE );
760
+ EXPOSE_CONST( FS_FILE_ALREADY_OPEN_ERROR_RESPONSE );
761
+ EXPOSE_CONST( FS_FILE_NOT_OPEN_ERROR_RESPONSE );
762
+ EXPOSE_CONST( FS_DIR_CORRUPTED_ERROR_RESPONSE );
763
+ EXPOSE_CONST( FS_INVALID_OFFSET_ERROR_RESPONSE );
764
+ EXPOSE_CONST( FS_BAD_PERMISSIONS_ERROR_RESPONSE );
765
+ EXPOSE_CONST( FS_EOF_REACHED_ERROR_RESPONSE );
766
+ EXPOSE_CONST( FS_INVALID_FILE_HANDLE_ERROR_RESPONSE );
767
+
768
+ EXPOSE_CONST( FS_CRYPTO_OPEN_PERMISSION_ERROR_RESPONSE );
769
+ EXPOSE_CONST( FS_CRYPTO_HANDLE_ALREADY_IN_USE_RESPONSE );
770
+ EXPOSE_CONST( FS_CRYPTO_USER_KEY_NOT_SPECIFIED_RESPONSE );
771
+ EXPOSE_CONST( FS_CRYPTO_USER_KEY_ADD_ERROR_RESPONSE );
772
+ EXPOSE_CONST( FS_CRYPTO_USER_KEY_FETCH_ERROR_RESPONSE );
773
+ EXPOSE_CONST( FS_CRYPTO_IVNONE_READ_ERROR_RESPONSE );
774
+ EXPOSE_CONST( FS_CRYPTO_BLOCK_OFFSET_ERROR_RESPONSE );
775
+ EXPOSE_CONST( FS_CRYPTO_BLOCK_SIZE_ERROR_RESPONSE );
776
+ EXPOSE_CONST( FS_CRYPTO_CFG_TYPE_NOT_SUPPORTED_RESPONSE );
777
+
778
+ EXPOSE_CONST( FS_FIT_FILE_HEADER_ERROR_RESPONSE );
779
+ EXPOSE_CONST( FS_FIT_FILE_SIZE_INTEGRITY_ERROR_RESPONSE );
780
+ EXPOSE_CONST( FS_FIT_FILE_CRC_ERROR_RESPONSE );
781
+ EXPOSE_CONST( FS_FIT_FILE_CHECK_PERMISSION_ERROR_RESPONSE );
782
+ EXPOSE_CONST( FS_FIT_FILE_CHECK_FILE_TYPE_ERROR_RESPONSE );
783
+ EXPOSE_CONST( FS_FIT_FILE_OP_ABORT_ERROR_RESPONSE );
784
+ #undef EXPOSE_CONST
785
+
786
+ init_ant_channel();
787
+ init_ant_message();
788
+
789
+ rant_start_callback_thread();
790
+ }
791
+