Advertisement
Guest User

Untitled

a guest
Nov 21st, 2014
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stddef.h>
  4. #include <time.h>
  5. #include <iostream>
  6. #include <termios.h>
  7. #include <fcntl.h>
  8. #include <unistd.h>
  9. #include <sys/types.h>
  10. #include <string.h>
  11. #include <ctype.h>
  12. #include <math.h>
  13. #include <limits.h>
  14. #include "Payload.h"
  15.  
  16.  
  17. #define SLOTS "/sys/devices/bone_capemgr.9/slots"
  18. #define CR 0x0d
  19. #define SPACE 0x20
  20. #define COMMA 0x2C
  21. #define MAXSIZE 100
  22. unsigned long time_data;
  23. unsigned int button = 45;
  24. int i,z =0, j=0, value;
  25. int rx_length;
  26.  
  27.  
  28. int main()
  29. {
  30. //uart4 configuration using termios
  31.  
  32. int fd;
  33. //unsigned char *mess;
  34. unsigned int value = 0;
  35.  
  36. gpio_export(button);
  37.  
  38. //Wait until the button is pushed
  39. while (value != 1){
  40. if (z==0){
  41. printf("waitingn");}
  42. z++;
  43. gpio_get_value(button, &value);}
  44.  
  45.  
  46.  
  47. //OPEN THE UART
  48. //open uart4 for tx/rx, not controlling device
  49.  
  50. if((fd = open("/dev/ttyO4", O_RDONLY | O_NOCTTY|O_NONBLOCK)) < 0){
  51. printf("Unable to open uart4 access.n");
  52. }
  53. termios uart4;
  54. cfsetospeed(&uart4, B9600); //Set the speed
  55.  
  56. //set attributes of uart4
  57. uart4.c_iflag = 0;
  58. uart4.c_oflag = 0;
  59. uart4.c_lflag = 0;
  60. tcsetattr(fd, TCSANOW, &uart4);
  61.  
  62.  
  63.  
  64.  
  65. //----- CHECK FOR ANY RX BYTES -----
  66. // Read up to 100 characters from the port if they are there
  67.  
  68. unsigned char stringRead[MAXSIZE];
  69. unsigned char charRead;
  70.  
  71.  
  72. do{
  73.  
  74. if (rx_length = read(fd, (void*)charRead, MAXSIZE)>0){
  75.  
  76. if (charRead =='$'){
  77. i=0;
  78. stringRead[i] = charRead; //Store in the first position of the char --> $
  79. do {
  80. rx_length = read(fd, (void*)charRead, MAXSIZE); //Read the next bit
  81. if( (charRead != '') ) {
  82. i++;
  83. stringRead[i] = charRead; //write into stringRead
  84. }
  85. } while(charRead != 'CR'); //ASCII Carriage Return
  86. stringRead[i+1] = charRead;
  87. printf("%s", stringRead);
  88. }}
  89. if (rx_length==0){
  90. //No data
  91. }
  92.  
  93. gpio_get_value(button, &value);
  94.  
  95. }while (value!=0);
  96.  
  97. gpio_unexport(button);
  98.  
  99. close(fd);
  100. return 0;
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement