seersdk_rs/api/
mod.rs

1//! API request types for RBK robot communication
2//!
3//! This module defines the API request enum that categorizes all RBK APIs
4//! into their respective modules based on the RBK protocol specification.
5
6mod request;
7mod response;
8
9pub use request::*;
10pub use response::*;
11
12pub type TaskId = String;
13pub type PointId = String;
14
15/// API request enum representing all RBK robot APIs
16///
17/// The RBK protocol organizes APIs into modules, each with its own port:
18/// - State APIs (1000-1999): Robot state queries on port 19204
19/// - Control APIs (2000-2999): Robot control commands on port 19205
20/// - Navigation APIs (3000-3999): Navigation commands on port 19206
21/// - Config APIs (4000-5999): Configuration management on port 19207
22/// - Kernel APIs (7000-7999): Kernel operations on port 19208
23/// - Misc APIs (6000-6998): Miscellaneous operations on port 19210
24/// - Push APIs (9000+): Push configuration and push data
25#[derive(Debug, Clone, Copy, PartialEq, Eq)]
26#[repr(u16)]
27pub enum ApiRequest {
28    /// State module APIs (1000-1999)
29    State(StateApi),
30    /// Control module APIs (2000-2999)
31    Control(ControlApi),
32    /// Navigation module APIs (3000-3999)
33    Nav(NavApi),
34    /// Config module APIs (4000-5999)
35    Config(ConfigApi),
36    /// Kernel module APIs (7000-7999)
37    Kernel(KernelApi),
38    /// Misc module APIs (6000-6998)
39    Peripheral(PeripheralApi),
40    /// Push module APIs (9000+)
41    Push(PushApi),
42}
43
44impl ApiRequest {
45    /// Get the API number for this request
46    pub fn api_no(&self) -> u16 {
47        match *self {
48            ApiRequest::State(api) => api as u16,
49            ApiRequest::Control(api) => api as u16,
50            ApiRequest::Nav(api) => api as u16,
51            ApiRequest::Config(api) => api as u16,
52            ApiRequest::Kernel(api) => api as u16,
53            ApiRequest::Peripheral(api) => api as u16,
54            ApiRequest::Push(api) => api as u16,
55        }
56    }
57}
58
59/// Macro to generate request DTO types for RBK robot APIs
60///
61/// This macro creates a request type with associated traits for serialization and response handling.
62///
63/// # Patterns
64///
65/// 1. Request without payload (returns empty string):
66/// ```ignore
67/// impl_api_request!(RequestTypeName, ApiRequest::Module(ModuleApi::Variant), res: ResponseType);
68/// ```
69///
70/// 2. Request with payload (serializes payload to JSON):
71/// ```ignore
72/// impl_api_request!(RequestTypeName, ApiRequest::Module(ModuleApi::Variant), req: PayloadType, res: ResponseType);
73/// ```
74///
75/// # Arguments
76///
77/// * `$req_type` - Name of the request type to generate
78/// * `$api_variant` - The API variant expression (e.g., `ApiRequest::State(StateApi::RobotInfo)`)
79/// * `$req_body_type` - (Optional) Type of the request payload for requests that need a body
80/// * `$res_type` - Type of the response that will be returned
81/// * `$docs` - (Optional) Documentation string for the generated request type
82macro_rules! impl_api_request {
83    // Pattern for requests without payload
84    ($req_type:ident, $api_variant:expr, res: $res_type:ty $(, $docs:literal)?) => {
85        $(#[doc = $docs])?
86        #[derive(Debug, Clone, Default)]
87        pub struct $req_type;
88
89        impl $req_type {
90            pub fn new() -> Self {
91                Self
92            }
93        }
94
95        impl $crate::api::ToRequestBody for $req_type {
96            fn to_request_body(&self) -> Result<String, serde_json::Error> {
97                Ok(String::new())
98            }
99
100            fn to_api_request(&self) -> ApiRequest {
101                $api_variant
102            }
103        }
104
105        impl $crate::api::FromResponseBody for $req_type {
106            type Response = $res_type;
107        }
108    };
109    // Pattern for requests with payload
110    ($req_type:ident, $api_variant:expr, req: $req_body_type:ty, res: $res_type:ty $(, $docs:literal)?) => {
111        $(#[doc = $docs])?
112        #[derive(Debug, Clone)]
113        pub struct $req_type {
114            pub req_body: $req_body_type,
115        }
116
117        impl $req_type {
118            pub fn new(req_body: $req_body_type) -> Self {
119                Self { req_body }
120            }
121        }
122
123        impl $req_body_type {
124            pub fn into_request(self) -> $req_type {
125                $req_type { req_body: self }
126            }
127        }
128
129        impl $crate::api::ToRequestBody for $req_type {
130            fn to_request_body(&self) -> Result<String, serde_json::Error> {
131                serde_json::to_string(&self.req_body)
132            }
133
134            fn to_api_request(&self) -> ApiRequest {
135                $api_variant
136            }
137        }
138
139        impl $crate::api::FromResponseBody for $req_type {
140            type Response = $res_type;
141        }
142    };
143}
144
145// State API requests
146impl_api_request!(CommonInfoRequest, ApiRequest::State(StateApi::Info), res: CommonInfo);
147impl_api_request!(OperationInfoRequest, ApiRequest::State(StateApi::Run), res: OperationInfo);
148impl_api_request!(RobotPoseRequest, ApiRequest::State(StateApi::Loc), res: RobotPose);
149impl_api_request!(RobotSpeedRequest, ApiRequest::State(StateApi::Speed), res: StatusMessage);
150impl_api_request!(BlockStatusRequest, ApiRequest::State(StateApi::Block), res: BlockStatus);
151impl_api_request!(BatteryStatusRequest, ApiRequest::State(StateApi::Battery), res: BatteryStatus);
152impl_api_request!(RobotLidarDataRequest, ApiRequest::State(StateApi::Laser), res: StatusMessage);
153impl_api_request!(RobotCurrentAreaRequest, ApiRequest::State(StateApi::Area), res: StatusMessage);
154impl_api_request!(RobotEmergencyStatusRequest, ApiRequest::State(StateApi::Emergency), res: StatusMessage);
155impl_api_request!(RobotIODataRequest, ApiRequest::State(StateApi::Io), res: StatusMessage);
156impl_api_request!(NavStatusRequest, ApiRequest::State(StateApi::Nav), req: GetNavStatus, res: NavStatus);
157impl_api_request!(TaskStatusRequest, ApiRequest::State(StateApi::TaskPackage), req: GetTaskStatus, res: TaskPackage);
158impl_api_request!(RobotRelocationStatusRequest, ApiRequest::State(StateApi::Reloc), res: StatusMessage);
159impl_api_request!(RobotLoadMapStatusRequest, ApiRequest::State(StateApi::LoadMap), res: StatusMessage);
160impl_api_request!(RobotSlamStatusRequest, ApiRequest::State(StateApi::Slam), res: StatusMessage);
161impl_api_request!(JackStatusRequest, ApiRequest::State(StateApi::Jack), res: StatusMessage);
162impl_api_request!(RobotAlarmStatusRequest, ApiRequest::State(StateApi::Alarm), res: StatusMessage);
163impl_api_request!(RobotAllStatus1Request, ApiRequest::State(StateApi::All1), res: StatusMessage);
164impl_api_request!(RobotAllStatus2Request, ApiRequest::State(StateApi::All2), res: StatusMessage);
165impl_api_request!(RobotAllStatus3Request, ApiRequest::State(StateApi::All3), res: StatusMessage);
166impl_api_request!(RobotMapInfoRequest, ApiRequest::State(StateApi::Map), res: StatusMessage);
167impl_api_request!(RobotParamsRequest, ApiRequest::State(StateApi::Params), res: StatusMessage);
168
169// Control API requests
170impl_api_request!(StopExerciseRequest, ApiRequest::Control(ControlApi::Stop), res: StatusMessage);
171impl_api_request!(RelocateRequest, ApiRequest::Control(ControlApi::Reloc), res: StatusMessage);
172impl_api_request!(ConfirmLocationRequest, ApiRequest::Control(ControlApi::ComfirmLoc), res: StatusMessage);
173impl_api_request!(OpenLoopMotionRequest, ApiRequest::Control(ControlApi::Motion), res: StatusMessage);
174impl_api_request!(SwitchMapRequest, ApiRequest::Control(ControlApi::LoadMap), res: StatusMessage);
175
176// Navigation API requests
177impl_api_request!(PauseTaskRequest, ApiRequest::Nav(NavApi::Pause), res: StatusMessage);
178impl_api_request!(ResumeTaskRequest, ApiRequest::Nav(NavApi::Resume), res: StatusMessage);
179impl_api_request!(CancelTaskRequest, ApiRequest::Nav(NavApi::Cancel), res: StatusMessage);
180impl_api_request!(MoveToTargetRequest, ApiRequest::Nav(NavApi::MoveToTarget), req: MoveToTarget, res: StatusMessage);
181impl_api_request!(TranslateRequest, ApiRequest::Nav(NavApi::Translate), res: StatusMessage);
182impl_api_request!(TurnRequest, ApiRequest::Nav(NavApi::Turn), res: StatusMessage);
183impl_api_request!(MoveDesignedPathRequest, ApiRequest::Nav(NavApi::MoveToTargetList), req: MoveDesignedPath, res: StatusMessage);
184
185// Peripheral API requests
186impl_api_request!(LoadJackRequest, ApiRequest::Peripheral(PeripheralApi::JackLoad), res: StatusMessage);
187impl_api_request!(UnloadJackRequest, ApiRequest::Peripheral(PeripheralApi::JackUnload), res: StatusMessage);
188impl_api_request!(StopJackRequest, ApiRequest::Peripheral(PeripheralApi::JackStop), res: StatusMessage);
189impl_api_request!(SetJackHeightRequest, ApiRequest::Peripheral(PeripheralApi::JackSetHeight), req: SetJackHeight, res: StatusMessage);
190
191#[derive(Debug, Clone, Copy, PartialEq, Eq)]
192#[repr(u16)]
193pub enum StateApi {
194    /// Query Robot Information
195    Info = 1000,
196    /// Query Robot Running Information
197    Run = 1002,
198    /// Query Robot Location
199    Loc = 1004,
200    /// Query Robot Speed
201    Speed = 1005,
202    /// Query Robot Blocked Status
203    Block = 1006,
204    /// Query Robot Battery Status
205    Battery = 1007,
206    /// Query Robot Laser Status
207    Laser = 1009,
208    /// Query Robot Area Status
209    Area = 1011,
210    /// Query Robot Estop Status
211    Emergency = 1012,
212    /// Query Robot I/O Status
213    Io = 1013,
214    /// Query Robot IMU Data
215    Imu = 1014,
216    /// Query Robot RFID Data
217    Rfid = 1015,
218    /// Query Robot Ultrasonic Status
219    Ultrasonic = 1016,
220    /// Query Robot PGV Data
221    Pgv = 1017,
222    /// Query Robot Encoder Status
223    Encoder = 1018,
224    /// Query Robot Navigation Status
225    Nav = 1020,
226    /// Query Robot Localization Status
227    Reloc = 1021,
228    /// Query Robot Map Loading Status
229    LoadMap = 1022,
230    /// Query Scanning Status of Robot
231    Slam = 1025,
232    /// Query Robot Jacking Status
233    Jack = 1027,
234    /// Query Robot Fork Status
235    Fork = 1028,
236    /// Query Robot Roller Status
237    Roller = 1029,
238    /// Query Robot Motor Status
239    Motor = 1040,
240    /// Query Robot Alarm Status
241    Alarm = 1050,
242    /// Query Robot Current Lock
243    CurrentLock = 1060,
244    /// Query Modbus Data
245    Modbus = 1071,
246    /// Query Batch Data 1
247    All1 = 1100,
248    /// Query Batch Data 2
249    All2 = 1101,
250    /// Query Batch Data 3
251    All3 = 1102,
252    /// Query Robot Task Status Package
253    TaskPackage = 1110,
254    /// Query Loaded Map and Stored Map
255    Map = 1300,
256    /// Query Station Information of Currently Loaded Map
257    Station = 1301,
258    /// Query MD5 Value of Specified Map List
259    MapMd5 = 1302,
260    /// Query the Path between Any Two Points
261    GetPath = 1303,
262    /// Query Robot Parameters
263    Params = 1400,
264    /// Download the Robot Model File
265    Model = 1500,
266    /// Query List of Robot Scripts
267    ScriptInfo = 1506,
268    /// Query List of Robot Script Details
269    ScriptDetailsList = 1507,
270    /// Query Default Parameters of Robot Script
271    ScriptArgs = 1508,
272    /// Query Robot Support Calibration List
273    CalibSupportList = 1509,
274    /// Query Robot Calibration Status
275    CalibStatus = 1510,
276    /// Query Robot Calibration File
277    CalibData = 1511,
278    /// Query 3D QR Code During Mapping
279    Tag3D = 1665,
280    /// Query Status of Robotic Arm
281    ArmStatus = 1669,
282    /// Calculate Coordinate Transformation of Robotic Arms
283    ArmCalculate = 1670,
284    /// Robotic Arm binTask
285    ArmTask = 1671,
286    /// Robotic Arm Motion Control
287    ArmMove = 1673,
288    /// Robotic Arm Teaching Panel Control
289    ArmOperation = 1674,
290    /// Query the Point Cloud Image of the Currently Recognized Camera
291    CloudProjection = 1675,
292    /// Emulation from File Recognition
293    RecoFiles = 1676,
294    /// Query Driver Params
295    CanFrame = 1750,
296    /// Query GNSS Connection Status
297    GnssCheck = 1760,
298    /// Query List of GNSS Devices
299    GnssList = 1761,
300    /// Query List of Robot Files
301    ListFile = 1798,
302    /// Upload the Robot File
303    UploadFile = 1799,
304    /// Download the Robot File
305    DownloadFile = 1800,
306    /// Query Storage Bin Information Seen by Robot
307    Bins = 1803,
308    /// Query Robot Sound Status
309    Sound = 1850,
310    /// Download Handle Custom Binding Event
311    JoystickKeymap = 1852,
312    /// Query Transparent Data
313    TransparentData = 1900,
314    /// Run Start Battery Script
315    StartBatteryScript = 1901,
316    /// Stop Robot Battery Script
317    StopBatteryScript = 1902,
318    /// Start Ambient Lamp Script
319    StartDmxScript = 1903,
320    /// Stop Ambient Lamp Script
321    StopDmxScript = 1904,
322}
323
324#[derive(Debug, Clone, Copy, PartialEq, Eq)]
325#[repr(u16)]
326pub enum ControlApi {
327    /// Stop Open Loop Motion
328    Stop = 2000,
329    /// Relocation
330    Reloc = 2002,
331    /// Confirm Correct Location
332    ComfirmLoc = 2003,
333    /// Cancel Relocation
334    CancelReloc = 2004,
335    /// Open Loop Motion
336    Motion = 2010,
337    /// Switch Map
338    LoadMap = 2022,
339    /// Clear Motor Encoder
340    ClearMotorEncoder = 2024,
341    /// Upload and Load Map
342    UploadAndLoadMap = 2025,
343    /// Clear Weight Sensor Value
344    ClearWeightdevvalue = 2026,
345}
346
347#[derive(Debug, Clone, Copy, PartialEq, Eq)]
348#[repr(u16)]
349pub enum NavApi {
350    /// Pause Navigation
351    Pause = 3001,
352    /// Resume Navigation
353    Resume = 3002,
354    /// Cancel Navigation
355    Cancel = 3003,
356    /// Path Navigation
357    MoveToTarget = 3051,
358    /// Get Navigation Path
359    TargetPath = 3053,
360    /// Translation
361    Translate = 3055,
362    /// Rotation
363    Turn = 3056,
364    /// Tray Rotation
365    Spin = 3057,
366    /// Circular Motion
367    Circular = 3058,
368    /// Enable and Disable Paths
369    Path = 3059,
370    /// Designated Path Navigation
371    MoveToTargetList = 3066,
372    /// Clear Specified Path Navigation
373    ClearTargetList = 3067,
374    /// Clear Specified Navigation Path with Task ID
375    SafeClearMovements = 3068,
376    /// Query Task Chain
377    TaskListStatus = 3101,
378    /// Execute Pre-Stored Tasks
379    TaskListName = 3106,
380    /// Query Robot Task Chain List
381    TaskListList = 3115,
382}
383
384#[derive(Debug, Clone, Copy, PartialEq, Eq)]
385#[repr(u16)]
386pub enum ConfigApi {
387    /// Preempt Control
388    Lock = 4005,
389    /// Release Control
390    Unlock = 4006,
391    /// Clear Robot's All Errors
392    ClearAllErrors = 4009,
393    /// Load Map to Robot
394    UploadMap = 4010,
395    /// Download Maps from Robots
396    DownloadMap = 4011,
397    /// Delete Map in Robot
398    RemoveMap = 4012,
399    /// Upload Robot Script
400    UploadScript = 4021,
401    /// Download Robot Script
402    DownloadScript = 4022,
403    /// Delete Robot Script
404    RemoveScript = 4023,
405    /// Configure Robot Push Port
406    Push = 4091,
407    /// Set Robot Params Temporarily
408    SetParams = 4100,
409    /// Set Robot Params Permanently
410    SaveParams = 4101,
411    /// Restore Robot Params
412    ReloadParams = 4102,
413    /// Configure Ultrasonic
414    Ultrasonic = 4130,
415    /// Configure DI
416    Di = 4140,
417    /// Motor Calibration
418    MotorCalib = 4150,
419    /// Motor Clear Fault
420    MotorClearFault = 4151,
421    /// Upload the Model File to Robot
422    Model = 4200,
423    /// Set up Calibration Process Data
424    CalibPushData = 4201,
425    /// Confirmation of Calibration Data
426    CalibConfirm = 4202,
427    /// Clear Calibration Data according to Calibration Type
428    CalibClear = 4203,
429    /// Clear the Robot.cp File
430    CalibClearAll = 4209,
431    /// Add Dynamic Obstacles (Robot Coordinate System)
432    AddObstacle = 4350,
433    /// Add Dynamic Obstacles (World Coordinate System)
434    AddGObstacle = 4351,
435    /// Remove Dynamic Obstacles
436    RemoveObstacle = 4352,
437    /// 3D QR Code Mapping
438    Tag3DMapping = 4353,
439    /// Clear Goods Shape
440    ClearGoodsShape = 4356,
441    /// Set Shelf Description File
442    SetShelfShape = 4357,
443    /// Set Driver Params
444    SendCanFrame = 4400,
445    /// Reset Running Info
446    ClearOdo = 4450,
447    /// Reset GNSS Configuration
448    ResetGnss = 4460,
449    /// Set GNSS Baudrate
450    SetGnssBaudrate = 4461,
451    /// Set GNSS to Rover mode
452    SetGnssRover = 4462,
453    /// Upload Handle Custom Binding Event
454    JoystickBindKeymap = 4470,
455    /// Set Third-Party Error
456    SetError = 4800,
457    /// Clear Third-Party Error
458    ClearError = 4801,
459    /// Set Third-Party Warning
460    SetWarning = 4802,
461    /// Clear Third-Party Warning
462    ClearWarning = 4803,
463}
464
465#[derive(Debug, Clone, Copy, PartialEq, Eq)]
466#[repr(u16)]
467pub enum KernelApi {
468    /// Turn off the robot, the robot will lose power and lose control
469    Shutdown = 5000,
470    /// Restart the robot, the connection will be disconnected during the restart
471    Reboot = 5003,
472    /// Reset the robot firmware
473    ResetFirmware = 5005,
474}
475
476#[derive(Debug, Clone, Copy, PartialEq, Eq)]
477#[repr(u16)]
478pub enum PeripheralApi {
479    /// Play Audio
480    PlayAudio = 6000,
481    /// Set DO
482    SetDo = 6001,
483    /// Batch Set DO
484    SetDos = 6002,
485    /// Set Relay
486    SetRelay = 6003,
487    /// Soft Estop
488    SoftEmc = 6004,
489    /// Set Charging Relay
490    SetChargingRelay = 6005,
491    /// Pause Audio
492    PauseAudio = 6010,
493    /// Resume Audio
494    ResumeAudio = 6011,
495    /// Stop Playing Audio
496    StopAudio = 6012,
497    /// Set Virtual DI
498    SetVdi = 6020,
499    /// Upload Audio Files
500    UploadAudio = 6030,
501    /// Download Audio Files
502    DownloadAudio = 6031,
503    /// Get Audio File List
504    AudioList = 6033,
505    /// Set Fork Height
506    SetForkHeight = 6040,
507    /// Stop Fork Motion
508    StopFork = 6041,
509    /// Write Peripheral User-defined Data
510    WritePeripheralData = 6049,
511    /// Roller (belt) Front Roll
512    RollerFrontRoll = 6051,
513    /// Roller (belt) Back Roll
514    RollerBackRoll = 6052,
515    /// Roller (belt) Left Roll
516    RollerLeftRoll = 6053,
517    /// Roller (belt) Right Roll
518    RollerRightRoll = 6054,
519    /// Roller (belt) Front Load
520    RollerFrontLoad = 6055,
521    /// Roller (belt) Front Unload
522    RollerFrontUnload = 6056,
523    /// Roller (belt) Front Pre-Load
524    RollerFrontPreLoad = 6057,
525    /// Roller (belt) Back Load
526    RollerBackLoad = 6058,
527    /// Roller (belt) Back Unload
528    RollerBackUnload = 6059,
529    /// Roller (belt) Back Pre-Load
530    RollerBackPreLoad = 6060,
531    /// Roller (belt) Left Load
532    RollerLeftLoad = 6061,
533    /// Roller (belt) Left Unload
534    RollerLeftUnload = 6062,
535    /// Roller (belt) Right Load
536    RollerRightLoad = 6063,
537    /// Roller (belt) Right Unload
538    RollerRightUnload = 6064,
539    /// Roller (belt) Left Pre-Load
540    RollerLeftPreLoad = 6065,
541    /// Roller (belt) Right Pre-Load
542    RollerRightPreLoad = 6066,
543    /// Roller (belt) Stop
544    RollerStop = 6067,
545    /// Roller (belt) Inverse Left and Right
546    RollerLeftRightInverse = 6068,
547    /// Roller (belt) Inverse Front and Back
548    RollerFrontBackInverse = 6069,
549    /// Jacking Load
550    JackLoad = 6070,
551    /// Jacking Unload
552    JackUnload = 6071,
553    /// Jacking Stop
554    JackStop = 6072,
555    /// Jacking Height
556    JackSetHeight = 6073,
557    /// Clear Cargo Status
558    ResetCargo = 6080,
559    /// Hook Load
560    HookLoad = 6082,
561    /// Hook Unload
562    HookUnload = 6083,
563    /// Write modbus Data
564    SetModbus = 6086,
565    /// Start Map Scanning
566    Slam = 6100,
567    /// End SLAM
568    EndSlam = 6101,
569    /// Start Calibration
570    Calibrate = 6110,
571    /// Cancel Calibration
572    EndCalibrate = 6111,
573    /// Get the Current Calibration Result
574    CalibResult = 6112,
575    /// Get the Current Calibration Result
576    CalibAllinone2 = 6115,
577    /// Motor Enabling and Disabling
578    SetMotorEnable = 6201,
579    /// Unbind designate goods
580    ClearGoods = 6801,
581    /// Unbind Goods from Designated Containers
582    ClearContainer = 6802,
583    /// Unbind Goods from all Containers
584    ClearAllContainersGoods = 6803,
585    /// Bind Goods to Containers
586    SetContainerGoods = 6804,
587    /// Update transparent data
588    UpdateTransparentData = 6900,
589    /// Storage Bin Detection
590    BinDetect = 6901,
591    /// Replay
592    Replay = 6910,
593}
594
595#[derive(Debug, Clone, Copy, PartialEq, Eq)]
596#[repr(u16)]
597pub enum PushApi {
598    /// Set the Robot Push Port
599    Config = 9300,
600    /// Robot Push
601    Push = 19301,
602}