Skip to content

CmdTlmServer clear counters #1089

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 9, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# GNU Affero General Public License for more details.

# Modified by OpenC3, Inc.
# All changes Copyright 2023, OpenC3, Inc.
# All changes Copyright 2024, OpenC3, Inc.
# All Rights Reserved
#
# This file may also be used under the terms of a commercial license
Expand Down Expand Up @@ -70,6 +70,7 @@
</template>

<script>
import { OpenC3Api } from '@openc3/tool-common/src/services/openc3-api'
import LogMessages from '@openc3/tool-common/src/components/LogMessages'
import TopBar from '@openc3/tool-common/src/components/TopBar'
export default {
Expand All @@ -79,6 +80,7 @@ export default {
},
data() {
return {
api: null,
title: 'CmdTlmServer',
panel: 0,
curTab: null,
Expand Down Expand Up @@ -117,15 +119,35 @@ export default {
items: [
{
label: 'Options',
icon: 'mdi-cog',
command: () => {
this.optionsDialog = true
},
},
{
label: 'Clear Counters',
icon: 'mdi-eraser',
command: () => {
this.clearCounters()
},
},
],
},
],
}
},
created() {
this.api = new OpenC3Api()
},
methods: {
clearCounters() {
this.api.get_interface_names().then((response) => {
for (var i = 0; i < response.length; i++) {
this.api.interface_cmd(response[i], 'clear_counters')
}
})
},
},
}
</script>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# GNU Affero General Public License for more details.

# Modified by OpenC3, Inc.
# All changes Copyright 2022, OpenC3, Inc.
# All changes Copyright 2024, OpenC3, Inc.
# All Rights Reserved
#
# This file may also be used under the terms of a commercial license
Expand All @@ -32,11 +32,11 @@ export class OpenC3Api {
params,
kwparams = {},
headerOptions = {},
timeout = 60000,
timeout = 60000
) {
try {
let refreshed = await OpenC3Auth.updateToken(
OpenC3Auth.defaultMinValidity,
OpenC3Auth.defaultMinValidity
)
if (refreshed) {
OpenC3Auth.setTokens()
Expand All @@ -63,7 +63,7 @@ export class OpenC3Api {
...headerOptions,
},
timeout: timeout,
},
}
)
// var data = response.data
// if (data.error) {
Expand Down Expand Up @@ -172,6 +172,14 @@ export class OpenC3Api {
return this.exec('disconnect_interface', [interface_name])
}

interface_cmd(interface_name, command_name, ...command_params) {
return this.exec('interface_cmd', [
interface_name,
command_name,
...command_params,
])
}

get_all_router_info() {
return this.exec('get_all_router_info', [])
}
Expand Down Expand Up @@ -300,7 +308,7 @@ export class OpenC3Api {
[items],
kw_args,
{},
10000, // 10s timeout ... should never be this long
10000 // 10s timeout ... should never be this long
)
var len = data[0].length
var converted = null
Expand Down Expand Up @@ -350,14 +358,14 @@ export class OpenC3Api {
target_name,
packet_name,
item_hash = null,
value_type = 'CONVERTED',
value_type = 'CONVERTED'
) {
data = await this.exec(
'inject_tlm',
[target_name, packet_name, item_hash],
{
type: value_type,
},
}
)
}

