Class: Tinkerforge::BrickRED
- Defined in:
- lib/tinkerforge/brick_red.rb
Overview
Executes user programs and controls other Bricks/Bricklets standalone
Constant Summary collapse
- DEVICE_IDENTIFIER =
:nodoc:
17- DEVICE_DISPLAY_NAME =
:nodoc:
'RED Brick'- CALLBACK_ASYNC_FILE_READ =
This callback reports the result of a call to the BrickRED#read_file_async function.
30- CALLBACK_ASYNC_FILE_WRITE =
This callback reports the result of a call to the BrickRED#write_file_async function.
31- CALLBACK_FILE_EVENTS_OCCURRED =
32- CALLBACK_PROCESS_STATE_CHANGED =
45- CALLBACK_PROGRAM_SCHEDULER_STATE_CHANGED =
65- CALLBACK_PROGRAM_PROCESS_SPAWNED =
66- FUNCTION_CREATE_SESSION =
:nodoc:
1- FUNCTION_EXPIRE_SESSION =
:nodoc:
2- FUNCTION_EXPIRE_SESSION_UNCHECKED =
:nodoc:
3- FUNCTION_KEEP_SESSION_ALIVE =
:nodoc:
4- FUNCTION_RELEASE_OBJECT =
:nodoc:
5- FUNCTION_RELEASE_OBJECT_UNCHECKED =
:nodoc:
6- FUNCTION_ALLOCATE_STRING =
:nodoc:
7- FUNCTION_TRUNCATE_STRING =
:nodoc:
8- FUNCTION_GET_STRING_LENGTH =
:nodoc:
9- FUNCTION_SET_STRING_CHUNK =
:nodoc:
10- FUNCTION_GET_STRING_CHUNK =
:nodoc:
11- FUNCTION_ALLOCATE_LIST =
:nodoc:
12- FUNCTION_GET_LIST_LENGTH =
:nodoc:
13- FUNCTION_GET_LIST_ITEM =
:nodoc:
14- FUNCTION_APPEND_TO_LIST =
:nodoc:
15- FUNCTION_REMOVE_FROM_LIST =
:nodoc:
16- FUNCTION_OPEN_FILE =
:nodoc:
17- FUNCTION_CREATE_PIPE =
:nodoc:
18- FUNCTION_GET_FILE_INFO =
:nodoc:
19- FUNCTION_READ_FILE =
:nodoc:
20- FUNCTION_READ_FILE_ASYNC =
:nodoc:
21- FUNCTION_ABORT_ASYNC_FILE_READ =
:nodoc:
22- FUNCTION_WRITE_FILE =
:nodoc:
23- FUNCTION_WRITE_FILE_UNCHECKED =
:nodoc:
24- FUNCTION_WRITE_FILE_ASYNC =
:nodoc:
25- FUNCTION_SET_FILE_POSITION =
:nodoc:
26- FUNCTION_GET_FILE_POSITION =
:nodoc:
27- FUNCTION_SET_FILE_EVENTS =
:nodoc:
28- FUNCTION_GET_FILE_EVENTS =
:nodoc:
29- FUNCTION_OPEN_DIRECTORY =
:nodoc:
33- FUNCTION_GET_DIRECTORY_NAME =
:nodoc:
34- FUNCTION_GET_NEXT_DIRECTORY_ENTRY =
:nodoc:
35- FUNCTION_REWIND_DIRECTORY =
:nodoc:
36- FUNCTION_CREATE_DIRECTORY =
:nodoc:
37- FUNCTION_GET_PROCESSES =
:nodoc:
38- FUNCTION_SPAWN_PROCESS =
:nodoc:
39- FUNCTION_KILL_PROCESS =
:nodoc:
40- FUNCTION_GET_PROCESS_COMMAND =
:nodoc:
41- FUNCTION_GET_PROCESS_IDENTITY =
:nodoc:
42- FUNCTION_GET_PROCESS_STDIO =
:nodoc:
43- FUNCTION_GET_PROCESS_STATE =
:nodoc:
44- FUNCTION_GET_PROGRAMS =
:nodoc:
46- FUNCTION_DEFINE_PROGRAM =
:nodoc:
47- FUNCTION_PURGE_PROGRAM =
:nodoc:
48- FUNCTION_GET_PROGRAM_IDENTIFIER =
:nodoc:
49- FUNCTION_GET_PROGRAM_ROOT_DIRECTORY =
:nodoc:
50- FUNCTION_SET_PROGRAM_COMMAND =
:nodoc:
51- FUNCTION_GET_PROGRAM_COMMAND =
:nodoc:
52- FUNCTION_SET_PROGRAM_STDIO_REDIRECTION =
:nodoc:
53- FUNCTION_GET_PROGRAM_STDIO_REDIRECTION =
:nodoc:
54- FUNCTION_SET_PROGRAM_SCHEDULE =
:nodoc:
55- FUNCTION_GET_PROGRAM_SCHEDULE =
:nodoc:
56- FUNCTION_GET_PROGRAM_SCHEDULER_STATE =
:nodoc:
57- FUNCTION_CONTINUE_PROGRAM_SCHEDULE =
:nodoc:
58- FUNCTION_START_PROGRAM =
:nodoc:
59- FUNCTION_GET_LAST_SPAWNED_PROGRAM_PROCESS =
:nodoc:
60- FUNCTION_GET_CUSTOM_PROGRAM_OPTION_NAMES =
:nodoc:
61- FUNCTION_SET_CUSTOM_PROGRAM_OPTION_VALUE =
:nodoc:
62- FUNCTION_GET_CUSTOM_PROGRAM_OPTION_VALUE =
:nodoc:
63- FUNCTION_REMOVE_CUSTOM_PROGRAM_OPTION =
:nodoc:
64- FUNCTION_GET_IDENTITY =
:nodoc:
255- ERROR_CODE_SUCCESS =
:nodoc:
0- ERROR_CODE_UNKNOWN_ERROR =
:nodoc:
1- ERROR_CODE_INVALID_OPERATION =
:nodoc:
2- ERROR_CODE_OPERATION_ABORTED =
:nodoc:
3- ERROR_CODE_INTERNAL_ERROR =
:nodoc:
4- ERROR_CODE_UNKNOWN_SESSION_ID =
:nodoc:
5- ERROR_CODE_NO_FREE_SESSION_ID =
:nodoc:
6- ERROR_CODE_UNKNOWN_OBJECT_ID =
:nodoc:
7- ERROR_CODE_NO_FREE_OBJECT_ID =
:nodoc:
8- ERROR_CODE_OBJECT_IS_LOCKED =
:nodoc:
9- ERROR_CODE_NO_MORE_DATA =
:nodoc:
10- ERROR_CODE_WRONG_LIST_ITEM_TYPE =
:nodoc:
11- ERROR_CODE_PROGRAM_IS_PURGED =
:nodoc:
12- ERROR_CODE_INVALID_PARAMETER =
:nodoc:
128- ERROR_CODE_NO_FREE_MEMORY =
:nodoc:
129- ERROR_CODE_NO_FREE_SPACE =
:nodoc:
130- ERROR_CODE_ACCESS_DENIED =
:nodoc:
121- ERROR_CODE_ALREADY_EXISTS =
:nodoc:
132- ERROR_CODE_DOES_NOT_EXIST =
:nodoc:
133- ERROR_CODE_INTERRUPTED =
:nodoc:
134- ERROR_CODE_IS_DIRECTORY =
:nodoc:
135- ERROR_CODE_NOT_A_DIRECTORY =
:nodoc:
136- ERROR_CODE_WOULD_BLOCK =
:nodoc:
137- ERROR_CODE_OVERFLOW =
:nodoc:
138- ERROR_CODE_BAD_FILE_DESCRIPTOR =
:nodoc:
139- ERROR_CODE_OUT_OF_RANGE =
:nodoc:
140- ERROR_CODE_NAME_TOO_LONG =
:nodoc:
141- ERROR_CODE_INVALID_SEEK =
:nodoc:
142- ERROR_CODE_NOT_SUPPORTED =
:nodoc:
143- ERROR_CODE_TOO_MANY_OPEN_FILES =
:nodoc:
144- OBJECT_TYPE_STRING =
:nodoc:
0- OBJECT_TYPE_LIST =
:nodoc:
1- OBJECT_TYPE_FILE =
:nodoc:
2- OBJECT_TYPE_DIRECTORY =
:nodoc:
3- OBJECT_TYPE_PROCESS =
:nodoc:
4- OBJECT_TYPE_PROGRAM =
:nodoc:
5- FILE_FLAG_READ_ONLY =
:nodoc:
1- FILE_FLAG_WRITE_ONLY =
:nodoc:
2- FILE_FLAG_READ_WRITE =
:nodoc:
4- FILE_FLAG_APPEND =
:nodoc:
8- FILE_FLAG_CREATE =
:nodoc:
16- FILE_FLAG_EXCLUSIVE =
:nodoc:
32- FILE_FLAG_NON_BLOCKING =
:nodoc:
64- FILE_FLAG_TRUNCATE =
:nodoc:
128- FILE_FLAG_TEMPORARY =
:nodoc:
256- FILE_FLAG_REPLACE =
:nodoc:
512- FILE_PERMISSION_USER_ALL =
:nodoc:
448- FILE_PERMISSION_USER_READ =
:nodoc:
256- FILE_PERMISSION_USER_WRITE =
:nodoc:
128- FILE_PERMISSION_USER_EXECUTE =
:nodoc:
64- FILE_PERMISSION_GROUP_ALL =
:nodoc:
56- FILE_PERMISSION_GROUP_READ =
:nodoc:
32- FILE_PERMISSION_GROUP_WRITE =
:nodoc:
16- FILE_PERMISSION_GROUP_EXECUTE =
:nodoc:
8- FILE_PERMISSION_OTHERS_ALL =
:nodoc:
7- FILE_PERMISSION_OTHERS_READ =
:nodoc:
4- FILE_PERMISSION_OTHERS_WRITE =
:nodoc:
2- FILE_PERMISSION_OTHERS_EXECUTE =
:nodoc:
1- PIPE_FLAG_NON_BLOCKING_READ =
:nodoc:
1- PIPE_FLAG_NON_BLOCKING_WRITE =
:nodoc:
2- FILE_TYPE_UNKNOWN =
:nodoc:
0- FILE_TYPE_REGULAR =
:nodoc:
1- FILE_TYPE_DIRECTORY =
:nodoc:
2- FILE_TYPE_CHARACTER =
:nodoc:
3- FILE_TYPE_BLOCK =
:nodoc:
4- FILE_TYPE_FIFO =
:nodoc:
5- FILE_TYPE_SYMLINK =
:nodoc:
6- FILE_TYPE_SOCKET =
:nodoc:
7- FILE_TYPE_PIPE =
:nodoc:
8- FILE_ORIGIN_BEGINNING =
:nodoc:
0- FILE_ORIGIN_CURRENT =
:nodoc:
1- FILE_ORIGIN_END =
:nodoc:
2- FILE_EVENT_READABLE =
:nodoc:
1- FILE_EVENT_WRITABLE =
:nodoc:
2- DIRECTORY_ENTRY_TYPE_UNKNOWN =
:nodoc:
0- DIRECTORY_ENTRY_TYPE_REGULAR =
:nodoc:
1- DIRECTORY_ENTRY_TYPE_DIRECTORY =
:nodoc:
2- DIRECTORY_ENTRY_TYPE_CHARACTER =
:nodoc:
3- DIRECTORY_ENTRY_TYPE_BLOCK =
:nodoc:
4- DIRECTORY_ENTRY_TYPE_FIFO =
:nodoc:
5- DIRECTORY_ENTRY_TYPE_SYMLINK =
:nodoc:
6- DIRECTORY_ENTRY_TYPE_SOCKET =
:nodoc:
7- DIRECTORY_FLAG_RECURSIVE =
:nodoc:
1- DIRECTORY_FLAG_EXCLUSIVE =
:nodoc:
2- PROCESS_SIGNAL_INTERRUPT =
:nodoc:
2- PROCESS_SIGNAL_QUIT =
:nodoc:
3- PROCESS_SIGNAL_ABORT =
:nodoc:
6- PROCESS_SIGNAL_KILL =
:nodoc:
9- PROCESS_SIGNAL_USER1 =
:nodoc:
10- PROCESS_SIGNAL_USER2 =
:nodoc:
12- PROCESS_SIGNAL_TERMINATE =
:nodoc:
15- PROCESS_SIGNAL_CONTINUE =
:nodoc:
18- PROCESS_SIGNAL_STOP =
:nodoc:
19- PROCESS_STATE_UNKNOWN =
:nodoc:
0- PROCESS_STATE_RUNNING =
:nodoc:
1- PROCESS_STATE_ERROR =
:nodoc:
2- PROCESS_STATE_EXITED =
:nodoc:
3- PROCESS_STATE_KILLED =
:nodoc:
4- PROCESS_STATE_STOPPED =
:nodoc:
5- PROGRAM_STDIO_REDIRECTION_DEV_NULL =
:nodoc:
0- PROGRAM_STDIO_REDIRECTION_PIPE =
:nodoc:
1- PROGRAM_STDIO_REDIRECTION_FILE =
:nodoc:
2- PROGRAM_STDIO_REDIRECTION_INDIVIDUAL_LOG =
:nodoc:
3- PROGRAM_STDIO_REDIRECTION_CONTINUOUS_LOG =
:nodoc:
4- PROGRAM_STDIO_REDIRECTION_STDOUT =
:nodoc:
5- PROGRAM_START_MODE_NEVER =
:nodoc:
0- PROGRAM_START_MODE_ALWAYS =
:nodoc:
1- PROGRAM_START_MODE_INTERVAL =
:nodoc:
2- PROGRAM_START_MODE_CRON =
:nodoc:
3- PROGRAM_SCHEDULER_STATE_STOPPED =
:nodoc:
0- PROGRAM_SCHEDULER_STATE_RUNNING =
:nodoc:
1
Constants inherited from Device
Device::RESPONSE_EXPECTED_ALWAYS_FALSE, Device::RESPONSE_EXPECTED_ALWAYS_TRUE, Device::RESPONSE_EXPECTED_FALSE, Device::RESPONSE_EXPECTED_INVALID_FUNCTION_ID, Device::RESPONSE_EXPECTED_TRUE
Instance Attribute Summary
Attributes inherited from Device
#callback_formats, #expected_response_function_id, #expected_response_sequence_number, #registered_callbacks, #uid
Instance Method Summary collapse
-
#abort_async_file_read(file_id) ⇒ Object
Aborts a BrickRED#read_file_async operation in progress.
-
#allocate_list(length_to_reserve, session_id) ⇒ Object
Allocates a new list object and reserves memory for
length_to_reserveitems. -
#allocate_string(length_to_reserve, buffer, session_id) ⇒ Object
Allocates a new string object, reserves
length_to_reservebytes memory for it and sets up to the first 60 bytes. -
#append_to_list(list_id, item_object_id) ⇒ Object
Appends an object to a list object and increases the reference count of the appended object by one.
- #continue_program_schedule(program_id) ⇒ Object
-
#create_directory(name_string_id, flags, permissions, uid, gid) ⇒ Object
FIXME: name has to be absolute.
-
#create_pipe(flags, length, session_id) ⇒ Object
Creates a new pipe and allocates a new file object for it.
- #create_session(lifetime) ⇒ Object
- #define_program(identifier_string_id, session_id) ⇒ Object
- #expire_session(session_id) ⇒ Object
- #expire_session_unchecked(session_id) ⇒ Object
- #get_custom_program_option_names(program_id, session_id) ⇒ Object
- #get_custom_program_option_value(program_id, name_string_id, session_id) ⇒ Object
-
#get_directory_name(directory_id, session_id) ⇒ Object
Returns the name of a directory object, as passed to BrickRED#open_directory, and the resulting error code.
- #get_file_events(file_id) ⇒ Object
-
#get_file_info(file_id, session_id) ⇒ Object
Returns various information about a file and the resulting error code.
-
#get_file_position(file_id) ⇒ Object
Returns the current seek position of a file object in bytes and returns the resulting error code.
-
#get_identity ⇒ Object
Returns the UID, the UID where the Brick is connected to, the position, the hardware and firmware version as well as the device identifier.
- #get_last_spawned_program_process(program_id, session_id) ⇒ Object
-
#get_list_item(list_id, index, session_id) ⇒ Object
Returns the object ID and type of the object stored at
indexin a list object and returns the resulting error code. -
#get_list_length(list_id) ⇒ Object
Returns the length of a list object in items and the resulting error code.
-
#get_next_directory_entry(directory_id, session_id) ⇒ Object
Returns the next entry in a directory object and the resulting error code.
-
#get_process_command(process_id, session_id) ⇒ Object
Returns the executable, arguments, environment and working directory used to spawn a process object, as passed to BrickRED#spawn_process, and the resulting error code.
-
#get_process_identity(process_id) ⇒ Object
Returns the process ID and the user and group ID used to spawn a process object, as passed to BrickRED#spawn_process, and the resulting error code.
-
#get_process_state(process_id) ⇒ Object
Returns the current state, timestamp and exit code of a process object, and the resulting error code.
-
#get_process_stdio(process_id, session_id) ⇒ Object
Returns the stdin, stdout and stderr files used to spawn a process object, as passed to BrickRED#spawn_process, and the resulting error code.
- #get_processes(session_id) ⇒ Object
-
#get_program_command(program_id, session_id) ⇒ Object
FIXME: working directory is relative to <home>/programs/<identifier>/bin.
- #get_program_identifier(program_id, session_id) ⇒ Object
-
#get_program_root_directory(program_id, session_id) ⇒ Object
FIXME: root directory is absolute: <home>/programs/<identifier>.
- #get_program_schedule(program_id, session_id) ⇒ Object
-
#get_program_scheduler_state(program_id, session_id) ⇒ Object
FIXME: message is currently valid in error-occurred state only.
-
#get_program_stdio_redirection(program_id, session_id) ⇒ Object
FIXME: stdio file names are relative to <home>/programs/<identifier>/bin.
- #get_programs(session_id) ⇒ Object
-
#get_string_chunk(string_id, offset) ⇒ Object
Returns a chunk up to 63 bytes from a string object beginning at
offsetand returns the resulting error code. -
#get_string_length(string_id) ⇒ Object
Returns the length of a string object in bytes and the resulting error code.
-
#initialize(uid, ipcon) ⇒ BrickRED
constructor
Creates an object with the unique device ID
uidand adds it to the IP Connectionipcon. - #keep_session_alive(session_id, lifetime) ⇒ Object
-
#kill_process(process_id, signal) ⇒ Object
Sends a UNIX signal to a process object and returns the resulting error code.
-
#open_directory(name_string_id, session_id) ⇒ Object
Opens an existing directory and allocates a new directory object for it.
-
#open_file(name_string_id, flags, permissions, uid, gid, session_id) ⇒ Object
Opens an existing file or creates a new file and allocates a new file object for it.
- #purge_program(program_id, cookie) ⇒ Object
-
#read_file(file_id, length_to_read) ⇒ Object
Reads up to 62 bytes from a file object.
-
#read_file_async(file_id, length_to_read) ⇒ Object
Reads up to 2\ :sup:
63\ - 1 bytes from a file object asynchronously. -
#register_callback(id, &block) ⇒ Object
Registers a callback with ID
idto the blockblock. -
#release_object(object_id, session_id) ⇒ Object
Decreases the reference count of an object by one and returns the resulting error code.
- #release_object_unchecked(object_id, session_id) ⇒ Object
- #remove_custom_program_option(program_id, name_string_id) ⇒ Object
-
#remove_from_list(list_id, index) ⇒ Object
Removes the object stored at
indexfrom a list object and decreases the reference count of the removed object by one. -
#rewind_directory(directory_id) ⇒ Object
Rewinds a directory object and returns the resulting error code.
- #set_custom_program_option_value(program_id, name_string_id, value_string_id) ⇒ Object
- #set_file_events(file_id, events) ⇒ Object
-
#set_file_position(file_id, offset, origin) ⇒ Object
Set the current seek position of a file object in bytes relative to
origin. -
#set_program_command(program_id, executable_string_id, arguments_list_id, environment_list_id, working_directory_string_id) ⇒ Object
FIXME: working directory is relative to <home>/programs/<identifier>/bin.
- #set_program_schedule(program_id, start_mode, continue_after_error, start_interval, start_fields_string_id) ⇒ Object
-
#set_program_stdio_redirection(program_id, stdin_redirection, stdin_file_name_string_id, stdout_redirection, stdout_file_name_string_id, stderr_redirection, stderr_file_name_string_id) ⇒ Object
FIXME: stdio file names are relative to <home>/programs/<identifier>/bin.
-
#set_string_chunk(string_id, offset, buffer) ⇒ Object
Sets a chunk of up to 58 bytes in a string object beginning at
offset. - #spawn_process(executable_string_id, arguments_list_id, environment_list_id, working_directory_string_id, uid, gid, stdin_file_id, stdout_file_id, stderr_file_id, session_id) ⇒ Object
- #start_program(program_id) ⇒ Object
-
#truncate_string(string_id, length) ⇒ Object
Truncates a string object to
lengthbytes and returns the resulting error code. -
#write_file(file_id, buffer, length_to_write) ⇒ Object
Writes up to 61 bytes to a file object.
-
#write_file_async(file_id, buffer, length_to_write) ⇒ Object
Writes up to 61 bytes to a file object.
-
#write_file_unchecked(file_id, buffer, length_to_write) ⇒ Object
Writes up to 61 bytes to a file object.
Methods inherited from Device
#dequeue_response, #enqueue_response, #get_api_version, #get_response_expected, #send_request, #set_response_expected, #set_response_expected_all
Constructor Details
#initialize(uid, ipcon) ⇒ BrickRED
Creates an object with the unique device ID uid and adds it to the IP Connection ipcon.
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 |
# File 'lib/tinkerforge/brick_red.rb', line 214 def initialize(uid, ipcon) super uid, ipcon @api_version = [2, 0, 0] @response_expected[FUNCTION_CREATE_SESSION] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_EXPIRE_SESSION] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_EXPIRE_SESSION_UNCHECKED] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_KEEP_SESSION_ALIVE] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_RELEASE_OBJECT] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_RELEASE_OBJECT_UNCHECKED] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_ALLOCATE_STRING] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_TRUNCATE_STRING] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_GET_STRING_LENGTH] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_STRING_CHUNK] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_GET_STRING_CHUNK] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_ALLOCATE_LIST] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_GET_LIST_LENGTH] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_GET_LIST_ITEM] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_APPEND_TO_LIST] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_REMOVE_FROM_LIST] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_OPEN_FILE] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_CREATE_PIPE] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_GET_FILE_INFO] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_READ_FILE] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_READ_FILE_ASYNC] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_ABORT_ASYNC_FILE_READ] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_WRITE_FILE] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_WRITE_FILE_UNCHECKED] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_WRITE_FILE_ASYNC] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_SET_FILE_POSITION] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_GET_FILE_POSITION] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_FILE_EVENTS] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_GET_FILE_EVENTS] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[CALLBACK_ASYNC_FILE_READ] = RESPONSE_EXPECTED_ALWAYS_FALSE @response_expected[CALLBACK_ASYNC_FILE_WRITE] = RESPONSE_EXPECTED_ALWAYS_FALSE @response_expected[CALLBACK_FILE_EVENTS_OCCURRED] = RESPONSE_EXPECTED_ALWAYS_FALSE @response_expected[FUNCTION_OPEN_DIRECTORY] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_GET_DIRECTORY_NAME] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_GET_NEXT_DIRECTORY_ENTRY] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_REWIND_DIRECTORY] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_CREATE_DIRECTORY] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_GET_PROCESSES] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SPAWN_PROCESS] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_KILL_PROCESS] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_GET_PROCESS_COMMAND] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_GET_PROCESS_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_GET_PROCESS_STDIO] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_GET_PROCESS_STATE] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[CALLBACK_PROCESS_STATE_CHANGED] = RESPONSE_EXPECTED_ALWAYS_FALSE @response_expected[FUNCTION_GET_PROGRAMS] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_DEFINE_PROGRAM] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_PURGE_PROGRAM] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_GET_PROGRAM_IDENTIFIER] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_GET_PROGRAM_ROOT_DIRECTORY] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_PROGRAM_COMMAND] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_GET_PROGRAM_COMMAND] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_PROGRAM_STDIO_REDIRECTION] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_GET_PROGRAM_STDIO_REDIRECTION] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_PROGRAM_SCHEDULE] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_GET_PROGRAM_SCHEDULE] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_GET_PROGRAM_SCHEDULER_STATE] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_CONTINUE_PROGRAM_SCHEDULE] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_START_PROGRAM] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_GET_LAST_SPAWNED_PROGRAM_PROCESS] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_GET_CUSTOM_PROGRAM_OPTION_NAMES] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_CUSTOM_PROGRAM_OPTION_VALUE] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_GET_CUSTOM_PROGRAM_OPTION_VALUE] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_REMOVE_CUSTOM_PROGRAM_OPTION] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[CALLBACK_PROGRAM_SCHEDULER_STATE_CHANGED] = RESPONSE_EXPECTED_ALWAYS_FALSE @response_expected[CALLBACK_PROGRAM_PROCESS_SPAWNED] = RESPONSE_EXPECTED_ALWAYS_FALSE @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE @callback_formats[CALLBACK_ASYNC_FILE_READ] = 'S C C60 C' @callback_formats[CALLBACK_ASYNC_FILE_WRITE] = 'S C C' @callback_formats[CALLBACK_FILE_EVENTS_OCCURRED] = 'S S' @callback_formats[CALLBACK_PROCESS_STATE_CHANGED] = 'S C Q C' @callback_formats[CALLBACK_PROGRAM_SCHEDULER_STATE_CHANGED] = 'S' @callback_formats[CALLBACK_PROGRAM_PROCESS_SPAWNED] = 'S' end |
Instance Method Details
#abort_async_file_read(file_id) ⇒ Object
Aborts a BrickRED#read_file_async operation in progress.
Returns the resulting error code.
On success the CALLBACK_ASYNC_FILE_READ callback will report OperationAborted.
532 533 534 |
# File 'lib/tinkerforge/brick_red.rb', line 532 def abort_async_file_read(file_id) send_request(FUNCTION_ABORT_ASYNC_FILE_READ, [file_id], 'S', 1, 'C') end |
#allocate_list(length_to_reserve, session_id) ⇒ Object
Allocates a new list object and reserves memory for length_to_reserve items. Set length_to_reserve to the number of items that should be stored in the list object.
Returns the object ID of the new list object and the resulting error code.
When a list object gets destroyed then the reference count of each object in the list object is decreased by one.
367 368 369 |
# File 'lib/tinkerforge/brick_red.rb', line 367 def allocate_list(length_to_reserve, session_id) send_request(FUNCTION_ALLOCATE_LIST, [length_to_reserve, session_id], 'S S', 3, 'C S') end |
#allocate_string(length_to_reserve, buffer, session_id) ⇒ Object
Allocates a new string object, reserves length_to_reserve bytes memory for it and sets up to the first 60 bytes. Set length_to_reserve to the length of the string that should be stored in the string object.
Returns the object ID of the new string object and the resulting error code.
331 332 333 |
# File 'lib/tinkerforge/brick_red.rb', line 331 def allocate_string(length_to_reserve, buffer, session_id) send_request(FUNCTION_ALLOCATE_STRING, [length_to_reserve, buffer, session_id], 'L Z58 S', 3, 'C S') end |
#append_to_list(list_id, item_object_id) ⇒ Object
Appends an object to a list object and increases the reference count of the appended object by one.
Returns the resulting error code.
395 396 397 |
# File 'lib/tinkerforge/brick_red.rb', line 395 def append_to_list(list_id, item_object_id) send_request(FUNCTION_APPEND_TO_LIST, [list_id, item_object_id], 'S S', 1, 'C') end |
#continue_program_schedule(program_id) ⇒ Object
800 801 802 |
# File 'lib/tinkerforge/brick_red.rb', line 800 def continue_program_schedule(program_id) send_request(FUNCTION_CONTINUE_PROGRAM_SCHEDULE, [program_id], 'S', 1, 'C') end |
#create_directory(name_string_id, flags, permissions, uid, gid) ⇒ Object
FIXME: name has to be absolute
651 652 653 |
# File 'lib/tinkerforge/brick_red.rb', line 651 def create_directory(name_string_id, flags, , uid, gid) send_request(FUNCTION_CREATE_DIRECTORY, [name_string_id, flags, , uid, gid], 'S L S L L', 1, 'C') end |
#create_pipe(flags, length, session_id) ⇒ Object
Creates a new pipe and allocates a new file object for it.
The flags parameter takes a ORed combination of the following possible pipe flags (in hexadecimal notation):
-
NonBlockingRead = 0x0001
-
NonBlockingWrite = 0x0002
The length of the pipe buffer can be specified with the length parameter in bytes. If length is set to zero, then the default pipe buffer length is used.
Returns the object ID of the new file object and the resulting error code.
464 465 466 |
# File 'lib/tinkerforge/brick_red.rb', line 464 def create_pipe(flags, length, session_id) send_request(FUNCTION_CREATE_PIPE, [flags, length, session_id], 'L Q S', 3, 'C S') end |
#create_session(lifetime) ⇒ Object
296 297 298 |
# File 'lib/tinkerforge/brick_red.rb', line 296 def create_session(lifetime) send_request(FUNCTION_CREATE_SESSION, [lifetime], 'L', 3, 'C S') end |
#define_program(identifier_string_id, session_id) ⇒ Object
745 746 747 |
# File 'lib/tinkerforge/brick_red.rb', line 745 def define_program(identifier_string_id, session_id) send_request(FUNCTION_DEFINE_PROGRAM, [identifier_string_id, session_id], 'S S', 3, 'C S') end |
#expire_session(session_id) ⇒ Object
301 302 303 |
# File 'lib/tinkerforge/brick_red.rb', line 301 def expire_session(session_id) send_request(FUNCTION_EXPIRE_SESSION, [session_id], 'S', 1, 'C') end |
#expire_session_unchecked(session_id) ⇒ Object
306 307 308 |
# File 'lib/tinkerforge/brick_red.rb', line 306 def expire_session_unchecked(session_id) send_request(FUNCTION_EXPIRE_SESSION_UNCHECKED, [session_id], 'S', 0, '') end |
#get_custom_program_option_names(program_id, session_id) ⇒ Object
815 816 817 |
# File 'lib/tinkerforge/brick_red.rb', line 815 def get_custom_program_option_names(program_id, session_id) send_request(FUNCTION_GET_CUSTOM_PROGRAM_OPTION_NAMES, [program_id, session_id], 'S S', 3, 'C S') end |
#get_custom_program_option_value(program_id, name_string_id, session_id) ⇒ Object
825 826 827 |
# File 'lib/tinkerforge/brick_red.rb', line 825 def get_custom_program_option_value(program_id, name_string_id, session_id) send_request(FUNCTION_GET_CUSTOM_PROGRAM_OPTION_VALUE, [program_id, name_string_id, session_id], 'S S S', 3, 'C S') end |
#get_directory_name(directory_id, session_id) ⇒ Object
Returns the name of a directory object, as passed to BrickRED#open_directory, and the resulting error code.
622 623 624 |
# File 'lib/tinkerforge/brick_red.rb', line 622 def get_directory_name(directory_id, session_id) send_request(FUNCTION_GET_DIRECTORY_NAME, [directory_id, session_id], 'S S', 3, 'C S') end |
#get_file_events(file_id) ⇒ Object
602 603 604 |
# File 'lib/tinkerforge/brick_red.rb', line 602 def get_file_events(file_id) send_request(FUNCTION_GET_FILE_EVENTS, [file_id], 'S', 3, 'C S') end |
#get_file_info(file_id, session_id) ⇒ Object
Returns various information about a file and the resulting error code.
Possible file types are:
-
Unknown = 0
-
Regular = 1
-
Directory = 2
-
Character = 3
-
Block = 4
-
FIFO = 5
-
Symlink = 6
-
Socket = 7
-
Pipe = 8
If the file type is Pipe then the returned name string object is invalid, because a pipe has no name. Otherwise the returned name string object was used to open or create the file object, as passed to BrickRED#open_file.
The returned flags were used to open or create the file object, as passed to BrickRED#open_file or BrickRED#create_pipe. See the respective function for a list of possible file and pipe flags.
FIXME: everything except flags and length is invalid if file type is Pipe
491 492 493 |
# File 'lib/tinkerforge/brick_red.rb', line 491 def get_file_info(file_id, session_id) send_request(FUNCTION_GET_FILE_INFO, [file_id, session_id], 'S S', 50, 'C C S L S L L Q Q Q Q') end |
#get_file_position(file_id) ⇒ Object
Returns the current seek position of a file object in bytes and returns the resulting error code.
If the file object was created by BrickRED#create_pipe then it has no seek position and the error code InvalidSeek is returned.
592 593 594 |
# File 'lib/tinkerforge/brick_red.rb', line 592 def get_file_position(file_id) send_request(FUNCTION_GET_FILE_POSITION, [file_id], 'S', 9, 'C Q') end |
#get_identity ⇒ Object
Returns the UID, the UID where the Brick is connected to, the position, the hardware and firmware version as well as the device identifier.
The position can be ‘0’-‘8’ (stack position).
The device identifier numbers can be found :ref:‘here <device_identifier>`. |device_identifier_constant|
842 843 844 |
# File 'lib/tinkerforge/brick_red.rb', line 842 def get_identity send_request(FUNCTION_GET_IDENTITY, [], '', 25, 'Z8 Z8 k C3 C3 S') end |
#get_last_spawned_program_process(program_id, session_id) ⇒ Object
810 811 812 |
# File 'lib/tinkerforge/brick_red.rb', line 810 def get_last_spawned_program_process(program_id, session_id) send_request(FUNCTION_GET_LAST_SPAWNED_PROGRAM_PROCESS, [program_id, session_id], 'S S', 11, 'C S Q') end |
#get_list_item(list_id, index, session_id) ⇒ Object
Returns the object ID and type of the object stored at index in a list object and returns the resulting error code.
Possible object types are:
-
String = 0
-
List = 1
-
File = 2
-
Directory = 3
-
Process = 4
-
Program = 5
387 388 389 |
# File 'lib/tinkerforge/brick_red.rb', line 387 def get_list_item(list_id, index, session_id) send_request(FUNCTION_GET_LIST_ITEM, [list_id, index, session_id], 'S S S', 4, 'C S C') end |
#get_list_length(list_id) ⇒ Object
Returns the length of a list object in items and the resulting error code.
372 373 374 |
# File 'lib/tinkerforge/brick_red.rb', line 372 def get_list_length(list_id) send_request(FUNCTION_GET_LIST_LENGTH, [list_id], 'S', 3, 'C S') end |
#get_next_directory_entry(directory_id, session_id) ⇒ Object
Returns the next entry in a directory object and the resulting error code.
If there is not next entry then error code NoMoreData is returned. To rewind a directory object call BrickRED#rewind_directory.
Possible directory entry types are:
-
Unknown = 0
-
Regular = 1
-
Directory = 2
-
Character = 3
-
Block = 4
-
FIFO = 5
-
Symlink = 6
-
Socket = 7
641 642 643 |
# File 'lib/tinkerforge/brick_red.rb', line 641 def get_next_directory_entry(directory_id, session_id) send_request(FUNCTION_GET_NEXT_DIRECTORY_ENTRY, [directory_id, session_id], 'S S', 4, 'C S C') end |
#get_process_command(process_id, session_id) ⇒ Object
Returns the executable, arguments, environment and working directory used to spawn a process object, as passed to BrickRED#spawn_process, and the resulting error code.
685 686 687 |
# File 'lib/tinkerforge/brick_red.rb', line 685 def get_process_command(process_id, session_id) send_request(FUNCTION_GET_PROCESS_COMMAND, [process_id, session_id], 'S S', 9, 'C S S S S') end |
#get_process_identity(process_id) ⇒ Object
Returns the process ID and the user and group ID used to spawn a process object, as passed to BrickRED#spawn_process, and the resulting error code.
The process ID is only valid if the state is Running or Stopped, see BrickRED#get_process_state.
694 695 696 |
# File 'lib/tinkerforge/brick_red.rb', line 694 def get_process_identity(process_id) send_request(FUNCTION_GET_PROCESS_IDENTITY, [process_id], 'S', 13, 'C L L L') end |
#get_process_state(process_id) ⇒ Object
Returns the current state, timestamp and exit code of a process object, and the resulting error code.
Possible process states are:
-
Unknown = 0
-
Running = 1
-
Error = 2
-
Exited = 3
-
Killed = 4
-
Stopped = 5
The timestamp represents the UNIX time since when the process is in its current state.
The exit code is only valid if the state is Error, Exited, Killed or Stopped and has different meanings depending on the state:
-
Error: error code for error occurred while spawning the process (see below)
-
Exited: exit status of the process
-
Killed: UNIX signal number used to kill the process
-
Stopped: UNIX signal number used to stop the process
Possible exit/error codes in Error state are:
-
InternalError = 125
-
CannotExecute = 126
-
DoesNotExist = 127
The CannotExecute error can be caused by the executable being opened for writing.
735 736 737 |
# File 'lib/tinkerforge/brick_red.rb', line 735 def get_process_state(process_id) send_request(FUNCTION_GET_PROCESS_STATE, [process_id], 'S', 11, 'C C Q C') end |
#get_process_stdio(process_id, session_id) ⇒ Object
Returns the stdin, stdout and stderr files used to spawn a process object, as passed to BrickRED#spawn_process, and the resulting error code.
700 701 702 |
# File 'lib/tinkerforge/brick_red.rb', line 700 def get_process_stdio(process_id, session_id) send_request(FUNCTION_GET_PROCESS_STDIO, [process_id, session_id], 'S S', 7, 'C S S S') end |
#get_processes(session_id) ⇒ Object
656 657 658 |
# File 'lib/tinkerforge/brick_red.rb', line 656 def get_processes(session_id) send_request(FUNCTION_GET_PROCESSES, [session_id], 'S', 3, 'C S') end |
#get_program_command(program_id, session_id) ⇒ Object
FIXME: working directory is relative to <home>/programs/<identifier>/bin
770 771 772 |
# File 'lib/tinkerforge/brick_red.rb', line 770 def get_program_command(program_id, session_id) send_request(FUNCTION_GET_PROGRAM_COMMAND, [program_id, session_id], 'S S', 9, 'C S S S S') end |
#get_program_identifier(program_id, session_id) ⇒ Object
755 756 757 |
# File 'lib/tinkerforge/brick_red.rb', line 755 def get_program_identifier(program_id, session_id) send_request(FUNCTION_GET_PROGRAM_IDENTIFIER, [program_id, session_id], 'S S', 3, 'C S') end |
#get_program_root_directory(program_id, session_id) ⇒ Object
FIXME: root directory is absolute: <home>/programs/<identifier>
760 761 762 |
# File 'lib/tinkerforge/brick_red.rb', line 760 def get_program_root_directory(program_id, session_id) send_request(FUNCTION_GET_PROGRAM_ROOT_DIRECTORY, [program_id, session_id], 'S S', 3, 'C S') end |
#get_program_schedule(program_id, session_id) ⇒ Object
790 791 792 |
# File 'lib/tinkerforge/brick_red.rb', line 790 def get_program_schedule(program_id, session_id) send_request(FUNCTION_GET_PROGRAM_SCHEDULE, [program_id, session_id], 'S S', 9, 'C C ? L S') end |
#get_program_scheduler_state(program_id, session_id) ⇒ Object
FIXME: message is currently valid in error-occurred state only
795 796 797 |
# File 'lib/tinkerforge/brick_red.rb', line 795 def get_program_scheduler_state(program_id, session_id) send_request(FUNCTION_GET_PROGRAM_SCHEDULER_STATE, [program_id, session_id], 'S S', 12, 'C C Q S') end |
#get_program_stdio_redirection(program_id, session_id) ⇒ Object
FIXME: stdio file names are relative to <home>/programs/<identifier>/bin
780 781 782 |
# File 'lib/tinkerforge/brick_red.rb', line 780 def get_program_stdio_redirection(program_id, session_id) send_request(FUNCTION_GET_PROGRAM_STDIO_REDIRECTION, [program_id, session_id], 'S S', 10, 'C C S C S C S') end |
#get_programs(session_id) ⇒ Object
740 741 742 |
# File 'lib/tinkerforge/brick_red.rb', line 740 def get_programs(session_id) send_request(FUNCTION_GET_PROGRAMS, [session_id], 'S', 3, 'C S') end |
#get_string_chunk(string_id, offset) ⇒ Object
Returns a chunk up to 63 bytes from a string object beginning at offset and returns the resulting error code.
355 356 357 |
# File 'lib/tinkerforge/brick_red.rb', line 355 def get_string_chunk(string_id, offset) send_request(FUNCTION_GET_STRING_CHUNK, [string_id, offset], 'S L', 64, 'C Z63') end |
#get_string_length(string_id) ⇒ Object
Returns the length of a string object in bytes and the resulting error code.
342 343 344 |
# File 'lib/tinkerforge/brick_red.rb', line 342 def get_string_length(string_id) send_request(FUNCTION_GET_STRING_LENGTH, [string_id], 'S', 5, 'C L') end |
#keep_session_alive(session_id, lifetime) ⇒ Object
311 312 313 |
# File 'lib/tinkerforge/brick_red.rb', line 311 def keep_session_alive(session_id, lifetime) send_request(FUNCTION_KEEP_SESSION_ALIVE, [session_id, lifetime], 'S L', 1, 'C') end |
#kill_process(process_id, signal) ⇒ Object
Sends a UNIX signal to a process object and returns the resulting error code.
Possible UNIX signals are:
-
Interrupt = 2
-
Quit = 3
-
Abort = 6
-
Kill = 9
-
User1 = 10
-
User2 = 12
-
Terminate = 15
-
Continue = 18
-
Stop = 19
678 679 680 |
# File 'lib/tinkerforge/brick_red.rb', line 678 def kill_process(process_id, signal) send_request(FUNCTION_KILL_PROCESS, [process_id, signal], 'S C', 1, 'C') end |
#open_directory(name_string_id, session_id) ⇒ Object
Opens an existing directory and allocates a new directory object for it.
FIXME: name has to be absolute
The reference count of the name string object is increased by one. When the directory object is destroyed then the reference count of the name string object is decreased by one. Also the name string object is locked and cannot be modified while the directory object holds a reference to it.
Returns the object ID of the new directory object and the resulting error code.
616 617 618 |
# File 'lib/tinkerforge/brick_red.rb', line 616 def open_directory(name_string_id, session_id) send_request(FUNCTION_OPEN_DIRECTORY, [name_string_id, session_id], 'S S', 3, 'C S') end |
#open_file(name_string_id, flags, permissions, uid, gid, session_id) ⇒ Object
Opens an existing file or creates a new file and allocates a new file object for it.
FIXME: name has to be absolute
The reference count of the name string object is increased by one. When the file object gets destroyed then the reference count of the name string object is decreased by one. Also the name string object is locked and cannot be modified while the file object holds a reference to it.
The flags parameter takes a ORed combination of the following possible file flags (in hexadecimal notation):
-
ReadOnly = 0x0001 (O_RDONLY)
-
WriteOnly = 0x0002 (O_WRONLY)
-
ReadWrite = 0x0004 (O_RDWR)
-
Append = 0x0008 (O_APPEND)
-
Create = 0x0010 (O_CREAT)
-
Exclusive = 0x0020 (O_EXCL)
-
NonBlocking = 0x0040 (O_NONBLOCK)
-
Truncate = 0x0080 (O_TRUNC)
-
Temporary = 0x0100
-
Replace = 0x0200
FIXME: explain Temporary and Replace flag
The permissions parameter takes a ORed combination of the following possible file permissions (in octal notation) that match the common UNIX permission bits:
-
UserRead = 00400
-
UserWrite = 00200
-
UserExecute = 00100
-
GroupRead = 00040
-
GroupWrite = 00020
-
GroupExecute = 00010
-
OthersRead = 00004
-
OthersWrite = 00002
-
OthersExecute = 00001
Returns the object ID of the new file object and the resulting error code.
448 449 450 |
# File 'lib/tinkerforge/brick_red.rb', line 448 def open_file(name_string_id, flags, , uid, gid, session_id) send_request(FUNCTION_OPEN_FILE, [name_string_id, flags, , uid, gid, session_id], 'S L S L L S', 3, 'C S') end |
#purge_program(program_id, cookie) ⇒ Object
750 751 752 |
# File 'lib/tinkerforge/brick_red.rb', line 750 def purge_program(program_id, ) send_request(FUNCTION_PURGE_PROGRAM, [program_id, ], 'S L', 1, 'C') end |
#read_file(file_id, length_to_read) ⇒ Object
Reads up to 62 bytes from a file object.
Returns the bytes read, the actual number of bytes read and the resulting error code.
If there is not data to be read, either because the file position reached end-of-file or because there is not data in the pipe, then zero bytes are returned.
If the file object was created by BrickRED#open_file without the NonBlocking flag or by BrickRED#create_pipe without the NonBlockingRead flag then the error code NotSupported is returned.
507 508 509 |
# File 'lib/tinkerforge/brick_red.rb', line 507 def read_file(file_id, length_to_read) send_request(FUNCTION_READ_FILE, [file_id, length_to_read], 'S C', 64, 'C C62 C') end |
#read_file_async(file_id, length_to_read) ⇒ Object
Reads up to 2\ :sup:63\ - 1 bytes from a file object asynchronously.
Reports the bytes read (in 60 byte chunks), the actual number of bytes read and the resulting error code via the CALLBACK_ASYNC_FILE_READ callback.
If there is not data to be read, either because the file position reached end-of-file or because there is not data in the pipe, then zero bytes are reported.
If the file object was created by BrickRED#open_file without the NonBlocking flag or by BrickRED#create_pipe without the NonBlockingRead flag then the error code NotSupported is reported via the CALLBACK_ASYNC_FILE_READ callback.
523 524 525 |
# File 'lib/tinkerforge/brick_red.rb', line 523 def read_file_async(file_id, length_to_read) send_request(FUNCTION_READ_FILE_ASYNC, [file_id, length_to_read], 'S Q', 0, '') end |
#register_callback(id, &block) ⇒ Object
Registers a callback with ID id to the block block.
847 848 849 850 |
# File 'lib/tinkerforge/brick_red.rb', line 847 def register_callback(id, &block) callback = block @registered_callbacks[id] = callback end |
#release_object(object_id, session_id) ⇒ Object
Decreases the reference count of an object by one and returns the resulting error code. If the reference count reaches zero the object gets destroyed.
317 318 319 |
# File 'lib/tinkerforge/brick_red.rb', line 317 def release_object(object_id, session_id) send_request(FUNCTION_RELEASE_OBJECT, [object_id, session_id], 'S S', 1, 'C') end |
#release_object_unchecked(object_id, session_id) ⇒ Object
322 323 324 |
# File 'lib/tinkerforge/brick_red.rb', line 322 def release_object_unchecked(object_id, session_id) send_request(FUNCTION_RELEASE_OBJECT_UNCHECKED, [object_id, session_id], 'S S', 0, '') end |
#remove_custom_program_option(program_id, name_string_id) ⇒ Object
830 831 832 |
# File 'lib/tinkerforge/brick_red.rb', line 830 def remove_custom_program_option(program_id, name_string_id) send_request(FUNCTION_REMOVE_CUSTOM_PROGRAM_OPTION, [program_id, name_string_id], 'S S', 1, 'C') end |
#remove_from_list(list_id, index) ⇒ Object
Removes the object stored at index from a list object and decreases the reference count of the removed object by one.
Returns the resulting error code.
403 404 405 |
# File 'lib/tinkerforge/brick_red.rb', line 403 def remove_from_list(list_id, index) send_request(FUNCTION_REMOVE_FROM_LIST, [list_id, index], 'S S', 1, 'C') end |
#rewind_directory(directory_id) ⇒ Object
Rewinds a directory object and returns the resulting error code.
646 647 648 |
# File 'lib/tinkerforge/brick_red.rb', line 646 def rewind_directory(directory_id) send_request(FUNCTION_REWIND_DIRECTORY, [directory_id], 'S', 1, 'C') end |
#set_custom_program_option_value(program_id, name_string_id, value_string_id) ⇒ Object
820 821 822 |
# File 'lib/tinkerforge/brick_red.rb', line 820 def set_custom_program_option_value(program_id, name_string_id, value_string_id) send_request(FUNCTION_SET_CUSTOM_PROGRAM_OPTION_VALUE, [program_id, name_string_id, value_string_id], 'S S S', 1, 'C') end |
#set_file_events(file_id, events) ⇒ Object
597 598 599 |
# File 'lib/tinkerforge/brick_red.rb', line 597 def set_file_events(file_id, events) send_request(FUNCTION_SET_FILE_EVENTS, [file_id, events], 'S S', 1, 'C') end |
#set_file_position(file_id, offset, origin) ⇒ Object
Set the current seek position of a file object in bytes relative to origin.
Possible file origins are:
-
Beginning = 0
-
Current = 1
-
End = 2
Returns the resulting absolute seek position and error code.
If the file object was created by BrickRED#create_pipe then it has no seek position and the error code InvalidSeek is returned.
583 584 585 |
# File 'lib/tinkerforge/brick_red.rb', line 583 def set_file_position(file_id, offset, origin) send_request(FUNCTION_SET_FILE_POSITION, [file_id, offset, origin], 'S q C', 9, 'C Q') end |
#set_program_command(program_id, executable_string_id, arguments_list_id, environment_list_id, working_directory_string_id) ⇒ Object
FIXME: working directory is relative to <home>/programs/<identifier>/bin
765 766 767 |
# File 'lib/tinkerforge/brick_red.rb', line 765 def set_program_command(program_id, executable_string_id, arguments_list_id, environment_list_id, working_directory_string_id) send_request(FUNCTION_SET_PROGRAM_COMMAND, [program_id, executable_string_id, arguments_list_id, environment_list_id, working_directory_string_id], 'S S S S S', 1, 'C') end |
#set_program_schedule(program_id, start_mode, continue_after_error, start_interval, start_fields_string_id) ⇒ Object
785 786 787 |
# File 'lib/tinkerforge/brick_red.rb', line 785 def set_program_schedule(program_id, start_mode, continue_after_error, start_interval, start_fields_string_id) send_request(FUNCTION_SET_PROGRAM_SCHEDULE, [program_id, start_mode, continue_after_error, start_interval, start_fields_string_id], 'S C ? L S', 1, 'C') end |
#set_program_stdio_redirection(program_id, stdin_redirection, stdin_file_name_string_id, stdout_redirection, stdout_file_name_string_id, stderr_redirection, stderr_file_name_string_id) ⇒ Object
FIXME: stdio file names are relative to <home>/programs/<identifier>/bin
775 776 777 |
# File 'lib/tinkerforge/brick_red.rb', line 775 def set_program_stdio_redirection(program_id, stdin_redirection, stdin_file_name_string_id, stdout_redirection, stdout_file_name_string_id, stderr_redirection, stderr_file_name_string_id) send_request(FUNCTION_SET_PROGRAM_STDIO_REDIRECTION, [program_id, stdin_redirection, stdin_file_name_string_id, stdout_redirection, stdout_file_name_string_id, stderr_redirection, stderr_file_name_string_id], 'S C S C S C S', 1, 'C') end |
#set_string_chunk(string_id, offset, buffer) ⇒ Object
Sets a chunk of up to 58 bytes in a string object beginning at offset.
Returns the resulting error code.
349 350 351 |
# File 'lib/tinkerforge/brick_red.rb', line 349 def set_string_chunk(string_id, offset, buffer) send_request(FUNCTION_SET_STRING_CHUNK, [string_id, offset, buffer], 'S L Z58', 1, 'C') end |
#spawn_process(executable_string_id, arguments_list_id, environment_list_id, working_directory_string_id, uid, gid, stdin_file_id, stdout_file_id, stderr_file_id, session_id) ⇒ Object
661 662 663 |
# File 'lib/tinkerforge/brick_red.rb', line 661 def spawn_process(executable_string_id, arguments_list_id, environment_list_id, working_directory_string_id, uid, gid, stdin_file_id, stdout_file_id, stderr_file_id, session_id) send_request(FUNCTION_SPAWN_PROCESS, [executable_string_id, arguments_list_id, environment_list_id, working_directory_string_id, uid, gid, stdin_file_id, stdout_file_id, stderr_file_id, session_id], 'S S S S L L S S S S', 3, 'C S') end |
#start_program(program_id) ⇒ Object
805 806 807 |
# File 'lib/tinkerforge/brick_red.rb', line 805 def start_program(program_id) send_request(FUNCTION_START_PROGRAM, [program_id], 'S', 1, 'C') end |
#truncate_string(string_id, length) ⇒ Object
Truncates a string object to length bytes and returns the resulting error code.
337 338 339 |
# File 'lib/tinkerforge/brick_red.rb', line 337 def truncate_string(string_id, length) send_request(FUNCTION_TRUNCATE_STRING, [string_id, length], 'S L', 1, 'C') end |
#write_file(file_id, buffer, length_to_write) ⇒ Object
Writes up to 61 bytes to a file object.
Returns the actual number of bytes written and the resulting error code.
If the file object was created by BrickRED#open_file without the NonBlocking flag or by BrickRED#create_pipe without the NonBlockingWrite flag then the error code NotSupported is returned.
543 544 545 |
# File 'lib/tinkerforge/brick_red.rb', line 543 def write_file(file_id, buffer, length_to_write) send_request(FUNCTION_WRITE_FILE, [file_id, buffer, length_to_write], 'S C61 C', 2, 'C C') end |
#write_file_async(file_id, buffer, length_to_write) ⇒ Object
Writes up to 61 bytes to a file object.
Reports the actual number of bytes written and the resulting error code via the CALLBACK_ASYNC_FILE_WRITE callback.
If the file object was created by BrickRED#open_file without the NonBlocking flag or by BrickRED#create_pipe without the NonBlockingWrite flag then the error code NotSupported is reported via the CALLBACK_ASYNC_FILE_WRITE callback.
567 568 569 |
# File 'lib/tinkerforge/brick_red.rb', line 567 def write_file_async(file_id, buffer, length_to_write) send_request(FUNCTION_WRITE_FILE_ASYNC, [file_id, buffer, length_to_write], 'S C61 C', 0, '') end |
#write_file_unchecked(file_id, buffer, length_to_write) ⇒ Object
Writes up to 61 bytes to a file object.
Does neither report the actual number of bytes written nor the resulting error code.
If the file object was created by BrickRED#open_file without the NonBlocking flag or by BrickRED#create_pipe without the NonBlockingWrite flag then the write operation will fail silently.
555 556 557 |
# File 'lib/tinkerforge/brick_red.rb', line 555 def write_file_unchecked(file_id, buffer, length_to_write) send_request(FUNCTION_WRITE_FILE_UNCHECKED, [file_id, buffer, length_to_write], 'S C61 C', 0, '') end |