prog.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. //Include Header-----------------------------------------------------
  2. #include"prog.h"
  3. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  4. //Main-Program
  5. int main(int argc, const char * argv[]){
  6. delay(100); //delete me!!
  7. //initializing USART at USB_PORT-------------------------------------
  8. int USB = open("/dev/ttyACM3", O_RDWR|O_NOCTTY|O_NONBLOCK);
  9. if(isatty(USB)==0){
  10. printf("ERROR: No File Descriptor! \n");
  11. return 0;
  12. }
  13. struct termios * termios_ptr = (struct termios *)
  14. malloc(sizeof(struct termios));
  15. (*termios_ptr).c_iflag = IGNPAR; //ignore Parity-Err
  16. (*termios_ptr).c_oflag = 0;
  17. (*termios_ptr).c_cflag = CS8|CREAD; //set Size, enable RX
  18. (*termios_ptr).c_lflag = 0;
  19. (*termios_ptr).c_cc[VMIN] = 0; //set min Characters
  20. // (*termios_ptr).c_cc[VTIME] = 0.01; //Timeout after 1ms
  21. cfsetspeed(termios_ptr, B19200); //set Baudrate 19.2k
  22. tcsetattr(USB, TCSANOW ,termios_ptr);
  23. //Get Command--------------------------------------------------------
  24. char cmd_check = 0;
  25. char * frame_ptr;
  26. char * data_ptr = (char *)malloc(3*sizeof(char));
  27. frame_ptr = cmd_build(page_read, page_size);
  28. write(USB, frame_ptr, 3*sizeof(char));
  29. while(cmd_check<3){
  30. read(USB, data_ptr, sizeof(char));
  31. tcflush(USB, TCIFLUSH);
  32. // printf("%d \n", *data_ptr);
  33. if(*data_ptr==page_size){
  34. cmd_check++;
  35. }
  36. }
  37. printf("Read Acknoledgement \n");
  38. cmd_check = 0;
  39. char * page_ptr = page_build(page_size+2);
  40. write(USB, page_ptr, (page_size+2)*sizeof(char));
  41. while(cmd_check<3){
  42. read(USB, data_ptr, sizeof(char));
  43. tcflush(USB, TCIFLUSH);
  44. printf("%d \n", *data_ptr);
  45. if(*data_ptr==frame_mask){
  46. cmd_check++;
  47. }
  48. }
  49. printf("Page Read Complete \n");
  50. close(USB);
  51. return EXIT_SUCCESS;
  52. }
  53. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  54. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++