class Tinkerforge::BrickletGPSV2

Determine position, velocity and altitude using GPS

Constants

CALLBACK_ALTITUDE

This callback is triggered periodically with the period that is set by BrickletGPSV2#set_altitude_callback_period. The parameters are the same as for BrickletGPSV2#get_altitude.

The CALLBACK_ALTITUDE callback is only triggered if the altitude changed since the last triggering and if there is currently a fix as indicated by BrickletGPSV2#get_status.

CALLBACK_COORDINATES

This callback is triggered periodically with the period that is set by BrickletGPSV2#set_coordinates_callback_period. The parameters are the same as for BrickletGPSV2#get_coordinates.

The CALLBACK_COORDINATES callback is only triggered if the coordinates changed since the last triggering and if there is currently a fix as indicated by BrickletGPSV2#get_status.

CALLBACK_DATE_TIME

This callback is triggered periodically with the period that is set by BrickletGPSV2#set_date_time_callback_period. The parameters are the same as for BrickletGPSV2#get_date_time.

The CALLBACK_DATE_TIME callback is only triggered if the date or time changed since the last triggering.

CALLBACK_MOTION

This callback is triggered periodically with the period that is set by BrickletGPSV2#set_motion_callback_period. The parameters are the same as for BrickletGPSV2#get_motion.

The CALLBACK_MOTION callback is only triggered if the motion changed since the last triggering and if there is currently a fix as indicated by BrickletGPSV2#get_status.

CALLBACK_PULSE_PER_SECOND

