Untitled
unknown
plain_text
2 years ago
2.6 kB
9
Indexable
#include "iso15118_20_states.h"
#include "../../shared/messages/iso15118-20/timeouts.h"
#include "../../shared/messages/iso15118-20/common_messages.h"
#include <iostream>
#include "../transport/tcp_client.h"
#include <nlohmann/json.hpp>
#include <typeinfo>
#include "../../secc/transport/tcp_server.h"
#include "../../secc/states/iso15118_20_states.h"
#include <fcntl.h>
#include <thread>
#include <cerrno>
//#include "../main.cpp"
#include <sys/select.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
int global_sock_fd;
Timeouts timeouts;
EVCCSessionSetup::EVCCSessionSetup(void* comm_session , int sockfd): StateEVCC(comm_session, timeouts.V2G_EVCC_COMMUNICATION_SETUP_TIMEOUT,"EVCCSessionSetup"),sock_fd(sockfd)
{
global_sock_fd = sock_fd;
};
void EVCCSessionSetup::process_message(void* message)
{
std::cout << "EVCCSessionSetup sockfd " << << std::endl;
AuthorizationSetupReq auth_setup_req("777777777877777777", 10);
nlohmann::json j;
j["SessionID"] = auth_setup_req.Header.SessionID;
j["Timestamp"] = auth_setup_req.Header.Timestamp;
j["Sockfd"] = sock_fd;
std::string serialized_data = j.dump();
clientsend(sock_fd,serialized_data.c_str());
//send_data(sock_fd, serialized_data.c_str());
this->create_next_message(nullptr, &auth_setup_req, timeouts.AUTHORIZATION_SETUP_REQ);
//EVCCAuthorizationSetup evccauthorizationsetup(nullptr,sock_fd,4);
};
EVCCAuthorizationSetup::EVCCAuthorizationSetup(void* comm_session): StateEVCC(comm_session, timeouts.AUTHORIZATION_SETUP_REQ, "EVCCAuthorizationSetup")
{
};
void EVCCAuthorizationSetup::process_message(void* message)
{
char buffer[1024];
try
{
std::cout << "EVCCAuthorizationSetup sockfd " << global_sock_fd << std::endl;
while(true)
{
int received_bytes = clientrecv(global_sock_fd, buffer, sizeof(buffer));
std::cout << "Received bytes: " << received_bytes << std::endl;
if(received_bytes > 0)
{
std::cout << "received_bytes > 0" << std::endl;
break;
}
else if(received_bytes == 0)
{
std::cout << "Connection closed by the other end." << std::endl;
}
else
{
std::cerr << "Error in receiving data: " << strerror(errno) << std::endl;
}
}
}
catch(const std::exception& e) {
std::cerr << "Exception caught: " << e.what() << std::endl;
}
};
Editor is loading...