I want to create an environment variable in startup in order to retrieve it in a QNX program.
Startup will read the value in a EEPROM, store it in an environment variable and so my QNX program will retrieve it.
I saw that function add_typed_string can set predefined variable but I want to create a new one. The function add_string could be OK but how my QNX program can retrieve the index returned ?
Some terminology here. What you want to do is create a syspage entry (not an environment variable).
Creating a new property in the syspage is not difficult.
In order to oass some data from your startup to your application in a non-portable way, the easiest thing to do would be to use add_string() (rather than add_typed_string). Defining a string in the format of an environment variable make sense.
For example to add a property FOO with a value BAR:
(in the startup)
add_string("FOO=BAR");
To retrieve the property FOO at process time (QNX running)
char *p=SYSPAGE_ENTRY(strings)->data;
while(*p) {
if(strncmp(p, "FOO", 3) == 0) {
char buf[80];
char *p1,*p2;
// found property FOO, now copy string and strtok() on '=' to get value
strcpy(buf, p);
p1=strtok(buf, "=");
p2=strtok(NULL, "");
// p2 is equal to FOO value (in this case "BAR")
break;
}
p += strlen(p);
}
Since this is non-portable, you should be sure that the property is not something that maps into the CS stuff…
BSP startup is written in C and setenv() function is not working at this moment.
Rgallen,
Your solution is working fine ! (the line p += strlen(p); should be p += (strlen(p)+1); because strings are zero terminated). I observed that size or syspage is 32768 bytes and that use bigger size then QNX is not started ! it doesn’t matter, I just need few bytes to transmit value.