/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */ /* * main.c * Copyright (C) 2015 alexey * * ttyptt is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ttyptt is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ #include #include #include #include int PTTport,level = 0; // set RTS level, return -1 if error // termios.h int set_RTS(int level, int *fd) { int serline; ioctl (*fd, TIOCMGET, &serline); if (level == 1) { serline |= TIOCM_RTS; return ioctl (*fd, TIOCMSET, &serline); } if (level == 0) { serline &= ~TIOCM_RTS; return ioctl (*fd, TIOCMSET, &serline); } return -1; } int openserial(char *serial) { PTTport = open(serial, O_RDWR | O_NOCTTY | O_NONBLOCK | O_NDELAY); if (PTTport <0) { perror(serial); printf("error open device [%s]\n\n",serial); return -1; } return 1; } int main(int argc, char *argv[]) { if (argc == 1) { printf("\nuse like ttyptt /dev/ttyPTT X (X=0 - set PTT-RTS off, X=1 - PTT-RTS ON)\n\n"); return(0); } if (openserial(argv[1]) < 1) return -1; if (*argv[2]=='1') level=1; else level=0; set_RTS(level,&PTTport); return (0); }