Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions openc3/lib/openc3/packets/packet_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@
require 'openc3/utilities/python_proxy'
require 'openc3/conversions'
require 'openc3/processors'
require 'openc3/accessors'
require 'nokogiri'
require 'ostruct'
require 'fileutils'
require 'tempfile'

module OpenC3
# Reads a command or telemetry configuration file and builds a hash of packets.
Expand Down Expand Up @@ -367,6 +369,32 @@ def dynamic_add_packet(packet, cmd_or_tlm = :TELEMETRY, affect_ids: false)
end
end

# This method provides way to quickly test packet configs
#
# require 'openc3/packets/packet_config'
#
# config = <<END
# ...
# END
#
# pc = PacketConfig.from_config(config, "MYTARGET")
# c = pc.commands['CMDADCS']['SET_POINTING_CMD']
# c.restore_defaults()
# c.write("MYITEM", 5)
# puts c.buffer.formatted
def self.from_config(config, process_target_name, language = 'ruby')
pc = self.new
tf = Tempfile.new("pc.txt")
tf.write(config)
tf.close
begin
pc.process_file(tf.path, process_target_name, language)
ensure
tf.unlink
end
return pc
end

protected

def update_id_value_hash(packet, hash)
Expand Down
1 change: 1 addition & 0 deletions openc3/lib/openc3/utilities/store_queued.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# if purchased from OpenC3, Inc.

require 'openc3/utilities/store'
require 'openc3/utilities/sleeper'

module OpenC3
class StoreQueued
Expand Down
5 changes: 5 additions & 0 deletions openc3/python/openc3/config/config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ def __init__(self, config_parser, message="Configuration Error", usage="", url="
# self.param url [String] The url to link to in error messages
def __init__(self, url="https://docs.openc3.com/docs"):
self.url = url
self.keyword = None
self.parameters = None
self.filename = None
self.line = None
self.line_number = None

# self.param message [String] The string to set the Exception message to
# self.param usage [String] The usage message
Expand Down
23 changes: 23 additions & 0 deletions openc3/python/openc3/packets/packet_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# if purchased from OpenC3, Inc.

import os
import tempfile
from openc3.config.config_parser import ConfigParser
from openc3.packets.packet import Packet
from openc3.packets.parsers.packet_parser import PacketParser
Expand Down Expand Up @@ -341,6 +342,28 @@ def finish_packet(self):
self.current_packet = None
self.current_item = None

# This method provides way to quickly test packet configs
#
# from openc3.packets.packet_config import PacketConfig
#
# config = """
# ...
# """
#
# pc = PacketConfig.from_config(config, "MYTARGET")
# c = pc.commands['CMDADCS']['SET_POINTING_CMD']
# c.restore_defaults()
# c.write("MYITEM", 5)
# print(c.buffer)
@classmethod
def from_config(cls, config, process_target_name):
pc = cls()
with tempfile.NamedTemporaryFile(mode="w+t", suffix=".txt") as tf:
tf.write(config)
tf.seek(0)
pc.process_file(tf.name, process_target_name)
return pc

def update_id_value_hash(self, hash):
if self.current_packet.id_items and len(self.current_packet.id_items) > 0:
key = []
Expand Down