private void json_status_recv_parse(json_response status) { #if CONSOLE_DEBUG Console.WriteLine("----------json_status_recv_parse-------------"); Console.WriteLine("json func:" + status.FUNC); Console.WriteLine("json operate:" + status.OPERATE); Console.WriteLine("json status:" + status.STATUS); Console.WriteLine("json param1:" + status.PARAM1); Console.WriteLine("json param2:" + status.PARAM2); Console.WriteLine("json param3:" + status.PARAM3); Console.WriteLine("json param4:" + status.PARAM4); Console.WriteLine("json param5:" + status.PARAM5); Console.WriteLine("----------json_status_recv_parse end--------"); #endif if (status.FUNC == "BT") { if (status.OPERATE == "BT_START") { if (status.STATUS == "SUCCESS") { /* TODO:profile mask的处理 */ ui_bt_inquiry_show(true, false); } } if (status.OPERATE == "BT_INQUIRY_STATUS") { if (status.PARAM1 == "START") { ui_bt_inquiry_show(false, true); } if (status.PARAM1 == "STOP") { ui_bt_inquiry_show(true, false); } } if (status.OPERATE == "BT_INQUIRY_RESULT") { int index = dg_inquiry_result.Rows.Add(); dg_inquiry_result.Rows[index].Cells[1].Value = status.PARAM1; dg_inquiry_result.Rows[index].Cells[2].Value = status.PARAM3; if (status.PARAM2 == "HEADSET") { dg_inquiry_result.Rows[index].Cells[0].Value = Properties.Resources.ResourceManager.GetObject("音频"); } else { dg_inquiry_result.Rows[index].Cells[0].Value = Properties.Resources.ResourceManager.GetObject("未知"); } } } }
/* 串口收到数据 */ private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e) { if (serialPort1.IsOpen) { try { byte[] read_data = new byte[serialPort1.BytesToRead]; serialPort1.Read(read_data, 0, read_data.Length); string recv_data_string = Encoding.GetEncoding("UTF-8").GetString(read_data); string[] arr = Regex.Split(recv_data_string, "\r\n"); foreach (string s in arr) { if (s.Contains("{") || (serial_recv_status == PARSEING_JSON)) { serial_recv_status = PARSEING_JSON; recv_json_str += s; if (s.Contains("}")) { serial_recv_status = PRINTFING_LOG; #if CONSOLE_DEBUG Console.WriteLine(recv_json_str); #endif json_response status = JsonConvert.DeserializeObject <json_response>(recv_json_str); json_status_recv_parse(status); recv_json_str = ""; //return; } } else { if (s != "") { t_data_recv.Text += (s + "\r\n"); t_data_recv.SelectionStart = t_data_recv.TextLength; t_data_recv.ScrollToCaret(); } } } } catch (Exception ex) { recv_json_str = ""; return; } } }
private void json_status_recv_parse(json_response status) { #if CONSOLE_DEBUG Console.WriteLine("----------json_status_recv_parse-------------"); Console.WriteLine("json func:" + status.FUNC); Console.WriteLine("json operate:" + status.OPERATE); Console.WriteLine("json status:" + status.STATUS); Console.WriteLine("json param1:" + status.PARAM1); Console.WriteLine("json param2:" + status.PARAM2); Console.WriteLine("json param3:" + status.PARAM3); Console.WriteLine("json param4:" + status.PARAM4); Console.WriteLine("json param5:" + status.PARAM5); Console.WriteLine("----------json_status_recv_parse end--------"); #endif if (status.FUNC == "BT") { if (status.OPERATE == "BT_START") { if (status.STATUS == "SUCCESS") { /* TODO:profile mask的处理 */ ui_bt_inquiry_show(true, false); } } if (status.OPERATE == "BT_INQUIRY_STATUS") { if (status.PARAM1 == "START") { ui_bt_inquiry_show(false, true); } if (status.PARAM1 == "STOP") { ui_bt_inquiry_show(true, false); } } if (status.OPERATE == "BT_INQUIRY_RESULT") { int index = dg_inquiry_result.Rows.Add(); dg_inquiry_result.Rows[index].Cells[1].Value = status.PARAM1; dg_inquiry_result.Rows[index].Cells[2].Value = status.PARAM3; if (status.PARAM2 == "HEADSET") { dg_inquiry_result.Rows[index].Cells[0].Value = Properties.Resources.ResourceManager.GetObject("音频"); } else { dg_inquiry_result.Rows[index].Cells[0].Value = Properties.Resources.ResourceManager.GetObject("未知"); } } if (status.OPERATE == "BT_CON_RESULT") { if (status.PARAM1 == "SPP") { ui_bt_spp_show(true); ui_bt_spp_con_status(true); ui_bt_spp_con_status(status.PARAM2); } if (status.PARAM1 == "HFP") { ui_bt_hfp_show(true); ui_bt_hfp_con_status(true); ui_bt_hfp_con_status(status.PARAM2); json_cmd_send(json_bt_cmd_func, json_bt_cmd_hfp_set_mic_volume, bt_hfp_default_mic_volume.ToString(), null, null, null, null, null); json_cmd_send(json_bt_cmd_func, json_bt_cmd_hfp_set_spk_volume, bt_hfp_default_spk_volume.ToString(), null, null, null, null, null); } } if (status.OPERATE == "BT_DISCON_RESULT") { if (status.PARAM1 == "SPP") { ui_bt_spp_show(false); ui_bt_spp_con_status(false); ui_bt_spp_con_status(null); } if (status.PARAM1 == "HFP") { ui_bt_hfp_show(false); ui_bt_hfp_answer_call_enable(false); ui_bt_hfp_end_call_enable(false); ui_bt_hfp_con_status(false); ui_bt_hfp_con_status(null); ui_bt_hfp_update_batt(null); ui_bt_hfp_update_signal(null); } } if (status.OPERATE == "BT_SPP_RECV") { t_spp_recv_data.Text += status.PARAM1 + "\r\n"; int spp_recv_count = Convert.ToInt32(l_spp_recv_count.Text) + Convert.ToInt32(status.PARAM2); l_spp_recv_count.Text = spp_recv_count.ToString(); } if (status.OPERATE == "BT_HFP_SIGNAL_STRENGTH") { string picture_name = "signal_" + status.PARAM1; ui_bt_hfp_update_signal(picture_name); } if (status.OPERATE == "BT_HFP_BATT_LEVEL") { string picture_name = "batt_" + status.PARAM1; ui_bt_hfp_update_batt(picture_name); } if (status.OPERATE == "BT_HFP_OPERATOR") { tb_hfp_operate.Text = status.PARAM1; } if (status.OPERATE == "BT_HFP_CALL_STATUS") { int call_status = Convert.ToInt32(status.PARAM1); if (call_status == HFP_CALL_NO_INPORCESS) { l_hfp_call_status.Text = "无通话"; bt_hfp_is_call_active = false; bt_hfp_call_time_count = 0; l_hfp_call_time.Text = "00:00:00"; l_hfp_call_pn.Text = "xxx-xxxx-xxxx"; ui_bt_hfp_answer_call_enable(false); ui_bt_hfp_end_call_enable(false); ui_bt_hfp_dtmf_show(false); } else if (call_status == HFP_CALL_INPORCESS) { bt_hfp_is_call_active = true; l_hfp_call_status.Text = "通话中"; ui_bt_hfp_answer_call_enable(false); ui_bt_hfp_end_call_enable(true); ui_bt_hfp_dtmf_show(true); } } if (status.OPERATE == "BT_HFP_CALL_SETUP") { int callsetup_status = Convert.ToInt32(status.PARAM1); if (callsetup_status == HFP_CALL_INCOMING_CALL) { l_hfp_call_status.Text = "来电中"; ui_bt_hfp_answer_call_enable(true); ui_bt_hfp_end_call_enable(true); } else if (callsetup_status == HFP_CALL_OUTGOING_CALL) { l_hfp_call_status.Text = "去电中"; ui_bt_hfp_answer_call_enable(false); ui_bt_hfp_end_call_enable(true); } } if (status.OPERATE == "BT_SCO_CON_RESULT") { b_hfp_audio_transfer.Text = "切换音源" + "(目前声音在HF)"; } if (status.OPERATE == "BT_SCO_DISCON_RESULT") { b_hfp_audio_transfer.Text = "切换音源" + "(目前声音在AG)"; } if (status.OPERATE == "BT_HFP_LOCAL_PN") { tb_hfp_lpn.Text = status.PARAM1; } if (status.OPERATE == "BT_HFP_CALL_PN") { l_hfp_call_pn.Text = status.PARAM1; } if (status.OPERATE == "BT_HFP_MANU_ID") { tb_hfp_manu_id.Text = status.PARAM1; } if (status.OPERATE == "BT_HFP_MODULE_ID") { tb_hfp_module_name.Text = status.PARAM1; } } }
private void json_status_recv_parse(json_response status) { #if CONSOLE_DEBUG Console.WriteLine("----------json_status_recv_parse-------------"); Console.WriteLine("json func:" + status.FUNC); Console.WriteLine("json operate:" + status.OPERATE); Console.WriteLine("json status:" + status.STATUS); Console.WriteLine("json param1:" + status.PARAM1); Console.WriteLine("json param2:" + status.PARAM2); Console.WriteLine("json param3:" + status.PARAM3); Console.WriteLine("json param4:" + status.PARAM4); Console.WriteLine("json param5:" + status.PARAM5); Console.WriteLine("----------json_status_recv_parse end--------"); #endif if (status.FUNC == "BT") { if (status.OPERATE == "BT_START") { if (status.STATUS == "SUCCESS") { /* TODO:profile mask的处理 */ ui_bt_inquiry_show(true, false); } } if (status.OPERATE == "BT_INQUIRY_STATUS") { if (status.PARAM1 == "START") { ui_bt_inquiry_show(false, true); } if (status.PARAM1 == "STOP") { ui_bt_inquiry_show(true, false); } } if (status.OPERATE == "BT_INQUIRY_RESULT") { int index = dg_inquiry_result.Rows.Add(); dg_inquiry_result.Rows[index].Cells[1].Value = status.PARAM1; dg_inquiry_result.Rows[index].Cells[2].Value = status.PARAM3; if (status.PARAM2 == "HEADSET") { dg_inquiry_result.Rows[index].Cells[0].Value = Properties.Resources.ResourceManager.GetObject("音频"); } else { dg_inquiry_result.Rows[index].Cells[0].Value = Properties.Resources.ResourceManager.GetObject("未知"); } } if (status.OPERATE == "BT_CON_RESULT") { if (status.PARAM1 == "SPP") { ui_bt_spp_show(true); ui_bt_spp_con_status(true); ui_bt_spp_con_status(status.PARAM2); } if (status.PARAM1 == "HFP") { ui_bt_hfp_show(true); ui_bt_hfp_con_status(true); ui_bt_hfp_con_status(status.PARAM2); } } if (status.OPERATE == "BT_DISCON_RESULT") { if (status.PARAM1 == "SPP") { ui_bt_spp_show(false); ui_bt_spp_con_status(false); ui_bt_spp_con_status(null); } if (status.PARAM1 == "HFP") { ui_bt_hfp_show(false); ui_bt_hfp_con_status(false); ui_bt_hfp_con_status(null); } } if (status.OPERATE == "BT_SPP_RECV") { t_spp_recv_data.Text += status.PARAM1 + "\r\n"; int spp_recv_count = Convert.ToInt32(l_spp_recv_count.Text) + Convert.ToInt32(status.PARAM2); l_spp_recv_count.Text = spp_recv_count.ToString(); } if (status.OPERATE == "BT_HFP_SIGNAL_STRENGTH") { string picture_name = "signal_" + status.PARAM1; ui_bt_hfp_update_signal(picture_name); } if (status.OPERATE == "BT_HFP_BATT_LEVEL") { string picture_name = "batt_" + status.PARAM1; ui_bt_hfp_update_batt(picture_name); } if (status.OPERATE == "BT_HFP_OPERATOR") { tb_hfp_operate.Text = status.PARAM1; } } }