Low Level


Defines

#define RF_GROUP_DEFAULT   0
#define RF_GROUP_CHAT   1
#define RF_GROUP_CYLAND   2
#define RF_GROUP_LABYRINTH   3
#define RF_GROUP_SERVER   4
#define RF_GROUP_FILES   5
#define RF_GROUP_GAMES   6
#define RF_GROUP_APPS   7
#define RF_GROUP_OTHER   8
#define RF_GROUP_SYSTEM   9

Functions

bool get_communications (void)
void set_communications (bool enable)
char get_appchannel (void)
char get_appchannel_of (cyid_t device_id)
void set_appchannel (char rf_channel)
char set_best_appchannel (char group_id)
char get_groupchannel (char group_id, char channel)
char set_groupchannel (char group_id, char channel)
char get_group_size (char group)
int get_people_on_channel (char channel)
cyid_t get_people_around (cyid_t prev_device)
void update_people_around (clock_t timeout)
bool is_rf_paused (void)
void rf_pause (void)
void rf_resume (void)
clock_t last_rf_clock (void)
time_t last_rf_time (void)
bool set_critical_mode (bool set)
bool get_critical_mode (void)


Detailed Description

Some low level communication functions. Don't use these functions if you don't know exactly what are you doing.


Define Documentation

#define RF_GROUP_APPS   7
 

Applications channel group.

#define RF_GROUP_CHAT   1
 

Chat channel group.

#define RF_GROUP_CYLAND   2
 

CyLandia channel group.

#define RF_GROUP_DEFAULT   0
 

Default group for unknown applications.

#define RF_GROUP_FILES   5
 

Files channel group.

#define RF_GROUP_GAMES   6
 

Games channel group.

#define RF_GROUP_LABYRINTH   3
 

Labyrinth channel group.

#define RF_GROUP_OTHER   8
 

Reserved channel group.

#define RF_GROUP_SERVER   4
 

Server channel group.

#define RF_GROUP_SYSTEM   9
 

System channel group (for debugging purposes).


Function Documentation

char get_appchannel ( void )
 

Returns the current application's channel.

Returns:
the current application channel.
       #include <cybiko.h>
       #define PRIVATE_CHAT_CHANNEL    0x1     
       ...
       char old_channel;
       ...
       //  Sets new application channel.
       old_channel = get_appchannel();
       set_appchannel( get_groupchannel( RF_GROUP_CHAT, 
                                         PRIVATE_CHAT_CHANNEL ) ); 
       ...
       //  Restores application channel.
       set_appchannel( old_channel );
       ...
See also:
set_appchannel.

char get_appchannel_of ( cyid_t device_id )
 

Returns the current application channel of the specified device.

Parameters:
device_id   the ID of the device, to determine its RF channel.
Returns:
current application channel of the specified device.
       #include<cybiko.h>
       ...
       char old_channel;
       cyid_t partner_id;
       ...
       //  Obtains partner_id.
       ...
       //  Sets application channel equal to your partner channel.
       old_channel = get_appchannel();
       set_appchannel( get_appchannel_of( partner_id ) );
       ...
       //  Restores application channel.
       set_appchannel( old_channel );
       ... 
See also:
set_appchannel.

bool get_communications ( void )
 

Returns the communications state.

Returns:
TRUE if communications are enabled.
       #include <cybiko.h>
       ...
       if ( !get_communications() )
             set_communications( TRUE );
       ...
See also:
set_communications.

bool get_critical_mode ( void )
 

Returns the critical mode state.

Returns:
the critical mode state.
       #include <cybiko.h>
       ...
       if( ! get_critical_mode() )
       {
         set_critical_mode( TRUE ); 
       }
       ...

char get_group_size ( char group )
 

Returns the number of channels in a specified group.

Parameters:
group   ID of the group.
Returns:
the number of channels in the group.
       #include <cybiko.h>
       ...
       char max_chat_channel;
       char current_channel;
       int people_in_chat = 0;
       ...
       //  Counts all people on chat channels.
       max_chat_channel = get_group_size( RF_GROUP_CHAT );
       for( current_channel = 0; current_channel < max_chat_channel; current_channel ++ )
       {
         people_in_chat += get_people_on_channel( get_groupchannel( RF_GROUP_CHAT, 
                                                                    current_channel ) );
       }  
       ...

char get_groupchannel ( char group_id,
char channel )
 

Returns the application channel, by channel group index.

Parameters:
group_id   ID of the group to which the application belongs.
channel   index of the application in the group.
Returns:
the application channel, by channel group index.
       #include <cybiko.h>
       #define PRIVATE_CHAT_CHANNEL    0x1     
       ...
       char old_channel;
       ...
       //  Sets new application channel.
       old_channel = get_appchannel();
       set_appchannel( get_groupchannel( RF_GROUP_CHAT, 
                                         PRIVATE_CHAT_CHANNEL ) ); 
       ...
       //  Restores application channel.
       set_appchannel( old_channel );
       ...
See also:
set_groupchannel.

cyid_t get_people_around ( cyid_t prev_device )
 

Returns the CyID of the next device after prev_device (the CyIDs of people in the vicinity).
To retrieve the first device in the list, set prev_device to zero.

Parameters:
prev_device   CyID of the device in the previous CyID list of people in the vicinity.
Returns:
the CyID of a device.
       #include <cybiko.h>
       ...
       char sz_str_ID[10];
       cyid_t current_device_id = 0;
       ...
       TRACE( "Devices around:" );
       while( current_device_id = get_people_around( current_device_id ) )
       {
         cyid2str( sz_str_ID, current_device_id );
         TRACE( "%s", sz_str_ID );
       }
       ...

int get_people_on_channel ( char channel )
 

Returns the device count on the channel.

Parameters:
channel   the index of the RF channel.
Returns:
the device count on the channel.
       #include <cybiko.h>
       ...
       char max_chat_channel;
       char current_channel;
       int people_in_chat = 0;
       ...
       //  Counts all people on chat channels.
       max_chat_channel = get_group_size( RF_GROUP_CHAT );
       for( current_channel = 0; current_channel < max_chat_channel; current_channel ++ )
       {
         people_in_chat += get_people_on_channel( get_groupchannel( RF_GROUP_CHAT, 
                                                                    current_channel ) );
       }  
       ...

bool is_rf_paused ( void )
 

Returns TRUE if RF communications are paused.

Returns:
TRUE if RF communications are paused.
       #include <cybiko.h>
       ...
       bool rf_paused;
       ...
       //  Disables communications.
       rf_paused = is_rf_paused();
       rf_pause();
       ...
       //  Restores communications.
       if( ! rf_paused )
       {
         rf_resume();
       }
       ...

clock_t last_rf_clock ( void )
 

Returns the clock_t value of the last sent or received frame except sent pings (last RF activity clock).

Returns:
the clock_t value of the last sent or received frame.
       #include <cybiko.h>
       ...
       int value;
       ...
       //  Initializes a pseudorandom sequence.
       srand( last_rf_clock() );
       ...
       value = random( 10 );
       ...

time_t last_rf_time ( void )
 

Returns the time the last frame was sent or received, except sent pings.

Returns:
the time the last frame was sent or received.
       #include <cybiko.h>
       ...
       struct Time last_message_time;
       ...
       Time_decode( &last_message_time, last_rf_time() );
       TRACE("Last message was sent or received at hour: %d, minutes: %d, seconds: %d",
             last_message_time.hour,
             last_message_time.minute,
             last_message_time.second );
       ...

void rf_pause ( void )
 

Pauses RF communications.
Another way to stop RF.

