]> git.ipfire.org Git - thirdparty/HylaFAX.git/commitdiff
Dmitry's class1-general patch:
authorRobert Colquhoun <rjc@trump.net.au>
Wed, 7 Jun 2000 02:47:28 +0000 (02:47 +0000)
committerRobert Colquhoun <rjc@trump.net.au>
Wed, 7 Jun 2000 02:47:28 +0000 (02:47 +0000)
    - Decoding T.30 DIS Frame
    - HDLC Timeout
    - Numberof training attempts

...also fixed the modem soft rest stuff so that the correct delay is used.

faxd/Class1.c++
faxd/Class1Send.c++
faxd/ClassModem.c++
faxd/HDLCFrame.c++

index df643867a9c934ca3ec4f673745c6136809d276b..8473d0b31e6902ae165036152096b1a0d54c8385 100644 (file)
@@ -396,8 +396,7 @@ Class1Modem::abortReceive()
 }
 
 /*
- * Receive an HDLC frame.  The timeout is against
- * the receipt of the HDLC flags; the frame itself must
+ * Receive an HDLC frame. The frame itself must
  * be received within 3 seconds (per the spec).
  * If a carrier is received, but the complete frame
  * is not received before the timeout, the receive
@@ -408,20 +407,22 @@ Class1Modem::recvRawFrame(HDLCFrame& frame)
 {
     int c;
     /*
-     * Search for HDLC frame flags.  The
-     * timeout is to reception of the flags.
+     * The spec says that a frame that takes between
+     * 2.55 and 3.45 seconds to be received may be
+     * discarded; we also add some time for DCE
+     * to detect and strip flags. 
+     */
+    startTimeout(5000);
+    /*
+     * Strip HDLC frame flags. This is not needed,
+     * (according to the standard DCE does the job),
+     * be we leave this legacy code unchanged
+     * for sure - D.B.
      */
     do {
        c = getModemChar(0);
     } while (c != EOF && c != 0xff);
