tinkerforge 2.0.13 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/lib/tinkerforge/brick_dc.rb +4 -11
  2. data/lib/tinkerforge/brick_imu.rb +17 -16
  3. data/lib/tinkerforge/brick_master.rb +96 -86
  4. data/lib/tinkerforge/brick_servo.rb +5 -12
  5. data/lib/tinkerforge/brick_stepper.rb +4 -29
  6. data/lib/tinkerforge/bricklet_ambient_light.rb +4 -5
  7. data/lib/tinkerforge/bricklet_analog_in.rb +4 -5
  8. data/lib/tinkerforge/bricklet_analog_out.rb +4 -5
  9. data/lib/tinkerforge/bricklet_barometer.rb +4 -9
  10. data/lib/tinkerforge/bricklet_current12.rb +4 -5
  11. data/lib/tinkerforge/bricklet_current25.rb +4 -5
  12. data/lib/tinkerforge/bricklet_distance_ir.rb +4 -5
  13. data/lib/tinkerforge/bricklet_distance_us.rb +4 -5
  14. data/lib/tinkerforge/bricklet_dual_button.rb +4 -7
  15. data/lib/tinkerforge/bricklet_dual_relay.rb +4 -13
  16. data/lib/tinkerforge/bricklet_gps.rb +4 -5
  17. data/lib/tinkerforge/bricklet_hall_effect.rb +6 -5
  18. data/lib/tinkerforge/bricklet_humidity.rb +4 -5
  19. data/lib/tinkerforge/bricklet_industrial_digital_in_4.rb +8 -6
  20. data/lib/tinkerforge/bricklet_industrial_digital_out_4.rb +7 -11
  21. data/lib/tinkerforge/bricklet_industrial_dual_0_20ma.rb +4 -5
  22. data/lib/tinkerforge/bricklet_industrial_quad_relay.rb +9 -13
  23. data/lib/tinkerforge/bricklet_io16.rb +15 -21
  24. data/lib/tinkerforge/bricklet_io4.rb +11 -17
  25. data/lib/tinkerforge/bricklet_joystick.rb +4 -5
  26. data/lib/tinkerforge/bricklet_lcd_16x2.rb +4 -5
  27. data/lib/tinkerforge/bricklet_lcd_20x4.rb +4 -5
  28. data/lib/tinkerforge/bricklet_led_strip.rb +6 -5
  29. data/lib/tinkerforge/bricklet_line.rb +4 -5
  30. data/lib/tinkerforge/bricklet_linear_poti.rb +4 -5
  31. data/lib/tinkerforge/bricklet_moisture.rb +4 -5
  32. data/lib/tinkerforge/bricklet_motion_detector.rb +4 -5
  33. data/lib/tinkerforge/bricklet_multi_touch.rb +4 -5
  34. data/lib/tinkerforge/bricklet_piezo_buzzer.rb +4 -5
  35. data/lib/tinkerforge/bricklet_piezo_speaker.rb +4 -5
  36. data/lib/tinkerforge/bricklet_ptc.rb +4 -5
  37. data/lib/tinkerforge/bricklet_remote_switch.rb +4 -5
  38. data/lib/tinkerforge/bricklet_rotary_encoder.rb +4 -5
  39. data/lib/tinkerforge/bricklet_rotary_poti.rb +4 -5
  40. data/lib/tinkerforge/bricklet_segment_display_4x7.rb +5 -6
  41. data/lib/tinkerforge/bricklet_sound_intensity.rb +4 -5
  42. data/lib/tinkerforge/bricklet_temperature.rb +4 -5
  43. data/lib/tinkerforge/bricklet_temperature_ir.rb +4 -5
  44. data/lib/tinkerforge/bricklet_tilt.rb +4 -5
  45. data/lib/tinkerforge/bricklet_voltage.rb +4 -5
  46. data/lib/tinkerforge/bricklet_voltage_current.rb +4 -5
  47. data/lib/tinkerforge/ip_connection.rb +73 -6
  48. data/lib/tinkerforge/version.rb +1 -1
  49. metadata +2 -2
@@ -1,8 +1,8 @@
1
1
  # -*- ruby encoding: utf-8 -*-
2
2
  #############################################################
3
- # This file was automatically generated on 2013-12-19. #
3
+ # This file was automatically generated on 2014-04-08. #
4
4
  # #
5
- # Bindings Version 2.0.13 #
5
+ # Bindings Version 2.1.0 #
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 #
@@ -83,9 +83,8 @@ module Tinkerforge
83
83
  #
84
84
  # The position can be 'a', 'b', 'c' or 'd'.
85
85
  #
86
- # The device identifiers can be found :ref:`here <device_identifier>`.
87
- #
88
- # .. versionadded:: 2.0.0~(Plugin)
86
+ # The device identifier numbers can be found :ref:`here <device_identifier>`.
87
+ # |device_identifier_constant|
89
88
  def get_identity
90
89
  send_request(FUNCTION_GET_IDENTITY, [], '', 25, 'Z8 Z8 k C3 C3 S')
91
90
  end
@@ -1,8 +1,8 @@
1
1
  # -*- ruby encoding: utf-8 -*-
2
2
  #############################################################
3
- # This file was automatically generated on 2013-12-19. #
3
+ # This file was automatically generated on 2014-04-08. #
4
4
  # #
5
- # Bindings Version 2.0.13 #
5
+ # Bindings Version 2.1.0 #
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 #
@@ -227,9 +227,8 @@ module Tinkerforge
227
227
  #
228
228
  # The position can be 'a', 'b', 'c' or 'd'.
229
229
  #
230
- # The device identifiers can be found :ref:`here <device_identifier>`.
231
- #
232
- # .. versionadded:: 2.0.0~(Plugin)
230
+ # The device identifier numbers can be found :ref:`here <device_identifier>`.
231
+ # |device_identifier_constant|
233
232
  def get_identity
234
233
  send_request(FUNCTION_GET_IDENTITY, [], '', 25, 'Z8 Z8 k C3 C3 S')
235
234
  end
@@ -1,8 +1,8 @@
1
1
  # -*- ruby encoding: utf-8 -*-
2
2
  #############################################################
3
- # This file was automatically generated on 2013-12-19. #
3
+ # This file was automatically generated on 2014-04-08. #
4
4
  # #
5
- # Bindings Version 2.0.13 #
5
+ # Bindings Version 2.1.0 #
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 #
@@ -374,9 +374,8 @@ module Tinkerforge
374
374
  #
375
375
  # The position can be 'a', 'b', 'c' or 'd'.
376
376
  #
377
- # The device identifiers can be found :ref:`here <device_identifier>`.
378
- #
379
- # .. versionadded:: 2.0.0~(Plugin)
377
+ # The device identifier numbers can be found :ref:`here <device_identifier>`.
378
+ # |device_identifier_constant|
380
379
  def get_identity
381
380
  send_request(FUNCTION_GET_IDENTITY, [], '', 25, 'Z8 Z8 k C3 C3 S')
382
381
  end
@@ -1,12 +1,15 @@
1
1
  # -*- ruby encoding: utf-8 -*-
2
- # Copyright (C) 2012-2013 Matthias Bolte <matthias@tinkerforge.com>
2
+ # Copyright (C) 2012-2014 Matthias Bolte <matthias@tinkerforge.com>
3
3
  #
4
4
  # Redistribution and use in source and binary forms of this file,
5
- # with or without modification, are permitted.
5
+ # with or without modification, are permitted. See the Creative
6
+ # Commons Zero (CC0 1.0) License for more details.
6
7
 
7
8
  require 'socket'
8
9
  require 'thread'
9
10
  require 'timeout'
11
+ require 'securerandom'
12
+ require 'openssl'
10
13
 
11
14
  module Tinkerforge
12
15
  class Base58
@@ -429,6 +432,31 @@ module Tinkerforge
429
432
  end
430
433
  end
431
434
 
435
+ # internal
436
+ class BrickDaemon < Device
437
+ FUNCTION_GET_AUTHENTICATION_NONCE = 1 # :nodoc:
438
+ FUNCTION_AUTHENTICATE = 2 # :nodoc:
439
+
440
+ # Creates an object with the unique device ID <tt>uid</tt> and adds it to
441
+ # the IP Connection <tt>ipcon</tt>.
442
+ def initialize(uid, ipcon)
443
+ super uid, ipcon
444
+
445
+ @api_version = [2, 0, 0]
446
+
447
+ @response_expected[FUNCTION_GET_AUTHENTICATION_NONCE] = RESPONSE_EXPECTED_ALWAYS_TRUE
448
+ @response_expected[FUNCTION_AUTHENTICATE] = RESPONSE_EXPECTED_TRUE
449
+ end
450
+
451
+ def get_authentication_nonce
452
+ send_request(FUNCTION_GET_AUTHENTICATION_NONCE, [], '', 4, 'C4')
453
+ end
454
+
455
+ def authenticate(client_nonce, digest)
456
+ send_request(FUNCTION_AUTHENTICATE, [client_nonce, digest], 'C4 C20', 0, '')
457
+ end
458
+ end
459
+
432
460
  class IPConnection
433
461
  attr_accessor :devices
434
462
  attr_accessor :timeout
@@ -469,9 +497,12 @@ module Tinkerforge
469
497
  @auto_reconnect_allowed = false
470
498
  @auto_reconnect_pending = false
471
499
 
472
- @next_sequence_number = 0
500
+ @next_sequence_number = 0 # protected by sequence_number_mutex
473
501
  @sequence_number_mutex = Mutex.new
474
502
 
503
+ @next_authentication_nonce = 0 # protected by authentication_mutex
504
+ @authentication_mutex = Mutex.new # protects authentication handshake
505
+
475
506
  @devices = {}
476
507
 
477
508
  @registered_callbacks = {}
@@ -491,6 +522,8 @@ module Tinkerforge
491
522
  @disconnect_probe_thread = nil # protected by socket_mutex
492
523
 
493
524
  @waiter_queue = Queue.new
525
+
526
+ @brickd = BrickDaemon.new '2', self
494
527
  end
495
528
 
496
529
  # Creates a TCP/IP connection to the given <tt>host</tt> and <tt>port</tt>.
@@ -551,6 +584,32 @@ module Tinkerforge
551
584
  end
552
585
  end
553
586
 
587
+ # Performs an authentication handshake with the connected Brick Daemon or
588
+ # WIFI/Ethernet Extension. If the handshake succeeds the connection switches
589
+ # from non-authenticated to authenticated state and communication can
590
+ # continue as normal. If the handshake fails then the connection gets closed.
591
+ # Authentication can fail if the wrong secret was used or if authentication
592
+ # is not enabled at all on the Brick Daemon or the WIFI/Ethernet Extension.
593
+ #
594
+ # For more information about authentication see
595
+ # http://www.tinkerforge.com/en/doc/Tutorials/Tutorial_Authentication/Tutorial.html
596
+ def authenticate(secret)
597
+ @authentication_mutex.synchronize {
598
+ if @next_authentication_nonce == 0
599
+ @next_authentication_nonce = SecureRandom.random_number(1 << 32)
600
+ end
601
+
602
+ server_nonce = @brickd.get_authentication_nonce
603
+ client_nonce = unpack(pack([@next_authentication_nonce], 'L'), 'C4')[0]
604
+ @next_authentication_nonce += 1
605
+ nonce_bytes = pack [server_nonce, client_nonce], 'C4 C4'
606
+ digest_bytes = OpenSSL::HMAC.digest 'sha1', secret, nonce_bytes
607
+ digest = unpack(digest_bytes, 'C20')[0]
608
+
609
+ @brickd.authenticate client_nonce, digest
610
+ }
611
+ end
612
+
554
613
  # Can return the following states:
555
614
  #
556
615
  # - CONNECTION_STATE_DISCONNECTED: No connection is established.
@@ -572,7 +631,7 @@ module Tinkerforge
572
631
  # the IP Connection will try to reconnect to the previously given
573
632
  # host and port, if the connection is lost.
574
633
  #
575
- # Default value is *true*.
634
+ # Default value is <tt>true</tt>.
576
635
  def set_auto_reconnect(auto_reconnect)
577
636
  @auto_reconnect = auto_reconnect
578
637
 
@@ -666,6 +725,7 @@ module Tinkerforge
666
725
  [header, response_expected, sequence_number]
667
726
  end
668
727
 
728
+ # internal
669
729
  def send_request(request)
670
730
  @socket_mutex.synchronize {
671
731
  if @socket == nil
@@ -744,8 +804,8 @@ module Tinkerforge
744
804
  connect_reason = CONNECT_REASON_REQUEST
745
805
  end
746
806
 
747
- @auto_reconnect_allowed = false;
748
- @auto_reconnect_pending = false;
807
+ @auto_reconnect_allowed = false
808
+ @auto_reconnect_pending = false
749
809
 
750
810
  @callback.queue.push [QUEUE_KIND_META, [CALLBACK_CONNECTED,
751
811
  connect_reason, nil]]
@@ -812,6 +872,13 @@ module Tinkerforge
812
872
  rescue Errno::ECONNRESET
813
873
  handle_disconnect_by_peer DISCONNECT_REASON_SHUTDOWN, socket_id, false
814
874
  break
875
+ rescue Errno::ESHUTDOWN
876
+ # shutdown was called from disconnect_unlocked
877
+ break
878
+ end
879
+
880
+ if not @receive_flag
881
+ break
815
882
  end
816
883
 
817
884
  if data.length == 0
@@ -1,4 +1,4 @@
1
1
 
2
2
  module Tinkerforge
3
- VERSION = '2.0.13'
3
+ VERSION = '2.1.0'
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tinkerforge
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.13
4
+ version: 2.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-12-19 00:00:00.000000000 Z
12
+ date: 2014-04-08 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description:
15
15
  email: matthias@tinkerforge.com