Expand Down Expand Up @@ -415,7 +423,7 @@ export class OpenC3Api {
target_name,
packet_name,
parameter_name,
value_type = 'CONVERTED',
value_type = 'CONVERTED'
) {
return this.exec('get_cmd_value', [
target_name,
Expand Down Expand Up @@ -444,7 +452,7 @@ export class OpenC3Api {
method,
[target_name, command_name, param_list],
{},
headerOptions,
headerOptions
)
}

Expand All @@ -456,7 +464,7 @@ export class OpenC3Api {
'get_cmd_hazardous',
target_name,
command_name,
param_list,
param_list
)
}
}
Expand All @@ -470,7 +478,7 @@ export class OpenC3Api {
target_name,
command_name,
param_list,
headerOptions,
headerOptions
)
}
}
Expand All @@ -483,7 +491,7 @@ export class OpenC3Api {
'cmd_no_range_check',
target_name,
command_name,
param_list,
param_list
)
}
}
Expand All @@ -504,7 +512,7 @@ export class OpenC3Api {
'cmd_raw_no_range_check',
target_name,
command_name,
param_list,
param_list
)
}
}
Expand All @@ -517,7 +525,7 @@ export class OpenC3Api {
'cmd_no_hazardous_check',
target_name,
command_name,
param_list,
param_list
)
}
}
Expand All @@ -538,7 +546,7 @@ export class OpenC3Api {
'cmd_raw_no_hazardous_check',
target_name,
command_name,
param_list,
param_list
)
}
}
Expand All @@ -551,7 +559,7 @@ export class OpenC3Api {
'cmd_raw_no_checks',
target_name,
command_name,
param_list,
param_list
)
}
}
Expand Down Expand Up @@ -650,7 +658,7 @@ export class OpenC3Api {
// The resulting hash is stored in an array buffer
const hashAsArrayBuffer = await crypto.subtle.digest(
'SHA-256',
arrayBuffer,
arrayBuffer
)
// To create a string we will get the hexadecimal value of each byte of the array buffer
// This gets us an array where each byte of the array buffer becomes one item in the array
Expand Down
43 changes: 25 additions & 18 deletions openc3/lib/openc3/interfaces/interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# GNU Affero General Public License for more details.

# Modified by OpenC3, Inc.
# All changes Copyright 2023, OpenC3, Inc.
# All changes Copyright 2024, OpenC3, Inc.
# All Rights Reserved
#
# This file may also be used under the terms of a commercial license
Expand Down Expand Up @@ -205,8 +205,8 @@ def connect
else
cmd(cmd_string)
end
rescue Exception => err
Logger.error("Error sending periodic cmd(#{cmd_string}):\n#{err.formatted}")
rescue Exception => e
Logger.error("Error sending periodic cmd(#{cmd_string}):\n#{e.formatted}")
end
end
end
Expand Down Expand Up @@ -238,7 +238,7 @@ def read_interface
raise "read_interface not defined by Interface"
end

def write_interface(data, extra = nil)
def write_interface(_data, _extra = nil)
raise "write_interface not defined by Interface"
end

Expand Down Expand Up @@ -305,10 +305,10 @@ def read
Logger.warn("#{@name}: Interface unexpectedly requested disconnect") unless packet
return packet
end
rescue Exception => err
rescue Exception => e
Logger.error("#{@name}: Error reading from interface")
disconnect()
raise err
raise e
end

# Method to send a packet on the interface.
Expand Down Expand Up @@ -395,16 +395,16 @@ def _write
else
@write_mutex.synchronize { yield }
end
rescue WriteRejectError => err
Logger.error("#{@name}: Write rejected by interface: #{err.message}")
raise err
rescue Exception => err
rescue WriteRejectError => e
Logger.error("#{@name}: Write rejected by interface: #{e.message}")
raise e
rescue Exception => e
Logger.error("#{@name}: Error writing to interface")
disconnect()
raise err
raise e
end

def as_json(*a)
def as_json(*_a)
config = {}
config['name'] = @name
config['state'] = @state
Expand Down Expand Up @@ -528,7 +528,7 @@ def convert_packet_to_data(packet)
# method is called. Subclasses must implement this method.
#
# @return [String] Raw packet data
def read_interface_base(data, extra = nil)
def read_interface_base(data, _extra = nil)
@read_raw_data_time = Time.now
@read_raw_data = data.clone
@bytes_read += data.length
Expand All @@ -541,7 +541,7 @@ def read_interface_base(data, extra = nil)
#
# @param data [String] Raw packet data
# @return [String] The exact data written
def write_interface_base(data, extra = nil)
def write_interface_base(data, _extra = nil)
@written_raw_data_time = Time.now
@written_raw_data = data.clone
@bytes_written += data.length
Expand All @@ -567,9 +567,16 @@ def add_protocol(protocol_class, protocol_args, read_write)
return protocol
end

def interface_cmd(cmd_name, *cmd_args)
# Default do nothing - Implemented by subclasses
return false
def interface_cmd(cmd_name, *_cmd_args)
case cmd_name
when 'clear_counters'
@write_queue_size = 0
@read_queue_size = 0
@bytes_written = 0
@bytes_read = 0
@write_count = 0
@read_count = 0
end
end

def protocol_cmd(cmd_name, *cmd_args, read_write: :READ_WRITE, index: -1)
Expand All @@ -584,7 +591,7 @@ def protocol_cmd(cmd_name, *cmd_args, read_write: :READ_WRITE, index: -1)
write_protocols = @write_protocols.reverse
read_index = 0
write_index = 0
@protocol_info.each do |protocol_class, protocol_args, protocol_read_write|
@protocol_info.each do |_protocol_class, _protocol_args, protocol_read_write|
case protocol_read_write
when :READ
protocols << read_protocols[read_index]
Expand Down
Loading