uint8_t BT::power(uint8_t level)
{
	if(!present)
		return 1;

	switch(level)
	{
	   case 1:
		   sendCMD(PSTR("ATSPL,1,1\r"));
		   btPower = 1;
		   break;

	   case 2:
		   sendCMD(PSTR("ATSPL,2,1\r"));
		   btPower = 2;
		   break;

	   case 3:
		   sendCMD(PSTR("ATSPL,3,1\r"));
		   btPower = 3;
		   break;

	   default:
		   sendCMD(PSTR("ATSPL,0,0\r"));
		   btPower = 0;
		   break;
	}

	return checkOK();
}
Btowngtw::Btowngtw()    {
    m_gtwStatus = QSharedPointer<GwtStatus>(new GwtStatus("C1"));
    m_tcpSckSrv = QSharedPointer<TcpServer>(new TcpServer());
    connect(m_tcpSckSrv.data(), SIGNAL(sendCMD(QString, QString)), this, SLOT(receiveCMD(QString, QString)));
    m_webSckSrv = QSharedPointer<WebServer>(new WebServer());
    connect(m_webSckSrv.data(), SIGNAL(sendCMD(QString, QString)), this, SLOT(receiveCMD(QString, QString)));

    m_webSecSckSrv = QSharedPointer<WebSecureServer>(new WebSecureServer());
    connect(m_webSecSckSrv.data(), SIGNAL(sendCMD(QString, QString)), this, SLOT(receiveCMD(QString, QString)));
}
uint8_t BT::connect(char *address)
{
	if(!present)
		return 1;

	cancel();

	sendCMD(PSTR("ATDMLE"));
	sendCMD(address);
	sendCMD(PSTR("\r"));	

	return checkOK();
}
Exemple #4
0
void makeCommand(libusb_device_handle *handle,char* cmd,int delay){
	fprintf(stderr, "Moving %s for %d Ms\n",cmd,delay);
	int command = translateCommand(cmd);
	sendCMD(handle,command);
	// Bei Feuern: Kein Zeitlimit.
	if(command == LAUNCHER_FIRE){
		delay=0;
	}
	// Nur bei Bewegungskommandos pollen:
	if(command!=LAUNCHER_STOP && command!=LAUNCHER_POLL){
		waituntil(handle,command,delay);
		sendCMD(handle,LAUNCHER_STOP);
	}
	
}
Exemple #5
0
void TFT::setPixel(INT16U poX, INT16U poY,INT16U color)
{

    sendCMD(0x2A);                                                      /* Column Command address       */
    sendData(poX);
    sendData(poX);

    sendCMD(0x2B);                                                      /* Column Command address       */
    sendData(poY);
    sendData(poY);
    
    sendCMD(0x2c);

    sendData(color);
}
uint8_t BT::updateVersion(void)
{
	if(!present)
		return 1;

	sendCMD(PSTR("ATV?\r"));

	uint8_t i = checkOK();
	uint8_t n = 0;

	read();

	if(i > 0)
	{
		for(++i; i < BT_BUF_SIZE; i++)
		{
			if(buf[i] == 0)
				break;

			if(i == 6)
			{
				n = (buf[i] - '0');
				btVersion = n;
				return n;
			}
		}
	}

	return 255;
}
uint8_t BT::temperature(void)
{
	if(!present)
		return 1;

	sendCMD(PSTR("ATT?\r"));

	uint8_t i = checkOK();
	uint8_t n = 0;

	read();

	if(i > 0)
	{
		for(++i; i < BT_BUF_SIZE; i++)
		{
			if(buf[i] == 0)
				break;

			if(buf[i] == ',')
			{
				n = (buf[i + 1] - '0') * 100;
				n += (buf[i + 2] - '0') * 10;
				n += (buf[i + 3] - '0');
				return n;
			}
		}
	}

	return 255;
}
Exemple #8
0
void TFT::drawVerticalLine( INT16U poX, INT16U poY, INT16U length,INT16U color)
{
    setCol(poX,poX);
    setPage(poY,poY+length);
    sendCMD(0x2c);
    for(int i=0; i<length; i++)
    sendData(color);
}
uint8_t BT::advertise(void)
{
	if(!present)
		return 1;

	sendCMD(PSTR("ATDSLE\r"));

	return checkOK();
}
uint8_t BT::disconnect(void)
{
	if(!present)
		return 1;

	sendCMD(PSTR("ATDH,0\r"));

	return checkOK();
}
Exemple #11
0
void TFT::setXY(unsigned int poX, unsigned int poY)
{

	if(poX >239)poX = 239;
	if(poY >319)poY = 319;

    setCol(poX, poX);
    setPage(poY, poY);
    sendCMD(0x2c);
}
Exemple #12
0
void TFT::setPage(unsigned int StartPage,unsigned int EndPage)
{

	if(EndPage < StartPage)return ;
	StartPage = StartPage > 319 ? 319 : StartPage;
	EndPage   = EndPage > 319 ? 319 : EndPage;

	sendCMD(0x2B);                                                      /* Column Command address       */
    sendData(StartPage);
    sendData(EndPage);
}
Exemple #13
0
void TFT::setCol(unsigned int StartCol,unsigned int EndCol)
{

	if(EndCol < StartCol)return ;

	StartCol = StartCol > 239 ? 239 : StartCol;
	EndCol   = EndCol > 239 ? 239 : EndCol;
    sendCMD(0x2A);                                                      /* Column Command address       */
    sendData(StartCol);
    sendData(EndCol);
}
uint8_t BT::cancelScan(void)
{
	if(!present)
		return 1;

	sendCMD(PSTR("ATDC,1,1\r"));

	if(state != BT_ST_CONNECTED) state = BT_ST_IDLE;

	return checkOK();
}
Exemple #15
0
void TFT::drawVerticalLine( unsigned int poX, unsigned int poY, unsigned int length,unsigned int color)
{
    setCol(poX, poX);
    setPage(poY, poY+length-1);
    sendCMD(0x2c);
	
    for(int i=0; i<length; i++)
    {
    	sendData(color);
    }
	
}
uint8_t BT::init(void)
{
	_delay_ms(100);
	present = true;
	debug(STR("BT Init\n\r"));

//	sendCMD(STR("ATRST\r")); // Reset module
//	_delay_ms(200);

	while(read()); // Flush buffer

	sendCMD(STR("AT\r")); // Check connection

	debug(STR("Data: "));
	debug(data);
	debug_nl();

	if(checkOK() == 0)
	{
		present = false;
		return 0;
	}

	sendCMD(STR("ATSDBLE,0,0\r")); // Default to Idle (don't advertise)

	if(checkOK() == 0)
		return 0;

	sendCMD(STR("ATSN,Timelapse+\r")); // Set Name

	if(checkOK() == 0)
		return 0;

	sendCMD(STR("ATSZ,1,1,0\r")); // Configure Sleep mode (sleep on reset, wake on UART)

	if(checkOK() == 0)
		return 0;

	sendCMD(STR("ATSDIF,782,1,1\r")); // Configure discovery display

	if(checkOK() == 0)
		return 0;

	sendCMD(STR("ATFC\r")); // Save configuration

	if(checkOK() == 0)
		return 0;

	debug(STR("BT Init: Saved configuration\r\n"));

	state = BT_ST_IDLE;
	mode = BT_MODE_CMD;

	devices = 0;
	newDevices = 0;

//	updateVersion();

	return power(3);
}
uint8_t BT::scan(void)
{
	if(!present)
		return 1;

	if(state != BT_ST_CONNECTED) state = BT_ST_SCAN;

	newDevices = 0;

	sendCMD(PSTR("ATDILE\r"));

	return checkOK();
}
Exemple #18
0
unsigned char TFT::Read_Register(unsigned char Addr, unsigned char xParameter)
{
    unsigned char data=0;
    sendCMD(0xd9);                                                      /* ext command                  */
    WRITE_DATA(0x10+xParameter);                                        /* 0x11 is the first Parameter  */
    TFT_DC_LOW;
    TFT_CS_LOW;
    SPI.transfer(Addr);
    TFT_DC_HIGH;
    data = SPI.transfer(0);
    TFT_CS_HIGH;
    return data;
}
uint8_t BT::sleep(void)
{
	if(!present)
		return 1;

	cancel();

	state = BT_ST_SLEEP;

	if(version() >= 3)
	{
		sendCMD(PSTR("ATZ\r"));

		return checkOK();
	}
	else
	{
		return 1;
	}
}
Exemple #20
0
int waituntil(struct libusb_device_handle * handle,int interrupt_value,int delay){
	struct timeval  tStart, tStop, tLen;
	gettimeofday (&tStart, NULL) ;
	int interrupt;
	do{
		sendCMD(handle,LAUNCHER_POLL);
		interrupt = readInterrupt(handle);		
		gettimeofday (&tStop, NULL);
		timersub(&tStop,&tStart,&tLen);		
		if(delay!=0 && (tLen.tv_usec  > delay * 1000) ){
			break;
		}
		if(interrupt & interrupt_value){
			break;
		}
		// 2 Sekunden:
		//usleep(2000000);
		usleep(20*1000); // 20MS = 20k uSec
		
	}while(1);
}
void TransPanel::onClickBtnSaveConfig()
{
#define MIN_FREQUENCY_VALUE	1080
#define MAX_FREQUENCY_VALUE	1100

	QString ICAO_str = ui.lineEdit_icaoaddr->text() ;
	QString ID_str = ui.lineEdit_trID->text() ; 
	unsigned int frequency = ui.lineEdit_ply->text().toUInt() ;

	if(frequency>MAX_FREQUENCY_VALUE || frequency<MIN_FREQUENCY_VALUE)
	{
		QMessageBox::critical(this , "错误" , "频率源设置错误,取值范围[1080-1100]!");
		return	 ; 
	}

	bool icao_valid = validICAO(ICAO_str);
	if(!icao_valid)
	{
		QMessageBox::critical(this , "错误" , "ICAO地址必须为6个字节长度,0-F十六进制字符!");
		return	;
	}

	bool id_valid = validID(ID_str);
	if(!id_valid)
	{
		QMessageBox::critical(this , "错误" , "ID号长度不能超过8个字符!");
		return	;
	}

	std::string cmd = adsb_trans_ctrl_.cmd_save_config(ICAO_str.toStdString() ,ID_str.toStdString() ,frequency);


	sendCMD(cmd);



}
Exemple #22
0
void TFT::TFTinit (void)
{
    pinMode(2, OUTPUT);
    pinMode(4, OUTPUT);
    pinMode(15, OUTPUT);
    SPI.begin();
    SPI.setClockDivider(SPI_CLOCK_DIV2);
    
    TFT_CS_HIGH;
    TFT_DC_HIGH;
    INT8U i=0, TFTDriver=0;
    for(i=0;i<3;i++)
    {
        TFTDriver = readID();
    }
    delay(500);
    sendCMD(0x01);
    delay(200);

    sendCMD(0xCF);
    WRITE_DATA(0x00);
    WRITE_DATA(0x8B);
    WRITE_DATA(0X30);

    sendCMD(0xED);
    WRITE_DATA(0x67);
    WRITE_DATA(0x03);
    WRITE_DATA(0X12);
    WRITE_DATA(0X81);

    sendCMD(0xE8);
    WRITE_DATA(0x85);
    WRITE_DATA(0x10);
    WRITE_DATA(0x7A);

    sendCMD(0xCB);
    WRITE_DATA(0x39);
    WRITE_DATA(0x2C);
    WRITE_DATA(0x00);
    WRITE_DATA(0x34);
    WRITE_DATA(0x02);

    sendCMD(0xF7);
    WRITE_DATA(0x20);

    sendCMD(0xEA);
    WRITE_DATA(0x00);
    WRITE_DATA(0x00);

    sendCMD(0xC0);                                                      /* Power control                */
    WRITE_DATA(0x1B);                                                   /* VRH[5:0]                     */

    sendCMD(0xC1);                                                      /* Power control                */
    WRITE_DATA(0x10);                                                   /* SAP[2:0];BT[3:0]             */

    sendCMD(0xC5);                                                      /* VCM control                  */
    WRITE_DATA(0x3F);
    WRITE_DATA(0x3C);

    sendCMD(0xC7);                                                      /* VCM control2                 */
    WRITE_DATA(0XB7);

    sendCMD(0x36);                                                      /* Memory Access Control        */
    WRITE_DATA(0x08);

    sendCMD(0x3A);
    WRITE_DATA(0x55);

    sendCMD(0xB1);
    WRITE_DATA(0x00);
    WRITE_DATA(0x1B);

    sendCMD(0xB6);                                                      /* Display Function Control     */
    WRITE_DATA(0x0A);
    WRITE_DATA(0xA2);


    sendCMD(0xF2);                                                      /* 3Gamma Function Disable      */
    WRITE_DATA(0x00);

    sendCMD(0x26);                                                      /* Gamma curve selected         */
    WRITE_DATA(0x01);

    sendCMD(0xE0);                                                      /* Set Gamma                    */
    WRITE_DATA(0x0F);
    WRITE_DATA(0x2A);
    WRITE_DATA(0x28);
    WRITE_DATA(0x08);
    WRITE_DATA(0x0E);
    WRITE_DATA(0x08);
    WRITE_DATA(0x54);
    WRITE_DATA(0XA9);
    WRITE_DATA(0x43);
    WRITE_DATA(0x0A);
    WRITE_DATA(0x0F);
    WRITE_DATA(0x00);
    WRITE_DATA(0x00);
    WRITE_DATA(0x00);
    WRITE_DATA(0x00);

    sendCMD(0XE1);                                                      /* Set Gamma                    */
    WRITE_DATA(0x00);
    WRITE_DATA(0x15);
    WRITE_DATA(0x17);
    WRITE_DATA(0x07);
    WRITE_DATA(0x11);
    WRITE_DATA(0x06);
    WRITE_DATA(0x2B);
    WRITE_DATA(0x56);
    WRITE_DATA(0x3C);
    WRITE_DATA(0x05);
    WRITE_DATA(0x10);
    WRITE_DATA(0x0F);
    WRITE_DATA(0x3F);
    WRITE_DATA(0x3F);
    WRITE_DATA(0x0F);

    sendCMD(0x11);                                                      /* Exit Sleep                   */
    delay(120);
    sendCMD(0x29);                                                      /* Display on                   */
    fillScreen();
}
Exemple #23
0
void TFT::setXY(INT16U poX, INT16U poY)
{
    setCol(poX, poX);
    setPage(poY, poY);
    sendCMD(0x2c);
}
Exemple #24
0
void TFT::setPage(INT16U StartPage,INT16U EndPage)
{
    sendCMD(0x2B);                                                      /* Column Command address       */
    sendData(StartPage);
    sendData(EndPage);
}
Exemple #25
0
void TFT::setCol(INT16U StartCol,INT16U EndCol)
{
    sendCMD(0x2A);                                                      /* Column Command address       */
    sendData(StartCol);
    sendData(EndCol);
}
Exemple #26
0
bool usbDialog::readRawData()
{
	unsigned short addr = 0x02AC;
	int ptr = 0;
	wchar_t serial[10 + 1] = { 0 };

	di.ser.toWCharArray(serial);

	if((dev = hid_open(di.vid, di.pid, serial)) == 0)
	{
		QMessageBox::critical(this, APPNAME, tr("Could not open selected device!"));

		return false;
	}

	dumpfile.setFileName(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation) + QDir::separator() + "import.log");
	dumpfile.remove();

	if(!sendCMD(cmd_init))
	{
		hid_close(dev);

		QMessageBox::warning(this, APPNAME, tr("Press START/STOP button on device and try again..."));

		return false;
	}

	import = true;
	abort = false;

	comboBox->setEnabled(false);
	pushButton_import->setEnabled(false);
	toolButton_dump->setEnabled(false);

	progressBar->setMaximum(2*14*mem / 40);

	for(int i = 0; i < 2*14*mem / 40; i++)
	{
		if(abort)
		{
			sendCMD(cmd_fail);

			hid_close(dev);

			done(QDialog::Rejected);

			return false;
		}

		cmd_data[4] = addr >> 8;
		cmd_data[5] = addr & 0xFF;
		cmd_data[8] = buildCRC(cmd_data);

		sendCMD(cmd_data);

		memcpy(&payload[ptr], &rawdata[7], 40);

		ptr += 40;
		addr += 0x28;

		progressBar->setValue(i);

		QApplication::processEvents();
	}

	sendCMD(cmd_done);

	hid_close(dev);

	return true;
}
Exemple #27
0
void Motor::raiseDoorClosedEvent(){
	sendCMD(EVENT_DOORCLOSED);
}
Exemple #28
0
void Motor::raiseDoorOpenEvent(){
	sendCMD(EVENT_DOOROPEN);
}
//************************************
// Method:    sendDataViaCom
// FullName:  sendDataViaCom
// Access:    public 
// Returns:   DWORD WINAPI
// Qualifier:
// Parameter: void *
// 描述:确认通信正常,否则重启com口再尝试,失败后所有命令有效标识置FALSE
//		如果通信正常,那么把所得结果存到UPS_STATE结构体中的相应字段
//		
//************************************
DWORD WINAPI sendDataViaCom(void* dummy){
	DWORD tryTime;
	char com[20]={0};
	while(1){
		for(int i=0;i<NUM_OF_UPS;i++){
			if(_2023ups[i].UPS_SET_ACTIVE == TRUE){
				tryTime=CHECK_TIME;
				
				start_commu:
			//测试通信是否正常
				if(!sendCMD(_2023ups[i].UPS_COM_HANDLE,UPS_COMMUNICATION_INI,\
					UPS_COMMUNICATION_INI_DECODE,_2023ups[i].UPS_COMMUNICATION_INI_ANSWER,1) && \
						!sendCMD(_2023ups[i].UPS_COM_HANDLE,UPS_CMD_01,UPS_CMD_01_DECODE,_2023ups[i].UPS_CMD_01_ANSWER,10)){
						//不正常,清零结果
					memset(_2023ups[i].UPS_COMMUNICATION_INI_ANSWER,0,\
						sizeof(_2023ups[i].UPS_COMMUNICATION_INI_ANSWER));			//
					memset(_2023ups[i].UPS_CMD_01_ANSWER,0,sizeof(_2023ups[i].UPS_CMD_01_ANSWER));
					//不正常,重启com口,并设置
					if(tryTime--){			//最多尝试CHECK_TIME次
						Sleep(1000);
						printf("restart com%d\n",_2023ups[i].LINK_COM_NUM);
						closeCom(_2023ups[i].UPS_COM_HANDLE);
						memset(com,0,20);
						sprintf(com,"\\\\.\\COM%d",_2023ups[i].LINK_COM_NUM);
						_2023ups[i].UPS_COM_HANDLE=initialCom(com,1024);
		//				COMMTIMEOUTS timeouts={5,15,15,1,1};
						COMMTIMEOUTS timeouts={_2023ups[i].READ_INTERVAL,_2023ups[i].READ_MULTIPLIER,\
							_2023ups[i].READ_CONSTANT,_2023ups[i].WRITE_MULTIPLIER,_2023ups[i].WRITE_CONSTANT};
						if(setComTimeout(_2023ups[i].UPS_COM_HANDLE,timeouts))
							printf("set com timeout ok .....\n");//需要加入异常处理及日志记录
						if(setComPara(_2023ups[i].UPS_COM_HANDLE,_24_N_8_1))
							printf("set com parameter ok.....\n");	
						if(_2023ups[i].UPS_COM_HANDLE == INVALID_HANDLE_VALUE){		//无效句柄
							printf("Open Com Error,try %d times\n",CHECK_TIME);								//退出
							//
							exit(0);
						}
						goto start_commu;											//重新测试通信
					}
				//尝试CHECK_TIME次失败后,确认通信故障
					else{		//所有命令标识置为无效
						_2023ups[i].UPS_COMMUNICATE_NORMAL=FALSE;
						_2023ups[i].CMD_01_CHECK=FALSE;
						_2023ups[i].CMD_02_CHECK=FALSE;
						_2023ups[i].CMD_03_CHECK=FALSE;
						_2023ups[i].CMD_06_CHECK=FALSE;
						_2023ups[i].CMD_07_CHECK=FALSE;
						_2023ups[i].CMD_24_CHECK=FALSE;
						_2023ups[i].CMD_27_CHECK=FALSE;
						_2023ups[i].CMD_31_CHECK=FALSE;
						_2023ups[i].CMD_32_CHECK=FALSE;
						_2023ups[i].CMD_3B_CHECK=FALSE;
						_2023ups[i].CMD_42_CHECK=FALSE;
		//				if((log=fopen("log","w"))!=NULL){
		//					fprintf(log,"%s\n","通信故障");
		//					fclose(log);
		//				}
						break;			//通信故障,无需再发送其他命令,下一台ups
					}
				}
				_2023ups[i].UPS_COMMUNICATE_NORMAL=TRUE;	//确认通信正常,通信标识置为真
				printf("communicate:%s\n",_2023ups[i].UPS_COMMUNICATION_INI_ANSWER);
				printf("\nCmd1:\n");
				//发送命令,如果所得的结果字节少于预期,那么清空结果字段
				if(!sendCMD(_2023ups[i].UPS_COM_HANDLE,UPS_CMD_01,UPS_CMD_01_DECODE,\
					_2023ups[i].UPS_CMD_01_ANSWER,10)){
						memset(_2023ups[i].UPS_CMD_01_ANSWER,0,sizeof(_2023ups[i].UPS_CMD_01_ANSWER));
				}
				sendCMD(_2023ups[i].UPS_COM_HANDLE,UPS_CMD_ACCEPT,UPS_CMD_ACCEPT_DECODE,NULL,0);
				printf("cmd01:%s\n",_2023ups[i].UPS_CMD_01_ANSWER);
				Sleep(1000);		
				printf("\nCmd2:\n");
				if(!sendCMD(_2023ups[i].UPS_COM_HANDLE,UPS_CMD_02,UPS_CMD_02_DECODE,\
					_2023ups[i].UPS_CMD_02_ANSWER,9)){
						memset(_2023ups[i].UPS_CMD_02_ANSWER,0,sizeof(_2023ups[i].UPS_CMD_02_ANSWER));
				}
				sendCMD(_2023ups[i].UPS_COM_HANDLE,UPS_CMD_ACCEPT,UPS_CMD_ACCEPT_DECODE,NULL,0);
				printf("cmd02:%s\n",_2023ups[i].UPS_CMD_02_ANSWER);
				Sleep(1000);
				printf("\nCmd3:\n");
				//发送的命令或接收到的数据长度不正确,清空命令结果
				if(!sendCMD(_2023ups[i].UPS_COM_HANDLE,UPS_CMD_03,UPS_CMD_03_DECODE,\
					_2023ups[i].UPS_CMD_03_ANSWER,8)){
						memset(_2023ups[i].UPS_CMD_03_ANSWER,0,sizeof(_2023ups[i].UPS_CMD_03_ANSWER));
				}
				sendCMD(_2023ups[i].UPS_COM_HANDLE,UPS_CMD_ACCEPT,UPS_CMD_ACCEPT_DECODE,NULL,0);
				printf("cmd03:%s\n",_2023ups[i].UPS_CMD_03_ANSWER);
				Sleep(1000);
				printf("\nCmd06:\n");
				if(!sendCMD(_2023ups[i].UPS_COM_HANDLE,UPS_CMD_06,UPS_CMD_06_DECODE,\
					_2023ups[i].UPS_CMD_06_ANSWER,10)){
						memset(_2023ups[i].UPS_CMD_06_ANSWER,0,sizeof(_2023ups[i].UPS_CMD_06_ANSWER));
				}
				sendCMD(_2023ups[i].UPS_COM_HANDLE,UPS_CMD_ACCEPT,UPS_CMD_ACCEPT_DECODE,NULL,0);
				printf("cmd06:%s\n",_2023ups[i].UPS_CMD_06_ANSWER);
				Sleep(1000);
				printf("\nCmd07:\n");
				if(!sendCMD(_2023ups[i].UPS_COM_HANDLE,UPS_CMD_07,UPS_CMD_07_DECODE,\
					_2023ups[i].UPS_CMD_07_ANSWER,8)){
						memset(_2023ups[i].UPS_CMD_07_ANSWER,0,sizeof(_2023ups[i].UPS_CMD_07_ANSWER));
				}
				sendCMD(_2023ups[i].UPS_COM_HANDLE,UPS_CMD_ACCEPT,UPS_CMD_ACCEPT_DECODE,NULL,0);
				printf("cmd07:%s\n",_2023ups[i].UPS_CMD_07_ANSWER);
				Sleep(1000);
				printf("\nCmd24:\n");
				if(!sendCMD(_2023ups[i].UPS_COM_HANDLE,UPS_CMD_24,UPS_CMD_24_DECODE,\
					_2023ups[i].UPS_CMD_24_ANSWER,6)){
						memset(_2023ups[i].UPS_CMD_24_ANSWER,0,sizeof(_2023ups[i].UPS_CMD_24_ANSWER));
				}
				sendCMD(_2023ups[i].UPS_COM_HANDLE,UPS_CMD_ACCEPT,UPS_CMD_ACCEPT_DECODE,NULL,0);
				printf("cmd24:%s\n",_2023ups[i].UPS_CMD_24_ANSWER);

	/*printf("\nCmd27:\n");
			if(!sendCMD(_2023ups[i].UPS_COM_HANDLE,UPS_CMD_27,UPS_CMD_27_DECODE,\
				_2023ups[i].UPS_CMD_27_ANSWER,8)){
					memset(_2023ups[i].UPS_CMD_27_ANSWER,0,sizeof(_2023ups[i].UPS_CMD_27_ANSWER));
			}
			sendCMD(_2023ups[i].UPS_COM_HANDLE,UPS_CMD_ACCEPT,UPS_CMD_ACCEPT_DECODE,NULL,0);
	printf("cmd27:%s\n",_2023ups[i].UPS_CMD_27_ANSWER);*/			//无法得到回应,注释 2015/6/4


				Sleep(1000);
				printf("\nCmd31:\n");
				if(!sendCMD(_2023ups[i].UPS_COM_HANDLE,UPS_CMD_31,UPS_CMD_31_DECODE,\
					_2023ups[i].UPS_CMD_31_ANSWER,8)){
						memset(_2023ups[i].UPS_CMD_31_ANSWER,0,sizeof(_2023ups[i].UPS_CMD_31_ANSWER));
				}
				sendCMD(_2023ups[i].UPS_COM_HANDLE,UPS_CMD_ACCEPT,UPS_CMD_ACCEPT_DECODE,NULL,0);
				printf("cmd31:%s\n",_2023ups[i].UPS_CMD_31_ANSWER);
				Sleep(1000);
				printf("\nCmd32:\n");
				if(!sendCMD(_2023ups[i].UPS_COM_HANDLE,UPS_CMD_32,UPS_CMD_32_DECODE,\
					_2023ups[i].UPS_CMD_32_ANSWER,9)){
						memset(_2023ups[i].UPS_CMD_32_ANSWER,0,sizeof(_2023ups[i].UPS_CMD_32_ANSWER));
				}
				sendCMD(_2023ups[i].UPS_COM_HANDLE,UPS_CMD_ACCEPT,UPS_CMD_ACCEPT_DECODE,NULL,0);
				printf("cmd32:%s\n",_2023ups[i].UPS_CMD_32_ANSWER);
				Sleep(1000);
				printf("\nCmd3B:\n");
				if(!sendCMD(_2023ups[i].UPS_COM_HANDLE,UPS_CMD_3B,UPS_CMD_3B_DECODE,\
					_2023ups[i].UPS_CMD_3B_ANSWER,6)){
						memset(_2023ups[i].UPS_CMD_3B_ANSWER,0,sizeof(_2023ups[i].UPS_CMD_3B_ANSWER));
				}
				sendCMD(_2023ups[i].UPS_COM_HANDLE,UPS_CMD_ACCEPT,UPS_CMD_ACCEPT_DECODE,NULL,0);
				printf("cmd3B:%s\n",_2023ups[i].UPS_CMD_3B_ANSWER);
				Sleep(1000);
				printf("\nCmd42:\n");
				if(!sendCMD(_2023ups[i].UPS_COM_HANDLE,UPS_CMD_42,UPS_CMD_42_DECODE,\
					_2023ups[i].UPS_CMD_42_ANSWER,12)){
						memset(_2023ups[i].UPS_CMD_42_ANSWER,0,sizeof(_2023ups[i].UPS_CMD_42_ANSWER));
				}
				if(!sendCMD(_2023ups[i].UPS_COM_HANDLE,UPS_CMD_ACCEPT,UPS_CMD_ACCEPT_DECODE,\
					&_2023ups[i].UPS_CMD_42_ANSWER[12],5)){
						memset(_2023ups[i].UPS_CMD_42_ANSWER,0,sizeof(_2023ups[i].UPS_CMD_42_ANSWER));
				}
				sendCMD(_2023ups[i].UPS_COM_HANDLE,UPS_CMD_ACCEPT,UPS_CMD_ACCEPT_DECODE,NULL,0);
				printf("cmd42:%s\n",_2023ups[i].UPS_CMD_42_ANSWER);

				//将接收到的数据转换形式储存到UPS_STATE结构体中
				//设置通信正常标识
				if(_2023ups[i].UPS_COMMUNICATION_INI_ANSWER[0] == 0x16){
					_2023ups[i].UPS_COMMUNICATE_NORMAL=TRUE;
				}
				else{
					_2023ups[i].UPS_COMMUNICATE_NORMAL=FALSE;
				}
				//判断该应答是否有效(0x06,0x84打头),诺有效,依据应答填充UPS_STATE结构体
				//否则,命令有效标识置FALSE
				static const char VALID_ANSWER[3]={0x06,0x84,0x00};
				static const char VALID_CMD1_ANSWER[4]={0x06,0x84,0x66,0x00};
				static const char VALID_CMD2_ANSWER[4]={0x06,0x84,0x55,0x00};
				static const char VALID_CMD3_ANSWER[4]={0x06,0x84,0x44,0x00};
				static const char VALID_CMD6_ANSWER[4]={0x06,0x84,0x66,0x00};
				if(!strncmp(VALID_CMD1_ANSWER,_2023ups[i].UPS_CMD_01_ANSWER,3)){
					_2023ups[i].INPUT_POWER_ABNORMAL=(_2023ups[i].UPS_CMD_01_ANSWER[4]==0x00)?TRUE:FALSE;
					_2023ups[i].BATTERY_LOW_VOLTAGE=(_2023ups[i].UPS_CMD_01_ANSWER[5]==0x01)?TRUE:FALSE;
					_2023ups[i].DISCHARGE=(_2023ups[i].UPS_CMD_01_ANSWER[6]==0x00)?TRUE:FALSE;
					_2023ups[i].CMD_01_CHECK=TRUE;
				}
				else{
					_2023ups[i].CMD_01_CHECK=FALSE;
				}
				if(!strncmp(VALID_CMD2_ANSWER,_2023ups[i].UPS_CMD_02_ANSWER,3)){
					_2023ups[i].UPS_ERROR=(_2023ups[i].UPS_CMD_02_ANSWER[4]==0x01)?TRUE:FALSE;
					_2023ups[i].BATTERY_LINK_STATE=(_2023ups[i].UPS_CMD_02_ANSWER[5]==0x01)?TRUE:FALSE;
					_2023ups[i].OVERLOAD=(_2023ups[i].UPS_CMD_02_ANSWER[6]==0x00)?FALSE:TRUE;
					_2023ups[i].CMD_02_CHECK=TRUE;
				}
				else{
					_2023ups[i].CMD_02_CHECK=FALSE;
				}
				if(!strncmp(VALID_CMD3_ANSWER,_2023ups[i].UPS_CMD_03_ANSWER,3)){
					_2023ups[i].FAN_ERROR=(_2023ups[i].UPS_CMD_03_ANSWER[5]==0x00)?FALSE:TRUE;
					_2023ups[i].OVERHEAT=(_2023ups[i].UPS_CMD_03_ANSWER[6]==0x00)?FALSE:TRUE;
					_2023ups[i].CMD_03_CHECK=TRUE;
				}
				else{
					_2023ups[i].CMD_03_CHECK=FALSE;
				}
				if(!strncmp(VALID_CMD6_ANSWER,_2023ups[i].UPS_CMD_06_ANSWER,3)){
					_2023ups[i].BATTERY_CAPACITY=_2023ups[i].UPS_CMD_06_ANSWER[4];
					_2023ups[i].BATTERY_REMAIN_TIME=(	((unsigned char)_2023ups[i].UPS_CMD_06_ANSWER[5])+	\
						(((unsigned char)_2023ups[i].UPS_CMD_06_ANSWER[6])<<8)+	\
						(((unsigned char)_2023ups[i].UPS_CMD_06_ANSWER[7])<<16)+	\
						(((unsigned char)_2023ups[i].UPS_CMD_06_ANSWER[8])<<24)	)/60;
					_2023ups[i].CMD_06_CHECK=TRUE;
				}
				else{
					_2023ups[i].CMD_06_CHECK=FALSE;
				}

				if(!strncmp(VALID_ANSWER,_2023ups[i].UPS_CMD_07_ANSWER,2)){
					_2023ups[i].LOAD_PERCEN=_2023ups[i].UPS_CMD_07_ANSWER[4];
					_2023ups[i].BATTERY_VOLTATE=(unsigned char)_2023ups[i].UPS_CMD_07_ANSWER[5]+\
						((unsigned char)_2023ups[i].UPS_CMD_07_ANSWER[6]<<8);
					_2023ups[i].CMD_07_CHECK=TRUE;
				}
				else{
					_2023ups[i].CMD_07_CHECK=FALSE;
				}
				if(!strncmp(VALID_ANSWER,_2023ups[i].UPS_CMD_24_ANSWER,2)){
					_2023ups[i].BATTERY_SELFTEST=_2023ups[i].UPS_CMD_24_ANSWER[4];
					_2023ups[i].CMD_24_CHECK=TRUE;
				}
				else{
					_2023ups[i].CMD_24_CHECK=FALSE;
				}
				/*if(!strncmp(VALID_ANSWER,_2023ups[i].UPS_CMD_27_ANSWER,2)){
					_2023ups[i].BATTERY_LINK_STATE=(_2023ups[i].UPS_CMD_27_ANSWER[4]==0x01)?TRUE:FALSE;
					_2023ups[i].CHARGER_ERROR=(_2023ups[i].UPS_CMD_27_ANSWER[5]==0x01)?TRUE:FALSE;
					_2023ups[i].OVERCHARGE=(_2023ups[i].UPS_CMD_27_ANSWER[6]==0x01)?TRUE:FALSE;
					_2023ups[i].CMD_27_CHECK=TRUE;
				}
				else{
					_2023ups[i].CMD_27_CHECK=FALSE;
				}*/
				if(!strncmp(VALID_ANSWER,_2023ups[i].UPS_CMD_31_ANSWER,2)){
					_2023ups[i].INPUT_FREQUENCY=_2023ups[i].UPS_CMD_31_ANSWER[4];
					_2023ups[i].INPUT_VOLTAGE=(((unsigned char)_2023ups[i].UPS_CMD_31_ANSWER[6])<<8) +\
						(unsigned char)_2023ups[i].UPS_CMD_31_ANSWER[5];
					_2023ups[i].CMD_31_CHECK=TRUE;
				}
				else{
					_2023ups[i].CMD_31_CHECK=FALSE;
				}
				if(!strncmp(VALID_ANSWER,_2023ups[i].UPS_CMD_32_ANSWER,2)){
					_2023ups[i].INPUT_FREQUENCY_ABNORMAL=(_2023ups[i].UPS_CMD_32_ANSWER[4]==0x01)?TRUE:FALSE;
					_2023ups[i].INPUT_POWER_MODE=(_2023ups[i].UPS_CMD_32_ANSWER[6]==0x01)?TRUE:FALSE;
					_2023ups[i].INPUT_VOLTAGE_ABNORMAL=(_2023ups[i].UPS_CMD_32_ANSWER[7]==0x01)?TRUE:FALSE;
					_2023ups[i].CMD_32_CHECK=TRUE;
				}
				else{
					_2023ups[i].CMD_32_CHECK=FALSE;
				}
				if(!strncmp(VALID_ANSWER,_2023ups[i].UPS_CMD_3B_ANSWER,2)){
					_2023ups[i].BATTERY_MODE=(_2023ups[i].UPS_CMD_3B_ANSWER[4]==0x01)?TRUE:FALSE;
					_2023ups[i].CMD_3B_CHECK=TRUE;
				}
				else{
					_2023ups[i].CMD_3B_CHECK=FALSE;
				}
				if(_2023ups[i].UPS_CMD_42_ANSWER[0] == 0x06){
					_2023ups[i].OUTPUT_WATT=(unsigned char)_2023ups[i].UPS_CMD_42_ANSWER[4] + \
						((unsigned char)_2023ups[i].UPS_CMD_42_ANSWER[5]<<8);
					_2023ups[i].OUTPUT_VA=(unsigned char)_2023ups[i].UPS_CMD_42_ANSWER[6] + \
						((unsigned char)_2023ups[i].UPS_CMD_42_ANSWER[7]<<8);
					_2023ups[i].OUTPUT_CURRENT=(unsigned char)_2023ups[i].UPS_CMD_42_ANSWER[8]*0.1;
					_2023ups[i].OUTPUT_FREQUENCY=(unsigned char)_2023ups[i].UPS_CMD_42_ANSWER[9];
					_2023ups[i].OUTPUT_VOLTAGE=(unsigned char)_2023ups[i].UPS_CMD_42_ANSWER[14] + \
						((unsigned char)_2023ups[i].UPS_CMD_42_ANSWER[15]<<8);
					_2023ups[i].CMD_42_CHECK=TRUE;
				}
				else{
					_2023ups[i].CMD_42_CHECK=FALSE;
				}
			}
		}
		Sleep(15000);						//
	}
	return 0;
}
Exemple #30
0
int main (void) {

  SPIDDR=(1<<SDA)|(1<<CLK)|(1<<CS)|(1<<RESET); //Port-Direction Setup


  //Init Uart and send OK
  UCR = (1<<RXEN)|(1<<TXEN);
  UBRR=(F_CPU / (BAUD_RATE * 16L) - 1);
  loop_until_bit_is_set(USR, UDRE);
  UDR = 'O';
  loop_until_bit_is_set(USR, UDRE);
  UDR = 'K';


  CS0
  SDA0
  CLK1

  RESET1
  RESET0
  RESET1

  CLK1
  SDA1
  CLK1

  waitms(10);

  //Software Reset
  sendCMD(0x01);

  //Sleep Out
  sendCMD(0x11);

  //Booster ON
  sendCMD(0x03);

  waitms(10);

  //Display On
  sendCMD(0x29);

  //Normal display mode
  sendCMD(0x13);

  //Display inversion on
  sendCMD(0x21);

  //Data order
  sendCMD(0xBA);

  //Memory data access control
  sendCMD(0x36);

 //sendData(8|64);   //rgb + MirrorX
  sendData(8|128);   //rgb + MirrorY

#ifdef MODE565
  sendCMD(0x3A);
  sendData(5);   //16-Bit per Pixel
#else
  //sendCMD(0x3A);
  //sendData(3);   //12-Bit per Pixel (default)
#endif


  //Set Constrast
  //sendCMD(0x25);
  //sendData(63);


  //Column Adress Set
  sendCMD(0x2A);
  sendData(0);
  sendData(131);

  //Page Adress Set
  sendCMD(0x2B);
  sendData(0);
  sendData(131);

  //Memory Write
  sendCMD(0x2C);

	int i;
  //Test-Picture

  //red bar
  for (i=0;i<132*33;i++) {
    setPixel(255,0,0);
  }

  //green bar
  for (i=0;i<132*33;i++) {
    setPixel(0,255,0);
  }

  //blue bar
  for (i=0;i<132*33;i++) {
    setPixel(0,0,255);
  }

  //white bar
  for (i=0;i<132*33;i++) {
    setPixel(255,255,255);
  }


  //wait for RGB-Data on serial line and display on lcd

  while(1==1) {

    loop_until_bit_is_set(UCSRA, RXC);
    r = UDR;
    loop_until_bit_is_set(UCSRA, RXC);
    g = UDR;
    loop_until_bit_is_set(UCSRA, RXC);
    b = UDR;
    setPixel(r,g,b);

  }

}