Exemple #1
0
//*****************д×Ö·û´®**********************
void show(unsigned char * str)
{
	while(*str!='\0')
	{
		write_dat(*str);
		str++;
	}
}
Exemple #2
0
//----------------------------------------------------------------------------------------
// Display loeschen
//----------------------------------------------------------------------------------------
void ClearDisplay(void)
{
unsigned int a;

  write_cmd(0x15);
  write_cmd(0x07);
  write_cmd(0x39);
  write_cmd(0x75);
  write_cmd(0x00);
  write_cmd(0x4F);
  for (a=0; a<(102/2*80); a++) write_dat(0x00);        //clr
}
Exemple #3
0
// ------------------------------------------------------------------
// Funktion stellt ein Zeichen dar 5x7
// column 00..16 Spalten 17 X
// row     0...9 Zeilen  10 Y Reihe
// ------------------------------------------------------------------
void PaintChar(unsigned char sign, unsigned char column, unsigned char row) 
{
unsigned char CharCol_1, CharCol_2, CharCol_3, CharCol_4, CharCol_5;
unsigned char char_r_y_p12, char_r_y_p34, char_r_y_p56;
unsigned char pz, y;
unsigned int pos;
  
  if ((sign<0x20) || (sign>0x7F)) { sign = 0x20; } 
  pos = 5*(sign-0x20);

  CharCol_1 = pgm_read_byte(&code5x7[pos++]);
  CharCol_2 = pgm_read_byte(&code5x7[pos++]);
  CharCol_3 = pgm_read_byte(&code5x7[pos++]);
  CharCol_4 = pgm_read_byte(&code5x7[pos++]);
  CharCol_5 = pgm_read_byte(&code5x7[pos++]);

  write_cmd(0x15);
  write_cmd(7+3*column);
  write_cmd(7+3*column+2);
  write_cmd(0x75);
  write_cmd(8*row);
  write_cmd(8*row+7);
  
  pz = 1;                                                  //pixelzeile
  for (y=0; y<8; y++) 
  {
    char_r_y_p12 = char_r_y_p34 = char_r_y_p56 = 0;
    if (CharCol_1 & pz) { char_r_y_p12 |= 0xF0; }
    if (CharCol_2 & pz) { char_r_y_p12 |= 0x0F; }
    write_dat(char_r_y_p12);
    if (CharCol_3 & pz) { char_r_y_p34 |= 0xF0; }
    if (CharCol_4 & pz) { char_r_y_p34 |= 0x0F; }
    write_dat(char_r_y_p34);
    if (CharCol_5 & pz) { char_r_y_p56 = 0xF0; }           // 6.Spalte bleibt immer leer
    write_dat(char_r_y_p56);
    pz = pz << 1;
  }
}
Exemple #4
0
/*???*/
main()
{
	uchar i;
	wela=0;
	dula=0;
	delay_1ms(10);
	lcd_init();
	lcd_pos(1,0);
	i=0;
	while(dis2[i]!='\0')
	{
		write_dat(dis2[i]);
		i++;
	}
	lcd_pos(2,0);
	i=0;
	while(dis3[i]!='\0')
	{
		write_dat(dis3[i]);
		i++;
	}
	lcd_pos(3,0);
	i=0;
	while(dis4[i]!='\0')
	{
		write_dat(dis4[i]);
		i++;
	}
	while(1)
	{
		lcd_pos(0,0);
		makerand();
		for(i=0;i<10;i++)
		{
			write_dat(dis1[i]);
		}
	}
}
int deviceBlockDataRecvPacket(client_t *client, char *packet, int length) {
	int i = 0;
	int dataLength = packet[30] * 256 + (unsigned char)packet[31];
	int pktIndex = packet[13];
	int pktTotal = packet[29];
	char u8DeviceId[LEN_DEVICE_ID*2+1];
	char u8FileName[LEN_DEVICE_ID*4];

	apollo_printf("pkt_13:%d, pkt_29:%d, pkt_30:%d, pkt_31:%d\n", packet[13], packet[29], packet[30], (unsigned char)packet[31]);
	if (((client->pBlock->index + length) == LEN_BLOCK_PACKET) && ((pktIndex + 1) != pktTotal)) {
		apollo_printf(" copy index : %d, dataLength:%d\n", client->pBlock->index, dataLength);
		client->pBlock->index = 0;
		for (i = 0;i < dataLength;i ++) {
			client->pBlock->buffer[pktIndex * (LEN_BLOCK_PACKET-LEN_HEADER_LENGTH)+i] = packet[LEN_HEADER_LENGTH+i];
		}
		memset(packet, 0, LEN_BLOCK_PACKET);
		apollo_printf(" aaaa index : %d, dataLength:%d\n", client->pBlock->index, dataLength);
		
	} else {
		apollo_printf(" index:%d\n", client->pBlock->index);
		client->pBlock->index += length;
	}
	//the last packet
	if (((pktIndex + 1) == pktTotal) && (length >= (dataLength + LEN_HEADER_LENGTH))) {
		for (i = 0;i < dataLength;i ++) {
			client->pBlock->buffer[pktIndex * (LEN_BLOCK_PACKET-LEN_HEADER_LENGTH)+i] = packet[LEN_HEADER_LENGTH+i];
		}
		//save data to file
		hextostring(u8DeviceId ,packet+IDX_DEVICE_ID, LEN_DEVICE_ID);
		genBlockFilePathName(u8DeviceId, u8FileName);
		write_dat(u8FileName, client->pBlock->buffer, pktIndex * (LEN_BLOCK_PACKET - LEN_HEADER_LENGTH) + dataLength);

		//set redis key
		
	}

	return 0;
}
void apolloParsePacket(struct bufferevent *bev, client_t *client) {
	char *data = client->pBlock->packet;
	int nbytes, i;
	unsigned int blockIndex = client->pBlock->index;

	if (blockIndex > LEN_BLOCK_PACKET || blockIndex < 0) blockIndex = 0;
#if 0
	while ((nbytes = EVBUFFER_LENGTH(bev->input)) > 0) {
		if (nbytes > FRAME_LENGTH) nbytes = FRAME_LENGTH;
		evbuffer_remove(bev->input, data, nbytes); 
#else
	apollo_printf("cccc index:%d\n", client->pBlock->index);
	while ((nbytes = evbuffer_remove(bev->input, data + blockIndex, LEN_BLOCK_PACKET - blockIndex)) > 0) {
#endif
		apollo_printf(" blockIndex : %d, nbytes:%d, fd:%d, data[0]:0x%x\n", blockIndex, nbytes, client->fd, data[0]);
		
		apollo_printf("\n");
		switch (data[0]) {
			case HDR_HEART_PACKET_DEVICE: {
				char cmd;
				char setValueBuf[LEN_DEVICE_HEARTPACKET_RETURN_BUFFER] = {0};
				char retbuf[LEN_DEVICE_RETURN_BUFFER] = {'R', 'E', 'T', 'O', 'K', '%'};
				int result = ApolloProtocolInstance->deviceHeartPacket_Proc(data, nbytes, setValueBuf);
				if (result > 0) {	
					
					if ((result & 0xF0) == (CMD_PHONE_DEVICE_FAMILYNUMBER_SET & 0xF0)) {
						setValueBuf[0] = 'C';
						apolloReturnPacket(bev, client, setValueBuf, LEN_DEVICE_HEARTPACKET_RETURN_BUFFER);
					} else {
						cmd = (char)result;
						retbuf[0] = 'C';
						retbuf[IDX_DEVICE_RETURN_COMMAND] = cmd;						
						apolloReturnPacket(bev, client, retbuf, LEN_DEVICE_RETURN_BUFFER);
					}
				} else if (result == 0 || result == -1 || result == -2) {
					char retTimeBuf[LEN_DEVICE_RETURN_BUFFER*2+2] = {0};
					strcpy(retTimeBuf, "RETOK");
					writeTimeHeader(retTimeBuf+6);
					apolloReturnPacket(bev, client, retTimeBuf, LEN_DEVICE_RETURN_BUFFER*2+2);			
				} else {
					apollo_printf(" aaa [%s:%d] invaild key \n", __func__, __LINE__);
				}
				break;
			}
			case HDR_HEART_PACKET_PHONE: {
				char u8DeviceInfo[REDIS_COMMAND_LENGTH+4] = {0};
				int length = ApolloProtocolInstance->phoneHeaderPacket_Proc(data, nbytes, u8DeviceInfo+4);
				if (length < 0) {
					apollo_printf(" aaa [%s:%d] invaild key \n", __func__, __LINE__);
					break;
				}
				u8DeviceInfo[0] = 'R';
				u8DeviceInfo[1] = 'E';
				u8DeviceInfo[2] = 'T';
				u8DeviceInfo[3] = ':';

				apolloReturnPacket(bev, client, u8DeviceInfo, length+4);
				break;
			}
			case HDR_COMMAND_PACKET: {
				int length = ApolloProtocolInstance->phoneCommandPacket_Proc(data, nbytes);
				if (length < 0) {
					apollo_printf(" aaa [%s:%d] invaild key \n", __func__, __LINE__);
					break;
				}
				break;
			}
			case HDR_LOCATION_DATA: {
				char retbuf[LEN_DEVICE_RETURN_BUFFER] = {'R', 'E', 'T', 'O', 'K', '%'};
				ApolloProtocolInstance->deviceLocationPacket_Proc(data, nbytes);
				apolloReturnPacket(bev, client, retbuf, LEN_DEVICE_RETURN_BUFFER);	
				break;
			}
			case HDR_INFO_RETURN: {
				break;
			}
			case HDR_ADD_DEVICE: {
				ApolloProtocolInstance->phoneAddDevice_Proc(data, nbytes);
				break;
			}
			case HDR_OPERATOR_USER_INFO: {
				ApolloProtocolInstance->phoneOperatorUserInfo_Proc(bev, client, data, nbytes);
				break;
			}
			case HDR_BASE_STATION_DEVICE: {
				ApolloProtocolInstance->deviceBaseStation_Proc(data, nbytes);
				break;
			}
			case HDR_BLOCK_DATA_RECV: {
				int i = 0;
				int dataLength = data[30] * 256 + (unsigned char)data[31];
				int pktIndex = data[13];
				int pktTotal = data[29];
				char u8DeviceId[LEN_DEVICE_ID*2+1] = {0};
				char u8FileName[LEN_DEVICE_ID*4] = {0};
				char retbuf[LEN_DEVICE_RETURN_BUFFER] = {'S', 'E', 'T', 'O', 'K', '%'};				
				MulticastSynerPacket *pSynPacket = NULL;
				//ApolloProtocolInstance->deviceBlockDataRecvPacket_Proc(client, data, nbytes);

				apollo_printf("pkt_13:%d, pkt_29:%d, pkt_30:%d, pkt_31:%d\n", data[13], data[29], data[30], (unsigned char)data[31]);
				if (((blockIndex + nbytes) == LEN_BLOCK_PACKET) && ((pktIndex + 1) != pktTotal)) {
					apollo_printf(" copy index : %d, dataLength:%d\n", blockIndex, dataLength);
					for (i = 0;i < dataLength;i ++) {
						client->pBlock->buffer[pktIndex * (LEN_BLOCK_PACKET-LEN_HEADER_LENGTH)+i] = data[LEN_HEADER_LENGTH+i];
					}
					memset(data, 0, LEN_BLOCK_PACKET+4);
					client->pBlock->index = 0;
					blockIndex = 0;
					//printf(" aaaa index : %d, dataLength:%d\n", client->pBlock->index, dataLength);
					
				} else {
					blockIndex += nbytes;
					client->pBlock->index = blockIndex;
					apollo_printf(" index:%d\n", blockIndex);					
				}
				//the last packet
				if (((pktIndex + 1) == pktTotal) && (blockIndex >= (dataLength + LEN_HEADER_LENGTH))) {
					for (i = 0;i < dataLength;i ++) {
						client->pBlock->buffer[pktIndex * (LEN_BLOCK_PACKET-LEN_HEADER_LENGTH)+i] = data[LEN_HEADER_LENGTH+i];
					}
					//save data to file
					hextostring(u8DeviceId ,data+IDX_DEVICE_ID, LEN_DEVICE_ID);
					genBlockFilePathName(u8DeviceId, u8FileName);
					write_dat(u8FileName, client->pBlock->buffer, pktIndex * (LEN_BLOCK_PACKET - LEN_HEADER_LENGTH) + dataLength);

					apollo_printf(" save data \n");

					//return data to device
					apolloReturnPacket(bev, client, retbuf, LEN_DEVICE_RETURN_BUFFER);	
					//set redis key

					//multicast
					pSynPacket = (MulticastSynerPacket*)malloc(sizeof(MulticastSynerPacket));
					memset(pSynPacket, 0, sizeof(MulticastSynerPacket));
					memcpy(pSynPacket->u8DeviceId, u8DeviceId, LEN_DEVICE_ID*2);
					pSynPacket->u8DeviceId[LEN_DEVICE_ID*2] = 0x0;
					pSynPacket->u8flag = MULTICAST_TYPE_AGPS;
					StartApolloSynerAction((void*)pSynPacket);
				}
				//printf("bbbb index:%d\n", client->pBlock->index);
				break;
			}
			case HDR_BLOCK_DATA_SEND: {
				ApolloProtocolInstance->deviceBlockDataSendPacket_Proc(bev, client, data, nbytes);
				break;
			}
			default : {
				/*
				for (i = 0;i < nbytes;i ++) {
					apollo_printf(" 0x%x", data[i]);
				}
				apollo_printf("\n");
				*/
			}
		}
			
	}

	return ;
}


void initApolloProtocol(void) {
	ApolloProtocolInstance = (struct ApolloProtocolProcess*)malloc(sizeof(struct ApolloProtocolProcess));
	ApolloProtocolInstance->phoneHeaderPacket_Proc = phoneHeaderPacket;
	ApolloProtocolInstance->deviceHeartPacket_Proc = deviceHeartPacket;
	ApolloProtocolInstance->phoneCommandPacket_Proc = phoneCommandPacket;
	ApolloProtocolInstance->deviceLocationPacket_Proc = deviceLocationPacket;
	ApolloProtocolInstance->deviceBaseStation_Proc = deviceBaseStation;
	ApolloProtocolInstance->phoneAddDevice_Proc = phoneAddDevice;
	ApolloProtocolInstance->phoneOperatorUserInfo_Proc = phoneOperatorUserInfo;
	ApolloProtocolInstance->deviceBlockDataRecvPacket_Proc = deviceBlockDataRecvPacket;
	ApolloProtocolInstance->deviceBlockDataSendPacket_Proc = deviceBlockDataSendPacket;

}
Exemple #7
0
// ------------------------------------------------------------------
//  Bitmaps ans Oled-Display senden
// ------------------------------------------------------------------
void PaintPic(char *Ptr, char column, char row) 
{
unsigned char CharCol_1=0, CharCol_2=0;
unsigned char char_r_y_p12, char_r_y_p34, char_r_y_p56;
unsigned char pz, y,x,z,tmp;
unsigned int pos,bitmode,hoehe,breite;
tmp = column;
pos = 0;

  bitmode = pgm_read_byte(&Ptr[pos++]);
  hoehe = pgm_read_byte(&Ptr[pos++]);
  breite = pgm_read_byte(&Ptr[pos++]);
  if (bitmode==1) 
  {
    for (z=0; z<6; z++) 
    {
      for (x=0; x<42; x++) 
      {
        CharCol_1 = pgm_read_byte(&Ptr[pos++]);
        CharCol_2 = pgm_read_byte(&Ptr[pos++]);
        write_cmd(0x15);
        write_cmd(column+7);
        write_cmd(column+7);
        write_cmd(0x75);
        write_cmd(8*row);
        write_cmd(8*row+7);

        pz = 1;                                                  //pixelzeile
        for (y=0; y<8; y++) 
        {
          char_r_y_p12 = char_r_y_p34 = char_r_y_p56 = 0;
          if (CharCol_1 & pz) { char_r_y_p12 |= 0xF0; }
          if (CharCol_2 & pz) { char_r_y_p12 |= 0x0F; }
          write_dat(char_r_y_p12);
          pz = pz << 1;
        }
        column++;
      } // for < 42
      column=tmp;
      row++;
    } // z 10 Zeilen
  }
  else                       // bitmode: 4
  {
    pos = (hoehe * breite)/2-1+3;
    for (z=0; z<hoehe; z++)  // Zeilen
    {
      write_cmd(0x15);       // Spalte
      write_cmd(0+7);
      write_cmd((breite/2-1)+7);
      write_cmd(0x75);       // Reihe
      write_cmd(z);
      write_cmd(z);
      for (y=0; y<(breite/2); y++)
      {
        tmp = pgm_read_byte(&Ptr[pos--]);
        x = tmp>>4;
        tmp = tmp<<4;
        tmp = tmp+x;
        write_dat(tmp);     
      }
    }
  }
}