Bluecell_BootProtocol.cs 31 KB

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