Skip to content

Commit

Permalink
updating to krec-rs
Browse files Browse the repository at this point in the history
  • Loading branch information
hatomist committed Nov 22, 2024
1 parent 9b2368a commit 7b1c58d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 25 deletions.
3 changes: 2 additions & 1 deletion kos_core/src/services/krec_logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ impl TelemetryLogger {
action: String,
output_path: impl AsRef<Path>,
robot_name: String,
robot_serial: String,
) -> Result<Self> {
// Setup MQTT client
let mut mqtt_options = MqttOptions::new("kos-telemetry-logger", "localhost", 1883);
Expand All @@ -37,7 +38,7 @@ impl TelemetryLogger {
uuid,
task: action,
robot_platform: robot_name.clone(),
robot_serial: String::new(), // Add if available
robot_serial: robot_serial.clone(),
start_timestamp: std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)?
.as_nanos() as u64,
Expand Down
44 changes: 21 additions & 23 deletions platforms/kbot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,8 @@ impl Platform for KbotPlatform {
operations_service: Arc<OperationsServiceImpl>,
) -> Result<Vec<ServiceEnum>> {
if cfg!(target_os = "linux") {
let robot_name = format!("KBot-{}", self.serial());

// Create the process manager first and handle any errors
let process_manager = KBotProcessManager::new(robot_name)
let process_manager = KBotProcessManager::new(self.name().to_string(), self.serial())
.wrap_err("Failed to initialize GStreamer process manager")?;

Ok(vec![
Expand All @@ -71,26 +69,26 @@ impl Platform for KbotPlatform {
)),
),
),
ServiceEnum::Actuator(ActuatorServiceServer::new(ActuatorServiceImpl::new(
Arc::new(
KBotActuator::new(
operations_service,
"/dev/ttyCH341USB0",
HashMap::from([
(1, MotorType::Type04),
(2, MotorType::Type04),
(3, MotorType::Type04),
(4, MotorType::Type04),
(5, MotorType::Type04),
(6, MotorType::Type01),
]),
None,
None,
None,
)
.wrap_err("Failed to create actuator")?,
),
))),
// ServiceEnum::Actuator(ActuatorServiceServer::new(ActuatorServiceImpl::new(
// Arc::new(
// KBotActuator::new(
// operations_service,
// "/dev/ttyCH341USB0",
// HashMap::from([
// (1, MotorType::Type04),
// (2, MotorType::Type04),
// (3, MotorType::Type04),
// (4, MotorType::Type04),
// (5, MotorType::Type04),
// (6, MotorType::Type01),
// ]),
// None,
// None,
// None,
// )
// .wrap_err("Failed to create actuator")?,
// ),
// ))),
ServiceEnum::ProcessManager(ProcessManagerServiceServer::new(
ProcessManagerServiceImpl::new(Arc::new(process_manager)),
)),
Expand Down
5 changes: 4 additions & 1 deletion platforms/kbot/src/process_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,19 @@ pub struct KBotProcessManager {
pipeline: Mutex<Option<gst::Pipeline>>,
telemetry_logger: Mutex<Option<TelemetryLogger>>,
robot_name: String,
robot_serial: String,
}

impl KBotProcessManager {
pub fn new(robot_name: String) -> Result<Self> {
pub fn new(robot_name: String, robot_serial: String) -> Result<Self> {
gst::init().wrap_err("Failed to initialize GStreamer")?;

Ok(KBotProcessManager {
kclip_uuid: Mutex::new(None),
pipeline: Mutex::new(None),
telemetry_logger: Mutex::new(None),
robot_name,
robot_serial,
})
}

Expand Down Expand Up @@ -210,6 +212,7 @@ impl ProcessManager for KBotProcessManager {
action,
format!("telemetry_{}.kclip", new_uuid),
self.robot_name.clone(),
self.robot_serial.clone(),
)
.await?;

Expand Down

0 comments on commit 7b1c58d

Please sign in to comment.