home *** CD-ROM | disk | FTP | other *** search
/ The Unsorted BBS Collection / thegreatunsorted.tar / thegreatunsorted / texts / cell_nfo / ctlib.txt < prev    next >
Text File  |  1994-06-20  |  18KB  |  631 lines

  1.         Network Wizards Cellular Telephone Library Routines
  2.            Copyright (C) 1994 by Network Wizards
  3.  
  4.  
  5. USING THE PROGRAMMING LIBRARIES
  6.  
  7. The programming library file is CTLIB.OBJ.  The module and all other code
  8. were written in Borland Turbo C 2.0 using the small memory model, and word
  9. alignment (switches "-a -ms").  See the enclosed Makefile for compiling
  10. examples.  Any programs you write need to include CTLIB.H, and be linked
  11. with CTLIB.OBJ, TTY.OBJ, and TTYA.OBJ.  If you have trouble linking these
  12. with other compilers, please contact us for help.
  13.  
  14. [Note: There is a bug in the delay() function of Turbo C which may cause
  15. programs to not work on 486 machines.  If you have this problem you can get
  16. a patch file from the Borland BBS at (408) 439-9096]
  17.  
  18. CTLIB.H contains function header prototypes, structure element descriptions,
  19. and predefined constants.
  20.  
  21. TTY.OBJ and TTYA.OBJ contain serial I/O code used by CTLIB.OBJ to talk
  22. to the COM port the interface adapter is attached to.
  23.  
  24. The function descriptions use the following data types:
  25.   typedef unsigned char bool;
  26.   typedef unsigned char byte;
  27.   typedef unsigned int  word;  /* 16 bits */
  28.  
  29. ======================================================================
  30.     FUNCTION SUMMARY
  31.  
  32. INITIALIZATION
  33. ct_lib_init            initialize library routines
  34. ct_lib_done            cleanup after library routines
  35. ct_on                turn phone on
  36. ct_off                turn phone off
  37.  
  38. OPERATION
  39. ct_keypress            "press" a key on phone
  40.  
  41. TRANSMISSION
  42. ct_set_channel            select channel number
  43. ct_set_carrier            turn transmitter on or off
  44. ct_set_tx_power            set transmit power level
  45. ct_set_sat            select sat tones
  46.  
  47. AUDIO
  48. ct_set_audio_path        set source/destination of audio signals
  49. ct_set_rx_audio            mute or unmute received audio
  50. ct_set_tx_audio            mute or unmute transmitted audio
  51. ct_set_volume            set audio volume level
  52. ct_set_audio_tone        select audio alerting tones
  53. ct_set_dtmf            transmit DTMF tones
  54. ct_dtmf_decode            receive DTMF tones
  55. ct_set_comp_exp            turn compressor/expandor circuit on or off
  56.  
  57. DATA AND SIGNALLING
  58. ct_fcc_msg            receive a Forward Control Channel message
  59. ct_fvc_msg            receive a Forward Voice Channel message
  60. ct_rcc_msg            send a Reverse Control Channel message
  61. ct_rvc_msg            send a Reverse Voice Channel message
  62. ct_set_signalling_tone        turn signalling tone on or off
  63. ct_stream            set reception on even or odd data stream
  64. ct_get_bi            get busy/idle status
  65.  
  66. STATUS
  67. ct_get_rss            read received signal strength
  68. ct_get_battery_level        read battery level
  69.  
  70. MEMORIES
  71. ct_read_mem            read telephones internal memory
  72. ct_read_block            read memory block from phone
  73. ct_set_block            write memory block to phone
  74. ct_get_esn            read ESN from phone
  75. ct_get_romver            read ROM version number from phone
  76. ct_get_prog_pwd            read programming password from phone
  77. ct_get_cust_msg            read custom power on message from phone
  78. ct_set_cust_msg            write custom power on message to phone
  79. ct_get_nams            read NAMs out of phone
  80. ct_set_nams            write NAMs into phone
  81.  
  82. UTILITIES
  83. ct_inc_channel            increment to next channel
  84. ct_dec_channel            decrement to next channel
  85. ct_channel_type            return type of channel
  86. ct_decode_fcc_msg        decode a forward control channel message
  87. ct_decode_fvc_msg        decode a forward voice channel message
  88. ct_decode_order            decode a received order
  89. ct_tel2min            convert a telephone number to a MIN
  90. ct_gen_bch            generate a BCH error correction code
  91.  
  92. ======================================================================
  93. PHONE CONTROL FUNCTIONS
  94.  
  95. int ct_lib_init(model,addr,irq)
  96.   word model;
  97.   word addr;
  98.   byte irq;
  99.  
  100.   Initializes the cellular library routines and serial I/O routines.
  101.   This routine must be called only once before any other routine
  102.   may be used.
  103.  
  104.   model is the cellular telephone model number to be accessed, one of:
  105.     model    Description
  106.     900    OKI-900 or AT&T-3730
  107.     1150    OKI-1150 or AT&T-3760
  108.   [either model number can be used and ctlib will figure out what
  109.    type of phone it is really talking to]
  110.  
  111.   addr is the I/O address of the serial port UART.
  112.   irq is the interrupt request line of the UART.
  113.   addr and irq are typically set as follows:
  114.     port    (addr,irq)
  115.     COM1    (0x3f8,4)
  116.     COM2    (0x2f8,3)
  117.  
  118.   Returns TRUE on success.
  119.  
  120.  
  121.  
  122. void ct_lib_done()
  123.  
  124.   Cleans up the cellular and serial I/O routines.
  125.   This routine must be called before exiting your program.
  126.  
  127.  
  128.  
  129. int ct_on(mode)
  130.   word mode;
  131.  
  132.   Power up the phone in normal or test/debug mode.
  133.  
  134.   mode is one of MODE_NORMAL or MODE_TEST.
  135.   All routines in this library function only in MODE_TEST,
  136.   except for ct_keypress() which only works in MODE_NORMAL.
  137.  
  138.   Returns TRUE on success.
  139.  
  140.  
  141.  
  142. void ct_off()
  143.  
  144.   Power down the phone.
  145.  
  146.  
  147.  
  148. void ct_keypress(key)
  149.   int key;
  150.  
  151.   This function may only be used if the phone is powered up in
  152.   MODE_NORMAL.  A key is "pressed" by sending its keypress code
  153.   defined in ctlib.h.  A key is "released" by sending the release code.
  154.  
  155.  
  156.  
  157. void ct_set_carrier(state)
  158.   bool state;
  159.  
  160.   Turns the transmitter on (TRUE) or off (FALSE).
  161.  
  162.  
  163.  
  164. void ct_set_tx_power(level)
  165.   int level;
  166.  
  167.   Sets the transmitter power attenuation level, zero being the
  168.   highest power level (from 0-7).   See cellular specs for definition
  169.   of the attenuation levels.
  170.  
  171.  
  172.  
  173. void ct_set_sat(sat)
  174.   int sat;
  175.  
  176.   Controls the transmission of SAT tones.  sat is 0 thru 3 as follows:
  177.  
  178.     SAT        Operation
  179.      0        transmit 5970hz SAT 
  180.      1        transmit 6000hz SAT
  181.      2        transmit 6030hz SAT
  182.      3        disable transmission of SAT tones
  183.  
  184.  
  185.  
  186. void ct_set_dtmf(tone)
  187.   byte tone;
  188.  
  189.   Begins transmission of a DTMF tone.  Tone is one of the standard values
  190.   represented by "1234567890*#ABCD".  If tone is an ASCII space, DTMF
  191.   transmission is stopped.  The following special tones "efghijkl" are
  192.   defined as follows:
  193.     e    697hz (row1)        i    1209hz (col1)
  194.     f    770hz (row2)        j    1336hz (col2)
  195.     g    852hz (row3)        k    1477hz (col3)
  196.     h    941hz (row4)        l    1633hz (col4)
  197.  
  198.    
  199.  
  200. void ct_set_signalling_tone(state)
  201.   bool state;
  202.  
  203.   Begins transmitting a 10khz signalling tone (TRUE) or stops it (FALSE).  
  204.  
  205.  
  206.  
  207. void ct_set_audio_tone(tone,state)
  208.   int tone;
  209.   bool state;
  210.  
  211.   Turns a tone on (TRUE) or off (FALSE).  The tone is sent to the
  212.   current received audio path.  The tone is one of:
  213.  
  214.     Tone Value    Frequency
  215.     TONE_LOW    770hz
  216.     TONE_HIGH    1150hz
  217.  
  218.  
  219.  
  220. void ct_set_rx_audio(state)
  221.   bool state;
  222.  
  223.   Mutes (FALSE) or Unmutes (TRUE) the received audio signal.
  224.  
  225.  
  226.  
  227. void ct_set_tx_audio(state)
  228.   bool state;
  229.  
  230.   Mutes (FALSE) or Unmutes (TRUE) the transmitted audio signal.
  231.  
  232.  
  233.  
  234. void ct_set_comp_exp(state)
  235.   bool state;
  236.  
  237.   Enables (TRUE) or disables (FALSE) the audio compressor and expandor
  238.   circuits.
  239.  
  240.  
  241.  
  242. void ct_set_volume(vol)
  243.   int vol;
  244.  
  245.   Sets the audio output volume (0-7).  0 is the highest level.
  246.  
  247.  
  248.  
  249. void ct_set_audio_path(path)
  250.   int path;
  251.  
  252.   Sets the audio path to and from the radio.  One of:
  253.  
  254.   Path            Description
  255.   AUDIO_EXTERNAL    audio routed to external jack
  256.   AUDIO_EARPIECE    input from mic, output to earpiece
  257.   AUDIO_SOUNDER        input from mic, output to earpiece and sounder
  258.  
  259.  
  260.  
  261. void ct_set_channel(channel)
  262.   word channel;
  263.  
  264.   Tunes the cellular phone to the specified channel (1-1023).
  265.  
  266.  
  267.  
  268. int ct_dtmf_decode(command)
  269.   int command;
  270.  
  271.   Decodes DTMF tones received from the radio.  No other commands may
  272.   be sent to the phone between START and END of decoding period.
  273.  
  274.   command is one of:
  275.  
  276.   DTMF_DECODE_START    Start listening for DTMF tones (always returns TRUE).
  277.   DTMF_DECODE_GET    Returns FALSE if no valid tones received so far, 
  278.             or the ASCII value of one of "1234567890*#ABCD".
  279.   DTMF_DECODE_END    End listening for DTMF tones (always returns TRUE).
  280.  
  281.  
  282.  
  283. int ct_fvc_msg(command,data)
  284.   int command;
  285.   byte *data;
  286.  
  287.   Receives a message sent on the Forward Voice Channel, from the land
  288.   station to mobile station.  MSG_SETUP must be called to get the phone
  289.   ready to receive the next message.  MSG_GET can then be called to find
  290.   out when it arrives.  If a message is not received, MSG_ABORT can be
  291.   used to end the MSG_SETUP waiting mode.  No other commands can be issued
  292.   to the phone if it is waiting for a message.
  293.  
  294.   command is one of:
  295.  
  296.   MSG_SETUP        Start listening for the next FVC message on the
  297.             current    voice channel.
  298.   MSG_GET        Returns FALSE if no messages have been received
  299.             so far, or TRUE and the message in the location
  300.             pointed to by data.
  301.   MSG_ABORT        Abort listening for FVC messages.            
  302.  
  303.   data is NULL for MSG_SETUP and MSG_ABORT.  For MSG_GET, data points to
  304.   a 5 byte array to put the received message into.
  305.  
  306.  
  307.  
  308. int ct_fcc_msg(command,data)
  309.   int command;
  310.   byte *data;
  311.  
  312.   Receives a message sent on the Forward Control Channel, from the land
  313.   station to mobile station.  MSG_SETUP must be called to get the phone
  314.   ready to receive the next message.  MSG_GET can then be called to find
  315.   out when it arrives.  If a message is not received, MSG_ABORT can be
  316.   used to end the MSG_SETUP waiting mode.  No other commands can be issued
  317.   to the phone if it is waiting for a message.
  318.  
  319.   command is one of:
  320.  
  321.   MSG_SETUP        Start listening for the next FCC message on the
  322.             current control channel.
  323.   MSG_GET        Returns FALSE if no messages have been received
  324.             so far, or TRUE and the message in the location
  325.             pointed to by data.
  326.   MSG_ABORT        Abort listening for FCC messages.            
  327.  
  328.   data is NULL for MSG_SETUP and MSG_ABORT.  For MSG_GET, data points to
  329.   a 10 byte array to put the received message into.
  330.  
  331.  
  332.  
  333. int ct_rcc_msg(dcc,data)
  334.   int dcc;
  335.   byte *data;
  336.  
  337.   Sends a Reverse Control Channel message, from the mobile to the land
  338.   station.  dcc is the Digital Color Code received from the land
  339.   station (0-3).  data is a 30 byte array, consisting of five 6-byte words.
  340.   Returns TRUE if dcc and ESN (in data) are valid.
  341.  
  342.  
  343.  
  344. int ct_rvc_msg(data)
  345.   byte *data;
  346.  
  347.   Sends a Reverse Voice Channel message, from the mobile to the land
  348.   station.  data is a 12-byte array, consisting of two 6-byte words.
  349.   Always returns TRUE.
  350.  
  351.  
  352.  
  353. int ct_get_rss()
  354.  
  355.   Returns signal strength of currently tuned channel.
  356.   Value is adjusted for approximate range of 0-99 (99 is strongest).
  357.   -1 is returned on error.
  358.  
  359.  
  360.  
  361. int ct_get_battery_level(volts)
  362.   float *volts;
  363.  
  364.   Returns battery level (0-8).  If volts is not NULL, it is set to
  365.   the estimated battery voltage.
  366.  
  367.  
  368.  
  369. int ct_read_mem(dest,addr,n)
  370.   byte *dest;
  371.   word addr;
  372.   int n;  
  373.  
  374.   Reads a contiguous block of memory from the cellular phone.  dest points 
  375.   to a destination area where n bytes will be placed.  The block is read from
  376.   the cellular phones internal memory space starting at addr.  Returns TRUE
  377.   on success, FALSE otherwise.
  378.  
  379.  
  380.  
  381. int ct_read_block(dest,addr,n)
  382.   byte *dest;
  383.   word addr;
  384.   int n;  
  385.  
  386.   Reads a block of memory from the cellular phone.  dest points to a 
  387.   destination area where n bytes will be placed.  The block is read from
  388.   the cellular phones internal memory space starting at addr, but not
  389.   necessarily incrementing addr by one for the next byte, because some
  390.   phones skip over certain protected addresses in the memory space.
  391.   Returns TRUE on success, FALSE otherwise.
  392.  
  393.  
  394.  
  395. int ct_get_esn(esn)
  396.   unsigned long *esn;
  397.  
  398.   Places the cellular phones Electronic Serial Number (32-bits) into
  399.   the unsigned long pointed to by esn.  Returns TRUE on success,
  400.   FALSE otherwise.
  401.  
  402.  
  403.  
  404. char *ct_get_romver()
  405.  
  406.   Returns a pointer to an internal string identifying the cellular
  407.   telephone ROM version.
  408.  
  409.  
  410.  
  411. char *ct_get_prog_pwd()
  412.  
  413.   Returns a pointer to an internal string identifying the cellular
  414.   telephone programming password.
  415.  
  416.  
  417.  
  418. char *ct_get_cust_msg()
  419.  
  420.   Returns a pointer to an internal string which is displayed by the
  421.   cellular telephone as a custom power on message.
  422.  
  423.  
  424.  
  425. int ct_set_cust_msg(msg)
  426.   byte *msg;
  427.  
  428.   Given a string, sets the custom power on message displayed by the
  429.   cellular phone.  Returns TRUE if ok, FALSE otherwise.
  430.  
  431.  
  432.  
  433. int ct_get_nams()
  434.  
  435.   Reads NAM information from the cellular telephone.  Returns TRUE if ok.
  436.   The NAM information is placed in the following data structure defined
  437.   in ctlib.h:
  438.  
  439.   struct nam_data {
  440.     char number[15]            ;Tel Num: "(nnn) nnn-nnnn"
  441.     char sid[6]                ;System Id: nnnnn
  442.     char sys                ;System: 'A' or 'B'
  443.     char ipch[5]            ;Initial Paging Channel: nnnn
  444.     char olc[3]                ;Overload Class: nn
  445.     char gim[3]                ;Group ID Mark: nn
  446.   } nam_info[5]                ;  for each of 5 NAMs
  447.  
  448.  
  449.  
  450. int ct_set_nams()
  451.  
  452.   Set NAM information into the cellular telephone.  Returns TRUE if ok.
  453.   The NAM information from the data structure defined above is
  454.   written into the cellular phone.  The data must be formatted the same
  455.   way as ct_get_nams() returns it.  The 'sys' char is not used when
  456.   writing.
  457.  
  458.   This routine must not be interrupted or an invalid NAM block will
  459.   be sent to the phone causing it to display an error when the phone is
  460.   returned to normal operating mode.  It may also be wise to use
  461.   ct_get_battery_level() before calling this function and make sure
  462.   it is at a reasonable level and not about to die, as this function
  463.   will take a little while to complete.  The ct_get_nams() function
  464.   should be called at least once before changing any information and
  465.   using ct_set_nams().  If ct_get_nams() has not been called, then
  466.   ct_set_nams() will return FALSE.
  467.  
  468.  
  469.  
  470. int ct_stream(stream)
  471.   int stream;
  472.  
  473.   Sets or returns the status of whether the transceiver is receiving
  474.   on the even or odd data stream of the control channel.  If stream
  475.   is -1, then the status is returned (0 for even stream, 1 for odd).
  476.   If stream is 0 or 1, then the stream is changed to correspond to
  477.   the setting, and its new status is returned (or old status if it
  478.   couldn't switch).
  479.  
  480.   NOTE:  Older versions of this function required at least one NAM
  481.   be programmed as even and one as odd.  This is no longer required.
  482.  
  483.  
  484.  
  485. int ct_get_bi()
  486.   
  487.   Returns the status of the busy/idle bit when tuned to a valid
  488.   control channel.  Returns FALSE if busy and TRUE if idle.  This
  489.   bit indicates the status of the reverse control channel at the
  490.   instant it was polled, and is already invalid by the time this
  491.   function reports it.
  492.  
  493.  
  494.  
  495. struct ct_state_struct {
  496.   bool carrier;
  497.   bool sigtone;
  498.   bool rxaudio;
  499.   bool txaudio;
  500.   bool compexp;
  501.   int  powerlevel;
  502.   int  sat;
  503.   int  volume;
  504.   int  audiopath;
  505.   int  channel;
  506.   int  stream;
  507.   int  namindex;
  508.   int  oldnam;
  509. } ct_state;
  510.  
  511.   This structure contains internal state kept by the library routines.
  512.   It may be read but should not be changed.
  513.   
  514. ======================================================================
  515. UTILITY ROUTINES
  516.  
  517. word ct_inc_channel(channel)
  518.   word channel;
  519.  
  520.   Given a channel number, returns next voice channel number in the
  521.   current system (A/B), then the next system, then wraps around.
  522.  
  523.  
  524.  
  525. word ct_dec_channel(channel)
  526.   word channel;
  527.  
  528.   Given a channel number, returns previous voice channel number in the
  529.   current system (A/B), then the next system, then wraps around.
  530.  
  531.  
  532.  
  533. int ct_channel_type(channel,system,type)
  534.   word channel;
  535.   byte *system;
  536.   byte *type;
  537.  
  538.   Given a channel number, returns two bytes indicating:
  539.     system
  540.     'A'    system A
  541.     'B'    system B
  542.     type
  543.     'A'    audio channel
  544.     'C'    control channel
  545.  
  546.   Returns TRUE if valid channel number was given, FALSE otherwise.
  547.  
  548.  
  549.  
  550. int ct_decode_fvc_msg(msg,scc,pscc,order,ordq,local,chan,vmac)
  551.   byte *msg;
  552.   int *scc,*pscc,*order,*ordq,*local,*chan,*vmac;
  553.  
  554.   Given a pointer to a 5-byte Forward Voice Channel message in msg,
  555.   it decodes the message into the listed fields.  Returns TRUE if OK,
  556.   or FALSE if invalid message.  If scc is 0, 1, or 2, then pscc,
  557.   chan, and vmac are returned.  Otherwise scc is 3 (invalid scc),
  558.   and pscc, order, ordq, and local are returned. 
  559.  
  560.   scc        SAT color code for new channel (if 0, 1, or 2)
  561.  
  562.   pscc        present SAT color code of current channel
  563.  
  564.   order        order type
  565.  
  566.   ordq        order qualifier
  567.  
  568.   local        local control field (when order is local control type)
  569.  
  570.   chan        new voice channel number
  571.  
  572.   vmac        new voice channel mobile attenuation code
  573.  
  574.  
  575.  
  576. int ct_decode_fcc_msg(msg,scc,dcc,min,order,ordq,local,chan,vmac)
  577.   byte *msg, **min;
  578.   int *scc,*dcc,*order,*ordq,*local,*chan,*vmac;
  579.  
  580.   Given a pointer to a 10-byte Forward Control Channel message in msg,
  581.   it decodes the message into the listed fields.  Returns TRUE if OK,
  582.   or FALSE if invalid message.  If TRUE, always returns scc, dcc and min.
  583.   If scc is 0, 1, or 2, then chan, and vmac are returned.  Otherwise scc
  584.   is 3 (invalid scc), and order, ordq, and local are returned. 
  585.  
  586.   scc        SAT color code for new channel (if 0, 1, or 2)
  587.  
  588.   dcc        digital color coded field
  589.  
  590.   min        returns a pointer to a string with the Mobile Id
  591.         Number formatted as "(nnn) nnn-nnnn".  The string
  592.         is overwritten on each call.
  593.  
  594.   order        order type
  595.  
  596.   ordq        order qualifier
  597.  
  598.   local        local control field (when order is local control type)
  599.  
  600.   chan        voice channel number
  601.  
  602.  
  603.  
  604. char *ct_decode_order(order,ordq)
  605.   int order, ordq;
  606.  
  607.   Given an order and order qualification code (such as those returned
  608.   from ct_decode_fvc_msg() and ct_decode_fcc_msg(), returns a pointer
  609.   to a string describing the order.  The string pointed is overwritten
  610.   on each call.
  611.  
  612.  
  613.  
  614. void ct_tel2min(telnum,min1,min2)
  615.   char *telnum;
  616.   unsigned long *min1, *min2;
  617.  
  618.   Given a phone number in "(nnn) nnn-nnnn" format, it is returned
  619.   encoded as min1 and min2 as defined by the cellular specifications.
  620.  
  621.  
  622.  
  623. word ct_gen_bch(bits,buf)
  624.   int bits;
  625.   unsigned char *buf;
  626.  
  627.   Generates a BCH error correcting code.  Takes number of bits to
  628.   generate a bch code for, and pointer to first byte of data buffer
  629.   containing the data bits.  Deposits 12-bit BCH code into buffer
  630.   right after the given number of data bits.
  631.