Bluecell_BootProtocol.cs 32 KB

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