Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <stddef.h>
- #include <time.h>
- #include <iostream>
- #include <termios.h>
- #include <fcntl.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <string.h>
- #include <ctype.h>
- #include <math.h>
- #include <limits.h>
- #include "Payload.h"
- #define SLOTS "/sys/devices/bone_capemgr.9/slots"
- #define CR 0x0d
- #define SPACE 0x20
- #define COMMA 0x2C
- #define MAXSIZE 100
- unsigned long time_data;
- unsigned int button = 45;
- int i,z =0, j=0, value;
- int rx_length;
- int main()
- {
- //uart4 configuration using termios
- int fd;
- //unsigned char *mess;
- unsigned int value = 0;
- gpio_export(button);
- //Wait until the button is pushed
- while (value != 1){
- if (z==0){
- printf("waitingn");}
- z++;
- gpio_get_value(button, &value);}
- //OPEN THE UART
- //open uart4 for tx/rx, not controlling device
- if((fd = open("/dev/ttyO4", O_RDONLY | O_NOCTTY|O_NONBLOCK)) < 0){
- printf("Unable to open uart4 access.n");
- }
- termios uart4;
- cfsetospeed(&uart4, B9600); //Set the speed
- //set attributes of uart4
- uart4.c_iflag = 0;
- uart4.c_oflag = 0;
- uart4.c_lflag = 0;
- tcsetattr(fd, TCSANOW, &uart4);
- //----- CHECK FOR ANY RX BYTES -----
- // Read up to 100 characters from the port if they are there
- unsigned char stringRead[MAXSIZE];
- unsigned char charRead;
- do{
- if (rx_length = read(fd, (void*)charRead, MAXSIZE)>0){
- if (charRead =='$'){
- i=0;
- stringRead[i] = charRead; //Store in the first position of the char --> $
- do {
- rx_length = read(fd, (void*)charRead, MAXSIZE); //Read the next bit
- if( (charRead != '