cosmos 5.0.2 → 5.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/bin/cosmos +183 -42
  3. data/data/config/microservice.yaml +47 -35
  4. data/data/config/plugins.yaml +10 -147
  5. data/data/config/target.yaml +70 -0
  6. data/data/config/tool.yaml +37 -31
  7. data/ext/cosmos/ext/cosmos_io/cosmos_io.c +14 -14
  8. data/ext/cosmos/ext/packet/packet.c +3 -3
  9. data/ext/cosmos/ext/structure/structure.c +31 -31
  10. data/lib/cosmos/api/api.rb +1 -25
  11. data/lib/cosmos/api/cmd_api.rb +17 -6
  12. data/lib/cosmos/api/config_api.rb +10 -4
  13. data/lib/cosmos/api/limits_api.rb +1 -1
  14. data/lib/cosmos/api/settings_api.rb +19 -7
  15. data/lib/cosmos/api/target_api.rb +2 -2
  16. data/lib/cosmos/api/tlm_api.rb +65 -41
  17. data/lib/cosmos/config/config_parser.rb +19 -22
  18. data/lib/cosmos/config/meta_config_parser.rb +1 -1
  19. data/lib/cosmos/conversions/generic_conversion.rb +2 -2
  20. data/lib/cosmos/conversions/polynomial_conversion.rb +5 -8
  21. data/lib/cosmos/conversions/segmented_polynomial_conversion.rb +26 -9
  22. data/lib/cosmos/io/json_drb.rb +5 -1
  23. data/lib/cosmos/logs/log_writer.rb +78 -29
  24. data/lib/cosmos/microservices/cleanup_microservice.rb +28 -29
  25. data/lib/cosmos/microservices/decom_microservice.rb +1 -1
  26. data/lib/cosmos/microservices/interface_microservice.rb +0 -16
  27. data/lib/cosmos/microservices/microservice.rb +3 -3
  28. data/lib/cosmos/microservices/reducer_microservice.rb +12 -10
  29. data/lib/cosmos/models/cvt_model.rb +6 -6
  30. data/lib/cosmos/models/gem_model.rb +9 -3
  31. data/lib/cosmos/models/info_model.rb +1 -1
  32. data/lib/cosmos/models/interface_model.rb +16 -7
  33. data/lib/cosmos/models/interface_status_model.rb +1 -1
  34. data/lib/cosmos/models/metadata_model.rb +69 -219
  35. data/lib/cosmos/models/metric_model.rb +2 -2
  36. data/lib/cosmos/models/microservice_model.rb +7 -4
  37. data/lib/cosmos/models/microservice_status_model.rb +1 -1
  38. data/lib/cosmos/models/model.rb +23 -16
  39. data/lib/cosmos/models/note_model.rb +122 -0
  40. data/lib/cosmos/models/ping_model.rb +2 -1
  41. data/lib/cosmos/models/plugin_model.rb +108 -48
  42. data/lib/cosmos/models/process_status_model.rb +1 -1
  43. data/lib/cosmos/models/scope_model.rb +10 -25
  44. data/lib/cosmos/models/settings_model.rb +55 -0
  45. data/lib/cosmos/models/sorted_model.rb +167 -0
  46. data/lib/cosmos/models/target_model.rb +143 -27
  47. data/lib/cosmos/models/tool_config_model.rb +38 -0
  48. data/lib/cosmos/models/tool_model.rb +9 -9
  49. data/lib/cosmos/models/widget_model.rb +11 -11
  50. data/lib/cosmos/operators/microservice_operator.rb +2 -1
  51. data/lib/cosmos/packets/packet.rb +24 -1
  52. data/lib/cosmos/packets/packet_config.rb +2 -2
  53. data/lib/cosmos/packets/packet_item.rb +57 -0
  54. data/lib/cosmos/packets/packet_item_limits.rb +14 -2
  55. data/lib/cosmos/packets/parsers/packet_item_parser.rb +1 -1
  56. data/lib/cosmos/packets/parsers/packet_parser.rb +1 -1
  57. data/lib/cosmos/packets/parsers/xtce_parser.rb +1 -1
  58. data/lib/cosmos/packets/structure.rb +30 -33
  59. data/lib/cosmos/packets/structure_item.rb +10 -1
  60. data/lib/cosmos/script/api_shared.rb +30 -25
  61. data/lib/cosmos/script/calendar.rb +37 -15
  62. data/lib/cosmos/script/commands.rb +5 -7
  63. data/lib/cosmos/script/script.rb +19 -39
  64. data/lib/cosmos/script/storage.rb +92 -105
  65. data/lib/cosmos/system/system.rb +2 -1
  66. data/lib/cosmos/tools/table_manager/table_config.rb +16 -1
  67. data/lib/cosmos/tools/table_manager/table_item.rb +1 -1
  68. data/lib/cosmos/tools/table_manager/table_manager_core.rb +213 -309
  69. data/lib/cosmos/top_level.rb +5 -1
  70. data/lib/cosmos/topics/autonomic_topic.rb +2 -2
  71. data/lib/cosmos/topics/calendar_topic.rb +1 -1
  72. data/lib/cosmos/topics/command_decom_topic.rb +35 -1
  73. data/lib/cosmos/topics/command_topic.rb +6 -4
  74. data/lib/cosmos/topics/config_topic.rb +68 -0
  75. data/lib/cosmos/topics/interface_topic.rb +8 -8
  76. data/lib/cosmos/topics/limits_event_topic.rb +5 -3
  77. data/lib/cosmos/topics/notifications_topic.rb +1 -1
  78. data/lib/cosmos/topics/router_topic.rb +9 -9
  79. data/lib/cosmos/topics/telemetry_decom_topic.rb +5 -1
  80. data/lib/cosmos/topics/telemetry_topic.rb +1 -1
  81. data/lib/cosmos/topics/timeline_topic.rb +1 -1
  82. data/lib/cosmos/topics/topic.rb +23 -8
  83. data/lib/cosmos/utilities/logger.rb +4 -3
  84. data/lib/cosmos/utilities/metric.rb +32 -26
  85. data/lib/cosmos/utilities/s3.rb +61 -0
  86. data/lib/cosmos/utilities/s3_file_cache.rb +12 -6
  87. data/lib/cosmos/utilities/store.rb +1 -0
  88. data/lib/cosmos/utilities/store_autoload.rb +25 -134
  89. data/lib/cosmos/version.rb +5 -4
  90. data/templates/plugin-template/plugin.gemspec +0 -2
  91. metadata +12 -10
  92. data/bin/xtce_converter +0 -92
  93. data/lib/cosmos/models/narrative_model.rb +0 -280
