Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Caco
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Vytor Calixto
Caco
Commits
4c63b7b0
Commit
4c63b7b0
authored
Dec 4, 2015
by
Israel Barreto Sant'Anna
Browse files
Options
Downloads
Patches
Plain Diff
Message now being sent, but have wrong values
Signed-off-by:
Israel Barreto Sant'Anna
<
ibsa14@inf.ufpr.br
>
parent
cc28a42f
No related branches found
No related tags found
1 merge request
!1
Lento
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
Message.cpp
+18
-1
18 additions, 1 deletion
Message.cpp
Message.h
+1
-0
1 addition, 0 deletions
Message.h
Protocol.cpp
+32
-13
32 additions, 13 deletions
Protocol.cpp
client.cpp
+1
-3
1 addition, 3 deletions
client.cpp
definitions.h
+3
-3
3 additions, 3 deletions
definitions.h
with
55 additions
and
20 deletions
Message.cpp
+
18
−
1
View file @
4c63b7b0
#include
"Message.h"
#include
<bitset>
#include
"definitions.h"
BYTE
Message
::
calcParity
()
{
...
...
@@ -16,6 +17,22 @@ bool Message::checkParity() {
return
(
parity
==
this
->
header
.
c_ctrl
.
parity
);
}
vector
<
int
>
Message
::
getBitFieldsAsInt
(){
vector
<
int
>
bits
;
// bitset<8> begin(messages[i].header.i_ctrl.begin);
// bitset<6> size(messages[i].header.i_ctrl.size);
// bitset<6> sequence(messages[i].header.i_ctrl.sequence);
// bitset<4> type(messages[i].header.i_ctrl.type);
// bitset<8> parity(messages[i].header.i_ctrl.parity);
bits
.
push_back
((
int
)
bitset
<
8
>
(
header
.
i_ctrl
.
begin
).
to_ulong
());
bits
.
push_back
((
int
)
bitset
<
6
>
(
header
.
i_ctrl
.
size
).
to_ulong
());
bits
.
push_back
((
int
)
bitset
<
6
>
(
header
.
i_ctrl
.
sequence
).
to_ulong
());
bits
.
push_back
((
int
)
bitset
<
4
>
(
header
.
i_ctrl
.
type
).
to_ulong
());
bits
.
push_back
((
int
)
bitset
<
8
>
(
header
.
i_ctrl
.
parity
).
to_ulong
());
return
bits
;
}
string
Message
::
getSendData
()
{
calcParity
();
string
s
(
data
.
begin
(),
data
.
end
());
...
...
@@ -39,5 +56,5 @@ string Message::getSendData() {
}
Message
::
Message
()
{
this
->
header
.
c
_ctrl
.
begin
=
BEGIN
;
this
->
header
.
i
_ctrl
.
begin
=
BEGIN
;
}
This diff is collapsed.
Click to expand it.
Message.h
+
1
−
0
View file @
4c63b7b0
...
...
@@ -10,6 +10,7 @@ public:
BYTE
calcParity
();
bool
checkParity
();
string
getSendData
();
vector
<
int
>
getBitFieldsAsInt
();
Message
();
};
...
...
This diff is collapsed.
Click to expand it.
Protocol.cpp
+
32
−
13
View file @
4c63b7b0
#include
<sys/socket.h>
#include
<bitset>
#include
"Protocol.h"
#include
"definitions.h"
...
...
@@ -11,9 +12,23 @@ void Protocol::setMessages(vector<Message> messages){
}
bool
Protocol
::
sendMessages
(
int
socket
,
int
window
)
{
//FIXME: seqType char is wrong, could be because of how sequence is being set
for
(
int
i
=
0
;
i
<
messages
.
size
();
++
i
)
{
string
data
=
messages
[
i
].
getSendData
();
send
(
socket
,
data
.
c_str
(),
messages
[
i
].
header
.
i_ctrl
.
size
,
0
);
vector
<
BYTE
>
msg
;
msg
.
push_back
(
messages
[
i
].
header
.
c_ctrl
.
begin
);
cout
<<
"vector begin: "
<<
bitset
<
8
>
(
msg
[
0
])
<<
endl
;
cout
<<
"sizeSeq: "
<<
bitset
<
8
>
(
messages
[
i
].
header
.
c_ctrl
.
sizeSeq
)
<<
endl
;
cout
<<
"seqType: "
<<
bitset
<
8
>
(
messages
[
i
].
header
.
c_ctrl
.
seqType
)
<<
endl
;
msg
.
push_back
(
messages
[
i
].
header
.
c_ctrl
.
sizeSeq
);
cout
<<
"vector sizeSeq: "
<<
bitset
<
8
>
(
msg
[
1
])
<<
endl
;
msg
.
push_back
(
messages
[
i
].
header
.
c_ctrl
.
seqType
);
msg
.
insert
(
msg
.
end
(),
messages
[
i
].
data
.
begin
(),
messages
[
i
].
data
.
end
());
msg
.
push_back
(
messages
[
i
].
header
.
c_ctrl
.
parity
);
char
*
data
=
reinterpret_cast
<
char
*>
(
msg
.
data
());
cout
<<
"msg size: "
<<
bitset
<
6
>
(
messages
[
i
].
header
.
i_ctrl
.
size
)
<<
endl
;
cout
<<
"pointer begin: "
<<
bitset
<
8
>
(
data
[
0
])
<<
"|
\t
"
;
cout
<<
"msg isize: "
<<
messages
[
i
].
getBitFieldsAsInt
()[
1
]
<<
endl
;
send
(
socket
,
data
,
messages
[
i
].
getBitFieldsAsInt
()[
1
]
+
4
,
0
);
}
return
true
;
}
...
...
@@ -35,9 +50,8 @@ string Protocol::getDataAsString(){
void
Protocol
::
setData
(
vector
<
BYTE
>
data
,
int
type
){
vector
<
BYTE
>::
const_iterator
first
,
last
;
int
i
;
for
(
i
=
0
;
i
<=
data
.
size
()
-
MAXSIZE
;
i
+=
MAXSIZE
){
Message
msg
;
msg
.
header
.
i_ctrl
.
begin
=
BEGIN
;
for
(
i
=
0
;
i
<=
((
int
)
data
.
size
())
-
MAXSIZE
;
i
+=
MAXSIZE
){
Message
msg
=
Message
();
msg
.
header
.
i_ctrl
.
size
=
MAXSIZE
;
msg
.
header
.
i_ctrl
.
sequence
=
messages
.
size
()
%
(
MAXSIZE
+
1
);
msg
.
header
.
i_ctrl
.
type
=
type
;
...
...
@@ -45,15 +59,16 @@ void Protocol::setData(vector<BYTE> data, int type){
last
=
data
.
begin
()
+
i
+
MAXSIZE
+
1
;
vector
<
BYTE
>
subvector
(
first
,
last
);
msg
.
data
=
subvector
;
//TODO: Set p
arity
msg
.
calcP
arity
();
messages
.
push_back
(
msg
);
}
if
(
i
<
data
.
size
()){
Message
msg
;
msg
.
header
.
i_ctrl
.
begin
=
BEGIN
;
cout
<<
"entrou if"
<<
endl
;
Message
msg
=
Message
()
;
msg
.
header
.
i_ctrl
.
sequence
=
messages
.
size
()
%
(
MAXSIZE
+
1
);
msg
.
header
.
i_ctrl
.
type
=
type
;
int
size
=
data
.
size
()
-
i
;
int
size
=
((
int
)
data
.
size
())
-
i
;
cout
<<
"real size "
<<
size
<<
endl
;
first
=
data
.
begin
()
+
i
;
last
=
data
.
begin
()
+
size
+
1
;
vector
<
BYTE
>
subvector
(
first
,
last
);
...
...
@@ -62,16 +77,18 @@ void Protocol::setData(vector<BYTE> data, int type){
size
=
MINSIZE
;
msg
.
data
.
insert
(
msg
.
data
.
begin
(),
MINSIZE
-
size
,
0x0
);
}
cout
<<
"modified size "
<<
size
<<
endl
;
msg
.
header
.
i_ctrl
.
size
=
size
;
//TODO: Set p
arity
msg
.
calcP
arity
();
messages
.
push_back
(
msg
);
}
}
int
Protocol
::
recvMessage
(
int
sockt
){
BYTE
dataRec
[
MAXSIZE
+
4
];
recv
(
sockt
,
dataRec
,
MAXSIZE
,
0
);
cout
<<
dataRec
[
0
]
<<
dataRec
[
1
]
<<
dataRec
[
2
]
<<
"|
\t
"
;
int
r
=
recv
(
sockt
,
dataRec
,
MAXSIZE
+
4
,
0
);
cout
<<
"recv response: "
<<
r
<<
endl
;
cout
<<
bitset
<
8
>
(
dataRec
[
0
])
<<
bitset
<
8
>
(
dataRec
[
1
])
<<
bitset
<
8
>
(
dataRec
[
2
])
<<
"|
\t
"
;
Message
msg
;
msg
.
header
.
c_ctrl
.
begin
=
dataRec
[
0
];
if
(
msg
.
header
.
i_ctrl
.
begin
!=
BEGIN
){
...
...
@@ -83,7 +100,9 @@ int Protocol::recvMessage(int sockt){
return
SEQ_MISS
;
}
msg
.
header
.
c_ctrl
.
parity
=
dataRec
[
3
+
msg
.
header
.
i_ctrl
.
size
];
// TODO: Check parity
if
(
!
msg
.
checkParity
()){
return
INCONSISTENT
;
}
if
(
msg
.
header
.
i_ctrl
.
type
==
ENDTX
){
return
ENDTX
;
}
...
...
This diff is collapsed.
Click to expand it.
client.cpp
+
1
−
3
View file @
4c63b7b0
...
...
@@ -32,9 +32,7 @@ int main(){
//TODO
}
else
if
(
command
==
"lsr"
){
Message
msg
=
Message
();
msg
.
header
.
i_ctrl
.
type
=
LS
;
msg
.
data
=
vector
<
BYTE
>
(
line
.
begin
(),
line
.
end
());
protocol
.
addMessage
(
msg
);
protocol
.
setData
(
vector
<
BYTE
>
(
line
.
begin
(),
line
.
end
()),
LS
);
protocol
.
sendMessages
(
sockt
,
WAIT_STOP
);
// TODO: imprimir resposta
}
else
if
(
command
==
"put"
){
...
...
This diff is collapsed.
Click to expand it.
definitions.h
+
3
−
3
View file @
4c63b7b0
...
...
@@ -35,9 +35,9 @@ using namespace std;
#define SLIDING 3
//Values of data for ERROR messages
#define DIR_ERR '0'
#define PERM_ERR '1'
#define SPACE_ERR '2'
#define DIR_ERR '0'
//Nonexistent Directory
#define PERM_ERR '1'
//Permission denied
#define SPACE_ERR '2'
//File size bigger than disk free space size
//recvMessage errors
#define NOISE -1
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment