|
|
@@ -1,6 +1,5 @@
|
|
|
//Define Constants---------------------------------------------------
|
|
|
-#define USB_PORT /dev/ttyACM3
|
|
|
-#define PAGESIZE 64
|
|
|
+typedef enum {false, true} bool;
|
|
|
|
|
|
//Include Header Files-----------------------------------------------
|
|
|
#include<stdlib.h>
|
|
|
@@ -15,7 +14,7 @@
|
|
|
#include<sys/resource.h>
|
|
|
|
|
|
//Prototypes---------------------------------------------------------
|
|
|
-void delay(int delay_time);
|
|
|
+int delay(int delay_time);
|
|
|
void print_attrTermios(struct termios * ptr_attr);
|
|
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
@@ -32,7 +31,7 @@ int main(int argc, const char * argv[]){
|
|
|
struct termios * ptr_attr = (struct termios *)
|
|
|
malloc(sizeof(struct termios));
|
|
|
if(ptr_attr==NULL){
|
|
|
- printf("ERROR: Termios not available \n");
|
|
|
+ printf("ERROR: Termios not available! \n");
|
|
|
return 0;
|
|
|
}
|
|
|
tcgetattr(USB, ptr_attr);
|
|
|
@@ -42,22 +41,48 @@ int main(int argc, const char * argv[]){
|
|
|
(*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-------------------------------------------
|
|
|
- char req[] = "REQ";
|
|
|
- char ack[] = "ACK";
|
|
|
- char * ptr_ack = &ack[0];
|
|
|
- char * ptr_input = (char *)malloc(3*sizeof(char));
|
|
|
- char * ptr_req = &req[0];
|
|
|
- while(1){
|
|
|
- write(USB, ptr_req, 3*sizeof(char));
|
|
|
-// tcflush(USB, TCIFLUSH);
|
|
|
- read(USB, ptr_input, 3*sizeof(char));
|
|
|
-// tcflush(USB, TCOFLUSH);
|
|
|
- printf("%s \n", &ptr_input[0]);
|
|
|
+ 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;
|
|
|
}
|
|
|
- //delay(100);
|
|
|
+ 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;
|
|
|
}
|
|
|
@@ -66,10 +91,11 @@ int main(int argc, const char * argv[]){
|
|
|
|
|
|
|
|
|
//Delay-Function-----------------------------------------------------
|
|
|
-void delay(int delay_time){
|
|
|
+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-------------------------------------------
|