Script Language

erskyTx runs on many radios and upgrade boards
ersky9x was a port of er9x for use on the sky9x board.
cutdact
Posts: 21
Joined: Tue Oct 04, 2016 7:28 am
Country: Finland

Re: Script Language

Post by cutdact »

Wow thanks Mike! I think i have to give up, this is way beyond me. I don't get the basics of telemetry sending and receiving. Where can i read up on this?

Are you first requesting a value of a certain dataId and then receiving that value if the physicalId and primId are correct?

Thanks,
Martin

User avatar
MikeB
9x Developer
Posts: 17990
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: Script Language

Post by MikeB »

I'm not sure there is anything for you to read. As developers, we have some information from FrSky, but that is under a NDA, so we can't publish it. What is possible is to read code that makes use of the information.
In S6R.bas (written from S6R.LUA from FrSky), I'm accessing the S6R/S8R configuration data.

This line requests data:
result = sportTelemetrySend( 0x17, 0x30, 0x0C30, sportfield)
The 0x30 is the configuration request code, the 0x0C30 is the application ID for the S6R/S8R, and the value of "sportfield" is the specific item required.

Returned data is obtained by calling:
result = sportTelemetryReceive( physicalId, primId, dataId, value )
where the primId should be 0x32 (configuration request response), the dataId should still be 0xC30 and the value contains the specific item code in the lowest 8 bits and the data value in the remaining 24 bits.

Writing configuration data is done by calling:
sportTelemetrySend( 0x17, 0x31, 0x0C30, sportwrite + writevalue*256)
the 0x31 is the configuration write request and the last parameter contains the specific item code in the lowest 8 bits and the data value in the remaining 24 bits.

Mike.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
cutdact
Posts: 21
Joined: Tue Oct 04, 2016 7:28 am
Country: Finland

Re: Script Language

Post by cutdact »

Thank you for clarifying. I think it's the application ID that is throwing me off here. In LUA they use a bunch of bitwise operations and i can't really get my head around why. https://github.com/betaflight/betafligh ... msp_sp.lua

for example:

sportMspSeq = bit32.band(sportMspSeq + 1, 0x0F)

Isnt this the same as sportMspSeq += 1, with a max value of 15?

so it could be solved like,

sportMspSeq += 1
if sportMspSeq = 15 then sportMspSeq = 0
end

Martin
User avatar
MikeB
9x Developer
Posts: 17990
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: Script Language

Post by MikeB »

That looks to be a valid solution.

I have got copies of those .LUA files, but I don't have any betaflight hardware. So I can make suggestions for code for this script language but can't test them fully.
I see that .LUA file uses the XOR function. I have just added some support for that, but I haven't tested it yet (it is in "e6"). You use the operator '^' for XOR. I haven't yet got ^= in.

Mike.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
tsenecal
Posts: 45
Joined: Wed Mar 22, 2017 8:32 pm
Country: United States

Re: Script Language

Post by tsenecal »

Okay, i have the r221e6 rev of the firmware installed, and i am trying to run the different telemetry scripts... all of the examples that have been posted on this thread simply display model name, TX voltage, 00:00 on the first line, and SCRIPT ERROR in the middle of the screen.

running the S6R.bas from the scripts menu does work.

do i need to be doing something other than making a custom script telemetry screen to get the telemetry scripts to run? there is no line number printed anywhere, and i power on and off the transmitter after typing the name of a new script into the configuration screen.

edit:
running any of the scripts from the scripts (statistics) menu works. the tel0.bas script will not run as a telemetry script. in that case, it prints SCRIPT ERROR.

this is using a bone stock AR9x board on a turnigy 9x

User avatar
MikeB
9x Developer
Posts: 17990
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: Script Language

Post by MikeB »

Check this post: viewtopic.php?f=7&t=10325&start=30#p131972, for where telemetry scripts need to be on the SD card.

