]> git.rkrishnan.org Git - pihpsdr.git/commitdiff
rustify send_resp() in rigctl.c rust-new
authorRamakrishnan Muthukrishnan <ram@rkrishnan.org>
Thu, 10 Aug 2023 09:15:14 +0000 (14:45 +0530)
committerRamakrishnan Muthukrishnan <ram@rkrishnan.org>
Thu, 10 Aug 2023 09:15:14 +0000 (14:45 +0530)
rigctl.c
rust/src/rigctl.rs

index 6024661895999e160008b9f4eb802990bcd68c8d..10dde25299f4f529d7b0d1ccce03e4504e747966 100644 (file)
--- a/rigctl.c
+++ b/rigctl.c
@@ -59,6 +59,8 @@
 #endif
 #include <math.h>
 
+#include "libhpsdr.h"
+
 #define NEW_PARSER
 
 // IP stuff below
@@ -661,19 +663,6 @@ long long rigctl_getFrequency() {
     return vfo[active_receiver->id].frequency;
   }
 }
-// Looks up entry INDEX_NUM in the command structure and
-// returns the command string
-//
-void send_resp(int fd, char *msg) {
-  if (rigctl_debug)
-    g_print("RIGCTL: RESP=%s\n", msg);
-  int length = strlen(msg);
-  int written = 0;
-
-  while (written < length) {
-    written += write(fd, &msg[written], length - written);
-  }
-}
 
 //
 // 2-25-17 - K5JAE - removed duplicate rigctl
@@ -770,7 +759,7 @@ static gpointer rigctl_client(gpointer data) {
   g_mutex_lock(&mutex_a->m);
   cat_control++;
   if (rigctl_debug)
-    g_print("RIGCTL: CTLA INC cat_contro=%d\n", cat_control);
+    g_print("RIGCTL: CTLA INC cat_control=%d\n", cat_control);
   g_mutex_unlock(&mutex_a->m);
   g_idle_add(ext_vfo_update, NULL);
 
index 8aea534e7f27b340d1418b04a63b6856c938f9cf..5832cfc51ca59b3fc8be80cab0fe264f8421e17b 100644 (file)
@@ -1,4 +1,4 @@
-use std::os::fd::FromRawFd;
+use std::os::fd::{FromRawFd, IntoRawFd};
 use std::{fs::File, io::Write};
 use std::slice;
 use libc::{write, c_int, c_char};
@@ -8,6 +8,8 @@ pub extern "C" fn send_resp(fd: c_int, msg: *const c_char) -> () {
     let mut f: File = unsafe { File::from_raw_fd(fd) };
     let cstr = unsafe { std::ffi::CStr::from_ptr(msg) };
     let buf: &[u8] = cstr.to_bytes();
+    println!("send_resp: {}", std::str::from_utf8(buf).unwrap());
     let _ = f.write_all(buf);
+    let _ = f.into_raw_fd(); // this is so that fd is not closed
     ()
 }