Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.82 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <fcntl.h>
  3. #include <termios.h>
  4. #include <unistd.h>
  5. #include <string.h>
  6.  
  7. void base64Convert(){
  8.     FILE *r,*w;
  9.     unsigned char a,b,c,temp,chek[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  10.     r = fopen("out.txt","rb");
  11.     w = fopen("in.txt","wb");
  12.     temp='!';
  13.     fprintf(w,"%c",temp);
  14.     while(1){
  15.         fscanf(r,"%c",&a);
  16.         if(feof(r))break;
  17.         temp = a>>2;
  18.         temp = chek[temp];
  19.         fprintf(w,"%c",temp);
  20.  
  21.         fscanf(r,"%c",&b);
  22.         if(feof(r)){
  23.             temp = ((1<<6)-1) & a<<4;
  24.             temp = chek[temp];
  25.             fprintf(w,"%c",temp);
  26.             temp = '=';
  27.             fprintf(w,"%c",temp);
  28.             fprintf(w,"%c",temp);
  29.             break;
  30.         }
  31.         temp = ((1<<6)-1) & (a<<4 | b>>4);
  32.         temp = chek[temp];
  33.         fprintf(w,"%c",temp);
  34.  
  35.         fscanf(r,"%c",&c);
  36.         if(feof(r)){
  37.             temp = ((1<<6)-1) & b<<2;
  38.             temp = chek[temp];
  39.             fprintf(w,"%c",temp);
  40.             temp = '=';
  41.             fprintf(w,"%c",temp);
  42.             break;
  43.         }
  44.         temp = ((1<<6)-1) & (c>>6 | b<<2);
  45.         temp = chek[temp];
  46.         fprintf(w,"%c",temp);
  47.         temp = ((1<<6)-1) & c;
  48.         temp = chek[temp];
  49.         fprintf(w,"%c",temp);
  50.     }
  51.     temp='#';
  52.     fprintf(w,"%c",temp);
  53.     fclose(r);
  54.     fclose(w);
  55. }
  56.  
  57. int main(){
  58.     char buffer[256] = "" ;
  59.     base64Convert();
  60.     int port = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY) ;
  61.     if (port == -1){
  62.         perror("open_port: Unable to open /dev/ttyS0 - ");
  63.         return 0;
  64.     }else
  65.         fcntl(port, F_SETFL, 0);
  66.    
  67.     //Write is here
  68.     FILE *rFile=fopen("in.txt","rb");
  69.     while((buffer[0]=fgetc(rFile))!=EOF) {
  70.         if(buffer[0]==10) buffer[0]='\r';
  71.         //putchar(buffer[0]);
  72.         write(port,buffer,1);
  73.     }
  74.     fclose(rFile) ;
  75.     close(port) ;
  76.  
  77.  
  78.  
  79.     port = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY) ;
  80.     if (port == -1){
  81.         perror("open_port: Unable to open /dev/ttyS0 - ");
  82.         return 0;
  83.     }else
  84.         fcntl(port, F_SETFL, 0);
  85.     write(port,"###",3);
  86.     close(port) ;
  87.  
  88.     return 0 ;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement