Bluecell_BootProtocol.cs 31 KB

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