Logo Search packages:      
Sourcecode: icomlib version File versions  Download package

PComm::resetCall (  )  [private]

resets the radio and port

This function reset's the radio and the port when called. It is necessary to reset the radio after a certain number of read() and write()'s. In this case we have made it after 200 write() calls.

It closes the port, and reopens the port. Zero's out the call buffer, and copy's the poweron/ecmd command strings into the call buffer. It then select()'s to see if we are ready to write to the buffer. After which it writes to the radio to tell it, that we are back online and want it to come up. Then it bzero's the call buffer and reads what the radio has to say. It loops in that mode if it received only one character of data (the radio likes to send nothing but newlines sometimes) AND the number of loops is less than 10. We dont want to get stuck there.

Warning: this function is necessary for the radio to operate properly under the manual update mode. If you override this function make sure to run the radio in auto-update mode.

See also:
countCall()

Definition at line 496 of file pcomm.cpp.

References callBuf, callCount, fd, FDSet, PCClose(), PCOpen(), pcrDevice, pcrSpeed, and timeOut.

Referenced by countCall().

{
#ifdef DEBUG_VER_2
      fprintf(stderr, "PCOMM: resetCall() @ %d \n", callCount);
#endif DEBUG_VER_2
      callCount=0;
      int __readCounter=0;
      int __loopbreaker=0;
      
      PCClose();
      PCOpen(pcrDevice, pcrSpeed);
      bzero(callBuf, sizeof(callBuf));
      strncpy(callBuf, PCRPWRON, sizeof(callBuf)-1);
      strncat(callBuf, PCRECMD,  ((sizeof(callBuf))-(strlen(callBuf))-1));
      if (select(fd+1, NULL, FDSet, NULL, timeOut)) {
        write(fd, callBuf, strlen(callBuf));
            if (select(fd+1, NULL, FDSet, NULL, timeOut)) {
                bzero(callBuf, sizeof(callBuf));
                while ((__readCounter==1) && (__loopbreaker<10)) {
                    __readCounter = read(fd, callBuf, sizeof(callBuf));
                    __loopbreaker++;
                }
#ifdef DEBUG_VER_
          } else {
             // we should never have gotten here, if so, we are fubar'd
             // and should abort the program
            fprintf(stderr, "Read failed in PCOMM: resetCall()");
            fprintf(stderr, "***UNRECOVERABLE ERROR***");
            abort();
#endif // DEBUG_VER_
          }
#ifdef DEBUG_VER_
      } else {
          // we should never have gotten here, if so, we are fubar'd
          // and should abort the program
            fprintf(stderr, "Write failed in PCOMM: resetCall()");
      fprintf(stderr, "***UNRECOVERABLE ERROR***");
      abort();
#endif // DEBUG_VER_
      }
}


Generated by  Doxygen 1.6.0   Back to index