Bluecell_BootProtocol.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace Jdas_Mbic
  7. {
  8. public enum Bluepro_t
  9. {
  10. bluecell_header0 = 0,
  11. bluecell_header1,
  12. bluecell_header2,
  13. bluecell_header3,
  14. bluecell_type,
  15. bluecell_length_h,
  16. bluecell_length_l,
  17. bluecell_updatecnt_h,
  18. bluecell_updatecnt_l,
  19. bluecell_data,
  20. };
  21. public enum Updateseq
  22. {
  23. Bluecell_Reset = 0,
  24. Bluecell_Firmupdate_start,
  25. Bluecell_Firmupdate_sending,
  26. Bluecell_Firmupdate_end,
  27. };
  28. enum Bluecell_ProtIndex_p
  29. {
  30. Bluecell_Header = 0,
  31. Bluecell_Type,
  32. Bluecell_Length,
  33. Bluecell_CrcIndex,
  34. Bluecell_data,
  35. }
  36. enum Bluecell_Prot_t{
  37. TYPE_BLUECELL_RESET = 0,
  38. TYPE_BLUECELL_SET = 1,
  39. TYPE_BLUECELL_GET = 2,
  40. TYPE_BLUECELL_SAVE = 3,
  41. TYPE_BLUECELL_ACK = 4,
  42. };
  43. struct BLUESTATUS_st
  44. {
  45. byte bluecell_header;
  46. byte bluecell_type;
  47. byte bluecell_length;
  48. byte bluecell_crcindex;
  49. byte Selftest0;
  50. byte Selftest1;
  51. byte Selftest2;
  52. byte Selftest3;
  53. byte ATT_DL1_PATH;
  54. byte ATT_DL2_PATH;
  55. byte ATT_DL3_PATH;
  56. byte ATT_DL4_PATH;
  57. byte ATT_UL1_PATH;
  58. byte ATT_UL2_PATH;
  59. byte ATT_UL3_PATH;
  60. byte ATT_UL4_PATH;
  61. byte ATT_DL1_H;
  62. byte ATT_DL1_L;
  63. byte ATT_DL2_H;
  64. byte ATT_DL2_L;
  65. byte ATT_DL3_H;
  66. byte ATT_DL3_L;
  67. byte ATT_DL4_H;
  68. byte ATT_DL4_L;
  69. byte ATT_UL1_H;
  70. byte ATT_UL1_L;
  71. byte ATT_UL2_H;
  72. byte ATT_UL2_L;
  73. byte ATT_UL3_H;
  74. byte ATT_UL3_L;
  75. byte ATT_UL4_H;
  76. byte ATT_UL4_L;
  77. byte DET_DL1_IN_H;
  78. byte DET_DL1_IN_L;
  79. byte DET_DL2_IN_H;
  80. byte DET_DL2_IN_L;
  81. byte DET_DL3_IN_H;
  82. byte DET_DL3_IN_L;
  83. byte DET_DL4_IN_H;
  84. byte DET_DL4_IN_L;
  85. byte DET_UL1_IN_H;
  86. byte DET_UL1_IN_L;
  87. byte DET_UL2_IN_H;
  88. byte DET_UL2_IN_L;
  89. byte DET_UL3_IN_H;
  90. byte DET_UL3_IN_L;
  91. byte DET_UL4_IN_H;
  92. byte DET_UL4_IN_L;
  93. byte DET_TEMP_H;
  94. byte DET_TEMP_L;
  95. byte ATT_AGC1_ONOFF;
  96. byte ATT_ALC1_ONOFF;
  97. byte ATT_AGC2_ONOFF;
  98. byte ATT_ALC2_ONOFF;
  99. byte ATT_AGC3_ONOFF;
  100. byte ATT_ALC3_ONOFF;
  101. byte ATT_AGC4_ONOFF;
  102. byte ATT_ALC4_ONOFF;
  103. byte ATT_AGC1_H;
  104. byte ATT_AGC1_L;
  105. byte ATT_ALC1_H;
  106. byte ATT_ALC1_L;
  107. byte ATT_AGC2_H;
  108. byte ATT_AGC2_L;
  109. byte ATT_ALC2_H;
  110. byte ATT_ALC2_L;
  111. byte ATT_AGC3_H;
  112. byte ATT_AGC3_L;
  113. byte ATT_ALC3_H;
  114. byte ATT_ALC3_L;
  115. byte ATT_AGC4_H;
  116. byte ATT_AGC4_L;
  117. byte ATT_ALC4_H;
  118. byte ATT_ALC4_L;
  119. byte bluecell_crc;
  120. };
  121. class Bluecell_BootProtocol
  122. {
  123. public enum DATATYPE
  124. {
  125. ATTSET = 0x11,
  126. ATT_DL1_PATH = 0x12,
  127. ATT_UL1_PATH = 0x16,
  128. ATT_SelfTest1 = 0x18,
  129. ATT_DL2_PATH = 0x22,
  130. ATT_UL2_PATH = 0x26,
  131. ATT_SelfTest2 = 0x28,
  132. ATT_DL3_PATH = 0x32,
  133. ATT_UL3_PATH = 0x36,
  134. ATT_SelfTest3 = 0x38,
  135. ATT_DL4_PATH = 0x42,
  136. ATT_UL4_PATH = 0x46,
  137. ATT_SelfTest4 = 0x48,
  138. ALC1_EN = 0x51,
  139. ALC2_EN = 0x52,
  140. ALC3_EN = 0x53,
  141. ALC4_EN = 0x54,
  142. AGC1_EN = 0x61,
  143. AGC2_EN = 0x62,
  144. AGC3_EN = 0x63,
  145. AGC4_EN = 0x64,
  146. ATT_TableSet = 0x70,
  147. ATT_TableGet = 0x71,
  148. Bluecell_StatusReq = 0x77,
  149. Bluecell_StatusSave = 0x78,
  150. Bluecell_DL1_USER = 0x80,
  151. Bluecell_DL2_USER = 0x81,
  152. Bluecell_DL3_USER = 0x82,
  153. Bluecell_DL4_USER = 0x83,
  154. Bluecell_UL1_USER = 0x84,
  155. Bluecell_UL2_USER = 0x85,
  156. Bluecell_UL3_USER = 0x86,
  157. Bluecell_UL4_USER = 0x87,
  158. Bluecell_TEMP_USER = 0x88,
  159. };
  160. Serial serial;
  161. /*bluecell Header*/
  162. public const byte Bluecell_Header0 = 0x42;//ASCII : B
  163. public const byte Bluecell_Header1 = 0x4C;//ASCII : L
  164. public const byte Bluecell_Header2 = 0x55;//ASCII : U
  165. public const byte Bluecell_Header3 = 0x45;//ASCII : E
  166. /*bluecell type*/
  167. public const int bluecell_Firmupdate_sendlength = 1024;
  168. Crc16 crc16 = new Crc16();
  169. public const byte BLUECELL_HEADER = 0xBE;
  170. public const byte BLUECELL_TAILER = 0xEB;
  171. const byte BLUECELL_RESET_LENGTH = 6;
  172. const byte BLUECELL_FIX_DATA_LENGTH = 3;
  173. public void Bluecell_Reset(object serial)
  174. {
  175. this.serial = (Serial)serial;
  176. byte[] temp_buf = new byte[BLUECELL_RESET_LENGTH];
  177. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Header] = BLUECELL_HEADER;
  178. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type] = (byte)Bluecell_Prot_t.TYPE_BLUECELL_RESET;
  179. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Length] = BLUECELL_RESET_LENGTH - BLUECELL_FIX_DATA_LENGTH;
  180. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_CrcIndex] = (byte)Bluecell_ProtIndex_p.Bluecell_data;
  181. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data] = crc16.STH30_CreateCrc(temp_buf, BLUECELL_RESET_LENGTH - 3);
  182. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + 1] = BLUECELL_TAILER;
  183. this.serial.Serial_DataSend(temp_buf, temp_buf.Length);
  184. }
  185. public void Bluecell_RF_Status_Req(object serial)
  186. {
  187. Crc16 crc16 = new Crc16();
  188. this.serial = (Serial)serial;
  189. byte[] temp_buf = new byte[6];
  190. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Header] = BLUECELL_HEADER;
  191. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type] = (int)DATATYPE.Bluecell_StatusReq;
  192. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Length] = Convert.ToByte(temp_buf.Length - 3);
  193. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_CrcIndex] = Convert.ToByte(temp_buf.Length - 2);
  194. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + 0] = crc16.STH30_CreateCrc(temp_buf, temp_buf[2]);
  195. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + 1] = BLUECELL_TAILER;
  196. this.serial.Serial_DataSend(temp_buf, temp_buf.Length);
  197. }
  198. public const byte bluecell_length = 2;
  199. public const byte bluecell_updatecnt = 2;
  200. public const byte bluecell_crc16 = 2;
  201. private const byte BLUECELL_TYPE = 1;
  202. JdasMbic main_Form;
  203. const byte BLUECELL_DATA_SET_LENGTH = 56;
  204. public void Bluecell_RF_Status_Get(object serial, object main_form, byte[] temp_buf)
  205. {
  206. this.main_Form = (JdasMbic)main_form;
  207. this.serial = (Serial)serial;
  208. byte type = temp_buf[BLUECELL_TYPE];
  209. // main_Form.Invoke(new ByteSend(this.main_Form.ReSetting_Values),(temp_buf));
  210. switch (type)
  211. {
  212. case (byte)Bluecell_BootProtocol.DATATYPE.Bluecell_StatusReq:
  213. this.main_Form.GUIDataStatusSet(temp_buf);
  214. break;
  215. case (byte)Bluecell_BootProtocol.DATATYPE.ATT_TableGet:
  216. this.main_Form.TableDataStatusSet(temp_buf);
  217. break;
  218. //case (byte)Bluecell_Prot_t.TYPE_BLUECELL_ACK:
  219. //this.main_Form.Message_Box_Open();
  220. // break;
  221. // case (byte)Bluecell_Prot_t.TYPE_BLUECELL_ERROR:
  222. //this.main_Form.Message_Box_Error_Open(temp_buf);
  223. // break;
  224. }
  225. //Debug.Invoke(new StringSend(Debug.Data_Recv_Str), data);
  226. //main_Form.label1_8GHz_DL_OUT.Text = Convert.ToString(temp_val);
  227. }
  228. #if false
  229. public int Bluecell_Firmupdate_sendlength() {
  230. return bluecell_Firmupdate_sendlength;
  231. }
  232. private void BootHeaderput(ref byte[] fix_data)
  233. {
  234. fix_data[(int)Bluepro_t.bluecell_header0] = Bluecell_Header0;
  235. fix_data[(int)Bluepro_t.bluecell_header1] = Bluecell_Header1;
  236. fix_data[(int)Bluepro_t.bluecell_header2] = Bluecell_Header2;
  237. fix_data[(int)Bluepro_t.bluecell_header3] = Bluecell_Header3;
  238. }
  239. public byte[] Boot_Reset(object serial,byte[] Updatedata)
  240. {
  241. this.serial = (Serial)serial;
  242. byte[] fix_data = new byte[11];
  243. //Array.Clear(data, 0, data.Length);
  244. BootHeaderput(ref fix_data);
  245. fix_data[(int)Bluepro_t.bluecell_type] = (byte)Updateseq.Bluecell_Reset;
  246. fix_data[(int)Bluepro_t.bluecell_length_h] = 0;
  247. fix_data[(int)Bluepro_t.bluecell_length_l] = 5;
  248. fix_data[(int)Bluepro_t.bluecell_updatecnt_h] = Convert.ToByte((Updatedata.Length & 0xFF00) >> 8);
  249. fix_data[(int)Bluepro_t.bluecell_updatecnt_l] = Convert.ToByte((Updatedata.Length & 0x00FF));
  250. fix_data[(int)Bluepro_t.bluecell_data + 0] = Convert.ToByte((crc16.CRC16_Generate(fix_data, fix_data.Length - 4) & 0xFF00) >> 8);
  251. fix_data[(int)Bluepro_t.bluecell_data + 1] = Convert.ToByte((crc16.CRC16_Generate(fix_data, fix_data.Length - 4) & 0x00FF));
  252. this.serial.Serial_DataSend(fix_data, fix_data.Length);
  253. return fix_data;
  254. }
  255. public byte[] Boot_DataSending(byte[] update_data,UInt16 length, UInt16 updatacnt)
  256. {
  257. //Array.Clear(data, 0, data.Length);
  258. byte[] fix_data = new byte[bluecell_Firmupdate_sendlength];
  259. //BootHeaderput(ref fix_data);
  260. //length += 5;
  261. Array.Copy(update_data, (int)Bluepro_t.bluecell_data, fix_data, (int)Bluepro_t.bluecell_data, length);
  262. BootHeaderput(ref fix_data);
  263. fix_data[(int)Bluepro_t.bluecell_type] = (byte)Updateseq.Bluecell_Firmupdate_sending;
  264. fix_data[(int)Bluepro_t.bluecell_length_h] = Convert.ToByte((length & 0xFF00) >> 8);
  265. fix_data[(int)Bluepro_t.bluecell_length_l] = Convert.ToByte((length & 0x00FF));
  266. fix_data[(int)Bluepro_t.bluecell_updatecnt_h] = Convert.ToByte((updatacnt & 0xFF00) >> 8);
  267. fix_data[(int)Bluepro_t.bluecell_updatecnt_l] = Convert.ToByte((updatacnt & 0x00FF));
  268. //Array.Copy(update_data, 0, fix_data, (int)Bluepro_t.bluecell_data, length-3);
  269. fix_data[length + 9] = Convert.ToByte((crc16.CRC16_Generate(fix_data, length + 5) & 0xFF00) >> 8);
  270. fix_data[length + 10] = Convert.ToByte(crc16.CRC16_Generate(fix_data, length + 5) & 0x00FF);
  271. return fix_data;
  272. }
  273. public byte[] Boot_DataEnd(byte[] update_data, int length)
  274. {
  275. //Array.Clear(data, 0, data.Length);
  276. byte[] fix_data = new byte[11];
  277. Array.Copy(update_data, (int)Bluepro_t.bluecell_data, fix_data, (int)Bluepro_t.bluecell_data, length);
  278. BootHeaderput(ref fix_data);
  279. fix_data[(int)Bluepro_t.bluecell_type] = (byte)Updateseq.Bluecell_Firmupdate_end;
  280. fix_data[(int)Bluepro_t.bluecell_length_h] = Convert.ToByte((length & 0xFF00) >> 8);
  281. fix_data[(int)Bluepro_t.bluecell_length_l] = Convert.ToByte((length & 0x00FF));
  282. fix_data[(int)Bluepro_t.bluecell_updatecnt_h] = 0;
  283. fix_data[(int)Bluepro_t.bluecell_updatecnt_l] = 0;
  284. //Array.Copy(update_data, 0, fix_data, (int)Bluepro_t.bluecell_data, length-3);
  285. fix_data[length + 9] = Convert.ToByte((crc16.CRC16_Generate(fix_data, length + 5) & 0xFF00) >> 8);
  286. fix_data[length + 10] = Convert.ToByte(crc16.CRC16_Generate(fix_data, length + 5) & 0x00FF);
  287. return fix_data;
  288. }
  289. #endif
  290. }
  291. }