diff --git a/src/utilities/codemirror/satf/satf-sasf-utils.test.ts b/src/utilities/codemirror/satf/satf-sasf-utils.test.ts index 99bbdc8993..93a1f3cf5e 100644 --- a/src/utilities/codemirror/satf/satf-sasf-utils.test.ts +++ b/src/utilities/codemirror/satf/satf-sasf-utils.test.ts @@ -212,26 +212,54 @@ describe('sasfToSequence', () => { $$EOH RT_on_board_block(/start.txt,\\start\\, PARAMETERS, - attitude_spec( - TYPE,ENUM, - ENUM_NAME,\\STORE_NAME\\, - DEFAULT, \\BOB_HARDWARE\\, - RANGE,\\BOB_HARDWARE, SALLY_FARM, "TIM_FLOWERS"\\ + unsigned_decimal( + TYPE,UNSIGNED_DECIMAL, + RANGE,\\10.01...99.99\\, + RANGE,\\100...199.99\\, ), - rate( - TYPE,UINT, - DEFAULT, 10, + signed_decimal( + TYPE,SIGNED_DECIMAL, + DEFAULT, 10 RANGE,\\10, 90000, 120000, 150000, 360001\\, HELP, \\This is a help\\ ), - measure( - TYPE,FLOAT, - RANGE,\\10.01...99.99\\, - RANGE,\\100...199.99\\, + hex( + TYPE,HEXADECIMAL, + RANGE,\\0x00...0xff\\ + ), + octal( + TYPE,OCTAL, + DEFAULT, 10 + RANGE,\\0, 1, 2, 3, 4, 5, 6, 7\\ + ), + binary( + TYPE,BINARY, + RANGE,\\0, 1\\), + engine( + TYPE,ENGINEERING, ), - temp( + time( + TYPE,TIME, + RANGE,\\0T00:00:00...100T00:00:00\\ + ), + duration( + TYPE,DURATION, + DEFAULT, \\00:01:00\\ + ), + enum( TYPE,STRING, + ENUM_NAME,\\STORE_NAME\\, + DEFAULT, \\BOB_HARDWARE\\, + RANGE,\\BOB_HARDWARE, SALLY_FARM, "TIM_FLOWERS"\\ + ), + string( + TYPE,STRING, + DEFAULT, abc + ), + quoted_string( + TYPE,QUOTED_STRING, DEFAULT, "abc" + RANGES,\\"abc", "123"\\ ), end, STEPS, @@ -247,10 +275,17 @@ describe('sasfToSequence', () => { expect(result.sequences[0].name).toStrictEqual('start.txt'); expect(result.sequences[0].sequence).toStrictEqual(`## /start.txt @INPUT_PARAMS_BEGIN -attitude_spec ENUM STORE_NAME BOB_HARDWARE "BOB_HARDWARE, SALLY_FARM, TIM_FLOWERS" -rate UINT 10, "10, 90000, 120000, 150000, 360001" -measure FLOAT "" "10.01...99.99","100...199.99" -temp STRING "abc" +unsigned_decimal UINT "10.01...99.99, 100...199.99" +signed_decimal INT "" "10, 90000, 120000, 150000, 360001" +hex STRING "0x00...0xff" +octal STRING "" "0, 1, 2, 3, 4, 5, 6, 7" +binary STRING "" "0, 1" +engine FLOAT +time STRING "0T00:00:00...100T00:00:00" +duration STRING +enum ENUM STORE_NAME "" "BOB_HARDWARE, SALLY_FARM, TIM_FLOWERS" +string STRING +quoted_string STRING "" "abc, 123" @INPUT_PARAMS_END R00:01:00 NOOP`); @@ -262,7 +297,7 @@ R00:01:00 NOOP`); RT_on_board_block(/start.txt,\\start\\, PARAMETERS, attitude_spec( - TYPE,ENUM, + TYPE,STRING, ENUM_NAME,\\STORE_NAME\\, RANGE,\\"BOB_HARDWARE", "SALLY_FARM", "TIM_FLOWERS"\\ ), diff --git a/src/utilities/codemirror/satf/satf-sasf-utils.ts b/src/utilities/codemirror/satf/satf-sasf-utils.ts index efc43556c2..0d87a1700e 100644 --- a/src/utilities/codemirror/satf/satf-sasf-utils.ts +++ b/src/utilities/codemirror/satf/satf-sasf-utils.ts @@ -17,7 +17,6 @@ import { COMMAND, COMMANDS, COMMENT, - DEFAULT, ENGINE, ENTRY, ENUM, @@ -34,6 +33,15 @@ import { NUMBER, ON_BOARD_FILENAME, ON_BOARD_PATH, + PARAM_BINARY, + PARAM_DURATION, + PARAM_ENGINEERING, + PARAM_HEXADECIMAL, + PARAM_OCTAL, + PARAM_QUOTED_STRING, + PARAM_SIGNED_DECIMAL, + PARAM_TIME, + PARAM_UNSIGNED_DECIMAL, PARAMETERS, PROCESSOR, RANGE, @@ -53,6 +61,11 @@ import { TIME_RELATION, TYPE, VALUE, + VAR_ENUM, + VAR_FLOAT, + VAR_INT, + VAR_STRING, + VAR_UINT, VARIABLES, VIRTUAL_CHANNEL, } from './satfConstants'; @@ -691,27 +704,58 @@ function parseParameters( const typeNode = param.getChild(TYPE); const rangesNode = param.getChildren(RANGE); const enumNameNode = param.getChild(ENUM_NAME); - const defaultNode = param.getChild(DEFAULT); const name = nameNode ? `${text.slice(nameNode.from, nameNode.to)}` : ''; - const type = typeNode ? ` ${text.slice(typeNode.from, typeNode.to)}` : ''; const enumName = enumNameNode ? ` ${text.slice(enumNameNode.from, enumNameNode.to)}` : ''; - const defaultValue = defaultNode ? ` ${text.slice(defaultNode.from, defaultNode.to)}` : ' ""'; - - const ranges = - rangesNode && rangesNode.length > 0 - ? ` ${rangesNode - .map((range: any) => { - return `"${text - .slice(range.from, range.to) - .split(',') - .map(v => v.replaceAll('"', '').trim()) - .join(', ')}"`; - }) - .join(',')}` - : ''; - - return `${name}${type}${enumName}${defaultValue}${ranges}`; + let type = typeNode ? text.slice(typeNode.from, typeNode.to).trim() : ''; + switch (type) { + case PARAM_UNSIGNED_DECIMAL: + type = VAR_UINT; + break; + case PARAM_SIGNED_DECIMAL: + type = VAR_INT; + break; + case PARAM_HEXADECIMAL: + case PARAM_OCTAL: + case PARAM_BINARY: + case PARAM_TIME: + case PARAM_DURATION: + case PARAM_QUOTED_STRING: + type = VAR_STRING; + break; + case PARAM_ENGINEERING: + type = VAR_FLOAT; + break; + case VAR_STRING: + { + if (enumNameNode) { + type = VAR_ENUM; + } else { + type = VAR_STRING; + } + } + break; + default: + console.log(`type: ${type} is not supported`); + } + + const allowable_values: string[] = []; + const allowable_ranges: string[] = []; + rangesNode.forEach((range: any) => { + text + .slice(range.from, range.to) + .split(',') + .forEach(r => { + r = r.replaceAll('"', '').trim(); + if (r.includes('...')) { + allowable_ranges.push(r); + } else { + allowable_values.push(r); + } + }); + }); + + return `${name} ${type}${enumName}${allowable_ranges.length === 0 ? (allowable_values.length === 0 ? '' : ' ""') : ` "${allowable_ranges.join(', ')}"`}${allowable_values.length === 0 ? '' : ` "${allowable_values.join(', ')}"`}`; }) .join('\n'); parameter += `\n@${variableType}_END\n\n`; diff --git a/src/utilities/codemirror/satf/satfConstants.ts b/src/utilities/codemirror/satf/satfConstants.ts index 330585a486..d8393143ad 100644 --- a/src/utilities/codemirror/satf/satfConstants.ts +++ b/src/utilities/codemirror/satf/satfConstants.ts @@ -54,3 +54,18 @@ export const EXPRESSION = 'Expression'; export const ARITHMETICAL = 'Arithmetical'; export const MODEL = 'Model'; export const ASSUMED_MODEL_VALUES = 'AssumedModelValues'; + +export const PARAM_UNSIGNED_DECIMAL = 'UNSIGNED_DECIMAL'; +export const PARAM_SIGNED_DECIMAL = 'SIGNED_DECIMAL'; +export const PARAM_HEXADECIMAL = 'HEXADECIMAL'; +export const PARAM_OCTAL = 'OCTAL'; +export const PARAM_BINARY = 'BINARY'; +export const PARAM_ENGINEERING = 'ENGINEERING'; +export const PARAM_TIME = 'TIME'; +export const PARAM_DURATION = 'DURATION'; +export const PARAM_QUOTED_STRING = 'QUOTED_STRING'; +export const VAR_ENUM = 'ENUM'; +export const VAR_STRING = 'STRING'; +export const VAR_UINT = 'UINT'; +export const VAR_FLOAT = 'FLOAT'; +export const VAR_INT = 'INT';