Skip to content
Snippets Groups Projects
Commit 5d5e9fb2 authored by bfsc19's avatar bfsc19 :flushed:
Browse files

Merge branch '7-envio-de-dados' of gitlab.c3sl.ufpr.br:bfsc19/raw-socket-c

parents 98bb90e2 80e7f477
No related branches found
No related tags found
No related merge requests found
File moved
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
#include <string.h> #include <string.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/types.h>
#include <sys/time.h> #include <sys/time.h>
#include <sys/types.h>
#include <arpa/inet.h> #include <arpa/inet.h>
...@@ -67,7 +67,10 @@ public: ...@@ -67,7 +67,10 @@ public:
* *
* @param deviceIP -- ip address of the device * @param deviceIP -- ip address of the device
*/ */
conexao::conexao(char *deviceIP) { device = ConexaoRawSocket(deviceIP); memset(bufferSend, 0, sizeof(frame)*2); } conexao::conexao(char *deviceIP) {
device = ConexaoRawSocket(deviceIP);
memset(bufferSend, 0, sizeof(frame) * 2);
}
/** /**
* @brief Recebe um frame * @brief Recebe um frame
...@@ -80,7 +83,8 @@ frame *conexao::receive_frame() { ...@@ -80,7 +83,8 @@ frame *conexao::receive_frame() {
int lastSeq = -1; int lastSeq = -1;
long long start = timestamp(); long long start = timestamp();
struct timeval timeout = {.tv_sec = 0, .tv_usec = timeoutMillis * 1000}; struct timeval timeout = {.tv_sec = 0, .tv_usec = timeoutMillis * 1000};
setsockopt(device, SOL_SOCKET, SO_RCVTIMEO, (char*)&timeout, sizeof(timeout)); setsockopt(device, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout,
sizeof(timeout));
do { do {
byteRecv = recv(device, bufferReceived, sizeof(frame) * 2, 0); byteRecv = recv(device, bufferReceived, sizeof(frame) * 2, 0);
...@@ -148,8 +152,7 @@ int conexao::add_escapes(char *f, char *out) { ...@@ -148,8 +152,7 @@ int conexao::add_escapes(char *f, char *out) {
int conexao::remove_escapes(char *f, char *out) { int conexao::remove_escapes(char *f, char *out) {
int j = 0; int j = 0;
for (size_t i = 0; j < sizeof(frame); i++) for (size_t i = 0; j < sizeof(frame); i++) {
{
out[j++] = f[i]; out[j++] = f[i];
if (f[i] == 0x88 || f[i] == 0x81) if (f[i] == 0x88 || f[i] == 0x81)
...@@ -160,7 +163,6 @@ int conexao::remove_escapes(char *f, char* out) { ...@@ -160,7 +163,6 @@ int conexao::remove_escapes(char *f, char* out) {
} }
int conexao::ConexaoRawSocket(char *device) { int conexao::ConexaoRawSocket(char *device) {
cout << "Conectando com o dispositivo " << device << "\n";
int soquete; int soquete;
struct ifreq ir; struct ifreq ir;
struct sockaddr_ll endereco; struct sockaddr_ll endereco;
...@@ -197,12 +199,10 @@ int conexao::ConexaoRawSocket(char *device) { ...@@ -197,12 +199,10 @@ int conexao::ConexaoRawSocket(char *device) {
exit(-1); exit(-1);
} }
cout << "Conectado com sucesso em " << device << "\n";
return soquete; return soquete;
} }
long long conexao::timestamp() long long conexao::timestamp() {
{
struct timeval tp; struct timeval tp;
gettimeofday(&tp, NULL); gettimeofday(&tp, NULL);
return tp.tv_sec * 1000 + tp.tv_usec / 1000; return tp.tv_sec * 1000 + tp.tv_usec / 1000;
......
File moved
File moved
File moved
File moved
CC = g++ CC = g++
CPPFLAGS = -g -std=c++20 CPPFLAGS = -g -std=c++20
SRC = $(wildcard *.cpp) SRC = $(wildcard src/*.cpp)
OBJ = $(SRC:.cpp=.o) OBJ = $(SRC:.cpp=.o)
...@@ -10,9 +10,10 @@ TARGET = exemplo ...@@ -10,9 +10,10 @@ TARGET = exemplo
all: $(TARGET) all: $(TARGET)
$(TARGET): $(OBJ) $(TARGET): $(OBJ)
$(CC) $(CPPFLAGS) -o $(TARGET) $(OBJ)
clean: clean:
rm -f *.o vgcore* rm -f src/*.o vgcore*
purge: clean purge: clean
rm -f $(TARGET) rm -f $(TARGET)
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#include <iomanip> #include <iomanip>
#include <string> #include <string>
#include "crc8.h" #include "../headers/crc8.h"
#define POLINOMIO 0x9B #define POLINOMIO 0x9B
......
#include <bits/stdc++.h> #include <iostream>
#include <linux/if.h> #include <vector>
#include <linux/if_packet.h>
#include <net/ethernet.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <thread>
// include local // include local
#include "conexao.h" #include "../headers/conexao.h"
#include "crc8.h" #include "../headers/crc8.h"
#include "frame.h" #include "../headers/frame.h"
#include "macros.h" #include "../headers/macros.h"
#include "server.h" #include "../headers/server.h"
#include "client.h" #include "../headers/client.h"
using namespace std; using namespace std;
...@@ -35,9 +25,13 @@ int get_status( char *argv ) ...@@ -35,9 +25,13 @@ int get_status( char *argv )
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
gen_crc8_table(); gen_crc8_table();
<<<<<<< HEAD:exemplo.cpp
char* device = argv[2]; char* device = argv[2];
cout << "Device: " << device << endl; cout << "Device: " << device << endl;
conexao socket(device); conexao socket(device);
=======
conexao socket((char *)argv[2]);
>>>>>>> 80e7f477d4253b6d77bf36c80fb004480000a16a:src/exemplo.cpp
int status = get_status(argv[1]); int status = get_status(argv[1]);
switch ( status ) switch ( status )
......
Writing this to a file.
This diff is collapsed.
test_files/foto.jpg

133 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment