diff options
-rw-r--r-- | build.rs | 1 | ||||
-rw-r--r-- | src/kissattach.c | 105 | ||||
-rw-r--r-- | src/lib.rs | 2 | ||||
-rw-r--r-- | src/main.rs | 8 |
4 files changed, 107 insertions, 9 deletions
@@ -8,7 +8,6 @@ fn main() { .file("src/kissattach.c") .compile("kissattach"); - println!("cargo:rustc-link-lib=ax25"); /* .file("bar.c") diff --git a/src/kissattach.c b/src/kissattach.c index 74d4efb..c39923d 100644 --- a/src/kissattach.c +++ b/src/kissattach.c @@ -20,12 +20,109 @@ #include <net/if.h> #include <netax25/ax25.h> -#include <netrose/rose.h> -#include <netax25/daemon.h> -#include <netax25/axlib.h> -#include <netax25/ttyutils.h> +#define FALSE 0 +#define TRUE 1 + +static struct speed_struct { + int user_speed; + speed_t termios_speed; +} speed_table[] = { + {300, B300}, + {600, B600}, + {1200, B1200}, + {2400, B2400}, + {4800, B4800}, + {9600, B9600}, + {19200, B19200}, + {38400, B38400}, +#ifdef B57600 + {57600, B57600}, +#endif +#ifdef B115200 + {115200, B115200}, +#endif +#ifdef B230400 + {230400, B230400}, +#endif +#ifdef B460800 + {460800, B460800}, +#endif + {-1, B0} +}; + +static int tty_speed(int fd, int speed) +{ + struct termios term; + struct speed_struct *s; + + for (s = speed_table; s->user_speed != -1; s++) + if (s->user_speed == speed) + break; + + if (s->user_speed == -1) { + fprintf(stderr, "tty_speed: invalid speed %d\n", speed); + return FALSE; + } + + if (tcgetattr(fd, &term) == -1) { + perror("tty_speed: tcgetattr"); + return FALSE; + } + + cfsetispeed(&term, s->termios_speed); + cfsetospeed(&term, s->termios_speed); + + if (tcsetattr(fd, TCSANOW, &term) == -1) { + perror("tty_speed: tcsetattr"); + return FALSE; + } + + return TRUE; +} +static int ax25_aton_entry(const char *name, char *buf) +{ + int ct = 0; + int ssid = 0; + const char *p = name; + char c; + + while (ct < 6) { + c = toupper(*p); + + if (c == '-' || c == '\0') + break; + + if (!isalnum(c)) { + printf("axutils: invalid symbol in callsign '%s'\n", name); + return -1; + } + + buf[ct] = c << 1; + + p++; + ct++; + } + + while (ct < 6) { + buf[ct] = ' ' << 1; + ct++; + } + + if (*p != '\0') { + p++; + + if (sscanf(p, "%d", &ssid) != 1 || ssid < 0 || ssid > 15) { + printf("axutils: SSID must follow '-' and be numeric in the range 0-15 - '%s'\n", name); + return -1; + } + } + + buf[6] = ((ssid + '0') << 1) & 0x1E; + + return 0; +} static int setifcall(int fd, char *name) { @@ -4,4 +4,4 @@ extern crate spidev; extern crate sysfs_gpio; pub mod rfm95; -pub mod kiss; +//pub mod kiss; diff --git a/src/main.rs b/src/main.rs index 9073975..134ee11 100644 --- a/src/main.rs +++ b/src/main.rs @@ -39,13 +39,15 @@ fn create_pts_pair() -> std::io::Result<File> { } fn main() { - println!("Creating PTY pair"); + eprintln!("Creating PTY pair"); let master_file = match create_pts_pair() { Ok(fd) => fd, Err(e) => panic!("create_pts_pair failed: {}", e) }; + eprintln!("PTS master: {:?}", master_file); + let slavename; unsafe { slavename = libc::ptsname(master_file.as_raw_fd()); @@ -56,7 +58,7 @@ fn main() { } unsafe { let slice = CStr::from_ptr(slavename); - println!("PTS slave: {:?}", slice); + eprintln!("PTS slave: {:?}", slice); } match RF95::new(Bandwidth::Bw250, CodingRate::Cr8, SpreadingFactor::Sf10) { @@ -67,7 +69,7 @@ fn main() { println!("Device version: {:02x}", ver); } else { - println!("Cannot read device version"); + eprintln!("Cannot read device version"); } }, Err(e) => panic!("Cannot create lora radio object, {}", e) |