spring_ai_rs/ai_interface/callback/command/command_data/
group.rs

1use spring_ai_sys::{
2    SCreateGroupCommand, SEraseGroupCommand, SGroupAddUnitCommand, SGroupClearUnitCommand,
3    UnitCommandOptions as UnitCommandOptions_Sys,
4};
5
6use crate::ai_interface::callback::command::{
7    command_data::{CData, CommandData},
8    options::UnitCommandOptions,
9};
10
11// Group Add Unit data
12pub struct GroupAddUnitCommandData {
13    pub unit_id: i32,
14    pub group_id: i32,
15    pub options: Vec<UnitCommandOptions>,
16    pub timeout: i32,
17    pub to_group_id: i32,
18}
19
20impl CommandData for GroupAddUnitCommandData {
21    type CDataType = SGroupAddUnitCommand;
22
23    fn c_data(&mut self) -> Self::CDataType {
24        SGroupAddUnitCommand {
25            unitId: self.unit_id,
26            groupId: self.group_id,
27            options: self
28                .options
29                .iter()
30                .map(|&uco| UnitCommandOptions_Sys::from(uco))
31                .sum::<i32>() as libc::c_short,
32            timeOut: self.timeout,
33            toGroupId: self.to_group_id,
34        }
35    }
36}
37
38impl CData for SGroupAddUnitCommand {}
39
40// Group Create data
41pub struct CreateGroupCommandData {}
42
43impl CommandData for CreateGroupCommandData {
44    type CDataType = SCreateGroupCommand;
45
46    fn c_data(&mut self) -> Self::CDataType {
47        SCreateGroupCommand { ret_groupId: 0 }
48    }
49}
50
51impl CData for SCreateGroupCommand {}
52
53// Group Erase data
54pub struct EraseGroupCommandData {
55    pub group_id: i32,
56}
57
58impl CommandData for EraseGroupCommandData {
59    type CDataType = SEraseGroupCommand;
60
61    fn c_data(&mut self) -> Self::CDataType {
62        SEraseGroupCommand {
63            groupId: self.group_id,
64        }
65    }
66}
67
68impl CData for SEraseGroupCommand {}
69
70// Group Clear Unit data
71pub struct GroupClearUnitCommandData {
72    pub unit_id: i32,
73    pub group_id: i32,
74    pub options: Vec<UnitCommandOptions>,
75    pub timeout: i32,
76}
77
78impl CommandData for GroupClearUnitCommandData {
79    type CDataType = SGroupClearUnitCommand;
80
81    fn c_data(&mut self) -> Self::CDataType {
82        SGroupClearUnitCommand {
83            unitId: self.unit_id,
84            groupId: self.group_id,
85            options: self
86                .options
87                .iter()
88                .map(|&uco| UnitCommandOptions_Sys::from(uco))
89                .sum::<i32>() as libc::c_short,
90            timeOut: self.timeout,
91        }
92    }
93}
94
95impl CData for SGroupClearUnitCommand {}