Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- #include <stdlib.h>
- #include <fstream>
- #include <string.h>
- using namespace std;
- void gravaComando(char a, char b, fstream &out, string line)
- {
- if(line=="An;"){out<<a<<b<<"0"<<endl;cout<<a<<b<<"0"<<endl;}
- if(line=="nAoB;"){out<<a<<b<<"1"<<endl;cout<<a<<b<<"1"<<endl;}
- if(line=="AnB;"){out<<a<<b<<"2"<<endl;cout<<a<<b<<"2"<<endl;}
- if(line=="zeroL;"){out<<a<<b<<"3"<<endl;cout<<a<<b<<"3"<<endl;}
- if(line=="nAeB;"){out<<a<<b<<"4"<<endl;cout<<a<<b<<"4"<<endl;}
- if(line=="Bn;"){out<<a<<b<<"5"<<endl;cout<<a<<b<<"5"<<endl;}
- if(line=="AxB;"){out<<a<<b<<"6"<<endl;cout<<a<<b<<"6"<<endl;}
- if(line=="ABn;"){out<<a<<b<<"7"<<endl;cout<<a<<b<<"7"<<endl;}
- if(line=="AnoB;"){out<<a<<b<<"8"<<endl;cout<<a<<b<<"8"<<endl;}
- if(line=="nAxB;"){out<<a<<b<<"9"<<endl;cout<<a<<b<<"9"<<endl;}
- if(line=="B;"){out<<a<<b<<"a"<<endl;cout<<a<<b<<"a"<<endl;}
- if(line=="AB;"){out<<a<<b<<"b"<<endl;cout<<a<<b<<"b"<<endl;}
- if(line=="umL;"){out<<a<<b<<"c"<<endl;cout<<a<<b<<"c"<<endl;}
- if(line=="AoBn;"){out<<a<<b<<"d"<<endl;cout<<a<<b<<"d"<<endl;}
- if(line=="AoB;"){out<<a<<b<<"e"<<endl;cout<<a<<b<<"e"<<endl;}
- if(line=="A;"){out<<a<<b<<"f"<<endl;cout<<a<<b<<"f"<<endl;}
- }
- bool foundInObjStr(string tofind, char pattern[],size_t &posfind)
- {
- size_t match;
- match=tofind.find(pattern);
- if(match==tofind.npos){return false;}
- else{posfind=match;return true;}
- }
- int main()
- {
- size_t foundPos;
- string line;
- fstream arqIn, arqOut;
- arqIn.open("74181.alu",ios::in|ios::binary);
- arqOut.open("74181.hex",ios::out|ios::binary);
- if(arqIn.is_open() && arqOut.is_open())
- {
- cout<<"geracao do arquivo compilado:"<<endl<<"Inicio: "<<endl;
- do
- {
- //verify if the line is an instruction, if it is, burn in arqOut
- arqIn>>line;
- char a,b;
- if(!foundInObjStr(line,"=",foundPos))
- {
- gravaComando(a,b,arqOut,line);
- }
- //if it is not, it is an attribution,so it does it
- else
- {
- if(line[0]=='A'){a=line[line.length()-2];}
- if(line[0]=='B'){b=line[line.length()-2];}
- }
- }while(!arqIn.eof());
- arqIn.close();
- arqOut.close();
- cout<<"Sucesso ao ler codigo fonte e criar arquivo compilado"<<endl;
- }
- else
- {
- if(!arqIn.is_open()){cout<<"Falha ao ler codigo fonte - verifique as permissoes de leitura em seu S.O."<<endl; return 1;}
- if(!arqOut.is_open()){cout<<"Falha ao gerar arquivo compilado - verifique as permissoes de escrita em seu S.O."<<endl; return 2;}
- }
- //execute the .hex in arduino
- cout<<"Transmissao das instrucoes ao arduino"<<endl;
- arqOut.open("74181.hex",ios::in);
- if(!arqOut.is_open()){cout<<"Falha ao ler codigo fonte - verifique as permissoes de leitura em seu S.O."<<endl; return 1;}
- else
- {
- string comport;
- cout<<"Informe a porta COM:";
- cin.ignore();
- getline(cin,comport);
- while(!arqOut.eof())
- {
- switch('\n')
- {
- line.clear();
- arqOut>>line;
- //char args[4];
- //strcpy(args,line.c_str());
- string comando;
- comando="envia "+comport+" "+line[0]+" "+line[1]+" "+line[2];
- //comando+=args[0];
- //comando+=" ";
- //comando+=args[1];
- //comando+=" ";
- //comando+=args[2];
- system(comando.c_str());
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement