Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <fcntl.h>
- #include <termios.h>
- #include <unistd.h>
- #include <string.h>
- void base64Convert(){
- FILE *r,*w;
- unsigned char a,b,c,temp,chek[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
- r = fopen("out.txt","rb");
- w = fopen("in.txt","wb");
- temp='!';
- fprintf(w,"%c",temp);
- while(1){
- fscanf(r,"%c",&a);
- if(feof(r))break;
- temp = a>>2;
- temp = chek[temp];
- fprintf(w,"%c",temp);
- fscanf(r,"%c",&b);
- if(feof(r)){
- temp = ((1<<6)-1) & a<<4;
- temp = chek[temp];
- fprintf(w,"%c",temp);
- temp = '=';
- fprintf(w,"%c",temp);
- fprintf(w,"%c",temp);
- break;
- }
- temp = ((1<<6)-1) & (a<<4 | b>>4);
- temp = chek[temp];
- fprintf(w,"%c",temp);
- fscanf(r,"%c",&c);
- if(feof(r)){
- temp = ((1<<6)-1) & b<<2;
- temp = chek[temp];
- fprintf(w,"%c",temp);
- temp = '=';
- fprintf(w,"%c",temp);
- break;
- }
- temp = ((1<<6)-1) & (c>>6 | b<<2);
- temp = chek[temp];
- fprintf(w,"%c",temp);
- temp = ((1<<6)-1) & c;
- temp = chek[temp];
- fprintf(w,"%c",temp);
- }
- temp='#';
- fprintf(w,"%c",temp);
- fclose(r);
- fclose(w);
- }
- int main(){
- char buffer[256] = "" ;
- base64Convert();
- int port = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY) ;
- if (port == -1){
- perror("open_port: Unable to open /dev/ttyS0 - ");
- return 0;
- }else
- fcntl(port, F_SETFL, 0);
- //Write is here
- FILE *rFile=fopen("in.txt","rb");
- while((buffer[0]=fgetc(rFile))!=EOF) {
- if(buffer[0]==10) buffer[0]='\r';
- //putchar(buffer[0]);
- write(port,buffer,1);
- }
- fclose(rFile) ;
- close(port) ;
- port = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY) ;
- if (port == -1){
- perror("open_port: Unable to open /dev/ttyS0 - ");
- return 0;
- }else
- fcntl(port, F_SETFL, 0);
- write(port,"###",3);
- close(port) ;
- return 0 ;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement