Skip to content
Snippets Groups Projects
Commit 68c188e9 authored by Vytor Calixto's avatar Vytor Calixto :space_invader:
Browse files

Merge branch 'develop' of vsbc14/Caco into develop

parents 4e1f9996 8efd0f7b
Branches
No related tags found
1 merge request!1Lento
...@@ -79,12 +79,10 @@ string Message::getDataAsString() { ...@@ -79,12 +79,10 @@ string Message::getDataAsString() {
ostream& operator<<(ostream& os, const Message& msg){ ostream& operator<<(ostream& os, const Message& msg){
os << '|' << msg.begin << '|' << msg.size << '|' << msg.sequence << '|' << msg.type << '|'; os << '|' << msg.begin << '|' << msg.size << '|' << msg.sequence << '|' << msg.type << '|';
// os << msg.begin << msg.size << msg.sequence << msg.type;
for(int i=0; i<msg.data.size(); ++i){ for(int i=0; i<msg.data.size(); ++i){
os << bitset<8>(msg.data[i]); os << bitset<8>(msg.data[i]);
} }
os << '|' << msg.parity << '|'; os << '|' << msg.parity << '|';
// os << msg.parity;
return os; return os;
} }
......
...@@ -37,7 +37,7 @@ int main(){ ...@@ -37,7 +37,7 @@ int main(){
receiveProtocol.reset(); receiveProtocol.reset();
receiveProtocol.receive(sockt,SIZE,WAIT_STOP,false); receiveProtocol.receive(sockt,SIZE,WAIT_STOP,false);
cout << "fileSize: " << receiveProtocol.getDataAsString() <<endl; cout << "fileSize: " << receiveProtocol.getDataAsString() <<endl;
int fileSize = stoi(receiveProtocol.getDataAsString()); unsigned long long fileSize = stoi(receiveProtocol.getDataAsString());
sendProtocol.reset(); sendProtocol.reset();
if(hasEnoughSpace(fileSize)){ if(hasEnoughSpace(fileSize)){
sendProtocol.setData(vector<BYTE>(1,(BYTE)0), OK); sendProtocol.setData(vector<BYTE>(1,(BYTE)0), OK);
...@@ -45,6 +45,7 @@ int main(){ ...@@ -45,6 +45,7 @@ int main(){
}else{ }else{
sendProtocol.setData(vector<BYTE>(1,(BYTE)SPACE_ERR), ERROR); sendProtocol.setData(vector<BYTE>(1,(BYTE)SPACE_ERR), ERROR);
sendProtocol.sendMessage(sockt,0); sendProtocol.sendMessage(sockt,0);
continue;
} }
receiveProtocol.reset(); receiveProtocol.reset();
receiveProtocol.receive(sockt,DATA,SLIDING,true); receiveProtocol.receive(sockt,DATA,SLIDING,true);
...@@ -52,12 +53,34 @@ int main(){ ...@@ -52,12 +53,34 @@ int main(){
writeFile(getWorkingPath()+"/"+fileName,receiveProtocol.getData()); writeFile(getWorkingPath()+"/"+fileName,receiveProtocol.getData());
}else if(status == GET){ }else if(status == GET){
//TODO string filePath = getWorkingPath()+"/"+receiveProtocol.getDataAsString();
if(fexists(filePath)) {
string size = to_string(filesize(filePath));
cout << "ARQUIVO: " << filePath << "|" << size << endl;
sendProtocol.setData(vector<BYTE>(size.begin(), size.end()), SIZE);
sendProtocol.sendMessage(sockt, 0);
int error = receiveProtocol.receive(sockt, OK, WAIT_STOP, false);
if(error < 0) continue;
sendProtocol.reset();
ifstream putFile (filePath);
stringstream buffer;
buffer << putFile.rdbuf();
string data = buffer.str();
sendProtocol.setData(vector<BYTE>(data.begin(), data.end()), DATA);
sendProtocol.transmit(sockt, SLIDING);
} else {
sendProtocol.setData(vector<BYTE>(1,(BYTE)DIR_ERR), ERROR);
sendProtocol.sendMessage(sockt,0);
continue;
}
}else if(status == ENDTX){ }else if(status == ENDTX){
sendProtocol.reset(); sendProtocol.reset();
vector<BYTE> val(1,(BYTE)receiveProtocol.getMessages().back().sequence.to_ulong()); vector<BYTE> val(1,(BYTE)receiveProtocol.getMessages().back().sequence.to_ulong());
sendProtocol.setData(val, ACK); sendProtocol.setData(val, ACK);
sendProtocol.sendMessages(sockt); sendProtocol.sendMessages(sockt);
}else if(status < 0 && status != NOISE){
sendProtocol.setData(vector<BYTE>(1,(BYTE)NACK), ERROR);
sendProtocol.sendMessage(sockt,0);
} }
}catch(char const* strException){ }catch(char const* strException){
cout << "Erro:" <<strException <<endl; cout << "Erro:" <<strException <<endl;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment