Could I ask for some help and advise on this issue.

I am trying to interface my Microchip Pic based sim hardware to FG. I have
it working with a genetic string but the string is becoming to large for the
pics to handle, also I would like a crc or check sum on the data. Thus i
prefer a compressed hex format. Ie  the pic sends 4 bytes sync,16 bytes each
bit being a switch boolean, 16 bytes each being an analog setting then 2
bytes with each bit being a sign on the 16 analogs.

The format thus is A5 5A A5 5A hh hh hh hh hh hh .......for 40 bytes.

For simplicity I opted to clone and adapt the Atlas driver, keeping in line
with all existing FG conventions. and use it as a frame. and intigrate my
driver into FG when i build.

So far I have bumbled my way along, I not a good programmer but have learnt
my way around C with the microchip C18 to drive all the hardware. I have
managed to generate and output a binary compressed message from FG. But cant
seem to get it to decode on the inwards stream.


My approach is similar to the way i run the can bus between the hardware
Pics, pick up the char one at a time, check for the first A5, then 3 sync
chars from "buf" then if ok (synced up), copy the next 40 chars to "msgin".
If thats ok then it sets a flag to decode the data. for now i also have an
0x0D on the end making it 41 chars. Later i intend to add the CRC routine.
Also I intend to use a network socket to the Pics once its all working. I
try to work in small steps.

It seems I cant pick up the first A5, as I understand it, "buf" has the data
in.

My question is how does the low level IO in Sg and FG work, am I wrong to
work on the premise that every time parse message is called buf contains
fresh data from the serial, Or does the the low level code require a CR? DO
i need to set up a static ring buffer os sorts and take the incoming from
that?


Below Is the code as it stands. i would expect to come out of this with
Msg_CS_OK=1, but maybe its not quite correct, for starters I need to pick up
the first sync char.


I hope i have provided enough info to enable an answer,
Regards Harry

FYI the OS is suse11.1 but i am not having any problems from that point of
view.





bool FGSim::parse_message() {
    SG_LOG( SG_IO, SG_INFO, "parse atlas message" );
    char msgin[256],dblin[6];
    char a,b,c,d,e,f,g,h,b0,b1,b2,b3,b4,b5,b6,b7,w,starter,Char_Count,ch,l;
    static char Msg_State,Msg_pointer,Message_CS_H,Message_CS_L,Msg_CS_OK;
    double min, max;
    int intin;
    char pbsw;

//   string msg = buf;
//    msg = msg.substr( 0, length );
//    SG_LOG( SG_IO, SG_INFO, "entire message = " << msg );

   SGPropertyNode * node;




  Char_Count = 41; // length
  l =0;
  while(l != Char_Count)
      {

    ch = buf[l];
    switch (Msg_State)
    {
      case 0:                            // find the sync header byte 0
      if(ch == 0xA5)
      {
            Msg_State++;
            Msg_CS_OK = 0;
            b5=false;                                              // test
to see if value recieved.
            node = fgGetNode("/controls", true);
            node->setBoolValue("gear/gear-down", b5);
     }

      break;

      case 1:                            // find the sync header byte 1
      if(ch == 0x5A) {Msg_State++;}
      else Msg_State= 0;

      break;

      case 2:                            // find the sync header byte2
      if(ch == 0xA5) {Msg_State++;}
      else Msg_State= 0;
      break;
      case 3:                            // find the sync header byte 3
      if(ch == 0x5A) {Msg_State++;Msg_pointer=0;}            // reset
counter point for msgin
      else Msg_State= 0;
      break;

      case 4:
      msgin[Msg_pointer] =ch;
      Msg_pointer++;                    // write ch to msgin till all done
      if(Msg_pointer==40){Msg_State++;Msg_CS_OK=1;}
      break;

      case 5:                        //    get fist cs byte
      Message_CS_H = ch;
      Msg_State++;
      break;

      case 6:
      Message_CS_L =ch;
      Msg_State = 0;
      break;
      default:
      Msg_State=0;
      break;

    } // switch


     l++;
    } // while

.....
------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
Flightgear-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/flightgear-devel

Reply via email to