34 #include "../../../PracticalSockets/src/PracticalSockets.h"
35 #include "../include/config.h"
36 #include "opencv2/opencv.hpp"
45 int main(
int argc,
char * argv[]) {
47 if ((argc < 2) || (argc > 3)) {
48 cerr <<
"Usage: " << argv[0] <<
" <Server Port> <optional simulation mode>" << endl;
52 unsigned short servPort = atoi(argv[1]);
56 namedWindow(
"tb_recv", WINDOW_AUTOSIZE);
58 UDPSocket sock(servPort);
63 unsigned short sourcePort;
66 clock_t last_cycle_rx =
clock();
73 cout <<
" ___________________________________________________________________ " << endl;
74 cout <<
"/ \\" << endl;
75 cout <<
"INFO: Proxy tb Frame # " << ++
num_frame << endl;
76 cout <<
"INFO: Expecting length of packs:" << total_pack << endl;
77 char * longbuf =
new char[
PACK_SIZE * total_pack];
80 for (
int i = 0; i < total_pack; i++) {
81 if ( i == total_pack - 1 ) {
82 receiving_now = bytes_in_last_pack;
84 recvMsgSize = sock.recvFrom(buffer,
BUF_LEN, sourceAddress, sourcePort);
85 if (recvMsgSize != receiving_now) {
86 cerr <<
"ERROR: Received unexpected size pack:" << recvMsgSize << endl;
89 memcpy( & longbuf[i *
PACK_SIZE], buffer, receiving_now);
92 cout <<
"INFO: Received packet from " << sourceAddress <<
":" << sourcePort << endl;
95 if (
frame.size().width == 0) {
96 cerr <<
"ERROR: receive failure!" << endl;
99 imshow(
"tb_recv",
frame);
102 imwrite(
"../../../../ROLE/vision/hls/gammacorrection/test/input_from_udp_to_fpga.png",
frame);
105 string exec_cmd =
"make fcsim -j 4";
106 string ouf_file =
"../../../../ROLE/vision/hls/gammacorrection/gammacorrection_prj/solution1/fcsim/build/hls_out.jpg";
108 if (atoi(argv[2]) == 2) {
109 exec_cmd =
"make csim";
110 ouf_file =
"../../../../ROLE/vision/hls/gammacorrection/gammacorrection_prj/solution1/csim/build/hls_out.jpg";
112 else if (atoi(argv[2]) == 3) {
113 exec_cmd =
"make cosim";
114 ouf_file =
"../../../../ROLE/vision/hls/gammacorrection/gammacorrection_prj/solution1/cosim/build/hls_out.jpg";
116 else if (atoi(argv[2]) == 4) {
117 exec_cmd =
"make kcachegrind";
118 ouf_file =
"../../../../ROLE/vision/hls/gammacorrection/gammacorrection_prj/solution1/fcsim/build/hls_out.jpg";
126 clean_cmd =
"make clean && ";
128 string str_command =
"cd ../../../../ROLE/vision/hls/gammacorrection/ && " + clean_cmd +
"\
129 INPUT_IMAGE=./test/input_from_udp_to_fpga.png " + exec_cmd +
" && \
130 cd ../../../../HOST/vision/gammacorrection/build/ ";
131 const char *command = str_command.c_str();
132 cout <<
"Calling TB with command:" << command << endl;
137 clock_t next_cycle_rx =
clock();
138 double duration_rx = (next_cycle_rx - last_cycle_rx) / (
double) CLOCKS_PER_SEC;
139 cout <<
"INFO: Effective FPS RX:" << (1 / duration_rx) <<
" \tkbps:" << (
PACK_SIZE *
140 total_pack / duration_rx / 1024 * 8) << endl;
141 last_cycle_rx = next_cycle_rx;
145 frame = cv::imread(ouf_file, cv::IMREAD_GRAYSCALE);
147 cerr <<
"ERROR: Failed to load the image " << ouf_file << endl;
151 cout <<
"INFO: Succesfully loaded image " << ouf_file << endl;
156 imshow(
"tb_send",
frame);
160 assert(
frame.isContinuous());
164 clock_t last_cycle_tx =
clock();
165 for (
int i = 0; i < total_pack; i++) {
166 if ( i == total_pack - 1 ) {
167 sending_now = bytes_in_last_pack;
169 sock.sendTo( &
frame.data[i *
PACK_SIZE], sending_now, sourceAddress, sourcePort);
172 clock_t next_cycle_tx =
clock();
173 double duration_tx = (next_cycle_tx - last_cycle_tx) / (
double) CLOCKS_PER_SEC;
174 cout <<
"INFO: Effective FPS TX:" << (1 / duration_tx) <<
" \tkbps:" << (
PACK_SIZE *
175 total_pack / duration_tx / 1024 * 8) << endl;
176 last_cycle_tx = next_cycle_tx;
177 cout <<
"\\___________________________________________________________________/" << endl;
180 }
catch (SocketException & e) {
181 cerr << e.what() << endl;
int main(int argc, char *argv[])