Article View: cu.slug
Article #514A modern modem flavor
From: Daniel Finster
Date: Sat, 03 Feb 1996 00:00
Date: Sat, 03 Feb 1996 00:00
71 lines
4108 bytes
4108 bytes
This defines a v.32-bis modem, with a complete set of numeric and
verbose result codes. In addition, it also allows arbitrary commands
to be sent to the modem, instead of just numbers (example:
"DIAL|DIAL|X5V1&WD5551212").
I hope someone else out there finds this useful.
1;;; -*- Package: DIAL; Base: 10; Syntax: Common-Lisp -*-
0(defflavor 2v.32bis-modem0 () (2modem0)
(:mixture
(:rubout-escaping
(t serial-rubout-escape-translating-stream)
(nil serial-no-translation-stream))))
(define-modem-type :v.32bis v.32bis-modem t)
(defun-in-flavor 2(V.32BIS-MODEM-COMMAND v.32bis-modem)0 (2timeout0 2whostate0 2expected-response0 2string0 1&rest0 2args0)
(when string
(lexpr-funcall #'format (si:thin-character-stream self) string args)
(send self :tyo (ascii-code :cr))
(send self :finish)
(let* ((2echo0 (modem-read-response-line self "Read echo of command" timeout t))
(2at-start0 (string-search "AT" echo)))
(unless (and (not (string-equal "" echo)) at-start (zerop at-start))
(error 'modem-bad-response ':response echo)))
(loop for 2response0 = (modem-read-response-line self (or whostate "v.32bis Command") timeout t)
until (if (listp expected-response)
(loop for 2er0 in expected-response
thereis (string-equal response er))
(string-equal response expected-response))
unless (string-equal response "")
do (if expected-response
(selector response string-equal
(("2" "RING") (error 'modem-bad-response :response "Incoming RING detected."))
(("3" "NO CARRIER") (error 'modem-call-refused :foreign-host host :connection self :reason "No carrier."))
(("4" "ERROR") (ferror "Programming error talking to v.32bis modem."))
(("6" "NO DIALTONE") (error 'modem-call-refused :foreign-host host :connection self :reason "No dial tone."))
(("7" "BUSY") (error 'modem-call-refused :foreign-host host :connection self :reason "Busy."))
(("8" "NO ANSWER") (error 'modem-call-refused :foreign-host host :connection self :reason "No answer."))
(otherwise (error 'modem-bad-response ':response response)))
(return response)))))
(defvar 2*v.32bis-command-timeout*0 (* 60 60)
"60ths of a second to wait for response from modem.")
(defvar 2*extended-connect-result-codes*0 '(nil)
"Numeric and verbal result codes supported, in addition to CONNECT (1).")
(defmethod 2(:DIAL-THE-PHONE v.32bis-modem)0 (1&aux0 2succeeded0)
(error-restart (error "Redial call to ~A." host)
(send self ':ensure-open)
(unwind-protect
(progn
(send self :clear-input)
(v.32bis-modem-command *v.32bis-command-timeout* (format nil "Dialing ~A" phone-number)
`("0" "OK"
"1" "CONNECT" 1; Use X5 result codes and this will win.
0 ,@*extended-connect-result-codes*)
1;; Allow random commands to be inserted before the phone number.
0 "AT~A" (if (numberp (read-from-string phone-number))
(string-append "D" phone-number)
phone-number))
(setf 2succeeded0 t))
(if succeeded
(send self :put :data-terminal-ready t :request-to-send t :rts-cts-protocol t)
(send self :close :abort)))))
(compile-flavor-methods v.32bis-modem)
(export '(*v.32bis-command-timeout* *extended-connect-result-codes*))
Technical Details
Message-ID:
<823343357.7258@news.Colorado.EDU>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10077e,9f16a9a14411d9ee,start
X-Google-Attributes: gid10077e,public
From: Daniel Finster <DF@SDF.LONESTAR.ORG>
Subject: A modern modem flavor
Date: 1996/02/03
Message-ID: <823343357.7258@news.Colorado.EDU>
X-Deja-AN: 138009759
distribution: cu
sender: daemon@peabody.colorado.edu
character-type-mappings: (1 0 (NIL 0) (NIL :ITALIC NIL) "CPTFONTI")
fonts: CPTFONT, CPTFONTI, CPTFONTCB
x-note1: message-id generated by recnews
x-note2: mail msgid was <m0tiS7B-0000SJC@SDF.LONESTAR.ORG>
organization: University of Colorado at Boulder
(2 0 (nil 0) (nil : BOLD NIL) "CPTFONTCB")
reply-to: <DF@SDF.LONESTAR.ORG>
newsgroups: cu.slug