Mike.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
tsenecal
Posts: 45
Joined: Wed Mar 22, 2017 8:32 pm
Country: United States

Re: Script Language

Post by tsenecal »

MikeB wrote: Wed Sep 20, 2017 9:03 am Check this post: viewtopic.php?f=7&t=10325&start=30#p131972, for where telemetry scripts need to be on the SD card.

Mike.
in an effort to debug the three telemetry scripts that have been discussed on this thread, i have placed them in the following directories:

/SCRIPTS/
/SCRIPTS/TELEMETRY/

and renamed them t1, t2, t3, so...


/SCRIPTS/t1.bas
/SCRIPTS/t2.bas
/SCRIPTS/t3.bas
/SCRIPTS/S6R.bas

/SCRIPTS/TELEMETRY/t1.bas
/SCRIPTS/TELEMETRY/t2.bas
/SCRIPTS/TELEMETRY/t3.bas

as stated before, when running them as standalone scripts... they work. running them as telemetry scripts, they don't. i have also tried setting the telemetry script names in the custom telemetry screen to both "t1" and "t1.bas", and that makes no difference, either way, i get "SCRIPT ERROR".

the names of the directories were taken from the august 20th revision of the scripts.pdf document.
User avatar
MikeB
9x Developer
Posts: 17990
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: Script Language

Post by MikeB »

I've just posted a fix for telemetry scripts not displaying, and checked tel0.bas displays correctly on an AR9X board (happens to have a 4S8 processor).
In trying to fix a flickering display, I caused another problem.

If this sorts your problem, then I'll do a full "e7" version.

Mike.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
tsenecal
Posts: 45
Joined: Wed Mar 22, 2017 8:32 pm
Country: United States

Re: Script Language

Post by tsenecal »

MikeB wrote: Wed Sep 20, 2017 5:19 pm I've just posted a fix for telemetry scripts not displaying, and checked tel0.bas displays correctly on an AR9X board (happens to have a 4S8 processor).
In trying to fix a flickering display, I caused another problem.

If this sorts your problem, then I'll do a full "e7" version.

Mike.

Mike, i believe this fixes it... to a point. i think others also note that changing the script in the telemetry config screen means that one will have to reboot/power cycle the transmitter to get it to properly run the new script. I also noticed that pressing the exit button while viewing the actual telemetry script screen will cause the script to "crash", ie display the "SCRIPT ERROR" screen. the only way to resolve that is to power cycle.

other than that, all 3 telemetry scripts work, displaying "Hello", tx voltage, the line, the box, the live aileron pot value... etc.
User avatar
MikeB
9x Developer
Posts: 17990
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: Script Language

Post by MikeB »

tel0.bas is the (only?) script I've posted that is a "real" telemetry script. Pressing EXIT when this is displaying doesn't terminate it.
t.bas is a "standalone" script, so includes code to notice the EXIT button is pressed and then terminate.
When I select tel0.bas from the custom telemetry configuration it does start running correctly. I'll run some more tests, but changing the selected script name should reload all non-standalone scripts.
When you run a standalone script, alll other scripts are terminated, but are then re-loaded when the standalone script terminates.

If you haven't noticed, a standalone script may be run from an item in the main popup menu.

Mike.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Script Language

Post by jhsa »

Mike, what about if the telemetry scripts only worked when selected from the custom screen, and the others only from the other menu?
Is it possible for the radio to recognize the type of script and reject it if it is the wrong one? Perhaps a message like "WRONG SCRIPT" could be displayed??

Thanks

João
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW
User avatar
MikeB
9x Developer
Posts: 17990
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: Script Language

Post by MikeB »

A LONG EXIT, should terminate a standalone script, even if the script doesn't monitor the EXIT button.

There is no difference in the scripts to detect what "type" it is.
Standalone scripts must be in the "SCRIPTS" directory.
Telemetry scripts must be in the "SCRIPTS/TELEMETRY" directory.
Model scripts must be in the "SCRIPTS/MODEL" directory.

