syntax = "proto3";

package cmvr.msgs;

message SdoFrame {
  uint32 node_id = 1;            // 节点ID
  CommandSpecifier cs = 2;  // SDO命令字
  ObIndex index = 3;              // 对象字典索引
  ObSubIndex sub_index = 4;          // 子索引
  uint32 data = 5;                // 数据区
}

enum PdoBaseId{

  PDO_BASE_ID_UNSPECIFIED = 0;

  RPDO1_BASE_ID_200 = 0x200;
  RPDO2_BASE_ID_300 = 0x300;
  RPDO3_BASE_ID_400 = 0x400;
  RPDO4_BASE_ID_500 = 0x500;


  TPDO1_BASE_ID_180 = 0x180;
  TPDO2_BASE_ID_280 = 0x280;
  TPDO3_BASE_ID_380 = 0x380;
  TPDO4_BASE_ID_480 = 0x480;
}

// PDO 传输类型
enum TransmissionType {

  // 同步传输
  SYNC_EVENT_DRIVEN = 0x00;   // 非循环同步
  SYNC_CYCLIC = 0x01;         // 循环同步

  // 远程请求触发
  REMOTE_SYNC = 0xFC;         // 远程同步
  REMOTE_ASYNC = 0xFD;        // 远程异步

  // 异步传输
  ASYNC_MANUFACTURER_SPECIFIC = 0xFE; // 异步，制造商特定事件
  ASYNC_DEVICE_SPECIFIC = 0xFF;       // 异步，设备子协议特定事件
}



enum CommandSpecifier {
  CS_NO = 0;                          // 默认无效
  CS_WRITE_ONE_BYTE = 0x2F;          // 写 1 字节
  CS_WRITE_TWO_BYTES = 0x2B;         // 写 2 字节
  CS_WRITE_THREE_BYTES = 0x27;       // 写 3 字节
  CS_WRITE_FOUR_BYTES = 0x23;        // 写 4 字节
  CS_WRITE_SUCCESS_RESPONSE = 0x60;  // 写成功响应

  CS_READ_REQUEST = 0x40;                    // 发起读取请求
  CS_READ_RESPONSE_ONE_BYTE = 0x4F; // 响应 1 字节
  CS_READ_RESPONSE_TWO_BYTES = 0x4B;// 响应 2 字节
  CS_READ_RESPONSE_THREE_BYTES = 0x47;
  CS_READ_RESPONSE_FOUR_BYTES = 0x43;

  CS_EXCEPTION_RESPONSE = 0x80;     // 异常响应
}




enum NmtState {
  // 0x00 - 正在初始化（Initializing）
  NMT_INITIALIZING = 0x00;

  // 0x01 - 未连接 / 应用复位（Reset Application）
  NMT_RESET_APPLICATION = 0x01;

  // 0x02 - 正在连接（Connecting）
  NMT_CONNECTING = 0x02;

  // 0x03 - 准备（Preparing）
  NMT_PREPARING = 0x03;

  // 0x04 - 停止状态（Stopped），开启 SDO，关闭 PDO
  NMT_STOPPED = 0x04;

  // 0x05 - 运行状态（Operational），开启 SDO、PDO、NMT
  NMT_OPERATIONAL = 0x05;

  // 0x7F - 预运行状态（Pre-Operational），开启 SDO，关闭 PDO
  NMT_PRE_OPERATIONAL = 0x7F;
}



enum NmtCommand {
  // 未指定命令
  NMT_COMMAND_UNSPECIFIED = 0x00;

  // 0x01 - 启动远程节点（Start Remote Node）
  NMT_START_REMOTE_NODE = 0x01;

  // 0x02 - 停止远程节点（Stop Remote Node）
  NMT_STOP_REMOTE_NODE = 0x02;

  // 0x80 - 进入预操作状态（Enter Pre-Operational）
  NMT_ENTER_PRE_OPERATIONAL = 0x80;

  // 0x81 - 复位节点（Reset Node）
  NMT_RESET_NODE = 0x81;

  // 0x82 - 复位通信（Reset Communication）
  NMT_RESET_COMMUNICATION = 0x82;
}


// 索引
enum ObIndex {
  INDEX_ZERO = 0;
  USER_SAVE_PARA_2000 = 0x2000;         // 下发命令 1 保存参数
  POSITION_OFFSET_2008 = 0x2008;  // 位置偏移，子索引 0x00，用于设置零点、起始位置
  // Error Codes
  ERROR_CODE_6007 = 0x6007;
  ERROR_CODE_603F = 0x603F;

  // Control and Status
  CONTROL_WORD_6040 = 0x6040;
  STATUS_WORD_6041 = 0x6041;

  // Operation Modes
  OPERATION_MODE_6060 = 0x6060;
  MODE_DISPLAY_6061 = 0x6061;

  // Actual Values
  ACTUAL_POSITION_6064 = 0x6064;
  ACTUAL_SPEED_606C = 0x606C;
  ACTUAL_CURRENT_6078 = 0x6078;

  // Torque-related
  TARGET_TORQUE_6071 = 0x6071;
  MAX_TORQUE_6072 = 0x6072;
  DEMAND_TORQUE_6074 = 0x6074;

  // Position-related
  TARGET_POSITION_607A = 0x607A;
  SOFTWARE_POSITION_LIMIT_607D = 0x607D;  // Sub-indexes: 1, 2

  // Speed-related
  MAX_SPEED_607F = 0x607F;
  PROFILE_SPEED_6081 = 0x6081;
  PROFILE_ACCELERATION_6083 = 0x6083;
  PROFILE_DECELERATION_6084 = 0x6084;

  // Same as DEMAND_TORQUE? Verify correctness.
  //  TORQUE_SLOPE_6074 = 0x6074;

  // PID Control
  CURRENT_LOOP_PID_60F6 = 0x60F6;  // Sub-indexes: 1, 2
  SPEED_LOOP_PID_60F9 = 0x60F9;    // Sub-indexes: 1, 2
  POSITION_LOOP_PID_60FB = 0x60FB;  // Sub-indexes: 1, 2, 3

  // Target Speed
  TARGET_SPEED_60FF = 0x60FF;

  QUICK_STOP_OPTION_605A = 0x605A;
  QUICK_STOP_DECEL_6085 = 0x6085;

  // -------------------------
  // PDO 通信参数对象（Communication Object）
  RPDO1_COMM_1400 = 0x1400;
  RPDO2_COMM_1401 = 0x1401;
  RPDO3_COMM_1402 = 0x1402;
  RPDO4_COMM_1403 = 0x1403;

  TPDO1_COMM_1800 = 0x1800;
  TPDO2_COMM_1801 = 0x1801;
  TPDO3_COMM_1802 = 0x1802;
  TPDO4_COMM_1803 = 0x1803;

  // PDO 映射对象（Mapping Object）
  RPDO1_MAP_1600 = 0x1600;
  RPDO2_MAP_1601 = 0x1601;
  RPDO3_MAP_1602 = 0x1602;
  RPDO4_MAP_1603 = 0x1603;

  TPDO1_MAP_1A00 = 0x1A00;
  TPDO2_MAP_1A01 = 0x1A01;
  TPDO3_MAP_1A02 = 0x1A02;
  TPDO4_MAP_1A03 = 0x1A03;

  PRODUCER_HEARTBEAT_TIME = 0x1017;
}

// 子索引
enum ObSubIndex {
  SUB_INDEX_0 = 0;
  SUB_INDEX_1 = 1;
  SUB_INDEX_2 = 2;
  SUB_INDEX_3 = 3;
  SUB_INDEX_4 = 4;
  SUB_INDEX_5 = 5;
  SUB_INDEX_6 = 6;
  SUB_INDEX_7 = 7;
}


