Step 1: An Embryonic Project

Top  Previous  Next

This sample project is published on our website under the name "test_stg_lib".

 

Here it is, an embryonic project that allows us to verify the correctness of the descriptor file and related defines:

 

global.tbh:

 

'DEFINES-------------------------------------------------------------

 

'INCLUDES------------------------------------------------------------

include "settings\trunk\settings.tbh"

includepp "settings.txt" 'this will allow you to put #defines directly into settings.txt

 

 

main.tbs:

 

include "global.tbh"

 

'====================================================================

sub on_sys_init()

       if stg_start()<>EN_STG_STATUS_OK then sys.halt

end sub

 

 

device.tbs:

 

include "global.tbh"

 

'====================================================================

sub callback_stg_error(byref stg_name_or_num as string,index as byte,status as en_stg_status_codes)

end sub

 

'--------------------------------------------------------------------

sub callback_stg_pre_get(byref stg_name_or_num as string,index as byte,byref stg_value as string)

end sub

 

'--------------------------------------------------------------------

sub callback_stg_post_set(byref stg_name_or_num as string, index as byte,byref stg_value as string)

end sub

 

 

settings.txt:

 

>>DN                E        S        1        0        10        I        ^                Device Name

>>IP                E        D        1        4        4        A        192.168.1.93        IP address <-- set the one you want as the default value

>>PN                E        W        1        0        65535        A        1000                Port number

>>PTN                E        S        3        0        16        A        G-~/R-~/B-~        LED patterns

>>CPTN        R        B        1        0        2        A        0                Current pattern to play

 

#define STG_DEBUG_PRINT 1

 

 

 

note_tip-wt

For the IP setting, change the default setting value as needed! Setting initialization code will initialize the setting and the desired IP will be set.

 

The project above compiles, but as we run it, we discover that stg_start() fails and the following appears in the output pane:

 

 

STG> ---START---

STG> ERROR (setting 'PTN'): this setting's name length is 3, while you have 'STG_MAX_SETTING_NAME_LEN 2'.

 

 

Ah, indeed, we even have a "CPTN" setting, so we go ahead and add #define STG_MAX_SETTING_NAME_LEN 4 to settings.txt (we have "CPTN" setting there, too). Run again...

 

 

STG> ---START---

STG> ERROR: total number of settings is 5 while you have 'STG_MAX_NUM_SETTINGS 1'.

 

 

OK, we need #define STG_MAX_NUM_SETTINGS 5 to setting.txt. Run one more time...

 

 

STG> ---START---

STG> ERROR: your volatile settings need 2 bytes in the RAM, you now have 'STG_RAM_ARRAY_SIZE 0'.

 

 

Another error! Indeed, we plan to have two RAM settings -- "CPTN" and "PIP", and the library conveniently calculated the space needed! We add #define STG_RAM_ARRAY_SIZE 2. Try yet again...

 

 

STG> ---START---

STG> Initialize RAM (volatile) settings...

STG> STG_RESTORE_MULTIPLE(), init_mode= RAM ONLY

STG> STG_SG()

STG> SET 'CPTN(255)' to '0' : OK

STG> STG_SG()

STG> SET 'PIP(255)' to '0' : OK

STG> RAM (volatile) settings initialized

STG> Number of settings: 6

STG> Non-volatile memory space required: 193

 

 

Ah, it worked. Our descriptor file has been accepted! Here is how setting.txt looks now:

 

settings.txt:

 

>>DN                E        S        1        0        10        I        ^                Device Name

>>IP                E        D        1        4        4        A        192.168.1.93        IP address <-- set the one you want as the default value

>>PN                E        W        1        0        65535        A        1000                Port number

>>PTN                E        S        3        0        16        A        G-~/R-~/B-~        LED patterns

>>CPTN        R        B        1        0        2        A        0                Current pattern to play

 

#define STG_DEBUG_PRINT 1

#define STG_MAX_SETTING_NAME_LEN 4

#define STG_MAX_NUM_SETTINGS 5

#define STG_RAM_ARRAY_SIZE 2

 

 

The example above shows how to deal with the STG library. There are many more types of errors that can be reported. Whatever you encounter, read it, understand it, correct it, and you will be fine.

Output pane also showed that both RAM settings got initialized -- it happens automatically because, obviously, RAM settings need initialization every time the program runs. As for our non-volatile settings, we are supposed to find a way to initialize them in some convenient way. Read on...