When a script is run, some context information is provided to the script. This may be obtained by calling sysflags() in the script.
The result is a set of bits indicating:
Bit 0 is set if the display is available to the script.
Bit 1 is set if the script is running as a standalone script.
Bit 2 is set if the script is running as a telemetry script.
Bit 3 is set to indicate the script is resuming:
To prevent a script from taking over the processor from normal operation, the number of script statements that are executed each time it runs is limited (to 150 currently). If a script reaches a "stop" statement, then it stops executing, the display will be updated if in use, and the script will run from the beginning next time it runs. If a script runs for over 150 statements, then it is paused, the display is NOT updated, and it will continue from that point next time it runs. This is when the bit 3 will be set.

Each script is run every 10mS.

So a script can report if it is the "Wrong" one!

Mike.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Script Language

Post by jhsa »

Thanks for the explanation..

João
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW
tsenecal
Posts: 45
Joined: Wed Mar 22, 2017 8:32 pm
Country: United States

Re: Script Language

Post by tsenecal »

forgive me if this is a dim set of questions, especially if they have already been asked...

I have a pretty good handle on what a standalone script is, the SR6.bas gives me an example that makes sense.
I have a pretty good handle on what a telemetry script is, both the tel0.bas, and the telemetry scripts i have written in lua make that pretty obvious... in fact, i can understand the reason for a custom telemetry screen very easily... you want to display custom data in a manner not done by standard telemetry screens...

what i haven't yet wrapped my head around is the concept of a model script... what are the limitations, what are the benefits, why would someone "need" a model script? the documentation is kind of sparse on this... just trying to understand what would one use a model script for.

what happens if a model has both a model script and a telemetry script... i presume a telemetry script is unique to a model (tel0.bas for model "x", tel1.bas for model "y")
Last edited by tsenecal on Thu Sep 21, 2017 9:43 pm, edited 1 time in total.
User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Script Language

Post by jhsa »

I'm not into scripts, and i'm just trying to start understanding them, but You got a good point there.
Until today, I found very few things I couldn't do with just the radio while programming a model.. :)
Perhaps to do some wicked light sequencing for example? Something like that??

João
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW
User avatar
MikeB
9x Developer
Posts: 17990
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: Script Language

Post by MikeB »

As currently implemented, a model may have two telemetry scripts (one for each of the two custom telemetry screens), and a single model script.
A model script runs in the background, it doesn't have anywhere to display anything, but it can play voice files.
There are a number of functions available to access certain items:
getvalue
getswitch
settelitem
setswitch
playfile
playnumber

One request I recall is to be able to put a "marker" in a log file. A model script could be written to do that. There are 6 custom telemetry values (Cus1 to Cus6). A model script could monitor a switch, and when it sees the switch become ON, it could set a value into Cus1 (which is being logged) for a second or so. Then the logfile will have a marker for that time. Since this operation doesn't need to be able to display anything, it doesn't need to be a telemetry script and occupy a custom telemetry screen.

"settelitem" can put a value into a GVAR, and a GVAR may be used as a mix source, so such a script can control a mix, and thus a channel output of the receiver if required (although not recommended for any "critical" functions, any more than a LUA script on openTx).

Mike.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Script Language

Post by jhsa »

I just wouldn't like to see Ersky9x falling into the same situation that it is happening with openTX, which is people using scripts for stuff that can be easily done with the radio's normal programming.
One other thing that I'm afraid to see is new features that wouldn't be implemented because they can be achieved with a script. Well, many (probably most) of us won't ever be able to make scripts.
I'm actually afraid of using this kind of stuff on any model I care about. I am actually trying to understand this but plan to stay well away from it on any model that I fly.. I confess that the word "script" always scared me a bit :) I do not trust it :)
But this is just my opinion of course. Maybe it will change in the future.
One script that looks quite good and inoffensive to me is the one to configure the frsky recievers.. But I think it is not used for flying any model, only for configuration.

