Skip to content

Commit 802ea9b

Browse files
authored
Merge pull request #1930 from OpenC3/bigint
Support 64 bit ints in CommandSender
2 parents c0823f8 + bbe5893 commit 802ea9b

File tree

11 files changed

+141
-43
lines changed

11 files changed

+141
-43
lines changed

openc3-cosmos-init/plugins/packages/openc3-cosmos-demo/targets/INST/cmd_tlm/inst_cmds.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ COMMAND <%= target_name %> SETPARAMS BIG_ENDIAN "Sets numbered parameters"
3333
APPEND_PARAMETER VALUE<%= i %> 16 UINT 0 5 1 "Value <%= i %> setting" LITTLE_ENDIAN
3434
RELATED_ITEM <%= target_name %> PARAMS VALUE<%= i %>
3535
<% end %>
36+
APPEND_PARAMETER BIGINT 64 UINT MIN MAX 0 "UINT 64 parameter"
3637
SCREEN <%= target_name %> PARAMS
3738

3839
SELECT_PARAMETER VALUE5

openc3-cosmos-init/plugins/packages/openc3-cosmos-demo/targets/INST/cmd_tlm/inst_tlm.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,11 @@ TELEMETRY <%= target_name %> PARAMS BIG_ENDIAN "Params set by SETPARAMS command"
136136
STATE BAD 1 RED
137137
<% end %>
138138
APPEND_ITEM IP_ADDRESS 32 UINT "Encoded IP Address"
139-
APPEND_ITEM P_2.2,2 32 UINT "Test weird characters"
140-
APPEND_ITEM P-3+3=3 32 UINT "Test weird characters"
141-
APPEND_ITEM P4!@#$%^&*? 32 UINT "Test weird characters"
142-
APPEND_ITEM P</5|\> 32 UINT "Test weird characters"
143-
APPEND_ITEM P(:6;) 32 UINT "Test weird characters"
139+
APPEND_ITEM P_2.2,2 64 INT "Test weird characters"
140+
APPEND_ITEM P-3+3=3 64 INT "Test weird characters"
141+
APPEND_ITEM P4!@#$%^&*? 64 UINT "Test weird characters"
142+
APPEND_ITEM P</5|\> 64 UINT "Test weird characters"
143+
APPEND_ITEM P(:6;) 64 UINT "Test weird characters"
144144
ITEM PACKET_TIME 0 0 DERIVED "Ruby time based on TIMESEC and TIMEUS"
145145
READ_CONVERSION unix_time_conversion.rb TIMESEC TIMEUS
146146

openc3-cosmos-init/plugins/packages/openc3-cosmos-demo/targets/INST/lib/sim_inst.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# GNU Affero General Public License for more details.
1515

1616
# Modified by OpenC3, Inc.
17-
# All changes Copyright 2024, OpenC3, Inc.
17+
# All changes Copyright 2025, OpenC3, Inc.
1818
# All Rights Reserved
1919
#
2020
# This file may also be used under the terms of a commercial license
@@ -25,6 +25,7 @@
2525
require 'openc3'
2626
require 'stringio'
2727
require 'base64'
28+
require 'openc3/accessors/binary_accessor'
2829

2930
module OpenC3
3031
# Simulated instrument for the demo. Populates several packets and cycles
@@ -111,11 +112,11 @@ def initialize(target_name)
111112
packet.value3 = 2
112113
packet.value4 = 1
113114
packet.value5 = 0
114-
packet.write('P_2.2,2', 2)
115-
packet.write('P-3+3=3', 3)
116-
packet.write('P4!@#$%^&*?', 4)
117-
packet.write('P</5|\>', 5)
118-
packet.write('P(:6;)', 6)
115+
packet.write('P_2.2,2', BinaryAccessor::MIN_INT64)
116+
packet.write('P-3+3=3', BinaryAccessor::MAX_INT64)
117+
packet.write('P4!@#$%^&*?', 0)
118+
packet.write('P</5|\>', 1740684371613049856)
119+
packet.write('P(:6;)', BinaryAccessor::MAX_UINT64)
119120

120121
packet = @tlm_packets['IMAGE']
121122
packet.enable_method_missing
@@ -196,6 +197,7 @@ def write(packet)
196197
params_packet.value3 = packet.read('value3')
197198
params_packet.value4 = packet.read('value4')
198199
params_packet.value5 = packet.read('value5')
200+
params_packet.write('P4!@#$%^&*?', packet.read('bigint'))
199201
when 'ASCIICMD'
200202
hs_packet.cmd_acpt_cnt += 1
201203
hs_packet.asciicmd = packet.read('string')

