⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 modemutil.h

📁 VoiFax is a program that manage voice/data/fax modem in the same manner of vgetty and mgetty.VoiFax
💻 H
字号:
/*  voifax low level modem interface library *  Copyright (C) 2004  Simone Freddio & Andrea Emanuelli * *  This program 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 2 of the License, or *  (at your option) any later version. * *  This program 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, write to the Free Software *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */#ifndef MODEMUTIL_H#define MODEMUTIL_H#include <sys/time.h>#include "common.h"#define MODEM_MAX_HANDLERS	10typedef int t_callback(char *);		/* funzione callback per la gestione degli																		 eventi, deve tornare true. In caso di 																		 false viene interrotta la ricezione dati																		 e generato un errore grave.							*/typedef struct{	t_callback	*callback;		/* puntatore al gestore di evento									*/	char				str[20];			/* stringa successiva al DLE da interpretare come															 evento																					*/	int					len;					/* lunghezza stringa (per ottimizzazione)					*/	int					arg_chars;		/* numero di caratteri da passare all'handler			*/} t_event_handler;typedef struct{	char							dev[100];							/* device del modem, ad es. "ttyS0" */	char							full_dev[100];				/* nome device completo, ad es. 																						 "/dev/ttyS0"											*/	int								r_fd;									/* read file descriptor							*/	int								w_fd;									/* write file descriptor						*/	struct timeval		response_timeout;			/* tempo massimo per l'attesa di																						 ogni pacchetto dal modem					*/	int								response_initialsleep;/* ritardo iniziale per la ricezione																						 di un pacchetto									*/	t_event_handler		handlers[MODEM_MAX_HANDLERS];																					/* gestori degli eventi in ricezione*/	int								baudrate;	int								baudrate_const;	int								retries;	int								seek_end;} t_modem;/************//* Funzioni	*//************/int modem_init(t_modem *modem, char *dev);/*		Inizializza il modem dev e riempie la struttura modem. Attualmente la 		velocita' della seriale, i tempi di timeout ecc. sono impostati 		arbitrariamente.		Le impostazioni della seriale ammesse dal sistema operativo sono molto 		varie e permettono di fare una prima manipolazione dei dati		TODO: DA VEDERE!!!		(o)	modem		struttura con i dati del modem		(i)	dev			device di collegamento del modem, deve essere nella forma "ttyXX"		Valori di ritorno:	true	= inizializzazione ok	 											false	= errore di inizializzazione*/int modem_close(t_modem *modem);/*		Chiude il modem specificato		(i)	modem		struttura con i dati del modem		Valori di ritorno:	true	= chiusura modem ok												false	= errore nella chiusura*/int modem_sendcmd(t_modem *modem, char *cmd);/*		Invia un comando al modem specificato		(i)	modem		struttura con i dati del modem		(i)	cmd			comando da inviare, deve essere nella forma "ATI3", il carattere								<CR> viene aggiunto dalla funzione		Valori di ritorno:	true	= comando inviato												false	= errore scrittura o canale interrotto*/int modem_receiveresp(t_modem *modem, char *buf, int maxlen, int clean_resp);/*		Riceve un response dal modem		(i)	modem				struttura con i dati del modem		(o)	buf					il buffer di uscita		(i)	maxlen			lunghezza massima del buffer di uscita		(i)	clean_resp	se true, la funzione rimuove i caratteri <CR> e <LF> dal										buffer di uscita		Valori di ritorno:	-1	= errore grave												<n>	= numero di bytes effettivamente letti dal modem*/int modem_chat(t_modem *modem, char *cmd, char *resp);/*		Controlla che il comando cmd abbia avuto response resp dal modem; il 		response ricevuto dal modem viene pulito dai caratteri <CR> e <LF>		(i)	modem		struttura con i dati del modem		(i)	cmd			comando da inviare al modem		(i)	resp		response da controllare, nella forma "OK" o "ERROR"		Valori di ritorno:	-1		= errore grave												true	= il response ricevuto dal modem e' quello 																previsto												false	= il response ricevuto differisce da quello																previsto*/int modem_chat_timeout(	t_modem *modem, char *cmd, char *resp, 												int sec, int usec);/*		Come la precedente, ma usa un timeout massimo per il response specificato		in sec e usec.		(i)	modem		struttura con i dati del modem		(i)	cmd			comando da inviare al modem		(i)	resp		response da controllare, nella forma "OK" o "ERROR"		(i) sec			numero di secondi di timeout		(i)	usec		numero di microsecondi di timeout		Valori di ritorno:	-1		= errore grave												true	= il response ricevuto dal modem e' quello 																previsto												false	= il response ricevuto differisce da quello																previsto*/int modem_add_handler(t_modem			*modem,											t_callback	*callback,											char				*str,											int					chars_to_get);/*		Aggiunge un handler alla lista di quelli disponibili per i dati in ingresso.		(i/o)	modem					struttura con i dati del modem		(i)		callback			puntatore alla funzione callback		(i)		str						stringa identificativa dell'evento		(i)		chars_to_get	numero di caratteri successivi all'evento da passare												alla funzione handler		Valori di ritorno:	true	= handler aggiunto												false	=	errore*/int modem_remove_handler(t_modem *modem, t_callback *callback);/*		Rimuove un handler dalla lista di quelli disponibili		(i/o)	modem					struttura con i dati del modem		(i)		callback			puntatore alla funzione callback		Valori di ritorno:	true	= handler rimosso												false	=	errore*/#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -