Skip to content
Snippets Groups Projects
Commit fc522134 authored by Florian Hölzl's avatar Florian Hölzl
Browse files

Rework of Raspberry platform architecture for upcoming lab course.

refs 3079
parent 37d70f35
No related branches found
No related tags found
No related merge requests found
Showing
with 1552 additions and 350 deletions
/*******************************************************************************
* Copyright (c) 2017 fortiss GmbH.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* Florian Hoelzl - initial API and implementation
*******************************************************************************/
#ifndef INC_PROTOCOL_COORDINATOR_H_
#define INC_PROTOCOL_COORDINATOR_H_
#include <stdint.h>
#include "caninbox.h"
#include "protocol_worker.h"
#include "timeutil.h"
/** Main function of coordinator unit. */
int protocol_coordinator_main(
protocol_can_config_t* can_config,
protocol_worker_clock_config_t* clock_config,
protocol_worker_computation_config_t* computation_config);
#endif /* INC_PROTOCOL_COORDINATOR_H_ */
/*******************************************************************************
* Copyright (c) 2017 fortiss GmbH.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* Florian Hoelzl - initial API and implementation
*******************************************************************************/
#ifndef INC_PROTOCOL_FACTORY_H_
#define INC_PROTOCOL_FACTORY_H_
#include "protocol_can.h"
#include "protocol_worker.h"
#include "protocol_coordinator.h"
/** Creates a CAN configuration. */
protocol_can_config_t* protocol_can_config_create(
uint8_t can_id_worker_done,
uint8_t can_id_coordinator_clock,
uint8_t can_id_global_shutdown);
/** Creates a worker clock configuration. */
protocol_worker_clock_config_t* protocol_worker_clock_config_create(
uint64_t cycle_timeout_in_millis,
uint64_t stop_at_logical_time,
uint64_t waiting_sleep_in_micros);
/** Creates a worker computation configuration. */
protocol_worker_computation_config_t* protocol_worker_computation_config_create(
char* name,
void(*worker)(void),
can_inbox_t* remote_units_sync_inbox,
can_inbox_t* application_inbox,
can_outbox_t* application_outbox,
uint64_t simulated_workload_in_millis);
#endif /* INC_PROTOCOL_FACTORY_H_ */
/*******************************************************************************
* Copyright (c) 2017 fortiss GmbH.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* Florian Hoelzl - initial API and implementation
*******************************************************************************/
#ifndef INC_PROTOCOL_WORKER_H_
#define INC_PROTOCOL_WORKER_H_
#include <caninbox.h>
#include <canoutbox.h>
#include <stdint.h>
#include "protocol_can.h"
struct protocol_worker_computation_config {
char* name;
void(*worker)(void);
can_inbox_t* remote_units_sync_inbox;
can_inbox_t* application_inbox;
can_outbox_t* application_outbox;
uint64_t simulated_workload_in_millis;
};
typedef struct protocol_worker_computation_config protocol_worker_computation_config_t;
struct protocol_worker_clock_config {
uint64_t cycle_timeout_in_millis;
uint64_t stop_at_logical_time;
uint64_t waiting_sleep_in_micros;
};
typedef struct protocol_worker_clock_config protocol_worker_clock_config_t;
/** Main function of worker unit. */
int protocol_worker_main(
protocol_can_config_t* can_config,
protocol_worker_clock_config_t* clock_config,
protocol_worker_computation_config_t* computation_config);
#endif /* INC_PROTOCOL_WORKER_H_ */
/*******************************************************************************
* Copyright (c) 2017 fortiss GmbH.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* Florian Hoelzl - initial API and implementation
*******************************************************************************/
#ifndef INC_TIMEUTIL_H_
#define INC_TIMEUTIL_H_
#include <stdint.h>
#define MICROS_IN_NANOS (uint64_t)1000
#define MILLIS_IN_MICROS (uint64_t)1000
#define SECONDS_IN_MILLIS (uint64_t)1000
#define MILLIS_IN_NANOS MILLIS_IN_MICROS * MICROS_IN_NANOS
#define SECONDS_IN_MICROS SECONDS_IN_MILLIS * MILLIS_IN_MICROS
#define SECONDS_IN_NANOS SECONDS_IN_MILLIS * MILLIS_IN_NANOS
#define YEARS_IN_SECONDS (uint64_t)365 * (uint64_t)24 * (uint64_t)3600;
/** Returns the current time in microseconds. */
uint64_t time_util_get_current_micros();
/** Returns the elapsed microseconds since the start time. */
uint64_t time_util_get_elapsed_micros_since(uint64_t start_time);
/** Sleeps for the amount of seconds. */
void time_util_sleep_seconds(uint64_t seconds);
/** Sleeps for the amount of milliseconds. */
void time_util_sleep_millis(uint64_t millis);
/** Sleeps for the amount of microseconds. */
void time_util_sleep_micros(uint64_t micros);
#endif /* INC_TIMEUTIL_H_ */
/* ***********************************************************
* This file was automatically generated on 2017-07-27. *
* *
* C/C++ Bindings Version 2.1.17 *
* *
* If you have a bugfix for this file and want to commit it, *
* please fix the bug in the generator. You can find a link *
* to the generators git repository on tinkerforge.com *
*************************************************************/
#ifndef BRICKLET_DISTANCE_US_H
#define BRICKLET_DISTANCE_US_H
#include "ip_connection.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* \defgroup BrickletDistanceUS Distance US Bricklet
*/
/**
* \ingroup BrickletDistanceUS
*
* Measures distance between 2cm and 400cm with ultrasound
*/
typedef Device DistanceUS;
/**
* \ingroup BrickletDistanceUS
*/
#define DISTANCE_US_FUNCTION_GET_DISTANCE_VALUE 1
/**
* \ingroup BrickletDistanceUS
*/
#define DISTANCE_US_FUNCTION_SET_DISTANCE_CALLBACK_PERIOD 2
/**
* \ingroup BrickletDistanceUS
*/
#define DISTANCE_US_FUNCTION_GET_DISTANCE_CALLBACK_PERIOD 3
/**
* \ingroup BrickletDistanceUS
*/
#define DISTANCE_US_FUNCTION_SET_DISTANCE_CALLBACK_THRESHOLD 4
/**
* \ingroup BrickletDistanceUS
*/
#define DISTANCE_US_FUNCTION_GET_DISTANCE_CALLBACK_THRESHOLD 5
/**
* \ingroup BrickletDistanceUS
*/
#define DISTANCE_US_FUNCTION_SET_DEBOUNCE_PERIOD 6
/**
* \ingroup BrickletDistanceUS
*/
#define DISTANCE_US_FUNCTION_GET_DEBOUNCE_PERIOD 7
/**
* \ingroup BrickletDistanceUS
*/
#define DISTANCE_US_FUNCTION_SET_MOVING_AVERAGE 10
/**
* \ingroup BrickletDistanceUS
*/
#define DISTANCE_US_FUNCTION_GET_MOVING_AVERAGE 11
/**
* \ingroup BrickletDistanceUS
*/
#define DISTANCE_US_FUNCTION_GET_IDENTITY 255
/**
* \ingroup BrickletDistanceUS
*
* Signature: \code void callback(uint16_t distance, void *user_data) \endcode
*
* This callback is triggered periodically with the period that is set by
* {@link distance_us_set_distance_callback_period}. The parameter is the distance value
* of the sensor.
*
* The {@link DISTANCE_US_CALLBACK_DISTANCE} callback is only triggered if the distance value has changed
* since the last triggering.
*/
#define DISTANCE_US_CALLBACK_DISTANCE 8
/**
* \ingroup BrickletDistanceUS
*
* Signature: \code void callback(uint16_t distance, void *user_data) \endcode
*
* This callback is triggered when the threshold as set by
* {@link distance_us_set_distance_callback_threshold} is reached.
* The parameter is the distance value of the sensor.
*
* If the threshold keeps being reached, the callback is triggered periodically
* with the period as set by {@link distance_us_set_debounce_period}.
*/
#define DISTANCE_US_CALLBACK_DISTANCE_REACHED 9
/**
* \ingroup BrickletDistanceUS
*/
#define DISTANCE_US_THRESHOLD_OPTION_OFF 'x'
/**
* \ingroup BrickletDistanceUS
*/
#define DISTANCE_US_THRESHOLD_OPTION_OUTSIDE 'o'
/**
* \ingroup BrickletDistanceUS
*/
#define DISTANCE_US_THRESHOLD_OPTION_INSIDE 'i'
/**
* \ingroup BrickletDistanceUS
*/
#define DISTANCE_US_THRESHOLD_OPTION_SMALLER '<'
/**
* \ingroup BrickletDistanceUS
*/
#define DISTANCE_US_THRESHOLD_OPTION_GREATER '>'
/**
* \ingroup BrickletDistanceUS
*
* This constant is used to identify a Distance US Bricklet.
*
* The {@link distance_us_get_identity} function and the
* {@link IPCON_CALLBACK_ENUMERATE} callback of the IP Connection have a
* \c device_identifier parameter to specify the Brick's or Bricklet's type.
*/
#define DISTANCE_US_DEVICE_IDENTIFIER 229
/**
* \ingroup BrickletDistanceUS
*
* This constant represents the display name of a Distance US Bricklet.
*/
#define DISTANCE_US_DEVICE_DISPLAY_NAME "Distance US Bricklet"
/**
* \ingroup BrickletDistanceUS
*
* Creates the device object \c distance_us with the unique device ID \c uid and adds
* it to the IPConnection \c ipcon.
*/
void distance_us_create(DistanceUS *distance_us, const char *uid, IPConnection *ipcon);
/**
* \ingroup BrickletDistanceUS
*
* Removes the device object \c distance_us from its IPConnection and destroys it.
* The device object cannot be used anymore afterwards.
*/
void distance_us_destroy(DistanceUS *distance_us);
/**
* \ingroup BrickletDistanceUS
*
* Returns the response expected flag for the function specified by the
* \c function_id parameter. It is *true* if the function is expected to
* send a response, *false* otherwise.
*
* For getter functions this is enabled by default and cannot be disabled,
* because those functions will always send a response. For callback
* configuration functions it is enabled by default too, but can be disabled
* via the distance_us_set_response_expected function. For setter functions it is
* disabled by default and can be enabled.
*
* Enabling the response expected flag for a setter function allows to
* detect timeouts and other error conditions calls of this setter as well.
* The device will then send a response for this purpose. If this flag is
* disabled for a setter function then no response is send and errors are
* silently ignored, because they cannot be detected.
*/
int distance_us_get_response_expected(DistanceUS *distance_us, uint8_t function_id, bool *ret_response_expected);
/**
* \ingroup BrickletDistanceUS
*
* Changes the response expected flag of the function specified by the
* \c function_id parameter. This flag can only be changed for setter
* (default value: *false*) and callback configuration functions
* (default value: *true*). For getter functions it is always enabled.
*
* Enabling the response expected flag for a setter function allows to detect
* timeouts and other error conditions calls of this setter as well. The device
* will then send a response for this purpose. If this flag is disabled for a
* setter function then no response is send and errors are silently ignored,
* because they cannot be detected.
*/
int distance_us_set_response_expected(DistanceUS *distance_us, uint8_t function_id, bool response_expected);
/**
* \ingroup BrickletDistanceUS
*
* Changes the response expected flag for all setter and callback configuration
* functions of this device at once.
*/
int distance_us_set_response_expected_all(DistanceUS *distance_us, bool response_expected);
/**
* \ingroup BrickletDistanceUS
*
* Registers the given \c function with the given \c callback_id. The
* \c user_data will be passed as the last parameter to the \c function.
*/
void distance_us_register_callback(DistanceUS *distance_us, int16_t callback_id, void *function, void *user_data);
/**
* \ingroup BrickletDistanceUS
*
* Returns the API version (major, minor, release) of the bindings for this
* device.
*/
int distance_us_get_api_version(DistanceUS *distance_us, uint8_t ret_api_version[3]);
/**
* \ingroup BrickletDistanceUS
*
* Returns the current distance value measured by the sensor. The value has a
* range of 0 to 4095. A small value corresponds to a small distance, a big
* value corresponds to a big distance. The relation between the measured distance
* value and the actual distance is affected by the 5V supply voltage (deviations
* in the supply voltage result in deviations in the distance values) and is
* non-linear (resolution is bigger at close range).
*
* If you want to get the distance value periodically, it is recommended to
* use the {@link DISTANCE_US_CALLBACK_DISTANCE} callback and set the period with
* {@link distance_us_set_distance_callback_period}.
*/
int distance_us_get_distance_value(DistanceUS *distance_us, uint16_t *ret_distance);
/**
* \ingroup BrickletDistanceUS
*
* Sets the period in ms with which the {@link DISTANCE_US_CALLBACK_DISTANCE} callback is triggered
* periodically. A value of 0 turns the callback off.
*
* Der {@link DISTANCE_US_CALLBACK_DISTANCE} callback is only triggered if the distance value has changed
* since the last triggering.
*
* The default value is 0.
*/
int distance_us_set_distance_callback_period(DistanceUS *distance_us, uint32_t period);
/**
* \ingroup BrickletDistanceUS
*
* Returns the period as set by {@link distance_us_set_distance_callback_period}.
*/
int distance_us_get_distance_callback_period(DistanceUS *distance_us, uint32_t *ret_period);
/**
* \ingroup BrickletDistanceUS
*
* Sets the thresholds for the {@link DISTANCE_US_CALLBACK_DISTANCE_REACHED} callback.
*
* The following options are possible:
*
* \verbatim
* "Option", "Description"
*
* "'x'", "Callback is turned off"
* "'o'", "Callback is triggered when the distance value is *outside* the min and max values"
* "'i'", "Callback is triggered when the distance value is *inside* the min and max values"
* "'<'", "Callback is triggered when the distance value is smaller than the min value (max is ignored)"
* "'>'", "Callback is triggered when the distance value is greater than the min value (max is ignored)"
* \endverbatim
*
* The default value is ('x', 0, 0).
*/
int distance_us_set_distance_callback_threshold(DistanceUS *distance_us, char option, uint16_t min, uint16_t max);
/**
* \ingroup BrickletDistanceUS
*
* Returns the threshold as set by {@link distance_us_set_distance_callback_threshold}.
*/
int distance_us_get_distance_callback_threshold(DistanceUS *distance_us, char *ret_option, uint16_t *ret_min, uint16_t *ret_max);
/**
* \ingroup BrickletDistanceUS
*
* Sets the period in ms with which the threshold callbacks
*
* * {@link DISTANCE_US_CALLBACK_DISTANCE_REACHED},
*
* are triggered, if the thresholds
*
* * {@link distance_us_set_distance_callback_threshold},
*
* keep being reached.
*
* The default value is 100.
*/
int distance_us_set_debounce_period(DistanceUS *distance_us, uint32_t debounce);
/**
* \ingroup BrickletDistanceUS
*
* Returns the debounce period as set by {@link distance_us_set_debounce_period}.
*/
int distance_us_get_debounce_period(DistanceUS *distance_us, uint32_t *ret_debounce);
/**
* \ingroup BrickletDistanceUS
*
* Sets the length of a `moving averaging <https://en.wikipedia.org/wiki/Moving_average>`__
* for the distance value.
*
* Setting the length to 0 will turn the averaging completely off. With less
* averaging, there is more noise on the data.
*
* The range for the averaging is 0-100.
*
* The default value is 20.
*/
int distance_us_set_moving_average(DistanceUS *distance_us, uint8_t average);
/**
* \ingroup BrickletDistanceUS
*
* Returns the length moving average as set by {@link distance_us_set_moving_average}.
*/
int distance_us_get_moving_average(DistanceUS *distance_us, uint8_t *ret_average);
/**
* \ingroup BrickletDistanceUS
*
* 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' or 'd'.
*
* The device identifier numbers can be found :ref:`here <device_identifier>`.
* |device_identifier_constant|
*/
int distance_us_get_identity(DistanceUS *distance_us, char ret_uid[8], char ret_connected_uid[8], char *ret_position, uint8_t ret_hardware_version[3], uint8_t ret_firmware_version[3], uint16_t *ret_device_identifier);
#ifdef __cplusplus
}
#endif
#endif
/* ***********************************************************
* This file was automatically generated on 2017-07-27. *
* *
* C/C++ Bindings Version 2.1.17 *
* *
* If you have a bugfix for this file and want to commit it, *
* please fix the bug in the generator. You can find a link *
* to the generators git repository on tinkerforge.com *
*************************************************************/
#ifndef BRICKLET_SEGMENT_DISPLAY_4X7_H
#define BRICKLET_SEGMENT_DISPLAY_4X7_H
#include "ip_connection.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* \defgroup BrickletSegmentDisplay4x7 Segment Display 4x7 Bricklet
*/
/**
* \ingroup BrickletSegmentDisplay4x7
*
* Four 7-segment displays with switchable colon
*/
typedef Device SegmentDisplay4x7;
/**
* \ingroup BrickletSegmentDisplay4x7
*/
#define SEGMENT_DISPLAY_4X7_FUNCTION_SET_SEGMENTS 1
/**
* \ingroup BrickletSegmentDisplay4x7
*/
#define SEGMENT_DISPLAY_4X7_FUNCTION_GET_SEGMENTS 2
/**
* \ingroup BrickletSegmentDisplay4x7
*/
#define SEGMENT_DISPLAY_4X7_FUNCTION_START_COUNTER 3
/**
* \ingroup BrickletSegmentDisplay4x7
*/
#define SEGMENT_DISPLAY_4X7_FUNCTION_GET_COUNTER_VALUE 4
/**
* \ingroup BrickletSegmentDisplay4x7
*/
#define SEGMENT_DISPLAY_4X7_FUNCTION_GET_IDENTITY 255
/**
* \ingroup BrickletSegmentDisplay4x7
*
* Signature: \code void callback(void *user_data) \endcode
*
* This callback is triggered when the counter (see {@link segment_display_4x7_start_counter}) is
* finished.
*/
#define SEGMENT_DISPLAY_4X7_CALLBACK_COUNTER_FINISHED 5
/**
* \ingroup BrickletSegmentDisplay4x7
*
* This constant is used to identify a Segment Display 4x7 Bricklet.
*
* The {@link segment_display_4x7_get_identity} function and the
* {@link IPCON_CALLBACK_ENUMERATE} callback of the IP Connection have a
* \c device_identifier parameter to specify the Brick's or Bricklet's type.
*/
#define SEGMENT_DISPLAY_4X7_DEVICE_IDENTIFIER 237
/**
* \ingroup BrickletSegmentDisplay4x7
*
* This constant represents the display name of a Segment Display 4x7 Bricklet.
*/
#define SEGMENT_DISPLAY_4X7_DEVICE_DISPLAY_NAME "Segment Display 4x7 Bricklet"
/**
* \ingroup BrickletSegmentDisplay4x7
*
* Creates the device object \c segment_display_4x7 with the unique device ID \c uid and adds
* it to the IPConnection \c ipcon.
*/
void segment_display_4x7_create(SegmentDisplay4x7 *segment_display_4x7, const char *uid, IPConnection *ipcon);
/**
* \ingroup BrickletSegmentDisplay4x7
*
* Removes the device object \c segment_display_4x7 from its IPConnection and destroys it.
* The device object cannot be used anymore afterwards.
*/
void segment_display_4x7_destroy(SegmentDisplay4x7 *segment_display_4x7);
/**
* \ingroup BrickletSegmentDisplay4x7
*
* Returns the response expected flag for the function specified by the
* \c function_id parameter. It is *true* if the function is expected to
* send a response, *false* otherwise.
*
* For getter functions this is enabled by default and cannot be disabled,
* because those functions will always send a response. For callback
* configuration functions it is enabled by default too, but can be disabled
* via the segment_display_4x7_set_response_expected function. For setter functions it is
* disabled by default and can be enabled.
*
* Enabling the response expected flag for a setter function allows to
* detect timeouts and other error conditions calls of this setter as well.
* The device will then send a response for this purpose. If this flag is
* disabled for a setter function then no response is send and errors are
* silently ignored, because they cannot be detected.
*/
int segment_display_4x7_get_response_expected(SegmentDisplay4x7 *segment_display_4x7, uint8_t function_id, bool *ret_response_expected);
/**
* \ingroup BrickletSegmentDisplay4x7
*
* Changes the response expected flag of the function specified by the
* \c function_id parameter. This flag can only be changed for setter
* (default value: *false*) and callback configuration functions
* (default value: *true*). For getter functions it is always enabled.
*
* Enabling the response expected flag for a setter function allows to detect
* timeouts and other error conditions calls of this setter as well. The device
* will then send a response for this purpose. If this flag is disabled for a
* setter function then no response is send and errors are silently ignored,
* because they cannot be detected.
*/
int segment_display_4x7_set_response_expected(SegmentDisplay4x7 *segment_display_4x7, uint8_t function_id, bool response_expected);
/**
* \ingroup BrickletSegmentDisplay4x7
*
* Changes the response expected flag for all setter and callback configuration
* functions of this device at once.
*/
int segment_display_4x7_set_response_expected_all(SegmentDisplay4x7 *segment_display_4x7, bool response_expected);
/**
* \ingroup BrickletSegmentDisplay4x7
*
* Registers the given \c function with the given \c callback_id. The
* \c user_data will be passed as the last parameter to the \c function.
*/
void segment_display_4x7_register_callback(SegmentDisplay4x7 *segment_display_4x7, int16_t callback_id, void *function, void *user_data);
/**
* \ingroup BrickletSegmentDisplay4x7
*
* Returns the API version (major, minor, release) of the bindings for this
* device.
*/
int segment_display_4x7_get_api_version(SegmentDisplay4x7 *segment_display_4x7, uint8_t ret_api_version[3]);
/**
* \ingroup BrickletSegmentDisplay4x7
*
* The 7-segment display can be set with bitmaps. Every bit controls one
* segment:
*
* .. image:: /Images/Bricklets/bricklet_segment_display_4x7_bit_order.png
* :scale: 100 %
* :alt: Bit order of one segment
* :align: center
*
* For example to set a "5" you would want to activate segments 0, 2, 3, 5 and 6.
* This is represented by the number 0b01101101 = 0x6d = 109.
*
* The brightness can be set between 0 (dark) and 7 (bright). The colon
* parameter turns the colon of the display on or off.
*/
int segment_display_4x7_set_segments(SegmentDisplay4x7 *segment_display_4x7, uint8_t segments[4], uint8_t brightness, bool colon);
/**
* \ingroup BrickletSegmentDisplay4x7
*
* Returns the segment, brightness and color data as set by
* {@link segment_display_4x7_set_segments}.
*/
int segment_display_4x7_get_segments(SegmentDisplay4x7 *segment_display_4x7, uint8_t ret_segments[4], uint8_t *ret_brightness, bool *ret_colon);
/**
* \ingroup BrickletSegmentDisplay4x7
*
* Starts a counter with the *from* value that counts to the *to*
* value with the each step incremented by *increment*.
* The *length* of the increment is given in ms.
*
* Example: If you set *from* to 0, *to* to 100, *increment* to 1 and
* *length* to 1000, a counter that goes from 0 to 100 with one second
* pause between each increment will be started.
*
* The maximum values for *from*, *to* and *increment* is 9999,
* the minimum value is -999.
*
* Using a negative increment allows to count backwards.
*
* You can stop the counter at every time by calling {@link segment_display_4x7_set_segments}.
*/
int segment_display_4x7_start_counter(SegmentDisplay4x7 *segment_display_4x7, int16_t value_from, int16_t value_to, int16_t increment, uint32_t length);
/**
* \ingroup BrickletSegmentDisplay4x7
*
* Returns the counter value that is currently shown on the display.
*
* If there is no counter running a 0 will be returned.
*/
int segment_display_4x7_get_counter_value(SegmentDisplay4x7 *segment_display_4x7, uint16_t *ret_value);
/**
* \ingroup BrickletSegmentDisplay4x7
*
* 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' or 'd'.
*
* The device identifier numbers can be found :ref:`here <device_identifier>`.
* |device_identifier_constant|
*/
int segment_display_4x7_get_identity(SegmentDisplay4x7 *segment_display_4x7, char ret_uid[8], char ret_connected_uid[8], char *ret_position, uint8_t ret_hardware_version[3], uint8_t ret_firmware_version[3], uint16_t *ret_device_identifier);
#ifdef __cplusplus
}
#endif
#endif
/*
* Copyright (C) 2012-2014 Matthias Bolte <matthias@tinkerforge.com>
* Copyright (C) 2011 Olaf Lüke <olaf@tinkerforge.com>
*
* Redistribution and use in source and binary forms of this file,
* with or without modification, are permitted. See the Creative
* Commons Zero (CC0 1.0) License for more details.
*/
#ifndef IP_CONNECTION_H
#define IP_CONNECTION_H
/**
* \defgroup IPConnection IP Connection
*/
#ifndef __STDC_LIMIT_MACROS
#define __STDC_LIMIT_MACROS
#endif
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#if (!defined __cplusplus && defined __GNUC__) || (defined _MSC_VER && _MSC_VER >= 1600)
#include <stdbool.h>
#endif
#ifdef _WIN32
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
#else
#include <pthread.h>
#include <semaphore.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
enum {
E_OK = 0,
E_TIMEOUT = -1,
E_NO_STREAM_SOCKET = -2,
E_HOSTNAME_INVALID = -3,
E_NO_CONNECT = -4,
E_NO_THREAD = -5,
E_NOT_ADDED = -6, // unused since v2.0
E_ALREADY_CONNECTED = -7,
E_NOT_CONNECTED = -8,
E_INVALID_PARAMETER = -9, // error response from device
E_NOT_SUPPORTED = -10, // error response from device
E_UNKNOWN_ERROR_CODE = -11, // error response from device
E_STREAM_OUT_OF_SYNC = -12
};
#ifdef IPCON_EXPOSE_MILLISLEEP
void millisleep(uint32_t msec);
#endif // IPCON_EXPOSE_MILLISLEEP
#ifdef IPCON_EXPOSE_INTERNALS
typedef struct _Socket Socket;
typedef struct {
#ifdef _WIN32
CRITICAL_SECTION handle;
#else
pthread_mutex_t handle;
#endif
} Mutex;
void mutex_create(Mutex *mutex);
void mutex_destroy(Mutex *mutex);
void mutex_lock(Mutex *mutex);
void mutex_unlock(Mutex *mutex);
typedef struct {
#ifdef _WIN32
HANDLE handle;
#else
pthread_cond_t condition;
pthread_mutex_t mutex;
bool flag;
#endif
} Event;
typedef struct {
#ifdef _WIN32
HANDLE handle;
#else
sem_t object;
sem_t *pointer;
#endif
} Semaphore;
typedef void (*ThreadFunction)(void *opaque);
typedef struct {
#ifdef _WIN32
HANDLE handle;
DWORD id;
#else
pthread_t handle;
#endif
ThreadFunction function;
void *opaque;
} Thread;
typedef struct {
Mutex mutex;
int used;
int allocated;
uint32_t *keys;
void **values;
} Table;
typedef struct _QueueItem {
struct _QueueItem *next;
int kind;
void *data;
} QueueItem;
typedef struct {
Mutex mutex;
Semaphore semaphore;
QueueItem *head;
QueueItem *tail;
} Queue;
#if defined _MSC_VER || defined __BORLANDC__
#pragma pack(push)
#pragma pack(1)
#define ATTRIBUTE_PACKED
#elif defined __GNUC__
#ifdef _WIN32
// workaround struct packing bug in GCC 4.7 on Windows
// http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52991
#define ATTRIBUTE_PACKED __attribute__((gcc_struct, packed))
#else
#define ATTRIBUTE_PACKED __attribute__((packed))
#endif
#else
#error unknown compiler, do not know how to enable struct packing
#endif
typedef struct {
uint32_t uid; // always little endian
uint8_t length;
uint8_t function_id;
uint8_t sequence_number_and_options;
uint8_t error_code_and_future_use;
} ATTRIBUTE_PACKED PacketHeader;
typedef struct {
PacketHeader header;
uint8_t payload[64];
uint8_t optional_data[8];
} ATTRIBUTE_PACKED Packet;
#if defined _MSC_VER || defined __BORLANDC__
#pragma pack(pop)
#endif
#undef ATTRIBUTE_PACKED
#endif // IPCON_EXPOSE_INTERNALS
typedef struct _IPConnection IPConnection;
typedef struct _IPConnectionPrivate IPConnectionPrivate;
typedef struct _Device Device;
typedef struct _DevicePrivate DevicePrivate;
#ifdef IPCON_EXPOSE_INTERNALS
typedef struct _CallbackContext CallbackContext;
typedef struct _HighLevelCallback HighLevelCallback;
/**
* \internal
*/
struct _HighLevelCallback {
bool exists;
void *data;
size_t length;
};
#endif
typedef void (*EnumerateCallbackFunction)(const char *uid,
const char *connected_uid,
char position,
uint8_t hardware_version[3],
uint8_t firmware_version[3],
uint16_t device_identifier,
uint8_t enumeration_type,
void *user_data);
typedef void (*ConnectedCallbackFunction)(uint8_t connect_reason,
void *user_data);
typedef void (*DisconnectedCallbackFunction)(uint8_t disconnect_reason,
void *user_data);
#ifdef IPCON_EXPOSE_INTERNALS
typedef void (*CallbackWrapperFunction)(DevicePrivate *device_p, Packet *packet);
#endif
/**
* \internal
*/
struct _Device {
DevicePrivate *p;
};
#ifdef IPCON_EXPOSE_INTERNALS
#define DEVICE_NUM_FUNCTION_IDS 256
/**
* \internal
*/
struct _DevicePrivate {
int ref_count;
uint32_t uid; // always host endian
IPConnectionPrivate *ipcon_p;
uint8_t api_version[3];
Mutex request_mutex;
uint8_t expected_response_function_id; // protected by request_mutex
uint8_t expected_response_sequence_number; // protected by request_mutex
Mutex response_mutex;
Packet response_packet; // protected by response_mutex
Event response_event;
int response_expected[DEVICE_NUM_FUNCTION_IDS];
Mutex stream_mutex;
void *registered_callbacks[DEVICE_NUM_FUNCTION_IDS * 2];
void *registered_callback_user_data[DEVICE_NUM_FUNCTION_IDS * 2];
CallbackWrapperFunction callback_wrappers[DEVICE_NUM_FUNCTION_IDS];
HighLevelCallback high_level_callbacks[DEVICE_NUM_FUNCTION_IDS];
};
/**
* \internal
*/
enum {
DEVICE_RESPONSE_EXPECTED_INVALID_FUNCTION_ID = 0,
DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE, // getter
DEVICE_RESPONSE_EXPECTED_TRUE, // setter
DEVICE_RESPONSE_EXPECTED_FALSE // setter, default
};
/**
* \internal
*/
void device_create(Device *device, const char *uid,
IPConnectionPrivate *ipcon_p, uint8_t api_version_major,
uint8_t api_version_minor, uint8_t api_version_release);
/**
* \internal
*/
void device_release(DevicePrivate *device_p);
/**
* \internal
*/
int device_get_response_expected(DevicePrivate *device_p, uint8_t function_id,
bool *ret_response_expected);
/**
* \internal
*/
int device_set_response_expected(DevicePrivate *device_p, uint8_t function_id,
bool response_expected);
/**
* \internal
*/
int device_set_response_expected_all(DevicePrivate *device_p, bool response_expected);
/**
* \internal
*/
void device_register_callback(DevicePrivate *device_p, int16_t callback_id,
void *function, void *user_data);
/**
* \internal
*/
int device_get_api_version(DevicePrivate *device_p, uint8_t ret_api_version[3]);
/**
* \internal
*/
int device_send_request(DevicePrivate *device_p, Packet *request, Packet *response);
#endif // IPCON_EXPOSE_INTERNALS
/**
* \ingroup IPConnection
*
* Possible IDs for ipcon_register_callback.
*/
enum {
IPCON_CALLBACK_ENUMERATE = 253,
IPCON_CALLBACK_CONNECTED = 0,
IPCON_CALLBACK_DISCONNECTED = 1
};
/**
* \ingroup IPConnection
*
* Possible values for enumeration_type parameter of EnumerateCallback.
*/
enum {
IPCON_ENUMERATION_TYPE_AVAILABLE = 0,
IPCON_ENUMERATION_TYPE_CONNECTED = 1,
IPCON_ENUMERATION_TYPE_DISCONNECTED = 2
};
/**
* \ingroup IPConnection
*
* Possible values for connect_reason parameter of ConnectedCallback.
*/
enum {
IPCON_CONNECT_REASON_REQUEST = 0,
IPCON_CONNECT_REASON_AUTO_RECONNECT = 1
};
/**
* \ingroup IPConnection
*
* Possible values for disconnect_reason parameter of DisconnectedCallback.
*/
enum {
IPCON_DISCONNECT_REASON_REQUEST = 0,
IPCON_DISCONNECT_REASON_ERROR = 1,
IPCON_DISCONNECT_REASON_SHUTDOWN = 2
};
/**
* \ingroup IPConnection
*
* Possible return values of ipcon_get_connection_state.
*/
enum {
IPCON_CONNECTION_STATE_DISCONNECTED = 0,
IPCON_CONNECTION_STATE_CONNECTED = 1,
IPCON_CONNECTION_STATE_PENDING = 2 // auto-reconnect in progress
};
/**
* \internal
*/
struct _IPConnection {
IPConnectionPrivate *p;
};
#ifdef IPCON_EXPOSE_INTERNALS
#define IPCON_NUM_CALLBACK_IDS 256
#define IPCON_MAX_SECRET_LENGTH 64
/**
* \internal
*/
typedef Device BrickDaemon;
/**
* \internal
*/
struct _IPConnectionPrivate {
#ifdef _WIN32
bool wsa_startup_done; // protected by socket_mutex
#endif
char *host;
uint16_t port;
uint32_t timeout; // in msec
bool auto_reconnect;
bool auto_reconnect_allowed;
bool auto_reconnect_pending;
Mutex sequence_number_mutex;
uint8_t next_sequence_number; // protected by sequence_number_mutex
Mutex authentication_mutex; // protects authentication handshake
uint32_t next_authentication_nonce; // protected by authentication_mutex
Mutex devices_ref_mutex; // protects DevicePrivate.ref_count
Table devices;
void *registered_callbacks[IPCON_NUM_CALLBACK_IDS];
void *registered_callback_user_data[IPCON_NUM_CALLBACK_IDS];
Mutex socket_mutex;
Socket *socket; // protected by socket_mutex
uint64_t socket_id; // protected by socket_mutex
bool receive_flag;
Thread receive_thread; // protected by socket_mutex
CallbackContext *callback;
bool disconnect_probe_flag;
Thread disconnect_probe_thread; // protected by socket_mutex
Event disconnect_probe_event;
Semaphore wait;
BrickDaemon brickd;
};
#endif // IPCON_EXPOSE_INTERNALS
/**
* \ingroup IPConnection
*
* Creates an IP Connection object that can be used to enumerate the available
* devices. It is also required for the constructor of Bricks and Bricklets.
*/
void ipcon_create(IPConnection *ipcon);
/**
* \ingroup IPConnection
*
* Destroys the IP Connection object. Calls ipcon_disconnect internally.
* The connection to the Brick Daemon gets closed and the threads of the
* IP Connection are terminated.
*/
void ipcon_destroy(IPConnection *ipcon);
/**
* \ingroup IPConnection
*
* Creates a TCP/IP connection to the given \c host and c\ port. The host and
* port can point to a Brick Daemon or to a WIFI/Ethernet Extension.
*
* Devices can only be controlled when the connection was established
* successfully.
*
* Blocks until the connection is established and returns an error code if
* there is no Brick Daemon or WIFI/Ethernet Extension listening at the given
* host and port.
*/
int ipcon_connect(IPConnection *ipcon, const char *host, uint16_t port);
/**
* \ingroup IPConnection
*
* Disconnects the TCP/IP connection from the Brick Daemon or the WIFI/Ethernet
* Extension.
*/
int ipcon_disconnect(IPConnection *ipcon);
/**
* \ingroup IPConnection
*
* Performs an authentication handshake with the connected Brick Daemon or
* WIFI/Ethernet Extension. If the handshake succeeds the connection switches
* from non-authenticated to authenticated state and communication can
* continue as normal. If the handshake fails then the connection gets closed.
* Authentication can fail if the wrong secret was used or if authentication
* is not enabled at all on the Brick Daemon or the WIFI/Ethernet Extension.
*
* For more information about authentication see
* http://www.tinkerforge.com/en/doc/Tutorials/Tutorial_Authentication/Tutorial.html
*/
int ipcon_authenticate(IPConnection *ipcon, const char secret[64]);
/**
* \ingroup IPConnection
*
* Can return the following states:
*
* - IPCON_CONNECTION_STATE_DISCONNECTED: No connection is established.
* - IPCON_CONNECTION_STATE_CONNECTED: A connection to the Brick Daemon or
* the WIFI/Ethernet Extension is established.
* - IPCON_CONNECTION_STATE_PENDING: IP Connection is currently trying to
* connect.
*/
int ipcon_get_connection_state(IPConnection *ipcon);
/**
* \ingroup IPConnection
*
* Enables or disables auto-reconnect. If auto-reconnect is enabled,
* the IP Connection will try to reconnect to the previously given
* host and port, if the connection is lost.
*
* Default value is *true*.
*/
void ipcon_set_auto_reconnect(IPConnection *ipcon, bool auto_reconnect);
/**
* \ingroup IPConnection
*
* Returns *true* if auto-reconnect is enabled, *false* otherwise.
*/
bool ipcon_get_auto_reconnect(IPConnection *ipcon);
/**
* \ingroup IPConnection
*
* Sets the timeout in milliseconds for getters and for setters for which the
* response expected flag is activated.
*
* Default timeout is 2500.
*/
void ipcon_set_timeout(IPConnection *ipcon, uint32_t timeout);
/**
* \ingroup IPConnection
*
* Returns the timeout as set by ipcon_set_timeout.
*/
uint32_t ipcon_get_timeout(IPConnection *ipcon);
/**
* \ingroup IPConnection
*
* Broadcasts an enumerate request. All devices will respond with an enumerate
* callback.
*/
int ipcon_enumerate(IPConnection *ipcon);
/**
* \ingroup IPConnection
*
* Stops the current thread until ipcon_unwait is called.
*
* This is useful if you rely solely on callbacks for events, if you want
* to wait for a specific callback or if the IP Connection was created in
* a thread.
*
* ipcon_wait and ipcon_unwait act in the same way as "acquire" and "release"
* of a semaphore.
*/
void ipcon_wait(IPConnection *ipcon);
/**
* \ingroup IPConnection
*
* Unwaits the thread previously stopped by ipcon_wait.
*
* ipcon_wait and ipcon_unwait act in the same way as "acquire" and "release"
* of a semaphore.
*/
void ipcon_unwait(IPConnection *ipcon);
/**
* \ingroup IPConnection
*
* Registers the given \c function with the given \c callback_id. The
* \c user_data will be passed as the last parameter to the \c function.
*/
void ipcon_register_callback(IPConnection *ipcon, int16_t callback_id,
void *function, void *user_data);
#ifdef IPCON_EXPOSE_INTERNALS
/**
* \internal
*/
int packet_header_create(PacketHeader *header, uint8_t length,
uint8_t function_id, IPConnectionPrivate *ipcon_p,
DevicePrivate *device_p);
/**
* \internal
*/
uint8_t packet_header_get_sequence_number(PacketHeader *header);
/**
* \internal
*/
void packet_header_set_sequence_number(PacketHeader *header,
uint8_t sequence_number);
/**
* \internal
*/
uint8_t packet_header_get_response_expected(PacketHeader *header);
/**
* \internal
*/
void packet_header_set_response_expected(PacketHeader *header,
uint8_t response_expected);
/**
* \internal
*/
uint8_t packet_header_get_error_code(PacketHeader *header);
/**
* \internal
*/
int16_t leconvert_int16_to(int16_t native);
/**
* \internal
*/
uint16_t leconvert_uint16_to(uint16_t native);
/**
* \internal
*/
int32_t leconvert_int32_to(int32_t native);
/**
* \internal
*/
uint32_t leconvert_uint32_to(uint32_t native);
/**
* \internal
*/
int64_t leconvert_int64_to(int64_t native);
/**
* \internal
*/
uint64_t leconvert_uint64_to(uint64_t native);
/**
* \internal
*/
float leconvert_float_to(float native);
/**
* \internal
*/
int16_t leconvert_int16_from(int16_t little);
/**
* \internal
*/
uint16_t leconvert_uint16_from(uint16_t little);
/**
* \internal
*/
int32_t leconvert_int32_from(int32_t little);
/**
* \internal
*/
uint32_t leconvert_uint32_from(uint32_t little);
/**
* \internal
*/
int64_t leconvert_int64_from(int64_t little);
/**
* \internal
*/
uint64_t leconvert_uint64_from(uint64_t little);
/**
* \internal
*/
float leconvert_float_from(float little);
#endif // IPCON_EXPOSE_INTERNALS
#ifdef __cplusplus
}
#endif
#endif
Creative Commons Legal Code
CC0 1.0 Universal
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
HEREUNDER.
Statement of Purpose
The laws of most jurisdictions throughout the world automatically confer
exclusive Copyright and Related Rights (defined below) upon the creator
and subsequent owner(s) (each and all, an "owner") of an original work of
authorship and/or a database (each, a "Work").
Certain owners wish to permanently relinquish those rights to a Work for
the purpose of contributing to a commons of creative, cultural and
scientific works ("Commons") that the public can reliably and without fear
of later claims of infringement build upon, modify, incorporate in other
works, reuse and redistribute as freely as possible in any form whatsoever
and for any purposes, including without limitation commercial purposes.
These owners may contribute to the Commons to promote the ideal of a free
culture and the further production of creative, cultural and scientific
works, or to gain reputation or greater distribution for their Work in
part through the use and efforts of others.
For these and/or other purposes and motivations, and without any
expectation of additional consideration or compensation, the person
associating CC0 with a Work (the "Affirmer"), to the extent that he or she
is an owner of Copyright and Related Rights in the Work, voluntarily
elects to apply CC0 to the Work and publicly distribute the Work under its
terms, with knowledge of his or her Copyright and Related Rights in the
Work and the meaning and intended legal effect of CC0 on those rights.
1. Copyright and Related Rights. A Work made available under CC0 may be
protected by copyright and related or neighboring rights ("Copyright and
Related Rights"). Copyright and Related Rights include, but are not
limited to, the following:
i. the right to reproduce, adapt, distribute, perform, display,
communicate, and translate a Work;
ii. moral rights retained by the original author(s) and/or performer(s);
iii. publicity and privacy rights pertaining to a person's image or
likeness depicted in a Work;
iv. rights protecting against unfair competition in regards to a Work,
subject to the limitations in paragraph 4(a), below;
v. rights protecting the extraction, dissemination, use and reuse of data
in a Work;
vi. database rights (such as those arising under Directive 96/9/EC of the
European Parliament and of the Council of 11 March 1996 on the legal
protection of databases, and under any national implementation
thereof, including any amended or successor version of such
directive); and
vii. other similar, equivalent or corresponding rights throughout the
world based on applicable law or treaty, and any national
implementations thereof.
2. Waiver. To the greatest extent permitted by, but not in contravention
of, applicable law, Affirmer hereby overtly, fully, permanently,
irrevocably and unconditionally waives, abandons, and surrenders all of
Affirmer's Copyright and Related Rights and associated claims and causes
of action, whether now known or unknown (including existing as well as
future claims and causes of action), in the Work (i) in all territories
worldwide, (ii) for the maximum duration provided by applicable law or
treaty (including future time extensions), (iii) in any current or future
medium and for any number of copies, and (iv) for any purpose whatsoever,
including without limitation commercial, advertising or promotional
purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
member of the public at large and to the detriment of Affirmer's heirs and
successors, fully intending that such Waiver shall not be subject to
revocation, rescission, cancellation, termination, or any other legal or
equitable action to disrupt the quiet enjoyment of the Work by the public
as contemplated by Affirmer's express Statement of Purpose.
3. Public License Fallback. Should any part of the Waiver for any reason
be judged legally invalid or ineffective under applicable law, then the
Waiver shall be preserved to the maximum extent permitted taking into
account Affirmer's express Statement of Purpose. In addition, to the
extent the Waiver is so judged Affirmer hereby grants to each affected
person a royalty-free, non transferable, non sublicensable, non exclusive,
irrevocable and unconditional license to exercise Affirmer's Copyright and
Related Rights in the Work (i) in all territories worldwide, (ii) for the
maximum duration provided by applicable law or treaty (including future
time extensions), (iii) in any current or future medium and for any number
of copies, and (iv) for any purpose whatsoever, including without
limitation commercial, advertising or promotional purposes (the
"License"). The License shall be deemed effective as of the date CC0 was
applied by Affirmer to the Work. Should any part of the License for any
reason be judged legally invalid or ineffective under applicable law, such
partial invalidity or ineffectiveness shall not invalidate the remainder
of the License, and in such case Affirmer hereby affirms that he or she
will not (i) exercise any of his or her remaining Copyright and Related
Rights in the Work or (ii) assert any associated claims and causes of
action with respect to the Work, in either case contrary to Affirmer's
express Statement of Purpose.
4. Limitations and Disclaimers.
a. No trademark or patent rights held by Affirmer are waived, abandoned,
surrendered, licensed or otherwise affected by this document.
b. Affirmer offers the Work as-is and makes no representations or
warranties of any kind concerning the Work, express, implied,
statutory or otherwise, including without limitation warranties of
title, merchantability, fitness for a particular purpose, non
infringement, or the absence of latent or other defects, accuracy, or
the present or absence of errors, whether or not discoverable, all to
the greatest extent permissible under applicable law.
c. Affirmer disclaims responsibility for clearing rights of other persons
that may apply to the Work or any use thereof, including without
limitation any person's Copyright and Related Rights in the Work.
Further, Affirmer disclaims responsibility for obtaining any necessary
consents, permissions or other rights required for any use of the
Work.
d. Affirmer understands and acknowledges that Creative Commons is not a
party to this document and has no duty or obligation with respect to
this CC0 or use of the Work.
File added
File added
# The default application name.
ifndef APPL
APPL=my_app
endif
# The default build path.
ifndef BPATH
BPATH=build
endif
# The compiler.
ifndef CROSSCC
CROSSCC=gcc
endif
# The linker.
ifndef CROSSLD
CROSSLD=gcc
endif
# The flags which are passed to the compiler and the linker.
CCFLAGS+=-std=gnu99 -Wall -pthread -lwiringPi -pedantic -c ${patsubst %,-I%,${subst :, ,${IPATH}}}
LDFLAGS+=-std=gnu99 -Wall -pthread -lpthread -lwiringPi -pedantic
# The default rules, i.e. the entry point.
all: ${BPATH}
all: ${BPATH}/${APPL}.run
# The target to clean the build directory.
clean:
@echo "cleaning up path '${BPATH}' ..."
@rm -rf ${BPATH}
# The rule for creating the build directory.
${BPATH}:
@echo "creating path '${BPATH}' ..."
@mkdir ${BPATH}
# The rule for building an object file from the corresponding C source file.
${BPATH}/%.o: %.c
@echo "compiling file '${<}' ..."
@${CROSSCC} ${CCFLAGS} -o ${@} ${<}
# The rule for linking an application.
${BPATH}/%.run:
@echo "linking application '${@}' ..."
@${CROSSLD} ${LDFLAGS} -o ${@} $(filter %.o %.a, ${^})
\ No newline at end of file
/* generated by AutoFOCUS 3 (2.11.0) on Tue May 16 17:42:09 CEST 2017 */
#ifndef __HEADER_data_dictionary_h
#define __HEADER_data_dictionary_h
#if defined(__cplusplus)
typedef bool GEN_TYPE_boolean;
#else
typedef enum Enum_TYPE_boolean {
false = 0, true = 1
} GEN_TYPE_boolean;
#endif
typedef int GEN_TYPE_int;
typedef double GEN_TYPE_double;
/*extern GEN_TYPE_double abs(GEN_TYPE_double _V);
extern GEN_TYPE_double arctan(GEN_TYPE_double _V);
extern GEN_TYPE_double cos(GEN_TYPE_double _V);
extern GEN_TYPE_double cot(GEN_TYPE_double _V);
extern GEN_TYPE_double e();
extern GEN_TYPE_double exp(GEN_TYPE_double _V);
extern GEN_TYPE_double ln(GEN_TYPE_double _V);
extern GEN_TYPE_double pi();
extern GEN_TYPE_double sgn(GEN_TYPE_double _V);
extern GEN_TYPE_double sin(GEN_TYPE_double _V);
extern GEN_TYPE_double sqrt(GEN_TYPE_double _V);
extern GEN_TYPE_double tan(GEN_TYPE_double _V);
extern GEN_TYPE_double _sqrt(GEN_TYPE_double _X,GEN_TYPE_double _V);
extern GEN_TYPE_double pow(GEN_TYPE_double _V,GEN_TYPE_double _N);
extern GEN_TYPE_double factorial(GEN_TYPE_double _V);
extern GEN_TYPE_double min(GEN_TYPE_double _a,GEN_TYPE_double _b);
extern GEN_TYPE_double max(GEN_TYPE_double _a,GEN_TYPE_double _b);
extern GEN_TYPE_double rad2deg(GEN_TYPE_double _A);
extern GEN_TYPE_double deg2rad(GEN_TYPE_double _A);*/
#endif // __HEADER_data_dictionary_h
#ifndef __CANCONNECTOR_H
#define __CANCONNECTOR_H
#include <stdio.h>
#include "inc/libcansocket.h"
#include "inc-gen/data_dictionary.h"
// types
typedef const char* CAN_MSG_T;
typedef unsigned long CAN_CLK_T;
// constants
extern const char* CAN_DEVICE_NAME;
// send and receive
void can_send();
void can_send_clock(CAN_CLK_T counter);
void can_receive();
CAN_CLK_T can_receive_clock();
// init, terminate, prepare
void can_init();
void can_term();
void prepare_input_CanConnector();
void finish_input_CanConnector();
void prepare_output_CanConnector();
void finish_output_CanConnector();
// noval
GEN_TYPE_boolean can_is_noval(CAN_MSG_T msg);
GEN_TYPE_boolean can_set_noval(CAN_MSG_T msg);
// readers
GEN_TYPE_boolean can_read_bool(CAN_MSG_T msg);
GEN_TYPE_double can_read_double(CAN_MSG_T msg);
GEN_TYPE_int can_read_int(CAN_MSG_T pomsgrt);
// writers
void can_write_bool(CAN_MSG_T msg, GEN_TYPE_boolean value);
void can_write_double(CAN_MSG_T msg, GEN_TYPE_double value);
void can_write_int(CAN_MSG_T msg, GEN_TYPE_int value);
#endif // __CANCONNECTOR_H
#ifndef __GPIO_H
#define __GPIO_H
#include <stdio.h>
#include <wiringPi.h>
#include "inc-gen/data_dictionary.h"
// types
typedef int GPIO_PIN_T;
// init, term
void gpio_init(GPIO_PIN_T pin);
void gpio_init_in(GPIO_PIN_T pin);
void gpio_init_out(GPIO_PIN_T pin);
void gpio_term(GPIO_PIN_T pin);
// noval
GEN_TYPE_boolean gpio_is_noval(GPIO_PIN_T pin);
void gpio_set_noval(GPIO_PIN_T pin);
// readers
GEN_TYPE_boolean gpio_read(GPIO_PIN_T pin);
// writers
void gpio_write(GPIO_PIN_T pin, GEN_TYPE_boolean value);
#endif // __GPIO_H
#ifndef __GAMEPAD_H
#define __GAMEPAD_H
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#include <unistd.h>
#include "inc-gen/data_dictionary.h"
// constants
#define JS_EVENT_BUTTON 0x01
#define JS_EVENT_AXIS 0x02
#define JS_EVENT_INIT 0x80
extern const char* GP_DEVICE_NAME;
// types etc
union input_events {
struct input_btns {
int16_t js1_lr; // LX
int16_t js1_ud; // LY
int16_t js2_lr; // RX
int16_t js2_ud; // RY
int16_t gp_lr; // GPX
int16_t gp_ud; // GPY
int16_t bt_tri; // BTN1
int16_t bt_cir; // BTN2
int16_t bt_x; // BTN3
int16_t bt_sqr; // BTN4
int16_t bt_l1; // L1
int16_t bt_r1; // R1
int16_t bt_l2; // L2
int16_t bt_r2; // R2
int16_t bt_sel; // SELECT
int16_t bt_strt;// START
int16_t js1_bt; // LCLICK
int16_t js2_bt; // RCLICK
} btns;
int16_t inps[18];
};
struct js_event {
uint32_t time; // event time stamp in millisecons
int16_t value; // value
uint8_t type; // event type
uint8_t number; // axis/button number
};
extern volatile union input_events ie;
// worker
void* gp_worker(void* pt_args);
// init, term
void gp_init();
void gp_term();
// readers
GEN_TYPE_boolean gp_btn1_read();
GEN_TYPE_boolean gp_btn2_read();
GEN_TYPE_boolean gp_btn3_read();
GEN_TYPE_boolean gp_btn4_read();
GEN_TYPE_boolean gp_btnL1_read();
GEN_TYPE_boolean gp_btnL2_read();
GEN_TYPE_boolean gp_btnR1_read();
GEN_TYPE_boolean gp_btnR2_read();
GEN_TYPE_double gp_btnLX_read();
GEN_TYPE_double gp_btnLY_read();
GEN_TYPE_double gp_btnRX_read();
GEN_TYPE_double gp_btnRY_read();
// noval
GEN_TYPE_boolean gp_btn1_is_noval();
GEN_TYPE_boolean gp_btn2_is_noval();
GEN_TYPE_boolean gp_btn3_is_noval();
GEN_TYPE_boolean gp_btn4_is_noval();
GEN_TYPE_boolean gp_btnL1_is_noval();
GEN_TYPE_boolean gp_btnL2_is_noval();
GEN_TYPE_boolean gp_btnR1_is_noval();
GEN_TYPE_boolean gp_btnR2_is_noval();
GEN_TYPE_boolean gp_btnLX_is_noval();
GEN_TYPE_boolean gp_btnLY_is_noval();
GEN_TYPE_boolean gp_btnRX_is_noval();
GEN_TYPE_boolean gp_btnRY_is_noval();
#endif // __GAMEPAD_H
#ifndef __LASERRANGEFINDER_H
#define __LASERRANGEFINDER_H
#include <stdlib.h>
#include "inc-gen/data_dictionary.h"
#include "inc/libuart.h"
// constants
const char* LRF_DEVICE_NAME;
// init, terminate
void lrf_init();
void lrf_term();
// getters
GEN_TYPE_boolean lrf_is_noval();
GEN_TYPE_int lrf_read();
#endif // __LASERRANGEFINDER_H
#ifndef __PWM_H
#define __PWM_H
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <termios.h>
#include <fcntl.h>
#include <sys/stat.h>
#include "inc-gen/data_dictionary.h"
#include "inc/libmaestro.h"
// macros
// 6072 is the value for 0, max. value to motor is currently 7572
// from AF3 you get a max. speed value in mm/s : 1471
// Hence, add the constant 6072 and map values -1471-1471 to -1500-1500
#define PWM_ADJUST_VALUE(x) (6072 + 1500 * x /1471)
// types
typedef unsigned char PWM_CHANNEL_T;
// constants
extern const int PWM_SLEEP_TIME;
extern const char* PWM_DEVICE_NAME;
extern const size_t PWM_MAX_NO_CHANNELS;
// worker
void* pwm_worker(void* pt_args);
// init, term
void pwm_init(PWM_CHANNEL_T channel);
void pwm_term(PWM_CHANNEL_T channel);
// writers
void pwm_write(PWM_CHANNEL_T channel, GEN_TYPE_int value);
void pwm_set_noval(PWM_CHANNEL_T channel);
#endif // __PWM_H
#ifndef __IO_H
#define __IO_H
#include "inc-gen/data_dictionary.h"
// init, terminate
void init_left_stick();
void term_left_stick();
void init_right_stick();
void term_right_stick();
// NOVAL
GEN_TYPE_boolean is_noval_left_stick();
GEN_TYPE_boolean is_noval_right_stick();
// readers
GEN_TYPE_double read_left_stick();
GEN_TYPE_double read_right_stick();
// writers
void write_left_stick(GEN_TYPE_double value);
void write_right_stick(GEN_TYPE_double value);
#endif // __IO_H
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment