prog.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. //Include Header-----------------------------------------------------
  2. #include"prog.h"
  3. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  4. //Main-Program
  5. int main(int argc, const char * argv[]){
  6. delay(1000); //delete me!!
  7. //initializing USART at USB_PORT-------------------------------------
  8. int USB = open("/dev/ttyACM3", O_RDWR|O_NOCTTY);
  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] = 2; //set min Characters
  20. // (*termios_ptr).c_cc[VTIME] = 0.1; //Timeout after 10ms
  21. cfsetspeed(termios_ptr, B19200); //set Baudrate 19.2k
  22. tcsetattr(USB, TCSANOW ,termios_ptr);
  23. //Get Command--------------------------------------------------------
  24. char * frame_ptr = cmd_build(page_read, page_size);
  25. for(int i=0; i<3; i++, frame_ptr++){
  26. write(USB, frame_ptr, sizeof(char));
  27. printf("%d \n", *frame_ptr);
  28. }
  29. char cmd_check = 0;
  30. frame_ptr = &cmd_arr[0];
  31. while(cmd_check < 3){
  32. read(USB, frame_ptr, sizeof(char));
  33. printf("Return: %d \n", *frame_ptr);
  34. if(*frame_ptr == page_size){
  35. cmd_check++;
  36. }
  37. }
  38. printf("Read Acknoledged \n");
  39. char * page_ptr = page_build();
  40. for(int i=0; i<70; i++){
  41. write(USB, page_ptr, sizeof(char));
  42. }
  43. frame_ptr = &cmd_arr[0];
  44. for(int i=0; i<3; i++, frame_ptr++){
  45. read(USB, frame_ptr, sizeof(char));
  46. printf("Return: %d \n", *frame_ptr);
  47. }
  48. close(USB);
  49. return EXIT_SUCCESS;
  50. }
  51. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  52. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++