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 » Sat Sep 30, 2017 9:07 am

Got while loops to work, my bad.

I also have a complete script for Betaflight testing, although i havent yet been able to recieve any data, i'm suspecting my setup although i'm getting telemetry data in. Could i just test it by requesting RSSI? I know it's unnecessary to request that since ersky9x already does that, but just for confirmation that my script works. On what IDs, and values are RSSI sent?


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

Re: Script Language

Post by MikeB » Sat Sep 30, 2017 11:38 am

Not all SPort data is sent to the script. It may be what you are expecting is filtered out. This is to prevent too much data being passed in that is not required by a script.
The receive function is:
sportTelemetryReceive( PhyId, Command, AppId, data)
Currently SPort data is only available if either the command ix 0x32 (Configuration response) or if the AppId is 50xx or 10xx. This is the same (actually with 10xx added) as openTx does with LUA scripts, and that appears to work with a Betaflight PID (LUA) script.

To check what is being received on the SPort, you could try logging the raw received SPort data.
Go here for instructions on how to enable "raw logging", get a log file and post it on here: viewtopic.php?f=7&t=40&p=123508&hilit=r ... ng#p123508.
The DEBUG menu is UP LONG, then RIGHT a few times.
Note that the "raw logging" option is not kept through a power off-on cycle.

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 » Sat Sep 30, 2017 12:53 pm

Code: Select all

reply:

	while result=1
		result = sportTelemetryReceive( physicalId, primId, dataId, value )
			if physicalId = REMOTE_SENSOR_ID
				if primId = REPLY_FRAME_ID

					payload[1] = dataId & 0xFF
					dataId /= 256
					payload[2] = dataId & 0xFF

					payload[3] = value & 0xFF
					value /= 256
					payload[4] = value & 0xFF
					value /= 256
					payload[5] = value & 0xFF
					value /= 256
					payload[6] = value & 0xFF
			
					gosub receive
				else
					goto run
				end
			end
	end

return


send:

    dataId = 0
    dataId = sportMspSeq
	dataId += 16
    dataId += 32

	sportMspSeq += 1
    sportMspSeq = sportMspSeq & 0x0F
   
    value = 0
    value = cmd & 0xFF
    value = value + 29952

    mspLastReq = cmd
    mspRequestsSent += 1
    
    sportTelemetrySend(LOCAL_SENSOR_ID, REQUEST_FRAME_ID, dataId, value)

return


run:

   now = gettime()

    if Event = EVT_MENU_LONG
      gosub reset
   end

   drawclear()
   drawtext(0, 0, "MSP/SPORT test script", INVERS)
   
    if getvalue("RSSI") > 0


        drawtext(1, 11, "Rqst:", 0)
        drawnumber(40, 11, mspRequestsSent, 0)
      
        drawtext(1, 21, "Rply:", 0)
        drawnumber(40, 21, mspRepliesReceived, 0)
       
        drawtext(1, 31, "PkRx:", 0)
        drawnumber(40, 31, mspPkRxed, 0)  
      
        drawtext(1, 41, "ErPk:", 0)
        drawnumber(40, 41, mspErrorPk, 0)
      
        drawtext(61, 11, "StPk:", 0)
        drawnumber(100, 11, mspStartPk, 0)
      
        drawtext(61, 21, "OuOr:", 0)
        drawnumber(100, 21, mspOutOfOrder, 0)
      
        drawtext(1, 51, "CRCE:", 0)
        drawnumber(40, 51, mspCRCErrors, 0)

		lastReqTSm = lastReqTS + 200
        if lastReqTSm <= now
			result = 1
            lastReqTS = now
			gosub send
        end
    else
        drawtext(50, 20, "NO", BLINK + DBLSIZE)
		drawtext(5, 40, "TELEMETRY!", BLINK + DBLSIZE)
    end
    gosub reply
    
	
	if Event = EVT_EXIT_BREAK then goto done
	end
stop
done:
finish
I'm expecting 0x32 to be returned, but do i need to send it aswell?
Attachments
Reptile-0000-00-00-000000.rar
(777 Bytes) Downloaded 69 times

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

Re: Script Language

Post by MikeB » Sat Sep 30, 2017 2:20 pm

I have a few changes to your code:

Code: Select all

rem Execution always begins at the start of the file
rem So if "run" should execute, you need:
goto run

rem Adding missing subroutine:
receive
return

reply:

	while result=1
		result = sportTelemetryReceive( physicalId, primId, dataId, value )
			if physicalId = REMOTE_SENSOR_ID
				if primId = REPLY_FRAME_ID

					payload[1] = dataId & 0xFF
					dataId /= 256
					payload[2] = dataId & 0xFF

					payload[3] = value & 0xFF
					value /= 256
					payload[4] = value & 0xFF
					value /= 256
					payload[5] = value & 0xFF
					value /= 256
					payload[6] = value & 0xFF
			
					gosub receive
rem The line above calls "receive", but it is not defined
rem "reply" is a subroutine, you should NOT goto anywhere outside it
rem				else
rem					goto run
				end
			end
	end

return


send:

    dataId = 0
    dataId = sportMspSeq
	dataId += 16
    dataId += 32

	sportMspSeq += 1
    sportMspSeq = sportMspSeq & 0x0F
   
    value = 0
    value = cmd & 0xFF
    value = value + 29952

    mspLastReq = cmd
    mspRequestsSent += 1
    
    sportTelemetrySend(LOCAL_SENSOR_ID, REQUEST_FRAME_ID, dataId, value)

return


run:

   now = gettime()

    if Event = EVT_MENU_LONG
      gosub reset
   end

   drawclear()
   drawtext(0, 0, "MSP/SPORT test script", INVERS)
   
    if getvalue("RSSI") > 0


        drawtext(1, 11, "Rqst:", 0)
        drawnumber(40, 11, mspRequestsSent, 0)
      
        drawtext(1, 21, "Rply:", 0)
        drawnumber(40, 21, mspRepliesReceived, 0)
       
        drawtext(1, 31, "PkRx:", 0)
        drawnumber(40, 31, mspPkRxed, 0)  
      
        drawtext(1, 41, "ErPk:", 0)
        drawnumber(40, 41, mspErrorPk, 0)
      
        drawtext(61, 11, "StPk:", 0)
        drawnumber(100, 11, mspStartPk, 0)
      
        drawtext(61, 21, "OuOr:", 0)
        drawnumber(100, 21, mspOutOfOrder, 0)
      
        drawtext(1, 51, "CRCE:", 0)
        drawnumber(40, 51, mspCRCErrors, 0)

		lastReqTSm = lastReqTS + 200
        if lastReqTSm <= now
			result = 1
            lastReqTS = now
			gosub send
        end
    else
        drawtext(50, 20, "NO", BLINK + DBLSIZE)
		drawtext(5, 40, "TELEMETRY!", BLINK + DBLSIZE)
    end
    gosub reply
    
	
	if Event = EVT_EXIT_BREAK then goto done
rem The "if" above includes a "then" so the "end" below is not required.
rem	end
stop
done:
finish
Try that and see if it is any better.
The raw telemetry data does not include a packet with a command of 0x32, so nothing was received.

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 » Sun Oct 01, 2017 2:03 pm

Still no response, i wish i had something to test my setup on, at the moment im only connected to a Frsky XSR hooked up on a flightcontroller running betaflight. Might borrow a taranis to test if i've set it up right. Thanks for your help!


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

Re: Script Language

Post by MikeB » Sun Oct 01, 2017 2:52 pm

I just had a look at your logged raw data. As well as the expected data from the XJT (RSSI, SWR, RxV), I can also see packets with a physical ID of 0x1A (the XJT uses 0x18).
There are two AppIDs, 0xF000 with data of 0 and 0xF103 (ADC2) with data of 0xCE (decimal 206).

I assume these are from your flight controller. I don't know what the F000 AppID represents, it isn't a standard FrSky ID.

I note you have:
sportTelemetrySend(LOCAL_SENSOR_ID, REQUEST_FRAME_ID, dataId, value)
but you don't define what LOCAL_SENSOR_ID or REQUEST_FRAME_ID are. The script will assume these are variables, and they will be set to 0 when the script first runs. The same applies to REMOTE_SENSOR_ID and REPLY_FRAME_ID.

You may need something like this at the start of your script:
if init then goto run
LOCAL_SENSOR_ID = ??
REQUEST_FRAME_ID = 0x31
REMOTE_SENSOR_ID = 0x1A
REPLY_FRAME_ID = ????
init = 1
goto run

Where you will need to fill in the ??? with the values you wish to use.

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 » Sun Oct 01, 2017 7:34 pm

I've attached the almost finished script, still gotta fix the receive: part. The defined values were not included in the code i posted here, sorry.
Attachments
msp_sp.rar
(1.32 KiB) Downloaded 77 times

User avatar
midelic
Posts: 126
Joined: Mon Dec 23, 2013 9:57 pm
Country: -

Re: Script Language

Post by midelic » Sun Oct 01, 2017 8:03 pm

I'm very interested in this .With this one you can change PID on betaflight?
I'm interested to test it with a modified version of multiprotocol.

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

Re: Script Language

Post by cutdact » Sun Oct 01, 2017 8:35 pm

midelic wrote:
Sun Oct 01, 2017 8:03 pm
I'm very interested in this .With this one you can change PID on betaflight?
I'm interested to test it with a modified version of multiprotocol.
Well that is my goal, right now i'm trying to get the basics working, sending and receiving data, i'm new to coding so it's a challange, the function will be exactly the same as the LUA scripts for Frsky Taranis.

User avatar
midelic
Posts: 126
Joined: Mon Dec 23, 2013 9:57 pm
Country: -

Re: Script Language

Post by midelic » Mon Oct 02, 2017 2:41 pm

Mike ,
I tested the script above with a modified version of multiprotocol with polling implemented.
I see something strange, when I poll Tx with 0x7E,0x0D I get a serial response bytes with framing error and parity error.
It looks like the serial back is not the same 100KE2 or is not framed correctly.
see below also in the attachment.

0.240747625000000,0x7E,,
0.240867625000000,0x0D,,
0.241584875000000,0xCF,Error,Error
0.241709500000000,0xE6,Error,
0.241909500000000,0x15,,Error
0.242039562500000,0x45,Error,
0.242239562500000,0xFF,Error,Error
0.242369562500000,0xA7,Error,
Attachments
untitled2.txt
(59.15 KiB) Downloaded 139 times
Last edited by midelic on Mon Oct 02, 2017 5:41 pm, edited 1 time in total.

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

Re: Script Language

Post by MikeB » Mon Oct 02, 2017 2:56 pm

My immediate thought is you are seeing the Tx data inverted.
What Tx are you using? Taranis and 9XR-PRO will send inverted serial.

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

User avatar
midelic
Posts: 126
Joined: Mon Dec 23, 2013 9:57 pm
Country: -

Re: Script Language

Post by midelic » Mon Oct 02, 2017 3:09 pm

I use 9xpro.
It looks like is inverted but also parity error it is something like 100K8E1inverted.
How can be my9Xpro works with normal telemetry from multi STM32 and return inverted telemetry signal ?

This is not normal.The telemetry is inverted and I set invert COM1=1 in telemetry screen to use it with multi so both ways should use normal signal.

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

Re: Script Language

Post by MikeB » Mon Oct 02, 2017 3:21 pm

Because the 9XR-PRO has a XOR gate in the receive signal path, controlled by the "Invert COM1" option. So it can handle SPort data (inverted both ways), or handle non-inverted receive data, but the Tx data will still be inverted.

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

User avatar
midelic
Posts: 126
Joined: Mon Dec 23, 2013 9:57 pm
Country: -

Re: Script Language

Post by midelic » Mon Oct 02, 2017 3:23 pm

So the only option is to invert the signal in multi and put invert COM1 back on 0.

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

Re: Script Language

Post by MikeB » Mon Oct 02, 2017 3:58 pm

Yes, unless you can control the signal inversion in the multi module individually.
However, the SPort signal effectively has a pull down resistor on it. For inverted data (both ways), this corresponds to line marking for when the signal is not being actively driven.

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

User avatar
midelic
Posts: 126
Joined: Mon Dec 23, 2013 9:57 pm
Country: -

Re: Script Language

Post by midelic » Tue Oct 03, 2017 9:23 pm

The script was wrong, I received packets now with my multi and script running on TX.Still need some debugging(there are some more wrong things) but is a start.
I connected an X4R to a FC betaflight board.
I receive packets from rx starting 7E,1B,32 with multi.
Last edited by midelic on Wed Oct 04, 2017 12:31 am, edited 1 time in total.

User avatar
midelic
Posts: 126
Joined: Mon Dec 23, 2013 9:57 pm
Country: -

Re: Script Language

Post by midelic » Tue Oct 03, 2017 11:47 pm

I see the script have XOR operation.
Is it implemented in script language ? or can we use some equivalence?I tried "^" and ^= but gives me error at line 130(where the XOR operation is).I have e7 version on 9Xpro

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

Re: Script Language

Post by cutdact » Wed Oct 04, 2017 7:04 am

So you successfully received data with the script using a X4R receiver? I'm suspecting my problem is my XSR... Next step would be to extract the PID values from the payload.

Martin

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

Re: Script Language

Post by MikeB » Wed Oct 04, 2017 8:16 am

I have got XOR in with "e7", '^' and '^=' are supposed to work.
I'll check them out a bit later today.

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

User avatar
midelic
Posts: 126
Joined: Mon Dec 23, 2013 9:57 pm
Country: -

Re: Script Language

Post by midelic » Wed Oct 04, 2017 11:59 am

@cutdact
Yes I received packets but I modified the script it was not working before.

Mike I flashed the TX with diag4 and still have script error at line....

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

Re: Script Language

Post by cutdact » Wed Oct 04, 2017 12:13 pm

Care to share what you've changed? I don't see any difference in the file you sent

User avatar
jhsa
Posts: 19305
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Script Language

Post by jhsa » Wed Oct 04, 2017 12:24 pm

midelic wrote:
Wed Oct 04, 2017 11:59 am

Mike I flashed the TX with diag4 and still have script error at line....
The Diag4 version is specific to test something else.. ;)

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: 16976
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: Script Language

Post by MikeB » Wed Oct 04, 2017 12:26 pm

I've found a couple of bugs that mean the addition of XOR isn't working. I have the fixes and I'll post an "e8" a bit later.

I agree I can't find any difference to midelic's file, and I used a specific file compare function that ignores "white space".

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

User avatar
midelic
Posts: 126
Joined: Mon Dec 23, 2013 9:57 pm
Country: -

Re: Script Language

Post by midelic » Wed Oct 04, 2017 12:45 pm

Ahh I sent you the old file back.
See now.
Attachments
msp_sp.bas.txt
new
(4 KiB) Downloaded 172 times

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

Re: Script Language

Post by MikeB » Wed Oct 04, 2017 3:48 pm

I've posted "e8", which should fix the XOR problems, both '^' and '^=' should now work, and I think I had to fix '|=' as well.
Scripts should also accept != instead of # for a not equals comparison.

I've also added, but not fully tested and new option "const".
With this you may define constant numeric values by name, e.g.:
const LOCAL_SENSOR_ID 0x0D
then use LOCAL_SENSOR elsewhere and the constant numeric should be used, rather than needing to define a constant set to the required value.

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

User avatar
midelic
Posts: 126
Joined: Mon Dec 23, 2013 9:57 pm
Country: -

Re: Script Language

Post by midelic » Wed Oct 04, 2017 9:46 pm

I noticed that when I reached mspPkRxed =16 the script takes no more commands except exit.I added also the PID screen on the same script that can be accessed by pressing "menu" short,..... and takes no more menu command only exit.
Also I cannot restart the script again.What is interesting is the if I stop the script at let say 12 and restart the script mspPkRxed counts more until 4 (16)and stop,Like this values 16 cannot be reset regardless of stopping/restarting the script or not.
The sportTelemetryReceive()can be called only 16 times?
Attachments
msp_sp.bas.txt
(6.17 KiB) Downloaded 156 times

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

Re: Script Language

Post by MikeB » Wed Oct 04, 2017 10:45 pm

I'm sure I have my S6R/S8R script calling sportTelemetryReceive() many more than 16 times.
A note regarding use of arrays when translating from LUA. I believe LUA uses arrays that index from 1, while this script uses arrays that index from 0.
So, on LUA, an array of size 20 does have an element at position 20, while with this script language element 19 is the last one.

I'm not sure you are using sportTelemetryReceive() correctly. It returns a success/failure value, 1 for success and 0 for failure. Failure simply indicates that there was no data available, and the values of the parameters are UNCHANGED.
I think you should be using something like:
result = sportTelemetryReceive( physicalId, primId, dataId, value )
then checking that result is not 0 before processing the data.

When you say it only responds to EXIT, is this a short EXIT (handled by the script), or a LONG EXIT (handled outside the script)?

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

User avatar
midelic
Posts: 126
Joined: Mon Dec 23, 2013 9:57 pm
Country: -

Re: Script Language

Post by midelic » Thu Oct 05, 2017 1:13 am

it was long exit

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

Re: Script Language

Post by MikeB » Thu Oct 05, 2017 11:07 am

Not having Betaflight, nor anything that runs it (unless it runs on a mini APM with a Mega2560 on it), I can't test the script myself. What might be the lowest cost board that would run Betaflight and connect to SPort?
I ran the S6R/S8R script on a 'PRO using an external XJT, and this sends and receives many more than 16 SPort packets without any problems.
Could the hangup problem be that requests for data are stop being sent?
If the script is not responding to button presses (EXIT LONG is actioned outside any script), then it seems the script is in an infinite loop somewhere. The script execution method limits the number of lines of the script that are executed at any one time so it cannot "take over" the processor, and prevent normal operation. The display is only refreshed when the script execution reaches the "stop" instruction (to make sure everything does get displayed).

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

User avatar
midelic
Posts: 126
Joined: Mon Dec 23, 2013 9:57 pm
Country: -

Re: Script Language

Post by midelic » Thu Oct 05, 2017 2:19 pm

I changed the script the lock in no more .It is working now( somehow). I put on display the primID and physicalId.Some times it is working receiving packets sometimes not I have to dig more,see why.Also receiving many error packets.

About the FC board there are many cheap ones on BG that can be used.I used this one below for test.It is cheap.
https://www.banggood.com/Eachine-Tiny-3 ... mds=search

There are cheaper that can be used.Like 10-11 USD.
https://www.banggood.com/Eachine-32bits ... otproducts
Attachments
msp_sp.bas.txt
(6.09 KiB) Downloaded 110 times


Post Reply

Return to “erskyTx (was ersky9x)”