@@ -28,6 +28,13 @@ TARGET:
28
28
  required: true
29
29
  description: Maximum file size in bytes (default = 50_000_000)
30
30
  values: \d+
31
+ CMD_LOG_RETAIN_TIME:
32
+ summary: How long to keep raw command logs in seconds.
33
+ parameters:
34
+ - name: Time
35
+ required: true
36
+ description: Number of seconds to keep raw command logs (default = nil = Forever)
37
+ values: \d+
31
38
  CMD_DECOM_LOG_CYCLE_TIME:
32
39
  summary: Command decommutation logs can be cycled on a time interval.
33
40
  parameters:
@@ -42,6 +49,13 @@ TARGET:
42
49
  required: true
43
50
  description: Maximum file size in bytes (default = 50_000_000)
44
51
  values: \d+
52
+ CMD_DECOM_LOG_RETAIN_TIME:
53
+ summary: How long to keep decom command logs in seconds.
54
+ parameters:
55
+ - name: Time
56
+ required: true
57
+ description: Number of seconds to keep decom command logs (default = nil = Forever)
58
+ values: \d+
45
59
  TLM_LOG_CYCLE_TIME:
46
60
  summary: Telemetry binary logs can be cycled on a time interval.
47
61
  parameters:
@@ -56,6 +70,13 @@ TARGET:
56
70
  required: true
57
71
  description: Maximum file size in bytes (default = 50_000_000)
58
72
  values: \d+
73
+ TLM_LOG_RETAIN_TIME:
74
+ summary: How long to keep raw telemetry logs in seconds.
75
+ parameters:
76
+ - name: Time
77
+ required: true
78
+ description: Number of seconds to keep raw telemetry logs (default = nil = Forever)
79
+ values: \d+
59
80
  TLM_DECOM_LOG_CYCLE_TIME:
60
81
  summary: Telemetry decommutation logs can be cycled on a time interval.
61
82
  parameters:
@@ -70,3 +91,52 @@ TARGET:
70
91
  required: true
71
92
  description: Maximum file size in bytes (default = 50_000_000)
72
93
  values: \d+
94
+ TLM_DECOM_LOG_RETAIN_TIME:
95
+ summary: How long to keep decom telemetry logs in seconds.
96
+ parameters:
97
+ - name: Time
98
+ required: true
99
+ description: Number of seconds to keep decom telemetry logs (default = nil = Forever)
100
+ values: \d+
101
+ REDUCED_MINUTE_LOG_RETAIN_TIME:
102
+ summary: How long to keep reduced minute telemetry logs in seconds.
103
+ parameters:
104
+ - name: Time
105
+ required: true
106
+ description: Number of seconds to keep reduced minute telemetry logs (default = nil = Forever)
107
+ values: \d+
108
+ REDUCED_HOUR_LOG_RETAIN_TIME:
109
+ summary: How long to keep reduced hour telemetry logs in seconds.
110
+ parameters:
111
+ - name: Time
112
+ required: true
113
+ description: Number of seconds to keep reduced hour telemetry logs (default = nil = Forever)
114
+ values: \d+
115
+ REDUCED_DAY_LOG_RETAIN_TIME:
116
+ summary: How long to keep reduced day telemetry logs in seconds.
117
+ parameters:
118
+ - name: Time
119
+ required: true
120
+ description: Number of seconds to keep reduced day telemetry logs (default = nil = Forever)
121
+ values: \d+
122
+ LOG_RETAIN_TIME:
123
+ summary: How long to keep all regular telemetry logs in seconds.
124
+ parameters:
125
+ - name: Time
126
+ required: true
127
+ description: Number of seconds to keep all regular telemetry logs (default = nil = Forever)
128
+ values: \d+
129
+ REDUCED_LOG_RETAIN_TIME:
130
+ summary: How long to keep all reduced telemetry logs in seconds.
131
+ parameters:
132
+ - name: Time
133
+ required: true
134
+ description: Number of seconds to keep all reduced telemetry logs (default = nil = Forever)
135
+ values: \d+
136
+ CLEANUP_POLL_TIME:
137
+ summary: Period at which to run the cleanup process.
138
+ parameters:
139
+ - name: Time
140
+ required: true
141
+ description: Number of seconds between runs of the cleanup process (default = 900 = 15 minutes)
142
+ values: \d+
@@ -1,57 +1,63 @@
1
1
  ---
2
2
  TOOL:
3
- summary: Defines a new tool
3
+ summary: Define a tool
4
4
  example: TOOL DEMO Demo
5
+ description: Defines a tool that the plugin adds to the COSMOS system. Tools are web based applications that make use of the Single-SPA javascript library that allows them to by dynamically added to the running system as independent frontend microservices.
5
6
  parameters:
6
- - name: Folder Name
7
+ - name: Tool Folder Name
8
+ description: The exact name of the tool folder in the plugin. ie. tools/<Tool Folder Name>
7
9
  required: true
8
- description: The folder where the tool is located relative to the tools folder in the plugin
9
- values: .*
10
- - name: Name
10
+ values: .+
11
+ - name: Tool Name
12
+ description: Name of the tool that is displayed in the COSMOS Navigation menu
11
13
  required: true
12
- description: The tool name displayed in the Nav bar
13
- values: .*
14
+ values: .+
14
15
  modifiers:
15
16
  URL:
16
- summary: Url to reach the tool relative to the tools Folder Name, or absolute
17
+ summary: Url used to access the tool
18
+ description: The relative url used to access the tool. Defaults to "/tools/<Tool Folder Name>".
17
19
  parameters:
18
- - name: URL
20
+ - name: Url
19
21
  required: true
20
- description: URL
21
- values: .*
22
+ description: The url. If not given defaults to tools/<Tool Folder Name>. Generally should not be given unless linking to external tools.
23
+ values: .+
22
24
  INLINE_URL:
23
- summary: Single SPA url to reach the tool
24
- example: js/app.js
25
+ summary: Internal url to load a tool
26
+ description: The url of the javascript file used to load the tool into single-SPA. Defaults to "js/app.js".
25
27
  parameters:
26
- - name: URL
28
+ - name: Url
27
29
  required: true
28
- description: URL
29
- values: .*
30
- ICON:
31
- summary: Icon used to display the tool link
32
- parameters:
33
- - name: Name
34
- required: true
35
- description: Material design icon name (https://materialdesignicons.com/)
36
- values: .*
30
+ description: The inline url. If not given defaults to js/app.js. Generally should not be given unless using a non-standard filename.
31
+ values: .+
37
32
  WINDOW:
38
- summary: How the tool should be displayed
33
+ summary: How to display the tool when navigated to
34
+ description: The window mode used to display the tool. INLINE opens the tool internally without refreshing the page using the Single-SPA framework. IFRAME opens external tools in an Iframe within COSMOS. NEW opens the tool in a new TAB.
39
35
  parameters:
40
- - name: Mode
36
+ - name: Window Mode
41
37
  required: true
42
38
  description: Tool display mode
43
39
  values: ["INLINE", "IFRAME", "NEW"]
40
+ ICON:
41
+ summary: Set tool icon
42
+ description: Icon shown next to the tool name in the COSMOS navigation menu.
43
+ parameters:
44
+ - name: Icon Name
45
+ required: true
46
+ description: Icon to display next to the tool name. Icons come from Font Awesome, Material Design (https://materialdesignicons.com/), and Astro.
47
+ values: .+
44
48
  CATEGORY:
45
- summary: Category to place the tool into
49
+ summary: Category for the tool
50
+ description: Associates the tool with a category. In a future release this will be able to organize tools into submenus in the Navigation menu.
46
51
  parameters:
47
- - name: Category
52
+ - name: Category Name
48
53
  required: true
49
- description: Name of a category to organize a tool into
50
- values: .*
54
+ description: Category to associate the tool with
55
+ values: .+
51
56
  SHOWN:
52
- summary: Is the Tool Shown in the Nav Bar
57
+ summary: Show the tool or not
58
+ description: Whether or not the tool is shown in the Navigation menu. Should generally be true, except for the cosmos base tool.
53
59
  parameters:
54
60
  - name: Shown
55
61
  required: true
56
- description: Is Shown?
62
+ description: Whether or not the tool is shown. TRUE or FALSE
57
63
  values: ["true", "false"]
@@ -30,19 +30,19 @@ VALUE mCosmosIO = Qnil;
30
30
  static ID id_method_read = 0;
31
31
 
32
32
  /* Reads a length field and then return the String resulting from reading the
33
- * number of bytes the length field indicates
34
- *
35
- * For example:
36
- * io = StringIO.new
37
- * # where io is "\x02\x01\x02\x03\x04...."
38
- * result = io.read_length_bytes(1)
39
- * # result will be "\x01x02" because the length field was given
40
- * # to be 1 byte. We read 1 byte which is a 2. So we then read two
41
- * # bytes and return.
42
- *
43
- * @param length_num_bytes [Integer] Number of bytes in the length field
44
- * @return [String] A String of "length field" number of bytes
45
- */
33
+ * number of bytes the length field indicates
34
+ *
35
+ * For example:
36
+ * io = StringIO.new
37
+ * # where io is "\x02\x01\x02\x03\x04...."
38
+ * result = io.read_length_bytes(1)
39
+ * # result will be "\x01x02" because the length field was given
40
+ * # to be 1 byte. We read 1 byte which is a 2. So we then read two
41
+ * # bytes and return.
42
+ *
43
+ * @param length_num_bytes [Integer] Number of bytes in the length field
44
+ * @return [String] A String of "length field" number of bytes
45
+ */
46
46
  static VALUE read_length_bytes(int argc, VALUE *argv, VALUE self)
47
47
  {
48
48
  int length_num_bytes = 0;
@@ -134,7 +134,7 @@ static VALUE read_length_bytes(int argc, VALUE *argv, VALUE self)
134
134
  }
135
135
 
136
136
  /* Read String */
137
- temp_string_length = UINT2NUM(string_length);
137
+ temp_string_length = UINT2NUM((unsigned int)string_length);
138
138
  return_value = rb_funcall(self, id_method_read, 1, temp_string_length);
139
139
  if (NIL_P(return_value) || (RSTRING_LEN(return_value) != string_length))
140
140
  {
@@ -196,7 +196,7 @@ static VALUE packet_initialize(int argc, VALUE *argv, VALUE self)
196
196
  packet_name = argv[1];
197
197
  default_endianness = symbol_BIG_ENDIAN;
198
198
  description = Qnil;
199
- buffer = rb_str_new2("");
199
+ buffer = Qnil;
200
200
  item_class = cPacketItem;
201
201
  break;
202
202
  case 3:
@@ -204,7 +204,7 @@ static VALUE packet_initialize(int argc, VALUE *argv, VALUE self)
204
204
  packet_name = argv[1];
205
205
  default_endianness = argv[2];
206
206
  description = Qnil;
207
- buffer = rb_str_new2("");
207
+ buffer = Qnil;
208
208
  item_class = cPacketItem;
209
209
  break;
210
210
  case 4:
@@ -212,7 +212,7 @@ static VALUE packet_initialize(int argc, VALUE *argv, VALUE self)
212
212
  packet_name = argv[1];
213
213
  default_endianness = argv[2];
214
214
  description = argv[3];
215
- buffer = rb_str_new2("");
215
+ buffer = Qnil;
216
216
  item_class = cPacketItem;
217
217
  break;
218
218
  case 5:
@@ -56,6 +56,7 @@ static ID id_method_reverse = 0;
56
56
  static ID id_method_Integer = 0;
57
57
  static ID id_method_Float = 0;
58
58
  static ID id_method_kind_of = 0;
59
+ static ID id_method_allocate_buffer_if_needed = 0;
59
60
 
60
61
  static ID id_ivar_buffer = 0;
61
62
  static ID id_ivar_bit_offset = 0;
@@ -520,7 +521,8 @@ static VALUE binary_accessor_read(VALUE self, VALUE param_bit_offset, VALUE para
520
521
  {
521
522
  string_length = upper_bound - lower_bound + 1;
522
523
  string = malloc(string_length + 1);
523
- if (string == NULL) {
524
+ if (string == NULL)
525
+ {
524
526
  rb_raise(rb_eNoMemError, "malloc of %d returned NULL", string_length + 1);
525
527
  }
526
528
  memcpy(string, buffer + lower_bound, string_length);
@@ -577,7 +579,8 @@ static VALUE binary_accessor_read(VALUE self, VALUE param_bit_offset, VALUE para
577
579
  string_length = ((bit_size - 1) / 8) + 1;
578
580
  array_length = string_length + 4; /* Required number of bytes plus slack */
579
581
  unsigned_char_array = (unsigned char *)malloc(array_length);
580
- if (unsigned_char_array == NULL) {
582
+ if (unsigned_char_array == NULL)
583
+ {
581
584
  rb_raise(rb_eNoMemError, "malloc of %d returned NULL", array_length);
582
585
  }
583
586
  read_bitfield(lower_bound, upper_bound, bit_offset, bit_size, given_bit_offset, given_bit_size, param_endianness, buffer, (int)buffer_length, unsigned_char_array);
@@ -692,7 +695,8 @@ static VALUE binary_accessor_read(VALUE self, VALUE param_bit_offset, VALUE para
692
695
  string_length = ((bit_size - 1) / 8) + 1;
693
696
  array_length = string_length + 4; /* Required number of bytes plus slack */
694
697
  unsigned_char_array = (unsigned char *)malloc(array_length);
695
- if (unsigned_char_array == NULL) {
698
+ if (unsigned_char_array == NULL)
699
+ {
696
700
  rb_raise(rb_eNoMemError, "malloc of %d returned NULL", array_length);
697
701
  }
698
702
  read_bitfield(lower_bound, upper_bound, bit_offset, bit_size, given_bit_offset, given_bit_size, param_endianness, buffer, (int)buffer_length, unsigned_char_array);
@@ -1147,7 +1151,8 @@ static VALUE binary_accessor_write(VALUE self, VALUE value, VALUE param_bit_offs
1147
1151
  string_length = ((bit_size - 1) / 8) + 1;
1148
1152
  array_length = string_length + 4; /* Required number of bytes plus slack */
1149
1153
  unsigned_char_array = (unsigned char *)malloc(array_length);
1150
- if (unsigned_char_array == NULL) {
1154
+ if (unsigned_char_array == NULL)
1155
+ {
1151
1156
  rb_raise(rb_eNoMemError, "malloc of %d returned NULL", array_length);
1152
1157
  }
1153
1158
 
@@ -1275,15 +1280,8 @@ static VALUE binary_accessor_write(VALUE self, VALUE value, VALUE param_bit_offs
1275
1280
  */
1276
1281
  static int get_int_length(VALUE self)
1277
1282
  {
1278
- volatile VALUE buffer = rb_ivar_get(self, id_ivar_buffer);
1279
- if (RTEST(buffer))
1280
- {
1281
- return (int)RSTRING_LEN(buffer);
1282
- }
1283
- else
1284
- {
1285
- return 0;
1286
- }
1283
+ rb_funcall(self, id_method_allocate_buffer_if_needed, 0);
1284
+ return (int)RSTRING_LEN(rb_ivar_get(self, id_ivar_buffer));
1287
1285
  }
1288
1286
 
1289
1287
  /*
@@ -1310,24 +1308,21 @@ static VALUE read_item_internal(VALUE self, VALUE item, VALUE buffer)
1310
1308
  return Qnil;
1311
1309
  }
1312
1310
 
1313
- if (RTEST(buffer))
1311
+ if (!(RTEST(buffer)))
1314
1312
  {
1315
- bit_offset = rb_ivar_get(item, id_ivar_bit_offset);
1316
- bit_size = rb_ivar_get(item, id_ivar_bit_size);
1317
- array_size = rb_ivar_get(item, id_ivar_array_size);
1318
- endianness = rb_ivar_get(item, id_ivar_endianness);
1319
- if (RTEST(array_size))
1320
- {
1321
- return rb_funcall(cBinaryAccessor, id_method_read_array, 6, bit_offset, bit_size, data_type, array_size, buffer, endianness);
1322
- }
1323
- else
1324
- {
1325
- return binary_accessor_read(cBinaryAccessor, bit_offset, bit_size, data_type, buffer, endianness);
1326
- }
1313
+ buffer = rb_funcall(self, id_method_allocate_buffer_if_needed, 0);
1314
+ }
1315
+ bit_offset = rb_ivar_get(item, id_ivar_bit_offset);
1316
+ bit_size = rb_ivar_get(item, id_ivar_bit_size);
1317
+ array_size = rb_ivar_get(item, id_ivar_array_size);
1318
+ endianness = rb_ivar_get(item, id_ivar_endianness);
1319
+ if (RTEST(array_size))
1320
+ {
1321
+ return rb_funcall(cBinaryAccessor, id_method_read_array, 6, bit_offset, bit_size, data_type, array_size, buffer, endianness);
1327
1322
  }
1328
1323
  else
1329
1324
  {
1330
- rb_raise(rb_eRuntimeError, "No buffer given to read_item");
1325
+ return binary_accessor_read(cBinaryAccessor, bit_offset, bit_size, data_type, buffer, endianness);
1331
1326
  }
1332
1327
  }
1333
1328
 
@@ -1404,8 +1399,8 @@ static VALUE structure_item_spaceship(VALUE self, VALUE other_item)
1404
1399
  if ((bit_offset == 0) && (other_bit_offset == 0))
1405
1400
  {
1406
1401
  /* Both bit_offsets are 0 so sort by bit_size
1407
- * This allows derived items with bit_size of 0 to be listed first
1408
- * Compare based on bit size */
1402
+ * This allows derived items with bit_size of 0 to be listed first
1403
+ * Compare based on bit size */
1409
1404
  bit_size = FIX2INT(rb_ivar_get(self, id_ivar_bit_size));
1410
1405
  other_bit_size = FIX2INT(rb_ivar_get(other_item, id_ivar_bit_size));
1411
1406
  if (bit_size == other_bit_size)
@@ -1518,12 +1513,12 @@ static VALUE structure_initialize(int argc, VALUE *argv, VALUE self)
1518
1513
  {
1519
1514
  case 0:
1520
1515
  default_endianness = HOST_ENDIANNESS;
1521
- buffer = rb_str_new2("");
1516
+ buffer = Qnil;
1522
1517
  item_class = cStructureItem;
1523
1518
  break;
1524
1519
  case 1:
1525
1520
  default_endianness = argv[0];
1526
- buffer = rb_str_new2("");
1521
+ buffer = Qnil;
1527
1522
  item_class = cStructureItem;
1528
1523
  break;
1529
1524
  case 2:
@@ -1592,6 +1587,10 @@ static VALUE resize_buffer(VALUE self)
1592
1587
  rb_str_concat(buffer, rb_str_times(ZERO_STRING, INT2FIX(defined_length - current_length)));
1593
1588
  }
1594
1589
  }
1590
+ else
1591
+ {
1592
+ rb_funcall(self, id_method_allocate_buffer_if_needed, 0);
1593
+ }
1595
1594
 
1596
1595
  return self;
1597
1596
  }
@@ -1618,6 +1617,7 @@ void Init_structure(void)
1618
1617
  id_method_Integer = rb_intern("Integer");
1619
1618
  id_method_Float = rb_intern("Float");
1620
1619
  id_method_kind_of = rb_intern("kind_of?");
1620
+ id_method_allocate_buffer_if_needed = rb_intern("allocate_buffer_if_needed");
1621
1621
 
1622
1622
  MIN_INT8 = INT2NUM(-128);
1623
1623
  MAX_INT8 = INT2NUM(127);
@@ -28,36 +28,12 @@ require 'cosmos/api/settings_api'
28
28
  require 'cosmos/api/target_api'
29
29
  require 'cosmos/api/tlm_api'
30
30
  require 'cosmos/utilities/authorization'
31
+ require 'cosmos/topics/topic'
31
32
 
32
33
  module Cosmos
33
34
  module Api
34
35
  include Extract
35
36
  include Authorization
36
37
  include ApiShared
37
-
38
- # PRIVATE - Shared by cmd_api and tlm_api
39
-
40
- def _get_cnt(topic)
41
- _, packet = Store.instance.read_topic_last(topic)
42
- packet ? packet["received_count"].to_i : 0
43
- end
44
-
45
- def get_all_cmd_tlm_info(type, scope:, token:)
46
- authorize(permission: 'system', scope: scope, token: token)
47
- result = []
48
- keys = []
49
- count = 0
50
- loop do
51
- count, part = Store.scan(0, :match => "#{scope}__#{type}__*", :count => 1000)
52
- keys.concat(part)
53
- break if count.to_i == 0
54
- end
55
- keys.each do |key|
56
- _, _, target, packet = key.gsub(/{|}/, '').split('__') # split off scope and type
57
- result << [target, packet, _get_cnt(key)]
58
- end
59
- # Return the results sorted by target, packet
60
- result.sort_by { |a| [a[0], a[1]] }
61
- end
62
38
  end
63
39
  end
@@ -35,6 +35,7 @@ module Cosmos
35
35
  'cmd_raw_no_checks',
36
36
  'send_raw',
37
37
  'get_all_commands',
38
+ 'get_all_commands_list',
38
39
  'get_command',
39
40
  'get_parameter',
40
41
  'get_cmd_buffer',
@@ -194,7 +195,7 @@ module Cosmos
194
195
  authorize(permission: 'cmd_info', target_name: target_name, packet_name: command_name, scope: scope, token: token)
195
196
  TargetModel.packet(target_name, command_name, type: :CMD, scope: scope)
196
197
  topic = "#{scope}__COMMAND__{#{target_name}}__#{command_name}"
197
- msg_id, msg_hash = Store.instance.read_topic_last(topic)
198
+ msg_id, msg_hash = Topic.get_newest_message(topic)
198
199
  if msg_id
199
200
  msg_hash['buffer'] = msg_hash['buffer'].b
200
201
  return msg_hash
@@ -212,6 +213,16 @@ module Cosmos
212
213
  TargetModel.packets(target_name, type: :CMD, scope: scope)
213
214
  end
214
215
 
216
+ # Returns an array of all the command names and their descriptions
217
+ #
218
+ # @since 5.0.3
219
+ # @param target_name [String] Name of the target
220
+ # @return [Array<Hash>] Array of all commands as a hash
221
+ def get_all_commands_list(target_name, scope: $cosmos_scope, token: $cosmos_token)
222
+ authorize(permission: 'cmd_info', target_name: target_name, scope: scope, token: token)
223
+ TargetModel.all_packet_name_descriptions(target_name, type: :CMD, scope: scope)
224
+ end
225
+
215
226
  # Returns a hash of the given command
216
227
  #
217
228
  # @since 5.0.0
@@ -291,7 +302,7 @@ module Cosmos
291
302
  # @return [Varies] value
292
303
  def get_cmd_value(target_name, command_name, parameter_name, value_type = :CONVERTED, scope: $cosmos_scope, token: $cosmos_token)
293
304
  authorize(permission: 'cmd_info', target_name: target_name, packet_name: command_name, scope: scope, token: token)
294
- Store.instance.get_cmd_item(target_name, command_name, parameter_name, type: value_type, scope: scope)
305
+ CommandDecomTopic.get_cmd_item(target_name, command_name, parameter_name, type: value_type, scope: scope)
295
306
  end
296
307
 
297
308
  # Returns the time the most recent command was sent
@@ -304,7 +315,7 @@ module Cosmos
304
315
  def get_cmd_time(target_name = nil, command_name = nil, scope: $cosmos_scope, token: $cosmos_token)
305
316
  authorize(permission: 'cmd_info', target_name: target_name, packet_name: command_name, scope: scope, token: token)
306
317
  if target_name and command_name
307
- time = Store.instance.get_cmd_item(target_name, command_name, 'RECEIVED_TIMESECONDS', type: :CONVERTED, scope: scope)
318
+ time = CommandDecomTopic.get_cmd_item(target_name, command_name, 'RECEIVED_TIMESECONDS', type: :CONVERTED, scope: scope)
308
319
  [target_name, command_name, time.to_i, ((time.to_f - time.to_i) * 1_000_000).to_i]
309
320
  else
310
321
  if target_name.nil?
@@ -316,7 +327,7 @@ module Cosmos
316
327
  time = 0
317
328
  command_name = nil
318
329
  TargetModel.packets(target_name, type: :CMD, scope: scope).each do |packet|
319
- cur_time = Store.instance.get_cmd_item(target_name, packet["packet_name"], 'RECEIVED_TIMESECONDS', type: :CONVERTED, scope: scope)
330
+ cur_time = CommandDecomTopic.get_cmd_item(target_name, packet["packet_name"], 'RECEIVED_TIMESECONDS', type: :CONVERTED, scope: scope)
320
331
  next unless cur_time
321
332
 
322
333
  if cur_time > time
@@ -338,7 +349,7 @@ module Cosmos
338
349
  def get_cmd_cnt(target_name, command_name, scope: $cosmos_scope, token: $cosmos_token)
339
350
  authorize(permission: 'system', target_name: target_name, packet_name: command_name, scope: scope, token: token)
340
351
  TargetModel.packet(target_name, command_name, type: :CMD, scope: scope)
341
- _get_cnt("#{scope}__COMMAND__{#{target_name}}__#{command_name}")
352
+ Topic.get_cnt("#{scope}__COMMAND__{#{target_name}}__#{command_name}")
342
353
  end
343
354
 
344
355
  # Get information on all command packets
@@ -351,7 +362,7 @@ module Cosmos
351
362
  TargetModel.packets(target_name, type: :CMD, scope: scope).each do | packet |
352
363
  command_name = packet['packet_name']
353
364
  key = "#{scope}__COMMAND__{#{target_name}}__#{command_name}"
354
- result << [target_name, command_name, _get_cnt(key)]
365
+ result << [target_name, command_name, Topic.get_cnt(key)]
355
366
  end
356
367
  end
357
368
  # Return the results sorted by target, packet
@@ -17,6 +17,8 @@
17
17
  # enterprise edition license of COSMOS if purchased from the
18
18
  # copyright holder
19
19
 
20
+ require 'cosmos/models/tool_config_model'
21
+
20
22
  module Cosmos
21
23
  module Api
22
24
  WHITELIST ||= []
@@ -34,19 +36,23 @@ module Cosmos
34
36
  end
35
37
 
36
38
  def list_configs(tool, scope: $cosmos_scope, token: $cosmos_token)
37
- Store.instance.hkeys("#{scope}__config__#{tool}")
39
+ authorize(permission: 'system', scope: scope, token: token)
40
+ ToolConfigModel.list_configs(tool, scope: scope)
38
41
  end
39
42
 
40
43
  def load_config(tool, name, scope: $cosmos_scope, token: $cosmos_token)
41
- Store.instance.hget("#{scope}__config__#{tool}", name)
44
+ authorize(permission: 'system', scope: scope, token: token)
45
+ ToolConfigModel.load_config(tool, name, scope: scope)
42
46
  end
43
47
 
44
48
  def save_config(tool, name, data, scope: $cosmos_scope, token: $cosmos_token)
45
- Store.instance.hset("#{scope}__config__#{tool}", name, data)
49
+ authorize(permission: 'system_set', scope: scope, token: token)
50
+ ToolConfigModel.save_config(tool, name, data, scope: scope)
46
51
  end
47
52
 
48
53
  def delete_config(tool, name, scope: $cosmos_scope, token: $cosmos_token)
49
- Store.instance.hdel("#{scope}__config__#{tool}", name)
54
+ authorize(permission: 'system_set', scope: scope, token: token)
55
+ ToolConfigModel.delete_config(tool, name, scope: scope)
50
56
  end
51
57
  end
52
58
  end
@@ -64,7 +64,7 @@ module Cosmos
64
64
  targets.each do |target_name|
65
65
  get_all_telemetry(target_name, scope: scope).each do |packet|
66
66
  topic = "#{scope}__TELEMETRY__{#{target_name}}__#{packet['packet_name']}"
67
- _, msg_hash = Store.get_newest_message(topic)
67
+ _, msg_hash = Topic.get_newest_message(topic)
68
68
  unless msg_hash && msg_hash['time'].to_i > stale_time
69
69
  next if with_limits_only && packet['items'].find { |item| item['limits'] }.nil?
70
70
 
@@ -19,8 +19,6 @@
19
19
 
20
20
  module Cosmos
21
21
  module Api
22
- SETTINGS_KEY = "cosmos__settings"
23
-
24
22
  WHITELIST ||= []
25
23
  WHITELIST.concat([
26
24
  'list_settings',
@@ -31,28 +29,42 @@ module Cosmos
31
29
  ])
32
30
 
33
31
  def list_settings(scope: $cosmos_scope, token: $cosmos_token)
34
- Store.instance.hkeys(SETTINGS_KEY)
32
+ authorize(permission: 'system', scope: scope, token: token)
33
+ SettingsModel.names(scope: scope)
35
34
  end
36
35
 
37
36
  def get_all_settings(scope: $cosmos_scope, token: $cosmos_token)
38
- Store.instance.hgetall(SETTINGS_KEY)
37
+ authorize(permission: 'system', scope: scope, token: token)
38
+ SettingsModel.all(scope: scope)
39
39
  end
40
40
 
41
41
  def get_setting(name, scope: $cosmos_scope, token: $cosmos_token)
42
- Store.instance.hget(SETTINGS_KEY, name)
42
+ authorize(permission: 'system', scope: scope, token: token)
43
+ setting = SettingsModel.get(name: name, scope: scope)
44
+ if setting
45
+ return setting["data"]
46
+ else
47
+ return nil
48
+ end
43
49
  end
44
50
 
45
51
  def get_settings(*args, scope: $cosmos_scope, token: $cosmos_token)
52
+ authorize(permission: 'system', scope: scope, token: token)
46
53
  ret = []
47
54
  args.each do |name|
48
- ret << Store.instance.hget(SETTINGS_KEY, name)
55
+ setting = SettingsModel.get(name: name, scope: scope)
56
+ if setting
57
+ ret << setting["data"]
58
+ else
59
+ ret << nil
60
+ end
49
61
  end
50
62
  return ret
51
63
  end
52
64
 
53
65
  def save_setting(name, data, scope: $cosmos_scope, token: $cosmos_token)
54
66
  authorize(permission: 'admin', scope: scope, token: token)
55
- Store.instance.hset(SETTINGS_KEY, name, data)
67
+ SettingsModel.set({ name: name, data: data }, scope: scope)
56
68
  end
57
69
  end
58
70
  end
@@ -56,12 +56,12 @@ module Cosmos
56
56
  cmd_cnt = 0
57
57
  packets = TargetModel.packets(target_name, type: :CMD, scope: scope)
58
58
  packets.each do |packet|
59
- cmd_cnt += _get_cnt("#{scope}__COMMAND__{#{target_name}}__#{packet['packet_name']}")
59
+ cmd_cnt += Topic.get_cnt("#{scope}__COMMAND__{#{target_name}}__#{packet['packet_name']}")
60
60
  end
61
61
  tlm_cnt = 0
62
62
  packets = TargetModel.packets(target_name, type: :TLM, scope: scope)
63
63
  packets.each do |packet|
64
- tlm_cnt += _get_cnt("#{scope}__TELEMETRY__{#{target_name}}__#{packet['packet_name']}")
64
+ tlm_cnt += Topic.get_cnt("#{scope}__TELEMETRY__{#{target_name}}__#{packet['packet_name']}")
65
65
  end
66
66
  interface_name = ''
67
67
  InterfaceModel.all(scope: scope).each do |name, interface|