openc3-cosmos-init/plugins/packages/openc3-cosmos-demo/targets/INST2/cmd_tlm/inst_cmds.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ COMMAND <%= target_name %> SETPARAMS BIG_ENDIAN "Sets numbered parameters"
3333
APPEND_PARAMETER VALUE<%= i %> 16 UINT 0 5 1 "Value <%= i %> setting" LITTLE_ENDIAN
3434
RELATED_ITEM <%= target_name %> PARAMS VALUE<%= i %>
3535
<% end %>
36+
APPEND_PARAMETER BIGINT 64 UINT MIN MAX 0 "UINT 64 parameter"
3637
SCREEN <%= target_name %> PARAMS
3738

3839
SELECT_PARAMETER VALUE5

openc3-cosmos-init/plugins/packages/openc3-cosmos-demo/targets/INST2/cmd_tlm/inst_tlm.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,11 @@ TELEMETRY <%= target_name %> PARAMS BIG_ENDIAN "Params set by SETPARAMS command"
128128
STATE BAD 1 RED
129129
<% end %>
130130
APPEND_ITEM IP_ADDRESS 32 UINT "Encoded IP Address"
131-
APPEND_ITEM P_2.2,2 32 UINT "Test weird characters"
132-
APPEND_ITEM P-3+3=3 32 UINT "Test weird characters"
133-
APPEND_ITEM P4!@#$%^&*? 32 UINT "Test weird characters"
134-
APPEND_ITEM P</5|\> 32 UINT "Test weird characters"
135-
APPEND_ITEM P(:6;) 32 UINT "Test weird characters"
131+
APPEND_ITEM P_2.2,2 64 INT "Test weird characters"
132+
APPEND_ITEM P-3+3=3 64 INT "Test weird characters"
133+
APPEND_ITEM P4!@#$%^&*? 64 UINT "Test weird characters"
134+
APPEND_ITEM P</5|\> 64 UINT "Test weird characters"
135+
APPEND_ITEM P(:6;) 64 UINT "Test weird characters"
136136
ITEM PACKET_TIME 0 0 DERIVED "Python time based on TIMESEC and TIMEUS"
137137
READ_CONVERSION openc3/conversions/unix_time_conversion.py TIMESEC TIMEUS
138138

openc3-cosmos-init/plugins/packages/openc3-cosmos-demo/targets/INST2/lib/sim_inst.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 OpenC3, Inc.
1+
# Copyright 2025 OpenC3, Inc.
22
# All Rights Reserved.
33
#
44
# This program is free software; you can modify and/or redistribute it
@@ -25,6 +25,7 @@
2525
from openc3.packets.packet import Packet
2626
from openc3.system.system import System
2727
from openc3.top_level import kill_thread
28+
from openc3.accessors.binary_accessor import BinaryAccessor
2829

2930

3031
# Simulated instrument for the demo. Populates several packets and cycles
@@ -114,11 +115,11 @@ def __init__(self, target_name):
114115
packet.write("value3", 2)
115116
packet.write("value4", 1)
116117
packet.write("value5", 0)
117-
packet.write('P_2.2,2', 2)
118-
packet.write('P-3+3=3', 3)
119-
packet.write('P4!@#$%^&*?', 4)
120-
packet.write('P</5|\>', 5)
121-
packet.write('P(:6;)', 6)
118+
packet.write('P_2.2,2', BinaryAccessor.MIN_INT64)
119+
packet.write('P-3+3=3', BinaryAccessor.MAX_INT64)
120+
packet.write('P4!@#$%^&*?', 0)
121+
packet.write('P</5|\>', 1740684371613049856)
122+
packet.write('P(:6;)', BinaryAccessor.MAX_UINT64)
122123

123124
packet = self.tlm_packets["IMAGE"]
124125
packet.write("CcsdsSeqFlags", "NOGROUP")
@@ -187,6 +188,7 @@ def write(self, packet):
187188
params_packet.write("value3", packet.read("value3"))
188189
params_packet.write("value4", packet.read("value4"))
189190
params_packet.write("value5", packet.read("value5"))
191+
params_packet.write('P4!@#$%^&*?', packet.read('bigint'))
190192
case "ASCIICMD":
191193
hs_packet.write("cmd_acpt_cnt", hs_packet.read("cmd_acpt_cnt") + 1)
192194
hs_packet.write("asciicmd", packet.read("string"))

openc3-cosmos-init/plugins/packages/openc3-cosmos-tool-cmdsender/src/tools/CommandSender/CommandSender.vue

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# GNU Affero General Public License for more details.
1414
1515
# Modified by OpenC3, Inc.
16-
# All changes Copyright 2024, OpenC3, Inc.
16+
# All changes Copyright 2025, OpenC3, Inc.
1717
# All Rights Reserved
1818
#
1919
# This file may also be used under the terms of a commercial license
@@ -184,7 +184,9 @@
184184
<v-card-text class="mt-6">
185185
Warning: Command {{ hazardousCommand }} is Hazardous. Send?
186186
<br />
187-
<span class="openc3-yellow"> Description: {{ commandDescription }} </span>
187+
<span class="openc3-yellow">
188+
Description: {{ commandDescription }}
189+
</span>
188190
</v-card-text>
189191
<v-card-actions class="px-2">
190192
<v-spacer />
@@ -491,7 +493,13 @@ export default {
491493
} else if (this.isFloat(str)) {
492494
return parseFloat(str)
493495
} else if (this.isInt(str)) {
494-
return parseInt(str)
496+
// If this is a number that is too large for a JS number
497+
// then we convert it to a BigInt which gets serialized in openc3Api.js
498+
if (!Number.isSafeInteger(Number(str))) {
499+
return BigInt(str)
500+
} else {
501+
return parseInt(str)
502+
}
495503
} else if (this.isArray(str)) {
496504
return eval(str)
497505
} else {
@@ -576,10 +584,14 @@ export default {
576584
// This is basically to handle the FLOAT MIN and MAX so they
577585
// don't print out the huge exponential
578586
if (parameter.minimum < -1e6) {
579-
parameter.minimum = parameter.minimum.toExponential(3)
587+
if (Number.isSafeInteger(parameter.minimum)) {
588+
parameter.minimum = parameter.minimum.toExponential(3)
589+
}
580590
}
581591
if (parameter.maximum > 1e6) {
582-
parameter.maximum = parameter.maximum.toExponential(3)
592+
if (Number.isSafeInteger(parameter.maximum)) {
593+
parameter.maximum = parameter.maximum.toExponential(3)
594+
}
583595
}
584596
}
585597
range = `${parameter.minimum}..${parameter.maximum}`

openc3-cosmos-init/plugins/packages/openc3-js-common/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@
5151
"sass": "1.85.0",
5252
"sortablejs": "1.15.6",
5353
"sprintf-js": "1.1.3",
54-
"uplot": "1.6.31"
54+
"uplot": "1.6.31",
55+
"lossless-json": "4.0.2"
5556
},
5657
"devDependencies": {
5758
"eslint": "9.20.1",

openc3-cosmos-init/plugins/packages/openc3-js-common/src/services/openc3Api.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@
2121
*/
2222

2323
import axios from './axios.js'
24+
import { parse, stringify, isSafeNumber } from 'lossless-json'
2425

26+
// parse huge integer values into a bigint, and use a regular number otherwise
27+
export function customNumberParser(value) {
28+
return isSafeNumber(value) ? parseFloat(value) : BigInt(value)
29+
}
2530
export default class OpenC3Api {
2631
id = 1
2732

@@ -67,6 +72,19 @@ export default class OpenC3Api {
6772
...headerOptions,
6873
},
6974
timeout: timeout,
75+
transformRequest: [
76+
(data, headers) => {
77+
// stringify the data with lossless-json
78+
return stringify(data)
79+
},
80+
],
81+
transformResponse: [
82+
(data) => {
83+
// parse the data with lossless-json ensuring that large numbers are parsed as BigInts
84+
// but all other numbers are parsed as regular numbers
85+
return parse(data, undefined, customNumberParser)
86+
},
87+
],
7088
},
7189
)
7290
// let data = response.data

openc3/spec/api/router_api_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class ApiTest
7171
expect(router).to be_a Hash
7272
expect(router['name']).to eql "ROUTE_INT"
7373
# Verify it also includes the status
74-
expect(router['state']).to eql "CONNECTED"
74+
expect(router['state']).to match(/CONNECTED|ATTEMPTING/)
7575
expect(router['clients']).to eql 0
7676
end
7777
end

0 commit comments

Comments
 (0)