⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gsmgprsview.cpp

📁 在pc机上应用tc35i进行调试的程序,有来电显,及拨号
💻 CPP
📖 第 1 页 / 共 3 页
字号:



















































































































































































































































































	DDX_Text(pDX, IDC_EDIT_SIMREAD, m_strSimRead);
	DDX_Text(pDX, IDC_EDIT_FLASHREAD, m_strFlashRead);
	DDX_Text(pDX, IDC_EDIT_PDUMODE, m_strPduMode);
	DDX_Text(pDX, IDC_EDIT_TEXTMODE, m_strTextMode);
	DDX_Text(pDX, IDC_EDIT_ORICHECK, m_strOriCheck);
	DDX_Text(pDX, IDC_EDIT_SIMSAVE, m_strSimSave);
	DDX_Text(pDX, IDC_EDIT_FLASHSAVE, m_strFlashSave);
	DDX_Text(pDX, IDC_EDIT_PHONEBACK, m_strPhoneBack);
	DDX_Text(pDX, IDC_EDIT_HANDPHONE, m_strHandPhone);
	DDX_Text(pDX, IDC_EDIT_SHOWCLOCK, m_strShowClock);
	DDX_Text(pDX, IDC_EDIT_SHOWNUMBER, m_strShowNum);
	//}}AFX_DATA_MAP
}

BOOL CGsmGprsView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CFormView::PreCreateWindow(cs);
}

void CGsmGprsView::OnInitialUpdate()
{
	CFormView::OnInitialUpdate();
	GetParentFrame()->RecalcLayout();
	ResizeParentToFit();
///////////////////////////////////////////////////////////
    
	m_ListCtrl.SetBkColor(RGB(196,220,232));//设置背景颜色
	m_ListCtrl.SetTextBkColor(RGB(196,220,232));//设置文本颜色

	m_ListCtrl.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
	m_ListCtrl.InsertColumn(0,_T("号码"),LVCFMT_IMAGE|LVCFMT_LEFT);
	m_ListCtrl.InsertColumn(1,_T("时间"));
	m_ListCtrl.InsertColumn(2,_T("消息内容"));
	m_ListCtrl.SetColumnWidth(0,100);
	m_ListCtrl.SetColumnWidth(1,150);
	m_ListCtrl.SetColumnWidth(2,360);

    InitListCtrl();//初始化列表

    char Cring[128]={0};
	SetTimer(1, 1000, NULL);//WriteComm("AT+CPMS=SM\r",11);
    SetTimer(2, 1000, NULL);//设置是否有电话信息

 	WriteComm("AT+CNMI=2,1,0,0,1\r",18);//最后一位只能设置1
    
    ReadComm(Cring,128);
    memset(Cring,0,128);
    WriteComm("at+clip=1\r",10);
	ReadComm(Cring,128);
    memset(Cring,0,128);

//新添内容
	 m_ctrlReadPos.SetCurSel(0);//初始化短信读写参数
	 m_ctrlWriteReadPos.SetCurSel(0);
     m_ctrlReceivePos.SetCurSel(0);

 
      strReadPos="\"ME\",";//选择调配
	  strWriteSendPos="\"ME\",";
      strReceivePos="\"MT\"";
//	  CString ss ;
	//  ss =+ "me" + "  " ";
        //CString strCpms="AT+CPMS="+"""+"ME"+"""+","+"""+"ME"+"""+","+"""+"MT"+"""\r";
		CString strCpms="AT+CPMS=\"ME\",\"ME\",\"MT\"\r";
     // CString strCpms1="AT+CPMS=";
	      //    strCpms1
		int lengthCpms=strCpms.GetLength();
		//CString strCpms=
		char cCpms[128] = {0};
		strcpy(cCpms,strCpms);
		WriteComm(cCpms,lengthCpms);
		ReadComm(cCpms,128);
		
		char ansF[128] = {0};
		
		WriteComm("AT+CGMI\r",8);//查看生产厂商
		
		ReadComm(ansF,128);
		if (strstr(ansF, "OK") == NULL)  
			strFactory="未连接";
		
		else 
			// {
			//  while(*ansF==NULL) 
			//   ansF=ansF+1;
			strFactory=ansF;

	     	strFactory.TrimLeft();
           strFactory.TrimRight();
		    //strFactory.Remove(' ');
		     strFactory = strFactory.SpanExcluding("\r\n");
		memset(ansF,0,128);
		// }
		char ansM[128]={0};
		WriteComm("AT+CGMM\r",8);//查看芯片组
		
		ReadComm(ansM, 128);//
		if (strstr(ansM, "OK") == NULL) 
			strModulMsg="未连接";
		else strModulMsg=ansM;//对字符进行处理提取有用字段
		    strModulMsg.TrimLeft();//去掉字符左边的空格
           strModulMsg.TrimRight();//去掉字符右边的空格
		   //strModulMsg.Remove(' ');
		  strModulMsg = strModulMsg.SpanExcluding("\r\n");//截取回车换行前的字符
		memset(ansM,0,128);   

		CString strStatus;
		
		strStatus.Format("STATUS:%s OPENED,通信速率%s,短信中心号码%s,厂商标志%s,模块信息%s",
			m_strPort1,m_strRate1,m_strSmsc1,strFactory,strModulMsg);
   
   //strStatus.Format("STATUS:COM%s OPENED,通信速率%s,短信中心号码%s","33", 
   //"m_strRate","m_strSmsc");
   
   m_ctrlPortStatus.SetWindowText(strStatus);
   UpdateData(FALSE); 
    
}

void CGsmGprsView::ShowBaseMsg()
{
  // strFactory
	
}







/////////////////////////////////////////////////////////////////////////////
// CGsmGprsView printing

BOOL CGsmGprsView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CGsmGprsView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CGsmGprsView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

void CGsmGprsView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
	// TODO: add customized printing code here
}

/////////////////////////////////////////////////////////////////////////////
// CGsmGprsView diagnostics

#ifdef _DEBUG
void CGsmGprsView::AssertValid() const
{
	CFormView::AssertValid();
	
}

void CGsmGprsView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}

CGsmGprsDoc* CGsmGprsView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGsmGprsDoc)));
	return (CGsmGprsDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CGsmGprsView message handlers

void CGsmGprsView::OnButtonSend() 
{
	// TODO: Add your control notification handler code here
	// 发送短信
	CComboBox* pNumberWnd=(CComboBox*)GetDlgItem(IDC_NUMBER);
	//获得指定的对话框中具有指定ID 的控件
	CComboBox* pContentWnd=(CComboBox*)GetDlgItem(IDC_CONTENT);

	CString strSmsc;
	CString strNumber;
	CString strContent;

	strSmsc = theApp.m_strSmsc;//
	pNumberWnd->GetWindowText(strNumber);
	//如果CWnd 对象是一个控件,则GetWindowText 成员函数将
//拷贝控件内的文本
	pContentWnd->GetWindowText(strContent);



	// 检查号码
	if(strNumber.GetLength() < 11)
	{
		AfxMessageBox("请输入正确的号码!");
		pNumberWnd->SetFocus();//这个函数要求得到输入焦点
		pNumberWnd->SetEditSel(-1, 0);//选中组合框的编辑控件中的字符指定起始位置。
		//如果为-1,则清除当前的选择指定起始位置。 
		return;
	}

	// 检查短消息内容是否空,或者超长
	CString strUnicode;
	WCHAR wchar[1024];
//	int Num; Num=strContent.GetLength(); 测试是否相等
	int nCount = ::MultiByteToWideChar(CP_ACP, 0, strContent, -1, wchar, 1024);


    //CP_ACP:ANSI code page 
	if(nCount <= 1)
	{
		AfxMessageBox("请输入消息内容!");
		pContentWnd->SetFocus();
		//pContentWnd->SetEditSel(-1, 0);
		return;
	}
	else if(nCount > 70)// 我们决定全部用UCS2编码,最大70个字符(半角/全角)
	{
		AfxMessageBox("消息内容太长,无法发送!");
		pContentWnd->SetFocus();
		pContentWnd->SetEditSel(-1, 0);
		return;
	}

	if(AfxMessageBox("确定发送吗?", MB_YESNO) == IDYES)
	{
		bMsgState=FALSE;  // 接收来电标志位
		SM_PARAM SmParam;

		memset(&SmParam, 0, sizeof(SM_PARAM));//清空

		// 去掉号码前的"+"

		strSmsc=strSmsc.Left(14);//去掉后面的字符

		if(strSmsc[0] == '+')  strSmsc = strSmsc.Mid(1);//选择从索引为一以后的所有字符
		if(strNumber[0] == '+')  strNumber = strNumber.Mid(1);

		// 在号码前加"86"
		if(strSmsc.Left(2) != "86")  strSmsc = "86" + strSmsc;
		if(strNumber.Left(2) != "86")  strNumber = "86" + strNumber;

		// 填充短消息结构
		strcpy(SmParam.SCA, strSmsc);
		strcpy(SmParam.TPA, strNumber);
		strcpy(SmParam.TP_UD, strContent);
		SmParam.TP_PID = 0;
		SmParam.TP_DCS = GSM_UCS2;

		// 发送短消息
		//KillTimer(2);//杀掉时间器2
		//sleep
		theApp.m_pSmsTraffic->PutSendMessage(&SmParam);

		// 列表中加入新串
		if(pNumberWnd->FindStringExact(-1, strNumber)<0)  
			pNumberWnd->InsertString(0, strNumber);
		//查找与指定的字符串匹配的第一个列表框字符串,如果nIndexStart
        //为-1,从头查找整个列表框,CListBox::FindStringExact
		if(pContentWnd->FindStringExact(-1, strContent)<0)  
			pContentWnd->InsertString(0, strContent);

		bMsgState=TRUE;
	}
    //如果不发送的情况停留焦点位置,以下需一起使用	
	pContentWnd->SetFocus();
	pContentWnd->SetEditSel(-1, 0);	
	
	//SetTimer(2, 1000, NULL);//设置是否有电话信息
}

void CGsmGprsView::OnButtonInitgprs() 
{
	// TODO: Add your control notification handler code here
	// 初始化GPRS
	if(Init_Gprs()==FALSE)
	{
		AfxMessageBox("初始化失败");
		return;
	}
	else
		AfxMessageBox("初始化成功");
	
	
}

void CGsmGprsView::OnButtonOpengprs() 
{
	// TODO: Add your control notification handler code here
	if(Open_GPGS_Mode()==FALSE)
	{
		AfxMessageBox("打开GPRS模式失败");
		return;
	}
	else
		AfxMessageBox("打开GPRS模式成功");	
}

void CGsmGprsView::OnButtonWritegprs() 
{
	// TODO: Add your control notification handler code here
	char* a = "1111";

	if(Write_GPRS_Data(a,5)==FALSE)
	{
		AfxMessageBox("写GPRS模式失败");
		return;
	}	
	else
		AfxMessageBox("写GPRS模式成功");	
}

void CGsmGprsView::OnButtonReadgprs() 
{
	// TODO: Add your control notification handler code here
	if(Read_GPRS_Data()==FALSE)
	{
		AfxMessageBox("读取GPRS模式失败");
		return;
	}
	else
		AfxMessageBox("读取GPRS模式成功");	
	
}

void CGsmGprsView::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
    if(nIDEvent == 1)//每一秒检测一次临界区,临界区为一个结构体数组
	{
		SM_PARAM SmParam;
		CString strTime;
		CString strNumber;
		CString strContent;

		// 取接收到的短消息
		if(theApp.m_pSmsTraffic->GetRecvMessage(&SmParam))
			//将一个结构体传递过去,获得数据
		{
			// 取短消息信息
			strNumber = SmParam.TPA;
			strContent = SmParam.TP_UD;
	 
			strTime = "20" + CString(&SmParam.TP_SCTS[0],2) //时间格式,2008 
				+ "-" + CString(&SmParam.TP_SCTS[2],2) 
				+ "-" + CString(&SmParam.TP_SCTS[4],2)
				+ " " + CString(&SmParam.TP_SCTS[6],2) 
				+ ":" + CString(&SmParam.TP_SCTS[8],2) 
				+ ":" + CString(&SmParam.TP_SCTS[10],2);

			// 去掉号码前的"86"
			if(strNumber.Left(2) == "86")  strNumber = strNumber.Mid(2);
        	SaveText(strNumber,strContent,strTime);	//	将内容保存在E:\\Info.txt
			// 最多保留200条
			int nItemCount = m_ListCtrl.GetItemCount();
			if(nItemCount >= 200)//超过200条自动删除
			{
				m_ListCtrl.DeleteItem(0);//删除第一条
				nItemCount--;
			}
			
			// 插入新消息
		/*m_ListCtrl.InsertItem(nItemCount, strNumber);
			m_ListCtrl.SetItemText(nItemCount, 1, strTime);
			m_ListCtrl.SetItemText(nItemCount, 2, strContent);
			
			m_ListCtrl.EnsureVisible(nItemCount, FALSE);*/
		}
	}
if(nIDEvent == 2)	
{
 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -