Skip to content

Commit

Permalink
Merge pull request #23 from ut-issl/feature/create_TypeA_cmd
Browse files Browse the repository at this point in the history
Type-Aコマンドの実装
  • Loading branch information
TomokiMochizuki authored May 7, 2023
2 parents aa32e60 + 6e8fb27 commit b9610c2
Show file tree
Hide file tree
Showing 24 changed files with 264 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const OpenPlanDialog = (props: OpenPlanDialogProps) => {
};

const handleOk = () => {
if (values != []) {
if (values.length != 0) {
indexes.forEach(index => {
if (values.indexOf(index.id) >= 0) {
dispatch(openPlan(index.id));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ import OpenPlanDialog from './OpenPlanDialog';
import PlanTabPanel from './PlanTabPanel';
import IconButtonInTabs from '../../common/IconButtonInTabs';
import { UNPLANNED_ID } from '../../../constants';
import Radio from '@material-ui/core/Radio';
import RadioGroup from '@material-ui/core/RadioGroup';
import FormControlLabel from '@material-ui/core/FormControlLabel';
import FormControl from '@material-ui/core/FormControl';
import FormLabel from '@material-ui/core/FormLabel';
import Toolbar from '@material-ui/core/Toolbar';
import { getCmdType } from '../../../redux/plans/selectors';
import { setCmdTypeAction } from '../../../redux/plans/actions';

const useStyles = makeStyles(
createStyles({
Expand Down Expand Up @@ -46,6 +54,10 @@ const useStyles = makeStyles(
width: '80%',
maxHeight: 435,
},
cmdTypeField: {
fontSize: "10pt",
textAlign:"center"
},
planTab: {
width: 700
}
Expand All @@ -71,6 +83,7 @@ const PlanDisplayArea = () => {
const planContents = getPlanContents(selector);
const inExecution = getInExecution(selector);
const value = openedIds.indexOf(activePlanId);
const [cmdType, setCmdType] = React.useState(getCmdType(selector));

const handleDialogOpen = () => {
if (!inExecution) {
Expand All @@ -89,6 +102,12 @@ const PlanDisplayArea = () => {
}
};

const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
let cmdType = (event.target as HTMLInputElement).value
setCmdType(cmdType);
dispatch(setCmdTypeAction(cmdType));
};

const closePlan = (id: string) => {
dispatch(closePlanAction(id));
}
Expand Down Expand Up @@ -135,9 +154,20 @@ const PlanDisplayArea = () => {
</IconButtonInTabs>
</Tabs>
<div className={classes.planTab} >
<FormControl component="fieldset">
<Toolbar>
<FormLabel component="legend" className={classes.cmdTypeField}>Data Type</FormLabel>
<RadioGroup aria-label="data-type" name="data-type" value={cmdType} onChange={handleChange}>
<Toolbar>
<FormControlLabel value="Type-A" control={<Radio />} label="Type-A" />
<FormControlLabel value="Type-B" control={<Radio />} label="Type-B" />
</Toolbar>
</RadioGroup>
</Toolbar>
</FormControl>
{planIndexes.length > 0 && (
planIndexes.map((index,i) => (
<PlanTabPanel key={index.id} value={value} index={i} name={index.name} content={planContents[index.id]} />
<PlanTabPanel key={index.id} value={value} index={i} name={index.name} content={planContents[index.id]} cmdType={cmdType} />
))
)}
</div>
Expand Down Expand Up @@ -182,9 +212,20 @@ const PlanDisplayArea = () => {
</IconButtonInTabs>
</Tabs>
<div className={classes.planTab} >
<FormControl component="fieldset">
<Toolbar>
<FormLabel component="legend" className={classes.cmdTypeField}>Data Type</FormLabel>
<RadioGroup aria-label="data-type" name="data-type" value={cmdType} onChange={handleChange}>
<Toolbar>
<FormControlLabel value="Type-A" control={<Radio />} label="Type-A" />
<FormControlLabel value="Type-B" control={<Radio />} label="Type-B" />
</Toolbar>
</RadioGroup>
</Toolbar>
</FormControl>
{planIndexes.length > 0 && (
planIndexes.map((index,i) => (
<PlanTabPanel key={index.id} value={value} index={i} name={index.name} content={planContents[index.id]} />
<PlanTabPanel key={index.id} value={value} index={i} name={index.name} content={planContents[index.id]} cmdType={cmdType} />
))
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ const useStyles = makeStyles(
button: {
width: 120
},
cmdTypeField: {
fontSize: "10pt",
textAlign:"center"
},
activeTab: {
height: 700,
zIndex: 99,
Expand All @@ -57,11 +61,12 @@ export interface PlanTabPanelProps {
value: number,
index: number,
name: string,
content: CommandPlanLine[]
content: CommandPlanLine[],
cmdType: string
}

const PlanTabPanel = (props: PlanTabPanelProps) => {
const {value, index, name, content } = props;
const {value, index, name, content, cmdType } = props;
const classes = useStyles();
const dispatch = useDispatch();
const selector = useSelector((state: RootState) => state);
Expand Down Expand Up @@ -216,7 +221,7 @@ const PlanTabPanel = (props: PlanTabPanelProps) => {
const executeMultipleRequests = async () => {
let row = selectedRow;
do {
const exeret = await executeRequest(row);
const exeret = await executeRequest(row, cmdType);
await sendCmdFileLine(row, exeret);
if (content[row].request.method == "call") {
break;
Expand Down Expand Up @@ -316,7 +321,7 @@ const PlanTabPanel = (props: PlanTabPanelProps) => {
}
}

const executeRequest = async (row: number): Promise<boolean> => {
const executeRequest = async (row: number, cmdType: string): Promise<boolean> => {
const req = content[row].request;
let exeret = false;
switch (req.type) {
Expand Down Expand Up @@ -372,7 +377,7 @@ const PlanTabPanel = (props: PlanTabPanelProps) => {
}
}
}
await dispatch(postCommand(row, req, paramsValue, commandret));
await dispatch(postCommand(row, cmdType, req, paramsValue, commandret));
exeret = commandret[0];
break;

Expand Down
3 changes: 2 additions & 1 deletion aspnetapp/WINGS/ClientApp/src/models/CommandPlan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export type CommandPlanLine = {

export type CommandPlanState = {
allIndexes: CommandPlanIndex[],
cmdFileVariables: CmdFileVariable[];
cmdFileVariables: CmdFileVariable[],
cmdType: string,
openedIds: string[],
activeId: string,
selectedRow: number,
Expand Down
8 changes: 8 additions & 0 deletions aspnetapp/WINGS/ClientApp/src/redux/plans/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const MOVE_UP_UNPLANNED_COMMAND = 'MOVE_UP_UNPLANNED_COMMAND' as const;
export const MOVE_DOWN_UNPLANNED_COMMAND = 'MOVE_DOWN_UNPLANNED_COMMAND' as const;
export const FINISH_EDIT_COMMAND_LINE = 'FINISH_EDIT_COMMAND_LINE' as const;
export const CANCEL_EDIT_COMMAND_LINE = 'CANCEL_EDIT_COMMAND_LINE' as const;
export const SET_COMMAND_TYPE = 'SET_COMMAND_TYPE' as const;

export const fetchPlanIndexesAction = (indexes: FileIndex[]) => {
return {
Expand Down Expand Up @@ -155,3 +156,10 @@ export const cancelEditCommandLineAction = (row: number) => {
payload: row
}
};

export const setCmdTypeAction = (cmdType: string) => {
return {
type: SET_COMMAND_TYPE,
payload: cmdType
}
};
12 changes: 10 additions & 2 deletions aspnetapp/WINGS/ClientApp/src/redux/plans/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const openPlan = (id: string) => {
}
};

export const postCommand = (row: number, req: Request, paramsValue: string[], ret: boolean[]) => {
export const postCommand = (row: number, cmdType: string, req: Request, paramsValue: string[], ret: boolean[]) => {
return async (dispatch: Dispatch, getState: () => RootState) => {
const opid = getState().operation.id;
var body = JSON.parse(JSON.stringify(req.body));
Expand All @@ -33,7 +33,15 @@ export const postCommand = (row: number, req: Request, paramsValue: string[], re
body.params[i].value = paramsValue[i];
}
}
const res = await fetch(`/api/operations/${opid}/cmd`,{
let cmd_uri :string;
if (cmdType == "Type-A")
{
cmd_uri = "cmd_typeA";
}
else {
cmd_uri = "cmd";
}
const res = await fetch(`/api/operations/${opid}/${cmd_uri}`,{
method: 'POST',
headers: {
'Content-Type': 'application/json'
Expand Down
8 changes: 8 additions & 0 deletions aspnetapp/WINGS/ClientApp/src/redux/plans/reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type Actions =
| ReturnType<typeof Actions.moveDownUnplannedCommandAction>
| ReturnType<typeof Actions.finishEditCommandLineAction>
| ReturnType<typeof Actions.cancelEditCommandLineAction>
| ReturnType<typeof Actions.setCmdTypeAction>
| ReturnType<typeof OperationActions.leaveOperationAction>
;

Expand Down Expand Up @@ -336,6 +337,13 @@ export const PlansReducer = (state = initialState.plans, action: Actions) => {
}
}

case Actions.SET_COMMAND_TYPE: {
return {
...state,
cmdType: action.payload
}
}

case OperationActions.LEAVE_OPERATION: {
return initialState.plans;
}
Expand Down
4 changes: 4 additions & 0 deletions aspnetapp/WINGS/ClientApp/src/redux/plans/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,7 @@ export const getInExecution = createSelector(
state => state.inExecution
);

export const getCmdType = createSelector(
[plansSelector],
state => state.cmdType
);
1 change: 1 addition & 0 deletions aspnetapp/WINGS/ClientApp/src/redux/store/initialState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const initialState: RootState = {
cmdFileInfoIndex: ""
}],
cmdFileVariables: [],
cmdType: "Type-B",
openedIds: [UNPLANNED_ID],
activeId: UNPLANNED_ID,
selectedRow: -1,
Expand Down
38 changes: 37 additions & 1 deletion aspnetapp/WINGS/Controllers/CommandController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@ namespace WINGS.Controllers
public class CommandController : ControllerBase
{
private readonly ICommandService _commandService;
private readonly ITmtcHandlerFactory _tmtcHandlerFactory;
private static int _cmdWindow;
private static bool _getCmdWindowFromTlm;

public CommandController(ICommandService commandService)
public CommandController(ICommandService commandService,
ITmtcHandlerFactory tmtcHandlerFactory)
{
_commandService = commandService;
_tmtcHandlerFactory = tmtcHandlerFactory;
}

// GET: api/operations/f364../cmd
Expand All @@ -27,6 +32,9 @@ public IActionResult GetAll(string id)
try
{
var commands = _commandService.GetAllCommand(id);
_cmdWindow = _tmtcHandlerFactory.GetTmPacketAnalyzer(id).GetCmdWindow();
_getCmdWindowFromTlm = false;
_commandService.InitializeTypeAStatus(id);

return StatusCode(Status200OK, new { data = commands });
}
Expand All @@ -51,6 +59,34 @@ public async Task<IActionResult> Send(string id, [FromBody]JsonElement json)
var ack = await _commandService.SendCommandAsync(id, command, commanderId);
return StatusCode(Status200OK, new { ack = ack });
}

// POST: api/operations/f364../cmd_typeA
[HttpPost("cmd_typeA")]
public async Task<IActionResult> SendTypeA(string id, [FromBody]JsonElement json)
{
var cmdStr = json.GetProperty("command").ToString();
var command = JsonSerializer.Deserialize<Command>(cmdStr, new JsonSerializerOptions{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
Converters = { new JsonStringEnumConverter() }
});
var commanderId = "";

var channelId = UInt16.Parse(command.Code.Remove(0,2), System.Globalization.NumberStyles.HexNumber);

bool ack;

if (!_getCmdWindowFromTlm)
{
_cmdWindow = (int)_tmtcHandlerFactory.GetTmPacketAnalyzer(id).GetCmdWindow();
_getCmdWindowFromTlm = true;
}

var sendTypeATask = _commandService.SendTypeACommandAsync(id, command, commanderId, _cmdWindow);
_cmdWindow = (_cmdWindow + 1) & 0xff;
ack = await sendTypeATask;

return StatusCode(Status200OK, new { ack = ack });
}

// POST: api/operations/f364../cmd/raw
[HttpPost("cmd/raw")]
Expand Down
Loading

0 comments on commit b9610c2

Please sign in to comment.