BallAerospace / python-ballcosmos

Python Support for Ball Aerospace COSMOS v4
Other
18 stars 4 forks source link

cmd binary as parameter value #30

Closed omermesser closed 9 months ago

omermesser commented 9 months ago

I'm trying to upload a file using a command that sends chunks of binary file.

One of the parameters of the cmd is the binary data itself. Another parameter is the data length (in bytes). I'm reading the file and sending the cmd with chunks of bytes multiple times (the chunk is is 1754 bytes).

the data of a chunk for example is: b '\xdd\x00\x00\x00D3"\x11\x88wfU\xcc\xbb\xaa\x99fU\x99\xaaXNLX\x00\x00\x00\x00\x80\x0f...'

(the 3 dots in the example above and below are my change so that the issue will not be long)

now I'm getting this error saying the data sent is longer than specified:

Exception has occurred: CosmosResponseError       (note: full exception trace is shown but execution is paused at: _run_module_as_main)
({'jsonrpc': '2.0', 'method': 'cmd', 'params': ['MyTarget', 'MIC_LSL-MIC_FILE_UPLOAD', {'MY_ID': 39, 'DATA_FILE_ID': 25, 'DATA_ENTRY_ID': 1, 'DATA_OFFSET': 0, 'DATA_LEN': 1754, 'DATA_BLOCK': 'Ý\x00\x00\x00D3"\x11\x88wfUÌ»ª\x99fU\x99ªXNLX\x00\x00\x00\x00\x80\x0f\x00\x00\x00\x00\x00ò\x00y\x00\x00\x00y\x00\x00Pj\x04\x00Pj\x04\x00....'}], 'id': 349}, {'jsonrpc': '2.0', 'id': 349, 'error': {'code': -32602, 'message': 'Invalid params', 'data': {'class': 'ArgumentError', 'message': 'value of 2496 bytes does not fit into 1754 bytes for data_type BLOCK', 'backtrace': ["C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/cosmos-4.5.0/lib/cosmos/packets/structure.rb:336:in `write'", "C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/cosmos-4.5.0/lib/cosmos/packets/structure.rb:336:in `write_item'", "C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/cosmos-4.5.0/lib/cosmos/packets/packet.rb:629:in `write_item'", "C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/cosmos-4.5.0/lib/cosmos/packets/structure.rb:364:in `write'", "C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/cosmos-4.5.0/lib/cosmos/packets/packet.rb:666:in `write'", "C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/cosmos-4.5.0/lib/cosmos/packets/commands.rb:340:in `block in set_parameters'", "C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/cosmos-4.5.0/lib/cosmos/packets/commands.rb:315:in `each'", "C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/cosmos-4.5.0/lib/cosmos/packets/commands.rb:315:in `set_parameters'", "C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/cosmos-4.5.0/lib/cosmos/packets/commands.rb:169:in `build_cmd'", "C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/cosmos-4.5.0/lib/cosmos/tools/cmd_tlm_server/api.rb:1618:in `cmd_implementation'", "C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/cosmos-4.5.0/lib/cosmos/tools/cmd_tlm_server/api.rb:161:in `cmd'", "C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/cosmos-4.5.0/lib/cosmos/io/json_drb.rb:265:in `process_request'", "C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/cosmos-4.5.0/lib/cosmos/io/json_drb_rack.rb:79:in `handle_post'", "C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/cosmos-4.5.0/lib/cosmos/io/json_drb_rack.rb:61:in `call'", "C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/puma-3.12.6/lib/puma/configuration.rb:227:in `call'", "C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/puma-3.12.6/lib/puma/server.rb:706:in `handle_request'", "C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/puma-3.12.6/lib/puma/server.rb:476:in `process_client'", "C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/puma-3.12.6/lib/puma/server.rb:334:in `block in run'", "C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/puma-3.12.6/lib/puma/thread_pool.rb:135:in `block in spawn_thread'"], 'instance_variables': {}}}})

How should I handle the bytes? it seems ballcosmos stringifys them.

this is the file handling:

with open(upload_filename, 'rb') as f:
    while True:
        data_block = f.read(entry_size)
        if not data_block:
            break
        cmdSend(my_id, file_id, entry_id, len(data_block) , data_block)
        time.sleep(0.05)

cmdSend is a wrapper function of cmd function:

def cmdSend(self, micron_id: int, data_file_id: int, data_entry_id: int, data_len: int, data_block):
    cmd_name = "MIC_FILE_UPLOAD"
    cmd_params = {
        "MY_ID": my_id,
        "DATA_FILE_ID": data_file_id,
        "DATA_ENTRY_ID": data_entry_id,
        "DATA_OFFSET": 0, # fixed
        "DATA_LEN": data_len,
        "DATA_BLOCK": data_block
    }
    cmd('MyTarget', cmd_name, cmd_params)

How should I handle the bytes? it seems ballcosmos stringifys them.

ryanmelt commented 9 months ago

Hello - This project is no longer supported. Please checkout openc3 cosmos, which is now has full built-in python support. https://github.com/openc3/cosmos

omermesser commented 9 months ago

Hello - This project is no longer supported. Please checkout openc3 cosmos, which is now has full built-in python support. https://github.com/openc3/cosmos

Hi, I understand it is not supported, but my teams already has a large project using COSMOS 4 and I'm struggling with this specific problem. Perhaps I could get assistance?

ryanmelt commented 9 months ago

If you are interested in a support contract reach out to support@openc3.com. Note that we are not making any updates to the COSMOS 4 code, so it would just be help seeing if we can make it work, or maybe a patch file.