bluesky icon indicating copy to clipboard operation
bluesky copied to clipboard

Console Application

Open tommynanny opened this issue 2 years ago • 8 comments

hi, I am new to python and was trying to use BlueSky as an external backend service for my application which is not written in python. Is there an easy way I could set up a "bridge" to let my program talk to a running BlueSky? Instead of writing some RESTful API that could send a command request to BlueSky and get a response, is there a way I could make BlueSky run as a console application that uses the console standard input and output for TrafScript (correct me if I am wrong, but currently, it seems to me that I could only use the GUI console to use TrafScript for input and output) (The output is to call the POS function to get the telemetry of a flight from time to time)

I might miss something important, and would be appreciated if someone could point me in a direction to do this efficiently.

tommynanny avatar Apr 13 '22 23:04 tommynanny

Hi @tommynanny,

Yes, that's certainly possible. Unfortunately the wiki still needs some work, a.o. on the different operating modes of bluesky.

When running bluesky in headless mode, only the bluesky server and a single simulation process are started. By itself this process doesn't allow interaction through the command line. You can, however, connect clients to it, such as the QtGL-based ui client: python3 BlueSky.py --client And more recently also a console text-based client: python3 BlueSky.py --console

If you want to connect your own program to bluesky you can use bluesky's client class (assuming your program is written in Python). Have a look at an example in the wiki: https://github.com/TUDelft-CNS-ATM/bluesky/wiki/Connecting-external-applications-to-BlueSky

We are currently in the process of setting up pypi package distribution of bluesky, so that you can more easily import bluesky modules into your own code. This is not ready yet, however.

jooste avatar Apr 14 '22 08:04 jooste

Thanks, @jooste for the informative response. I manage to run BlueSky.py with GUI after pulling the latest commits and installing PyQt6, and everything works just as it was with PyQt5. Following the instruction you've provided, I run a headless instance of BlueSky.py with the --headless flag; and then try to run a console instance with the --console flag, but got the error shown below. (python3 -V is Python 3.9.12)

image image

tommynanny avatar Apr 14 '22 13:04 tommynanny

Hi, I think this is because an annotation syntax was used that was only introduced in Python 3.10 (the union notation |). Since these annotations are optional anyway I removed a couple of them. I think this should also fix your error. See commit 951d906.

jooste avatar Apr 14 '22 18:04 jooste

Ah, I just noticed that you wrote 'not written in Python'. What language is your application developed in? BlueSky's networking is implemented with ZMQ and msgpack, which were both selected because they are available in multiple programming languages. It would be nice to have the bluesky client also in different languages!

jooste avatar Apr 14 '22 18:04 jooste

Ah, I just noticed that you wrote 'not written in Python'. What language is your application developed in? BlueSky's networking is implemented with ZMQ and msgpack, which were both selected because they are available in multiple programming languages. It would be nice to have the bluesky client also in different languages!

@jooste I am currently working with a golang application. I would be surprised if BlueSky could work with golang in a more convinient way that you've mentioned.

tommynanny avatar Apr 14 '22 21:04 tommynanny

Hi, I think this is because an annotation syntax was used that was only introduced in Python 3.10 (the union notation |). Since these annotations are optional anyway I removed a couple of them. I think this should also fix your error. See commit 951d906.

Thanks for the update. Despite the spam of "Client: Skipping stream data from unknown node", the --console flag works awesome on my side.

https://user-images.githubusercontent.com/22390882/163482723-e49aa102-f1cd-408c-a144-4265fd7ad1fb.mov

well on my side as a console application.

tommynanny avatar Apr 14 '22 21:04 tommynanny

the 'skipping' message is due to an orphan bluesky simulation process still running in the background. If you kill it these messages should stop too.

jooste avatar Apr 15 '22 11:04 jooste

ZMQ in Go: https://zeromq.org/languages/go/ msgPack: https://github.com/vmihailenco/msgpack

Should be possible!

jooste avatar Apr 15 '22 11:04 jooste

Hi, I think this is because an annotation syntax was used that was only introduced in Python 3.10 (the union notation |). Since these annotations are optional anyway I removed a couple of them. I think this should also fix your error. See commit 951d906.

Unfortunately the latest release still has compatibility issues with python versions prior to 3.10. Specifically if you're not using 3.10 Bluesky won't start and an exception will be thrown pointing to line 11 in cmdparser.py

obbe79 avatar Feb 29 '24 14:02 obbe79

Hi, I think this is because an annotation syntax was used that was only introduced in Python 3.10 (the union notation |). Since these annotations are optional anyway I removed a couple of them. I think this should also fix your error. See commit 951d906.

console mode no longer starts as some of the widget imports fail:

  File "C:\Users\user\envs\bluesky\lib\site-packages\textual\widgets\__init__.py", line 101, in __getattr__
    raise ImportError(f"Package 'textual.widgets' has no class '{widget_class}'")
ImportError: Package 'textual.widgets' has no class 'ScrollView'

ScrollView is no longer part of textual.widgets and TreeControl and TreeClick are no longer there.

Maybe an older version of textual should be considered

obbe79 avatar Feb 29 '24 15:02 obbe79

Hi, I think this is because an annotation syntax was used that was only introduced in Python 3.10 (the union notation |). Since these annotations are optional anyway I removed a couple of them. I think this should also fix your error. See commit 951d906.

Unfortunately the latest release still has compatibility issues with python versions prior to 3.10. Specifically if you're not using 3.10 Bluesky won't start and an exception will be thrown pointing to line 11 in cmdparser.py

This was fixed in 210c7e5, but hasn't made its way into a release yet.

jooste avatar Feb 29 '24 21:02 jooste