home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / me100.zip / ModemEngine.hpp < prev    next >
Text File  |  1996-06-22  |  7KB  |  163 lines

  1. //+----------------------------------------------------------------------------+
  2. //| MODEMENGINE.HPP                                                            |
  3. //|                                                                            |
  4. //| COPYRIGHT:                                                                 |
  5. //| ----------                                                                 |
  6. //|  Copyright (C) Sacha Prins, 1995, 1996.                                    |
  7. //|                                                                            |
  8. //| DISCLAIMER OF WARRANTIES:                                                  |
  9. //| -------------------------                                                  |
  10. //|  The following [enclosed] code is code created by Sacha Prins.             |
  11. //|  The code is provided "AS IS", without warranty of any kind. Sacha Prins   |
  12. //|  shall not be liable for any damages arising out of your use of the        |
  13. //|  [enclosed] code.                                                          |
  14. //|                                                                            |
  15. //| REVISION LEVEL: 1.0                                                        |
  16. //| ---------------                                                            |
  17. //|    22-jun-1996: Initial release to the public                              |
  18. //+----------------------------------------------------------------------------+
  19. #ifndef __MODEM_ENGINE__HPP__
  20. #define __MODEM_ENGINE__HPP__
  21.  
  22. #define INCL_DOSSEMAPHORES
  23. #define INCL_DOSFILEMGR
  24. #define INCL_DOSDEVIOCTL
  25. #define INCL_DOSDEVICES
  26. #define INCL_DOSPROCESS
  27. #define INCL_DOSSESMGR
  28. #define INCL_DOSQUEUES
  29. #define INCL_DOSERRORS
  30. #include <os2.h>
  31.  
  32. #define AT              "AT"
  33. #define RETURN          13
  34. #define PLAYEND         " "
  35.  
  36. //*****************************************************
  37. // CLASS definition MODEM_ENGINE
  38. //*****************************************************
  39. class MODEM_ENGINE {
  40.  
  41.    public:
  42.  
  43.         enum STATE { idle=0, Vcon, connected };
  44.         enum CONNECTSTATE { transmit=0, receive };
  45.         enum BITRANGE { two=2, three, four, eight };
  46.         enum LINE { line=0, phone, speaker, mic, lineMonitor };
  47.         enum _MODEMRESPONSE {   ok=0, connect, ring, no_carrier, error, no_dialtone=6, busy,
  48.                                 none=100, unknown, newCommand, atCommand, vcon };
  49.         enum DEVICE { data=0, class1fax=1, class2fax=2, voice=8 };
  50.         enum RESULTCODE { noerror=0, errorOPENCOM, errorCREATEMESSAGEQUEUE, errorCREATEDLEQUEUE, errorSENDSTRING };
  51.         enum MESSAGES { vmsetdevice=0, vmsetbits, vmsetdeadmantimer, vmsetspeed, vmsetsilencedetection,
  52.                         vmsetsilencedetectionvalue, vmsetsilencedeletion, vmsetline, vmbeep, manswer,
  53.                         vmtransmit, vmreceive, vmstoptransmit, vmstopreceive, minitialize, mhangup, quit,
  54.                         vmquerydevice, vmquerymodel, vmquerymanufacturer, vmqueryrevision,vmquerycompression, vmquerydevices};
  55.  
  56.         enum FLOW_CONTROL { fc_none=0, fc_rtscts, fc_xonxoff, fc_rtscts_xonxoff};
  57.  
  58.         struct MESSAGE {
  59.            MESSAGES     message;
  60.            PVOID        data;
  61.         };
  62.  
  63.         struct MODEMRESPONSE {
  64.            _MODEMRESPONSE       code;
  65.            CHAR                 verbose[100];
  66.         };
  67.  
  68.         _Export MODEM_ENGINE(PCHAR, FLOW_CONTROL, int);
  69.         _Export ~MODEM_ENGINE();
  70.  
  71.         void _Export           vmSetDevice (DEVICE d=voice);
  72.         DEVICE                 vmGetDevice () { return device; };
  73.  
  74.         void _Export           vmSetBits (BITRANGE b=four);
  75.         BITRANGE               vmGetBits () { return bitRange; };
  76.  
  77.         void _Export           vmSetDeadmanTimer (BYTE b=0);
  78.         BYTE                   vmGetDeadmanTimer () { return deadMan; };
  79.  
  80.         void _Export           vmSetSpeed (BYTE b=16);
  81.         BYTE                   vmGetSpeed () { return vmSpeed; };
  82.  
  83.         void _Export           vmSetSilenceDetection (BOOL    b=TRUE);
  84.         BOOL                   vmGetSilenceDetection () { return silenceDetection; };
  85.  
  86.         void _Export           vmSetSilenceDetectionValue (BYTE b=60);        //'in tens of seconds'
  87.         BYTE                   vmGetSilenceDetectionValue () { return silenceDetectionValue; };
  88.  
  89.         void _Export           vmSetSilenceDeletion (BOOL    b=FALSE);
  90.         BOOL                   vmGetSilenceDeletion () { return silenceDeletion; };
  91.  
  92.         void _Export           vmSetLine (LINE l=phone);
  93.         LINE                   vmGetLine () { return line; };
  94.  
  95.         void _Export           vmBeep ();
  96.         void _Export           vmTransmit (HFILE&);
  97.         void _Export           vmReceive (HFILE);
  98.         void _Export           vmStopTransmit ();
  99.         void _Export           vmStopReceive ();
  100.  
  101.         void _Export           vmQueryDevice ();
  102.         void _Export           vmQueryModel ();
  103.         void _Export           vmQueryManufacturer ();
  104.         void _Export           vmQueryRevision ();
  105.         void _Export           vmQueryCompression ();
  106.         void _Export           vmQueryDevices ();
  107.  
  108.         void _Export           mInitialize ();
  109.         void _Export           mHangup ();
  110.         void _Export           mAnswer ();
  111.  
  112.         void _Export           mDropDTR ();
  113.  
  114.         RESULTCODE _Export     mResultCode ();
  115.  
  116.         MODEMRESPONSE _Export  mWaitForModemResponse (BYTE tsec=30); // Wait for a response from the
  117.                                                                     // modem for 'sec' seconds/10
  118.  
  119.         CHAR _Export           mWaitForDLECode (BYTE tsec=30);         //Ditto
  120.  
  121.         void _Export           mWaitForModemResponseAndDLECode (MODEMRESPONSE&, CHAR&, BYTE tsec=30);
  122.  
  123.         MODEMRESPONSE _Export  mModemResponse ();
  124.  
  125.         void _Export    messageLoop ();
  126.         void _Export    RxLoop ();
  127.  
  128.  
  129.    protected:
  130.  
  131.         void _Export           mSendString (PCHAR);
  132.         void _Export           mSendString (CHAR);
  133.         void                   mSendATString (PCHAR p) { mSendString (AT);
  134.                                                          mSendString (p);
  135.                                                          mSendString (RETURN); };
  136.  
  137.    private:
  138.  
  139.         HFILE           hcom, hfile;
  140.         PCHAR           deviceName;
  141.         HQUEUE          hMessageQueue, hDLEQueue;
  142.         HMTX            hModemResponseSem, hResultCodeSem, hConnectStateSem;
  143.         HEV             hevModemResponseSem, hevModemResponseSeenSem;
  144.         TID             tidRxLoopThread, tidMessageLoopThread;
  145.         STATE           state;
  146.         CONNECTSTATE    connectState;
  147.         MODEMRESPONSE   modemResponse;
  148.         RESULTCODE      resultCode;
  149.  
  150.         DEVICE          device;
  151.         BITRANGE        bitRange;
  152.         LINE            vmLine;
  153.         BYTE            deadMan, vmSpeed;
  154.         BOOL            silenceDeletion, silenceDetection, bRunRxLoop, bRunMessageLoop,
  155.                         operational;
  156.         BYTE            silenceDetectionValue;
  157.  
  158.         BOOL _Export    mOpenCOM (FLOW_CONTROL);
  159. };
  160.  
  161. #endif
  162.  
  163.