Exemplo n.º 1
0
char ModBus(char NumByte) {
    int TempI;
    //вывод посылки на экран
    cmRcBuf0[NumByte]=0x00;

    //обработка посылки
    if (cmRcBuf0[0]!=0x20) return 0x00; //адрес устройства  //ответ не нужен
    CRC16=GetCRC16(cmRcBuf0,NumByte-2);//подсчет CRC в принятой посылке
    TempI=(int) (cmRcBuf0[NumByte-1]<<8) + cmRcBuf0[NumByte-2];
    if (CRC16!=TempI) return 0x00;  //контрольная сумма //ответ не нужен
    cmTrBuf0[0]=0x20;//адрес устройства
    //код команды
    switch(cmRcBuf0[1]) {
    case 0x03: { //чтение регистров
        TempI=(int) (cmRcBuf0[2]<<8) + cmRcBuf0[3];
        if (TempI!=1) { //првоерка номера регистра, есть только 1 регистр
            return ErrorMessage(0x02); //данный адрес не может быть обработан
        }
        TempI=(int) (cmRcBuf0[4]<<8) + cmRcBuf0[5];
        if (TempI!=1) { //проверка кол-ва запрашиваемых регистров, есть только 1 регистр
            return ErrorMessage(0x02); //данный адрес не может быть обработан
        }
        cmTrBuf0[1]=0x03;//команда
        cmTrBuf0[2]=0x02;//кол-во байт данных
        cmTrBuf0[3]=0x00;//старший байт
        TempI=PINB;
        cmTrBuf0[4]=Low(TempI);//уровни порта F
        TempI=GetCRC16(cmTrBuf0,5);//подсчет КС посылки
        cmTrBuf0[5]=Low(TempI);
        cmTrBuf0[6]=Hi(TempI);
        return 7;
    }
    case 0x06: { //запись в единичный регистр
        TempI=(int) (cmRcBuf0[2]<<8) + cmRcBuf0[3];
        if (TempI!=1) { //првоерка номера регистра, есть только 1 регистр
            return ErrorMessage(0x02); //данный адрес не может быть обработан
        }
        TempI=(int) (cmRcBuf0[4]<<8) + cmRcBuf0[5];
        if (TempI>0xFF) { //проверка числа, которое надо записать в порт
            return ErrorMessage(0x03); //недопустимые данные в запросе
        }
        PORTB=Low(TempI);
        cmTrBuf0[1]=cmRcBuf0[1];//команда
        cmTrBuf0[2]=cmRcBuf0[2];//адрес
        cmTrBuf0[3]=cmRcBuf0[3];//
        cmTrBuf0[4]=cmRcBuf0[4];//данные
        cmTrBuf0[5]=cmRcBuf0[5];//
        cmTrBuf0[6]=cmRcBuf0[6];//КС
        cmTrBuf0[7]=cmRcBuf0[7];//
        return 8;
    }
    default: {
        return ErrorMessage(0x01); //недопустимая команда
    }
    }
}//end ModBus()
Exemplo n.º 2
0
double
HTMLMeterElement::High() const
{
    /**
     * If the high value is defined, the high value is this value.
     * Otherwise, the high value is the maximum value.
     * If the high value is less than the low value,
     * the high value is the same as the low value.
     * If the high value is greater than the maximum value,
     * the high value is the same as the maximum value.
     */

    double max = Max();

    const nsAttrValue* attrHigh = mAttrsAndChildren.GetAttr(nsGkAtoms::high);
    if (!attrHigh || attrHigh->Type() != nsAttrValue::eDoubleValue) {
        return max;
    }

    double high = attrHigh->GetDoubleValue();

    if (high >= max) {
        return max;
    }

    return std::max(high, Low());
}
Exemplo n.º 3
0
static void __inline__ sccb_start(void)
{
	CFG_WRITE(SIO_D);

	Low(SIO_D);
	WAIT_STABLE();
}
Exemplo n.º 4
0
static void __inline__ sccb_stop(void)
{
	Low(SIO_C);
	WAIT_STABLE();
	
	CFG_WRITE(SIO_D);
	Low(SIO_D);
	WAIT_CYCLE();
	
	High(SIO_C);
	WAIT_STABLE();
	
	High(SIO_D);
	WAIT_CYCLE();
	
	CFG_READ(SIO_D);
}
Exemplo n.º 5
0
static void
dfs(Agraph_t * g, Agnode_t * u, bcstate * stp, Agnode_t * parent)
{
    Agnode_t *v;
    Agedge_t *e;
    Agedge_t *ep;
    Agraph_t *sg;

    stp->count++;
    Low(u) = N(u) = stp->count;
    for (e = agfstedge(g, u); e; e = agnxtedge(g, e, u)) {
	if ((v = aghead(e)) == u)
	    v = agtail(e);
	if (v == u)
	    continue;
	if (N(v) == 0) {
	    push(&stp->stk, e);
	    dfs(g, v, stp, u);
	    Low(u) = min(Low(u), Low(v));
	    if (Low(v) >= N(u)) {	/* u is an articulation point */
		Cut(u) = 1;
		sg = mkBlock(g, stp);
		do {
		    ep = pop(&stp->stk);
		    agsubnode(sg, aghead(ep), 1);
		    agsubnode(sg, agtail(ep), 1);
		} while (ep != e);
	    }
	} else if (parent != v) {
	    Low(u) = min(Low(u), N(v));
	    if (N(v) < N(u))
		push(&stp->stk, e);
	}
    }
}
Exemplo n.º 6
0
//формирование ответа об ошибке
char ErrorMessage(char Error) {
    char TempI;
    cmTrBuf0[1]=cmRcBuf0[1]+0x80;;//команда с ошибкой
    cmTrBuf0[2]=Error;
    TempI=GetCRC16(cmTrBuf0,3);//подсчет КС посылки
    cmTrBuf0[3]=Low(TempI);
    cmTrBuf0[4]=Hi(TempI);
    return 5;
}//end ErrorMessage()
Exemplo n.º 7
0
char ErrorMessage(char Error){
  unsigned int TempI;
  cmTrBuf1[1]=cmRcBuf1[1]+0x80;
  cmTrBuf1[2]=Error;
  TempI=GetCRC16(cmTrBuf1,3);
  cmTrBuf1[3]=Low(TempI);
  cmTrBuf1[4]=Hi(TempI);  
  return 5;
}//end ErrorMessage()
Exemplo n.º 8
0
static void __inline__ sccb_write_byte(u8 data)
{
	int i;

	CFG_WRITE(SIO_D);
	WAIT_STABLE();

	/* write 8-bits octet. */
	for (i=0;i<8;i++)
	{
		Low(SIO_C);
		WAIT_STABLE();

		if (data & 0x80)
		{
			High(SIO_D);
		}
		else
		{
			Low(SIO_D);
		}
		data = data<<1;
		WAIT_CYCLE();
		
		High(SIO_C);
		WAIT_CYCLE();
	}
	
	/* write byte done, wait the Don't care bit now. */
	{
		Low(SIO_C);
		High(SIO_D);
		CFG_READ(SIO_D);
		WAIT_CYCLE();
		
		High(SIO_C);
		WAIT_CYCLE();
	}
}
Exemplo n.º 9
0
static u8 __inline__ sccb_read_byte(void)
{
	int i;
	u8 data;

	CFG_READ(SIO_D);
	WAIT_STABLE();
	
	Low(SIO_C);
	WAIT_CYCLE();

	data = 0;
	for (i=0;i<8;i++)
	{
		High(SIO_C);
		WAIT_STABLE();
		
		data = data<<1;
		data |= State(SIO_D)?1:0;
		WAIT_CYCLE();
		
		Low(SIO_C);
		WAIT_CYCLE();
	}
	
	/* read byte down, write the NA bit now.*/
	{
		CFG_WRITE(SIO_D);
		High(SIO_D);
		WAIT_CYCLE();
		
		High(SIO_C);
		WAIT_CYCLE();
	}
	
	return data;
}
Exemplo n.º 10
0
//настройка UART
void StartUART0(void) {
    UBRRH=Hi(((dXTAL/16)/19200)-1);
    UBRRL=Low(((dXTAL/16)/19200)-1);

    UCSRA=0x00;
    UCSRB=0xD8;
    UCSRC=0x86;

    UBRRH=0x00;
    UBRRL=0x33;

    EnableReceive0;
    InitTimer0;
    StartTimer0;
}//end void StartUART0()
Exemplo n.º 11
0
nsEventStates
HTMLMeterElement::GetOptimumState() const
{
    /*
     * If the optimum value is in [minimum, low[,
     *     return if the value is in optimal, suboptimal or sub-suboptimal region
     *
     * If the optimum value is in [low, high],
     *     return if the value is in optimal or suboptimal region
     *
     * If the optimum value is in ]high, maximum],
     *     return if the value is in optimal, suboptimal or sub-suboptimal region
     */
    double value = Value();
    double low = Low();
    double high = High();
    double optimum = Optimum();

    if (optimum < low) {
        if (value < low) {
            return NS_EVENT_STATE_OPTIMUM;
        }
        if (value <= high) {
            return NS_EVENT_STATE_SUB_OPTIMUM;
        }
        return NS_EVENT_STATE_SUB_SUB_OPTIMUM;
    }
    if (optimum > high) {
        if (value > high) {
            return NS_EVENT_STATE_OPTIMUM;
        }
        if (value >= low) {
            return NS_EVENT_STATE_SUB_OPTIMUM;
        }
        return NS_EVENT_STATE_SUB_SUB_OPTIMUM;
    }
    // optimum in [low, high]
    if (value >= low && value <= high) {
        return NS_EVENT_STATE_OPTIMUM;
    }
    return NS_EVENT_STATE_SUB_OPTIMUM;
}
Exemplo n.º 12
0
static u8 __inline__ sccb_read_byte(void)
{
	int i;
	u8 data;

	CFG_READ(SIO_D);
	WAIT_STABLE();
	
	Low(SIO_C);
	WAIT_CYCLE();

	data = 0;
	for (i=7;i>=0;i--)
	{
		//High(SIO_C);
		//WAIT_STABLE();
		
		data |= State(SIO_D)<<i;
		WAIT_CYCLE();
		
		//Low(SIO_C);
		//WAIT_CYCLE();
	}
	
	/* read byte down, write the NA bit now.*/
	{
		CFG_WRITE(SIO_D);
		High(SIO_D);
		WAIT_CYCLE();
		
		High(SIO_C);
		WAIT_CYCLE();
	}
	printk("(%d)",data & 0xFF);
	return (data);
}
Exemplo n.º 13
0
NS_IMETHODIMP
HTMLMeterElement::GetLow(double* aValue)
{
    *aValue = Low();
    return NS_OK;
}
Exemplo n.º 14
0
//обработка принятого сообщения
void DataModBus1(unsigned char NumberByte)
{

      if (GetSostPort1() & HardError)  //если произошла ошибка приема
        {
          Tr_buf_data_uart1[4]=0;
          Tr_buf_data_uart1[5]=0;
          ErrorMessage1(0xE1);
        }
      else
        {
              if ((Rec_buf_data_uart1[0]==0x55)&&(Rec_buf_data_uart1[1]==0xAA))  //проверка байт синхронизации
              {
                if (Rec_buf_data_uart1[3]!=NumberByte-5) //сравним принятое количество байт данных с заявленным
                {
                    Tr_buf_data_uart1[4]=Rec_buf_data_uart1[3]; //заявленное кол-во байт данных
                    Tr_buf_data_uart1[5]=NumberByte-5; //принятое кол-во байт данных
                    ErrorMessage1(0xE3);
                }
                else
                {
                  CRCSum1=GetCRCSum1(Rec_buf_data_uart1,NumberByte-1);
                  if (CRCSum1!=Rec_buf_data_uart1[NumberByte-1]) //прверка принятого CRC
                  {
                    Tr_buf_data_uart1[4]=Rec_buf_data_uart1[NumberByte-1];  //принятая контрольная сумма
                    Tr_buf_data_uart1[5]=CRCSum1; //вычисленная контрольная сумма
                    ErrorMessage1(0xE2);
                  }
                  else
                  {
                    if ((Rec_buf_data_uart1[2]==0x74)||(Rec_buf_data_uart1[2]==0x73))
                    {

                      if (Rec_buf_data_uart1[2]==0x74){
                        PassToPC=(ePassword[0]-0x30)*1000+(ePassword[1]-0x30)*100+(ePassword[2]-0x30)*10+(ePassword[3]-0x30);
                        Tr_buf_data_uart1[4]=Hi(PassToPC);
                        Tr_buf_data_uart1[5]=Low(PassToPC);
                        TransDataInf1(0x72, 2);
                      }
                      if (Rec_buf_data_uart1[2]==0x73)
                      {
                        PassToPC=(Rec_buf_data_uart1[4]<<8)+Rec_buf_data_uart1[5];
                        ePassword[0]=PassToPC/1000+0x30;
                        PassToPC-=(ePassword[0]-0x30)*1000;
                        ePassword[1]=PassToPC/100+0x30;
                        PassToPC-=(ePassword[1]-0x30)*100;
                        ePassword[2]=PassToPC/10+0x30;
                        PassToPC-=(ePassword[2]-0x30)*10;
                        ePassword[3]=PassToPC+0x30;

                        TransDataInf1(0x73, 0);

                        //а теперь запишем пароль в EEPROM
                        eWrite=1;
                        eAddressWrite=0;
                        eMassiveWrite=ePassword;
                      }
                      PCtime=PC_wait;
                      EnableReceive1;
                    }
                    else
                    {
                      for (i_dc1=0; i_dc1<NumberByte; i_dc1++)
                      {
                        Tr_buf_data_uart[i_dc1]=Rec_buf_data_uart1[i_dc1];
                        Rec_buf_data_uart1[i_dc1]=0x00;
                      }
                      PCbyte=NumberByte;
                      PCready=1;
                      PCtime=PC_wait;
                    }
                  }
                }

              } //end if (col.11)
              else //если адрес не тот, то опять следим за линией
              {
                EnableReceive1;
              }
        }//end else (col.9)
      ClearPortError1();   //после начала отправки сообщения очистим регистр приема
} //end DataModBus
Exemplo n.º 15
0
/* The commutate function uses the High, Low and Float functions to commutate
 * the motor. The input to the function is the motor state from the hall effect 
 * sensors. Depending on the value of the global variable "direction" the
 * function sets the motor outputs according to the motor's commutation pattern.
 * The commutation pattern is derived from the commutation diagram found on p32
 * of Maxon's E-Paper Catalog and is shown below.
 *
 * Hall Sen 321 | 101 | 001 | 011 | 010 | 110 | 100 |
 *     State    |  5  |  1  |  3  |  2  |  6  |  4  |
 * -------------|-----|-----|-----|-----|-----|-----|
 * 1 -   Red    |  +  |  +  |  0  |  -  |  -  |  0  |
 * 2 -  Black   |  -  |  0  |  +  |  +  |  0  |  -  |
 * 3 -  White   |  0  |  -  |  -  |  0  |  +  |  +  |
 *
 * An input of 0 to the commutate function will turn off the motor.
 */
void commutate(int state){
    switch(state){
        case 0:
            Float(1); Float(2); Float(3);
            break;
        case 1:
            if(direction){
                High(1); Float(2); Low(3);
            } else{
                Low(1); Float(2); High(3);
            }
            break;
        case 2:
            if(direction){
                Low(1); High(2); Float(3);
            } else{
                High(1); Low(2); Float(3);
            }
            break;
        case 3:
            if(direction){
                Float(1); High(2); Low(3);
            } else{
                Float(1); Low(2); High(3);
            }
            break;
        case 4:
            if(direction){
                Float(1); Low(2); High(3);
            } else{
                Float(1); High(2); Low(3);
            }
            break;
        case 5:
            if(direction){
                High(1); Low(2); Float(3);
            } else{
                Low(1); High(2); Float(3);
            }
            break;
        case 6:
            if(direction){
                Low(1); Float(2); High(3);
            } else{
                High(1); Float(2); Low(3);
            }
            break;
        case 7:
            Low(1); High(2);
            break;
        default:
            Float(1); Float(2); Float(3);
            break;
    }
}
Exemplo n.º 16
0
int main(int argc, char* argv[])
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
	glutInitWindowSize(800, 600);
	glutInitWindowPosition(100,100);
	glutCreateWindow("OGLplus+GLUT+GLEW");

	if(glewInit() == GLEW_OK) try
	{
		glGetError();
		namespace se = oglplus::smart_enums;
		oglplus::Context gl;
		oglplus::AMD_performance_monitor apm;

		const char* f1[2] = {"  +--", "  `--"};
		const char* f2[2] = {"  |", "   "};
		const char* f3[2] = {"  +--", "  `--"};
		const char* f4[2] = {"  |", ""};

		auto groups = apm.GetGroups();
		auto gi=groups.begin(), ge=groups.end();

		std::cout << "--+-{Performance monitor groups}" << std::endl;
		if(gi != ge) std::cout << "  |" << std::endl;

		while(gi != ge)
		{
			auto group = *gi;
			++gi;
			const int fgi = (gi == ge)?1:0;

			std::cout << f1[fgi] << "+-[";
			std::cout << group.GetString();
			std::cout << "]" << std::endl;
			std::cout << f2[fgi] << f4[0] << std::endl;

			GLint max;
			auto counters = group.GetCounters(max);
			auto ci=counters.begin(), ce=counters.end();

			while(ci != ce)
			{
				auto counter = *ci;
				++ci;
				const int fci = (ci == ce)?1:0;
				std::cout << f2[fgi] << f3[fci] << "(";
				std::cout << counter.GetString();
				std::cout << ") [";
				std::cout << EnumValueName(counter.Type());
				std::cout << "]" << std::endl;
				std::cout << f2[fgi] << f4[fci] << std::endl;
			}
			if(fgi != 0)
			{
				oglplus::PerfMonitorAMD mon;
				mon.SelectCounters(true, counters);
				mon.Begin();
				// Imagine some heavy duty rendering here
				gl.Clear().ColorBuffer();
				mon.End();

				if(mon.ResultAvailable())
				{
					std::vector<oglplus::PerfMonitorAMDResult>
						values;
					mon.Result(values);

					auto ri=values.begin(), re=values.end();
					while(ri != re)
					{
						auto counter = ri->Counter();
						auto type = counter.Type();

						std::cout << counter.GetString();
						std::cout << " [";
						std::cout << EnumValueName(type);
						std::cout << "] = ";
						if(type == se::UnsignedInt())
							std::cout << ri->Low();
						else if(type == se::Float())
							std::cout << ri->Float();
						else if(type == se::Percentage())
							std::cout << ri->Float() << "%";
						else if(type == se::UnsignedInt64())
							std::cout << "too big";
						std::cout << std::endl;
						++ri;
					}
				}
			}
		}
		return 0;
	}
	catch(oglplus::Error& err)
	{
		std::cerr
			<< "Error (in "
			<< err.GLFunc()
			<< "'): "
			<< err.what()
			<< " ["
			<< err.SourceFile()
			<< ":"
			<< err.SourceLine()
			<< "] "
			<< std::endl;
	}
	return 1;
}
Exemplo n.º 17
0
BYTE ModBus(BYTE NumByte){
  BYTE RNum=0;
  BYTE RSum=0;
  
unsigned int TempI=0;

  cmRcBuf1[NumByte]=0x00;

  if (cmRcBuf1[0]!=DEVICE_ADDRESS) return 0x00;
 
  CRC16=GetCRC16(cmRcBuf1,NumByte-2);
  TempI=(unsigned int) (cmRcBuf1[NumByte-1]<<8) + cmRcBuf1[NumByte-2];  
  if (CRC16!=TempI) return 0x00;
		
  cmTrBuf1[0]=DEVICE_ADDRESS;
  switch(cmRcBuf1[1]){
    case 0x03:{
      TempI=(unsigned int) (cmRcBuf1[2]<<8) + cmRcBuf1[3];
      RNum=TempI;
      if (RNum>=0x64){
        return ErrorMessage(0x02);
      }
      TempI=(unsigned int) (cmRcBuf1[4]<<8) + cmRcBuf1[5];
      RSum=TempI;
      if ((RSum>0x64)||((RNum+RSum)>0x64)) {
    	  return ErrorMessage(0x02);
      }
      cmTrBuf1[1]=0x03;
      
      BYTE i=RSum*2;      
      BYTE j=RNum*2; 
      cmTrBuf1[2]=i;
      
      BYTE n=3;
      
      while(i--){
                 //cmTrBuf1[n++]=MODBUS_MAS[j++];
				 cmTrBuf1[n++]=AOHR_registers[j++]; 
                }
      
      TempI=GetCRC16(cmTrBuf1,n);
      cmTrBuf1[n++]=Low(TempI);
      cmTrBuf1[n++]=Hi(TempI); 
      return n;
    }
    case 0x06:{
      TempI=(unsigned int) (cmRcBuf1[2]<<8) + cmRcBuf1[3];
      RNum=TempI;
      if (RNum>=0x64){
                       return ErrorMessage(0x02);
                     }
      TempI=(unsigned int) (cmRcBuf1[4]<<8) + cmRcBuf1[5];      
      BYTE c=RNum*2;
      //MODBUS_MAS[c++]=Hi(TempI);
      //MODBUS_MAS[c]=Low(TempI);
      AOHR_registers[c++]=Hi(TempI);
	  AOHR_registers[c]=Low(TempI);
	  
      cmTrBuf1[1]=cmRcBuf1[1];
      cmTrBuf1[2]=cmRcBuf1[2];
      cmTrBuf1[3]=cmRcBuf1[3];
      cmTrBuf1[4]=cmRcBuf1[4];
      cmTrBuf1[5]=cmRcBuf1[5];
      cmTrBuf1[6]=cmRcBuf1[6];
      cmTrBuf1[7]=cmRcBuf1[7];
      return 8;
    }
    
    case 0x10:{
      TempI=(unsigned int) (cmRcBuf1[2]<<8) + cmRcBuf1[3];
      RNum=TempI;
      if (RNum>=0x64){
         return ErrorMessage(0x02);
      }
      
      TempI=(unsigned int) (cmRcBuf1[4]<<8) + cmRcBuf1[5];
      RSum=TempI;
      if ((RSum>0x64)||((RNum+RSum)>0x64)){
    	  return ErrorMessage(0x02);
      }
      
      
      TempI=(unsigned int) cmRcBuf1[6];
      BYTE BSum=TempI;
      
      BYTE n=7;
      
      while(BSum--){
		//MODBUS_MAS[RNum++]=cmRcBuf1[n++];
		AOHR_registers[RNum++]=cmRcBuf1[n++];
      }
      
      cmTrBuf1[1]=cmRcBuf1[1];
      cmTrBuf1[2]=cmRcBuf1[2];
      cmTrBuf1[3]=cmRcBuf1[3];
      cmTrBuf1[4]=cmRcBuf1[4];
      cmTrBuf1[5]=cmRcBuf1[5];
      TempI=GetCRC16(cmTrBuf1,6);
      cmTrBuf1[6]=Low(TempI);
      cmTrBuf1[7]=Hi(TempI);
      return 8;
    }
    
    
    
    default:{
       return ErrorMessage(0x01);
    }
  }
}