|
|
@@ -1,109 +0,0 @@
|
|
|
-//Define Constants---------------------------------------------------
|
|
|
-typedef enum {false, true} bool;
|
|
|
-
|
|
|
-//Include Header Files-----------------------------------------------
|
|
|
-#include<stdlib.h>
|
|
|
-#include<stdio.h>
|
|
|
-#include<time.h>
|
|
|
-#include<errno.h>
|
|
|
-#include<unistd.h>
|
|
|
-#include<termios.h>
|
|
|
-#include<sys/types.h>
|
|
|
-#include<sys/stat.h>
|
|
|
-#include<fcntl.h>
|
|
|
-#include<sys/resource.h>
|
|
|
-
|
|
|
-//Prototypes---------------------------------------------------------
|
|
|
-int delay(int delay_time);
|
|
|
-void print_attrTermios(struct termios * ptr_attr);
|
|
|
-
|
|
|
-//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
-//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
-//Main-Program
|
|
|
-int main(int argc, const char * argv[]){
|
|
|
-
|
|
|
-//initializing USART at USB_PORT-------------------------------------
|
|
|
- int USB = open("/dev/ttyACM3", O_RDWR|O_NOCTTY);
|
|
|
- if(isatty(USB)==0){
|
|
|
- printf("ERROR: No File Descriptor! \n");
|
|
|
- return 0;
|
|
|
- }
|
|
|
- struct termios * ptr_attr = (struct termios *)
|
|
|
- malloc(sizeof(struct termios));
|
|
|
- if(ptr_attr==NULL){
|
|
|
- printf("ERROR: Termios not available! \n");
|
|
|
- return 0;
|
|
|
- }
|
|
|
- tcgetattr(USB, ptr_attr);
|
|
|
- (*ptr_attr).c_iflag = IGNPAR;
|
|
|
- (*ptr_attr).c_oflag = 0;
|
|
|
- (*ptr_attr).c_cflag = CS8|CREAD;
|
|
|
- (*ptr_attr).c_lflag = 0;
|
|
|
- cfsetspeed(ptr_attr, B19200);
|
|
|
- tcsetattr(USB, TCSANOW ,ptr_attr);
|
|
|
-
|
|
|
- char req[] = {'R', 'E', 'Q'};
|
|
|
- char ack[] = {'A', 'C', 'K'};
|
|
|
- char input[3];
|
|
|
- char page[] = "PAGE";
|
|
|
- char * ptr_req = &req[0];
|
|
|
- char * ptr_ack = &ack[0];
|
|
|
- char * ptr_input = &input[0];
|
|
|
- char * ptr_page = &page[0];
|
|
|
- int connection;
|
|
|
- delay(1000);
|
|
|
-
|
|
|
-//Establishing Connection-------------------------------------------
|
|
|
- write(USB, ptr_req, sizeof(req));
|
|
|
- tcflush(USB, TCIFLUSH);
|
|
|
- read(USB, ptr_input, sizeof(input));
|
|
|
- tcflush(USB, TCOFLUSH);
|
|
|
- ptr_input = &input[0];
|
|
|
- for(int i=0; i<3; i++){
|
|
|
- connection = false;
|
|
|
- if(input[i]!=ack[i]){
|
|
|
- break;
|
|
|
- }
|
|
|
- connection = true;
|
|
|
- }
|
|
|
- if(connection==true){
|
|
|
- printf("Connection Success! \n");
|
|
|
- }
|
|
|
- else{
|
|
|
- printf("Connection Failed! \n");
|
|
|
- }
|
|
|
-
|
|
|
-//Sending Page-------------------------------------------------------
|
|
|
- for(int i=0; i<64; i++){
|
|
|
- write(USB, ptr_page, sizeof(char));
|
|
|
- tcflush(USB, TCIFLUSH);
|
|
|
- ptr_page++;
|
|
|
- if(ptr_page> & page[3]){
|
|
|
- ptr_page = &page[0];
|
|
|
- }
|
|
|
- }
|
|
|
- printf("Page send! \n");
|
|
|
- close(USB);
|
|
|
- return EXIT_SUCCESS;
|
|
|
-}
|
|
|
-//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
-//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
-
|
|
|
-
|
|
|
-//Delay-Function-----------------------------------------------------
|
|
|
-int delay(int delay_time){
|
|
|
- clock_t time1 = clock();
|
|
|
- while(((clock()-time1)/CLOCKS_PER_SEC)*1000
|
|
|
- != (clock_t)delay_time);
|
|
|
- return 1;
|
|
|
-}
|
|
|
-
|
|
|
-//Print Termios-Attributes-------------------------------------------
|
|
|
-void print_attrTermios(struct termios * ptr_attr){
|
|
|
- printf("Input Mode Flag: %d \n", (*ptr_attr).c_iflag);
|
|
|
- printf("Output Mode Flag: %d \n", (*ptr_attr).c_oflag);
|
|
|
- printf("Control Mode Flag: %d \n", (*ptr_attr).c_cflag);
|
|
|
- printf("Local Mode Flag: %d \n", (*ptr_attr).c_lflag);
|
|
|
- printf("Baudrate Input: %d \n", (*ptr_attr).c_ispeed);
|
|
|
- printf("Baudrate Output: %d \n", (*ptr_attr).c_ospeed);
|
|
|
-}
|