Returns:
None
       #include <cybiko.h>
       ...
       bool rf_paused;
       ...
       //  Disables communications.
       rf_paused = is_rf_paused();
       rf_pause();
       ...
       //  Restores communications.
       if( ! rf_paused )
       {
         rf_resume();
       }
       ...
See also:
rf_resume.

void rf_resume ( void )
 

Resumes RF communications after a pause.

Returns:
None
       #include <cybiko.h>
       ...
       bool rf_paused;
       ...
       //  Disables communications.
       rf_paused = is_rf_paused();
       rf_pause();
       ...
       //  Restores communications.
       if( ! rf_paused )
       {
         rf_resume();
       }
       ...
See also:
rf_pause.

void set_appchannel ( char rf_channel )
 

Sets current application channel.
The channel #0 is the Base channel.

Parameters:
rf_channel   RF channel to set.
Returns:
None.
       #include <cybiko.h>
       #define PRIVATE_CHAT_CHANNEL    0x1     
       ...
       char old_channel;
       ...
       //  Sets new application channel.
       old_channel = get_appchannel();
       set_appchannel( get_groupchannel( RF_GROUP_CHAT, 
                                         PRIVATE_CHAT_CHANNEL ) ); 
       ...
       //  Restores application channel.
       set_appchannel( old_channel );
       ...
See also:
get_appchannel_of.

char set_best_appchannel ( char group_id )
 

Selects the application channel with the least traffic.

Parameters:
group_id   ID of the group to which the application belongs.
Returns:
ID of the channel with the last traffic.
       #include <cybiko.h>
       ...
       char old_channel;
       ...
       // Sets application channel with the least traffic.
       old_channel = get_appchannel();
       set_best_appchannel( RF_GROUP_CHAT );
       ...
       //  Restores application channel.
       set_appchannel( old_channel );
       ... 

void set_communications ( bool enable )
 

Enables or disables communications through RF.
Disabling RF communications turns off all communications devices (e.g. AVR, PLL and RF2915), so power consumption is decreased. Also, it disables periodically sending pings.

Parameters:
enable   specifies whether communications should be enabled. A TRUE value enables communications; a FALSE value disables them.
Returns:
None.
       #include <cybiko.h>
       ...
       if( !get_communications() )
            set_communications( TRUE );
       ...
See also:
get_communications.

bool set_critical_mode ( bool set )
 

Sets a special critical mode to disable network or internal task interrupts, such as invite.

Parameters:
set   if TRUE, enables critical mode; any other answer disables it
Returns:
previous state.
       #include <cybiko.h>
       ...
       if( ! get_critical_mode() )
       {
         set_critical_mode( TRUE ); 
       }
       ...

char set_groupchannel ( char group_id,
char channel )
 

Selects the application channel by channel group index.

Parameters:
group_id   ID of the group to which the application belongs.
channel   index of the application in the group.
Returns:
returns the application channel.
       #include <cybiko.h>
       #define PRIVATE_CHAT_CHANNEL    0x1     
       ...
       char old_channel;
       ...
       //  Sets new application channel.
       old_channel = get_appchannel();
       set_groupchannel( RF_GROUP_CHAT, PRIVATE_CHAT_CHANNEL ); 
       ...
       //  Restores application channel.
       set_appchannel( old_channel );
       ...
See also:
get_groupchannel.

void update_people_around ( clock_t timeout )
 

Selects the base channel, waits the timeout, and resets the work channel.

Parameters:
timeout   the amount of time to wait.
Returns:
None.
       #include <cybiko.h>
       #define PRIVATE_CHAT_CHANNEL    0x1
       ...
       char old_channel;
       ...
       //  Sets new application channel.
       old_channel = get_appchannel();
       set_groupchannel( RF_GROUP_CHAT, PRIVATE_CHAT_CHANNEL );
       ...
       update_people_around( 250 );
       //  Retrives people arround.
       ...
       //  Restores application channel.
       set_appchannel( old_channel );
       ...