-    stopTimeout("waiting for HDLC flags");
-    if (c == 0xff) {                   // flags received
-       /*
-        * The spec says that a frame that takes between
-        * 2.55 and 3.45 seconds to be received may be
-        * discarded; we use 3.1 seconds as a compromise.
-        */
-       startTimeout(3100);
+    if (c == 0xff) {                   // address field received
        do {
            if (c == DLE) {
                c = getModemChar(0);
@@ -430,8 +431,8 @@ Class1Modem::recvRawFrame(HDLCFrame& frame)
            }
            frame.put(frameRev[c]);
        } while ((c = getModemChar(0)) != EOF);
-       stopTimeout("receiving HDLC frame data");
     }
+    stopTimeout("receiving HDLC frame data");
     if (wasTimeout()) {
        abortReceive();
        return (false);
@@ -638,8 +639,14 @@ Class1Modem::recvFrame(HDLCFrame& frame, long ms)
     frame.reset();
     startTimeout(ms);
     bool readPending = atCmd(rhCmd, AT_NOTHING);
-    if (readPending && waitFor(AT_CONNECT,0))
-       return recvRawFrame(frame);             // NB: stops inherited timeout
+    if (readPending && waitFor(AT_CONNECT,0)){
+        stopTimeout("waiting for HDLC flags");
+        if (wasTimeout()){
+            abortReceive();
+            return (false);
+        }
+        return recvRawFrame(frame);
+    }
     stopTimeout("waiting for v.21 carrier");
     if (readPending && wasTimeout())
        abortReceive();
index a2d636e733a21d6b134fc6961e81fe6b8a1ea5e2..16663d9015f83003682f2a470844cd2755561434 100644 (file)
@@ -103,9 +103,7 @@ Class1Modem::getPrologue(Class2Params& params, bool& hasDoc, fxStr& emsg)
     time_t start = Sys::now();
     HDLCFrame frame(conf.class1FrameOverhead);
 
-    startTimeout(conf.t2Timer);
     bool framerecvd = recvRawFrame(frame);
-    stopTimeout("receiving id frame");
     for (;;) {
        if (framerecvd) {
            /*
@@ -465,7 +463,16 @@ Class1Modem::sendTraining(Class2Params& params, int tries, fxStr& emsg)
         */
        params.br = curcap->br;
        dcs = (dcs &~ DCS_SIGRATE) | curcap->sr;
-       int t = 2;
+        /*
+        * Set the number of train attemps on the same
+        * modulation; having set it to 1 we immediately drop
+        * the speed if the training has been failed.
+        * This parameter is not specified by T.30
+        * (the algorith left implementation defined),
+        * so we choose the exact value according to our
+        * common sense.
+        */
+       int t = 1;
        do {
            protoTrace("SEND training at %s %s",
                modulationNames[curcap->mod],
@@ -540,7 +547,7 @@ Class1Modem::sendTraining(Class2Params& params, int tries, fxStr& emsg)
            pause(conf.class1TrainingRecovery);
        } while (--t > 0);
        /*
-        * Two attempts at the current speed failed, drop
+        * (t) attempts at the current speed failed, drop
         * the signalling rate to the next lower rate supported
         * by the local & remote sides and try again.
         */
@@ -846,6 +853,7 @@ Class1Modem::sendPPM(u_int ppm, HDLCFrame& mcf, fxStr& emsg)
            return (false);
     }
     emsg = "No response to MPS or EOP repeated 3 tries";
+    protoTrace(emsg);
     return (false);
 }
 
index 77cad3fd125a600d011f432be415126268295eee..de11b0bc98afe14dfbd202fafbf1a26eb97f84a4 100644 (file)
@@ -130,8 +130,6 @@ ClassModem::ClassModem(ModemServer& s, const ModemConfig& c)
     // XXX: workaround yet another GCC bug (sigh)
     const fxStr& flow = conf.getFlowCmd(conf.flowControl);
     resetCmds = "AT"
-             | stripAT(conf.softResetCmd)
-             | "\nAT"
              | stripAT(conf.resetCmds)         // prepend to insure our needs
              | stripAT(conf.echoOffCmd)
              | stripAT(conf.verboseResultsCmd)
@@ -649,10 +647,17 @@ ClassModem::reset(long ms)
      */
     server.reopenDevice();
 #endif
-    if (!setBaudRate(rate, iFlow, oFlow))
-       return (false);
+    if (!setBaudRate(rate, iFlow, oFlow)) {
+        return (false);
+    }
     flushModemInput();
-    return atCmd(resetCmds, AT_OK, ms);
+    /*
+     * Perform a soft reset as well to ensure the modem
+     * is in a stable state before sending the additional
+     * reset commands.
+     */
+    return atCmd(conf.softResetCmd, AT_OK, conf.resetDelay)
+            && atCmd(resetCmds, AT_OK, ms);
 }
 
 bool
index e6c7cf1f72baa402def4e02f33be8e60093df8b8..f38366e26671358b0614ed087e5babac84e4e38b 100644 (file)
@@ -105,10 +105,10 @@ u_int
 HDLCFrame::getDataWord() const
 {
     u_int n = getFrameDataLength();
-    u_int w = (n > 1) ? (*this)[3] : 0;
-    if (n > 2) w = (w<<8)|(*this)[4];
-    if (n > 3) w = (w<<8)|(*this)[5];
-    if (n > 4) w = (w<<8)|(*this)[6];
+    u_int w = (n >= 1) ? (*this)[3] : 0;
+    if (n >= 2) w = (w<<8)|(*this)[4];
+    if (n >= 3) w = (w<<8)|(*this)[5];
+    if (n >= 4) w = (w<<8)|(*this)[6];
     return w;
 }
 
@@ -116,9 +116,9 @@ u_int
 HDLCFrame::getDIS() const
 {
     u_int n = getFrameDataLength();
-    u_int dis = (n > 1) ? (*this)[3] : 0;
-    dis <<= 8; if (n > 2) dis |= (*this)[4];
-    dis <<= 8; if (n > 3) dis |= (*this)[5];
+    u_int dis = (n >= 1) ? (*this)[3] : 0;
+    dis <<= 8; if (n >= 2) dis |= (*this)[4];
+    dis <<= 8; if (n >= 3) dis |= (*this)[5];
     return dis;
 }
 
@@ -126,9 +126,9 @@ u_int
 HDLCFrame::getXINFO() const
 {
     u_int n = getFrameDataLength();
-    u_int xinfo = (n > 4 && ((*this)[5] & 0x1)) ? (*this)[6] : 0;
-    xinfo <<= 8; if (n > 5 && (xinfo & 0x100)) xinfo |= (*this)[7];
-    xinfo <<= 8; if (n > 6 && (xinfo & 0x100)) xinfo |= (*this)[8];
-    xinfo <<= 8; if (n > 7 && (xinfo & 0x100)) xinfo |= (*this)[9];
+    u_int xinfo = (n >= 4 && ((*this)[5] & 0x1)) ? (*this)[6] : 0;
+    xinfo <<= 8; if (n >= 5 && (xinfo & 0x100)) xinfo |= (*this)[7];
+    xinfo <<= 8; if (n >= 6 && (xinfo & 0x100)) xinfo |= (*this)[8];
+    xinfo <<= 8; if (n >= 7 && (xinfo & 0x100)) xinfo |= (*this)[9];
     return xinfo;
 }