Advertisement
cr88192

StepCtrl UI Protocol (early spec)

Mar 2nd, 2019
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.80 KB | None | 0 0
  1. General Goals:
  2. * Will send relevant mouse and keyboard events.
  3. * Will recieve console text.
  4. * Will implement basic File Transfer.
  5. ** For now will focus on transferring G-Code Programs.
  6. ** A more general purpose mechanism may be added later.
  7.  
  8.  
  9. === Overview ===
  10.  
  11. The basic protocol will be UDP Based, with the server at port 16961. The server in this context will refer to the CNC Controller, with the user-side client connecting to the server.
  12.  
  13. The UI will run on the server, with the screen image being streamed to the client. The screen will use a color-cell format, nominally at 80x25.
  14.  
  15. Messages will also be scrambled using the NodeID as a key. The NodeID will be be externally agreed upon between the endpoints.
  16.  
  17. This key will obfuscate the datagrams, and also help avoid interaction with non-paired nodes.
  18.  
  19.  
  20. === Message Formats ===
  21.  
  22. Messages will use a TLV format.
  23. As-is network-protocol tradition, will use big-endian.
  24.  
  25.  
  26. Messages will start with a 16-bit hash and a message size, in effect the message is itself in TLV format, with the message has as the tag.
  27.  
  28. TLV Format (Basic):
  29. u16 tag; //0xA000..0xFFFF
  30. u16 len; //up to 32K
  31.  
  32. Tags between 0xA000 and 0xFFFF will be TWOCC tags.
  33.  
  34. Tag values in the range of 0x0000 to 0x7FFF will be the start of 32-bit FOURCC values. Values in the range of 0x8000..0x9FFF are reserved for larger tags.
  35.  
  36. The length is nominally 16 bits, with a size limit of 32K.
  37. The length will include both the size of the tag as well as the size of the payload.
  38.  
  39. If the length is 0x8000 to 0xBFFF, it will be interpreted as the high word of a 32-bit length (up to 1GB). 0xC000..0xDFFF will start a 48-bit length (up to 32TB).
  40.  
  41. For the basic UDP protocol, only 16-bit tags and lengths are allowed.
  42.  
  43.  
  44. Messages:
  45. 0xCD00, Reserved
  46.  
  47. 0xCD01, Console Delta (Basic)
  48. 0xCD02, ASCII/ANSI
  49. SV->CL: Text to display on screen.
  50. CL->SV: Mouse + Keyboard.
  51. 0xCD03, Connect
  52. 0xCD04, KeyMap
  53.  
  54. 0xFD01, File Data
  55. 0xFD02, File Data ACK
  56. 0xFD03, Request File
  57.  
  58.  
  59. === KeyMap ===
  60.  
  61. Will transfer 32 bytes of data representing a bitmap for which keys are currently pressed.
  62.  
  63. The first 16 bits of the message will be used as a sequence number.
  64. The following 16 bits will give a status code.
  65.  
  66. The remaining 32 bytes will give a keypress bitmap. This bitmap will be interpreted in LSB-first order.
  67.  
  68. Bits 0..127 will be represent the keys interpreted in ASCII order.
  69. Bits 128..255 will be used for the remaining (non-ASCII) keys.
  70.  
  71.  
  72. === Console Memory ===
  73.  
  74. The console will be organized as 80x25 cells, each composed of 8 DWORDs.
  75. * DWord 0: Text Cell or Color Endpoints
  76. * DWord 1: Color Endpoints (Usually)
  77. * DWord 2/3: Color Endpoints
  78. * DWord 4..7: Pixel Bits
  79.  
  80.  
  81. Text Cells will nominally follow the layout (0.0):
  82. * (31:30): 00 (Text Cell)
  83. * (29:28): 00 (RGB6)
  84. * (27:22): ColorA
  85. * (21:16): ColorB
  86. * (15:10): Attribute Flags
  87. * ( 9: 8): Font
  88. * ( 7: 0): Glyph
  89.  
  90. But, may also follow the layout (0.2):
  91. * (31:30): 00 (Text Cell)
  92. * (29:28): 10 (RGB9)
  93. * (27:19): ColorA
  94. * (18:10): ColorB
  95. * ( 9: 8): Font
  96. * ( 7: 0): Glyph
  97.  
  98. The latter mode has more colors available, but may not have attribute flags.
  99.  
  100. Fonts:
  101. * 0: Codepage 437
  102. * 1: Various Block Drawing Characters
  103. * 2: Codepage 1252
  104. * 3: Dynamic
  105.  
  106.  
  107. Pixel Bits will represent either an 8x8x2 cell, or an 8x16x1 cell.
  108. Each dword will represent a subcell (4x4x2 or 4x8x1), with the cells organized in raster order (4=UL, 5=UR, 6=LL, 7=LR).
  109.  
  110. Pixels will be organized as 2-bit pairs in raster order starting from the MSB.
  111. With 4x8 subcells, the high bit of each 2-bit pair will represent the even scanline, and the low bit will represent the odd scanline.
  112.  
  113. Color Endpoints for color-cell blocks will be in YVU654 order:
  114. * (14: 9): Y
  115. * ( 8: 4): V (Cr)
  116. * ( 3: 0): U (Cb)
  117.  
  118. This may be unpacked and converted to RGB for display.
  119.  
  120. Alternately, the server may opt to use 15-bit RGB555 instead.
  121. (15:10): R
  122. ( 9: 5): G
  123. ( 4: 0): B
  124.  
  125. The high 2 bits of Word 0 and 1 will be used to encode the Cell Type.
  126.  
  127. High bits of Word 0:
  128. * 00(0)=Text Cell (only uses Word 0, 32 bits)
  129. * 01(1)=Limited Graphics Cell Formats (Words 0 and 1, 64 bits)
  130. * 10(2)=Medium Graphics Cell Formats (Words 0..3, 128 bits)
  131. * 11(3)=Full Graphics Cell Formats (Words 0..7, 256 bits)
  132.  
  133. In Mode 3, the high 2 bits of Word 1 give the subtype:
  134. * 00(0)=Reserved
  135. * 01(1)=8x16x1 (4x 4x8x1)
  136. * 10(2)=4:2:0, 4x8x2 (2x 4x4x2)
  137. * 11(3)=8x8x2 (4x 4x4x2)
  138.  
  139. In Mode 3, the low 30 bits in dwords 0..3 are interpretes as pairs of color endpoints in YVU654 or RGB555. These endpoints are in the same order as their corresponding pixel blocks.
  140.  
  141. In sub-mode 2, only words 6 and 7 are used for pixel data. The 8 color endpoint values are interpreted as color centers, with words 4 and 5 giving Ymax-Ymin values (as a series of 7 bit entries).
  142.  
  143. The modes will thus give the effective screen resolutions at 80x25:
  144. * 0: Reserved
  145. * 1: 640x400
  146. * 2: 320x200
  147. * 3: 640x200
  148.  
  149.  
  150. === Console Delta ===
  151.  
  152. First Word of the Console Delta message will be interpreted as a sequence number.
  153.  
  154. The remainder of the message will be interpreted as a series of 16-bit words encoding changes to the console buffer.
  155.  
  156. Consists of a series of 16-bit tags:
  157. * 0000..00FF: Cell Character
  158. ** Updates the text character of the cell
  159. ** Automatically advances to next cell
  160.  
  161. * 0100..01FF: Delta-Mask DWords
  162. ** Gives a mask of which DWords have changed
  163. ** Followed by the DWord values
  164. ** Automatically advances to next cell
  165.  
  166. * 0200..02FF: Run of character bytes
  167. ** Only the cell characters have changed
  168. ** Run length is in terms of pairs of bytes.
  169. ** Uses 0200 as a special-case, encoding a sequence number.
  170.  
  171. * 0300..03FF: Run of character low DWords
  172. ** The low DWord of each cell has changed
  173.  
  174. * 2000..2FFF: Cell DWord, Mode 0.0 (RGB6)
  175. * 3000..3FFF: Cell DWord, Mode 0.2 (RGB9)
  176. ** Update the low DWord of the cell (Character+Attribute)
  177. ** Automatically advances to next cell
  178. * 4000..7FFF: Jump to screen position (cell index).
  179.  
  180.  
  181. === File Data ===
  182.  
  183. Starts with a DWORD encoding a file handle and the sector offset.
  184. * (31:24)=Handle
  185. * ( 23)=End Of Transfer
  186. * (22: 0)=Sector Offset
  187.  
  188. This is followed by 512 or 1024 bytes of file data.
  189. The payload may be smaller at the end of the file.
  190.  
  191. End Of Transfer:
  192. * Set by sender if all preceding blocks have been transfered and acknowledged.
  193. * If reciever sees this, it can safely close the file.
  194. ** Any following blocks recieved for this handle should be ignored.
  195.  
  196. The sector offset will be in terms of 512 byte sectors.
  197.  
  198.  
  199. The File Data ACK message contains the request DWORD and a status WORD, but does not contain payload. It is used by the reciever to inform the sender which blocks have been recieved thus far. The default 'ACK' status will be 0x0001.
  200.  
  201. The sender will transmit blocks until it has seen acknowldegements for all blocks, and will then terminate the transfer. Transfers may be done in either a bursty or ping-pong style.
  202.  
  203.  
  204. === Request File ===
  205.  
  206. Request file to be sent or recieved.
  207. Nominally, these requests will be sent from the server to the client.
  208.  
  209. Will contain a 32-bit DWORD:
  210. * (31:24): File handle to use.
  211. * (23:20): Flags
  212. * (19:16): Request Type
  213. * (15:14): File Type
  214. * (13: 0): File Number
  215.  
  216. The word will be followed by a status code whose meaning depends on the request type.
  217.  
  218. Program Type:
  219. * 00: G-Code / NC Program.
  220. * 01: Named Handle (Generic File)
  221. Request Type:
  222. * 0: None
  223. * 1: GET, Request a file to be sent.
  224. * 2: PUT, Request to send a file.
  225. * 3: STATUS, Response code for a request.
  226.  
  227.  
  228. For G-Code programs, the program number will range from 0000 to 9999.
  229. These will come from a specific directory, and will follow the form "Oxxxx.nc"
  230.  
  231. This directory will be specific to the transfer of CNC programs.
  232.  
  233.  
  234. Named handles will correspond to indices into a name-table.
  235. A mechanism may be provided to transfer names.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement