Exemplo n.º 1
0
static void cliWrite(uint8_t ch)
{
    uartWrite(core.mainport, ch);
}
Exemplo n.º 2
0
static void sendTelemetryTail(void)
{
    uartWrite(PROTOCOL_TAIL);
}
Exemplo n.º 3
0
static void cliPrint(const char *str)
{
    while (*str)
        uartWrite(core.mainport, *(str++));
}
Exemplo n.º 4
0
static void _putc(void *p, char c)
{
    uartWrite(c);
}
Exemplo n.º 5
0
static void sendDataHead(uint8_t id)
{
    uartWrite(PROTOCOL_HEADER);
    uartWrite(id);
}
Exemplo n.º 6
0
void serialize8(uint8_t a)
{
    uartWrite(a);
    checksum ^= a;
}
Exemplo n.º 7
0
Arquivo: cli.c Projeto: DuinoPilot/TMR
void cliProcess(void)
{
    if (!cliMode) {
        cliMode = 1;
        uartPrint("\r\nEntering CLI Mode, type 'exit' to return, or 'help'\r\n");
        cliPrompt();
    }

    while (uartAvailable()) {
        uint8_t c = uartRead();
        if (c == '\t' || c == '?') {
            // do tab completion
            const clicmd_t *cmd, *pstart = NULL, *pend = NULL;
            int i = bufferIndex;
            for (cmd = cmdTable; cmd < cmdTable + CMD_COUNT; cmd++) {
                if (bufferIndex && (strncasecmp(cliBuffer, cmd->name, bufferIndex) != 0))
                    continue;
                if (!pstart)
                    pstart = cmd;
                pend = cmd;
            }
            if (pstart) {    /* Buffer matches one or more commands */
                for (; ; bufferIndex++) {
                    if (pstart->name[bufferIndex] != pend->name[bufferIndex])
                        break;
                    if (!pstart->name[bufferIndex]) {
                        /* Unambiguous -- append a space */
                        cliBuffer[bufferIndex++] = ' ';
                        break;
                    }
                    cliBuffer[bufferIndex] = pstart->name[bufferIndex];
                }
            }
            if (!bufferIndex || pstart != pend) {
                /* Print list of ambiguous matches */
                uartPrint("\r\033[K");
                for (cmd = pstart; cmd <= pend; cmd++) {
                    uartPrint(cmd->name);
                    uartWrite('\t');
                }
                cliPrompt();
                i = 0;    /* Redraw prompt */
            }
            for (; i < bufferIndex; i++)
                uartWrite(cliBuffer[i]);
        } else if (!bufferIndex && c == 4) {
            cliExit(cliBuffer);
            return;
        } else if (c == 12) {
            // clear screen
            uartPrint("\033[2J\033[1;1H");
            cliPrompt();
        } else if (bufferIndex && (c == '\n' || c == '\r')) {
            // enter pressed
            clicmd_t *cmd = NULL;
            clicmd_t target;
            uartPrint("\r\n");
            cliBuffer[bufferIndex] = 0; // null terminate
            
            target.name = cliBuffer;
            target.param = NULL;
            
            cmd = bsearch(&target, cmdTable, CMD_COUNT, sizeof cmdTable[0], cliCompare);
            if (cmd)
                cmd->func(cliBuffer + strlen(cmd->name) + 1);
            else
                uartPrint("ERR: Unknown command, try 'help'");

            memset(cliBuffer, 0, sizeof(cliBuffer));
            bufferIndex = 0;

            // 'exit' will reset this flag, so we don't need to print prompt again
            if (!cliMode)
                return;
            cliPrompt();
        } else if (c == 127) {
            // backspace
            if (bufferIndex) {
                cliBuffer[--bufferIndex] = 0;
                uartPrint("\010 \010");
            }
        } else if (bufferIndex < sizeof(cliBuffer) && c >= 32 && c <= 126) {
            if (!bufferIndex && c == 32)
                continue;
            cliBuffer[bufferIndex++] = c;
            uartWrite(c);
        }
    }
}
Exemplo n.º 8
0
bool sim300RcvProc(){

    if((simrcv_t.idle_ticks >SIM_IDLE_GAP)  && (1 == simrcv_t.received_flag)){   // 有接收信息
    
          pch = strstr((char *)simrcv_t.buf,RDY);   //  
                  if(NULL != pch){
 #if (SIM300_DEBUG == 1)                  
                      uartWrite(0, "get RDY\r\n",9);
#endif                      
                      sim_state_machine = SIM_S_RDY;
                }  
                pch = strstr((char *)simrcv_t.buf,CALL_READY);   //  
                  if(NULL != pch){
 #if (SIM300_DEBUG == 1)                  
                     uartWrite(0, "get called\r\n",12);
 #endif              
                    sim_state_machine = SIM_S_CALLED;
            }
            
             pch = strstr((char *)simrcv_t.buf,"OK");  //  
             if(NULL != pch){
                switch(sim_state_machine){
                    
                    case SIM_S_IDLE:
                    case SIM_S_RDY:
                    case SIM_S_CALLED:
                    break;    
                    case SIM_S_AT:

        #if (SIM300_DEBUG == 1)                  
                        uartWrite(0, "get AT ok\r\n",12);
        #endif                      
                        sim_state_machine = SIM_S_AT_OK;
                    break;
                    case SIM_S_CSTT:
        #if (SIM300_DEBUG == 1)                  
                              uartWrite(0, "get CSTT ok\r\n",14);
        #endif                      
                              sim_state_machine = SIM_S_CSTT_OK;

                    break;
                    case SIM_S_CIICR:

        #if (SIM300_DEBUG == 1)                  
                              uartWrite(0, "get CIIR ok\r\n",14);
        #endif                      
                              sim_state_machine = SIM_S_CIICR_OK;
                  
                    break;
                   
                    case SIM_S_CIPSTART:

        #if (SIM300_DEBUG == 1)                  
                              uartWrite(0, "get CIPSTART ok\r\n",17);
        #endif                      
                              sim_state_machine = SIM_S_CIPSTART_OK;
 
                    break;
                    case SIM_S_CIPSEND:
#if (SIM300_DEBUG == 1)                  
                              uartWrite(0, "get CIPsend ok\r\n",16);
#endif                      
                              sim_state_machine = SIM_S_CIPSEND_OK;
                    
                }
              
             }
         pch = strstr((char *)simrcv_t.buf,"ERROR");  //  
             if(NULL != pch){
                switch(sim_state_machine){
                    
                    case SIM_S_IDLE:
                    case SIM_S_RDY:
                    case SIM_S_CALLED:
                    break;    
                    case SIM_S_AT:

        #if (SIM300_DEBUG == 1)                  
                        uartWrite(0, "get AT ERROR\r\n",14);
        #endif                      
                        sim_state_machine = SIM_S_AT_ERROR;
                    break;
                    case SIM_S_CSTT:
        #if (SIM300_DEBUG == 1)                  
                              uartWrite(0, "get CSTT ERROR\r\n",16);
        #endif                      
                              sim_state_machine = SIM_S_CSTT_ERROR;

                    break;
                    case SIM_S_CIICR:

        #if (SIM300_DEBUG == 1)                  
                              uartWrite(0, "get CIIR ER\r\n",14);
        #endif                      
                              sim_state_machine = SIM_S_CIICR_ERROR;
                  
                    break;
                    case SIM_S_CIFSR:

        #if (SIM300_DEBUG == 1)                  
                              uartWrite(0, "get CIFSR ER\r\n",14);
        #endif                      
                              sim_state_machine = SIM_S_CIFSR_ERROR;

                    break;
                    case SIM_S_CIPSTART:

        #if (SIM300_DEBUG == 1)                  
                              uartWrite(0, "get CIPSTART er\r\n",14);
        #endif                      
                              sim_state_machine = SIM_S_CIPSTART_ERROR;
 
                    break;
                    case SIM_S_CIPSEND:

        #if (SIM300_DEBUG == 1)                  
                              uartWrite(0, "get CIPSEND er\r\n",14);
        #endif                      
                              sim_state_machine = SIM_S_CIPSEND_ERROR;
 
                    break;
                    
                }
              
             }

              pch = strstr((char *)simrcv_t.buf,".");  //  case SIM_S_CIFSR:
              if(NULL != pch){
                pch = strstr((char *)simrcv_t.buf,"."); 
                if((NULL != pch)&&(SIM_S_CIFSR == sim_state_machine )){
#if (SIM300_DEBUG == 1)                  
                              uartWrite(0, "get CIFSR ok\r\n",14);
#endif
                   sim_state_machine =  SIM_S_CIFSR_OK; 
                }
              }
              pch = strstr((char *)simrcv_t.buf,"+IPD");   //  有UDP接受信息
              if(NULL != pch){
 #if (SIM300_DEBUG == 1)            
                      
                     // pch = strstr(pch,":");      
                      
                      uartWrite(0, pch,10);
#endif                      
                   //   sim_state_machine = SIM_S_RDY;
                }  

        
        sim300RcvFlush(); 
        return TRUE;
    }
    return FALSE;

}
Exemplo n.º 9
0
size_t HardwareSerial::write(uint8_t c)
{
    uartWrite(_uart, c);
    return 1;
}
Exemplo n.º 10
0
int8_t sim300Prepare(uint16_t which_mark,uint16_t num_send){
    uint8_t i;
    char * tmp;
    uint8_t tmpch;
    
    gsm_pw = 0;   //GSM 断电信号
    
    PTEDD |= 0x63;
    PTED  |= 0x02;
    
      
        OSTimeDly(OS_TICKS_PER_SEC*5);
    
    
           
            SIM300_PWRKEY_LOW; 
            OSTimeDly(OS_TICKS_PER_SEC);
            SIM300_PWRKEY_HIGH;
            OSTimeDly(OS_TICKS_PER_SEC*8); 
            SIM300_PWR_OFF;
     OSTimeDly(OS_TICKS_PER_SEC*5);
    
    uartInit(SIM300_PORT,9600,0,'n');
 #if (SIM300_DEBUG == 1)    
    uartInit(0,9600,0,'n'); 
#endif   
    sim300RcvInit();
    sim300RcvFlush();
    sim300RcvUartClr();
    
    SIM300_PWR_ON;
    SIM300_PWRKEY_HIGH;
    OSTimeDly(OS_TICKS_PER_SEC*3);    
    SIM300_PWRKEY_LOW; 
    OSTimeDly(OS_TICKS_PER_SEC*2);
    SIM300_PWRKEY_HIGH;
    
    
    sim_state_machine = SIM_S_IDLE;  
    udp_backed = 0;   //是否有udp接收帧
    
    //取得RDY信号
   
   
   
    for(i=0;i<3;i++){
          
          OSTimeDly(OS_TICKS_PER_SEC*10);
           while(uartRead(SIM300_PORT,&tmpch,1)){
               if(0 != tmpch){
                simrcv_t.buf[simrcv_t.index++] = tmpch;
               simrcv_t.index = ((simrcv_t.index > (simrcv_t.buf_len-2))? (simrcv_t.buf_len-2):simrcv_t.index);
               }
           }
        tmp = strstr((char *)simrcv_t.buf,"Call"); 
        if(NULL == tmp){
#if (SIM300_DEBUG == 1)    
        uartWrite(0,"not RDY\r\n",9);
#endif             
        }else{
            i = 5;   
        }
    }
    if( 3 == i){   // 没有正常RDY
            return ERROR_RDY;
    }
    
    //RDY判断结束
    //发送AT复位   
    for(i=0;i<3;i++){
        
        uartWrite(SIM300_PORT,AT,strlen(AT));
        OSTimeDly(OS_TICKS_PER_SEC*3);
        sim300RcvFlush();
        while(uartRead(SIM300_PORT,&tmpch,1)){
               if(0 != tmpch){
                simrcv_t.buf[simrcv_t.index++] = tmpch;
               simrcv_t.index = ((simrcv_t.index > (simrcv_t.buf_len-2))? (simrcv_t.buf_len-2):simrcv_t.index);
               }
           }
        tmp = strstr((char *)simrcv_t.buf,"OK"); 
        if(NULL == tmp){
    #if (SIM300_DEBUG == 1)    
            uartWrite(0,"at ok error\r\n",13);
    #endif             
         }else{
                i = 5;   
         }  
    }
    if( 3 == i){   // 没有正常AT
            return ERROR_AT;
    }
    //AT 正常回复
    gsm_pw = 1;   //GSM 供电信号
    
    //设置回显模式
    uartWrite(SIM300_PORT, "ATE0\r\n",6);
    OSTimeDly(OS_TICKS_PER_SEC*2);
    
    uartWrite(SIM300_PORT, CMGF,strlen(CMGF));
    OSTimeDly(OS_TICKS_PER_SEC*2);
    
       //设置ip报头模式
    uartWrite(SIM300_PORT, "AT+CIPHEAD=1\r\n",14);
    OSTimeDly(OS_TICKS_PER_SEC*3);
    sim300RcvUartClr();
    OSTimeDly(OS_TICKS_PER_SEC);  
    






#if  (1 == MULTI_IP)
    uartWrite(SIM300_PORT, CIPMUX,strlen(CIPMUX));
    OSTimeDly(OS_TICKS_PER_SEC*2);  
#endif 
    //链接CMNET
     for(i=0;i<3;i++){
        uartWrite(SIM300_PORT,CSTT,strlen(CSTT));
        OSTimeDly(OS_TICKS_PER_SEC*5);
            sim300RcvFlush();
           while(uartRead(SIM300_PORT,&tmpch,1)){
               if(0 != tmpch){
                simrcv_t.buf[simrcv_t.index++] = tmpch;
               simrcv_t.index = ((simrcv_t.index > (simrcv_t.buf_len-2))? (simrcv_t.buf_len-2):simrcv_t.index);
               }
           }
            tmp = strstr((char *)simrcv_t.buf,"OK"); 
            if(NULL == tmp){
        #if (SIM300_DEBUG == 1)    
                uartWrite(0,"at CSTT error\r\n",15);
        #endif             
             }else{
                    i = 5;   
             }  
    }
    if( 3 == i){   // 没有正常AT
            return ERROR_CSTT;
    }  
    
    
    
    //链接CMNET结束   
    //启动gprs网络     //需要等待时间比较长,
        uartWrite(SIM300_PORT,CIICR,strlen(CIICR));
        sim300RcvFlush();
        for(i=0;i<3;i++){
        
        OSTimeDly(OS_TICKS_PER_SEC*7);
        
       while(uartRead(SIM300_PORT,&tmpch,1)){
               if(0 != tmpch){
                simrcv_t.buf[simrcv_t.index++] = tmpch;
               simrcv_t.index = ((simrcv_t.index > (simrcv_t.buf_len-2))? (simrcv_t.buf_len-2):simrcv_t.index);
               }
           }
         tmp = strstr((char *)simrcv_t.buf,"OK"); 
         if(NULL == tmp){
        #if (SIM300_DEBUG == 1)    
                uartWrite(0,"at CIICR error\r\n",16);
        #endif             
         }else{
#if (SIM300_DEBUG == 1)           
                    uartWrite(0,"CIICR OK\r\n",10);
#endif                     
                    i = 5;   
         }  
    }
    if( 3 == i){   // 没有正常AT
            return ERROR_CIICR;
    }
    
    //设置ip报头模式
/*    uartWrite(SIM300_PORT, "AT+CIPMUX=0\r\n",13);
    OSTimeDly(OS_TICKS_PER_SEC*4);
    sim300RcvUartClr();    */
    //启动gprs网络结束
    //获取IP地址
    for(i=0;i<3;i++){
        uartWrite(SIM300_PORT,CIFSR,strlen(CIFSR));
        OSTimeDly(OS_TICKS_PER_SEC*5);
        sim300RcvFlush();
        while(uartRead(SIM300_PORT,&tmpch,1)){
               if(0 != tmpch){
                simrcv_t.buf[simrcv_t.index++] = tmpch;
               simrcv_t.index = ((simrcv_t.index > (simrcv_t.buf_len-2))? (simrcv_t.buf_len-2):simrcv_t.index);
               }
           }
         tmp = strstr((char *)simrcv_t.buf,"."); 
         if(NULL == tmp){
        #if (SIM300_DEBUG == 1)    
                uartWrite(0,"at CIFSR error\r\n",16);
        #endif             
         }else{
                    i = 5;   
         }  
    }
    if( 3 == i){   // 没有正常AT
            return ERROR_CIFSR;
    } 
    //获取IP地址结束   
    //创建udp链接
       
#if  (1 == MULTI_IP)
//第一个站点开始
    for(i=0;i<3;i++){
    uartWrite(SIM300_PORT,CIPSTART_M0,strlen(CIPSTART_M0));
    uartWrite(SIM300_PORT,"\"",1);
    uartWrite(SIM300_PORT,ipaddress,strlen(ipaddress));
    uartWrite(SIM300_PORT,"\",",2);
    uartWrite(SIM300_PORT,udpport,strlen(udpport));
    uartWrite(SIM300_PORT,"\r\n",2);
    
     OSTimeDly(OS_TICKS_PER_SEC*5+(mcu_time_count&0x000000ff));
        sim300RcvFlush();
        while(uartRead(SIM300_PORT,&tmpch,1)){
               if(0 != tmpch){
                simrcv_t.buf[simrcv_t.index++] = tmpch;
               simrcv_t.index = ((simrcv_t.index > (simrcv_t.buf_len-2))? (simrcv_t.buf_len-2):simrcv_t.index);
               }
           }
         tmp = strstr((char *)simrcv_t.buf,"OK"); 
         if(NULL == tmp){
        #if (SIM300_DEBUG == 1)    
                uartWrite(0,"at CIPSTART error\r\n",19);
        #endif             
         } else{
                    i = 5;   
         }  
    }
    
    OSTimeDly(OS_TICKS_PER_SEC*3+(mcu_time_count&0x000000ff));
    uartWrite(SIM300_PORT,CIPSEND36_M0,strlen(CIPSEND36_M0));
    
    hex_BCD(num_send);
    uartWrite(SIM300_PORT,ASC_buf,3);
    uartWrite(SIM300_PORT,"\r",1);
    
    OSTimeDly(OS_TICKS_PER_SEC*2);
           
           
       if(which_mark==0)
       {
        
           uartWrite(SIM300_PORT,prt_frame,num_send);
         
         if(0 == reUDPsend){
              reUDP_times = 1;  
         }
         
         task_active[TASKACTIVE_SAMPLE]++;
         SIM300Waiting(40);
         if(reUDP_times>0){
           reUDPsend = 1;
           reUDP_times--;  
         }else{
            reUDPsend = 0;
   
         }
         }else 
          uartWrite(SIM300_PORT,prt_frame,num_send);
          
           OSTimeDly(OS_TICKS_PER_SEC*5);
       
    ///第一个站点结束
    
    //第二个站点开始
    if((ipadd_other[0][0]>='0')&&(ipadd_other[0][0]<='9')) {
        
    for(i=0;i<3;i++){
    uartWrite(SIM300_PORT,CIPSTART_M1,strlen(CIPSTART_M1));
    uartWrite(SIM300_PORT,"\"",1);
    uartWrite(SIM300_PORT,ipadd_other[0],strlen(ipadd_other[0]));
    uartWrite(SIM300_PORT,"\",",2);
    uartWrite(SIM300_PORT,udpport,strlen(udpport));
    uartWrite(SIM300_PORT,"\r\n",2);
    
     OSTimeDly(OS_TICKS_PER_SEC*5+(mcu_time_count&0x000000ff));
        sim300RcvFlush();
        while(uartRead(SIM300_PORT,&tmpch,1)){
               if(0 != tmpch){
                simrcv_t.buf[simrcv_t.index++] = tmpch;
               simrcv_t.index = ((simrcv_t.index > (simrcv_t.buf_len-2))? (simrcv_t.buf_len-2):simrcv_t.index);
               }
           }
         tmp = strstr((char *)simrcv_t.buf,"OK"); 
         if(NULL == tmp){
        #if (SIM300_DEBUG == 1)    
                uartWrite(0,"at CIPSTART error\r\n",19);
        #endif             
         } else{
                    i = 5;   
         }  
    }
    
    OSTimeDly(OS_TICKS_PER_SEC*3+(mcu_time_count&0x000000ff));
    uartWrite(SIM300_PORT,CIPSEND36_M1,strlen(CIPSEND36_M1));
        hex_BCD(num_send);
    uartWrite(SIM300_PORT,ASC_buf,3);
    uartWrite(SIM300_PORT,"\r",1);
    
    OSTimeDly(OS_TICKS_PER_SEC*2);
           
           
       if(which_mark==0)
       {
        
           uartWrite(SIM300_PORT,prt_frame,num_send);
       }else 
          uartWrite(SIM300_PORT,prt_frame,num_send); 
           OSTimeDly(OS_TICKS_PER_SEC*5);
         
     
    }
    ///第二个站点结束
    //第三个站点开始
    if((ipadd_other[1][0]>='0')&&(ipadd_other[1][0]<='9')) {
        
    for(i=0;i<3;i++){
    uartWrite(SIM300_PORT,CIPSTART_M2,strlen(CIPSTART_M2));
    uartWrite(SIM300_PORT,"\"",1);
    uartWrite(SIM300_PORT,ipadd_other[1],strlen(ipadd_other[1]));
    uartWrite(SIM300_PORT,"\",",2);
    uartWrite(SIM300_PORT,udpport,strlen(udpport));
    uartWrite(SIM300_PORT,"\r\n",2);
    
     OSTimeDly(OS_TICKS_PER_SEC*5+(mcu_time_count&0x000000ff));
        sim300RcvFlush();
        while(uartRead(SIM300_PORT,&tmpch,1)){
               if(0 != tmpch){
                simrcv_t.buf[simrcv_t.index++] = tmpch;
               simrcv_t.index = ((simrcv_t.index > (simrcv_t.buf_len-2))? (simrcv_t.buf_len-2):simrcv_t.index);
               }
           }
         tmp = strstr((char *)simrcv_t.buf,"OK"); 
         if(NULL == tmp){
        #if (SIM300_DEBUG == 1)    
                uartWrite(0,"at CIPSTART error\r\n",19);
        #endif             
         } else{
                    i = 5;   
         }  
    }
    
    OSTimeDly(OS_TICKS_PER_SEC*3+(mcu_time_count&0x000000ff));
    uartWrite(SIM300_PORT,CIPSEND36_M2,strlen(CIPSEND36_M2));
           hex_BCD(num_send);
    uartWrite(SIM300_PORT,ASC_buf,3);
    uartWrite(SIM300_PORT,"\r",1);
    
    OSTimeDly(OS_TICKS_PER_SEC*2);
           
           
       if(which_mark==0)
       {
        
           uartWrite(SIM300_PORT,prt_frame,num_send);
       }else 
          uartWrite(SIM300_PORT,prt_frame,num_send);
           OSTimeDly(OS_TICKS_PER_SEC*5);

    }
    ///第三个站点结束
    //第四个站点开始
    if((ipadd_other[2][0]>='0')&&(ipadd_other[2][0]<='9')) {
        
    for(i=0;i<3;i++){
    uartWrite(SIM300_PORT,CIPSTART_M3,strlen(CIPSTART_M3));
    uartWrite(SIM300_PORT,"\"",1);
    uartWrite(SIM300_PORT,ipadd_other[2],strlen(ipadd_other[2]));
    uartWrite(SIM300_PORT,"\",",2);
    uartWrite(SIM300_PORT,udpport,strlen(udpport));
    uartWrite(SIM300_PORT,"\r\n",2);
    
     OSTimeDly(OS_TICKS_PER_SEC*5+(mcu_time_count&0x000000ff));
        sim300RcvFlush();
        while(uartRead(SIM300_PORT,&tmpch,1)){
               if(0 != tmpch){
                simrcv_t.buf[simrcv_t.index++] = tmpch;
               simrcv_t.index = ((simrcv_t.index > (simrcv_t.buf_len-2))? (simrcv_t.buf_len-2):simrcv_t.index);
               }
           }
         tmp = strstr((char *)simrcv_t.buf,"OK"); 
         if(NULL == tmp){
        #if (SIM300_DEBUG == 1)    
                uartWrite(0,"at CIPSTART error\r\n",19);
        #endif             
         } else{
                    i = 5;   
         }  
    }
    
    OSTimeDly(OS_TICKS_PER_SEC*3+(mcu_time_count&0x000000ff));
    uartWrite(SIM300_PORT,CIPSEND36_M3,strlen(CIPSEND36_M3));
           hex_BCD(num_send);
    uartWrite(SIM300_PORT,ASC_buf,3);
    uartWrite(SIM300_PORT,"\r",1);
    
    OSTimeDly(OS_TICKS_PER_SEC*2);
           
           
       if(which_mark==0)
       {
        
           uartWrite(SIM300_PORT,prt_frame,num_send);
       }else 
          uartWrite(SIM300_PORT,prt_frame,num_send);
           OSTimeDly(OS_TICKS_PER_SEC*5);
         
    
    }
    ///第四个站点结束
#else
    
    for(i=0;i<3;i++){
    uartWrite(SIM300_PORT,CIPSTART1,strlen(CIPSTART1));
    uartWrite(SIM300_PORT,"\"",1);
    uartWrite(SIM300_PORT,ipaddress,strlen(ipaddress));
    uartWrite(SIM300_PORT,"\",",2);
    uartWrite(SIM300_PORT,udpport,strlen(udpport));
    uartWrite(SIM300_PORT,"\r\n",2);
    
     OSTimeDly(OS_TICKS_PER_SEC*5+(mcu_time_count&0x000000ff));
        sim300RcvFlush();
        while(uartRead(SIM300_PORT,&tmpch,1)){
               if(0 != tmpch){
                simrcv_t.buf[simrcv_t.index++] = tmpch;
               simrcv_t.index = ((simrcv_t.index > (simrcv_t.buf_len-2))? (simrcv_t.buf_len-2):simrcv_t.index);
               }
           }
         tmp = strstr((char *)simrcv_t.buf,"OK"); 
         if(NULL == tmp){
        #if (SIM300_DEBUG == 1)    
                uartWrite(0,"at CIPSTART error\r\n",19);
        #endif             
         } else{
                    i = 5;   
         }  
    }
    if( 3 == i){   // 没有正常AT
            return ERROR_CIPSTART;
    } 
    
    
    OSTimeDly(OS_TICKS_PER_SEC*3+(mcu_time_count&0x000000ff));
    uartWrite(SIM300_PORT,CIPSEND36,strlen(CIPSEND36));
          OSTimeDly(OS_TICKS_PER_SEC*2);
           uartWrite(SIM300_PORT,(uint8_t *)&rtufile,38);
           OSTimeDly(OS_TICKS_PER_SEC*5);
         
            
#endif         
/*    upd 接受处理,SIM300Waiting 实验屏蔽
        sim300RcvFlush();
        while(uartRead(SIM300_PORT,&tmpch,1)){
               simrcv_t.buf[simrcv_t.index++] = tmpch;
               simrcv_t.index = ((simrcv_t.index > (simrcv_t.buf_len-2))? (simrcv_t.buf_len-2):simrcv_t.index);
           }
         tmp = strstr((char *)simrcv_t.buf,"+IPD"); 
         if(NULL == tmp){
        #if (SIM300_DEBUG == 1)    
                uartWrite(0,"no UDP data\r\n",13);
        #endif             
         } else{
         #if (SIM300_DEBUG == 1)  
                   uartWrite(0,"got UDP\r\n",9); 
         #endif
         
           UDPDecode(tmp);   
         }  */
         
         task_active[TASKACTIVE_SAMPLE]++;
         SIM300Waiting(40);
         SIM300msg();
         #if (SIM300_DEBUG == 1)
                msg_num += '0';    
                uartWrite(0,&msg_num,1);
        #endif          
         
         
    //       OSTimeDly(OS_TICKS_PER_SEC*5);
           
     //        SIM300_PWRKEY_LOW; 
     //       OSTimeDly(OS_TICKS_PER_SEC);
     //       SIM300_PWRKEY_HIGH;
     //       OSTimeDly(OS_TICKS_PER_SEC*8); 
     //       SIM300_PWR_OFF;
            return 0;          
    
    
    
}
Exemplo n.º 11
0
int8_t sim300FirstOn(){
  
    uint8_t i;
    char * tmp;
    uint8_t tmpch;
    
    gsm_pw = 0;   //GSM 断电信号
    
    PTEDD |= 0x63;
    PTED  |= 0x02;
    
    OSTimeDly(OS_TICKS_PER_SEC*5);
    
    
           
            SIM300_PWRKEY_LOW; 
            OSTimeDly(OS_TICKS_PER_SEC);
            SIM300_PWRKEY_HIGH;
            OSTimeDly(OS_TICKS_PER_SEC*8); 
            SIM300_PWR_OFF;
     OSTimeDly(OS_TICKS_PER_SEC*5);
    
    uartInit(SIM300_PORT,9600,0,'n');
 #if (SIM300_DEBUG == 1)    
    uartInit(0,9600,0,'n'); 
#endif   
    sim300RcvInit();
    sim300RcvFlush();
    sim300RcvUartClr();
    
    SIM300_PWR_ON;
    SIM300_PWRKEY_HIGH;
    OSTimeDly(OS_TICKS_PER_SEC*3);    
    SIM300_PWRKEY_LOW; 
    OSTimeDly(OS_TICKS_PER_SEC*2);
    SIM300_PWRKEY_HIGH;
    
    
    sim_state_machine = SIM_S_IDLE;  
    udp_backed = 0;   //是否有udp接收帧
    
    //取得RDY信号
    for(i=0;i<3;i++){
          
          OSTimeDly(OS_TICKS_PER_SEC*10);
           while(uartRead(SIM300_PORT,&tmpch,1)){
               if(0 != tmpch){
                simrcv_t.buf[simrcv_t.index++] = tmpch;
               simrcv_t.index = ((simrcv_t.index > (simrcv_t.buf_len-2))? (simrcv_t.buf_len-2):simrcv_t.index);
               }
           }
        tmp = strstr((char *)simrcv_t.buf,"Call"); 
        if(NULL == tmp){
#if (SIM300_DEBUG == 1)    
        uartWrite(0,"not RDY\r\n",9);
#endif             
        }else{
            i = 5;   
        }
    }
    if( 3 == i){   // 没有正常RDY
            return ERROR_RDY;
    }
    
    //RDY判断结束
    //发送AT复位   
    for(i=0;i<3;i++){
        
        uartWrite(SIM300_PORT,AT,strlen(AT));
        OSTimeDly(OS_TICKS_PER_SEC*3);
        sim300RcvFlush();
        while(uartRead(SIM300_PORT,&tmpch,1)){
               if(0 != tmpch){
                simrcv_t.buf[simrcv_t.index++] = tmpch;
               simrcv_t.index = ((simrcv_t.index > (simrcv_t.buf_len-2))? (simrcv_t.buf_len-2):simrcv_t.index);
               }
           }
        tmp = strstr((char *)simrcv_t.buf,"OK"); 
        if(NULL == tmp){
    #if (SIM300_DEBUG == 1)    
            uartWrite(0,"at ok error\r\n",13);
    #endif             
         }else{
                i = 5;   
         }  
    }
    if( 3 == i){   // 没有正常AT
            return ERROR_AT;
    }
    //AT 正常回复
    gsm_pw = 1;   //GSM 供电信号
}
Exemplo n.º 12
0
 void sim300Task(void *p_arg){
    uint8_t  simdata[20];
    uint32_t simticks;
    uint8_t  len;
    (void)p_arg;
      sim300Init();



    while(1){
       sim300Receive();
       simrcv_t.idle_ticks++;
       if(TRUE ==sim300RcvProc()){
          sim300StateMachine(&sim_state_machine);  
       }
       OSTimeDly(OS_TICKS_PER_SEC>>4);
       if(SIM_S_CIPSTART_OK == sim_state_machine){
           uartWrite(SIM300_PORT,CIPSEND20,strlen(CIPSEND20));
           uartWrite(SIM300_PORT,testudp,22);
           OSTimeDly(OS_TICKS_PER_SEC*2);
           uartWrite(SIM300_PORT,CIPSEND20,strlen(CIPSEND20));
           uartWrite(SIM300_PORT,testudp,22);
           OSTimeDly(OS_TICKS_PER_SEC*2);
           sim_state_machine = SIM_S_CIPSEND;
       }
       
    /*   if(0 != uartRead(0,simdata,1)){
           if(('r' == simdata[0])&&(SIM_S_PWRDOWN == sim_state_machine)){
                SIM300_PWR_ON;
                SIM300_PWRKEY_HIGH;
                OSTimeDly(OS_TICKS_PER_SEC);    
                SIM300_PWRKEY_LOW; 
                OSTimeDly(OS_TICKS_PER_SEC*3);
                SIM300_PWRKEY_HIGH;
                sim_state_machine = SIM_S_IDLE;  
           }
       }    */
       
       if(SIM_S_CIPSEND_OK == sim_state_machine){
             simticks = OSTimeGet();
             
             sim_state_machine =  SIM_S_WAITDATA;

 
       } if(SIM_S_WAITDATA == sim_state_machine){
            if(OSTimeGet() - simticks > OS_TICKS_PER_SEC*30){
              /*    关闭连接 */
            SIM300_PWRKEY_LOW; 
            OSTimeDly(OS_TICKS_PER_SEC);
            SIM300_PWRKEY_HIGH;
            OSTimeDly(OS_TICKS_PER_SEC*8);
            sim_state_machine=  SIM_S_PWRDOWN;  
            }
        
       }

        
    }



}
Exemplo n.º 13
0
void sim300StateMachine( uint8_t volatile * s){
    switch(*s){
        case SIM_S_RDY:
                 uartWrite(SIM300_PORT, "ATE0\r\n",6);
                  OSTimeDly(OS_TICKS_PER_SEC*2);
                 uartWrite(SIM300_PORT, "AT+CIPHEAD=1\r\n",14);
            break;
        case SIM_S_CALLED:
        
             uartWrite(SIM300_PORT,AT,strlen(AT));
             *s= SIM_S_AT;
        
        break;
        case SIM_S_AT_OK:
              uartWrite(SIM300_PORT,CSTT,strlen(CSTT));
             *s= SIM_S_CSTT;
        break;
        case SIM_S_CSTT_OK:
              uartWrite(SIM300_PORT,CIICR,strlen(CIICR));
             *s= SIM_S_CIICR;
        break;
        case SIM_S_CIICR_OK:
             uartWrite(SIM300_PORT,CIFSR,strlen(CIFSR));
             *s= SIM_S_CIFSR;
        break;        
        case SIM_S_CIFSR_OK:
             uartWrite(SIM300_PORT,CIPSTART1,strlen(CIPSTART1));
             uartWrite(SIM300_PORT,"\"",1);
             uartWrite(SIM300_PORT,sim_ip,strlen(sim_ip));
             uartWrite(SIM300_PORT,"\"",1);
             uartWrite(SIM300_PORT,sim_port,strlen(sim_port));
             uartWrite(SIM300_PORT,"\r\n",2);
             *s= SIM_S_CIPSTART;
        break;
        case SIM_S_CIPSEND:
          //   uartWrite(SIM300_PORT,CIPSEND20,strlen(CIPSEND20));
        break;
        case SIM_S_CIPSEND_ERROR:
             SIM300_PWRKEY_LOW; 
             OSTimeDly(OS_TICKS_PER_SEC);
             SIM300_PWRKEY_HIGH;
             OSTimeDly(OS_TICKS_PER_SEC*8);
             *s=  SIM_S_PWRDOWN;
             
        break;
        
        
    }
    
}
Exemplo n.º 14
0
void msgGetInfo(char * msg){
    uint8_t check;
    uint8_t d;
    uint8_t chs[5];  //UDP端口
    
    //改变IP地址
        tp = strstr(msg,"newip:");
		if(NULL != tp){ 
#if (SIM300_DEBUG == 1)
                uartWrite(0,"newip done\r",11);
#endif
            *(strstr(tp,"\x0d"))=0;
            configParaSet(PARA_ADD_IP,"ip ",3);// save to EEPROM  
	        configParaSet(PARA_ADD_IP+3,tp+6,strlen(tp)-6);// save to EEPROM  
	        configParaSet(PARA_ADD_IP+3+strlen(tp)-6,"\x00",1);// save to EEPROM 
//            myReset();	          
//            return TRUE;
              //主IP
            configParaGet(PARA_ADD_IP,ipbuf,20);
         
            if((ipbuf[0]!='i') || (ipbuf[1]!='p')||(ipbuf[2]!= ' ') ){     //错误
                 ;
           
            }else {
                ipbuf[19] = 0;
                memset(ipaddress,0,20);
                memcpy(ipaddress,ipbuf+3,strlen((char *)ipbuf)-3);
               // return TRUE;
               reUDPsend = 1;   //改变设置,从新发送一次。
            }
		}
		
//改变发送间隔
        tp = strstr(msg,"newgap:");
		if(NULL != tp){ 
#if (SIM300_DEBUG == 1)
                uartWrite(0,"newgap done\r",12);
#endif
        check = 0;
        
        for(d=0;d<4;d++){
           if((  (*(tp+7+d)) <'0')&&((*(tp+7+d)) >'F')){
             goto portBegin;
           }
           if(( (*(tp+7+d))>'9')&&((*(tp+7+d)) <'A')){
            goto portBegin;
           } 
            
        }
        check = *(tp+7);
        at24Write((uint16_t)PARA_ADD_SEND_GAP,*(tp+7));
        check += *(tp+8);
        at24Write((uint16_t)(PARA_ADD_SEND_GAP+1),*(tp+8));
        check += *(tp+9);
        at24Write((uint16_t)(PARA_ADD_SEND_GAP+2),*(tp+9));
        check += *(tp+10);
        at24Write((uint16_t)(PARA_ADD_SEND_GAP+3),*(tp+10));
        

        at24Write((uint16_t)(PARA_ADD_SEND_GAP+4),check);    //求和校验
   
         // send gap     
        check = configParaGet(PARA_ADD_SEND_GAP,chs,4);
         
        configParaGet(PARA_ADD_SEND_GAP+4,&d,1);
        
            if(d != check){   //para出错
                   ;         //默认10分钟
            }else{  //参数转换出错
                    
                paras4toUint16(chs,&para_send_gap_min);
              }
	    }

		
        
//改变端口        
portBegin:      
       tp = strstr(msg,"newport:");   //必须是5位
		if(NULL != tp){ 
#if (SIM300_DEBUG == 1)
           uartWrite(0,"newport done\r",13);
#endif
        if((*(tp+8) >'9')||(*(tp+9) >'9')||(*(tp+10) >'9')||(*(tp+11) >'9')||(*(tp+12) >'9')){
           goto portError;   
        }
        if((*(tp+8) <'0')||(*(tp+9) <'0')||(*(tp+10) <'0')||(*(tp+11) <'0')||(*(tp+12) <'0')){
           goto portError;  
        }
        
        check = 0;
        check = *(tp+8);
        at24Write((uint16_t)PARA_UDP_PORT,*(tp+8));
        check += *(tp+9);
        at24Write((uint16_t)(PARA_UDP_PORT+1),*(tp+9));
        check += *(tp+10);
        at24Write((uint16_t)(PARA_UDP_PORT+2),*(tp+10));
        check += *(tp+11);
        at24Write((uint16_t)(PARA_UDP_PORT+3),*(tp+11));
        check += *(tp+12);
        at24Write((uint16_t)(PARA_UDP_PORT+4),*(tp+12));
         
        
        at24Write((uint16_t)(PARA_UDP_PORT+5),check);    //求和校验
            
    check = configParaGet(PARA_UDP_PORT,chs,5);     
    configParaGet(PARA_UDP_PORT+5,&d,1);
    if(d != check){   //para出错
          ;//端口不变    
    }else{  
         udpport[0] = chs[0];
         udpport[1] = chs[1];
         udpport[2] = chs[2];
         udpport[3] = chs[3];
         udpport[4] = chs[4];  
         udpport[5] = 0; 
         reUDPsend = 1;   //改变设置,从新发送一次。 
    }
		}
portError:
      udpport[5] = 0;				
}