[prev in list] [next in list] [prev in thread] [next in thread] 

List:       flightgear-devel
Subject:    Re: [Flightgear-devel] Help needed fo write an FG string property
From:       Harry Campigli <harrycam2 () gmail ! com>
Date:       2009-04-17 14:50:22
Message-ID: acbcb7140904170750u308c77f5t11e971f1a896533a () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


HI Curtis thanks for the response,

Well I tore my hair out for a couple of days. But I could never make any
sense of the string stored in the structure, nor could I find a string
terminator in it. I dont know exactly why as i am not very experieced in c
strings.

I ended up putting the property to a local string, then writing it into a
normal char array in the structure adding a teminator after the last
printable.


Certianly not elegant but works for now to load the stucture. A programer
would write it differently to me!


      tempnode = node->getChild("registration");
      pt = net->registration[i];                        // pointer to array
in struct
      pt[0] = '\0';                                           // put an end
of string for default
      if ( tempnode != NULL ) {
          temp =  tempnode->getStringValue();
          n=0;
          x=0x31;
          while ( (x > 0x19)& (x<0x7f) & (n < SL_MAX_REGISTRATION)){
          x=temp[n];                                            // pointer
to prop string to send
          pt[n] = x;                                             // wite to
the struct string
          n++;
          }
          pt[n] = '\0'; //0x0A;
      }

>From the structure Its written into the other machine with

      node->setStringValue("registration", net->registration[i]);



The file is a clone of the native controls io, purpose being to forward the
clouds, AI and multiplayer info to the slave pcs for display.

Now I have the Ai aircraft  data across to the slaves, my next question is
where does FG pick up the AI items attached for display by the AIbase? Ie I
need to fool the slaves to display the imported aircraft from the data,
preferably with out diabling the Ai base as It is still used displaying the
multiplayer on the slaves from another protocol and port.

I know i could do it with a cloned Ai update funtion, but maybe i can do it
at a lower level?


BTW ref our mail of last weekend, I have been putting a drawing together of
how I have interconnected  the sim aircraft hardware by can bus to FG I
would have mailed it by now if I had not been banging my head on the walls
with this string issue. I will revert with it shortly


Regards Harry






On Fri, Apr 17, 2009 at 2:30 AM, Curtis Olson <curtolson@gmail.com> wrote:

>
>
> On Thu, Apr 16, 2009 at 1:07 AM, Harry Campigli wrote:
>
>>
>>
>>
>> How fo write an FG string property from an indexed string in a structure?
>>
>> Possibly someone can help please , I have tried to find an example with no
>> luck, I am sure i had it working yesterday but now every way i try i end up
>> with it wrong at compile, a seg fault or a property node with an empty
>> string. The basic setup works fine with doubles ect, here i only show the
>> string code.
>>
>>
>> Its wrong, but this is what i want to do, where : index i is declared as
>> an int,  path is a node, and path[i] is a string indexed in the structure
>> called buf-    node->setStringValue("path",buf->path[i]);
>> )
>>
>> 1-The stucture called buf with indexed stings in it from the h file
>> >
>>     enum {
>>         FG_MAX_AIRCRAFT = 25
>>     };
>>     uint32_t num_aircraft;
>>     string callsign[FG_MAX_AIRCRAFT];
>>     string path[FG_MAX_AIRCRAFT];
>> >
>>
>>
>> 2- I write to the stucture with
>>
>> >
>>       tempnode = node->getChild("path");
>>       if ( tempnode != NULL ) {
>>           net->path[i] =  tempnode->getStringValue();
>>       }
>>
>> >
>
>
> At a glance, this looks like it should work.  I believe getStringValue()
> returns a const char * type and you should be able to assign this to a
> "string" variable like you show in your example code.
>
> If I was going to dig into this, I might start inserting some printf()'s to
> dump out the value of tempnode->getStringValue() to make sure that is sane.
> Make sure [i] is a sane index value, etc.  Off by one errors are pretty easy
> to accidentally introduce.  Hehe, I still have trouble with those off by an
> order of magnitude errors ... :-)
>
> Without seeing your surrounding code, I think I would be most interested in
> first checking the value of "i".  That should remain between 0 and 24 (i=25
> would be an array overrun because you'd be referencing the 26th element of
> the array.)
>
> Best regards,
>
> Curt.
> --
> Curtis Olson: http://baron.flightgear.org/~curt/<http://baron.flightgear.org/%7Ecurt/>
>
>
> ------------------------------------------------------------------------------
> Stay on top of everything new and different, both inside and
> around Java (TM) technology - register by April 22, and save
> $200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
> 300 plus technical and hands-on sessions. Register today.
> Use priority code J9JMT32. http://p.sf.net/sfu/p
> _______________________________________________
> Flightgear-devel mailing list
> Flightgear-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/flightgear-devel
>
>


-- 
Regards Harry

19b Jln Danau Poso
Sanur, Bali
80228

H +62 361 285629
M +62 812 7016328

