Bluecell_BootProtocol.cs 33 KB

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