Bluecell_BootProtocol.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793
  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_DL_H,
  77. PLL_3_5G_DL_L,
  78. PLL_3_5G_UL_H,
  79. PLL_3_5G_UL_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. /* * * * * * FIX DATA * * * * * */
  322. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Header] = BLUECELL_HEADER;
  323. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type] = (byte)Bluecell_Prot_t.TYPE_BLUECELL_SET;
  324. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Length] = BLUECELL_DATA_SET_LENGTH - BLUECELL_FIX_DATA_LENGTH;
  325. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_CrcIndex] = (byte)BLUECELL_DATA_SET_LENGTH - 2;
  326. temp_buf[(int)Bluecell_TypeIndex_t.ATT_1_8G_DL1] = Bluecell_BDA4601_Calc(Convert.ToDouble(main_Form.numericUpDown_ATT_1_8G_DL1.Text));
  327. temp_buf[(int)Bluecell_TypeIndex_t.ATT_1_8G_DL2] = Bluecell_BDA4601_Calc(Convert.ToDouble(main_Form.numericUpDown_ATT_1_8G_DL2.Text));
  328. temp_buf[(int)Bluecell_TypeIndex_t.ATT_1_8G_UL1] = Bluecell_BDA4601_Calc(Convert.ToDouble(main_Form.numericUpDown_ATT_1_8G_UL1.Text));
  329. temp_buf[(int)Bluecell_TypeIndex_t.ATT_1_8G_UL2] = Bluecell_BDA4601_Calc(Convert.ToDouble(main_Form.numericUpDown_ATT_1_8G_UL2.Text));
  330. temp_buf[(int)Bluecell_TypeIndex_t.ATT_1_8G_UL3] = Bluecell_BDA4601_Calc(Convert.ToDouble(main_Form.numericUpDown_ATT_1_8G_UL3.Text));
  331. temp_buf[(int)Bluecell_TypeIndex_t.ATT_1_8G_UL4] = Bluecell_BDA4601_Calc(Convert.ToDouble(main_Form.numericUpDown_ATT_1_8G_UL4.Text));
  332. temp_buf[(int)Bluecell_TypeIndex_t.ATT_2_1G_DL1] = Bluecell_BDA4601_Calc(Convert.ToDouble(main_Form.numericUpDown_ATT_2_1G_DL1.Text));
  333. temp_buf[(int)Bluecell_TypeIndex_t.ATT_2_1G_DL2] = Bluecell_BDA4601_Calc(Convert.ToDouble(main_Form.numericUpDown_ATT_2_1G_DL2.Text));
  334. temp_buf[(int)Bluecell_TypeIndex_t.ATT_2_1G_UL1] = Bluecell_BDA4601_Calc(Convert.ToDouble(main_Form.numericUpDown_ATT_2_1G_UL1.Text));
  335. temp_buf[(int)Bluecell_TypeIndex_t.ATT_2_1G_UL2] = Bluecell_BDA4601_Calc(Convert.ToDouble(main_Form.numericUpDown_ATT_2_1G_UL2.Text));
  336. temp_buf[(int)Bluecell_TypeIndex_t.ATT_2_1G_UL3] = Bluecell_BDA4601_Calc(Convert.ToDouble(main_Form.numericUpDown_ATT_2_1G_UL3.Text));
  337. temp_buf[(int)Bluecell_TypeIndex_t.ATT_2_1G_UL4] = Bluecell_BDA4601_Calc(Convert.ToDouble(main_Form.numericUpDown_ATT_2_1G_UL4.Text));
  338. temp_buf[(int)Bluecell_TypeIndex_t.ATT_3_5G_LOW1] = Bluecell_PE43711_Calc(Convert.ToDouble(main_Form.numericUpDown_ATT_3_5G_LOW1.Text));
  339. temp_buf[(int)Bluecell_TypeIndex_t.ATT_3_5G_HIGH1] = Bluecell_PE43711_Calc(Convert.ToDouble(main_Form.numericUpDown_ATT_3_5G_HIGH1.Text));
  340. temp_buf[(int)Bluecell_TypeIndex_t.ATT_3_5G_COM1] = Bluecell_PE43711_Calc(Convert.ToDouble(main_Form.numericUpDown_ATT_3_5G_COM1.Text));
  341. temp_buf[(int)Bluecell_TypeIndex_t.ATT_3_5G_LOW2] = Bluecell_PE43711_Calc(Convert.ToDouble(main_Form.numericUpDown_ATT_3_5G_LOW2.Text));
  342. temp_buf[(int)Bluecell_TypeIndex_t.ATT_3_5G_HIGH2] = Bluecell_PE43711_Calc(Convert.ToDouble(main_Form.numericUpDown_ATT_3_5G_HIGH2.Text));
  343. temp_buf[(int)Bluecell_TypeIndex_t.ATT_3_5G_COM2] = Bluecell_PE43711_Calc(Convert.ToDouble(main_Form.numericUpDown_ATT_3_5G_COM2.Text));
  344. if (Convert.ToDouble(main_Form.numericUpDown_PLL_1_8G_DL.Text) > 0)
  345. {
  346. temp_val = (Convert.ToUInt32(Convert.ToDouble(main_Form.numericUpDown_PLL_1_8G_DL.Text) - 220) * 10);
  347. }
  348. else
  349. {
  350. temp_val = 0;
  351. }
  352. temp_buf[(int)Bluecell_TypeIndex_t.PLL_1_8G_DL_H] = Convert.ToByte((temp_val & 0xFF00) >> 8);
  353. temp_buf[(int)Bluecell_TypeIndex_t.PLL_1_8G_DL_L] = Convert.ToByte((temp_val & 0x00FF));
  354. if (Convert.ToDouble(main_Form.numericUpDown_PLL_1_8G_UL.Text) > 0)
  355. {
  356. temp_val = (Convert.ToUInt32(Convert.ToDouble(main_Form.numericUpDown_PLL_1_8G_UL.Text) - 270) * 10);
  357. }
  358. else
  359. {
  360. temp_val = 0;
  361. }
  362. temp_buf[(int)Bluecell_TypeIndex_t.PLL_1_8G_UL_H] = Convert.ToByte((temp_val & 0xFF00) >> 8);
  363. temp_buf[(int)Bluecell_TypeIndex_t.PLL_1_8G_UL_L] = Convert.ToByte((temp_val & 0x00FF));
  364. if (Convert.ToDouble(main_Form.numericUpDown_PLL_2_1G_DL.Text) > 0)
  365. {
  366. temp_val = (Convert.ToUInt32(Convert.ToDouble(main_Form.numericUpDown_PLL_2_1G_DL.Text) - 145) * 10);
  367. }
  368. else
  369. {
  370. temp_val = 0;
  371. }
  372. temp_buf[(int)Bluecell_TypeIndex_t.PLL_2_1G_DL_H] = Convert.ToByte((temp_val & 0xFF00) >> 8);
  373. temp_buf[(int)Bluecell_TypeIndex_t.PLL_2_1G_DL_L] = Convert.ToByte((temp_val & 0x00FF));
  374. if(Convert.ToDouble(main_Form.numericUpDown_PLL_2_1G_UL.Text) > 0)
  375. {
  376. temp_val = (Convert.ToUInt32(Convert.ToDouble(main_Form.numericUpDown_PLL_2_1G_UL.Text) + 345) * 10);
  377. }
  378. else
  379. {
  380. temp_val = 0;
  381. }
  382. temp_buf[(int)Bluecell_TypeIndex_t.PLL_2_1G_UL_H] = Convert.ToByte((temp_val & 0xFF00) >> 8);
  383. temp_buf[(int)Bluecell_TypeIndex_t.PLL_2_1G_UL_L] = Convert.ToByte((temp_val & 0x00FF));
  384. temp_val = Convert.ToUInt32(Convert.ToDouble(main_Form.numericUpDown_PLL_3_5G_DL.Text) * 10);
  385. temp_buf[(int)Bluecell_TypeIndex_t.PLL_3_5G_DL_H] = Convert.ToByte((temp_val & 0xFF00) >> 8);
  386. temp_buf[(int)Bluecell_TypeIndex_t.PLL_3_5G_DL_L] = Convert.ToByte((temp_val & 0x00FF));
  387. temp_val = Convert.ToUInt32(Convert.ToDouble(main_Form.numericUpDown_PLL_3_5G_UL.Text) * 10);
  388. temp_buf[(int)Bluecell_TypeIndex_t.PLL_3_5G_UL_H] = Convert.ToByte((temp_val & 0xFF00) >> 8);
  389. temp_buf[(int)Bluecell_TypeIndex_t.PLL_3_5G_UL_L] = Convert.ToByte((temp_val & 0x00FF));
  390. temp_buf[(int)Bluecell_TypeIndex_t.PLL_LD_6_BIT] = 0;//Convert.ToByte(main_Form.numericUpDown_ATT_3_5G_COM1.Text);
  391. temp_buf[(int)Bluecell_TypeIndex_t.DET_1_8G_DL_IN_H] = 0;// Convert.ToByte(main_Form.numericUpDown_ATT_3_5G_COM1.Text);
  392. temp_buf[(int)Bluecell_TypeIndex_t.DET_1_8G_DL_IN_L] = 0;// Convert.ToByte(main_Form.numericUpDown_ATT_3_5G_COM1.Text);
  393. temp_buf[(int)Bluecell_TypeIndex_t.DET_1_8G_DL_OUT_H] = 0;
  394. temp_buf[(int)Bluecell_TypeIndex_t.DET_1_8G_DL_OUT_L] = 0;
  395. temp_buf[(int)Bluecell_TypeIndex_t.DET_1_8G_UL_IN_H] = 0;
  396. temp_buf[(int)Bluecell_TypeIndex_t.DET_1_8G_UL_IN_L] = 0;
  397. temp_buf[(int)Bluecell_TypeIndex_t.DET_1_8G_UL_OUT_H] = 0;
  398. temp_buf[(int)Bluecell_TypeIndex_t.DET_1_8G_UL_OUT_L] = 0;
  399. temp_buf[(int)Bluecell_TypeIndex_t.DET_2_1G_DL_IN_H] = 0;
  400. temp_buf[(int)Bluecell_TypeIndex_t.DET_2_1G_DL_IN_L] = 0;
  401. temp_buf[(int)Bluecell_TypeIndex_t.DET_2_1G_DL_OUT_H] = 0;
  402. temp_buf[(int)Bluecell_TypeIndex_t.DET_2_1G_DL_OUT_L] = 0;
  403. temp_buf[(int)Bluecell_TypeIndex_t.DET_2_1G_UL_IN_H] = 0;
  404. temp_buf[(int)Bluecell_TypeIndex_t.DET_2_1G_UL_IN_L] = 0;
  405. temp_buf[(int)Bluecell_TypeIndex_t.DET_2_1G_UL_OUT_H] = 0;
  406. temp_buf[(int)Bluecell_TypeIndex_t.DET_2_1G_UL_OUT_L] = 0;
  407. temp_buf[(int)Bluecell_TypeIndex_t.DET_3_5G_DL_IN_H] = 0;
  408. temp_buf[(int)Bluecell_TypeIndex_t.DET_3_5G_DL_IN_L] = 0;
  409. temp_buf[(int)Bluecell_TypeIndex_t.DET_3_5G_DL_OUT_L] = 0;
  410. temp_buf[(int)Bluecell_TypeIndex_t.DET_3_5G_DL_OUT_H] = 0;
  411. temp_buf[(int)Bluecell_TypeIndex_t.DET_3_5G_UL_IN_H] = 0;
  412. temp_buf[(int)Bluecell_TypeIndex_t.DET_3_5G_UL_IN_L] = 0;
  413. temp_buf[(int)Bluecell_TypeIndex_t.DET_3_5G_UL_OUT_H] = 0;
  414. temp_buf[(int)Bluecell_TypeIndex_t.DET_3_5G_UL_OUT_L] = 0;
  415. temp_buf[(int)Bluecell_TypeIndex_t.RFU_TEMP_H] = 0;
  416. temp_buf[(int)Bluecell_TypeIndex_t.RFU_TEMP_L] = 0;
  417. temp_buf[(int)Bluecell_TypeIndex_t._28V_DET_H] = 0;
  418. temp_buf[(int)Bluecell_TypeIndex_t._28V_DET_L] = 0;
  419. temp_buf[(int)Bluecell_TypeIndex_t.ALARM_AC] = 0;
  420. temp_buf[(int)Bluecell_TypeIndex_t.ALARM_DC] = 0;
  421. temp_buf[(int)Bluecell_TypeIndex_t.PATH_EN_1_8G_DL] = Convert.ToByte(PATH_1_8G_DL_Get_Func());
  422. temp_buf[(int)Bluecell_TypeIndex_t.PATH_EN_1_8G_UL] = Convert.ToByte(PATH_1_8G_UL_Get_Func());
  423. temp_buf[(int)Bluecell_TypeIndex_t.PATH_EN_2_1G_DL] = Convert.ToByte(PATH_2_1G_DL_Get_Func());
  424. temp_buf[(int)Bluecell_TypeIndex_t.PATH_EN_2_1G_UL] = Convert.ToByte(PATH_2_1G_UL_Get_Func());
  425. temp_buf[(int)Bluecell_TypeIndex_t.PATH_EN_3_5G_L] = Convert.ToByte(Path_3_5G_L_Get_Func());
  426. temp_buf[(int)Bluecell_TypeIndex_t.PATH_EN_3_5G_H] = Convert.ToByte(Path_3_5G_H_Get_Func());
  427. temp_buf[(int)Bluecell_TypeIndex_t.PATH_EN_3_5G_DL] = Convert.ToByte(PATH_3_5G_DL_Get_Func());
  428. temp_buf[(int)Bluecell_TypeIndex_t.PATH_EN_3_5G_UL] = Convert.ToByte(PATH_3_5G_UL_Get_Func());
  429. temp_buf[(int)Bluecell_TypeIndex_t.PLL_ON_OFF_3_5G_H] = Convert.ToByte(PLL_ON_OFF_3_5G_H_Get_Func());
  430. temp_buf[(int)Bluecell_TypeIndex_t.PLL_ON_OFF_3_5G_L] = Convert.ToByte(PLL_ON_OFF_3_5G_L_Get_Func());
  431. temp_buf[(int)Bluecell_TypeIndex_t.T_SYNC_DL] = main_Form.Tdd_T_Sync;//Convert.ToByte(PATH_3_5G_DL_Get_Func());
  432. temp_buf[(int)Bluecell_TypeIndex_t._T_SYNC_DL] = main_Form.Tdd_T_Sync;//Convert.ToByte(PATH_3_5G_DL_Get_Func());
  433. temp_buf[(int)Bluecell_TypeIndex_t.T_SYNC_UL] = main_Form.Tdd_T_Sync;//Convert.ToByte(PLL_ON_OFF_3_5G_H_Get_Func());
  434. temp_buf[(int)Bluecell_TypeIndex_t._T_SYNC_UL] = main_Form.Tdd_T_Sync;//Convert.ToByte(PLL_ON_OFF_3_5G_L_Get_Func());
  435. /***********************DAC A Sector**********************************/
  436. double double_temp = Convert.ToDouble(main_Form.numericUpDown_DAC_VoltCtrl_A.Text) * 4095;
  437. UInt16 temp = Convert.ToUInt16(double_temp / 4);
  438. temp = Convert.ToUInt16(temp & 0x0FFF);
  439. temp_buf[(int)Bluecell_TypeIndex_t.DAC_VCtrl_A_H]
  440. = Convert.ToByte(0x00 + Convert.ToByte((temp & 0xFF00) >> 8));
  441. temp_buf[(int)Bluecell_TypeIndex_t.DAC_VCtrl_A_L]
  442. = Convert.ToByte(Convert.ToUInt16(temp) & 0x00FF);
  443. /***********************DAC B Sector**********************************/
  444. double_temp = Convert.ToDouble(main_Form.numericUpDown_DAC_VoltCtrl_B.Text) * 4095;
  445. temp = Convert.ToUInt16(double_temp / 4);
  446. temp = Convert.ToUInt16(temp & 0x0FFF);
  447. temp_buf[(int)Bluecell_TypeIndex_t.DAC_VCtrl_B_H]
  448. = Convert.ToByte(0x10 + Convert.ToByte((temp & 0xFF00) >> 8));
  449. temp_buf[(int)Bluecell_TypeIndex_t.DAC_VCtrl_B_L]
  450. = Convert.ToByte(Convert.ToUInt16(temp) & 0x00FF);
  451. /***********************DAC C Sector**********************************/
  452. double_temp = Convert.ToDouble(main_Form.numericUpDown_DAC_VoltCtrl_C.Text) * 4095;
  453. temp = Convert.ToUInt16(double_temp / 4);
  454. temp = Convert.ToUInt16(temp & 0x0FFF);
  455. temp_buf[(int)Bluecell_TypeIndex_t.DAC_VCtrl_C_H]
  456. = Convert.ToByte(0x20 + Convert.ToByte((temp & 0xFF00) >> 8));
  457. temp_buf[(int)Bluecell_TypeIndex_t.DAC_VCtrl_C_L]
  458. = Convert.ToByte(Convert.ToUInt16(temp) & 0x00FF);
  459. /***********************DAC D Sector**********************************/
  460. double_temp = Convert.ToDouble(main_Form.numericUpDown_DAC_VoltCtrl_D.Text) * 4095;
  461. temp = Convert.ToUInt16(double_temp / 4);
  462. temp = Convert.ToUInt16(temp & 0x0FFF);
  463. temp_buf[(int)Bluecell_TypeIndex_t.DAC_VCtrl_D_H]
  464. = Convert.ToByte(0x30 + Convert.ToByte((temp & 0xFF00) >> 8));
  465. temp_buf[(int)Bluecell_TypeIndex_t.DAC_VCtrl_D_L]
  466. = Convert.ToByte(Convert.ToUInt16(temp) & 0x00FF);
  467. /***********************DAC E Sector**********************************/
  468. double_temp = Convert.ToDouble(main_Form.numericUpDown_DAC_VoltCtrl_E.Text) * 4095;
  469. temp = Convert.ToUInt16(double_temp / 4);
  470. temp = Convert.ToUInt16(temp & 0x0FFF);
  471. temp_buf[(int)Bluecell_TypeIndex_t.DAC_VCtrl_E_H]
  472. = Convert.ToByte(0x40 + Convert.ToByte((temp & 0xFF00) >> 8));
  473. temp_buf[(int)Bluecell_TypeIndex_t.DAC_VCtrl_E_L]
  474. = Convert.ToByte(Convert.ToUInt16(temp) & 0x00FF);
  475. /***********************DAC F Sector**********************************/
  476. double_temp = Convert.ToDouble(main_Form.numericUpDown_DAC_VoltCtrl_F.Text) * 4095;
  477. temp = Convert.ToUInt16(double_temp / 4);
  478. temp = Convert.ToUInt16(temp & 0x0FFF);
  479. temp_buf[(int)Bluecell_TypeIndex_t.DAC_VCtrl_F_H]
  480. = Convert.ToByte(0x50 + Convert.ToByte((temp & 0xFF00) >> 8));
  481. temp_buf[(int)Bluecell_TypeIndex_t.DAC_VCtrl_F_L]
  482. = Convert.ToByte(Convert.ToUInt16(temp) & 0x00FF);
  483. /***********************DAC G Sector**********************************/
  484. double_temp = Convert.ToDouble(main_Form.numericUpDown_DAC_VoltCtrl_G.Text) * 4095;
  485. temp = Convert.ToUInt16(double_temp / 4);
  486. temp = Convert.ToUInt16(temp & 0x0FFF);
  487. temp_buf[(int)Bluecell_TypeIndex_t.DAC_VCtrl_G_H]
  488. = Convert.ToByte(0x60 + Convert.ToByte((temp & 0xFF00) >> 8));
  489. temp_buf[(int)Bluecell_TypeIndex_t.DAC_VCtrl_G_L]
  490. = Convert.ToByte(Convert.ToUInt16(temp) & 0x00FF);
  491. /***********************DAC H Sector**********************************/
  492. double_temp = Convert.ToDouble(main_Form.numericUpDown_DAC_VoltCtrl_H.Text) * 4095;
  493. temp = Convert.ToUInt16(double_temp / 4);
  494. temp = Convert.ToUInt16(temp & 0x0FFF);
  495. temp_buf[(int)Bluecell_TypeIndex_t.DAC_VCtrl_H_H]
  496. = Convert.ToByte(0x70 + Convert.ToByte((temp & 0xFF00) >> 8));
  497. temp_buf[(int)Bluecell_TypeIndex_t.DAC_VCtrl_H_L]
  498. = Convert.ToByte(Convert.ToUInt16(temp) & 0x00FF);
  499. /* * * * * * FIX DATA * * * * * */
  500. temp_buf[(int)Bluecell_TypeIndex_t.DAC_VCtrl_H_L + 1]
  501. = crc16.STH30_CreateCrc(temp_buf, BLUECELL_DATA_SET_LENGTH - 3);
  502. temp_buf[(int)Bluecell_TypeIndex_t.DAC_VCtrl_H_L + 2]
  503. = BLUECELL_TAILER;
  504. this.serial.Serial_DataSend(temp_buf, temp_buf.Length);
  505. }
  506. int[] RF_Status = new int[BLUECELL_DATA_SET_LENGTH];
  507. private delegate void StringSend(string Text);
  508. private delegate void ByteSend(byte[] Text);
  509. public void Bluecell_RF_Status_Get(object serial, object main_form,byte[] temp_buf)
  510. {
  511. this.main_Form = (Main_Form)main_form;
  512. this.serial = (Serial)serial;
  513. byte type = temp_buf[(byte)Bluecell_TypeIndex_t.BLUE_TYPE];
  514. // main_Form.Invoke(new ByteSend(this.main_Form.ReSetting_Values),(temp_buf));
  515. switch (type)
  516. {
  517. case (byte)Bluecell_Prot_t.TYPE_BLUECELL_GET:
  518. this.main_Form.ADC_Voltage_Value_Set(temp_buf);
  519. break;
  520. case (byte)Bluecell_Prot_t.TYPE_BLUECELL_ACK:
  521. this.main_Form.Message_Box_Open();
  522. break;
  523. case (byte)Bluecell_Prot_t.TYPE_BLUECELL_ERROR:
  524. this.main_Form.Message_Box_Error_Open(temp_buf);
  525. break;
  526. }
  527. //Debug.Invoke(new StringSend(Debug.Data_Recv_Str), data);
  528. //main_Form.label1_8GHz_DL_OUT.Text = Convert.ToString(temp_val);
  529. }
  530. public void Bluecell_RF_Status_Req(object serial)
  531. {
  532. Crc16 crc16 = new Crc16();
  533. this.serial = (Serial)serial;
  534. byte[] temp_buf = new byte[6];
  535. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Header] = BLUECELL_HEADER;
  536. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type] = 2;
  537. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Length] = Convert.ToByte(temp_buf.Length - 3);
  538. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_CrcIndex] = Convert.ToByte(temp_buf.Length - 2);
  539. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + 0] = crc16.STH30_CreateCrc(temp_buf, temp_buf[2]);
  540. temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + 1] = BLUECELL_TAILER;
  541. this.serial.Serial_DataSend(temp_buf, temp_buf.Length);
  542. }
  543. bool PATH_1_8G_UL_Get_Func()
  544. {
  545. bool ret = false;
  546. if (this.main_Form.pictureBox_PATH_1_8G_UL_OFF.Visible == true)
  547. ret = false;
  548. else
  549. ret = true;
  550. return ret;
  551. }
  552. bool PATH_1_8G_DL_Get_Func()
  553. {
  554. bool ret = false;
  555. if (this.main_Form.pictureBox_PATH_1_8G_DL_OFF.Visible == true)
  556. ret = false;
  557. else
  558. ret = true;
  559. return ret;
  560. }
  561. bool PATH_2_1G_UL_Get_Func()
  562. {
  563. bool ret = false;
  564. if (this.main_Form.pictureBox_PATH_2_1G_UL_OFF.Visible == true)
  565. ret = false;
  566. else
  567. ret = true;
  568. return ret;
  569. }
  570. bool PATH_2_1G_DL_Get_Func()
  571. {
  572. bool ret = false;
  573. if (this.main_Form.pictureBox_PATH_2_1G_DL_OFF.Visible == true)
  574. ret = false;
  575. else
  576. ret = true;
  577. return ret;
  578. }
  579. bool Path_3_5G_L_Get_Func()
  580. {
  581. bool ret = false;
  582. if (this.main_Form.pictureBox_PATH_3_5G_L_OFF.Visible == true)
  583. ret = false;
  584. else
  585. ret = true;
  586. return ret;
  587. }
  588. bool Path_3_5G_H_Get_Func()
  589. {
  590. bool ret = false;
  591. if (this.main_Form.pictureBox_PATH_3_5G_H_OFF.Visible == true)
  592. ret = false;
  593. else
  594. ret = true;
  595. return ret;
  596. }
  597. bool PLL_ON_OFF_3_5G_L_Get_Func()
  598. {
  599. bool ret = false;
  600. if (this.main_Form.pictureBox_PLL_ON_OFF_3_5G_L_OFF.Visible == true)
  601. ret = false;
  602. else
  603. ret = true;
  604. return ret;
  605. }
  606. bool PLL_ON_OFF_3_5G_H_Get_Func()
  607. {
  608. bool ret = false;
  609. if (this.main_Form.pictureBox_PLL_ON_OFF_3_5G_H_OFF.Visible == true)
  610. ret = false;
  611. else
  612. ret = true;
  613. return ret;
  614. }
  615. bool PATH_3_5G_UL_Get_Func()
  616. {
  617. bool ret = false;
  618. if (this.main_Form.pictureBox_PATH_3_5G_UL_OFF.Visible == true)
  619. ret = false;
  620. else
  621. ret = true;
  622. return ret;
  623. }
  624. bool PATH_3_5G_DL_Get_Func()
  625. {
  626. bool ret = false;
  627. if (this.main_Form.pictureBox_PATH_3_5G_DL_OFF.Visible == true)
  628. ret = false;
  629. else
  630. ret = true;
  631. return ret;
  632. }
  633. /* public System.Windows.Forms.PictureBox pictureBox_PATH_3_5G_L_OFF;
  634. public System.Windows.Forms.PictureBox pictureBox_PATH_3_5G_H_OFF;
  635. public System.Windows.Forms.PictureBox pictureBox_PLL_ON_OFF_3_5G_L_OFF;
  636. public System.Windows.Forms.PictureBox pictureBox_PLL_ON_OFF_3_5G_H_OFF;
  637. public System.Windows.Forms.PictureBox pictureBox_PATH_3_5G_UL_OFF;
  638. public System.Windows.Forms.PictureBox pictureBox_PATH_3_5G_DL_OFF;
  639. public System.Windows.Forms.PictureBox pictureBox_PATH_2_1G_UL_OFF;
  640. public System.Windows.Forms.PictureBox pictureBox_PATH_2_1G_DL_OFF;
  641. public System.Windows.Forms.PictureBox pictureBox_PATH_1_8G_UL_OFF;
  642. public System.Windows.Forms.PictureBox pictureBox_PATH_1_8G_DL_OFF;
  643. */
  644. #if false
  645. public int Bluecell_Firmupdate_sendlength() {
  646. return bluecell_Firmupdate_sendlength;
  647. }
  648. private void BootHeaderput(ref byte[] fix_data)
  649. {
  650. fix_data[(int)Bluepro_t.bluecell_header0] = Bluecell_Header0;
  651. fix_data[(int)Bluepro_t.bluecell_header1] = Bluecell_Header1;
  652. fix_data[(int)Bluepro_t.bluecell_header2] = Bluecell_Header2;
  653. fix_data[(int)Bluepro_t.bluecell_header3] = Bluecell_Header3;
  654. }
  655. public byte[] Boot_Reset(object serial,byte[] Updatedata)
  656. {
  657. this.serial = (Serial)serial;
  658. byte[] fix_data = new byte[11];
  659. //Array.Clear(data, 0, data.Length);
  660. BootHeaderput(ref fix_data);
  661. fix_data[(int)Bluepro_t.bluecell_type] = (byte)Updateseq.Bluecell_Reset;
  662. fix_data[(int)Bluepro_t.bluecell_length_h] = 0;
  663. fix_data[(int)Bluepro_t.bluecell_length_l] = 5;
  664. fix_data[(int)Bluepro_t.bluecell_updatecnt_h] = Convert.ToByte((Updatedata.Length & 0xFF00) >> 8);
  665. fix_data[(int)Bluepro_t.bluecell_updatecnt_l] = Convert.ToByte((Updatedata.Length & 0x00FF));
  666. fix_data[(int)Bluepro_t.bluecell_data + 0] = Convert.ToByte((crc16.CRC16_Generate(fix_data, fix_data.Length - 4) & 0xFF00) >> 8);
  667. fix_data[(int)Bluepro_t.bluecell_data + 1] = Convert.ToByte((crc16.CRC16_Generate(fix_data, fix_data.Length - 4) & 0x00FF));
  668. this.serial.Serial_DataSend(fix_data, fix_data.Length);
  669. return fix_data;
  670. }
  671. public byte[] Boot_DataSending(byte[] update_data,UInt16 length, UInt16 updatacnt)
  672. {
  673. //Array.Clear(data, 0, data.Length);
  674. byte[] fix_data = new byte[bluecell_Firmupdate_sendlength];
  675. //BootHeaderput(ref fix_data);
  676. //length += 5;
  677. Array.Copy(update_data, (int)Bluepro_t.bluecell_data, fix_data, (int)Bluepro_t.bluecell_data, length);
  678. BootHeaderput(ref fix_data);
  679. fix_data[(int)Bluepro_t.bluecell_type] = (byte)Updateseq.Bluecell_Firmupdate_sending;
  680. fix_data[(int)Bluepro_t.bluecell_length_h] = Convert.ToByte((length & 0xFF00) >> 8);
  681. fix_data[(int)Bluepro_t.bluecell_length_l] = Convert.ToByte((length & 0x00FF));
  682. fix_data[(int)Bluepro_t.bluecell_updatecnt_h] = Convert.ToByte((updatacnt & 0xFF00) >> 8);
  683. fix_data[(int)Bluepro_t.bluecell_updatecnt_l] = Convert.ToByte((updatacnt & 0x00FF));
  684. //Array.Copy(update_data, 0, fix_data, (int)Bluepro_t.bluecell_data, length-3);
  685. fix_data[length + 9] = Convert.ToByte((crc16.CRC16_Generate(fix_data, length + 5) & 0xFF00) >> 8);
  686. fix_data[length + 10] = Convert.ToByte(crc16.CRC16_Generate(fix_data, length + 5) & 0x00FF);
  687. return fix_data;
  688. }
  689. public byte[] Boot_DataEnd(byte[] update_data, int length)
  690. {
  691. //Array.Clear(data, 0, data.Length);
  692. byte[] fix_data = new byte[11];
  693. Array.Copy(update_data, (int)Bluepro_t.bluecell_data, fix_data, (int)Bluepro_t.bluecell_data, length);
  694. BootHeaderput(ref fix_data);
  695. fix_data[(int)Bluepro_t.bluecell_type] = (byte)Updateseq.Bluecell_Firmupdate_end;
  696. fix_data[(int)Bluepro_t.bluecell_length_h] = Convert.ToByte((length & 0xFF00) >> 8);
  697. fix_data[(int)Bluepro_t.bluecell_length_l] = Convert.ToByte((length & 0x00FF));
  698. fix_data[(int)Bluepro_t.bluecell_updatecnt_h] = 0;
  699. fix_data[(int)Bluepro_t.bluecell_updatecnt_l] = 0;
  700. //Array.Copy(update_data, 0, fix_data, (int)Bluepro_t.bluecell_data, length-3);
  701. fix_data[length + 9] = Convert.ToByte((crc16.CRC16_Generate(fix_data, length + 5) & 0xFF00) >> 8);
  702. fix_data[length + 10] = Convert.ToByte(crc16.CRC16_Generate(fix_data, length + 5) & 0x00FF);
  703. return fix_data;
  704. }
  705. #endif
  706. }
  707. }