Main_Form.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. //Add code
  11. using System.IO;
  12. using System.IO.Ports;
  13. namespace RF_TRIO_PLL_ZIG
  14. {
  15. public partial class Main_Form : Form
  16. {
  17. Serial serial = new Serial(); // Uart Open
  18. Bluecell_BootProtocol bluecell_BootProtocol = new Bluecell_BootProtocol();
  19. Update_Serial file = new Update_Serial();
  20. public byte Tdd_T_Sync = 0;
  21. public Main_Form()
  22. {
  23. InitializeComponent();
  24. serial.Serial_Initialize(ref comboBox_Port);
  25. }
  26. private void Firmware_Update_Click(object sender, EventArgs e)
  27. {
  28. OpenFileDialog ofd = new OpenFileDialog();
  29. //FileDownload file = new FileDownload();
  30. if (Ascii_checkBox.Checked == true)
  31. Ascii_checkBox.Checked = false;
  32. file.ShowFileOpenDialog(ref serial, ofd);
  33. }
  34. private void Crc16_Check_Click(object sender, EventArgs e)
  35. {
  36. #if false
  37. Crc16 crc16 = new Crc16();
  38. byte[] tempdata = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,0x0A };
  39. label1.Text = crc16.CRC16_Generate(tempdata, 11).ToString();
  40. #endif
  41. this.serial.Test_Serial();
  42. }
  43. private void Button_PortOpen_Click(object sender, EventArgs e)
  44. {
  45. bool ret = false;
  46. ret = Serial_connectiondisable(serial.Serial_PortOpen(ref button_PortOpen, ref comboBox_Port));
  47. if (ret == false && timer.Enabled == false)
  48. {
  49. timer.Start(); //타이머를 발동시킨다.
  50. }
  51. else if (timer.Enabled == true)
  52. {
  53. timer.Stop(); //타이머를 멈춘다.
  54. }
  55. else
  56. {
  57. /*NOP*/
  58. }
  59. serial.Serial_Main_Form_Get(this);
  60. }
  61. private void ComboBox_Port_SelectedIndexChanged(object sender, EventArgs e)
  62. {
  63. serial.Serial_Name = comboBox_Port.SelectedItem.ToString();
  64. }
  65. private void Button_terminal_Click(object sender, EventArgs e)
  66. {
  67. serial.Serial_TerminalOpen(serial);
  68. }
  69. public bool Serial_connectiondisable(Boolean on_off)
  70. {
  71. comboBox_Port.Enabled = on_off;
  72. comboBox_baudrate.Enabled = on_off;
  73. return on_off;
  74. }
  75. private delegate void BoolSet();
  76. public void TX_Light_ON()
  77. {
  78. this.pictureBox_G_TX.Visible = true;
  79. this.pictureBox_R_TX.Visible = false;
  80. }
  81. public void TX_Light_OFF()
  82. {
  83. this.pictureBox_R_TX.Visible = true;
  84. this.pictureBox_G_TX.Visible = false;
  85. }
  86. public void RX_Light_ON()
  87. {
  88. this.pictureBox_G_RX.Visible = true;
  89. this.pictureBox_R_RX.Visible = false;
  90. }
  91. public void RX_Light_OFF()
  92. {
  93. this.pictureBox_R_RX.Visible = true;
  94. this.pictureBox_G_RX.Visible = false;
  95. }
  96. private void timer_Tick(object sender, EventArgs e)
  97. {
  98. if (this.pictureBox_G_TX.Visible == true)
  99. {
  100. TX_Light_OFF();
  101. }
  102. if(this.pictureBox_G_RX.Visible == true)
  103. {
  104. RX_Light_OFF();
  105. }
  106. }
  107. private void Main_Form_Load(object sender, EventArgs e)
  108. {
  109. pictureBox_PATH_1_8G_DL_ON.Visible = !false;
  110. pictureBox_PATH_1_8G_UL_ON.Visible = !false;
  111. pictureBox_PATH_2_1G_DL_ON.Visible = !false;
  112. pictureBox_PATH_2_1G_UL_ON.Visible = !false;
  113. pictureBox_PATH_3_5G_L_ON.Visible = !false;
  114. pictureBox_PATH_3_5G_H_ON.Visible = !false;
  115. pictureBox_PLL_ON_OFF_3_5G_L_ON.Visible = !false;
  116. pictureBox_PLL_ON_OFF_3_5G_H_ON.Visible = !false;
  117. pictureBox_PATH_3_5G_UL_ON.Visible = !false;
  118. pictureBox_PATH_3_5G_DL_ON.Visible = !false;
  119. pictureBox_PATH_1_8G_DL_OFF.Visible = false;
  120. pictureBox_PATH_1_8G_UL_OFF.Visible = false;
  121. pictureBox_PATH_2_1G_DL_OFF.Visible = false;
  122. pictureBox_PATH_2_1G_UL_OFF.Visible = false;
  123. pictureBox_PATH_3_5G_L_OFF.Visible = false;
  124. pictureBox_PATH_3_5G_H_OFF.Visible = false;
  125. pictureBox_PLL_ON_OFF_3_5G_L_OFF.Visible = false;
  126. pictureBox_PLL_ON_OFF_3_5G_H_OFF.Visible = false;
  127. pictureBox_PATH_3_5G_UL_OFF.Visible = false;
  128. pictureBox_PATH_3_5G_DL_OFF.Visible = false;
  129. pictureBox_G_RX.Visible = !false;
  130. pictureBox_G_TX.Visible = !false;
  131. /* public System.Windows.Forms.PictureBox pictureBox_PATH_3_5G_L_OFF;
  132. public System.Windows.Forms.PictureBox pictureBox_PATH_3_5G_H_OFF;
  133. public System.Windows.Forms.PictureBox pictureBox_PLL_ON_OFF_3_5G_L_OFF;
  134. public System.Windows.Forms.PictureBox pictureBox_PLL_ON_OFF_3_5G_H_OFF;
  135. public System.Windows.Forms.PictureBox pictureBox_PATH_3_5G_UL_OFF;
  136. public System.Windows.Forms.PictureBox pictureBox_PATH_3_5G_DL_OFF;
  137. public System.Windows.Forms.PictureBox pictureBox_PATH_2_1G_UL_OFF;
  138. public System.Windows.Forms.PictureBox pictureBox_PATH_2_1G_DL_OFF;
  139. public System.Windows.Forms.PictureBox pictureBox_PATH_1_8G_UL_OFF;
  140. public System.Windows.Forms.PictureBox pictureBox_PATH_1_8G_DL_OFF;
  141. public System.Windows.Forms.PictureBox pictureBox_PATH_3_5G_L_ON;
  142. public System.Windows.Forms.PictureBox pictureBox_PATH_3_5G_H_ON;
  143. public System.Windows.Forms.PictureBox pictureBox_PLL_ON_OFF_3_5G_L_ON;
  144. public System.Windows.Forms.PictureBox pictureBox_PLL_ON_OFF_3_5G_H_ON;
  145. public System.Windows.Forms.PictureBox pictureBox_PATH_3_5G_UL_ON;
  146. public System.Windows.Forms.PictureBox pictureBox_PATH_3_5G_DL_ON;
  147. public System.Windows.Forms.PictureBox pictureBox_PATH_2_1G_UL_ON;
  148. public System.Windows.Forms.PictureBox pictureBox_PATH_2_1G_DL_ON;
  149. public System.Windows.Forms.PictureBox pictureBox_PATH_1_8G_UL_ON;;*/
  150. }
  151. private delegate void StringSend(object label, String str);
  152. public void ADC_Voltage_Value_Set(byte[] data)
  153. {
  154. int temp_val = 0;
  155. try
  156. {
  157. temp_val = (int)(data[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DET_1_8G_DL_IN_H] << 8) | (data[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DET_1_8G_DL_IN_L]);
  158. this.Invoke(new StringSend(Label_Text_Set), label1_8GHz_DL_IN, Convert.ToString(temp_val));
  159. temp_val = (int)(data[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DET_1_8G_DL_IN_H] << 8) | (data[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DET_1_8G_DL_OUT_L]);
  160. this.Invoke(new StringSend(Label_Text_Set), label1_8GHz_DL_OUT, Convert.ToString(temp_val));
  161. temp_val = (int)(data[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DET_1_8G_DL_OUT_H] << 8) | (data[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DET_1_8G_UL_IN_L]);
  162. this.Invoke(new StringSend(Label_Text_Set), label1_8GHz_UL_IN, Convert.ToString(temp_val));
  163. temp_val = (int)(data[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DET_1_8G_UL_IN_H] << 8) | (data[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DET_1_8G_UL_OUT_L]);
  164. this.Invoke(new StringSend(Label_Text_Set), label1_8GHz_UL_OUT, Convert.ToString(temp_val));
  165. temp_val = (int)(data[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DET_1_8G_UL_OUT_H] << 8) | (data[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DET_2_1G_DL_IN_L]);
  166. this.Invoke(new StringSend(Label_Text_Set), label2_1GHz_DL_IN, Convert.ToString(temp_val));
  167. temp_val = (int)(data[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DET_2_1G_DL_IN_H] << 8) | (data[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DET_2_1G_DL_OUT_L]);
  168. this.Invoke(new StringSend(Label_Text_Set), label2_1GHz_DL_OUT, Convert.ToString(temp_val));
  169. temp_val = (int)(data[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DET_2_1G_DL_OUT_H] << 8) | (data[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DET_2_1G_UL_IN_L]);
  170. this.Invoke(new StringSend(Label_Text_Set), label2_1GHz_UL_IN, Convert.ToString(temp_val));
  171. temp_val = (int)(data[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DET_2_1G_UL_IN_H] << 8) | (data[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DET_2_1G_UL_OUT_L]);
  172. this.Invoke(new StringSend(Label_Text_Set), label2_1GHz_UL_OUT, Convert.ToString(temp_val));
  173. temp_val = (int)(data[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DET_3_5G_DL_IN_H] << 8) | (data[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DET_3_5G_DL_IN_L]);
  174. this.Invoke(new StringSend(Label_Text_Set), label3_5GHz_DL_IN, Convert.ToString(temp_val));
  175. temp_val = (int)(data[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DET_3_5G_DL_OUT_H] << 8) | (data[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DET_3_5G_DL_OUT_L]);
  176. this.Invoke(new StringSend(Label_Text_Set), label3_5GHz_DL_OUT, Convert.ToString(temp_val));
  177. temp_val = (int)(data[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DET_3_5G_UL_IN_H] << 8) | (data[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DET_3_5G_UL_IN_L]);
  178. this.Invoke(new StringSend(Label_Text_Set), label3_5GHz_UL_IN, Convert.ToString(temp_val));
  179. temp_val = (int)(data[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DET_3_5G_UL_OUT_H] << 8) | (data[(int)Bluecell_ProtIndex_p.Bluecell_data + (int)Bluecell_TypeIndex_t.DET_3_5G_UL_OUT_L]);
  180. this.Invoke(new StringSend(Label_Text_Set), label3_5GHz_UL_OUT, Convert.ToString(temp_val));
  181. }
  182. catch { }
  183. }
  184. private void Label_Text_Set(object label,String str)
  185. {
  186. Label Temp_label = (Label)label;
  187. Temp_label.Text = str;
  188. }
  189. private void ATT_Enter(object sender, KeyEventArgs e)
  190. {
  191. if (e.KeyCode == Keys.Enter)
  192. {
  193. Button_Set_Click(sender, e);
  194. //to do
  195. }
  196. else
  197. {
  198. return;
  199. }
  200. }
  201. private void TDD_T_SYNC_Click(object sender, EventArgs e)
  202. {
  203. PictureBox pictureBox = (PictureBox)sender;
  204. Tdd_T_Sync = Convert.ToByte(pictureBox.Tag);
  205. bluecell_BootProtocol.Bluecell_BtnSet(this.serial, this);
  206. pictureBox_TDD_T_SYNC_UL_ON.Visible = !pictureBox_TDD_T_SYNC_UL_ON.Visible;
  207. pictureBox_TDD_T_SYNC_DL_OFF.Visible = !pictureBox_TDD_T_SYNC_DL_OFF.Visible;
  208. }
  209. const byte PATH_1_8G_DL_ON = 1;
  210. const byte PATH_1_8G_DL_OFF = 2;
  211. const byte PATH_1_8G_UL_ON = 3;
  212. const byte PATH_1_8G_UL_OFF = 4;
  213. const byte PATH_2_1G_DL_ON = 5;
  214. const byte PATH_2_1G_DL_OFF = 6;
  215. const byte PATH_2_1G_UL_ON = 7;
  216. const byte PATH_2_1G_UL_OFF = 8;
  217. const byte PATH_3_5G_DL_ON = 9;
  218. const byte PATH_3_5G_DL_OFF = 10;
  219. const byte PATH_3_5G_UL_ON = 11;
  220. const byte PATH_3_5G_UL_OFF = 12;
  221. const byte PATH_3_5G_H_ON = 13;
  222. const byte PATH_3_5G_H_OFF = 14;
  223. const byte PATH_3_5G_L_ON = 15;
  224. const byte PATH_3_5G_L_OFF = 16;
  225. const byte PLL_POWER_ONOFF_3_5G_H_ON = 17;
  226. const byte PLL_POWER_ONOFF_3_5G_H_OFF = 18;
  227. const byte PLL_POWER_ONOFF_3_5G_L_ON = 19;
  228. const byte PLL_POWER_ONOFF_3_5G_L_OFF = 20;
  229. private void Power_OnOff_Set(object sender, EventArgs e)
  230. {
  231. byte temp_tag = 0;
  232. PictureBox pictureBox = (PictureBox)sender;
  233. temp_tag = Convert.ToByte(pictureBox.Tag);
  234. switch (temp_tag)
  235. {
  236. case PATH_1_8G_DL_OFF:
  237. pictureBox_PATH_1_8G_DL_ON.Visible = true;
  238. break;
  239. case PATH_1_8G_DL_ON:
  240. pictureBox_PATH_1_8G_DL_OFF.Visible = true;
  241. break;
  242. case PATH_1_8G_UL_OFF:
  243. pictureBox_PATH_1_8G_UL_ON.Visible = true;
  244. break;
  245. case PATH_1_8G_UL_ON:
  246. pictureBox_PATH_1_8G_UL_OFF.Visible = true;
  247. break;
  248. case PATH_2_1G_DL_OFF:
  249. pictureBox_PATH_2_1G_DL_ON.Visible = true;
  250. break;
  251. case PATH_2_1G_DL_ON:
  252. pictureBox_PATH_2_1G_DL_OFF.Visible = true;
  253. break;
  254. case PATH_2_1G_UL_OFF:
  255. pictureBox_PATH_2_1G_UL_ON.Visible = true;
  256. break;
  257. case PATH_2_1G_UL_ON:
  258. pictureBox_PATH_2_1G_UL_OFF.Visible = true;
  259. break;
  260. case PATH_3_5G_DL_OFF:
  261. pictureBox_PATH_3_5G_DL_ON.Visible = true;
  262. break;
  263. case PATH_3_5G_DL_ON:
  264. pictureBox_PATH_3_5G_DL_OFF.Visible = true;
  265. break;
  266. case PATH_3_5G_UL_OFF:
  267. pictureBox_PATH_3_5G_UL_ON.Visible = true;
  268. break;
  269. case PATH_3_5G_UL_ON:
  270. pictureBox_PATH_3_5G_UL_OFF.Visible = true;
  271. break;
  272. case PATH_3_5G_H_OFF:
  273. pictureBox_PATH_3_5G_H_ON.Visible = true;
  274. break;
  275. case PATH_3_5G_H_ON:
  276. pictureBox_PATH_3_5G_H_OFF.Visible = true;
  277. break;
  278. case PATH_3_5G_L_OFF:
  279. pictureBox_PATH_3_5G_L_ON.Visible = true;
  280. break;
  281. case PATH_3_5G_L_ON:
  282. pictureBox_PATH_3_5G_L_OFF.Visible = true;
  283. break;
  284. case PLL_POWER_ONOFF_3_5G_H_ON:
  285. pictureBox_PLL_ON_OFF_3_5G_H_OFF.Visible = true;
  286. break;
  287. case PLL_POWER_ONOFF_3_5G_H_OFF:
  288. pictureBox_PLL_ON_OFF_3_5G_H_ON.Visible = true;
  289. break;
  290. case PLL_POWER_ONOFF_3_5G_L_ON:
  291. pictureBox_PLL_ON_OFF_3_5G_L_OFF.Visible = true;
  292. break;
  293. case PLL_POWER_ONOFF_3_5G_L_OFF:
  294. pictureBox_PLL_ON_OFF_3_5G_L_ON.Visible = true;
  295. break;
  296. }
  297. pictureBox.Visible = !pictureBox.Visible;
  298. bluecell_BootProtocol.Bluecell_BtnSet(this.serial, this);
  299. }
  300. private void button1_Click(object sender, EventArgs e)
  301. {
  302. Crc16 crc16 = new Crc16();
  303. byte[] temp_buf = new byte[6];
  304. temp_buf[0] = 0xbe;
  305. temp_buf[1] = 2;
  306. temp_buf[2] = 4;
  307. temp_buf[3] = 5;
  308. temp_buf[4] = crc16.STH30_CreateCrc(temp_buf, temp_buf[2]);
  309. temp_buf[5] = 0xeb;
  310. serial.Serial_DataSend(temp_buf, temp_buf[2] + 2);
  311. }
  312. private void Button_Set_Click(object sender, EventArgs e)
  313. {
  314. bluecell_BootProtocol.Bluecell_BtnSet(this.serial, this);
  315. }
  316. }
  317. }