Welcome to my first ever Nasal script. And I'm very much a novice programmer, so please bear with me.
System: (Linux Manjaro 4.19.36-1-MANJARO, X86_64, XFCE, FGFS 2018.3.2)
Goal:
To add a new property to the property tree of the FGUK Lightning T5. The value of this new property is to be a string of 9 bools.
These bools are to represent the undercarriage position in terms of the cockpit indicator lamps that are illuminated per undercaruage leg:
Green (locked down)
Amber (unlocked / in transit)
Red (locked up)
I am trying to read the 0.00 to 1.00 value of each leg using these properties:
Port: props.globals.getValue(gear/gear[1]/position-norm
Nose: props.globals.getValue(gear/gear[0]/position-norm
Stbd: props.globals.getValue(gear/gear[2]/position-norm
Then I am doing less than / greater than compares within IF functions to set my bools, which are then hopefully assembled into a string in a new property:
gear/indicators/as-string
This new string property is to be sent out over serial protocol to my Arduino board to operate a physical undercarriage indicator. I want it as a single string with no delimiters between the bools as I wish to chuff it straight out of the Arduino over I2C to an I/O expander IC dedicated to this indicator unit. (Had I set up individual properties for each bool, I'd end up with delimited data going to the Arduino which I'd then have to re-assemble as a string.)
Work so far:
This has all very much been a monkey-see, monkey do approach to coding, as I couldn't really understand the nasal instructions / guidance. As an alternative approach, I delved into existing nasal files and had a go at interpreting the code from them, and forming my own take on it.
I have edited /home/scott/fguk/Aircraft/EE-Lightning/ lightningT5-yasim-set.xml to include a reference for the nasal script, I assume this to be correct as my .nas file appears in the log file (with errors):
- Code: Select all
<uc-hardware-indicators>
<file>Aircraft/EE-Lightning/Nasal/uc-hw-ind.nas</file>
</uc-hardware-indicators>
</nasal>
/home/scott/fguk/Aircraft/EE-Lightning/Nasal/uc-hw-ind.nas file contents - I must emphasise this was based on my best guess of what might work based on no nasal experience

- Code: Select all
print("loading Undercarriage Hardware Indicator script...");
bool port-red;
bool port-amber;
bool port-green;
bool nose-red;
bool nose-amber;
bool nose-green;
bool stbd-red;
bool stbd-amber;
bool stbd-green;
##Build string of bools, one for each indicator lamp:
initNode(path = gear/indicators/as-string, value = "port-red""port-amber""port-green""nose-red""nose-amber""nosegreen""stbd-red""stbd-amber""stbd-green", STRING);
##Port [1] undercarriage indicator lamps:
if ( props.globals.getValue(gear/gear[1]/position-norm < 0.2 ) {
port-red.setBoolValue(1);
}
else {
port-red.setBoolValue(0);
}
if ( props.globals.getValue(gear/gear[1]/position-norm > 0.2 ) {
if ( props.globals.getValue(gear/gear[1]/position-norm < 0.8 ) {
port-amber.setBoolValue(1);
}
else {
port-amber.setBoolValue(0);
}
}
if ( props.globals.getValue(gear/gear[1]/position-norm > 0.8 ) {
port-green.setBoolValue(1);
}
else {
port-green.setBoolValue(0);
}
##Nose [0] undercarriage indicator lamps:
if ( props.globals.getValue(gear/gear[0]/position-norm < 0.2 ) {
nose-red.setBoolValue(1);
}
else {
nose-red.setBoolValue(0);
}
if ( props.globals.getValue(gear/gear[0]/position-norm > 0.2 ) {
if ( props.globals.getValue(gear/gear[0]/position-norm < 0.8 ) {
nose-amber.setBoolValue(1);
}
else {
nose-amber.setBoolValue(0);
}
}
if ( props.globals.getValue(gear/gear[0]/position-norm > 0.8 ) {
nose-green.setBoolValue(1);
}
else {
nose-green.setBoolValue(0);
}
##Stbd [0] undercarriage indicator lamps:
if ( props.globals.getValue(gear/gear[2]/position-norm < 0.2 ) {
stbd-red.setBoolValue(1);
}
else {
stbd-red.setBoolValue(0);
}
if ( props.globals.getValue(gear/gear[2]/position-norm > 0.2 ) {
if ( props.globals.getValue(gear/gear[2]/position-norm < 0.8 ) {
stbd-amber.setBoolValue(1);
}
else {
stbd-amber.setBoolValue(0);
}
}
if ( props.globals.getValue(gear/gear[2]/position-norm > 0.8 ) {
stbd-green.setBoolValue(1);
}
else {
stbd-green.setBoolValue(0);
}
Log File error:
- Code: Select all
nasal:5:/var/tmp/pamac-build-scott/flightgear/src/flightgear-2018.3.2/src/Scripting/NasalSys.cxx:1315:Nasal parse error: parse error in /home/scott/fguk/Aircraft/EE-Lightning/Nasal/uc-hw-ind.nas, line 25
Ok, so a parse error in the first request for data from the property tree in this line: "if ( props.globals.getValue(gear/gear[1]/position-norm < 0.2 ) {" since all the other requests follow the same format I'll correct them all too if someone can tell me what's wrong.
I ran fgfs, checked the property browser, and found my new string property is not there under gear/ so I guess if I can fix this parse error in the log, it'll be followed by another error of creating the new property.
Please, any help is greatly appreciated, I hope this explains what I'm trying to achieve, and how I've gone about it in enough detail.
Many thanks, Scott.