i2cmd.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:12k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*******************************************************************************
  2. *
  3. *   (c) 1998 by Computone Corporation
  4. *
  5. ********************************************************************************
  6. *
  7. *
  8. *   PACKAGE:     Linux tty Device Driver for IntelliPort family of multiport
  9. *                serial I/O controllers.
  10. *
  11. *   DESCRIPTION: Definition table for In-line and Bypass commands. Applicable
  12. *                only when the standard loadware is active. (This is included
  13. *                source code, not a separate compilation module.)
  14. *
  15. *******************************************************************************/
  16. //------------------------------------------------------------------------------
  17. //
  18. // Revision History:
  19. //
  20. // 10 October 1991   MAG First Draft
  21. //  7 November 1991  MAG Reflects additional commands.
  22. // 24 February 1992  MAG Additional commands for 1.4.x loadware
  23. // 11 March 1992     MAG Additional commands
  24. // 30 March 1992     MAG Additional command: CMD_DSS_NOW
  25. // 18 May 1992       MAG Discovered commands 39 & 40 must be at the end of a
  26. //                       packet: affects implementation.
  27. //------------------------------------------------------------------------------
  28. //************
  29. //* Includes *
  30. //************
  31. #include "i2cmd.h"   /* To get some bit-defines */
  32. //------------------------------------------------------------------------------
  33. // Here is the table of global arrays which represent each type of command
  34. // supported in the IntelliPort standard loadware. See also i2cmd.h
  35. // for a more complete explanation of what is going on.
  36. //------------------------------------------------------------------------------
  37. // Here are the various globals: note that the names are not used except through
  38. // the macros defined in i2cmd.h. Also note that although they are character
  39. // arrays here (for extendability) they are cast to structure pointers in the
  40. // i2cmd.h macros. See i2cmd.h for flags definitions.
  41. //                     Length Flags Command
  42. static UCHAR ct02[] = { 1, BTH,     0x02                     }; // DTR UP
  43. static UCHAR ct03[] = { 1, BTH,     0x03                     }; // DTR DN
  44. static UCHAR ct04[] = { 1, BTH,     0x04                     }; // RTS UP
  45. static UCHAR ct05[] = { 1, BTH,     0x05                     }; // RTS DN
  46. static UCHAR ct06[] = { 1, BYP,     0x06                     }; // START FL
  47. static UCHAR ct07[] = { 2, BTH,     0x07,0                   }; // BAUD
  48. static UCHAR ct08[] = { 2, BTH,     0x08,0                   }; // BITS
  49. static UCHAR ct09[] = { 2, BTH,     0x09,0                   }; // STOP
  50. static UCHAR ct10[] = { 2, BTH,     0x0A,0                   }; // PARITY
  51. static UCHAR ct11[] = { 2, BTH,     0x0B,0                   }; // XON
  52. static UCHAR ct12[] = { 2, BTH,     0x0C,0                   }; // XOFF
  53. static UCHAR ct13[] = { 1, BTH,     0x0D                     }; // STOP FL
  54. static UCHAR ct14[] = { 1, BYP|VIP, 0x0E                     }; // ACK HOTK
  55. //static UCHAR ct15[]={ 2, BTH|VIP, 0x0F,0                   }; // IRQ SET
  56. static UCHAR ct16[] = { 2, INL,     0x10,0                   }; // IXONOPTS
  57. static UCHAR ct17[] = { 2, INL,     0x11,0                   }; // OXONOPTS
  58. static UCHAR ct18[] = { 1, INL,     0x12                     }; // CTSENAB
  59. static UCHAR ct19[] = { 1, BTH,     0x13                     }; // CTSDSAB
  60. static UCHAR ct20[] = { 1, INL,     0x14                     }; // DCDENAB
  61. static UCHAR ct21[] = { 1, BTH,     0x15                     }; // DCDDSAB
  62. static UCHAR ct22[] = { 1, BTH,     0x16                     }; // DSRENAB
  63. static UCHAR ct23[] = { 1, BTH,     0x17                     }; // DSRDSAB
  64. static UCHAR ct24[] = { 1, BTH,     0x18                     }; // RIENAB
  65. static UCHAR ct25[] = { 1, BTH,     0x19                     }; // RIDSAB
  66. static UCHAR ct26[] = { 2, BTH,     0x1A,0                   }; // BRKENAB
  67. static UCHAR ct27[] = { 1, BTH,     0x1B                     }; // BRKDSAB
  68. //static UCHAR ct28[]={ 2, BTH,     0x1C,0                   }; // MAXBLOKSIZE
  69. //static UCHAR ct29[]={ 2, 0,       0x1D,0                   }; // reserved
  70. static UCHAR ct30[] = { 1, INL,     0x1E                     }; // CTSFLOWENAB
  71. static UCHAR ct31[] = { 1, INL,     0x1F                     }; // CTSFLOWDSAB
  72. static UCHAR ct32[] = { 1, INL,     0x20                     }; // RTSFLOWENAB
  73. static UCHAR ct33[] = { 1, INL,     0x21                     }; // RTSFLOWDSAB
  74. static UCHAR ct34[] = { 2, BTH,     0x22,0                   }; // ISTRIPMODE
  75. static UCHAR ct35[] = { 2, BTH|END, 0x23,0                   }; // SENDBREAK
  76. static UCHAR ct36[] = { 2, BTH,     0x24,0                   }; // SETERRMODE
  77. //static UCHAR ct36a[]={ 3, INL,    0x24,0,0                 }; // SET_REPLACE
  78. // The following is listed for completeness, but should never be sent directly
  79. // by user-level code. It is sent only by library routines in response to data
  80. // movement.
  81. //static UCHAR ct37[]={ 5, BYP|VIP, 0x25,0,0,0,0             }; // FLOW PACKET
  82. // Back to normal
  83. static UCHAR ct38[] = {11, BTH|VAR, 0x26,0,0,0,0,0,0,0,0,0,0 }; // DEF KEY SEQ
  84. //static UCHAR ct39[]={ 3, BTH|END, 0x27,0,0                 }; // OPOSTON
  85. //static UCHAR ct40[]={ 1, BTH|END, 0x28                     }; // OPOSTOFF
  86. static UCHAR ct41[] = { 1, BYP,     0x29                     }; // RESUME
  87. //static UCHAR ct42[]={ 2, BTH,     0x2A,0                   }; // TXBAUD
  88. //static UCHAR ct43[]={ 2, BTH,     0x2B,0                   }; // RXBAUD
  89. //static UCHAR ct44[]={ 2, BTH,     0x2C,0                   }; // MS PING
  90. //static UCHAR ct45[]={ 1, BTH,     0x2D                     }; // HOTENAB
  91. //static UCHAR ct46[]={ 1, BTH,     0x2E                     }; // HOTDSAB
  92. static UCHAR ct47[] = { 7, BTH,     0x2F,0,0,0,0,0,0         }; // UNIX FLAGS
  93. //static UCHAR ct48[]={ 1, BTH,     0x30                     }; // DSRFLOWENAB
  94. //static UCHAR ct49[]={ 1, BTH,     0x31                     }; // DSRFLOWDSAB
  95. //static UCHAR ct50[]={ 1, BTH,     0x32                     }; // DTRFLOWENAB
  96. //static UCHAR ct51[]={ 1, BTH,     0x33                     }; // DTRFLOWDSAB
  97. //static UCHAR ct52[]={ 1, BTH,     0x34                     }; // BAUDTABRESET
  98. static UCHAR ct53[] = { 3, BTH,     0x35,0,0                 }; // BAUDREMAP
  99. static UCHAR ct54[] = { 3, BTH,     0x36,0,0                 }; // CUSTOMBAUD1
  100. static UCHAR ct55[] = { 3, BTH,     0x37,0,0                 }; // CUSTOMBAUD2
  101. static UCHAR ct56[] = { 2, BTH|END, 0x38,0                   }; // PAUSE
  102. static UCHAR ct57[] = { 1, BYP,     0x39                     }; // SUSPEND
  103. static UCHAR ct58[] = { 1, BYP,     0x3A                     }; // UNSUSPEND
  104. static UCHAR ct59[] = { 2, BTH,     0x3B,0                   }; // PARITYCHK
  105. static UCHAR ct60[] = { 1, INL|VIP, 0x3C                     }; // BOOKMARKREQ
  106. //static UCHAR ct61[]={ 2, BTH,     0x3D,0                   }; // INTERNALLOOP
  107. //static UCHAR ct62[]={ 2, BTH,     0x3E,0                   }; // HOTKTIMEOUT
  108. static UCHAR ct63[] = { 2, INL,     0x3F,0                   }; // SETTXON
  109. static UCHAR ct64[] = { 2, INL,     0x40,0                   }; // SETTXOFF
  110. //static UCHAR ct65[]={ 2, BTH,     0x41,0                   }; // SETAUTORTS
  111. //static UCHAR ct66[]={ 2, BTH,     0x42,0                   }; // SETHIGHWAT
  112. //static UCHAR ct67[]={ 2, BYP,     0x43,0                   }; // STARTSELFL
  113. //static UCHAR ct68[]={ 2, INL,     0x44,0                   }; // ENDSELFL
  114. //static UCHAR ct69[]={ 1, BYP,     0x45                     }; // HWFLOW_OFF
  115. //static UCHAR ct70[]={ 1, BTH,     0x46                     }; // ODSRFL_ENAB
  116. //static UCHAR ct71[]={ 1, BTH,     0x47                     }; // ODSRFL_DSAB
  117. //static UCHAR ct72[]={ 1, BTH,     0x48                     }; // ODCDFL_ENAB
  118. //static UCHAR ct73[]={ 1, BTH,     0x49                     }; // ODCDFL_DSAB
  119. //static UCHAR ct74[]={ 2, BTH,     0x4A,0                   }; // LOADLEVEL
  120. //static UCHAR ct75[]={ 2, BTH,     0x4B,0                   }; // STATDATA
  121. //static UCHAR ct76[]={ 1, BYP,     0x4C                     }; // BREAK_ON
  122. //static UCHAR ct77[]={ 1, BYP,     0x4D                     }; // BREAK_OFF
  123. //static UCHAR ct78[]={ 1, BYP,     0x4E                     }; // GETFC
  124. static UCHAR ct79[] = { 2, BYP,     0x4F,0                   }; // XMIT_NOW
  125. //static UCHAR ct80[]={ 4, BTH,     0x50,0,0,0               }; // DIVISOR_LATCH
  126. //static UCHAR ct81[]={ 1, BYP,     0x51                     }; // GET_STATUS
  127. //static UCHAR ct82[]={ 1, BYP,     0x52                     }; // GET_TXCNT
  128. //static UCHAR ct83[]={ 1, BYP,     0x53                     }; // GET_RXCNT
  129. //static UCHAR ct84[]={ 1, BYP,     0x54                     }; // GET_BOXIDS
  130. //static UCHAR ct85[]={10, BYP,     0x55,0,0,0,0,0,0,0,0,0   }; // ENAB_MULT
  131. //static UCHAR ct86[]={ 2, BTH,     0x56,0                   }; // RCV_ENABLE
  132. static UCHAR ct87[] = { 1, BYP,     0x57                     }; // HW_TEST
  133. //static UCHAR ct88[]={ 3, BTH,     0x58,0,0                 }; // RCV_THRESHOLD
  134. //static UCHAR ct89[]={ 1, BYP,     0x59                     }; // DSS_NOW
  135. //static UCHAR ct90[]={ 3, BYP,     0x5A,0,0                 }; // Set SILO
  136. //static UCHAR ct91[]={ 2, BYP,     0x5B,0                   }; // timed break
  137. // Some composite commands as well
  138. //static UCHAR cc01[]={ 2, BTH,     0x02,0x04                }; // DTR & RTS UP
  139. //static UCHAR cc02[]={ 2, BTH,     0x03,0x05                }; // DTR & RTS DN
  140. //********
  141. //* Code *
  142. //********
  143. //******************************************************************************
  144. // Function:   i2cmdSetSeq(type, size, string)
  145. // Parameters: type   - sequence number
  146. //             size   - length of sequence
  147. //             string - substitution string
  148. //
  149. // Returns:    Pointer to command structure
  150. //
  151. // Description:
  152. //
  153. // This routine sets the parameters of command 38 Define Hot Key sequence (alias
  154. // "special receive sequence"). Returns a pointer to the structure. Endeavours
  155. // to be bullet-proof in that the sequence number is forced in range, and any
  156. // out-of-range sizes are forced to zero.
  157. //******************************************************************************
  158. cmdSyntaxPtr
  159. i2cmdSetSeq(unsigned char type, unsigned char size, unsigned char *string)
  160. {
  161. cmdSyntaxPtr pCM = (cmdSyntaxPtr) ct38;
  162. unsigned char *pc;
  163. pCM->cmd[1] = ((type > 0xf) ? 0xf : type);   // Sequence number
  164. size = ((size > 0x8) ? 0 : size);            // size
  165. pCM->cmd[2] = size;
  166. pCM->length = 3 + size;                      // UPDATES THE LENGTH!
  167. pc = &(pCM->cmd[3]);
  168. while(size--) {
  169. *pc++ = *string++;
  170. }
  171. return pCM;
  172. }
  173. //******************************************************************************
  174. // Function:   i2cmdUnixFlags(iflag, cflag, lflag)
  175. // Parameters: Unix tty flags
  176. //
  177. // Returns:    Pointer to command structure
  178. //
  179. // Description:
  180. //
  181. // This routine sets the parameters of command 47 and returns a pointer to the
  182. // appropriate structure.
  183. //******************************************************************************
  184. cmdSyntaxPtr
  185. i2cmdUnixFlags(unsigned short iflag,unsigned short cflag,unsigned short lflag)
  186. {
  187. cmdSyntaxPtr pCM = (cmdSyntaxPtr) ct47;
  188. pCM->cmd[1] = (unsigned char)  iflag;
  189. pCM->cmd[2] = (unsigned char) (iflag >> 8);
  190. pCM->cmd[3] = (unsigned char)  cflag;
  191. pCM->cmd[4] = (unsigned char) (cflag >> 8);
  192. pCM->cmd[5] = (unsigned char)  lflag;
  193. pCM->cmd[6] = (unsigned char) (lflag >> 8);
  194. return pCM;
  195. }
  196. //******************************************************************************
  197. // Function:   i2cmdBaudRemap(dest,src)
  198. // Parameters: ?
  199. //
  200. // Returns:    Pointer to command structure
  201. //
  202. // Description:
  203. //
  204. // This routine sets the parameters of command 53 and returns a pointer to the
  205. // appropriate structure.
  206. //******************************************************************************
  207. cmdSyntaxPtr
  208. i2cmdBaudRemap(unsigned char dest, unsigned char src)
  209. {
  210. cmdSyntaxPtr pCM = (cmdSyntaxPtr) ct53;
  211. pCM->cmd[1] = dest;
  212. pCM->cmd[2] = src;
  213. return pCM;
  214. }
  215. //******************************************************************************
  216. // Function:   i2cmdBaudDef(which, rate)
  217. // Parameters: ?
  218. //
  219. // Returns:    Pointer to command structure
  220. //
  221. // Description:
  222. //
  223. // This routine sets the parameters of commands 54 or 55 (according to the
  224. // argument which), and returns a pointer to the appropriate structure.
  225. //******************************************************************************
  226. cmdSyntaxPtr
  227. i2cmdBaudDef(int which, unsigned short rate)
  228. {
  229. cmdSyntaxPtr pCM;
  230. switch(which)
  231. {
  232. case 1:
  233. pCM = (cmdSyntaxPtr) ct54;
  234. break;
  235. default:
  236. case 2:
  237. pCM = (cmdSyntaxPtr) ct55;
  238. break;
  239. }
  240. pCM->cmd[1] = (unsigned char) rate;
  241. pCM->cmd[2] = (unsigned char) (rate >> 8);
  242. return pCM;
  243. }