tinkerforge 2.1.24 → 2.1.29
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/tinkerforge/brick_dc.rb +156 -75
- data/lib/tinkerforge/brick_hat.rb +69 -31
- data/lib/tinkerforge/brick_hat_zero.rb +55 -23
- data/lib/tinkerforge/brick_imu.rb +185 -78
- data/lib/tinkerforge/brick_imu_v2.rb +209 -106
- data/lib/tinkerforge/brick_master.rb +491 -183
- data/lib/tinkerforge/brick_red.rb +197 -74
- data/lib/tinkerforge/brick_servo.rb +186 -102
- data/lib/tinkerforge/brick_silent_stepper.rb +247 -167
- data/lib/tinkerforge/brick_stepper.rb +211 -99
- data/lib/tinkerforge/bricklet_accelerometer.rb +57 -23
- data/lib/tinkerforge/bricklet_accelerometer_v2.rb +104 -54
- data/lib/tinkerforge/bricklet_air_quality.rb +116 -59
- data/lib/tinkerforge/bricklet_ambient_light.rb +50 -21
- data/lib/tinkerforge/bricklet_ambient_light_v2.rb +44 -24
- data/lib/tinkerforge/bricklet_ambient_light_v3.rb +65 -27
- data/lib/tinkerforge/bricklet_analog_in.rb +62 -25
- data/lib/tinkerforge/bricklet_analog_in_v2.rb +56 -23
- data/lib/tinkerforge/bricklet_analog_in_v3.rb +66 -25
- data/lib/tinkerforge/bricklet_analog_out.rb +22 -9
- data/lib/tinkerforge/bricklet_analog_out_v2.rb +19 -8
- data/lib/tinkerforge/bricklet_analog_out_v3.rb +53 -20
- data/lib/tinkerforge/bricklet_barometer.rb +100 -27
- data/lib/tinkerforge/bricklet_barometer_v2.rb +98 -37
- data/lib/tinkerforge/bricklet_can.rb +83 -19
- data/lib/tinkerforge/bricklet_can_v2.rb +171 -38
- data/lib/tinkerforge/bricklet_co2.rb +33 -14
- data/lib/tinkerforge/bricklet_co2_v2.rb +97 -38
- data/lib/tinkerforge/bricklet_color.rb +68 -27
- data/lib/tinkerforge/bricklet_color_v2.rb +86 -33
- data/lib/tinkerforge/bricklet_compass.rb +77 -30
- data/lib/tinkerforge/bricklet_current12.rb +57 -24
- data/lib/tinkerforge/bricklet_current25.rb +57 -24
- data/lib/tinkerforge/bricklet_dc_v2.rb +521 -0
- data/lib/tinkerforge/bricklet_distance_ir.rb +56 -23
- data/lib/tinkerforge/bricklet_distance_ir_v2.rb +82 -31
- data/lib/tinkerforge/bricklet_distance_us.rb +39 -16
- data/lib/tinkerforge/bricklet_distance_us_v2.rb +66 -25
- data/lib/tinkerforge/bricklet_dmx.rb +87 -34
- data/lib/tinkerforge/bricklet_dual_button.rb +23 -10
- data/lib/tinkerforge/bricklet_dual_button_v2.rb +63 -24
- data/lib/tinkerforge/bricklet_dual_relay.rb +26 -11
- data/lib/tinkerforge/bricklet_dust_detector.rb +39 -16
- data/lib/tinkerforge/bricklet_e_paper_296x128.rb +87 -32
- data/lib/tinkerforge/bricklet_energy_monitor.rb +72 -27
- data/lib/tinkerforge/bricklet_gps.rb +63 -26
- data/lib/tinkerforge/bricklet_gps_v2.rb +116 -47
- data/lib/tinkerforge/bricklet_hall_effect.rb +42 -23
- data/lib/tinkerforge/bricklet_hall_effect_v2.rb +70 -27
- data/lib/tinkerforge/bricklet_humidity.rb +50 -21
- data/lib/tinkerforge/bricklet_humidity_v2.rb +82 -31
- data/lib/tinkerforge/bricklet_imu_v3.rb +784 -0
- data/lib/tinkerforge/bricklet_industrial_analog_out.rb +37 -14
- data/lib/tinkerforge/bricklet_industrial_analog_out_v2.rb +80 -29
- data/lib/tinkerforge/bricklet_industrial_counter.rb +100 -39
- data/lib/tinkerforge/bricklet_industrial_digital_in_4.rb +44 -17
- data/lib/tinkerforge/bricklet_industrial_digital_in_4_v2.rb +76 -29
- data/lib/tinkerforge/bricklet_industrial_digital_out_4.rb +35 -14
- data/lib/tinkerforge/bricklet_industrial_digital_out_4_v2.rb +72 -27
- data/lib/tinkerforge/bricklet_industrial_dual_0_20ma.rb +39 -16
- data/lib/tinkerforge/bricklet_industrial_dual_0_20ma_v2.rb +79 -30
- data/lib/tinkerforge/bricklet_industrial_dual_ac_relay.rb +325 -0
- data/lib/tinkerforge/bricklet_industrial_dual_analog_in.rb +48 -19
- data/lib/tinkerforge/bricklet_industrial_dual_analog_in_v2.rb +137 -31
- data/lib/tinkerforge/bricklet_industrial_dual_relay.rb +60 -23
- data/lib/tinkerforge/bricklet_industrial_ptc.rb +475 -0
- data/lib/tinkerforge/bricklet_industrial_quad_relay.rb +35 -14
- data/lib/tinkerforge/bricklet_industrial_quad_relay_v2.rb +66 -25
- data/lib/tinkerforge/bricklet_io16.rb +54 -21
- data/lib/tinkerforge/bricklet_io16_v2.rb +89 -34
- data/lib/tinkerforge/bricklet_io4.rb +54 -23
- data/lib/tinkerforge/bricklet_io4_v2.rb +95 -36
- data/lib/tinkerforge/bricklet_isolator.rb +72 -29
- data/lib/tinkerforge/bricklet_joystick.rb +58 -25
- data/lib/tinkerforge/bricklet_joystick_v2.rb +67 -26
- data/lib/tinkerforge/bricklet_laser_range_finder.rb +81 -32
- data/lib/tinkerforge/bricklet_laser_range_finder_v2.rb +95 -36
- data/lib/tinkerforge/bricklet_lcd_128x64.rb +191 -70
- data/lib/tinkerforge/bricklet_lcd_16x2.rb +44 -18
- data/lib/tinkerforge/bricklet_lcd_20x4.rb +57 -23
- data/lib/tinkerforge/bricklet_led_strip.rb +59 -22
- data/lib/tinkerforge/bricklet_led_strip_v2.rb +90 -46
- data/lib/tinkerforge/bricklet_line.rb +33 -14
- data/lib/tinkerforge/bricklet_linear_poti.rb +50 -21
- data/lib/tinkerforge/bricklet_linear_poti_v2.rb +54 -21
- data/lib/tinkerforge/bricklet_load_cell.rb +60 -23
- data/lib/tinkerforge/bricklet_load_cell_v2.rb +79 -30
- data/lib/tinkerforge/bricklet_moisture.rb +39 -16
- data/lib/tinkerforge/bricklet_motion_detector.rb +21 -10
- data/lib/tinkerforge/bricklet_motion_detector_v2.rb +61 -27
- data/lib/tinkerforge/bricklet_motorized_linear_poti.rb +70 -27
- data/lib/tinkerforge/bricklet_multi_touch.rb +30 -13
- data/lib/tinkerforge/bricklet_multi_touch_v2.rb +75 -28
- data/lib/tinkerforge/bricklet_nfc.rb +126 -62
- data/lib/tinkerforge/bricklet_nfc_rfid.rb +32 -13
- data/lib/tinkerforge/bricklet_oled_128x64.rb +28 -11
- data/lib/tinkerforge/bricklet_oled_128x64_v2.rb +65 -24
- data/lib/tinkerforge/bricklet_oled_64x48.rb +28 -11
- data/lib/tinkerforge/bricklet_one_wire.rb +65 -24
- data/lib/tinkerforge/bricklet_outdoor_weather.rb +71 -28
- data/lib/tinkerforge/bricklet_particulate_matter.rb +74 -30
- data/lib/tinkerforge/bricklet_performance_dc.rb +682 -0
- data/lib/tinkerforge/bricklet_piezo_buzzer.rb +18 -9
- data/lib/tinkerforge/bricklet_piezo_speaker.rb +21 -10
- data/lib/tinkerforge/bricklet_piezo_speaker_v2.rb +79 -42
- data/lib/tinkerforge/bricklet_ptc.rb +73 -42
- data/lib/tinkerforge/bricklet_ptc_v2.rb +94 -48
- data/lib/tinkerforge/bricklet_real_time_clock.rb +44 -33
- data/lib/tinkerforge/bricklet_real_time_clock_v2.rb +77 -44
- data/lib/tinkerforge/bricklet_remote_switch.rb +38 -29
- data/lib/tinkerforge/bricklet_remote_switch_v2.rb +86 -49
- data/lib/tinkerforge/bricklet_rgb_led.rb +17 -8
- data/lib/tinkerforge/bricklet_rgb_led_button.rb +61 -30
- data/lib/tinkerforge/bricklet_rgb_led_matrix.rb +78 -33
- data/lib/tinkerforge/bricklet_rgb_led_v2.rb +51 -20
- data/lib/tinkerforge/bricklet_rotary_encoder.rb +38 -19
- data/lib/tinkerforge/bricklet_rotary_encoder_v2.rb +59 -24
- data/lib/tinkerforge/bricklet_rotary_poti.rb +52 -28
- data/lib/tinkerforge/bricklet_rotary_poti_v2.rb +56 -23
- data/lib/tinkerforge/bricklet_rs232.rb +89 -28
- data/lib/tinkerforge/bricklet_rs232_v2.rb +117 -44
- data/lib/tinkerforge/bricklet_rs485.rb +222 -95
- data/lib/tinkerforge/bricklet_segment_display_4x7.rb +24 -14
- data/lib/tinkerforge/bricklet_segment_display_4x7_v2.rb +74 -35
- data/lib/tinkerforge/bricklet_servo_v2.rb +565 -0
- data/lib/tinkerforge/bricklet_silent_stepper_v2.rb +1024 -0
- data/lib/tinkerforge/bricklet_solid_state_relay.rb +24 -13
- data/lib/tinkerforge/bricklet_solid_state_relay_v2.rb +58 -25
- data/lib/tinkerforge/bricklet_sound_intensity.rb +34 -18
- data/lib/tinkerforge/bricklet_sound_pressure_level.rb +71 -31
- data/lib/tinkerforge/bricklet_temperature.rb +39 -16
- data/lib/tinkerforge/bricklet_temperature_ir.rb +56 -23
- data/lib/tinkerforge/bricklet_temperature_ir_v2.rb +70 -27
- data/lib/tinkerforge/bricklet_temperature_v2.rb +60 -25
- data/lib/tinkerforge/bricklet_thermal_imaging.rb +104 -44
- data/lib/tinkerforge/bricklet_thermocouple.rb +44 -24
- data/lib/tinkerforge/bricklet_thermocouple_v2.rb +64 -27
- data/lib/tinkerforge/bricklet_tilt.rb +23 -10
- data/lib/tinkerforge/bricklet_uv_light.rb +35 -18
- data/lib/tinkerforge/bricklet_uv_light_v2.rb +84 -37
- data/lib/tinkerforge/bricklet_voltage.rb +51 -28
- data/lib/tinkerforge/bricklet_voltage_current.rb +90 -73
- data/lib/tinkerforge/bricklet_voltage_current_v2.rb +89 -68
- data/lib/tinkerforge/bricklet_xmc1400_breakout.rb +79 -30
- data/lib/tinkerforge/device_display_names.rb +170 -0
- data/lib/tinkerforge/ip_connection.rb +153 -33
- data/lib/tinkerforge/version.rb +1 -1
- metadata +11 -3
@@ -1,14 +1,16 @@
|
|
1
1
|
# -*- ruby encoding: utf-8 -*-
|
2
2
|
#############################################################
|
3
|
-
# This file was automatically generated on
|
3
|
+
# This file was automatically generated on 2021-05-06. #
|
4
4
|
# #
|
5
|
-
# Ruby Bindings Version 2.1.
|
5
|
+
# Ruby Bindings Version 2.1.29 #
|
6
6
|
# #
|
7
7
|
# If you have a bugfix for this file and want to commit it, #
|
8
8
|
# please fix the bug in the generator. You can find a link #
|
9
9
|
# to the generators git repository on tinkerforge.com #
|
10
10
|
#############################################################
|
11
11
|
|
12
|
+
require_relative './ip_connection'
|
13
|
+
|
12
14
|
module Tinkerforge
|
13
15
|
# Breakout for Infineon XMC1400 microcontroller
|
14
16
|
class BrickletXMC1400Breakout < Device
|
@@ -87,7 +89,7 @@ module Tinkerforge
|
|
87
89
|
# Creates an object with the unique device ID <tt>uid</tt> and adds it to
|
88
90
|
# the IP Connection <tt>ipcon</tt>.
|
89
91
|
def initialize(uid, ipcon)
|
90
|
-
super uid, ipcon
|
92
|
+
super uid, ipcon, DEVICE_IDENTIFIER, DEVICE_DISPLAY_NAME
|
91
93
|
|
92
94
|
@api_version = [2, 0, 0]
|
93
95
|
|
@@ -115,21 +117,26 @@ module Tinkerforge
|
|
115
117
|
@response_expected[FUNCTION_READ_UID] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
116
118
|
@response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
117
119
|
|
118
|
-
@callback_formats[CALLBACK_ADC_VALUES] = 'S8'
|
119
|
-
@callback_formats[CALLBACK_COUNT] = 'L'
|
120
|
+
@callback_formats[CALLBACK_ADC_VALUES] = [24, 'S8']
|
121
|
+
@callback_formats[CALLBACK_COUNT] = [12, 'L']
|
120
122
|
|
123
|
+
@ipcon.add_device self
|
121
124
|
end
|
122
125
|
|
123
126
|
# Example for a setter function. The values are the values that can be given to
|
124
127
|
# the XMC_GPIO_Init function. See communication.c in the firmware.
|
125
128
|
def set_gpio_config(port, pin, mode, input_hysteresis, output_level)
|
126
|
-
|
129
|
+
check_validity
|
130
|
+
|
131
|
+
send_request FUNCTION_SET_GPIO_CONFIG, [port, pin, mode, input_hysteresis, output_level], 'C C C C ?', 8, ''
|
127
132
|
end
|
128
133
|
|
129
134
|
# Example for a getter function. Returns the result of a
|
130
135
|
# XMC_GPIO_GetInput call for the given port/pin.
|
131
136
|
def get_gpio_input(port, pin)
|
132
|
-
|
137
|
+
check_validity
|
138
|
+
|
139
|
+
send_request FUNCTION_GET_GPIO_INPUT, [port, pin], 'C C', 9, '?'
|
133
140
|
end
|
134
141
|
|
135
142
|
# Enables a ADC channel for the ADC driver example (adc.c/adc.h).
|
@@ -145,17 +152,23 @@ module Tinkerforge
|
|
145
152
|
# * Channel 6: P2_1
|
146
153
|
# * Channel 7: P2_2
|
147
154
|
def set_adc_channel_config(channel, enable)
|
148
|
-
|
155
|
+
check_validity
|
156
|
+
|
157
|
+
send_request FUNCTION_SET_ADC_CHANNEL_CONFIG, [channel, enable], 'C ?', 8, ''
|
149
158
|
end
|
150
159
|
|
151
160
|
# Returns the config for the given channel as set by BrickletXMC1400Breakout#set_adc_channel_config.
|
152
161
|
def get_adc_channel_config(channel)
|
153
|
-
|
162
|
+
check_validity
|
163
|
+
|
164
|
+
send_request FUNCTION_GET_ADC_CHANNEL_CONFIG, [channel], 'C', 9, '?'
|
154
165
|
end
|
155
166
|
|
156
167
|
# Returns the 12-bit value of the given ADC channel of the ADC driver example.
|
157
168
|
def get_adc_channel_value(channel)
|
158
|
-
|
169
|
+
check_validity
|
170
|
+
|
171
|
+
send_request FUNCTION_GET_ADC_CHANNEL_VALUE, [channel], 'C', 10, 'S'
|
159
172
|
end
|
160
173
|
|
161
174
|
# Returns the values for all 8 ADC channels of the adc driver example.
|
@@ -164,7 +177,9 @@ module Tinkerforge
|
|
164
177
|
#
|
165
178
|
# See BrickletXMC1400Breakout#set_adc_values_callback_configuration and CALLBACK_ADC_VALUES callback.
|
166
179
|
def get_adc_values
|
167
|
-
|
180
|
+
check_validity
|
181
|
+
|
182
|
+
send_request FUNCTION_GET_ADC_VALUES, [], '', 24, 'S8'
|
168
183
|
end
|
169
184
|
|
170
185
|
# The period is the period with which the CALLBACK_ADC_VALUES
|
@@ -177,13 +192,17 @@ module Tinkerforge
|
|
177
192
|
# If it is set to false, the callback is continuously triggered with the period,
|
178
193
|
# independent of the value.
|
179
194
|
def set_adc_values_callback_configuration(period, value_has_to_change)
|
180
|
-
|
195
|
+
check_validity
|
196
|
+
|
197
|
+
send_request FUNCTION_SET_ADC_VALUES_CALLBACK_CONFIGURATION, [period, value_has_to_change], 'L ?', 8, ''
|
181
198
|
end
|
182
199
|
|
183
200
|
# Returns the callback configuration as set by
|
184
201
|
# BrickletXMC1400Breakout#set_adc_values_callback_configuration.
|
185
202
|
def get_adc_values_callback_configuration
|
186
|
-
|
203
|
+
check_validity
|
204
|
+
|
205
|
+
send_request FUNCTION_GET_ADC_VALUES_CALLBACK_CONFIGURATION, [], '', 13, 'L ?'
|
187
206
|
end
|
188
207
|
|
189
208
|
# Returns the value of the example count (see example.c).
|
@@ -197,7 +216,9 @@ module Tinkerforge
|
|
197
216
|
# CALLBACK_COUNT callback. You can set the callback configuration
|
198
217
|
# with BrickletXMC1400Breakout#set_count_callback_configuration.
|
199
218
|
def get_count
|
200
|
-
|
219
|
+
check_validity
|
220
|
+
|
221
|
+
send_request FUNCTION_GET_COUNT, [], '', 12, 'L'
|
201
222
|
end
|
202
223
|
|
203
224
|
# The period is the period with which the CALLBACK_COUNT callback is triggered
|
@@ -226,12 +247,16 @@ module Tinkerforge
|
|
226
247
|
#
|
227
248
|
# If the option is set to 'x' (threshold turned off) the callback is triggered with the fixed period.
|
228
249
|
def set_count_callback_configuration(period, value_has_to_change, option, min, max)
|
229
|
-
|
250
|
+
check_validity
|
251
|
+
|
252
|
+
send_request FUNCTION_SET_COUNT_CALLBACK_CONFIGURATION, [period, value_has_to_change, option, min, max], 'L ? k L L', 8, ''
|
230
253
|
end
|
231
254
|
|
232
255
|
# Returns the callback configuration as set by BrickletXMC1400Breakout#set_count_callback_configuration.
|
233
256
|
def get_count_callback_configuration
|
234
|
-
|
257
|
+
check_validity
|
258
|
+
|
259
|
+
send_request FUNCTION_GET_COUNT_CALLBACK_CONFIGURATION, [], '', 22, 'L ? k L L'
|
235
260
|
end
|
236
261
|
|
237
262
|
# Returns the error count for the communication between Brick and Bricklet.
|
@@ -246,7 +271,9 @@ module Tinkerforge
|
|
246
271
|
# The errors counts are for errors that occur on the Bricklet side. All
|
247
272
|
# Bricks have a similar function that returns the errors on the Brick side.
|
248
273
|
def get_spitfp_error_count
|
249
|
-
|
274
|
+
check_validity
|
275
|
+
|
276
|
+
send_request FUNCTION_GET_SPITFP_ERROR_COUNT, [], '', 24, 'L L L L'
|
250
277
|
end
|
251
278
|
|
252
279
|
# Sets the bootloader mode and returns the status after the requested
|
@@ -259,12 +286,16 @@ module Tinkerforge
|
|
259
286
|
# This function is used by Brick Viewer during flashing. It should not be
|
260
287
|
# necessary to call it in a normal user program.
|
261
288
|
def set_bootloader_mode(mode)
|
262
|
-
|
289
|
+
check_validity
|
290
|
+
|
291
|
+
send_request FUNCTION_SET_BOOTLOADER_MODE, [mode], 'C', 9, 'C'
|
263
292
|
end
|
264
293
|
|
265
294
|
# Returns the current bootloader mode, see BrickletXMC1400Breakout#set_bootloader_mode.
|
266
295
|
def get_bootloader_mode
|
267
|
-
|
296
|
+
check_validity
|
297
|
+
|
298
|
+
send_request FUNCTION_GET_BOOTLOADER_MODE, [], '', 9, 'C'
|
268
299
|
end
|
269
300
|
|
270
301
|
# Sets the firmware pointer for BrickletXMC1400Breakout#write_firmware. The pointer has
|
@@ -274,7 +305,9 @@ module Tinkerforge
|
|
274
305
|
# This function is used by Brick Viewer during flashing. It should not be
|
275
306
|
# necessary to call it in a normal user program.
|
276
307
|
def set_write_firmware_pointer(pointer)
|
277
|
-
|
308
|
+
check_validity
|
309
|
+
|
310
|
+
send_request FUNCTION_SET_WRITE_FIRMWARE_POINTER, [pointer], 'L', 8, ''
|
278
311
|
end
|
279
312
|
|
280
313
|
# Writes 64 Bytes of firmware at the position as written by
|
@@ -286,7 +319,9 @@ module Tinkerforge
|
|
286
319
|
# This function is used by Brick Viewer during flashing. It should not be
|
287
320
|
# necessary to call it in a normal user program.
|
288
321
|
def write_firmware(data)
|
289
|
-
|
322
|
+
check_validity
|
323
|
+
|
324
|
+
send_request FUNCTION_WRITE_FIRMWARE, [data], 'C64', 9, 'C'
|
290
325
|
end
|
291
326
|
|
292
327
|
# Sets the status LED configuration. By default the LED shows
|
@@ -297,22 +332,28 @@ module Tinkerforge
|
|
297
332
|
#
|
298
333
|
# If the Bricklet is in bootloader mode, the LED is will show heartbeat by default.
|
299
334
|
def set_status_led_config(config)
|
300
|
-
|
335
|
+
check_validity
|
336
|
+
|
337
|
+
send_request FUNCTION_SET_STATUS_LED_CONFIG, [config], 'C', 8, ''
|
301
338
|
end
|
302
339
|
|
303
340
|
# Returns the configuration as set by BrickletXMC1400Breakout#set_status_led_config
|
304
341
|
def get_status_led_config
|
305
|
-
|
342
|
+
check_validity
|
343
|
+
|
344
|
+
send_request FUNCTION_GET_STATUS_LED_CONFIG, [], '', 9, 'C'
|
306
345
|
end
|
307
346
|
|
308
|
-
# Returns the temperature
|
347
|
+
# Returns the temperature as measured inside the microcontroller. The
|
309
348
|
# value returned is not the ambient temperature!
|
310
349
|
#
|
311
350
|
# The temperature is only proportional to the real temperature and it has bad
|
312
351
|
# accuracy. Practically it is only useful as an indicator for
|
313
352
|
# temperature changes.
|
314
353
|
def get_chip_temperature
|
315
|
-
|
354
|
+
check_validity
|
355
|
+
|
356
|
+
send_request FUNCTION_GET_CHIP_TEMPERATURE, [], '', 10, 's'
|
316
357
|
end
|
317
358
|
|
318
359
|
# Calling this function will reset the Bricklet. All configurations
|
@@ -322,7 +363,9 @@ module Tinkerforge
|
|
322
363
|
# calling functions on the existing ones will result in
|
323
364
|
# undefined behavior!
|
324
365
|
def reset
|
325
|
-
|
366
|
+
check_validity
|
367
|
+
|
368
|
+
send_request FUNCTION_RESET, [], '', 8, ''
|
326
369
|
end
|
327
370
|
|
328
371
|
# Writes a new UID into flash. If you want to set a new UID
|
@@ -331,25 +374,31 @@ module Tinkerforge
|
|
331
374
|
#
|
332
375
|
# We recommend that you use Brick Viewer to change the UID.
|
333
376
|
def write_uid(uid)
|
334
|
-
|
377
|
+
check_validity
|
378
|
+
|
379
|
+
send_request FUNCTION_WRITE_UID, [uid], 'L', 8, ''
|
335
380
|
end
|
336
381
|
|
337
382
|
# Returns the current UID as an integer. Encode as
|
338
383
|
# Base58 to get the usual string version.
|
339
384
|
def read_uid
|
340
|
-
|
385
|
+
check_validity
|
386
|
+
|
387
|
+
send_request FUNCTION_READ_UID, [], '', 12, 'L'
|
341
388
|
end
|
342
389
|
|
343
390
|
# Returns the UID, the UID where the Bricklet is connected to,
|
344
391
|
# the position, the hardware and firmware version as well as the
|
345
392
|
# device identifier.
|
346
393
|
#
|
347
|
-
# The position can be 'a', 'b', 'c' or '
|
394
|
+
# The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port).
|
395
|
+
# A Bricklet connected to an :ref:`Isolator Bricklet <isolator_bricklet>` is always at
|
396
|
+
# position 'z'.
|
348
397
|
#
|
349
398
|
# The device identifier numbers can be found :ref:`here <device_identifier>`.
|
350
399
|
# |device_identifier_constant|
|
351
400
|
def get_identity
|
352
|
-
send_request FUNCTION_GET_IDENTITY, [], '',
|
401
|
+
send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S'
|
353
402
|
end
|
354
403
|
|
355
404
|
# Registers a callback with ID <tt>id</tt> to the block <tt>block</tt>.
|
@@ -0,0 +1,170 @@
|
|
1
|
+
# -*- ruby encoding: utf-8 -*-
|
2
|
+
#############################################################
|
3
|
+
# This file was automatically generated on 2021-05-06. #
|
4
|
+
# #
|
5
|
+
# Ruby Bindings Version 2.1.29 #
|
6
|
+
# #
|
7
|
+
# If you have a bugfix for this file and want to commit it, #
|
8
|
+
# please fix the bug in the generator. You can find a link #
|
9
|
+
# to the generators git repository on tinkerforge.com #
|
10
|
+
#############################################################
|
11
|
+
|
12
|
+
module Tinkerforge
|
13
|
+
DEVICE_DISPLAY_NAMES = {
|
14
|
+
11 => 'DC Brick',
|
15
|
+
13 => 'Master Brick',
|
16
|
+
14 => 'Servo Brick',
|
17
|
+
15 => 'Stepper Brick',
|
18
|
+
16 => 'IMU Brick',
|
19
|
+
17 => 'RED Brick',
|
20
|
+
18 => 'IMU Brick 2.0',
|
21
|
+
19 => 'Silent Stepper Brick',
|
22
|
+
21 => 'Ambient Light Bricklet',
|
23
|
+
23 => 'Current12 Bricklet',
|
24
|
+
24 => 'Current25 Bricklet',
|
25
|
+
25 => 'Distance IR Bricklet',
|
26
|
+
26 => 'Dual Relay Bricklet',
|
27
|
+
27 => 'Humidity Bricklet',
|
28
|
+
28 => 'IO-16 Bricklet',
|
29
|
+
29 => 'IO-4 Bricklet',
|
30
|
+
111 => 'HAT Brick',
|
31
|
+
112 => 'HAT Zero Brick',
|
32
|
+
210 => 'Joystick Bricklet',
|
33
|
+
211 => 'LCD 16x2 Bricklet',
|
34
|
+
212 => 'LCD 20x4 Bricklet',
|
35
|
+
213 => 'Linear Poti Bricklet',
|
36
|
+
214 => 'Piezo Buzzer Bricklet',
|
37
|
+
215 => 'Rotary Poti Bricklet',
|
38
|
+
216 => 'Temperature Bricklet',
|
39
|
+
217 => 'Temperature IR Bricklet',
|
40
|
+
218 => 'Voltage Bricklet',
|
41
|
+
219 => 'Analog In Bricklet',
|
42
|
+
220 => 'Analog Out Bricklet',
|
43
|
+
221 => 'Barometer Bricklet',
|
44
|
+
222 => 'GPS Bricklet',
|
45
|
+
223 => 'Industrial Digital In 4 Bricklet',
|
46
|
+
224 => 'Industrial Digital Out 4 Bricklet',
|
47
|
+
225 => 'Industrial Quad Relay Bricklet',
|
48
|
+
226 => 'PTC Bricklet',
|
49
|
+
227 => 'Voltage/Current Bricklet',
|
50
|
+
228 => 'Industrial Dual 0-20mA Bricklet',
|
51
|
+
229 => 'Distance US Bricklet',
|
52
|
+
230 => 'Dual Button Bricklet',
|
53
|
+
231 => 'LED Strip Bricklet',
|
54
|
+
232 => 'Moisture Bricklet',
|
55
|
+
233 => 'Motion Detector Bricklet',
|
56
|
+
234 => 'Multi Touch Bricklet',
|
57
|
+
235 => 'Remote Switch Bricklet',
|
58
|
+
236 => 'Rotary Encoder Bricklet',
|
59
|
+
237 => 'Segment Display 4x7 Bricklet',
|
60
|
+
238 => 'Sound Intensity Bricklet',
|
61
|
+
239 => 'Tilt Bricklet',
|
62
|
+
240 => 'Hall Effect Bricklet',
|
63
|
+
241 => 'Line Bricklet',
|
64
|
+
242 => 'Piezo Speaker Bricklet',
|
65
|
+
243 => 'Color Bricklet',
|
66
|
+
244 => 'Solid State Relay Bricklet',
|
67
|
+
246 => 'NFC/RFID Bricklet',
|
68
|
+
249 => 'Industrial Dual Analog In Bricklet',
|
69
|
+
250 => 'Accelerometer Bricklet',
|
70
|
+
251 => 'Analog In Bricklet 2.0',
|
71
|
+
253 => 'Load Cell Bricklet',
|
72
|
+
254 => 'RS232 Bricklet',
|
73
|
+
255 => 'Laser Range Finder Bricklet',
|
74
|
+
256 => 'Analog Out Bricklet 2.0',
|
75
|
+
258 => 'Industrial Analog Out Bricklet',
|
76
|
+
259 => 'Ambient Light Bricklet 2.0',
|
77
|
+
260 => 'Dust Detector Bricklet',
|
78
|
+
262 => 'CO2 Bricklet',
|
79
|
+
263 => 'OLED 128x64 Bricklet',
|
80
|
+
264 => 'OLED 64x48 Bricklet',
|
81
|
+
265 => 'UV Light Bricklet',
|
82
|
+
266 => 'Thermocouple Bricklet',
|
83
|
+
267 => 'Motorized Linear Poti Bricklet',
|
84
|
+
268 => 'Real-Time Clock Bricklet',
|
85
|
+
270 => 'CAN Bricklet',
|
86
|
+
271 => 'RGB LED Bricklet',
|
87
|
+
272 => 'RGB LED Matrix Bricklet',
|
88
|
+
276 => 'GPS Bricklet 2.0',
|
89
|
+
277 => 'RS485 Bricklet',
|
90
|
+
278 => 'Thermal Imaging Bricklet',
|
91
|
+
279 => 'XMC1400 Breakout Bricklet',
|
92
|
+
282 => 'RGB LED Button Bricklet',
|
93
|
+
283 => 'Humidity Bricklet 2.0',
|
94
|
+
284 => 'Industrial Dual Relay Bricklet',
|
95
|
+
285 => 'DMX Bricklet',
|
96
|
+
286 => 'NFC Bricklet',
|
97
|
+
288 => 'Outdoor Weather Bricklet',
|
98
|
+
289 => 'Remote Switch Bricklet 2.0',
|
99
|
+
290 => 'Sound Pressure Level Bricklet',
|
100
|
+
291 => 'Temperature IR Bricklet 2.0',
|
101
|
+
292 => 'Motion Detector Bricklet 2.0',
|
102
|
+
293 => 'Industrial Counter Bricklet',
|
103
|
+
294 => 'Rotary Encoder Bricklet 2.0',
|
104
|
+
295 => 'Analog In Bricklet 3.0',
|
105
|
+
296 => 'Solid State Relay Bricklet 2.0',
|
106
|
+
297 => 'Air Quality Bricklet',
|
107
|
+
298 => 'LCD 128x64 Bricklet',
|
108
|
+
299 => 'Distance US Bricklet 2.0',
|
109
|
+
2100 => 'Industrial Digital In 4 Bricklet 2.0',
|
110
|
+
2101 => 'PTC Bricklet 2.0',
|
111
|
+
2102 => 'Industrial Quad Relay Bricklet 2.0',
|
112
|
+
2103 => 'LED Strip Bricklet 2.0',
|
113
|
+
2104 => 'Load Cell Bricklet 2.0',
|
114
|
+
2105 => 'Voltage/Current Bricklet 2.0',
|
115
|
+
2106 => 'Real-Time Clock Bricklet 2.0',
|
116
|
+
2107 => 'CAN Bricklet 2.0',
|
117
|
+
2108 => 'RS232 Bricklet 2.0',
|
118
|
+
2109 => 'Thermocouple Bricklet 2.0',
|
119
|
+
2110 => 'Particulate Matter Bricklet',
|
120
|
+
2111 => 'IO-4 Bricklet 2.0',
|
121
|
+
2112 => 'OLED 128x64 Bricklet 2.0',
|
122
|
+
2113 => 'Temperature Bricklet 2.0',
|
123
|
+
2114 => 'IO-16 Bricklet 2.0',
|
124
|
+
2115 => 'Analog Out Bricklet 3.0',
|
125
|
+
2116 => 'Industrial Analog Out Bricklet 2.0',
|
126
|
+
2117 => 'Barometer Bricklet 2.0',
|
127
|
+
2118 => 'UV Light Bricklet 2.0',
|
128
|
+
2119 => 'Dual Button Bricklet 2.0',
|
129
|
+
2120 => 'Industrial Dual 0-20mA Bricklet 2.0',
|
130
|
+
2121 => 'Industrial Dual Analog In Bricklet 2.0',
|
131
|
+
2122 => 'Isolator Bricklet',
|
132
|
+
2123 => 'One Wire Bricklet',
|
133
|
+
2124 => 'Industrial Digital Out 4 Bricklet 2.0',
|
134
|
+
2125 => 'Distance IR Bricklet 2.0',
|
135
|
+
2127 => 'RGB LED Bricklet 2.0',
|
136
|
+
2128 => 'Color Bricklet 2.0',
|
137
|
+
2129 => 'Multi Touch Bricklet 2.0',
|
138
|
+
2130 => 'Accelerometer Bricklet 2.0',
|
139
|
+
2131 => 'Ambient Light Bricklet 3.0',
|
140
|
+
2132 => 'Hall Effect Bricklet 2.0',
|
141
|
+
2137 => 'Segment Display 4x7 Bricklet 2.0',
|
142
|
+
2138 => 'Joystick Bricklet 2.0',
|
143
|
+
2139 => 'Linear Poti Bricklet 2.0',
|
144
|
+
2140 => 'Rotary Poti Bricklet 2.0',
|
145
|
+
2144 => 'Laser Range Finder Bricklet 2.0',
|
146
|
+
2145 => 'Piezo Speaker Bricklet 2.0',
|
147
|
+
2146 => 'E-Paper 296x128 Bricklet',
|
148
|
+
2147 => 'CO2 Bricklet 2.0',
|
149
|
+
2152 => 'Energy Monitor Bricklet',
|
150
|
+
2153 => 'Compass Bricklet',
|
151
|
+
2156 => 'Performance DC Bricklet',
|
152
|
+
2157 => 'Servo Bricklet 2.0',
|
153
|
+
2161 => 'IMU Bricklet 3.0',
|
154
|
+
2162 => 'Industrial Dual AC Relay Bricklet',
|
155
|
+
2164 => 'Industrial PTC Bricklet',
|
156
|
+
2165 => 'DC Bricklet 2.0',
|
157
|
+
2166 => 'Silent Stepper Bricklet 2.0'
|
158
|
+
}
|
159
|
+
|
160
|
+
# internal
|
161
|
+
def get_device_display_name(device_identifier)
|
162
|
+
device_display_name = DEVICE_DISPLAY_NAMES[device_identifier]
|
163
|
+
|
164
|
+
if device_display_name == nil
|
165
|
+
device_display_name = "Unknown Device [#{device_identifier}]"
|
166
|
+
end
|
167
|
+
|
168
|
+
device_display_name
|
169
|
+
end
|
170
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# -*- ruby encoding: utf-8 -*-
|
2
|
-
# Copyright (C) 2012-2014, 2019 Matthias Bolte <matthias@tinkerforge.com>
|
2
|
+
# Copyright (C) 2012-2014, 2019-2020 Matthias Bolte <matthias@tinkerforge.com>
|
3
3
|
#
|
4
4
|
# Redistribution and use in source and binary forms of this file,
|
5
5
|
# with or without modification, are permitted. See the Creative
|
@@ -10,8 +10,10 @@ require 'thread'
|
|
10
10
|
require 'timeout'
|
11
11
|
require 'securerandom'
|
12
12
|
require 'openssl'
|
13
|
+
require_relative './device_display_names'
|
13
14
|
|
14
15
|
module Tinkerforge
|
16
|
+
# internal
|
15
17
|
class Base58
|
16
18
|
ALPHABET = '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ'
|
17
19
|
|
@@ -64,6 +66,16 @@ module Tinkerforge
|
|
64
66
|
class StreamOutOfSyncException < TinkerforgeException
|
65
67
|
end
|
66
68
|
|
69
|
+
class WrongDeviceTypeException < TinkerforgeException
|
70
|
+
end
|
71
|
+
|
72
|
+
class DeviceReplacedException < TinkerforgeException
|
73
|
+
end
|
74
|
+
|
75
|
+
class WrongResponseLengthException < TinkerforgeException
|
76
|
+
end
|
77
|
+
|
78
|
+
# internal
|
67
79
|
class Packer
|
68
80
|
def self.pack(unpacked, format)
|
69
81
|
data = ''
|
@@ -131,7 +143,8 @@ module Tinkerforge
|
|
131
143
|
u = []
|
132
144
|
|
133
145
|
if f0 == '?'
|
134
|
-
|
146
|
+
n1 = (Integer(f1) / 8.0).ceil()
|
147
|
+
r = data.unpack "C#{n1}a*"
|
135
148
|
data = r[-1]
|
136
149
|
r.delete_at(-1)
|
137
150
|
|
@@ -207,12 +220,18 @@ module Tinkerforge
|
|
207
220
|
end
|
208
221
|
end
|
209
222
|
|
223
|
+
# internal
|
210
224
|
class Device
|
225
|
+
DEVICE_IDENTIFIER_CHECK_PENDING = 0
|
226
|
+
DEVICE_IDENTIFIER_CHECK_MATCH = 1
|
227
|
+
DEVICE_IDENTIFIER_CHECK_MISMATCH = 2
|
228
|
+
|
211
229
|
RESPONSE_EXPECTED_INVALID_FUNCTION_ID = 0
|
212
230
|
RESPONSE_EXPECTED_ALWAYS_TRUE = 1 # getter
|
213
231
|
RESPONSE_EXPECTED_TRUE = 2 # setter
|
214
232
|
RESPONSE_EXPECTED_FALSE = 3 # setter, default
|
215
233
|
|
234
|
+
attr_accessor :replaced
|
216
235
|
attr_accessor :uid
|
217
236
|
attr_accessor :expected_response_function_id
|
218
237
|
attr_accessor :expected_response_sequence_number
|
@@ -220,10 +239,11 @@ module Tinkerforge
|
|
220
239
|
attr_accessor :high_level_callbacks
|
221
240
|
attr_accessor :registered_callbacks
|
222
241
|
|
223
|
-
#
|
224
|
-
|
225
|
-
|
242
|
+
# internal
|
243
|
+
def initialize(uid, ipcon, device_identifier, device_display_name)
|
244
|
+
@replaced = false
|
226
245
|
@uid = Base58.decode uid
|
246
|
+
@uid_string = uid
|
227
247
|
|
228
248
|
if @uid > (1 << 64) - 1
|
229
249
|
raise ArgumentError, "UID '#{uid}' is too big"
|
@@ -249,6 +269,12 @@ module Tinkerforge
|
|
249
269
|
|
250
270
|
@ipcon = ipcon
|
251
271
|
|
272
|
+
@device_identifier = device_identifier
|
273
|
+
@device_display_name = device_display_name
|
274
|
+
@device_identifier_lock = Mutex.new
|
275
|
+
@device_identifier_check = DEVICE_IDENTIFIER_CHECK_PENDING # protected by device_identifier_lock
|
276
|
+
@wrong_device_display_name = '?' # protected by device_identifier_lock
|
277
|
+
|
252
278
|
@request_mutex = Mutex.new
|
253
279
|
|
254
280
|
@response_expected = Array.new(256, RESPONSE_EXPECTED_INVALID_FUNCTION_ID)
|
@@ -265,8 +291,6 @@ module Tinkerforge
|
|
265
291
|
@callback_formats = {}
|
266
292
|
@high_level_callbacks = {}
|
267
293
|
@registered_callbacks = {}
|
268
|
-
|
269
|
-
@ipcon.devices[@uid] = self # FIXME: use a weakref here
|
270
294
|
end
|
271
295
|
|
272
296
|
# Returns the API version (major, minor, revision) of the bindings for
|
@@ -288,7 +312,7 @@ module Tinkerforge
|
|
288
312
|
# Enabling the response expected flag for a setter function allows to
|
289
313
|
# detect timeouts and other error conditions calls of this setter as
|
290
314
|
# well. The device will then send a response for this purpose. If this
|
291
|
-
# flag is disabled for a setter function then no response is
|
315
|
+
# flag is disabled for a setter function then no response is sent and
|
292
316
|
# errors are silently ignored, because they cannot be detected.
|
293
317
|
def get_response_expected(function_id)
|
294
318
|
if function_id < 0 or function_id > 255
|
@@ -317,7 +341,7 @@ module Tinkerforge
|
|
317
341
|
# Enabling the response expected flag for a setter function allows to
|
318
342
|
# detect timeouts and other error conditions calls of this setter as
|
319
343
|
# well. The device will then send a response for this purpose. If this
|
320
|
-
# flag is disabled for a setter function then no response is
|
344
|
+
# flag is disabled for a setter function then no response is sent and
|
321
345
|
# errors are silently ignored, because they cannot be detected.
|
322
346
|
def set_response_expected(function_id, response_expected)
|
323
347
|
if function_id < 0 or function_id > 255
|
@@ -360,7 +384,7 @@ module Tinkerforge
|
|
360
384
|
|
361
385
|
# internal
|
362
386
|
def send_request(function_id, request_data, request_format,
|
363
|
-
|
387
|
+
expected_response_length, response_format)
|
364
388
|
response = nil
|
365
389
|
|
366
390
|
if request_data.length > 0
|
@@ -402,7 +426,13 @@ module Tinkerforge
|
|
402
426
|
error_code = Packer.get_error_code_from_data packet
|
403
427
|
|
404
428
|
if error_code == 0
|
405
|
-
|
429
|
+
if expected_response_length == 0
|
430
|
+
expected_response_length = 8 # setter with response-expected enabled
|
431
|
+
end
|
432
|
+
|
433
|
+
if packet.length != expected_response_length
|
434
|
+
raise WrongResponseLengthException, "Expected response of #{expected_response_length} byte for function ID #{function_id}, got #{packet.length} byte instead"
|
435
|
+
end
|
406
436
|
elsif error_code == 1
|
407
437
|
raise InvalidParameterException, "Got invalid parameter for function ID #{function_id}"
|
408
438
|
elsif error_code == 2
|
@@ -411,7 +441,7 @@ module Tinkerforge
|
|
411
441
|
raise UnknownErrorCodeException, "Function ID #{function_id} returned an unknown error"
|
412
442
|
end
|
413
443
|
|
414
|
-
if
|
444
|
+
if response_format.length > 0
|
415
445
|
response = Packer.unpack packet[8..-1], response_format
|
416
446
|
|
417
447
|
if response.length == 1
|
@@ -449,6 +479,34 @@ module Tinkerforge
|
|
449
479
|
|
450
480
|
response
|
451
481
|
end
|
482
|
+
|
483
|
+
# internal
|
484
|
+
def check_validity()
|
485
|
+
if @replaced
|
486
|
+
raise DeviceReplacedException, 'Device has been replaced'
|
487
|
+
end
|
488
|
+
|
489
|
+
if @device_identifier_check == DEVICE_IDENTIFIER_CHECK_MATCH
|
490
|
+
return
|
491
|
+
end
|
492
|
+
|
493
|
+
@device_identifier_lock.synchronize {
|
494
|
+
if @device_identifier_check == DEVICE_IDENTIFIER_CHECK_PENDING
|
495
|
+
device_identifier = send_request(255, [], '', 33, 'Z8 Z8 k C3 C3 S')[5] # <device>.get_identity
|
496
|
+
|
497
|
+
if device_identifier == @device_identifier
|
498
|
+
@device_identifier_check = DEVICE_IDENTIFIER_CHECK_MATCH
|
499
|
+
else
|
500
|
+
@device_identifier_check = DEVICE_IDENTIFIER_CHECK_MISMATCH
|
501
|
+
@wrong_device_display_name = get_device_display_name device_identifier
|
502
|
+
end
|
503
|
+
end
|
504
|
+
|
505
|
+
if @device_identifier_check == DEVICE_IDENTIFIER_CHECK_MISMATCH
|
506
|
+
raise WrongDeviceTypeException, "UID #{@uid_string} belongs to a #{@wrong_device_display_name} instead of the expected #{@device_display_name}"
|
507
|
+
end
|
508
|
+
}
|
509
|
+
end
|
452
510
|
end
|
453
511
|
|
454
512
|
# internal
|
@@ -474,16 +532,18 @@ module Tinkerforge
|
|
474
532
|
# Creates an object with the unique device ID <tt>uid</tt> and adds it to
|
475
533
|
# the IP Connection <tt>ipcon</tt>.
|
476
534
|
def initialize(uid, ipcon)
|
477
|
-
super uid, ipcon
|
535
|
+
super uid, ipcon, 0, 'Brick Daemon'
|
478
536
|
|
479
537
|
@api_version = [2, 0, 0]
|
480
538
|
|
481
539
|
@response_expected[FUNCTION_GET_AUTHENTICATION_NONCE] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
482
540
|
@response_expected[FUNCTION_AUTHENTICATE] = RESPONSE_EXPECTED_TRUE
|
541
|
+
|
542
|
+
@ipcon.add_device self
|
483
543
|
end
|
484
544
|
|
485
545
|
def get_authentication_nonce
|
486
|
-
send_request FUNCTION_GET_AUTHENTICATION_NONCE, [], '',
|
546
|
+
send_request FUNCTION_GET_AUTHENTICATION_NONCE, [], '', 12, 'C4'
|
487
547
|
end
|
488
548
|
|
489
549
|
def authenticate(client_nonce, digest)
|
@@ -492,7 +552,6 @@ module Tinkerforge
|
|
492
552
|
end
|
493
553
|
|
494
554
|
class IPConnection
|
495
|
-
attr_accessor :devices
|
496
555
|
attr_accessor :timeout
|
497
556
|
|
498
557
|
CALLBACK_ENUMERATE = 253
|
@@ -538,6 +597,7 @@ module Tinkerforge
|
|
538
597
|
@authentication_mutex = Mutex.new # protects authentication handshake
|
539
598
|
|
540
599
|
@devices = {}
|
600
|
+
@replace_mutex = Mutex.new # used to synchronize replacements in the devices dict
|
541
601
|
|
542
602
|
@registered_callbacks = {}
|
543
603
|
|
@@ -731,6 +791,19 @@ module Tinkerforge
|
|
731
791
|
@registered_callbacks[id] = callback
|
732
792
|
end
|
733
793
|
|
794
|
+
# internal
|
795
|
+
def add_device(device)
|
796
|
+
@replace_mutex.synchronize {
|
797
|
+
replaced_device = @devices.fetch device.uid, nil
|
798
|
+
|
799
|
+
if replaced_device != nil
|
800
|
+
replaced_device.replaced = true
|
801
|
+
end
|
802
|
+
|
803
|
+
@devices[device.uid] = device # FIXME: use a weakref here
|
804
|
+
}
|
805
|
+
end
|
806
|
+
|
734
807
|
# internal
|
735
808
|
def get_next_sequence_number
|
736
809
|
@sequence_number_mutex.synchronize {
|
@@ -951,8 +1024,10 @@ module Tinkerforge
|
|
951
1024
|
# internal
|
952
1025
|
def dispatch_meta(function_id, parameter, socket_id)
|
953
1026
|
if function_id == CALLBACK_CONNECTED
|
954
|
-
|
955
|
-
|
1027
|
+
cb = @registered_callbacks[CALLBACK_CONNECTED]
|
1028
|
+
|
1029
|
+
if cb != nil
|
1030
|
+
cb.call parameter
|
956
1031
|
end
|
957
1032
|
elsif function_id == CALLBACK_DISCONNECTED
|
958
1033
|
if parameter != DISCONNECT_REASON_REQUEST
|
@@ -980,8 +1055,10 @@ module Tinkerforge
|
|
980
1055
|
# socket. the first receive will then fail directly
|
981
1056
|
sleep 0.1
|
982
1057
|
|
983
|
-
|
984
|
-
|
1058
|
+
cb = @registered_callbacks[CALLBACK_DISCONNECTED]
|
1059
|
+
|
1060
|
+
if cb != nil
|
1061
|
+
cb.call parameter
|
985
1062
|
end
|
986
1063
|
|
987
1064
|
if parameter != DISCONNECT_REASON_REQUEST and @auto_reconnect and @auto_reconnect_allowed
|
@@ -1018,16 +1095,41 @@ module Tinkerforge
|
|
1018
1095
|
uid = Packer.get_uid_from_data packet
|
1019
1096
|
function_id = Packer.get_function_id_from_data packet
|
1020
1097
|
|
1021
|
-
if function_id == CALLBACK_ENUMERATE
|
1022
|
-
|
1098
|
+
if function_id == CALLBACK_ENUMERATE
|
1099
|
+
cb = @registered_callbacks[CALLBACK_ENUMERATE]
|
1100
|
+
|
1101
|
+
if cb == nil
|
1102
|
+
return
|
1103
|
+
end
|
1104
|
+
|
1105
|
+
if packet.length != 34
|
1106
|
+
return # silently ignoring callback with wrong length
|
1107
|
+
end
|
1108
|
+
|
1023
1109
|
payload = Packer.unpack packet[8..-1], 'Z8 Z8 k C3 C3 S C'
|
1024
|
-
|
1025
|
-
|
1026
|
-
|
1110
|
+
|
1111
|
+
cb.call(*payload)
|
1112
|
+
return
|
1113
|
+
end
|
1114
|
+
|
1115
|
+
device = @devices[uid]
|
1116
|
+
|
1117
|
+
if device != nil
|
1118
|
+
begin
|
1119
|
+
device.check_validity
|
1120
|
+
rescue TinkerforgeException
|
1121
|
+
return # silently ignoring callback for invalid device
|
1122
|
+
end
|
1027
1123
|
|
1028
1124
|
if device.high_level_callbacks.has_key?(-function_id)
|
1029
1125
|
hlcb = device.high_level_callbacks[-function_id] # [roles, options, data]
|
1030
|
-
|
1126
|
+
format = device.callback_formats[function_id] # FIXME: currently assuming that low-level callback has more than one element
|
1127
|
+
|
1128
|
+
if packet.length != format[0]
|
1129
|
+
return # silently ignoring callback with wrong length
|
1130
|
+
end
|
1131
|
+
|
1132
|
+
payload = Packer.unpack packet[8..-1], format[1]
|
1031
1133
|
has_data = false
|
1032
1134
|
data = nil
|
1033
1135
|
|
@@ -1071,7 +1173,9 @@ module Tinkerforge
|
|
1071
1173
|
end
|
1072
1174
|
end
|
1073
1175
|
|
1074
|
-
|
1176
|
+
cb = device.registered_callbacks[-function_id]
|
1177
|
+
|
1178
|
+
if has_data and cb != nil
|
1075
1179
|
result = []
|
1076
1180
|
|
1077
1181
|
hlcb[0].zip(payload).each do |role, value|
|
@@ -1082,14 +1186,27 @@ module Tinkerforge
|
|
1082
1186
|
end
|
1083
1187
|
end
|
1084
1188
|
|
1085
|
-
|
1189
|
+
cb.call(*result)
|
1086
1190
|
end
|
1087
1191
|
end
|
1088
1192
|
end
|
1089
1193
|
|
1090
|
-
|
1091
|
-
|
1092
|
-
|
1194
|
+
cb = device.registered_callbacks[function_id]
|
1195
|
+
|
1196
|
+
if cb != nil
|
1197
|
+
format = device.callback_formats[function_id]
|
1198
|
+
|
1199
|
+
if format == nil
|
1200
|
+
return # silently ignore registered but unknown callback
|
1201
|
+
end
|
1202
|
+
|
1203
|
+
if packet.length != format[0]
|
1204
|
+
return # silently ignoring callback with wrong length
|
1205
|
+
end
|
1206
|
+
|
1207
|
+
payload = Packer.unpack packet[8..-1], format[1]
|
1208
|
+
|
1209
|
+
cb.call(*payload)
|
1093
1210
|
end
|
1094
1211
|
end
|
1095
1212
|
end
|
@@ -1172,7 +1289,6 @@ module Tinkerforge
|
|
1172
1289
|
def handle_response(packet)
|
1173
1290
|
@disconnect_probe_flag = false
|
1174
1291
|
|
1175
|
-
uid = Packer.get_uid_from_data packet
|
1176
1292
|
function_id = Packer.get_function_id_from_data packet
|
1177
1293
|
sequence_number = Packer.get_sequence_number_from_data packet
|
1178
1294
|
|
@@ -1180,9 +1296,13 @@ module Tinkerforge
|
|
1180
1296
|
if @registered_callbacks.has_key? CALLBACK_ENUMERATE
|
1181
1297
|
@callback.queue.push [QUEUE_KIND_PACKET, packet]
|
1182
1298
|
end
|
1183
|
-
|
1184
|
-
|
1299
|
+
return
|
1300
|
+
end
|
1301
|
+
|
1302
|
+
uid = Packer.get_uid_from_data packet
|
1303
|
+
device = @devices[uid]
|
1185
1304
|
|
1305
|
+
if device != nil
|
1186
1306
|
if sequence_number == 0
|
1187
1307
|
if device.registered_callbacks.has_key? function_id or \
|
1188
1308
|
device.high_level_callbacks.has_key?(-function_id)
|