Jump to content
  • Revista PROGRAMAR: Já está disponível a edição #60 da revista programar. Faz já o download aqui!

Sign in to follow this  

programa que nao consegue ler

Recommended Posts


int main (int argc, const char * argv[]) 
 int n;
 unsigned ch = 0;
 unsigned char buf[128*1024];

 int res;
 struct timeval Timeout;
 int loop = 1;

 fd_set readfs;

// just in case of make eay stuff - wrong --> char dir = "/b1firmware.b1b";
     printf("Started out app\n");
 for (n=0; n<1; n++)
	 // open file to send
	 int fd  = open("/b1firmware.b1b",O_RDONLY );    
    if( fd < 0) 
	  printf("Can't open the file\n");       
		  unsigned char chFileHeader[64];
		  printf("ficheiro aberto \n");
		  lseek(fd, 0, SEEK_SET);
		  if(read(fd, chFileHeader, sizeof(chFileHeader)) == sizeof(chFileHeader))
			  int iBytesRead =
			  read(fd, buf, sizeof(buf));
			  printf("read %d bytes into buf\n",iBytesRead);
			  // validate CRC
			  unsigned char ourcrc[4];
			  // verfic if file ok no curropt
			  for (int n= 0; n < iBytesRead; n++) 
				  ourcrc[n % 4] ^= buf[n];
			  if(memcmp(ourcrc, chFileHeader+0x3c,4) == 0)
				  printf("file is ok.\n");

				  // got some data...

				  // fd = open("/dev/tty.usbserial-A6007bC3", O_RDONLY);

				  Timeout.tv_usec = 0;  /* milliseconds */
				  Timeout.tv_sec  = 1;  /* seconds */
				   FD_SET(fd, &readfs); 
				  while (loop) 
					  /* set testing for source 1 */
					/* block until input becomes available */
					  res = select(fd, &readfs, NULL, NULL, &Timeout);
					   if ( res == 0) 
						   loop = 0;

está no tempo defenido e após acabar o tempo sai fora tudo bem

o problema é que nunca consigo receber o sinal do aparelho

alguma ideia?

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  


Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.