示例#1
0
static uint8_t APP_GetXY(uint16_t *x, uint16_t *y, int8_t *x8, int8_t *y8) {
  uint8_t res;
  uint16_t values[2];

  res = AD1_Measure(TRUE);

  if (res!=ERR_OK) {
    return res;
  }
  res = AD1_GetValue16(&values[0]);
  if (res!=ERR_OK) {
    return res;
  }
  if (x!=NULL) {
    *x = values[0];
  }
  if (y!=NULL) {
    *y = values[1];
  }
  /* transform into -128...127 with zero as mid position */

  if (x8!=NULL) {
    *x8 = ToSigned8Bit(values[0], TRUE);
  }
  if (y8!=NULL) {
    *y8 = ToSigned8Bit(values[1], FALSE);
  }
  return ERR_OK;
}
示例#2
0
/*lint -save  -e970 Disable MISRA rule (6.3) checking. */
int main(void)
/*lint -restore Enable MISRA rule (6.3) checking. */
{
  /* Write your local variable definition here */

  /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
  PE_low_level_init();
  /*** End of Processor Expert internal initialization.                    ***/
  /* Write your code here */
  /* For example: for(;;) { } */

  /*** Don't write any code pass this line, or it will be deleted during code generation. ***/
  /*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/
  #ifdef PEX_RTOS_START
    PEX_RTOS_START();                  /* Startup of the selected RTOS. Macro is defined by the RTOS component. */
  #endif
  /*** End of RTOS startup code.  ***/
  /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
  for(;;){
	  
	  (void)AD1_Measure(TRUE); /* do conversion and wait for the result */
	  (void)AD1_GetValue16(&value); /* get the result into value variable */
	  UTIL1_Num16uToStr(buf, sizeof(buf), value); /* transform into string */
	  i=0;
	  while(buf[i]!=0) {
	  RxBuf_Put(buf[i]); /* write string */
	  i++;
	  }
	  APP_Run();
  }
  /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/
示例#3
0
void mcp3301Task(void *p_arg){
     
     uint16_t v;
     uint16_t temp;
     uint32_t i,j;
     char ch;
   
     (void)p_arg;
               
//    mcp3301Init(64,0x43,0x50,0);     /// wrong use, spiInit should be called only once!!!
        
     
    m25p40Init(32,0x43,0x50,0);
    
    dinInit();
    doutInit();
    wfx40Init();   //rs485 水位计 
    
    AD1_Init();
    
    getDin16(&wdin);/// get Din;
    
    
    
    rtc_pause_count = 0;
    
      //m25p40Init(32,0x43,0x90,0);
//    m25p40Init(64,0x43,0x90,0);
    
  /*  
    pcfTime.year = 10;
    pcfTime.mon  = 5;
    pcfTime.day  = 0x25;
    pcfTime.hour = 0x17;
    pcfTime.min  = 0x19;
    pcfTime.sec  = 0x00;
    pcf8563SetTime();
    */
  
    
/////////////////////////////   fix it!//////////////////////////////////////////////////    
    
//    m25p40EraseCmd(0);
//    m25p40EraseCmd(SECTOR_BYTES);
   
    
    OSTimeDly(500);         // waiting for GPRS ready
    
    pcf8563Init();   //RTC
    trigger_minutes = 0;        //启动后发送数据
    //////此处增加参数初始化//
    fixed_sendtime1 = 0xffff;  //需要改为从at24中读取
    fixed_sent = 0;   
    
    
      

    m25p40ParaInit();
    
    m25_add = m25sector.start_addr; 
     
    pcf8563GetTime();
    m25p40Write(m25_add,"reset:",6);
    m25_add+=6;
    m25p40Write(m25_add,(uint8_t *)&pcfTime,6); 
    m25_add+=6; 
    pre_minutes =  BCD2char(pcfTime.hour)*60 + BCD2char(pcfTime.min);
    
    stop_check_minutes = pre_minutes;
    ////////循环开始    ////////////////////////////////////////////
    req_sample = 0;
    rtc_pause_count = 0;
    raingaugebak = raingauge;
    
  /*  while((0 ==  gprsIPdone) &&(0 == SMSdone)){
         OSTimeDly(100);
    }
    */
    while(1){
    
       
      pcf8563GetTime();
      
      current_minutes =  BCD2char(pcfTime.hour)*60 + BCD2char(pcfTime.min);
      if(current_minutes - pre_minutes >= para_send_gap_min){
            req_sample = 1;
            req_send = 1;
            pre_minutes = current_minutes;
            
      }
      
      if(fixed_sendtime1 == current_minutes){
          if(0 == fixed_sent){
              req_send = 1; 
              fixed_sent = 1;   
          }
      }
      if(current_minutes > fixed_sendtime1 ){
            fixed_sent = 0;      //恢复
      }
      
    //判断PCF8536是否正常
    
     if(rtc_pause_count > 15){      //大于一分钟却没有变化
        if(stop_check_minutes == current_minutes){
            
            if(rtc_pause_count > 10*para_send_gap_min){
                req_sample = 1;
                req_send = 1;
                rtc_pause_count = 0;
            }
        }else{
            stop_check_minutes = current_minutes; 
            rtc_pause_count = 0;  
        }
      } 
    rtc_pause_count++;    //每个循环6秒钟
    
    
  
    
    
//    req_sample = 1;
    if(req_sample){
        //翻斗式雨量计
          /**** 雨量采集 ****/
        if(raingaugebak != raingauge){
            raingaugebak = raingauge;
             ch = '#';
            sc16puts(&ch,1); 
            configParaSet(PARA_RAIN,&raingauge,2);   //只在雨量有变化才存贮
        }
        
        
        //数字量采集
        getDin16(&wdin);/// get Din;
        ///模拟量采集
        for(i=0;i<6;i++){
            adAverage[i] = 0;
      
        }
        for(i=0;i<3;i++){
      
            AD1_Measure(1);
            AD1_GetValue16(adValues);
            for(j=0;j<6;j++){
                adAverage[j] += (adValues[j]>>4);
            }
        }
        for(j=0;j<6;j++){
            adAverage[j] /= 3;
        }   
      
        for(j=0;j<4;j++){
            ch = adAverage[2]>>((3-j)*4)&0x0f;
            ch += '0';
            sc16puts(&ch,1);
        }
        sc16puts(" ",1);
        //485采集
        /*
        */
        setDout(0);         //打开电源
        OSTimeDly(200);
        wfx40Write();       //

        OSTimeDly(100);
        if(TRUE == wfx40Data(&waterlevel)){
            sc16puts(&waterlevel,2);    
       
        }
        OSTimeDly(100);
        clrDout(0);         //关闭电源
        
        
        
        protocolConstruct();
      
        m25p40Write(m25_add,(uint8_t *)&rtufile,rtufile.len*2+4);
        m25_add+= rtufile.len*2+4;
      
        if(1 == req_send ){
            if((1 ==gprsIPdone )&& (0== gprsLock)) {
                gprsSendData((uint8_t *)&rtufile,rtufile.len*2+2+2);    // head + crc
                pro_in.no_received++;
          
            }else  if((1 == SMSdone)&&(0== gprsLock)){
                msgProtocolSend("13910996917",&rtufile);
            }
            req_send = 0;
        }
      
        for(j=0;j<4;j++){
            ch = rtufile.time[2]>>((3-j)*4)&0x0f;
            ch += '0';
            sc16puts(&ch,1);
        }
        sc16puts(" ",1);
        req_sample = 0;  
       
    }
    
    if(udp_download){
            i = timegap_end-timegap_start ;
            time_add = timegap_start;
            while(i){
                if(i>80){
                    for(temp=0;temp<80;temp++){
                        m25p40RD(time_add,&frame_buffer[temp],1);
                        time_add++;
                                
                    }
                    gprsSendData(frame_buffer,80);
                    i-=80;
                }else{
                    for(temp=0;temp<i;temp++){
                        m25p40RD(time_add,&frame_buffer[temp],1);        
                        time_add++;
                    } 
                    gprsSendData(frame_buffer,i);  
                    i=0;
                }
   
            }
       
          udp_download = 0;
        
    }
          
    OSTimeDly(300);
    msgGetList();
    OSTimeDly(300);
    
    }
    
}
示例#4
0
void mcp3301Task(void *p_arg){
     
     uint16_t v;
     uint16_t temp;
     uint32_t i;
     uint16_t j;
     char ch;
   
     (void)p_arg;
     
     rtcInit();
               
//    mcp3301Init(64,0x43,0x50,0);     /// wrong use, spiInit should be called only once!!!
    m25p40Init(32,0x43,0x50,0);
      
    AD1_Init();
    dinInit();
    doutInit();
//    wfx40Init();   //rs485 水位计
    YSIInit();
//    RS485Init();
    
             
//   TUFInit();
   
    at24Init();          //参数初始化
    configParaInit();
   
    
    getDin16(&wdin);/// get Din;

    rtc_pause_count = 0;
    mcu_time_count = 0;    
      //m25p40Init(32,0x43,0x90,0);
//    m25p40Init(64,0x43,0x90,0);
    
/////////////////////////////   fix it!//////////////////////////////////////////////////    

/*********************************** 
    m25p40EraseCmd(0);
    m25p40EraseCmd(SECTOR_BYTES);
    m25p40EraseCmd(SECTOR_BYTES*2);
    m25p40EraseCmd(SECTOR_BYTES*3);
    m25p40EraseCmd(SECTOR_BYTES*4);
    m25p40EraseCmd(SECTOR_BYTES*5);
    m25p40EraseCmd(SECTOR_BYTES*6);
    m25p40EraseCmd(SECTOR_BYTES*7);*******************/ 
   
    
    OSTimeDly(500);         // waiting for GPRS ready
    
    pcf8563Init();   //RTC
    trigger_minutes = 0;        //启动后发送数据
    //////此处增加参数初始化//
    fixed_sendtime1 = 0xffff;  //需要改为从at24中读取
    fixed_sent = 0;   
    

    m25p40ParaInit();
    
    m25_add = m25sector.start_addr; 
     
    pcf8563GetTime();
    m25p40Write(m25_add,"reset:",6);
    m25_add+=6;
    m25p40Write(m25_add,(uint8_t *)&pcfTime,6); 
    m25_add+=6; 
    pre_minutes =  BCD2char(pcfTime.hour)*60 + BCD2char(pcfTime.min);
    
    stop_check_minutes = pre_minutes;
    ////////循环开始    ////////////////////////////////////////////
    req_sample = 0;
    rtc_pause_count = 0;
    mcu_time_count = 0;
    raingaugebak = raingauge;
    
    
    OSTimeDly(3500);         // waiting for GPRS ready
    

    while(1){
    
      
     
      pcf8563GetTime();
      
      current_minutes =  BCD2char(pcfTime.hour)*60 + BCD2char(pcfTime.min);
/*      if(current_minutes - pre_minutes >= para_send_gap_min){
            req_sample = 1;
            req_send = 1;
            pre_minutes = current_minutes;
            
      }  */
       //需要修改,防止一分钟内重复进入
         
      if((TRUE == triggerTime(current_minutes))&&(current_minutes != pre_minutes)){
           req_sample = 1;
            req_send = 1;
            pre_minutes = current_minutes;  
      }
      
      if(fixed_sendtime1 == current_minutes){
          if(0 == fixed_sent){
              req_send = 1; 
              fixed_sent = 1;   
          }
      }
      if(current_minutes > fixed_sendtime1 ){
            fixed_sent = 0;      //恢复
      }
      if((TRUE == triggerSample(current_minutes))&&(current_minutes != pre_minutes)){
           req_sample = 1;
           pre_minutes = current_minutes;  
      }
      
    //判断PCF8536是否正常
    
     if(rtc_pause_count > 15){      //大于一分钟却没有变化
        if(stop_check_minutes == current_minutes){
            
            if(mcu_time_count > 60*para_send_gap_min){
                req_sample = 1;
                req_send = 1;
                
                mcu_time_count = 0;
            }
        }else{
            stop_check_minutes = current_minutes; 
            rtc_pause_count = 0; 
            mcu_time_count = 0; 
        }
      } 
    rtc_pause_count++;    //每个循环6秒钟
     mcu_time_count++;
    
    
  //翻斗式雨量计
          /**** 雨量采集 ****/   /** 实时采集,有降雨就发送 **/
        if(raingaugebak != raingauge){
            if(raingauge - raingaugebak>= RAIN_TRIGGER){
                req_sample = 1;
                req_send = 1;
            }
            raingaugebak = raingauge;
             ch = '#';
            sc16puts(&ch,1); 
            configParaSet(PARA_RAIN,&raingauge,2);   //只在雨量有变化才存贮
            if(0 ==(raingauge%para_rain_cont)){
                
                req_sample = 1;
                req_send = 1;
            }
        }
    
    
    
     if(reUDPsend){    //需要重发
        ch = '$';
        sc16puts(&ch,1); 
         req_sample = 1;
         req_send = 1;
        reUDPsend = 0;
      }
//    req_sample = 1;
    if(req_sample){
        
        
        
        //数字量采集
        getDin16(&wdin);/// get Din;
        ///模拟量采集
        for(i=0;i<9;i++){
            adAverage[i] = 0;
      
        }
        for(i=0;i<3;i++){
      
            AD1_Measure(1);
            AD1_GetValue16(adValues);
            for(j=0;j<9;j++){
                adAverage[j] += (adValues[j]>>4);
            }
        }
        for(j=0;j<9;j++){
            adAverage[j] /= 3;
        }   
      
        for(j=0;j<4;j++){
            ch = adAverage[8]>>((3-j)*4)&0x0f;
            ch += '0';
            sc16puts(&ch,1);
        }
        sc16puts(" ",1);
        //485采集
        /*
        */
#if  WFX_485        
        setDout(0);         //打开电源
        OSTimeDly(200);
        wfx40Write();       //

        OSTimeDly(100);
        if(TRUE == wfx40Data(&waterlevel)){
            sc16puts(&waterlevel,2);    
       
        }
        /*判断界限**/
        if(waterlevel > para_water_high){
                req_send = 1;   
        }
        OSTimeDly(100);
        clrDout(0);         //关闭电源
#endif
        YSIWeekup();
       OSTimeDly(50);
       YSITwipeb();
       OSTimeDly(50);
  
       
       YSIWrite();
       OSTimeDly(10);
       YSIClr();
       
       OSTimeDly(700);
       YSIRead(); 
        OSTimeDly(50);
       YSISleep();           
        
        
 /*

TUFRead();
TUFWrite();
  OSTimeDly(3);
//   TUFCSRxd();

TUFRead();
*/
        
        protocolConstruct();
      
        m25p40Write(m25_add,(uint8_t *)&rtufile,rtufile.len*2+4);
        m25_add+= rtufile.len*2+4;
        
        
        ///以下代码根据阀值判断是否需要发送
        /*
        if((waterlevel > high) ||(waterlevel < low)){
            req_send = 1;
        } 
        
        */
        
      
        if(1 == req_send ){
            if(0 == gprsIPdone){
                rebootflag = 1;   //重新配置gprs标志
                    task_active[TASKACTIVE_SAMPLE]++;
                gprsPrepare();  
                    task_active[TASKACTIVE_SAMPLE]++;              
                rebootflag = 0;
            }
                 
            if((1 ==gprsIPdone) && (0== gprsLock)) { 
            pro_in.no_received++;     //先增加,避免在3秒时间内收到数据而统计错误
                gprsSendData((uint8_t *)&rtufile,rtufile.len*2+2+2);    // head + crc
                for(j=0;j<3;j++){
                    if(1 == gprsStnDone[j]){
                        OSTimeDly(500);
                      gprsData(j+2,(uint8_t *)&rtufile,rtufile.len*2+2+2 + 5);    // head + crc  
                      
                    }
                }
//               pro_in.no_received++;
                    noUDPrec = rtc_pause_count;     //记录发送时间,六秒为单位
                    
                      
            }
            /*else  if((1 == SMSdone)&&(0== gprsLock)){
                msgProtocolSend("13910996917",&rtufile);
            
                myReset();     
            } */
            req_send = 0;
             OSTimeDly(300);
            msgGetList();      //短信列表
             OSTimeDly(300);
         
            gprsShutdown();
            clrDout(1);
            gprsIPdone =0;
            
        }else{              //增加心跳包
                            
        }
      
        for(j=0;j<4;j++){
            ch = rtufile.time[2]>>((3-j)*4)&0x0f;
            ch += '0';
            sc16puts(&ch,1);
        }
        sc16puts(" ",1);
        req_sample = 0; 
         
         
        
         
       
       
    }
    if(0 == task_active[TASKACTIVE_SAMPLE]&0x0f){
        
        msgGetList();      //短信列表
    }
    
    if(udp_download){          //召测
            i = timegap_end-timegap_start ;
            time_add = timegap_start;
            frame_buffer[0] = 'Z';
            frame_buffer[1] = 'C';
            j = 0;
            while(i){
                if(i>80){
                    for(temp=0;temp<80;temp++){
                        m25p40RD(time_add,&frame_buffer[temp+2],1);
                        time_add++;
                                
                    }
                    frame_buffer[82]= j>>8;
                    frame_buffer[83]= j&0xff;
                    gprsSendData(frame_buffer,84);
                    i-=80;
                }else{
                    for(temp=0;temp<i;temp++){
                        m25p40RD(time_add,&frame_buffer[temp+2],1);        
                        time_add++;
                    }
                    frame_buffer[temp+2]= 0xE5;
                    frame_buffer[temp+3]= 0xE5;    //最后一帧
                    gprsSendData(frame_buffer,i+4);  
                    i=0;
                }
                j++;
                task_active[TASKACTIVE_SAMPLE]++;
            }
       
          udp_download = 0;
        
    }
          
    OSTimeDly(300);
    task_active[TASKACTIVE_SAMPLE]++;
    OSTimeDly(300);
    }