João
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW
User avatar
MikeB
9x Developer
Posts: 17990
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: Script Language

Post by MikeB »

While it is called a script, it is actually an "interpreted" programming language, unlike the main firmware which is compiled. Compiled means the text of the program is converted to instructions the processor exeutes directly. Interpreted means the text of the program is read by a program that works out what is required. In practice, to improve performance, the text is converted into "tokens", so every character of the text doesn't need to be read all the time.
In the early days of home computing the most common programming language was BASIC, and this was interpreted initially, first with "Tiny Basic" (that only needed 2k of RAM for the interpreter, and later with more capable Basic interpreters that needed 5k to 8k. These worked very reliably.
The "script" I've implemented is based on "Tiny Basic" and should be reliable.
In general, however, the main uses for these scripts are standalone ones that do things like the S6R/S8R configuration, and telemetry ones that provide alternative displays for telemetry data or provide for things like PID modification for flight controllers. These are then extensions to the main firmware that don't need a new firmware release to be added, or take up space in the firmware when they are only used very occasionally.

Mike.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Script Language

Post by jhsa »

Thanks for the explanation once again Mike..
But i was referring to the "MODEL" scripts on my post above.
I would prefer to have the firmware in the radio controlling a feature on my model, and not a script. Also imagine for example the mess that would be exchanging models that need scripts with other radios, or even sharing them with friends. Very easy to mess something up.
Unless of course you develop another system for handling models, like, storing models on the card and have a folder for each model where all its files would be placed inside. Files like the eepm model file, scripts, check list text files, etc.
Then only one model would be loaded to the radio and stored on its memory. it would be automatically saved to the card when turning the radio OFF or loading a new model.
I think you've mentioned something along this line some time ago?

Thank You

João
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW
mrozilla
Posts: 60
Joined: Sat Nov 14, 2015 9:59 pm
Country: -

Re: Script Language

Post by mrozilla »

The "e6" version on 9XR Pro does not work tel0 script in custom telemetry. Just after the script has been opened, the screen freezes and nothing moves, the next left / right click goes to the next window correctly, but the script does not display.
The X6R script comes on, but on the D8R-II Plus nothing shows, with each option being 3 dashes (---).
Now in the test script t.bas every time after the exit (EXIT) message "ALERT, Script Error, Error 103 at line 8, press any Key", earlier this error was not.
The message appears when I hold down the EXIT button for a short while, the error does not appear.

SCRIPT/t.bas
SCRIPT/S6R.bas
SCRIPT/TELEMETRY/tel0.bas
User avatar
MikeB
9x Developer
Posts: 17990
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: Script Language

Post by MikeB »

I'll have the fix for tel0 not showing on the screen in "e7", probably I'll get that posted tomorrow.
The S6R script is only for use with S6R/S8R (stabilising) receivers, nothing will happen with a D8R-II.
I suspect the script error message is not from t.bas, but from the telemetry script that is loaded when the standalone script terminates.

From the script.pdf file, the errors are:
Error Numbers:
1 – Duplicate label
2 – Syntax (line index)
3 – Syntax
4 – Too many variables
5 – Missing ')'
6 – Divide by 0
7 – Missing THEN
8 – return without gosub
9 – invalid function name
10 – Too large
11 – Exceed dimension size
12 - Too many nested gosubs
Error numbers are returned with 100 added if detected at run time.

"e7" will also handle starting and stopping scripts better. Changing the setting in a custom telemetry screen should start and stop a telemetry script without needing a power cycle.

Mike.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
mrozilla
Posts: 60
Joined: Sat Nov 14, 2015 9:59 pm
Country: -

Re: Script Language

Post by mrozilla »

Ok, I'll wait for the new version and then I'll see what works and what does not.
User avatar
MikeB
9x Developer
Posts: 17990
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: Script Language

Post by MikeB »

"e7" now posted.

Mike.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
mrozilla
Posts: 60
Joined: Sat Nov 14, 2015 9:59 pm
Country: -

Re: Script Language

Post by mrozilla »

tel0.bas is already running, S6R is working the same way as before, but still after exiting EXIT in t.bas, an error like before, with a short press, comes out of the script without problems.
I've noticed some time ago that from one of the updates like loudly whispering loudspeaker in 9XR Pro as it is not used, there was always a slight noise but as if quieter, now it seems to me louder.
User avatar
MikeB
9x Developer
Posts: 17990
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: Script Language

Post by MikeB »

So are you still getting the "Script Error, Error 103 at line 8"? If so please create a new model, then just run t.bas as a standalone script and let me know if you still get that error report.

Mike.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
mrozilla
Posts: 60
Joined: Sat Nov 14, 2015 9:59 pm
Country: -

Re: Script Language

Post by mrozilla »

I did as you wrote and in the new profile nei error occurs when i go back to your where i have tel0.bas set up error you write when you hold down the EXIT button, when you ask about it you have already got an idea?
User avatar
MikeB
9x Developer
Posts: 17990
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: Script Language

Post by MikeB »

I can't reproduce the problem.
I set tel0.bas running in one of the custom telemetry screens, checked it is working, then ran "t.bas" from the main popup menu. This ran correctly, and when I pressed EXIT, it terminated and tel0.bas was then running again.

Do you have anything set in the model General menu for the "Bg Script"?

Mike.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
cutdact
Posts: 21
Joined: Tue Oct 04, 2016 7:28 am
Country: Finland

Re: Script Language

Post by cutdact »

Hi Mike,

could you help me solve this?

Here is the LUA code:

Code: Select all

         
         payload[1] = bit32.band(dataId,0xFF)
         dataId = bit32.rshift(dataId,8)
         payload[2] = bit32.band(dataId,0xFF)

         payload[3] = bit32.band(value,0xFF)
         value = bit32.rshift(value,8)
         payload[4] = bit32.band(value,0xFF)
         value = bit32.rshift(value,8)
         payload[5] = bit32.band(value,0xFF)
         value = bit32.rshift(value,8)
         payload[6] = bit32.band(value,0xFF)
         
I understand the function of this but i'm not sure how i would go about solving it without bitwise operations. Any chance you would implement bitwise operations in script? :lol:

EDIT: I realise just after posting that this is maybe solved simply using payload[1] = dataId & 0xFF?

Code: Select all

    payload[1] = dataId & 0xFF
    dataId /= 256
    if dataId < 1 then dataId = 0   <--- not needed
    payload[2] = dataId & 0xFF

    payload[3] = value & 0xFF
    value /= 256
    if value < 1 then value = 0   <--- not needed
    payload[4] = value & 0xFF
    value /= 256
    if value < 1 then value = 0   <--- not needed
    payload[5] = value & 0xFF
    value /= 256
    if value < 1 then value = 0   <--- not needed
    payload[6] = value & 0xFF
Would this be a valid solution? I'm not able to test it at the moment..

Martin
cutdact
Posts: 21
Joined: Tue Oct 04, 2016 7:28 am
Country: Finland

Re: Script Language

Post by cutdact »

Getting syntax error when using while loop, am i doing something wrong or is it not working yet?

Martin
User avatar
MikeB
9x Developer
Posts: 17990
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: Script Language

Post by MikeB »

Your code in the post above looks OK.
Note that the 32-bit "value", is stored as a signed value. When you go to divide it by 256, if the top bit was set, it is a negative number. You might consider doing an AND with 0xFFFFFF after the division.
I have now included the operations |=, &=, and ^= (XOR=).

The syntax for a while loop is:
while <expression>
. . . . .
end
(not wend).

while loops should be working, what is the exact error message you are getting, and what is on the line referenced?

Mike.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!

Post Reply

Return to “erskyTx (was ersky9x)”