20,741
edits
m (→Introduction) |
m (→Introduction) |
||
| Line 3: | Line 3: | ||
= Introduction = | = Introduction = | ||
You can't really directly 'access' a device from nasal. What you'll most likely want to do is define a [[Generic Protocol]] for the properties | You can't really directly 'access' a device from nasal. What you'll most likely want to do is define a [[Generic Protocol]] for the properties you're interested in sending between fgfs and your device. You can configure FlightGear to use that protocol directly with your serial device, through network to secondary program which handles serial, etc. | ||
Of course, in flightgear, you can then use nasal to handle and modify the properties being sent/received by whatever logic you desire. | Of course, in flightgear, you can then use nasal to handle and modify the properties being sent/received by whatever logic you desire. | ||
| Line 16: | Line 16: | ||
This is due to the power of the subsystems that are largely configurable, usable and accessible using XML and the property tree - there's is often no need for any low level "hard coding" (i.e. in C or C++ space). Basically, FlightGear allows you to make use of features that would take even an experienced C++ developers hours or even weeks to recreate in C++ space, and this is without even touching the core C++ source code. | This is due to the power of the subsystems that are largely configurable, usable and accessible using XML and the property tree - there's is often no need for any low level "hard coding" (i.e. in C or C++ space). Basically, FlightGear allows you to make use of features that would take even an experienced C++ developers hours or even weeks to recreate in C++ space, and this is without even touching the core C++ source code. | ||
Accessing a serial port by coming up with a generic protocol is simple and well-documented. We have a plethora of examples, too - if you'd | Accessing a serial port by coming up with a generic protocol is simple and well-documented. We have a plethora of examples, too - if you'd like to copy/paste stuff from different places. Then, all you need to do is to come up with input and output properties for transmitting your data. Once this is working, you can look into coming up with a piece of Nasal to further process the properties as required. | ||
A generic protocol is really nothing more than a list of properties to send and/or receive. Nothing complex to develop and think about, just what properties are of importance to you. Also don't worry about Nasal at this point, it is not necessary for sending/receiving from generic protocol which just reads/writes from the property tree. Thinking about Nasal at this point is just muddying the water...forget about it until you actually need it. | A generic protocol is really nothing more than a list of properties to send and/or receive. Nothing complex to develop and think about, just what properties are of importance to you. Also don't worry about Nasal at this point, it is not necessary for sending/receiving from generic protocol which just reads/writes from the property tree. Thinking about Nasal at this point is just muddying the water...forget about it until you actually need it. | ||
| Line 22: | Line 22: | ||
For example: just imagine the simplest protocol that you can come up with which simply sends a string to some other host, once you are able to modify this string from Nasal space, you can also implement entire protocols on top of the property tree without it even being aware of it. | For example: just imagine the simplest protocol that you can come up with which simply sends a string to some other host, once you are able to modify this string from Nasal space, you can also implement entire protocols on top of the property tree without it even being aware of it. | ||
Now, all you need is some simple generic protocol that sends your "output property" to your target device/host. | Now, all you need is some simple generic protocol that sends your "output property" to your target device/host: | ||
<syntaxhighlight lang="xml"> | |||
<?xml version="1.0"?> | |||
<PropertyList> | |||
<generic> | |||
<output> | |||
<line_separator>newline</line_separator> | |||
<var_separator>tab</var_separator> | |||
<chunk> | |||
<name>eufd property</name> | |||
<node>/sim/cockpit/eufd</node> | |||
<type>string</type> | |||
<format>%s</format> | |||
</chunk> | |||
</output> | |||
</generic> | |||
</PropertyList> | |||
</syntaxhighlight> | |||
The same concept could also be used to come up with an "input property" to process results from your device. | The same concept could also be used to come up with an "input property" to process results from your device. | ||
| Line 31: | Line 52: | ||
We suggest you just try it, create a simple protocol with a couple properties, explore ways to send and receive those values, and so on. If your serial device is a microcontroller that your programming then you may be able to get away with sending/receiving the values directly to/from flightgear without need of any secondary 'middleware' programs at all. If not you may need a small program to handle marshalling the data between flightgear and your hardware. | We suggest you just try it, create a simple protocol with a couple properties, explore ways to send and receive those values, and so on. If your serial device is a microcontroller that your programming then you may be able to get away with sending/receiving the values directly to/from flightgear without need of any secondary 'middleware' programs at all. If not you may need a small program to handle marshalling the data between flightgear and your hardware. | ||
On the pc side of things I would strongly suggest forgetting about C/C++ unless you really, really prefer it and/or have no choice. It is going to be much more complex doing serial and/or network programming in straight C/C++. Using a serial device properly requires more than just 'fopen'ing it, except in the most simple of cases, and can be quite tedious and complex using straight C system calls...networking as well. Personally I recommend using a higher level language (I use Python) that will make your life so much easier and allow you to get things done quickly and easily without hassles of low level details. | On the pc side of things I would strongly suggest forgetting about C/C++ unless you really, really prefer it and/or have no choice. It is going to be much more complex doing serial and/or network programming in straight C/C++. | ||
Using a serial device properly requires more than just 'fopen'ing it, except in the most simple of cases, and can be quite tedious and complex using straight C system calls...networking as well. Personally I recommend using a higher level language (I use Python) that will make your life so much easier and allow you to get things done quickly and easily without hassles of low level details. | |||
For your data processing needs (formatting, conversion, marshalling, compression etc), you can use a combination of the sprintf() library function, and the [http://gitorious.org/fg/fgdata/blobs/master/Nasal/bits.nas bits.nas module in $FG_ROOT/bits.nas]. | For your data processing needs (formatting, conversion, marshalling, compression etc), you can use a combination of the sprintf() library function, and the [http://gitorious.org/fg/fgdata/blobs/master/Nasal/bits.nas bits.nas module in $FG_ROOT/bits.nas]. | ||
| Line 40: | Line 63: | ||
setprop(output_property, data); | setprop(output_property, data); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
* http://plausible.org/nasal/lib.html | * http://plausible.org/nasal/lib.html | ||