This callback is triggered precisely once per second, see `PPS <CALLBACK_STATUS

This callback is triggered periodically with the period that is set by BrickletGPSV2#set_status_callback_period. The parameters are the same as for BrickletGPSV2#get_status.

The CALLBACK_STATUS callback is only triggered if the status changed since the last triggering.

Public Class Methods

new(uid, ipcon) click to toggle source

Creates an object with the unique device ID uid and adds it to the IP Connection ipcon.

Calls superclass method
# File lib/tinkerforge/bricklet_gps_v2.rb, line 141
def initialize(uid, ipcon)
  super uid, ipcon, DEVICE_IDENTIFIER, DEVICE_DISPLAY_NAME

  @api_version = [2, 0, 1]

  @response_expected[FUNCTION_GET_COORDINATES] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_STATUS] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_ALTITUDE] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_MOTION] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_DATE_TIME] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_RESTART] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_SATELLITE_SYSTEM_STATUS_LOW_LEVEL] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_SATELLITE_STATUS] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_FIX_LED_CONFIG] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_FIX_LED_CONFIG] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_COORDINATES_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE
  @response_expected[FUNCTION_GET_COORDINATES_CALLBACK_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_STATUS_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE
  @response_expected[FUNCTION_GET_STATUS_CALLBACK_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_ALTITUDE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE
  @response_expected[FUNCTION_GET_ALTITUDE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_MOTION_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE
  @response_expected[FUNCTION_GET_MOTION_CALLBACK_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_DATE_TIME_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE
  @response_expected[FUNCTION_GET_DATE_TIME_CALLBACK_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_SBAS_CONFIG] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_SBAS_CONFIG] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_SPITFP_ERROR_COUNT] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_BOOTLOADER_MODE] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_BOOTLOADER_MODE] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_WRITE_FIRMWARE_POINTER] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_WRITE_FIRMWARE] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_STATUS_LED_CONFIG] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_STATUS_LED_CONFIG] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_CHIP_TEMPERATURE] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_RESET] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_WRITE_UID] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_READ_UID] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE

  @callback_formats[CALLBACK_PULSE_PER_SECOND] = [8, '']
  @callback_formats[CALLBACK_COORDINATES] = [18, 'L k L k']
  @callback_formats[CALLBACK_STATUS] = [10, '? C']
  @callback_formats[CALLBACK_ALTITUDE] = [16, 'l l']
  @callback_formats[CALLBACK_MOTION] = [16, 'L L']
  @callback_formats[CALLBACK_DATE_TIME] = [16, 'L L']

  @ipcon.add_device self
end

Public Instance Methods

get_altitude() click to toggle source

Returns the current altitude and corresponding geoidal separation.

This data is only valid if there is currently a fix as indicated by BrickletGPSV2#get_status.

# File lib/tinkerforge/bricklet_gps_v2.rb, line 220
def get_altitude
  check_validity

  send_request FUNCTION_GET_ALTITUDE, [], '', 16, 'l l'
end
get_altitude_callback_period() click to toggle source

Returns the period as set by BrickletGPSV2#set_altitude_callback_period.

# File lib/tinkerforge/bricklet_gps_v2.rb, line 366
def get_altitude_callback_period
  check_validity

  send_request FUNCTION_GET_ALTITUDE_CALLBACK_PERIOD, [], '', 12, 'L'
end
get_bootloader_mode() click to toggle source

Returns the current bootloader mode, see BrickletGPSV2#set_bootloader_mode.

# File lib/tinkerforge/bricklet_gps_v2.rb, line 461
def get_bootloader_mode
  check_validity

  send_request FUNCTION_GET_BOOTLOADER_MODE, [], '', 9, 'C'
end
get_chip_temperature() click to toggle source

Returns the temperature as measured inside the microcontroller. The value returned is not the ambient temperature!

The temperature is only proportional to the real temperature and it has bad accuracy. Practically it is only useful as an indicator for temperature changes.

# File lib/tinkerforge/bricklet_gps_v2.rb, line 519
def get_chip_temperature
  check_validity

  send_request FUNCTION_GET_CHIP_TEMPERATURE, [], '', 10, 's'
end
get_coordinates() click to toggle source

Returns the GPS coordinates. Latitude and longitude are given in the “DD.dddddd°“ format, the value 57123468 means 57.123468°. The parameter “ns“ and “ew“ are the cardinal directions for latitude and longitude. Possible values for “ns“ and “ew“ are 'N', 'S', 'E' and 'W' (north, south, east and west).

This data is only valid if there is currently a fix as indicated by BrickletGPSV2#get_status.

# File lib/tinkerforge/bricklet_gps_v2.rb, line 199
def get_coordinates
  check_validity

  send_request FUNCTION_GET_COORDINATES, [], '', 18, 'L k L k'
end
get_coordinates_callback_period() click to toggle source

Returns the period as set by BrickletGPSV2#set_coordinates_callback_period.

# File lib/tinkerforge/bricklet_gps_v2.rb, line 330
def get_coordinates_callback_period
  check_validity

  send_request FUNCTION_GET_COORDINATES_CALLBACK_PERIOD, [], '', 12, 'L'
end
get_date_time() click to toggle source

Returns the current date and time. The date is given in the format “ddmmyy“ and the time is given in the format “hhmmss.sss“. For example, 140713 means 14.07.13 as date and 195923568 means 19:59:23.568 as time.

# File lib/tinkerforge/bricklet_gps_v2.rb, line 244
def get_date_time
  check_validity

  send_request FUNCTION_GET_DATE_TIME, [], '', 16, 'L L'
end
get_date_time_callback_period() click to toggle source

Returns the period as set by BrickletGPSV2#set_date_time_callback_period.

# File lib/tinkerforge/bricklet_gps_v2.rb, line 402
def get_date_time_callback_period
  check_validity

  send_request FUNCTION_GET_DATE_TIME_CALLBACK_PERIOD, [], '', 12, 'L'
end
get_fix_led_config() click to toggle source

Returns the configuration as set by BrickletGPSV2#set_fix_led_config

# File lib/tinkerforge/bricklet_gps_v2.rb, line 312
def get_fix_led_config
  check_validity

  send_request FUNCTION_GET_FIX_LED_CONFIG, [], '', 9, 'C'
end
get_identity() click to toggle source

Returns the UID, the UID where the Bricklet is connected to, the position, the hardware and firmware version as well as the device identifier.

The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port). A Bricklet connected to an :ref:`Isolator Bricklet <isolator_bricklet>` is always at position 'z'.

The device identifier numbers can be found :ref:`here <device_identifier>`. |device_identifier_constant|

# File lib/tinkerforge/bricklet_gps_v2.rb, line 566
def get_identity
  send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S'
end
get_motion() click to toggle source

Returns the current course and speed. A course of 0° means the Bricklet is traveling north bound and 90° means it is traveling east bound.

Please note that this only returns useful values if an actual movement is present.

This data is only valid if there is currently a fix as indicated by BrickletGPSV2#get_status.

# File lib/tinkerforge/bricklet_gps_v2.rb, line 234
def get_motion
  check_validity

  send_request FUNCTION_GET_MOTION, [], '', 16, 'L L'
end
get_motion_callback_period() click to toggle source

Returns the period as set by BrickletGPSV2#set_motion_callback_period.

# File lib/tinkerforge/bricklet_gps_v2.rb, line 384
def get_motion_callback_period
  check_validity

  send_request FUNCTION_GET_MOTION_CALLBACK_PERIOD, [], '', 12, 'L'
end
get_satellite_status(satellite_system, satellite_number) click to toggle source

Returns the current elevation, azimuth and SNR for a given satellite and satellite system.

The satellite number here always goes from 1 to 32. For GLONASS it corresponds to the satellites 65-96.

Galileo is not yet supported.

# File lib/tinkerforge/bricklet_gps_v2.rb, line 291
def get_satellite_status(satellite_system, satellite_number)
  check_validity

  send_request FUNCTION_GET_SATELLITE_STATUS, [satellite_system, satellite_number], 'C C', 14, 's s s'
end
get_satellite_system_status(satellite_system) click to toggle source

Returns the

  • satellite numbers list (up to 12 items)

  • fix value,

  • PDOP value,

  • HDOP value and

  • VDOP value

for a given satellite system. Currently GPS and GLONASS are supported, Galileo is not yet supported.

The GPS and GLONASS satellites have unique numbers and the satellite list gives the numbers of the satellites that are currently utilized. The number 0 is not a valid satellite number and can be ignored in the list.

# File lib/tinkerforge/bricklet_gps_v2.rb, line 584
def get_satellite_system_status(satellite_system)
  ret = get_satellite_system_status_low_level satellite_system

  [ret[1][0, ret[0]], ret[2], ret[3], ret[4], ret[5]]
end
get_satellite_system_status_low_level(satellite_system) click to toggle source

Returns the

  • satellite numbers list (up to 12 items)

  • fix value,

  • PDOP value,

  • HDOP value and

  • VDOP value

for a given satellite system. Currently GPS and GLONASS are supported, Galileo is not yet supported.

The GPS and GLONASS satellites have unique numbers and the satellite list gives the numbers of the satellites that are currently utilized. The number 0 is not a valid satellite number and can be ignored in the list.

# File lib/tinkerforge/bricklet_gps_v2.rb, line 278
def get_satellite_system_status_low_level(satellite_system)
  check_validity

  send_request FUNCTION_GET_SATELLITE_SYSTEM_STATUS_LOW_LEVEL, [satellite_system], 'C', 28, 'C C12 C S S S'
end
get_sbas_config() click to toggle source

Returns the SBAS configuration as set by BrickletGPSV2#set_sbas_config

.. versionadded

2.0.2$nbsp;(Plugin)

# File lib/tinkerforge/bricklet_gps_v2.rb, line 422
def get_sbas_config
  check_validity

  send_request FUNCTION_GET_SBAS_CONFIG, [], '', 9, 'C'
end
get_spitfp_error_count() click to toggle source

Returns the error count for the communication between Brick and Bricklet.

The errors are divided into

  • ACK checksum errors,

  • message checksum errors,

  • framing errors and

  • overflow errors.

The errors counts are for errors that occur on the Bricklet side. All Bricks have a similar function that returns the errors on the Brick side.

# File lib/tinkerforge/bricklet_gps_v2.rb, line 439
def get_spitfp_error_count
  check_validity

  send_request FUNCTION_GET_SPITFP_ERROR_COUNT, [], '', 24, 'L L L L'
end
get_status() click to toggle source

Returns if a fix is currently available as well as the, the number of satellites that are in view.

There is also a :ref:`green LED <gps_v2_bricklet_fix_led>` on the Bricklet that indicates the fix status.

# File lib/tinkerforge/bricklet_gps_v2.rb, line 210
def get_status
  check_validity

  send_request FUNCTION_GET_STATUS, [], '', 10, '? C'
end
get_status_callback_period() click to toggle source

Returns the period as set by BrickletGPSV2#set_status_callback_period.

# File lib/tinkerforge/bricklet_gps_v2.rb, line 348
def get_status_callback_period
  check_validity

  send_request FUNCTION_GET_STATUS_CALLBACK_PERIOD, [], '', 12, 'L'
end
get_status_led_config() click to toggle source

Returns the configuration as set by BrickletGPSV2#set_status_led_config

# File lib/tinkerforge/bricklet_gps_v2.rb, line 507
def get_status_led_config
  check_validity

  send_request FUNCTION_GET_STATUS_LED_CONFIG, [], '', 9, 'C'
end
read_uid() click to toggle source

Returns the current UID as an integer. Encode as Base58 to get the usual string version.

# File lib/tinkerforge/bricklet_gps_v2.rb, line 550
def read_uid
  check_validity

  send_request FUNCTION_READ_UID, [], '', 12, 'L'
end
register_callback(id, &block) click to toggle source

Registers a callback with ID id to the block block.

# File lib/tinkerforge/bricklet_gps_v2.rb, line 591
def register_callback(id, &block)
  callback = block
  @registered_callbacks[id] = callback
end
reset() click to toggle source

Calling this function will reset the Bricklet. All configurations will be lost.

After a reset you have to create new device objects, calling functions on the existing ones will result in undefined behavior!

# File lib/tinkerforge/bricklet_gps_v2.rb, line 531
def reset
  check_validity

  send_request FUNCTION_RESET, [], '', 8, ''
end
restart(restart_type) click to toggle source

Restarts the GPS Bricklet, the following restart types are available:

"Value", "Description"

"0", "Hot start (use all available data in the NV store)"
"1", "Warm start (don't use ephemeris at restart)"
"2", "Cold start (don't use time, position, almanacs and ephemeris at restart)"
"3", "Factory reset (clear all system/user configurations at restart)"
# File lib/tinkerforge/bricklet_gps_v2.rb, line 258
def restart(restart_type)
  check_validity

  send_request FUNCTION_RESTART, [restart_type], 'C', 8, ''
end
set_altitude_callback_period(period) click to toggle source

Sets the period with which the CALLBACK_ALTITUDE callback is triggered periodically. A value of 0 turns the callback off.

The CALLBACK_ALTITUDE callback is only triggered if the altitude changed since the last triggering.

# File lib/tinkerforge/bricklet_gps_v2.rb, line 359
def set_altitude_callback_period(period)
  check_validity

  send_request FUNCTION_SET_ALTITUDE_CALLBACK_PERIOD, [period], 'L', 8, ''
end
set_bootloader_mode(mode) click to toggle source

Sets the bootloader mode and returns the status after the requested mode change was instigated.

You can change from bootloader mode to firmware mode and vice versa. A change from bootloader mode to firmware mode will only take place if the entry function, device identifier and CRC are present and correct.

This function is used by Brick Viewer during flashing. It should not be necessary to call it in a normal user program.

# File lib/tinkerforge/bricklet_gps_v2.rb, line 454
def set_bootloader_mode(mode)
  check_validity

  send_request FUNCTION_SET_BOOTLOADER_MODE, [mode], 'C', 9, 'C'
end
set_coordinates_callback_period(period) click to toggle source

Sets the period with which the CALLBACK_COORDINATES callback is triggered periodically. A value of 0 turns the callback off.

The CALLBACK_COORDINATES callback is only triggered if the coordinates changed since the last triggering.

# File lib/tinkerforge/bricklet_gps_v2.rb, line 323
def set_coordinates_callback_period(period)
  check_validity

  send_request FUNCTION_SET_COORDINATES_CALLBACK_PERIOD, [period], 'L', 8, ''
end
set_date_time_callback_period(period) click to toggle source

Sets the period with which the CALLBACK_DATE_TIME callback is triggered periodically. A value of 0 turns the callback off.

The CALLBACK_DATE_TIME callback is only triggered if the date or time changed since the last triggering.

# File lib/tinkerforge/bricklet_gps_v2.rb, line 395
def set_date_time_callback_period(period)
  check_validity

  send_request FUNCTION_SET_DATE_TIME_CALLBACK_PERIOD, [period], 'L', 8, ''
end
set_fix_led_config(config) click to toggle source

Sets the fix LED configuration. By default the LED shows if the Bricklet got a GPS fix yet. If a fix is established the LED turns on. If there is no fix then the LED is turned off.

You can also turn the LED permanently on/off, show a heartbeat or let it blink in sync with the PPS (pulse per second) output of the GPS module.

If the Bricklet is in bootloader mode, the LED is off.

# File lib/tinkerforge/bricklet_gps_v2.rb, line 305
def set_fix_led_config(config)
  check_validity

  send_request FUNCTION_SET_FIX_LED_CONFIG, [config], 'C', 8, ''
end
set_motion_callback_period(period) click to toggle source

Sets the period with which the CALLBACK_MOTION callback is triggered periodically. A value of 0 turns the callback off.

The CALLBACK_MOTION callback is only triggered if the motion changed since the last triggering.

# File lib/tinkerforge/bricklet_gps_v2.rb, line 377
def set_motion_callback_period(period)
  check_validity

  send_request FUNCTION_SET_MOTION_CALLBACK_PERIOD, [period], 'L', 8, ''
end
set_status_callback_period(period) click to toggle source

Sets the period with which the CALLBACK_STATUS callback is triggered periodically. A value of 0 turns the callback off.

The CALLBACK_STATUS callback is only triggered if the status changed since the last triggering.

# File lib/tinkerforge/bricklet_gps_v2.rb, line 341
def set_status_callback_period(period)
  check_validity

  send_request FUNCTION_SET_STATUS_CALLBACK_PERIOD, [period], 'L', 8, ''
end
set_status_led_config(config) click to toggle source

Sets the status LED configuration. By default the LED shows communication traffic between Brick and Bricklet, it flickers once for every 10 received data packets.

You can also turn the LED permanently on/off or show a heartbeat.

If the Bricklet is in bootloader mode, the LED is will show heartbeat by default.

# File lib/tinkerforge/bricklet_gps_v2.rb, line 500
def set_status_led_config(config)
  check_validity

  send_request FUNCTION_SET_STATUS_LED_CONFIG, [config], 'C', 8, ''
end
set_write_firmware_pointer(pointer) click to toggle source

Sets the firmware pointer for BrickletGPSV2#write_firmware. The pointer has to be increased by chunks of size 64. The data is written to flash every 4 chunks (which equals to one page of size 256).

This function is used by Brick Viewer during flashing. It should not be necessary to call it in a normal user program.

# File lib/tinkerforge/bricklet_gps_v2.rb, line 473
def set_write_firmware_pointer(pointer)
  check_validity

  send_request FUNCTION_SET_WRITE_FIRMWARE_POINTER, [pointer], 'L', 8, ''
end
write_firmware(data) click to toggle source

Writes 64 Bytes of firmware at the position as written by BrickletGPSV2#set_write_firmware_pointer before. The firmware is written to flash every 4 chunks.

You can only write firmware in bootloader mode.

This function is used by Brick Viewer during flashing. It should not be necessary to call it in a normal user program.

# File lib/tinkerforge/bricklet_gps_v2.rb, line 487
def write_firmware(data)
  check_validity

  send_request FUNCTION_WRITE_FIRMWARE, [data], 'C64', 9, 'C'
end
write_uid(uid) click to toggle source

Writes a new UID into flash. If you want to set a new UID you have to decode the Base58 encoded UID string into an integer first.

We recommend that you use Brick Viewer to change the UID.

# File lib/tinkerforge/bricklet_gps_v2.rb, line 542
def write_uid(uid)
  check_validity

  send_request FUNCTION_WRITE_UID, [uid], 'L', 8, ''
end