Bluecell_BootProtocol.cs 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace RF_TRIO_PLL_ZIG
  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. };
  41. enum Bluecell_TypeIndex_t
  42. {
  43. ATT_1_8G_DL1 = 0,
  44. ATT_1_8G_DL2,
  45. ATT_1_8G_UL1,
  46. ATT_1_8G_UL2,
  47. ATT_1_8G_UL3,
  48. ATT_1_8G_UL4,
  49. ATT_2_1G_DL1,
  50. ATT_2_1G_DL2,
  51. ATT_2_1G_UL1,
  52. ATT_2_1G_UL2,
  53. ATT_2_1G_UL3,
  54. ATT_2_1G_UL4,
  55. ATT_3_5G_DL,
  56. ATT_3_5G_UL,
  57. ATT_3_5G_COM1,
  58. ATT_3_5G_COM2,
  59. ATT_3_5G_COM3,
  60. PLL_1_8G_DL_H,
  61. PLL_1_8G_DL_L,
  62. PLL_1_8G_UL_H,
  63. PLL_1_8G_UL_L,
  64. PLL_2_1G_DL_H,
  65. PLL_2_1G_DL_L,
  66. PLL_2_1G_UL_H,
  67. PLL_2_1G_UL_L,
  68. PLL_3_5G_DL_H,
  69. PLL_3_5G_DL_L,
  70. PLL_3_5G_UL_H,
  71. PLL_3_5G_UL_L,
  72. PLL_LD_6_BIT,
  73. DET_1_8G_DL_IN_H,
  74. DET_1_8G_DL_IN_L,
  75. DET_1_8G_DL_OUT_H,
  76. DET_1_8G_DL_OUT_L,
  77. DET_1_8G_UL_IN_H,
  78. DET_1_8G_UL_IN_L,
  79. DET_1_8G_UL_OUT_H,
  80. DET_1_8G_UL_OUT_L,
  81. DET_2_1G_DL_IN_H,
  82. DET_2_1G_DL_IN_L,
  83. DET_2_1G_DL_OUT_H,
  84. DET_2_1G_DL_OUT_L,
  85. DET_2_1G_UL_IN_H,
  86. DET_2_1G_UL_IN_L,
  87. DET_2_1G_UL_OUT_H,
  88. DET_2_1G_UL_OUT_L,
  89. DET_3_5G_DL_IN_H,
  90. DET_3_5G_DL_IN_L,
  91. DET_3_5G_DL_OUT_H,
  92. DET_3_5G_DL_OUT_L,
  93. DET_3_5G_UL_IN_H,
  94. DET_3_5G_UL_IN_L,
  95. DET_3_5G_UL_OUT_H,
  96. DET_3_5G_UL_OUT_L,
  97. RFU_TEMP_H,
  98. RFU_TEMP_L,
  99. _28V_DET_H,
  100. _28V_DET_L,
  101. ALARM_AC,
  102. ALARM_DC,
  103. PATH_EN_1_8G_DL,
  104. PATH_EN_1_8G_UL,
  105. PATH_EN_2_1G_DL,
  106. PATH_EN_2_1G_UL,
  107. PATH_EN_3_5G_L,
  108. PATH_EN_3_5G_H,
  109. PATH_EN_3_5G_DL,
  110. PATH_EN_3_5G_UL,
  111. PLL_ON_OFF_3_5G_H,
  112. PLL_ON_OFF_3_5G_L,
  113. T_SYNC_DL,
  114. _T_SYNC_DL,
  115. T_SYNC_UL,
  116. _T_SYNC_UL,
  117. DAC_VCtrl_A_H,
  118. DAC_VCtrl_A_L,
  119. DAC_VCtrl_B_H,
  120. DAC_VCtrl_B_L,
  121. DAC_VCtrl_C_H,
  122. DAC_VCtrl_C_L,
  123. DAC_VCtrl_D_H,
  124. DAC_VCtrl_D_L,
  125. DAC_VCtrl_E_H,
  126. DAC_VCtrl_E_L,
  127. DAC_VCtrl_F_H,
  128. DAC_VCtrl_F_L,
  129. DAC_VCtrl_G_H,
  130. DAC_VCtrl_G_L,
  131. DAC_VCtrl_H_H,
  132. DAC_VCtrl_H_L,
  133. };
  134. class Bluecell_BootProtocol
  135. {
  136. Serial serial;
  137. /*bluecell Header*/
  138. public const byte Bluecell_Header0 = 0x42;//ASCII : B
  139. public const byte Bluecell_Header1 = 0x4C;//ASCII : L
  140. public const byte Bluecell_Header2 = 0x55;//ASCII : U
  141. public const byte Bluecell_Header3 = 0x45;//ASCII : E
  142. /*bluecell type*/
  143. public const int bluecell_Firmupdate_sendlength = 1024;
  144. Crc16 crc16 = new Crc16();
  145. public const byte BLUECELL_HEADER = 0xBE;
  146. public const byte BLUECELL_TAILER = 0xEB;
  147. const byte BLUECELL_RESET_LENGTH = 6;
  148. const byte BLUECELL_FIX_DATA_LENGTH = 3;
  149. public void Bluecell_Reset(object serial)
  150. {
  151. this.serial = (Serial)serial;
  152. byte[] temp_buf = new byte[BLUECELL_RESET_LENGTH];
  153. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Header] = BLUECELL_HEADER;
  154. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type] = (byte)Bluecell_Prot_t.TYPE_BLUECELL_RESET;
  155. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Length] = BLUECELL_RESET_LENGTH - BLUECELL_FIX_DATA_LENGTH;
  156. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_CrcIndex] = (byte)Bluecell_ProtIndex_p.Bluecell_data;
  157. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data] = crc16.STH30_CreateCrc(temp_buf, BLUECELL_RESET_LENGTH - 3);
  158. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + 1] = BLUECELL_TAILER;
  159. this.serial.Serial_DataSend(temp_buf, temp_buf.Length);
  160. }
  161. private byte Bluecell_BDA4601_Calc(double data)
  162. {
  163. byte ret = 0;
  164. if (data == 31.5)
  165. ret = 0x3F;
  166. if (data >= 16) {
  167. ret |= 0x01;
  168. data -= 16;
  169. }
  170. if (data >= 8)
  171. {
  172. ret |= 0x02;
  173. data -= 8;
  174. }
  175. if (data >= 4)
  176. {
  177. ret |= 0x04;
  178. data -= 4;
  179. }
  180. if (data >= 2)
  181. {
  182. ret |= 0x08;
  183. data -= 2;
  184. }
  185. if (data >= 1)
  186. {
  187. ret |= 0x10;
  188. data -= 1;
  189. }
  190. if (data >= 0.5)
  191. {
  192. ret |= 0x20;
  193. data -= 0.5;
  194. }
  195. return ret;
  196. }
  197. private byte Bluecell_PE43711_Calc(double data)
  198. {
  199. byte ret = 0;
  200. if (data == 31.75)
  201. ret = 0x7F;
  202. if (data >= 16)
  203. {
  204. ret |= 0x40;
  205. data -= 16;
  206. }
  207. if (data >= 8)
  208. {
  209. ret |= 0x20;
  210. data -= 8;
  211. }
  212. if (data >= 4)
  213. {
  214. ret |= 0x10;
  215. data -= 4;
  216. }
  217. if (data >= 2)
  218. {
  219. ret |= 0x08;
  220. data -= 2;
  221. }
  222. if (data >= 1)
  223. {
  224. ret |= 0x04;
  225. data -= 1;
  226. }
  227. if (data >= 0.5)
  228. {
  229. ret |= 0x02;
  230. data -= 0.5;
  231. }
  232. if (data >= 0.25)
  233. {
  234. ret |= 0x01;
  235. data -= 0.25;
  236. }
  237. return ret;
  238. }
  239. const byte BLUECELL_DATA_SET_LENGTH = (byte)Bluecell_TypeIndex_t.DAC_VCtrl_H_L + 3 + 3 + 1;
  240. Main_Form main_Form;
  241. public void Bluecell_BtnSet(object serial, object main_form)
  242. {
  243. this.main_Form = (Main_Form)main_form;
  244. this.serial = (Serial)serial;
  245. byte[] temp_buf = new byte[BLUECELL_DATA_SET_LENGTH];
  246. UInt32 temp_val = 0;
  247. /* * * * * * FIX DATA * * * * * */
  248. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Header] = BLUECELL_HEADER;
  249. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type] = (byte)Bluecell_Prot_t.TYPE_BLUECELL_SET;
  250. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Length] = BLUECELL_DATA_SET_LENGTH - BLUECELL_FIX_DATA_LENGTH;
  251. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_CrcIndex] = (byte)BLUECELL_DATA_SET_LENGTH - 2;
  252. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.ATT_1_8G_DL1] = Bluecell_BDA4601_Calc(Convert.ToDouble(main_Form.numericUpDown_ATT_1_8G_DL1.Text));
  253. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.ATT_1_8G_DL2] = Bluecell_BDA4601_Calc(Convert.ToDouble(main_Form.numericUpDown_ATT_1_8G_DL2.Text));
  254. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.ATT_1_8G_UL1] = Bluecell_BDA4601_Calc(Convert.ToDouble(main_Form.numericUpDown_ATT_1_8G_UL1.Text));
  255. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.ATT_1_8G_UL2] = Bluecell_BDA4601_Calc(Convert.ToDouble(main_Form.numericUpDown_ATT_1_8G_UL2.Text));
  256. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.ATT_1_8G_UL3] = Bluecell_BDA4601_Calc(Convert.ToDouble(main_Form.numericUpDown_ATT_1_8G_UL3.Text));
  257. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.ATT_1_8G_UL4] = Bluecell_BDA4601_Calc(Convert.ToDouble(main_Form.numericUpDown_ATT_1_8G_UL4.Text));
  258. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.ATT_2_1G_DL1] = Bluecell_BDA4601_Calc(Convert.ToDouble(main_Form.numericUpDown_ATT_2_1G_DL1.Text));
  259. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.ATT_2_1G_DL2] = Bluecell_BDA4601_Calc(Convert.ToDouble(main_Form.numericUpDown_ATT_2_1G_DL2.Text));
  260. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.ATT_2_1G_UL1] = Bluecell_BDA4601_Calc(Convert.ToDouble(main_Form.numericUpDown_ATT_2_1G_UL1.Text));
  261. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.ATT_2_1G_UL2] = Bluecell_BDA4601_Calc(Convert.ToDouble(main_Form.numericUpDown_ATT_2_1G_UL2.Text));
  262. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.ATT_2_1G_UL3] = Bluecell_BDA4601_Calc(Convert.ToDouble(main_Form.numericUpDown_ATT_2_1G_UL3.Text));
  263. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.ATT_2_1G_UL4] = Bluecell_BDA4601_Calc(Convert.ToDouble(main_Form.numericUpDown_ATT_2_1G_UL4.Text));
  264. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.ATT_3_5G_DL] = Bluecell_PE43711_Calc(Convert.ToDouble(main_Form.numericUpDown_ATT_3_5G_DL.Text));
  265. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.ATT_3_5G_UL] = Bluecell_PE43711_Calc(Convert.ToDouble(main_Form.numericUpDown_ATT_3_5G_UL.Text));
  266. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.ATT_3_5G_COM1] = Bluecell_PE43711_Calc(Convert.ToDouble(main_Form.numericUpDown_ATT_3_5G_COM1.Text));
  267. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.ATT_3_5G_COM2] = Bluecell_PE43711_Calc(Convert.ToDouble(main_Form.numericUpDown_ATT_3_5G_COM2.Text));
  268. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.ATT_3_5G_COM3] = Bluecell_PE43711_Calc(Convert.ToDouble(main_Form.numericUpDown_ATT_3_5G_COM3.Text));
  269. temp_val = Convert.ToUInt32(Convert.ToDouble(main_Form.numericUpDown_PLL_1_8G_DL.Text) * 10);
  270. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.PLL_1_8G_DL_H] = Convert.ToByte((temp_val & 0xFF00) >> 8);
  271. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.PLL_1_8G_DL_L] = Convert.ToByte((temp_val & 0x00FF));
  272. temp_val = Convert.ToUInt32(Convert.ToDouble(main_Form.numericUpDown_PLL_1_8G_UL.Text) * 10);
  273. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.PLL_1_8G_UL_H] = Convert.ToByte((temp_val & 0xFF00) >> 8);
  274. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.PLL_1_8G_UL_L] = Convert.ToByte((temp_val & 0x00FF));
  275. temp_val = Convert.ToUInt32(Convert.ToDouble(main_Form.numericUpDown_PLL_2_1G_DL.Text) * 10);
  276. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.PLL_2_1G_DL_H] = Convert.ToByte((temp_val & 0xFF00) >> 8);
  277. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.PLL_2_1G_DL_L] = Convert.ToByte((temp_val & 0x00FF));
  278. temp_val = Convert.ToUInt32(Convert.ToDouble(main_Form.numericUpDown_PLL_2_1G_UL.Text) * 10);
  279. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.PLL_2_1G_UL_H] = Convert.ToByte((temp_val & 0xFF00) >> 8);
  280. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.PLL_2_1G_UL_L] = Convert.ToByte((temp_val & 0x00FF));
  281. temp_val = Convert.ToUInt32(Convert.ToDouble(main_Form.numericUpDown_PLL_3_5G_DL.Text) * 10);
  282. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.PLL_3_5G_DL_H] = Convert.ToByte((temp_val & 0xFF00) >> 8);
  283. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.PLL_3_5G_DL_L] = Convert.ToByte((temp_val & 0x00FF));
  284. temp_val = Convert.ToUInt32(Convert.ToDouble(main_Form.numericUpDown_PLL_3_5G_UL.Text) * 10);
  285. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.PLL_3_5G_UL_H] = Convert.ToByte((temp_val & 0xFF00) >> 8);
  286. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.PLL_3_5G_UL_L] = Convert.ToByte((temp_val & 0x00FF));
  287. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.PLL_LD_6_BIT] = 0;//Convert.ToByte(main_Form.numericUpDown_ATT_3_5G_COM1.Text);
  288. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DET_1_8G_DL_IN_H] = 0;// Convert.ToByte(main_Form.numericUpDown_ATT_3_5G_COM1.Text);
  289. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DET_1_8G_DL_IN_L] = 0;// Convert.ToByte(main_Form.numericUpDown_ATT_3_5G_COM1.Text);
  290. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DET_1_8G_DL_OUT_H] = 0;
  291. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DET_1_8G_DL_OUT_L] = 0;
  292. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DET_1_8G_UL_IN_H] = 0;
  293. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DET_1_8G_UL_IN_L] = 0;
  294. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DET_1_8G_UL_OUT_H] = 0;
  295. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DET_1_8G_UL_OUT_L] = 0;
  296. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DET_2_1G_DL_IN_H] = 0;
  297. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DET_2_1G_DL_IN_L] = 0;
  298. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DET_2_1G_DL_OUT_H] = 0;
  299. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DET_2_1G_DL_OUT_L] = 0;
  300. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DET_2_1G_UL_IN_H] = 0;
  301. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DET_2_1G_UL_IN_L] = 0;
  302. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DET_2_1G_UL_OUT_H] = 0;
  303. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DET_2_1G_UL_OUT_L] = 0;
  304. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DET_3_5G_DL_IN_H] = 0;
  305. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DET_3_5G_DL_IN_L] = 0;
  306. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DET_3_5G_DL_OUT_L] = 0;
  307. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DET_3_5G_DL_OUT_H] = 0;
  308. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DET_3_5G_UL_IN_H] = 0;
  309. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DET_3_5G_UL_IN_L] = 0;
  310. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DET_3_5G_UL_OUT_H] = 0;
  311. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DET_3_5G_UL_OUT_L] = 0;
  312. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.RFU_TEMP_H] = 0;
  313. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.RFU_TEMP_L] = 0;
  314. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t._28V_DET_H] = 0;
  315. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t._28V_DET_L] = 0;
  316. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.ALARM_AC] = 0;
  317. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.ALARM_DC] = 0;
  318. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.PATH_EN_1_8G_DL] = Convert.ToByte(PATH_1_8G_DL_Get_Func());
  319. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.PATH_EN_1_8G_UL] = Convert.ToByte(PATH_1_8G_UL_Get_Func());
  320. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.PATH_EN_2_1G_DL] = Convert.ToByte(PATH_2_1G_DL_Get_Func());
  321. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.PATH_EN_2_1G_UL] = Convert.ToByte(PATH_2_1G_UL_Get_Func());
  322. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.PATH_EN_3_5G_L] = Convert.ToByte(Path_3_5G_L_Get_Func());
  323. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.PATH_EN_3_5G_H] = Convert.ToByte(Path_3_5G_H_Get_Func());
  324. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.PATH_EN_3_5G_DL] = Convert.ToByte(PATH_3_5G_DL_Get_Func());
  325. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.PATH_EN_3_5G_UL] = Convert.ToByte(PATH_3_5G_UL_Get_Func());
  326. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.PLL_ON_OFF_3_5G_H] = Convert.ToByte(PLL_ON_OFF_3_5G_H_Get_Func());
  327. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.PLL_ON_OFF_3_5G_L] = Convert.ToByte(PLL_ON_OFF_3_5G_L_Get_Func());
  328. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.T_SYNC_DL] = main_Form.Tdd_T_Sync;//Convert.ToByte(PATH_3_5G_DL_Get_Func());
  329. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t._T_SYNC_DL] = main_Form.Tdd_T_Sync;//Convert.ToByte(PATH_3_5G_DL_Get_Func());
  330. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.T_SYNC_UL] = main_Form.Tdd_T_Sync;//Convert.ToByte(PLL_ON_OFF_3_5G_H_Get_Func());
  331. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t._T_SYNC_UL] = main_Form.Tdd_T_Sync;//Convert.ToByte(PLL_ON_OFF_3_5G_L_Get_Func());
  332. double double_temp = Convert.ToDouble(main_Form.numericUpDown_DAC_VoltCtrl_A.Text) * 4095;
  333. UInt16 temp = Convert.ToUInt16(double_temp / 4);
  334. temp = Convert.ToUInt16(temp & 0xFF00);
  335. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DAC_VCtrl_A_H]
  336. = Convert.ToByte(0x00 + Convert.ToByte(temp >> 8));
  337. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DAC_VCtrl_A_L]
  338. = Convert.ToByte(Convert.ToUInt16((Convert.ToDouble(main_Form.numericUpDown_DAC_VoltCtrl_A.Text) * 4095) / 4) & 0x00FF);
  339. double_temp = Convert.ToDouble(main_Form.numericUpDown_DAC_VoltCtrl_B.Text) * 4095;
  340. temp = Convert.ToUInt16(double_temp / 4);
  341. temp = Convert.ToUInt16(temp & 0xFF00);
  342. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DAC_VCtrl_B_H]
  343. = Convert.ToByte(0x10 + Convert.ToByte(temp >> 8));
  344. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DAC_VCtrl_B_L]
  345. = Convert.ToByte(Convert.ToUInt16((Convert.ToDouble(main_Form.numericUpDown_DAC_VoltCtrl_B.Text) * 4095) / 4) & 0x00FF);
  346. double_temp = Convert.ToDouble(main_Form.numericUpDown_DAC_VoltCtrl_C.Text) * 4095;
  347. temp = Convert.ToUInt16(double_temp / 4);
  348. temp = Convert.ToUInt16(temp & 0xFF00);
  349. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DAC_VCtrl_C_H]
  350. = Convert.ToByte(0x20 + Convert.ToByte(temp >> 8));
  351. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DAC_VCtrl_C_L]
  352. = Convert.ToByte(Convert.ToUInt16((Convert.ToDouble(main_Form.numericUpDown_DAC_VoltCtrl_C.Text) * 4095) / 4) & 0x00FF);
  353. double_temp = Convert.ToDouble(main_Form.numericUpDown_DAC_VoltCtrl_D.Text) * 4095;
  354. temp = Convert.ToUInt16(double_temp / 4);
  355. temp = Convert.ToUInt16(temp & 0xFF00);
  356. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DAC_VCtrl_D_H]
  357. = Convert.ToByte(0x30 + Convert.ToByte(temp >> 8));
  358. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DAC_VCtrl_D_L]
  359. = Convert.ToByte(Convert.ToUInt16((Convert.ToDouble(main_Form.numericUpDown_DAC_VoltCtrl_D.Text) * 4095) / 4) & 0x00FF); ;
  360. double_temp = Convert.ToDouble(main_Form.numericUpDown_DAC_VoltCtrl_E.Text) * 4095;
  361. temp = Convert.ToUInt16(double_temp / 4);
  362. temp = Convert.ToUInt16(temp & 0xFF00);
  363. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DAC_VCtrl_E_H]
  364. = Convert.ToByte(0x40 + Convert.ToByte(temp >> 8));
  365. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DAC_VCtrl_E_L]
  366. = Convert.ToByte(Convert.ToUInt16((Convert.ToDouble(main_Form.numericUpDown_DAC_VoltCtrl_E.Text) * 4095) / 4) & 0x00FF);
  367. double_temp = Convert.ToDouble(main_Form.numericUpDown_DAC_VoltCtrl_F.Text) * 4095;
  368. temp = Convert.ToUInt16(double_temp / 4);
  369. temp = Convert.ToUInt16(temp & 0xFF00);
  370. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DAC_VCtrl_F_H]
  371. = Convert.ToByte(0x50 + Convert.ToByte(temp >> 8));
  372. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DAC_VCtrl_F_L]
  373. = Convert.ToByte(Convert.ToUInt16((Convert.ToDouble(main_Form.numericUpDown_DAC_VoltCtrl_F.Text) * 4095) / 4) & 0x00FF);
  374. double_temp = Convert.ToDouble(main_Form.numericUpDown_DAC_VoltCtrl_G.Text) * 4095;
  375. temp = Convert.ToUInt16(double_temp / 4);
  376. temp = Convert.ToUInt16(temp & 0xFF00);
  377. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DAC_VCtrl_G_H]
  378. = Convert.ToByte(0x60 + Convert.ToByte(temp >> 8));
  379. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DAC_VCtrl_G_L]
  380. = Convert.ToByte(Convert.ToUInt16((Convert.ToDouble(main_Form.numericUpDown_DAC_VoltCtrl_G.Text) * 4095) / 4) & 0x00FF);
  381. double_temp = Convert.ToDouble(main_Form.numericUpDown_DAC_VoltCtrl_H.Text) * 4095;
  382. temp = Convert.ToUInt16(double_temp / 4);
  383. temp = Convert.ToUInt16(temp & 0xFF00);
  384. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DAC_VCtrl_H_H]
  385. = Convert.ToByte(0x70 + Convert.ToByte(temp >> 8));
  386. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DAC_VCtrl_H_L]
  387. = Convert.ToByte(Convert.ToUInt16((Convert.ToDouble(main_Form.numericUpDown_DAC_VoltCtrl_H.Text) * 4095) / 4) & 0x00FF);
  388. /* * * * * * FIX DATA * * * * * */
  389. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DAC_VCtrl_H_L + 1]
  390. = crc16.STH30_CreateCrc(temp_buf, BLUECELL_DATA_SET_LENGTH - 3);
  391. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DAC_VCtrl_H_L + 2]
  392. = BLUECELL_TAILER;
  393. this.serial.Serial_DataSend(temp_buf, temp_buf.Length);
  394. }
  395. int[] RF_Status = new int[BLUECELL_DATA_SET_LENGTH];
  396. private delegate void StringSend(string Text);
  397. private delegate void ByteSend(byte[] Text);
  398. public void Bluecell_RF_Status_Get(object serial, object main_form,byte[] temp_buf)
  399. {
  400. this.main_Form = (Main_Form)main_form;
  401. this.serial = (Serial)serial;
  402. this.main_Form.ADC_Voltage_Value_Set(temp_buf);
  403. //Debug.Invoke(new StringSend(Debug.Data_Recv_Str), data);
  404. //main_Form.label1_8GHz_DL_OUT.Text = Convert.ToString(temp_val);
  405. }
  406. bool PATH_1_8G_UL_Get_Func()
  407. {
  408. bool ret = false;
  409. if (this.main_Form.pictureBox_PATH_1_8G_UL_OFF.Visible == true)
  410. ret = false;
  411. else
  412. ret = true;
  413. return ret;
  414. }
  415. bool PATH_1_8G_DL_Get_Func()
  416. {
  417. bool ret = false;
  418. if (this.main_Form.pictureBox_PATH_1_8G_DL_OFF.Visible == true)
  419. ret = false;
  420. else
  421. ret = true;
  422. return ret;
  423. }
  424. bool PATH_2_1G_UL_Get_Func()
  425. {
  426. bool ret = false;
  427. if (this.main_Form.pictureBox_PATH_2_1G_UL_OFF.Visible == true)
  428. ret = false;
  429. else
  430. ret = true;
  431. return ret;
  432. }
  433. bool PATH_2_1G_DL_Get_Func()
  434. {
  435. bool ret = false;
  436. if (this.main_Form.pictureBox_PATH_2_1G_DL_OFF.Visible == true)
  437. ret = false;
  438. else
  439. ret = true;
  440. return ret;
  441. }
  442. bool Path_3_5G_L_Get_Func()
  443. {
  444. bool ret = false;
  445. if (this.main_Form.pictureBox_PATH_3_5G_L_OFF.Visible == true)
  446. ret = false;
  447. else
  448. ret = true;
  449. return ret;
  450. }
  451. bool Path_3_5G_H_Get_Func()
  452. {
  453. bool ret = false;
  454. if (this.main_Form.pictureBox_PATH_3_5G_H_OFF.Visible == true)
  455. ret = false;
  456. else
  457. ret = true;
  458. return ret;
  459. }
  460. bool PLL_ON_OFF_3_5G_L_Get_Func()
  461. {
  462. bool ret = false;
  463. if (this.main_Form.pictureBox_PLL_ON_OFF_3_5G_L_OFF.Visible == true)
  464. ret = false;
  465. else
  466. ret = true;
  467. return ret;
  468. }
  469. bool PLL_ON_OFF_3_5G_H_Get_Func()
  470. {
  471. bool ret = false;
  472. if (this.main_Form.pictureBox_PLL_ON_OFF_3_5G_H_OFF.Visible == true)
  473. ret = false;
  474. else
  475. ret = true;
  476. return ret;
  477. }
  478. bool PATH_3_5G_UL_Get_Func()
  479. {
  480. bool ret = false;
  481. if (this.main_Form.pictureBox_PATH_3_5G_UL_OFF.Visible == true)
  482. ret = false;
  483. else
  484. ret = true;
  485. return ret;
  486. }
  487. bool PATH_3_5G_DL_Get_Func()
  488. {
  489. bool ret = false;
  490. if (this.main_Form.pictureBox_PATH_3_5G_DL_OFF.Visible == true)
  491. ret = false;
  492. else
  493. ret = true;
  494. return ret;
  495. }
  496. /* public System.Windows.Forms.PictureBox pictureBox_PATH_3_5G_L_OFF;
  497. public System.Windows.Forms.PictureBox pictureBox_PATH_3_5G_H_OFF;
  498. public System.Windows.Forms.PictureBox pictureBox_PLL_ON_OFF_3_5G_L_OFF;
  499. public System.Windows.Forms.PictureBox pictureBox_PLL_ON_OFF_3_5G_H_OFF;
  500. public System.Windows.Forms.PictureBox pictureBox_PATH_3_5G_UL_OFF;
  501. public System.Windows.Forms.PictureBox pictureBox_PATH_3_5G_DL_OFF;
  502. public System.Windows.Forms.PictureBox pictureBox_PATH_2_1G_UL_OFF;
  503. public System.Windows.Forms.PictureBox pictureBox_PATH_2_1G_DL_OFF;
  504. public System.Windows.Forms.PictureBox pictureBox_PATH_1_8G_UL_OFF;
  505. public System.Windows.Forms.PictureBox pictureBox_PATH_1_8G_DL_OFF;
  506. */
  507. #if false
  508. public int Bluecell_Firmupdate_sendlength() {
  509. return bluecell_Firmupdate_sendlength;
  510. }
  511. private void BootHeaderput(ref byte[] fix_data)
  512. {
  513. fix_data[(int)Bluepro_t.bluecell_header0] = Bluecell_Header0;
  514. fix_data[(int)Bluepro_t.bluecell_header1] = Bluecell_Header1;
  515. fix_data[(int)Bluepro_t.bluecell_header2] = Bluecell_Header2;
  516. fix_data[(int)Bluepro_t.bluecell_header3] = Bluecell_Header3;
  517. }
  518. public byte[] Boot_Reset(object serial,byte[] Updatedata)
  519. {
  520. this.serial = (Serial)serial;
  521. byte[] fix_data = new byte[11];
  522. //Array.Clear(data, 0, data.Length);
  523. BootHeaderput(ref fix_data);
  524. fix_data[(int)Bluepro_t.bluecell_type] = (byte)Updateseq.Bluecell_Reset;
  525. fix_data[(int)Bluepro_t.bluecell_length_h] = 0;
  526. fix_data[(int)Bluepro_t.bluecell_length_l] = 5;
  527. fix_data[(int)Bluepro_t.bluecell_updatecnt_h] = Convert.ToByte((Updatedata.Length & 0xFF00) >> 8);
  528. fix_data[(int)Bluepro_t.bluecell_updatecnt_l] = Convert.ToByte((Updatedata.Length & 0x00FF));
  529. fix_data[(int)Bluepro_t.bluecell_data + 0] = Convert.ToByte((crc16.CRC16_Generate(fix_data, fix_data.Length - 4) & 0xFF00) >> 8);
  530. fix_data[(int)Bluepro_t.bluecell_data + 1] = Convert.ToByte((crc16.CRC16_Generate(fix_data, fix_data.Length - 4) & 0x00FF));
  531. this.serial.Serial_DataSend(fix_data, fix_data.Length);
  532. return fix_data;
  533. }
  534. public byte[] Boot_DataSending(byte[] update_data,UInt16 length, UInt16 updatacnt)
  535. {
  536. //Array.Clear(data, 0, data.Length);
  537. byte[] fix_data = new byte[bluecell_Firmupdate_sendlength];
  538. //BootHeaderput(ref fix_data);
  539. //length += 5;
  540. Array.Copy(update_data, (int)Bluepro_t.bluecell_data, fix_data, (int)Bluepro_t.bluecell_data, length);
  541. BootHeaderput(ref fix_data);
  542. fix_data[(int)Bluepro_t.bluecell_type] = (byte)Updateseq.Bluecell_Firmupdate_sending;
  543. fix_data[(int)Bluepro_t.bluecell_length_h] = Convert.ToByte((length & 0xFF00) >> 8);
  544. fix_data[(int)Bluepro_t.bluecell_length_l] = Convert.ToByte((length & 0x00FF));
  545. fix_data[(int)Bluepro_t.bluecell_updatecnt_h] = Convert.ToByte((updatacnt & 0xFF00) >> 8);
  546. fix_data[(int)Bluepro_t.bluecell_updatecnt_l] = Convert.ToByte((updatacnt & 0x00FF));
  547. //Array.Copy(update_data, 0, fix_data, (int)Bluepro_t.bluecell_data, length-3);
  548. fix_data[length + 9] = Convert.ToByte((crc16.CRC16_Generate(fix_data, length + 5) & 0xFF00) >> 8);
  549. fix_data[length + 10] = Convert.ToByte(crc16.CRC16_Generate(fix_data, length + 5) & 0x00FF);
  550. return fix_data;
  551. }
  552. public byte[] Boot_DataEnd(byte[] update_data, int length)
  553. {
  554. //Array.Clear(data, 0, data.Length);
  555. byte[] fix_data = new byte[11];
  556. Array.Copy(update_data, (int)Bluepro_t.bluecell_data, fix_data, (int)Bluepro_t.bluecell_data, length);
  557. BootHeaderput(ref fix_data);
  558. fix_data[(int)Bluepro_t.bluecell_type] = (byte)Updateseq.Bluecell_Firmupdate_end;
  559. fix_data[(int)Bluepro_t.bluecell_length_h] = Convert.ToByte((length & 0xFF00) >> 8);
  560. fix_data[(int)Bluepro_t.bluecell_length_l] = Convert.ToByte((length & 0x00FF));
  561. fix_data[(int)Bluepro_t.bluecell_updatecnt_h] = 0;
  562. fix_data[(int)Bluepro_t.bluecell_updatecnt_l] = 0;
  563. //Array.Copy(update_data, 0, fix_data, (int)Bluepro_t.bluecell_data, length-3);
  564. fix_data[length + 9] = Convert.ToByte((crc16.CRC16_Generate(fix_data, length + 5) & 0xFF00) >> 8);
  565. fix_data[length + 10] = Convert.ToByte(crc16.CRC16_Generate(fix_data, length + 5) & 0x00FF);
  566. return fix_data;
  567. }
  568. #endif
  569. }
  570. }