[Attachment #5 (text/html)]

HI Curtis thanks for the response,<br><br>Well I tore my hair out for a couple of \
days. But I could never make any sense of the string stored in the structure, nor \
could I find a string terminator in it. I dont know exactly why as i am not very \
experieced in c strings.<br>  <br>I ended up putting the property to a local string, \
then writing it into a normal char array in the structure adding a teminator after \
the last printable.<br><br><br>Certianly not elegant but works for now to load the \
stucture. A programer would write it differently to me!<br> <br><br>      tempnode = \
node-&gt;getChild(&quot;registration&quot;);<br>      pt = net-&gt;registration[i];   \
// pointer to array in struct<br>      pt[0] = &#39;\0&#39;;                          \
// put an end of string for default<br>  if ( tempnode != NULL ) {<br>          temp \
=  tempnode-&gt;getStringValue();<br>          n=0;<br>          x=0x31;<br>          \
while ( (x &gt; 0x19)&amp; (x&lt;0x7f) &amp; (n &lt; SL_MAX_REGISTRATION)){<br>       \
x=temp[n];                                            // pointer to prop string to \
send <br>  pt[n] = x;                                             // wite to the \
struct string<br>          n++;<br>          }<br>          pt[n] = &#39;\0&#39;; \
//0x0A;<br>      }<br><br>From the structure Its written into the other machine \
with<br> <br>      node-&gt;setStringValue(&quot;registration&quot;, \
net-&gt;registration[i]); <br><br><br><br>The file is a clone of the native controls \
io, purpose being to forward the clouds, AI and multiplayer info to the slave pcs for \
display.<br> <br>Now I have the Ai aircraft  data across to the slaves, my next \
question is where does FG pick up the AI items attached for display by the AIbase? Ie \
I need to fool the slaves to display the imported aircraft from the data, preferably \
with out diabling the Ai base as It is still used displaying the multiplayer on the \
slaves from another protocol and port. <br> <br>I know i could do it with a cloned Ai \
update funtion, but maybe i can do it at a lower level?<br><br><br>BTW ref our mail \
of last weekend, I have been putting a drawing together of how I have interconnected  \
the sim aircraft hardware by can bus to FG I would have mailed it by now if I had not \
been banging my head on the walls with this string issue. I will revert with it \
shortly<br> <br><br>Regards Harry<br><br> <br><br>  <br><br><br><div \
class="gmail_quote">On Fri, Apr 17, 2009 at 2:30 AM, Curtis Olson <span \
dir="ltr">&lt;<a href="mailto:curtolson@gmail.com">curtolson@gmail.com</a>&gt;</span> \
wrote:<br> <blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, \
204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br><br><div \
class="gmail_quote"><div><div></div><div class="h5">On Thu, Apr 16, 2009 at 1:07 AM, \
Harry Campigli <span dir="ltr"></span>wrote:<br> <blockquote class="gmail_quote" \
style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; \
padding-left: 1ex;"> <br clear="all"><br><br>How fo write an FG string property from \
an indexed string in a structure?<br><br>Possibly someone can help please , I have \
tried to find an example with no luck, I am sure i had it working yesterday but now \
every way i try i end up with it wrong at compile, a seg fault or a property node \
with an empty string. The basic setup works fine with doubles ect, here i only show \
the string code.<br>


<br><br>Its wrong, but this is what i want to do, where : index i is declared as an \
int,  path is a node, and path[i] is a string indexed in the structure called buf-    \
node-&gt;setStringValue(&quot;path&quot;,buf-&gt;path[i]);  <br>


)  <br><br>1-The stucture called buf with indexed stings in it from the h \
file<br>&gt;<br>    enum {<br>        FG_MAX_AIRCRAFT = 25<br>    };<br>    uint32_t \
num_aircraft;<br>    string callsign[FG_MAX_AIRCRAFT];<br>    string \
path[FG_MAX_AIRCRAFT];<br>


&gt;<br><br><br>2- I write to the stucture with <br><br>&gt;<br>      tempnode = \
node-&gt;getChild(&quot;path&quot;);<br>      if ( tempnode != NULL ) {<br>          \
net-&gt;path[i] =  tempnode-&gt;getStringValue();<br>      }<br>


<br>&gt;<font color="#888888"></font></blockquote></div></div><div><br>At a glance, \
this looks like it should work.  I believe getStringValue() returns a const char * \
type and you should be able to assign this to a &quot;string&quot; variable like you \
show in your example code.<br>

<br>If I was going to dig into this, I might start inserting some printf()&#39;s to \
dump out the value of tempnode-&gt;getStringValue() to make sure that is sane.  Make \
sure [i] is a sane index value, etc.  Off by one errors are pretty easy to \
accidentally introduce.  Hehe, I still have trouble with those off by an order of \
magnitude errors ... :-)<br>

<br>Without seeing your surrounding code, I think I would be most interested in first \
checking the value of &quot;i&quot;.  That should remain between 0 and 24 (i=25 would \
be an array overrun because you&#39;d be referencing the 26th element of the array.) \
<br>

</div></div><br clear="all">Best regards,<br><br>Curt.<br><font color="#888888">-- \
<br>Curtis Olson: <a href="http://baron.flightgear.org/%7Ecurt/" \
target="_blank">http://baron.flightgear.org/~curt/</a><br> \
</font><br>------------------------------------------------------------------------------<br>
 Stay on top of everything new and different, both inside and<br>
around Java (TM) technology - register by April 22, and save<br>
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.<br>
300 plus technical and hands-on sessions. Register today.<br>
Use priority code J9JMT32. <a href="http://p.sf.net/sfu/p" \
target="_blank">http://p.sf.net/sfu/p</a><br>_______________________________________________<br>
 Flightgear-devel mailing list<br>
<a href="mailto:Flightgear-devel@lists.sourceforge.net">Flightgear-devel@lists.sourceforge.net</a><br>
 <a href="https://lists.sourceforge.net/lists/listinfo/flightgear-devel" \
target="_blank">https://lists.sourceforge.net/lists/listinfo/flightgear-devel</a><br> \
<br></blockquote></div><br><br clear="all"><br>-- <br>Regards Harry<br><br>19b Jln \
Danau Poso<br>Sanur, Bali<br>80228<br><br>H +62 361 285629<br>M +62 812 7016328<br>



------------------------------------------------------------------------------
Stay on top of everything new and different, both inside and 
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today. 
Use priority code J9JMT32. http://p.sf.net/sfu/p

_______________________________________________
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic