你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

查看: 755|回复: 8

[其他] 一个将中文转换成PDU格式的小工具

[复制链接]

17

主题

445

回帖

68

蝴蝶豆

金牌会员

最后登录
2020-7-29
发表于 2019-11-4 04:14:18 | 显示全部楼层 |阅读模式
用VC++写的,生成后的编码直接复制到AT命令即可实现发送中文短信,目前还有个bug: 汉字后有一问号,但不影响使用
<
回复

使用道具 举报

17

主题

445

回帖

68

蝴蝶豆

金牌会员

最后登录
2020-7-29
 楼主| 发表于 2019-11-4 04:29:34 | 显示全部楼层
为传一个小小的文件,从3:15折磨到4:28,先是文件夹被打乱,后是在SD卡的文件"跑"到手机卡里,所以被迫爬行

HZ2PDU_exe.zip

下载

531.02 KB, 下载次数: 12, 下载积分: ST金币 -1

回复 支持 反对

使用道具 举报

20

主题

1513

回帖

5

蝴蝶豆

论坛元老

最后登录
2020-12-9
发表于 2019-11-4 08:39:45 | 显示全部楼层
熬夜写代码,逛论坛?佩服了
回复 支持 反对

使用道具 举报

17

主题

445

回帖

68

蝴蝶豆

金牌会员

最后登录
2020-7-29
 楼主| 发表于 2019-11-4 15:40:26 | 显示全部楼层
不是熬夜哦,醒了之后睡不着,哎,痛苦啊!
回复 支持 反对

使用道具 举报

17

主题

445

回帖

68

蝴蝶豆

金牌会员

最后登录
2020-7-29
 楼主| 发表于 2020-2-6 03:09:25 | 显示全部楼层
这是PDU 工具的源程序,在vc++6环境中直接打开dsw 或dsp 文件即可,在VS 中可能有新旧版兼容性问题。
想学上位机界面编程的朋友,这是个完整的例子     
折腾半小时也上传不了!改名(全英文,RAR文件),换路径,将编译过程文件删除到只有828k…都不成功,
回复 支持 反对

使用道具 举报

17

主题

445

回帖

68

蝴蝶豆

金牌会员

最后登录
2020-7-29
 楼主| 发表于 2020-2-6 11:34:31 | 显示全部楼层
// PDUuniCodeDlg.cpp : implementation file
#include "stdafx.h"
#include "DUuniCode.h"
#include "DUuniCodeDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
CPDUuniCodeDlg::CPDUuniCodeDlg(CWnd* pParent /*=NULL*/)
        : CDialog(CPDUuniCodeDlg::IDD, pParent){
        //{{AFX_DATA_INIT(CPDUuniCodeDlg)
        //}}AFX_DATA_INIT
        m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CPDUuniCodeDlg:oDataExchange(CDataExchange* pDX){
        CDialog:oDataExchange(pDX);
        //{{AFX_DATA_MAP(CPDUuniCodeDlg)
        //}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPDUuniCodeDlg, CDialog)
        //{{AFX_MSG_MAP(CPDUuniCodeDlg)
        ON_WM_PAINT()
        ON_WM_QUERYDRAGICON()
        ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
        ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
        ON_BN_CLICKED(IDC_CHK_PDU, OnChkPdu)
        //}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
BOOL CPDUuniCodeDlg::OnInitDialog(){
        CDialog::OnInitDialog();
        SetIcon(m_hIcon, TRUE);                        // Set big icon
        SetIcon(m_hIcon, FALSE);                // Set small icon
        SetDlgItemText(IDE_UNICODE,"514D8D3951714EAB");

        SetDlgItemText(IDE_MSG_CENTER,  "+8613800553500");
        SetDlgItemText(IDE_MSG_RECIEVER,"+8613866362895");
        return TRUE;  // return TRUE  unless you set the focus to a control
}
void CPDUuniCodeDlg::OnPaint() {
        if (IsIconic())        {
                CPaintDC dc(this); // device context for painting
                SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
                int cxIcon = GetSystemMetrics(SM_CXICON);
                int cyIcon = GetSystemMetrics(SM_CYICON);
                CRect rect;
                GetClientRect(&rect);
                int x = (rect.Width() - cxIcon + 1) / 2;
                int y = (rect.Height() - cyIcon + 1) / 2;
                dc.DrawIcon(x, y, m_hIcon);
        }        else        {                CDialog::OnPaint();          }
}
HCURSOR CPDUuniCodeDlg::OnQueryDragIcon(){        return (HCURSOR) m_hIcon;  }
// ﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌
#define ZGYD_MSGCODE "+8613800553500" //短信中心号码:上海移动:+8613800210500;上海联通:+8613010314500;
#define CARD_SIMCODE "+8615212252203" //              北京移动:+8613800100500;北京联通:+8613010112500;
#define Recieve_CODE "+8613866362895"
#define InterNationT "91"   //国际化
#define TxMsgUniCode "77ED4FE15E7353F00050004400556A215F0F4F7F75280055006E00690063006F006400657F167801"
//无论中文2国际还是国际2中文,对应的函数都需要调用2次,如:第一次得到大小;第二次真正转换(末尾参数变化)
//
//        int iSize= WideCharToMultiByte(CP_ACP,0,TxUniCode,-1,NULL,0,NULL,NULL);↓AfxMessageBox(MultiByte);
//        WideCharToMultiByte(CP_ACP,0,TxUniCode,-1,MultiByte,iSize+1,NULL,NULL);          MultiByte[iSize+1]='\0';
char  MultiByte[256]={0};  //您好(60A8,597D)再见!(518D89C1,0021)   //"短信平台PDU模式使用Unicode编码";
WCHAR TxUniCode[]={0x77ed,0x4fe1,0x5e73,0x53f0};
char  str[256], strPDU[256];        //11000D91,683168362698F5,000800,0A5DE54F5C987A5229FF01;工作顺利
//--------------------------- 中文转UNICODE -----------------------------------
//调用方法:                                            char multiByte[32]={0};
//    ::GetDlgItemText(m_hWnd,IDE_MULTIBYTE,multiByte,sizeof(multiByte));
//          strChinese2UniCode(multiByte);
//    SetDlgItemText(IDE_UNICODE,str); //  两个EDIT控件和1个按钮实现这4行
//.............................................................................
char* CPDUuniCodeDlg::strChinese2UniCode(char strZW[128]){    // 输入中文字符串
    char stm[4]; DWORD i;  //char strTmp[128]=_T(""); //CP_ACP,CP_UTF8,
        DWORD iSize = MultiByteToWideChar(CP_ACP,0,strZW,-1,NULL,0);//-1:整个串长
        WCHAR* GJuniCode=new wchar_t[iSize+1];
        memset(GJuniCode,0,iSize*2+2);
        int nRet =  MultiByteToWideChar(CP_ACP,0,strZW,-1,GJuniCode,iSize+1);
        if (nRet<0) return "BadFace"; else{ GJuniCode[iSize]='\0';  strcpy(str,"");
        for (i=0;i<(iSize-1);i++){ sprintf(stm,"%X",*(WCHAR*)(GJuniCode+i));
        strcat(str,stm); }}//strcat(strTmp,stm);  //827E,548C,8363<=>艾和荣
        delete [] GJuniCode;   return str;  //return strTmp; ←为何出错????
}//----------------------------------------------------------20190827----------
//2019-08-28 去年父亲
//--------------------------- UNICODE转中文 -----------------------------------
//调用方法:
//char strU[]={"5171515A501F520067404EBA4E4B9634973E85CF4E8E72364EB288AB6BB4"};
//     //::GetDlgItemText(m_hWnd,IDE_UNICODE,strU,sizeof(strU));
//  strUniCode2Chinese(strU);              SetDlgItemText(IDE_MULTIBYTE,str);
//.............................................................................
char* CPDUuniCodeDlg::strUniCode2Chinese(char strGJ[128]){  // 输入16进制国际码
        WCHAR* uniGJ=new wchar_t[128];        memset(uniGJ,0,256);   char ich;
    char strANSI[64]=_T("");  unsigned short iTmp;    int len,i,Siz;
        Siz=strlen(strGJ);
        for(len=0;len<Siz;len+=4){ iTmp=0;
        for(i=0;i<4;i++){      ich=strGJ[len+i];
                        if(ich >0x40 ) ich-=0x37;  else  ich-=0x30;
                        switch(i){        case 3:         iTmp+=ich     ;     break;
                                    case 2:         iTmp+=ich*  16;     break;
                                    case 1:         iTmp+=ich* 256;     break;
                                    case 0:         iTmp+=ich*4096;     break;
                        }//if (((ich>0x40)&&(ich<0x47))||((ich>0x2F)&&(ich<0x3A)))
                }  wcscat(uniGJ,(const unsigned short *)&iTmp);
        }    *(WCHAR*)(uniGJ+len-1)='\0'; //语法:wcscat(uniCode,LPCWSTR(str));
    int need=WideCharToMultiByte(CP_ACP,0,uniGJ,-1, NULL  ,  0   ,NULL,NULL);
        if (need<0)  return "BadFace"; else {
            len= WideCharToMultiByte(CP_ACP,0,uniGJ,-1,strANSI,need+1,NULL,NULL);
                     strANSI[need]='\0';}
        strcpy(str,strANSI); return str;
}//----------------------------------------------------------20190827----------
//=============================================================================
//工程->设置->C/C++->预处理程序定义:将"_MBCS"改成"-UNICODE" 20190826
char* CPDUuniCodeDlg::codeFMTtoPDU(char *TelNum, int ZGYD){     
      int i,len; char j; char code[32]="+8613800100500", ps[8]=InterNationT;
      strcpy(code,TelNum);
      if (strstr(code,"+")){ len = strlen(code); for (i=0;i<len;i++){ j=code[i+1];code[i]=j;}; len--;}
      if (len%2) { strcat(code,"F"); }
      for (i=0;i<(len+1);i+=2){ j=code[i+1];code[i+1]=code[i];code[i]=j; }
      sprintf(str,"%s%s",ps,code);       strcpy(code,str);
      if (ZGYD==1){ len = strlen(str)/2;                   sprintf(str,"%02X%s",     len,code); }
      else        { strcpy(ps,"1100");   strcpy(code,str); sprintf(str,"%s%02X%s",ps,len,code); }
      return str;
}
char* CPDUuniCodeDlg::msgTXcvPDU(char *contxt){  //to finished !
        int len;  char text[128]="Hello World!";    strcpy(text,contxt);      
        len = strlen(text);   sprintf(str,"%02X%s",len/2,text);
        return str;
}
int CPDUuniCodeDlg::numTXmsgPDU(){
    char tmp[256]="", eXchange[256]="";   int lenMix=0;     char *ss1,*ss2;
    ::GetDlgItemText(m_hWnd,IDE_MSG_RECIEVER, tmp,sizeof(tmp)); //strcpy(tmp,Recieve_CODE);
    ss1 = codeFMTtoPDU(tmp,0);     strcpy(strPDU,ss1);    strcat(strPDU,"000800");
    ::GetDlgItemText(m_hWnd,IDE_UNICODE,   tmp,sizeof(tmp)); //strcpy(tmp,TxMsgUniCode);
    if (strlen(tmp)<4) { AfxMessageBox("Input Chinese Message First!"); return 0;}
    ss2 = msgTXcvPDU(tmp);         strcat(strPDU,ss2);    lenMix=strlen(strPDU)/2;
    ::GetDlgItemText(m_hWnd,IDE_MSG_CENTER,tmp,sizeof(tmp)); //strcpy(tmp,ZGYD_MSGCODE);
        strcpy(eXchange,strPDU);
    strcpy(strPDU, codeFMTtoPDU(tmp,1)); strcat(strPDU,eXchange); strcat(strPDU,"Z");
        *(int*)(strPDU+strlen(strPDU)-1)=0x1A;
//    if(((char) *(int*)(strPDU+strlen(strPDU)-1) )==0x1A) AfxMessageBox(_T("Tail is ^Z !"));
    return lenMix;
}
//-----------------------------------------------------------------------------------------------------
void CPDUuniCodeDlg::OnChkPdu() {
        if (IsDlgButtonChecked(IDC_CHK_PDU) != 0)   SetDlgItemText(IDC_BUTTON2,"生成完整编码");
}
void CPDUuniCodeDlg::OnButton1() { //To China
   char strU[]={"5171515A501F520067404EBA4E4B9634973E85CF4E8E72364EB288AB6BB4"};
    ::GetDlgItemText(m_hWnd,IDE_UNICODE,strU,sizeof(strU));
    strUniCode2Chinese(strU);              SetDlgItemText(IDE_MULTIBYTE,str);
}
void CPDUuniCodeDlg::OnButton2() { //To International
        char multiByte[64]={0}; int nc;
    ::SetDlgItemText(m_hWnd,IDE_UNICODE,_T("")); //清空
    ::GetDlgItemText(m_hWnd,IDE_MULTIBYTE,multiByte,sizeof(multiByte)); //读输入的汉字
        strChinese2UniCode(multiByte);  
    ::SetDlgItemText(m_hWnd,IDE_UNICODE,str);
    if (IsDlgButtonChecked(IDC_CHK_PDU) != 0) {         nc = numTXmsgPDU();
            sprintf(multiByte,"%d",nc);  SetDlgItemText(IDE_LEN_PDU,multiByte);
        ::SetDlgItemText(m_hWnd,IDE_UNICODE,strPDU);
        }
}
回复 支持 反对

使用道具 举报

17

主题

445

回帖

68

蝴蝶豆

金牌会员

最后登录
2020-7-29
 楼主| 发表于 2020-2-6 11:36:26 | 显示全部楼层
// PDUuniCodeDlg.h : header file
//

#if !defined(AFX_PDUUNICODEDLG_H__6002B983_BF49_433D_B93B_280736E7ABBB__INCLUDED_)
#define AFX_PDUUNICODEDLG_H__6002B983_BF49_433D_B93B_280736E7ABBB__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

/////////////////////////////////////////////////////////////////////////////
// CPDUuniCodeDlg dialog

class CPDUuniCodeDlg : public CDialog
{
// Construction
public:
        char* Unicode2Ascii(CString uniCode);
        void ConverGBKToUTF8(CString& strGBK);
        void ConverUTF8ToGBK(CString& strUtf8);
        void CString2Char(CString strC, char chC);
        CPDUuniCodeDlg(CWnd* pParent = NULL);        // standard constructor
char* codeFMTtoPDU(char *TelNum, int ZGYD);
char* msgTXcvPDU(char *contxt);
char* strChinese2UniCode(char  strZW[64]);
char* strUniCode2Chinese(char  strGJ[64]);
int   numTXmsgPDU();

// Dialog Data
        //{{AFX_DATA(CPDUuniCodeDlg)
        enum { IDD = IDD_PDUUNICODE_DIALOG };
                // NOTE: the ClassWizard will add data members here
        //}}AFX_DATA

        // ClassWizard generated virtual function overrides
        //{{AFX_VIRTUAL(CPDUuniCodeDlg)
        protected:
        virtual void DoDataExchange(CDataExchange* pDX);        // DDX/DDV support
        //}}AFX_VIRTUAL

// Implementation
protected:
        HICON m_hIcon;

        // Generated message map functions
        //{{AFX_MSG(CPDUuniCodeDlg)
        virtual BOOL OnInitDialog();
        afx_msg void OnPaint();
        afx_msg HCURSOR OnQueryDragIcon();
        afx_msg void OnButton1();
        afx_msg void OnButton2();
        afx_msg void OnChkPdu();
        //}}AFX_MSG
        DECLARE_MESSAGE_MAP()
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_PDUUNICODEDLG_H__6002B983_BF49_433D_B93B_280736E7ABBB__INCLUDED_)
回复 支持 反对

使用道具 举报

17

主题

445

回帖

68

蝴蝶豆

金牌会员

最后登录
2020-7-29
 楼主| 发表于 2020-2-7 02:06:30 | 显示全部楼层
直接打开即可!是一个完整的VC ++源码

tool_vc6.rar

下载

3.45 MB, 下载次数: 3, 下载积分: ST金币 -1

回复 支持 反对

使用道具 举报

0

主题

7

回帖

0

蝴蝶豆

初级会员

最后登录
2020-7-13
发表于 2020-4-30 19:32:15 | 显示全部楼层
这个点发的文章和代码,博主很厉害了,但是也要注意休息啊。
回复 支持 反对

使用道具 举报

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
st-img 微信公众号
st-img 手机版