نمایش نتایج 1 تا 2 از 2

نام تاپیک: فرستادن اس ام اس فارسی با نوکیا 3310

  1. #1

    Question فرستادن اس ام اس فارسی با نوکیا 3310

    من از طریق پورت سریال میتونم اس ام اس بفرستم ولی همه ی اس ام اس هایی که میفرستم انگلیسی هستند من میخوام با دستور فرستادن اس ام اس بتونم اس ام اس فارسی بفرستم .
    ولی نوکیا 3310 از at command پشتیبانی نمیکند و من باید از طریق f-bus این کارو بکنم.
    این تابعی هستش که من با اون اس ام اس میفرستم:



    /*----------------------------------------------------------------------------

    ////////////////////////////n-61///////////////////////////,GComBuf[512];
    // **** Functions ****
    int SendChar1 (int ch);
    void n61_init(int (*func)(int cmd, unsigned char c)); // initialize the driver
    int n61_smssend(unsigned char *dest, unsigned char *msg); // send SMS
    int n61_smsrecv(unsigned char *dest, unsigned char *msg); // recv SMS
    //int n61_smsqueue(); // check the recv queue
    //void n61_update(); // keep the driver in sync

    // **** Functions - internal ****

    //void n61_block(); // protect during update
    //void n61_unblock(); // unprotect

    void n61_update_main(void); // main update
    //void n61_update_internal(); // internal version of
    // n61_update()

    void n61_serial_send(unsigned char c); // send byte
    //unsigned char n61_serial_recv(); // recv byte
    //unsigned char n61_serial_isdata(); // check for serial data
    //void n61_serial_delay(); // wait 1 millisecond

    //int n61_nextseq(); // get next sequence number
    int n61_sendframe(int type, int size, unsigned char *data); // send frame
    int n61_sendmsg(int type, int size, unsigned char *data); // send message
    void n61_sendack(int type, int seqnum); // send acknowledgement

    void n61_ackwait(int x); // wait for ack
    void n61_wait(int x); // wait for a message

    void n61_addchar(unsigned char *str, unsigned char c); // strcat() but for chars
    void n61_bcd(unsigned char *dest, unsigned char *s); // encode SMSC number
    void n61_bcd2(unsigned char *dest, unsigned char *s); // encode phone number
    unsigned char *n61_unbcd(unsigned char *dat); // decode SMSC number
    unsigned char *n61_unbcd2(unsigned char *dat); // decode phone number

    void n61_pack7(unsigned char *dest, unsigned char *s); // pack when sending
    unsigned char *n61_unpack7(unsigned char *dat, int len); // unpack when received

    unsigned char n61_gettrans(unsigned char c); // translate char
    void n61_addmsg(unsigned char *dest, unsigned char *msg); // add a received SMS
    // to the queue

    void n61_procmsg(struct N61_MESSAGE *msg); // process incoming message

    //void n61_getstatus(); // request phone status
    //void n61_getsmsc(); // request SMSC
    void n61_delsms(int x); // delete SMS message
    int n61_smssendfull(unsigned char *smsc, unsigned char *dest, unsigned char *msg); // send SMS via SMSC
    int myhandler(int cmd, unsigned char c);

    ////////////Function Declare/////////////////////
    unsigned char CalCrc(unsigned char GetSet, unsigned char CmdLen, unsigned char CrcNo);//ÊÇÈÚ ãÍÇÓÈå CRC
    void CheckBus(void);//ÊÇÈÚ ÈÑÇí ÌÏÇ ˜ÑÏä ÏÓÊæÑÇÊ íÇ ÌæÇÈ ÏÓÊæÑÇÊ
    void TranslateData(void);//ÈÑÇí ÑÏÇÒÔ ÏÇÏå åÇí ÏÑíÇÝÊí ÇÒ æÑÊ ÏÓÊæÑ íÇ ÌæÇÈ ÏÓÊæÑÑÇ ˜ ãí ˜äÏ
    void SendCmd(unsigned char CmdNo, unsigned char CmdLen, unsigned char CrcNo);//(GTmp)ÈÑÇí ÇÑÓÇá í˜ ÏÓÊæÑãæÑÏ ÇÓÊÝÇÏå ÞÑÇÑ ãí íÑÏ (æÑæÏíåÇ ÔãÇÑå ÏÓÊæÑ Øæá ÑÔÊå ÇÑÇãÊÑåÇ æ ÔãÇÑå Óí ÂÑ Óí ãí ÈÇÔÏ ÑÔÊå ÇÑÇãÊÑåÇ ãÊÛíÑ ÓÑÇÓÑí ÇÓÊ ˜å ÞÈá ÇÒ ÝÑÇÎæÇäí Çíä ÊÇÈÚ Ñ ãí ÔæÏ)Ê
    void SendAnswer(unsigned char AnsLen, unsigned char CrcNo);// CRC Ñ ãí ÔæÏ æ ÔãÇÑå GTmp ÇÑÓÇá ÌæÇÈ ÏÓÊæÑ ÏÑíÇÝÊí¡ ÇÑÇãÊÑåÇ:Øæá ÇÑÇãÊÑ ÌæÇÈ ÏÓÊæÑ ˜å ÏÑ ãÊÛíÑ
    void SendToPC(void);
    //////////////////////////

    //?????????????????????????????????????????????????? ???????????????????????????????????????????

    void strcopy(unsigned char sourc[],unsigned char indx,char len) //convert characters from string
    {
    char i;//,len;
    memset(msg2,0,20);
    for (i = indx; i < (len+indx); i++)
    {
    msg2[i] = sourc[i-indx];
    }
    msg=msg2;
    }

    //?????????????????????????????????????????????????? ?????????????????????????????????????????????

    void InitDecript(void) // for change usb descriptor
    {
    char change[17];
    char i,tmp;
    for(i = 0; i < 17; i++)//read from eprom to change hid friendly name
    {
    change[i] = read_by_ID(id_of_no+i);
    }
    tmp = 0;
    for(i = 0; i < 17; i++)//check eprom memory if = ff then write default string to these index memory
    {
    if (change[i] != 0xff)
    tmp = 1;
    }
    if (tmp == 0)
    {
    i = 0;
    change[i] = 'M';i++;
    change[i] = '.';i++;
    change[i] = 'S';i++;
    change[i] = '.';i++;
    change[i] = 'I';i++;
    change[i] = 'O';i++;
    change[i] = ' ';i++;
    change[i] = ' ';i++;
    change[i] = 'G';i++;
    change[i] = 'S';i++;
    change[i] = 'M';i++;
    change[i] = '3';i++;
    change[i] = ' ';i++;
    change[i] = '0';i++;
    change[i] = '0';i++;
    change[i] = '0';i++;
    change[i] = '0';
    for(i = 0; i < 17; i++)
    {
    Write_by_ID(id_of_no+i,change[i]); //write default string to these index memory
    }
    }
    USB_StringDescriptor[0] = 0x04;
    USB_StringDescriptor[1] = USB_STRING_DESCRIPTOR_TYPE;
    USB_StringDescriptor[2] = 0x09;
    USB_StringDescriptor[3] = 0x04;
    USB_StringDescriptor[4] = 0x1C;
    USB_StringDescriptor[5] = USB_STRING_DESCRIPTOR_TYPE;

    USB_StringDescriptor[6] = 'M'; USB_StringDescriptor[7] = 0;
    USB_StringDescriptor[8] = 'A'; USB_StringDescriptor[9] = 0;
    USB_StringDescriptor[10] = 'N'; USB_StringDescriptor[11] = 0;
    USB_StringDescriptor[12] = 'S'; USB_StringDescriptor[13] = 0;
    USB_StringDescriptor[14] = 'H'; USB_StringDescriptor[15] = 0;
    USB_StringDescriptor[16] = 'O'; USB_StringDescriptor[17] = 0;
    USB_StringDescriptor[18] = 'O'; USB_StringDescriptor[19] = 0;
    USB_StringDescriptor[20] = 'R'; USB_StringDescriptor[21] = 0;
    USB_StringDescriptor[22] = 'S'; USB_StringDescriptor[23] = 0;
    USB_StringDescriptor[24] = 'I'; USB_StringDescriptor[25] = 0;
    USB_StringDescriptor[26] = 'M'; USB_StringDescriptor[27] = 0;
    USB_StringDescriptor[28] = 'I'; USB_StringDescriptor[29] = 0;
    USB_StringDescriptor[30] = 'N'; USB_StringDescriptor[31] = 0;

    USB_StringDescriptor[32] = 0x24;
    USB_StringDescriptor[33] = USB_STRING_DESCRIPTOR_TYPE;

    USB_StringDescriptor[34] = change[0]; USB_StringDescriptor[35] = 0;
    USB_StringDescriptor[36] = change[1]; USB_StringDescriptor[37] = 0;
    USB_StringDescriptor[38] = change[2]; USB_StringDescriptor[39] = 0;
    USB_StringDescriptor[40] = change[3]; USB_StringDescriptor[41] = 0;
    USB_StringDescriptor[42] = change[4]; USB_StringDescriptor[43] = 0;
    USB_StringDescriptor[44] = change[5]; USB_StringDescriptor[45] = 0;
    USB_StringDescriptor[46] = change[6]; USB_StringDescriptor[47] = 0;
    USB_StringDescriptor[48] = change[7]; USB_StringDescriptor[49] = 0;
    USB_StringDescriptor[50] = change[8]; USB_StringDescriptor[51] = 0;
    USB_StringDescriptor[52] = change[9]; USB_StringDescriptor[53] = 0;
    USB_StringDescriptor[54] = change[10]; USB_StringDescriptor[55] = 0;
    USB_StringDescriptor[56] = change[11]; USB_StringDescriptor[57] = 0;
    USB_StringDescriptor[58] = change[12]; USB_StringDescriptor[59] = 0;
    USB_StringDescriptor[60] = change[13]; USB_StringDescriptor[61] = 0;
    USB_StringDescriptor[62] = change[14]; USB_StringDescriptor[63] = 0;
    USB_StringDescriptor[64] = change[15]; USB_StringDescriptor[65] = 0;
    USB_StringDescriptor[66] = change[16]; USB_StringDescriptor[67] = 0;

    /* Index 0x44: Serial Number */
    USB_StringDescriptor[68] = 0x1A;
    USB_StringDescriptor[69] = USB_STRING_DESCRIPTOR_TYPE;
    USB_StringDescriptor[70] = 'V';
    USB_StringDescriptor[71] = 0;
    USB_StringDescriptor[72] = 'E';
    USB_StringDescriptor[73] = 0;
    USB_StringDescriptor[74] = 'R';
    USB_StringDescriptor[75] = 0;
    USB_StringDescriptor[76] = ' ';
    USB_StringDescriptor[77] = 0;
    USB_StringDescriptor[78] = ' ';
    USB_StringDescriptor[79] = 0;
    USB_StringDescriptor[80] = '0';
    USB_StringDescriptor[81] = 0;
    USB_StringDescriptor[82] = '1';
    USB_StringDescriptor[83] = 0;
    USB_StringDescriptor[84] = '.';
    USB_StringDescriptor[85] = 0;
    USB_StringDescriptor[86] = '0';
    USB_StringDescriptor[87] = 0;
    USB_StringDescriptor[88] = '0';
    USB_StringDescriptor[89] = 0;
    USB_StringDescriptor[90] = ' ';
    USB_StringDescriptor[91] = 0;
    USB_StringDescriptor[92] = ' ';
    USB_StringDescriptor[93] = 0;

    USB_StringDescriptor[94] = 0x08;
    USB_StringDescriptor[95] = USB_STRING_DESCRIPTOR_TYPE;
    USB_StringDescriptor[96] = 'H';
    USB_StringDescriptor[97] = 0;
    USB_StringDescriptor[98] = 'I';
    USB_StringDescriptor[99] = 0;
    USB_StringDescriptor[100] = 'D';
    USB_StringDescriptor[101] = 0;
    }



    // if (GAnsOk == 1)GAnsOk =0;

    void SendToPC(void)
    {
    GetInReport();
    USB_WriteEP(0x81, &InReport, sizeof(InReport));
    }

    void wait2(void)
    {
    unsigned int j;
    j = 15000;
    while (j > 0)
    j--;
    }

    unsigned char CalCrc(unsigned char GetSet, unsigned char CmdLen, unsigned char CrcNo)
    {
    unsigned char Crc, i,j;
    int SumCrc;
    SumCrc = 0;
    CRCCheck = 0;
    if (GetSet == 'g')
    {
    for(i = 0; i < CmdLen; i++)
    {
    SumCrc = SumCrc + GGetCmd[i];
    GTmp[i] = GGetCmd[i];
    }
    }
    else
    {
    for(i = 0; i < CmdLen; i++)
    {
    SumCrc = SumCrc + GSendCmd[i];
    }
    }
    switch (CrcNo)
    {
    case 1:
    {
    Crc = ((CmdLen + SumCrc) & 0xFC);
    if ((Crc + GResCmd) == GGetCmd[GLastPos+1])
    CRCCheck = 1;
    break;
    }
    case 2:
    {
    Crc = CmdLen + SumCrc;
    Crc = ~(Crc);
    if (Crc == GGetCmd[GLastPos+2])
    CRCCheck = 1;
    break;
    }
    case 3:
    {
    if (Crc == GGetCmd[GLastPos+3])
    CRCCheck = 1;
    break;
    }
    }
    if (GetSet == 'g')
    {
    j = 0;
    for(i = 0; i < CmdLen - 1; i++)
    {
    if ((GTmp[i] == '$') || (GTmp[i] == '('))
    {
    if (i < CmdLen - 2)
    {
    if (GTmp[i] == GTmp[i+1])
    i++;
    }
    }
    GGetCmd[j] = GTmp[i];
    j++;
    }
    }
    return Crc;
    }


    /*----------------------------------------------------------------------------
    Set HID Output Report <- OutReport
    *----------------------------------------------------------------------------*/


    void CheckBus(void)
    {
    if (GResCmd > 0)
    {
    if (GReadCo == 0)
    {
    if (GGetCmd[GReadIn] == GGetCmd[GReadIn-1])
    {
    if ((odd & 1) == 1)
    {
    GReadCo = 0;
    GResCmd = 0;
    }
    }
    else
    GResCmd = GGetCmd[GReadIn] & 0X03;
    }
    if (GResCmd > 0)
    {
    GReadCo++;
    if (GReadCo == GResCmd)
    {
    TranslateData();
    GReadCo = 0;
    GResCmd = 0;
    odd = 0;
    }
    }
    }
    if ((GGetCmd[GReadIn] == '$') || (GGetCmd[GReadIn] == '('))
    {
    odd++;
    if ((odd & 1) == 1)
    {
    GLastPos = GReadIn;
    GReadCo = 0;
    GResCmd = 1;
    }
    }
    }

    void TranslateData(void)
    {
    if (GLastPos != -1)
    {
    if (GResCmd >= 1)
    {
    CalCrc('g', GLastPos+1, 1);
    }
    if((CRCCheck == 1)&&(GResCmd >= 2))
    {
    CalCrc('g', GLastPos+1, 2);
    }
    if((CRCCheck == 1)&&(GResCmd == 3))
    {
    CalCrc('g', GLastPos+1, 3);
    }
    }
    GReadIn = -1;
    if (CRCCheck == 1)
    {
    if (Answait == 1)
    GAnsOk = 1;
    else
    GReciveCMD = 1;//ÏÑíÇÝÊ ÔÏ CMD í˜
    }
    else
    {
    if (Answait == 1)
    GAnsOk = 2;//ÏÑ ÕæÑÊ ÕÍíÍ äÈæÏä crc
    else
    GReciveCMD = 2;//ÏÑ ÕæÑÊ ÕÍíÍ äÈæÏä crc
    }
    }

    void SendCmd(unsigned char CmdNo,unsigned char CmdLen,unsigned char CrcNo)//ÇÑÓÇá ÏÓÊæÑ Èå ˜ÇãíæÊÑ
    {
    int i,j;
    GSendCmd[0] = CmdNo;//ÔãÇÑå ÏÓÊæÑ
    GCmdLen = CmdLen;
    j = 1;
    for(i = 1; i <= CmdLen; i++)
    {
    if (GTmp[i-1] == '(')
    {
    GCmdLen++;
    GSendCmd[j] = GTmp[i-1];
    j++;
    }
    GSendCmd[j] = GTmp[i-1];
    j++;
    }
    i = j;
    GSendCmd[i] = '(';
    GCmdLen += 2;
    if (CrcNo >= 1)
    {
    i++;
    GSendCmd[i] = (CrcNo + CalCrc('s', GCmdLen, 1));
    }
    if (CrcNo >= 2)
    {
    i++;
    GSendCmd[i] = CalCrc('s', GCmdLen, 2);
    }
    if (CrcNo == 3)
    {
    i++;
    GSendCmd[i] = CalCrc('s', GCmdLen, 3);
    }
    GCmdLen = GCmdLen + CrcNo - 1;
    for(i = 0; i <= GCmdLen; i++)
    {
    gg = GSendCmd[i]; //ÇÑÓÇá Èå æÑÊ
    SendToPC();
    wait2();
    }
    GAnsOk = 0;
    Answait = 1;
    }

    void SendAnswer(unsigned char AnsLen, unsigned char CrcNo)//ÇÑÓÇá ÌæÇÈ ÏÓÊæÑ
    {
    int i,j;
    GSendCmd[0] = '#';
    GCmdLen = AnsLen;
    j = 1;
    for(i = 1; i <= AnsLen; i++)
    {
    if ((GTmp[i-1] == '#') || (GTmp[i-1] == '$'))
    {
    GCmdLen++;
    GSendCmd[j] = GTmp[i-1];
    j++;
    }
    GSendCmd[j] = GTmp[i-1];
    j++;
    }
    i = j;
    GSendCmd[i] = '$';
    GCmdLen += 2;
    if (CrcNo >= 1)
    {
    i++;
    GSendCmd[i] = (CrcNo + CalCrc('s', GCmdLen, 1));
    }
    if (CrcNo >= 2)
    {
    i++;
    GSendCmd[i] = CalCrc('s', GCmdLen, 2);
    }
    if (CrcNo == 3)
    {
    i++;
    GSendCmd[i] = CalCrc('s', GCmdLen, 3);
    }
    GCmdLen = GCmdLen + CrcNo-1;
    for(i = 0; i <= GCmdLen; i++)
    {
    gg = GSendCmd[i]; //ÇÑÓÇá Èå æÑÊ
    SendToPC();
    wait2();
    }
    }

    void SavePassword(unsigned char *pass)
    {
    char i;
    for(i = 0; i < 6; i++)
    Write_by_ID(id_of_Pass+i,pass[i]);
    }

    void ReadPassword(void)
    {
    char i;
    unsigned char rdata[6];
    for(i = 0; i < 6; i++)
    {
    rdata[i] = read_by_ID(id_of_Pass+i);
    }
    Eppass = rdata;
    }

    /*void SaveSMSCent(unsigned char *pass)
    {
    unsigned char i;
    for(i=0; i < 13; i++)
    Write_by_ID(id_of_no+107+i,pass[i]);
    } */

    void ReadSMSCent(void)
    {
    Scenter = read_by_ID(id_of_SMSCent);
    if(Scenter == 0)strcopy("+9891100500",0,11);
    else strcopy("+989350001400",0,13);
    }

    void SaveSMSCent(void)
    {
    // unsigned char i,rdata[13],tmp,rdata2[11];
    if(Scenter) Write_by_ID(id_of_SMSCent,1); //+989350001400
    else Write_by_ID(id_of_SMSCent,0); //+989110500

    }

    void SaveDelMobNO(unsigned char Del,unsigned char indx, unsigned char *pass) // Save or delete Mobile total 4 no
    {
    char i;
    for(i = 0; i < 11; i++)
    {
    if (Del == 0)
    {
    Write_by_ID(id_of_TelNO+(indx*11+i),pass[i]);
    EpMobNO[indx-1][i] = pass[i];
    }
    else
    {
    Write_by_ID(id_of_TelNO+(indx*11+i),255);
    EpMobNO[indx-1][i] = 0xff;
    }
    }
    }

    void ReadMobNO(unsigned char indx)
    {
    char i;
    for(i = 0; i < 11; i++)
    {
    EpMobNO[indx-1][i] = read_by_ID(id_of_TelNO+(indx*11)+i);
    //printf("%d,",EpMobNO[indx-1][i]);
    }
    }

    void SaveAutoSendSms()
    {
    char i;
    Write_by_ID(id_of_AutoSMSFlag,autosms);
    if (autosms == 0) timstart = 0;
    for(i = 0; i < 8; i++)
    {
    Write_by_ID(id_of_InpCheck+i,Inptchk[i]);
    }
    for(i = 0; i < 8; i++)
    {
    Write_by_ID(id_of_DisInptchk+i,DisInptchk[i]);
    }
    /*for (i = 0;i < 11;i++)
    {
    Write_by_ID(id_of_no+j,PHNO[i]);
    j++;
    } */
    Write_by_ID(id_of_smstimer,smstimer);
    }

    void ReadAutoSendSms(void)
    {
    char i;

    autosms = read_by_ID(id_of_AutoSMSFlag);
    if (autosms == 0) timstart = 0;

    for(i=0; i<8; i++)
    {
    Inptchk[i] = read_by_ID(id_of_InpCheck+i);
    }
    for(i=0; i<8; i++)
    {
    DisInptchk[i] = read_by_ID(id_of_DisInptchk+i);
    }

    smstimer = read_by_ID(id_of_smstimer);
    }

    // ** Code **
    void wait(void)
    {
    unsigned int j;
    j = 15000;
    while (j > 0)
    j--;
    }

    int myhandler(int cmd, unsigned char c)
    {



    if(cmd == 0)
    {
    //n61_serial_send(c); // send c out the port
    // putchar(c); // wait(); fn61_init
    SendChar(c);

    return 1;
    }
    else
    if(cmd == 1)
    {
    if (USART2->SR & USART_FLAG_RXNE)
    {
    {
    GetKey();
    }
    return 1;
    }
    else
    return 0;// return zero if queue is empty
    }
    else
    if(cmd == 2) //
    {
    if (USART2->SR & USART_FLAG_RXNE)
    return 1;
    else
    return 0;//for test return 0; // return zero if queue is empty */
    }
    else
    if(cmd == 3) ;
    wait(); // delay for 1 millisecond
    return 1;
    }

    unsigned char n61_gettrans(unsigned char c)
    {
    unsigned char n;
    if(c == '?')
    return 0x3f;
    for(n = 0; n < 128; ++n)
    {
    if(n61_transtable[n] == c)
    return n;
    }
    return 0x3f;
    }

    void n61_block()
    {
    n61_blocked = 1;
    }

    void n61_unblock()
    {
    n61_blocked = 0;
    }

    void n61_update()
    {
    if(!n61_blocked)
    {
    n61_block();
    n61_update_main();
    n61_unblock();
    }
    }

    void n61_update_internal()
    {
    n61_update_main();
    }

    void n61_serial_send(unsigned char c)
    {
    n61_serial(0, c);
    }

    //unsigned char n61_serial_recv()
    //{
    // return n61_serial(1, 0);
    //}

    //unsigned char n61_serial_isdata()
    //{
    // return n61_serial(2, 0);
    //}

    void n61_serial_delay()
    {
    n61_serial(3, 0);
    }

    void n61_ackwait(int x)
    {
    int n;
    for(n = 0; n < x; ++n)
    {
    ////////////////////////////////////////NEW
    //n61_serial_recv();
    ///////////////////////////////////////
    n61_update_internal();
    n61_serial_delay();
    if(n61_ack)
    return;
    }
    }

    void n61_wait(int x)
    {
    int n;
    for(n = 0; n < x; ++n)
    {
    ////////////New///////////
    // n61_serial_recv();
    //////////////////////
    n61_update_internal();
    n61_serial_delay();
    if(n61_gotmsg)
    return;
    }
    }

    void n61_addmsg(unsigned char *dest, unsigned char *msg)
    {
    int n;
    // clip args for safety. in theory not necessary
    msg[160] = 0;
    dest[16] = 0;

    // add the message
    if (n61_msgqueuesize == 15) n61_msgqueuesize = 0;
    n = n61_msgqueuesize;
    strcpy(n61_msgqueue[n], msg);
    strcpy(n61_msgqueue2[n], dest);
    ++n61_msgqueuesize;
    }

    int n61_smsrecv(unsigned char *dest, unsigned char *msg)
    {
    int n;
    n61_block();
    n = n61_msgqueuesize;
    if(n <= 0)
    {
    n61_unblock();
    return 0;
    }
    strcpy(msg, n61_msgqueue[0]);
    strcpy(dest, n61_msgqueue2[0]);
    --n61_msgqueuesize;

    for(n = 0; n < n61_msgqueuesize; ++n)
    {
    strcpy(n61_msgqueue[n], n61_msgqueue[n+1]);
    strcpy(n61_msgqueue2[n], n61_msgqueue2[n+1]);
    }
    n61_unblock();
    return 1;
    }

    int n61_smsqueue()
    {
    return n61_msgqueuesize;
    }

    int n61_sendframe(int type, int size, unsigned char *data)
    {
    unsigned char buf[256];
    int at, n, check, len;
    unsigned short *p;
    at = 0;

    // build header
    buf[at++] = 0x1e; // message startbyte
    buf[at++] = 0x00; // dest: phone
    buf[at++] = 0x0c; // source: PC
    buf[at++] = type;
    buf[at++] = 0x00;
    buf[at++] = size;

    // add data
    for(n = 0; n < size; ++n)
    buf[at++] = data[n];

    // if odd numbered, add filler byte
    if(size % 2)
    {
    buf[at++] = 0x00;
    }

    // calculate checksums
    check = 0;
    p = (unsigned short *)buf;
    len = at / 2;
    for(n = 0; n < len; ++n)
    check ^= p[n];
    p[n] = check;
    at += 2;

    // send the message!
    for(n = 0; n < at; ++n)
    {
    n61_serial_send(buf[n]);
    // n61_wait(100);
    }
    return 1;
    }

    int n61_nextseq()
    {
    int n;
    n = n61_seqnum;
    n61_prevseq = n;
    ++n61_seqnum;
    n61_seqnum &= 7;
    return (n + 0x40);
    }

    int n61_sendmsg(int type, int size, unsigned char *data)
    {
    unsigned char buf[N61MAXSIZE + 2];
    unsigned char num, lastsize;
    int n;
    int len;

    num = (size + N61MAXSIZE - 1) / N61MAXSIZE;
    lastsize = size % N61MAXSIZE;
    for(n = 0; n < num;)
    {
    if(n + 1 == num)
    len = lastsize;
    else
    len = N61MAXSIZE;

    // get current chunk
    memcpy(buf, data + (n * N61MAXSIZE), len);
    buf[len] = num - n;
    buf[len+1] = n61_nextseq();
    if(n)
    buf[len+1] &= 7;
    n61_ack = 0;
    n61_sendframe(type, len + 2, buf);
    n61_ackwait(1000);
    //if(n61_ack)////////////NEW
    ++n;
    }
    return 1;
    }

    void n61_sendack(int type, int seqnum)
    {
    unsigned char buf[2];
    buf[0] = type;
    buf[1] = seqnum;
    n61_sendframe(0x7f, 2, buf);
    }

    void n61_update_main()
    {
    int n;
    unsigned char c;
    while (/*n61_serial_recv()) */GComBuf[GRIndex] != -1)
    {
    //c = n61_serial_recv();
    c = GComBuf[GRIndex];//RecData;
    //SendChar1(GComBuf[GRIndex]);
    GComBuf[GRIndex] = -1;
    GRIndex++;
    if (GRIndex > 511)
    GRIndex = 0;
    // calculate the checksums
    n61_tmp.cs[n61_atbyte & 1] ^= c;
    // act on the byte
    switch(n61_mode)
    {
    case N61MODE_SYNC:
    if(c == 0x1e)
    {
    if(!n61_multiple)
    {
    memset(n61_tmp.dat, 0, 256);
    n61_atbyte = 0;
    }
    n61_tmp.cs[0] = 0x1e;
    n61_tmp.cs[1] = 0;
    n61_mode = N61MODE_DEST;
    }
    break;
    case N61MODE_DEST:
    n61_tmp.dest = c;
    n61_mode = N61MODE_SOURCE;
    break;
    case N61MODE_SOURCE:
    n61_tmp.source = c;
    n61_mode = N61MODE_TYPE;
    break;
    case N61MODE_TYPE:
    n61_tmp.type = c;
    n61_mode = N61MODE_UNKNOWN;
    break;
    case N61MODE_UNKNOWN:
    n61_tmp.unknown = c;
    n61_mode = N61MODE_SIZE;
    break;
    case N61MODE_SIZE:
    if(n61_multiple)
    n61_tmp.size += c - 2;
    else
    {
    n61_tmp.size = c;
    n61_datp = 0;
    }
    n61_mode = N61MODE_DATA;
    // calculate the number of bytes to read
    n = n61_tmp.size % 2;
    // message size + filler + checksums
    n61_readsize = n61_tmp.size + n + 2;
    break;
    case N61MODE_DATA:
    n = n61_datp++;
    if(n > 255)
    {
    n61_multiple = 0;
    n61_mode = N61MODE_SYNC;
    break;
    }
    n61_tmp.dat[n] = c; // get the byte
    // are we done yet?
    if(n >= n61_readsize - 1)
    {
    // checksums ok?
    if(n61_tmp.cs[0] == n61_tmp.cs[1] && n61_tmp.cs[0] == 0)
    {
    // don't want to ACK on an ACK
    if(n61_tmp.type != 0x7f)
    {
    n61_sendack(n61_tmp.type, n61_tmp.dat[n61_tmp.size-1] & 0x0f);
    if(n61_tmp.size > 1 && n61_tmp.dat[n61_tmp.size-2] != 0x01)
    {
    n61_datp -= 4; // back up past checksums and seqinfo
    ++n61_multiple;
    }
    else
    n61_multiple = 0;
    }
    if(!n61_multiple || n61_tmp.type == 0x7f)
    {
    n61_multiple = 0;
    memcpy(&n61_buf, &n61_tmp, sizeof(struct N61_MESSAGE));
    n61_procmsg(&n61_buf);
    }
    }
    else
    {
    // bad!
    n61_multiple = 0;
    }
    n61_mode = N61MODE_SYNC;
    }
    default:
    break;
    }
    ++n61_atbyte;
    }
    }

    void n61_getstatus()
    {
    unsigned char buf[32];
    buf[0] = 0x00;
    buf[1] = 0x01;
    buf[2] = 0x00;
    buf[3] = 0x6d;
    n61_sendmsg(0x11, 4, buf);
    }

    void n61_getsmsc()
    {
    unsigned char buf[32];

    buf[0] = 0x00;
    buf[1] = 0x01;
    buf[2] = 0x00;

    buf[3] = 0x33;
    buf[4] = 0x64;

    buf[5] = 0x01;

    // "do" or "try", there is no "do not"
    //while(1)
    {
    // send off the request
    n61_state = N61STATE_PROC;

    n61_gotmsg = 0;
    n61_waittype = 2;
    n61_sendmsg(0x02, 6, buf);

    n61_wait(1000);
    // if(n61_state == N61STATE_GOOD)
    // break;
    }
    }

    void n61_delsms(int x)
    {
    unsigned char buf[32];

    buf[0] = 0x00;
    buf[1] = 0x01;
    buf[2] = 0x00;

    buf[3] = 0x0a;
    buf[4] = 0x02;
    buf[5] = x;

    n61_sendmsg(0x14, 6, buf);
    }

    void n61_bcd(unsigned char *dest, unsigned char *s)
    {
    int x, y, n, hi, lo;

    if(s[0] == '+')
    {
    dest[1] = 0x91;
    ++s;
    }
    else
    dest[1] = 0x81;

    x = 0;
    y = 2;
    while(s[x])
    {
    lo = s[x++] - '0';
    if(s[x])
    hi = s[x++] - '0';
    else
    hi = 0x0f;
    n = (hi << 4) + lo;
    dest[y++] = n;
    }
    dest[0] = y - 1;
    }

    void n61_bcd2(unsigned char *dest, unsigned char *s)
    {
    int x, y, n, hi, lo;
    if(s[0] == '+')
    {
    dest[1] = 0x91;
    ++s;
    }
    else
    dest[1] = 0x81;
    x = 0;
    y = 2;
    while(s[x])
    {
    lo = s[x++] - '0';
    if(s[x])
    hi = s[x++] - '0';
    else
    hi = 0x0f;

    n = (hi << 4) + lo;
    dest[y++] = n;
    }
    dest[0] = strlen(s);
    }

    void n61_pack7(unsigned char *dest, unsigned char *s)
    {
    int len;
    unsigned short *p, w;
    int at;
    int shift;
    int n, x;
    len = strlen(s);
    x = (len * 8) / 7;
    for(n = 0; n < x; ++n)
    dest[n] = 0;
    shift = 0;
    at = 0;
    w = 0;
    for(n = 0; n < len; ++n)
    {
    p = (unsigned short *)(dest + at);
    w = n61_gettrans(s[n]) & 0x7f;
    w <<= shift;
    *p |= w;
    shift += 7;
    if(shift >= 8)
    {
    shift &= 7;
    ++at;
    }
    }
    }

    int n61_smssendfull(unsigned char *smsc, unsigned char *dest, unsigned char *msg)
    {
    unsigned char buf[256];
    int i;
    // standard frame data header
    buf[0] = 0x00;
    buf[1] = 0x01;
    buf[2] = 0x00;

    // send sms ?
    buf[3] = 0x01;
    buf[4] = 0x02;
    buf[5] = 0x00;

    // smsc

    memset(buf + 6, 0, 12);
    n61_bcd(buf + 6, smsc);

    // TPDU ?
    buf[18] = 0x11;

    // misc
    buf[19] = 0x00; // message ref
    buf[20] = 0x00; // protocol ID
    buf[21] = 0xf1; // data coding scheme (non-flash)

    // message size

    buf[22] = strlen(msg);

    // destination
    memset(buf + 23, 0, 12);
    n61_bcd2(buf + 23, dest);

    // validity period
    buf[35] = N61VALID_24H;

    // filler
    buf[36] = 0;
    buf[37] = 0;
    buf[38] = 0;
    buf[39] = 0;
    buf[40] = 0;
    buf[41] = 0;

    // the string
    n61_pack7(buf + 42, msg);

    // try till we get some response
    //while(1) /////////New
    for(i=0;i<2;i++)
    {

    n61_state = N61STATE_PROC;
    n61_gotmsg = 0;
    n61_waittype = 1;
    n61_sendmsg(0x02, 42 + strlen(msg), buf);
    // n61_sendmsg(0x02, 42 + strlen(msg), buf);
    // if ((USART2->SR & USART_FLAG_RXNE))
    {
    GetKey();
    }
    n61_wait(100);


    // if(n61_state != N61STATE_PROC)///////////////////
    // break;
    }

    // if(n61_state == N61STATE_GOOD)
    return 1;
    //else
    //return 0;
    }

    int n61_smssend(unsigned char *dest, unsigned char *msg)
    {
    int n;
    n61_block();
    n = n61_smssendfull(n61_smsc, dest, msg);
    n61_unblock();
    return n;
    }

    void n61_addchar(unsigned char *str, unsigned char c)
    {
    int n;
    n = strlen(str);
    str[n] = c;
    str[n+1] = 0;
    }

    unsigned char *n61_unbcd(unsigned char *dat)
    {
    static unsigned char buf[32];
    int len;
    int n, x;

    buf[0] = 0;
    len = dat[0];

    if(dat[1] == 0x91)
    {
    n61_addchar(buf, '+');
    }

    for(n = 0; n < len-1; ++n)
    {
    x = dat[n+2] & 0x0f;
    if(x < 10)
    n61_addchar(buf, '0' + x);
    x = (dat[n+2] >> 4) & 0x0f;
    if(x < 10)
    n61_addchar(buf, '0' + x);
    }
    return buf;
    }

    unsigned char *n61_unbcd2(unsigned char *dat)
    {
    static unsigned char buf[32];
    int len;
    int n, x;
    int at;

    buf[0] = 0;
    len = dat[0];

    if(dat[1] == 0x6f || dat[1] == 0x91)
    {
    n61_addchar(buf, '+');
    }

    at = 2;
    for(n = 0; n < len; ++n)
    {
    x = dat[at] & 0x0f;
    if(x < 10)
    n61_addchar(buf, '0' + x);
    ++n;
    if(!(n < len))
    break;
    x = (dat[at] >> 4) & 0x0f;
    if(x < 10)
    n61_addchar(buf, '0' + x);
    ++at;
    }
    return buf;
    }

    unsigned char *n61_unpack7(unsigned char *dat, int len)
    {
    static unsigned char buf[256];
    unsigned short *p, w;
    unsigned char c;
    int n;
    int shift;
    int at;

    shift = 0;
    at = 0;
    buf[0] = 0;
    for(n = 0; n < len; ++n)
    {
    p = (unsigned short *)(dat + at);
    w = *p;
    w >>= shift;
    c = w & 0x7f;

    shift += 7;
    if(shift & 8)
    {
    shift &= 0x07;
    ++at;
    }
    n61_addchar(buf, n61_transtable[c]);
    }
    return buf;
    }

    void n61_procmsg(struct N61_MESSAGE *msg)
    {
    int subtype;
    // check if this is a msg of interest
    subtype = 0;
    if(msg->type != 0x7f)
    {
    if(msg->type == 0x02)
    {
    if(msg->dat[3] == 0x02 || msg->dat[3] == 0x03)
    subtype = 1;
    if(msg->dat[3] == 0x10)
    subtype = 2;
    if(msg->dat[3] == 0x34)
    subtype = 3;
    }
    if(subtype == n61_waittype)
    n61_gotmsg = 1;
    }
    // act on it
    switch(msg->type)
    {
    // SMS
    case 0x02:
    if(msg->dat[3] == 0x02)
    {
    n61_state = N61STATE_GOOD;
    }
    if(msg->dat[3] == 0x03)
    {
    n61_state = N61STATE_BAD;
    }
    if(msg->dat[3] == 0x10)
    {
    n61_addmsg(n61_unbcd2(msg->dat + 23), n61_unpack7(msg->dat + 42, msg->dat[22]));
    // now delete the msg
    if(msg->dat[5])
    n61_delsms(msg->dat[5]);
    }
    // SMSC
    if(msg->dat[3] == 0x34)
    {
    n61_state = N61STATE_GOOD;
    strcpy(n61_smsc, n61_unbcd(msg->dat+21));
    }
    break;
    case 0x7f:
    if((msg->dat[1] & 7) == n61_prevseq)
    n61_ack = 1;
    //if(msg->dat[0] == 0xD1)
    n61_Pow = 1;//D1,84,CF,E9 call phon
    break;
    case 0xD0:
    if((msg->dat[0] == 1) & (msg->dat[1] == 1))
    n61_Pow = 1;
    break;
    default:
    break;
    }
    }

    void n61_init(int (*func)(int cmd, unsigned char c))
    {
    //SendChar1(c);
    //SendChar1(cmd & 0xff);
    n61_seqnum = 0;
    n61_serial = func;
    n61_blocked = 0;
    n61_msgqueuesize = 0;
    n61_multiple = 0;
    n61_readbase = 0;
    //n61_getsmsc();
    }

    void n61_CheckTurnOn()
    {
    /*unsigned char buf[30];
    int i,j;
    i = 0;
    // chpow = 1;
    buf[i] = 0x1E;i++;
    buf[i] = 0x00;i++;
    buf[i] = 0x10;i++;
    buf[i] = 0x40;i++;
    buf[i] = 0x00;i++;
    buf[i] = 0x05;i++;
    buf[i] = 0x00;i++;
    buf[i] = 0x01;i++;
    buf[i] = 0x66;i++;
    buf[i] = 0x01;i++;
    buf[i] = 0x43;i++;
    buf[i] = 0x00;i++;
    buf[i] = 0x2B;i++;
    buf[i] = 0x45;i++;
    for (j = 1; j <= 200;j++)
    {
    buf[i] = 0x55;i++;
    }
    buf[i] = 0xC1;i++;
    buf[i] = 0x1E;i++;
    buf[i] = 0x00;i++;
    buf[i] = 0x10;i++;
    buf[i] = 0xD1;i++;
    buf[i] = 0x00;i++;
    buf[i] = 0x07;i++;
    buf[i] = 0x00;i++;
    buf[i] = 0x01;i++;
    buf[i] = 0x00;i++;
    buf[i] = 0x03;i++;
    buf[i] = 0x00;i++;
    buf[i] = 0x01;i++;
    buf[i] = 0x44;i++;
    buf[i] = 0x00;i++;
    buf[i] = 0x4A;i++;
    buf[i] = 0xD5;i++; */

    /*buf[i] = 0x1E;i++;
    buf[i] = 0x00;i++;
    buf[i] = 0x10;i++;
    buf[i] = 0x7F;i++;
    buf[i] = 0x00;i++;
    buf[i] = 0x02;i++;
    buf[i] = 0xD2;i++;
    buf[i] = 0x43;i++;
    buf[i] = 0xDC;i++;
    buf[i] = 0x3E;i++;
    buf[i] = 0x1E;i++;
    buf[i] = 0x00;i++;
    buf[i] = 0x10;i++;
    buf[i] = 0x40;i++;
    buf[i] = 0x00;i++;
    buf[i] = 0x05;i++;
    buf[i] = 0x00;i++;
    buf[i] = 0x01;i++;
    buf[i] = 0x66;i++;
    buf[i] = 0x01;i++;
    buf[i] = 0x45;i++;
    buf[i] = 0x00;i++;
    buf[i] = 0x2D;i++;
    buf[i] = 0x45;i++;
    for(j = 0; j < i; j++)
    {
    SendChar(buf[j]);
    }
    i = 0;
    while ((n61_Pow == 0) && (i < 65000))
    {
    GetKey();
    n61_update();
    i++;
    } */
    n61_Pow = 1;
    }
    ////////////usb/////////////
    // HID Out Report
    /*----------------------------------------------------------------------------



    ما در این برنامه با تابع








    int n61_smssendfull(unsigned char *smsc, unsigned char *dest, unsigned char *msg)



    اس ام اسو میفرستیم
    در اول تابع (دریافتی های تابع )شمارهی sms center بعد شماره موبایل مقصد بعد هم متن اس ام اسو میگیره.
    مشکل من اینه که کاراکتر های فارسی در جدول آسکی بالا تر از 256 هستند و 2 بایتی محسوب میشوند برای همین این تابه اونارو دونه دونه میفرسته و وقتی به مقصد میرسه به صورد 2 تا کاراکتر جدا حساب میشه.
    حالا من چه راهی دارم که اینو به صورت یه کاراکتر بفرستم نه دوتا؟؟؟؟




  2. #2

    نقل قول: فرستادن اس ام اس فارسی با نوکیا 3310

    سلام.
    منم اینو نیاز دارم.
    هیچ جایی پیدا نکردم اینو.

تاپیک های مشابه

  1. حرفه ای: فرستادن اس ام اس فارسی( انگلیسیش هست)
    نوشته شده توسط arefba در بخش C#‎‎
    پاسخ: 9
    آخرین پست: یک شنبه 09 مرداد 1390, 14:02 عصر
  2. سوال: فرستادن مقدار با حروف فارسی به کمک query string
    نوشته شده توسط naeeme در بخش ASP.NET Web Forms
    پاسخ: 2
    آخرین پست: چهارشنبه 23 مرداد 1387, 22:34 عصر
  3. مشکل در فرستادن ایمیل فارسی
    نوشته شده توسط msnasiri در بخش PHP
    پاسخ: 9
    آخرین پست: پنج شنبه 16 شهریور 1385, 13:46 عصر
  4. فرستادن فکس با vb (کاملا فارسی)
    نوشته شده توسط 123 در بخش برنامه نویسی در 6 VB
    پاسخ: 2
    آخرین پست: دوشنبه 28 فروردین 1385, 21:04 عصر
  5. چگونگی فرستادن Email فارسی
    نوشته شده توسط nima_jafari در بخش طراحی وب (Web Design)
    پاسخ: 1
    آخرین پست: سه شنبه 29 آذر 1384, 23:12 عصر

برچسب های این تاپیک

قوانین ایجاد تاپیک در تالار

  • شما نمی توانید تاپیک جدید ایجاد کنید
  • شما نمی توانید به تاپیک ها پاسخ دهید
  • شما نمی توانید ضمیمه ارسال کنید
  • شما نمی توانید پاسخ هایتان را ویرایش کنید
  •