34 #include "PracticalSockets.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]);
57 namedWindow(
"tb_recv", WINDOW_AUTOSIZE);
62 UDPSocket sock(servPort);
64 TCPServerSocket servSock(servPort);
65 TCPSocket *servsock = servSock.accept();
73 cout <<
"Handling client ";
75 cout << servsock->getForeignAddress() <<
":";
76 }
catch (SocketException e) {
77 cerr <<
"Unable to get foreign address" << endl;
80 cout << servsock->getForeignPort();
81 }
catch (SocketException e) {
82 cerr <<
"Unable to get foreign port" << endl;
89 clock_t last_cycle_rx =
clock();
96 cout <<
" ___________________________________________________________________ " << endl;
97 cout <<
"/ \\" << endl;
98 cout <<
"INFO: Proxy tb Frame # " << ++
num_frame << endl;
99 cout <<
"INFO: Expecting length of packs:" << total_pack << endl;
100 char * longbuf =
new char[
PACK_SIZE * total_pack];
103 for (
int i = 0; i < total_pack; i++) {
104 if ( i == total_pack - 1 ) {
105 receiving_now = bytes_in_last_pack;
108 recvMsgSize = sock.recvFrom(buffer,
BUF_LEN, sourceAddress, servPort);
110 recvMsgSize = servsock->recv(buffer, receiving_now);
112 if (recvMsgSize != receiving_now) {
113 cerr <<
"ERROR: Received unexpected size pack:" << recvMsgSize << endl;
116 memcpy( & longbuf[i *
PACK_SIZE], buffer, receiving_now);
119 cout <<
"INFO: Received packet from " << sourceAddress <<
":" << servPort << endl;
122 if (
frame.size().width == 0) {
123 cerr <<
"ERROR: receive failure!" << endl;
127 imshow(
"tb_recv",
frame);
131 imwrite(
"../../../../../../ROLE/vision/hls/sobel/test/input_from_udp_to_fpga.png",
frame);
134 string synth_cmd =
" ";
135 string exec_cmd =
"make fcsim -j 4";
136 string ouf_file =
"../../../../../../ROLE/vision/hls/sobel/sobel_prj/solution1/fcsim/build/hls_out.jpg";
138 if (atoi(argv[2]) == 2) {
139 exec_cmd =
"make csim";
140 ouf_file =
"../../../../../../ROLE/vision/hls/sobel/sobel_prj/solution1/csim/build/hls_out.jpg";
142 else if (atoi(argv[2]) == 3) {
143 synth_cmd =
"make csynth && ";
144 exec_cmd =
"make cosim";
145 ouf_file =
"../../../../../../ROLE/vision/hls/sobel/sobel_prj/solution1/sim/wrapc_pc/hls_out.jpg";
147 else if (atoi(argv[2]) == 4) {
148 exec_cmd =
"make kcachegrind";
149 ouf_file =
"../../../../../../ROLE/vision/hls/sobel/sobel_prj/solution1/fcsim/build/hls_out.jpg";
157 clean_cmd =
"make clean && ";
159 string str_command =
"cd ../../../../../../ROLE/vision/hls/sobel/ && " + clean_cmd + synth_cmd +
"\
160 INPUT_IMAGE=./test/input_from_udp_to_fpga.png " + exec_cmd +
" && \
161 cd ../../../../HOST/vision/sobel/languages/cplusplus/build/ ";
162 const char *command = str_command.c_str();
163 cout <<
"Calling TB with command:" << command << endl;
168 clock_t next_cycle_rx =
clock();
169 double duration_rx = (next_cycle_rx - last_cycle_rx) / (
double) CLOCKS_PER_SEC;
170 cout <<
"INFO: Effective FPS RX:" << (1 / duration_rx) <<
" \tkbps:" << (
PACK_SIZE *
171 total_pack / duration_rx / 1024 * 8) << endl;
172 last_cycle_rx = next_cycle_rx;
176 frame = cv::imread(ouf_file, cv::IMREAD_GRAYSCALE);
178 cerr <<
"ERROR: Failed to load the image " << ouf_file << endl;
182 cout <<
"INFO: Succesfully loaded image " << ouf_file << endl;
187 imshow(
"tb_send",
frame);
191 assert(
frame.isContinuous());
195 clock_t last_cycle_tx =
clock();
196 for (
int i = 0; i < total_pack; i++) {
197 if ( i == total_pack - 1 ) {
198 sending_now = bytes_in_last_pack;
201 sock.sendTo( &
frame.data[i *
PACK_SIZE], sending_now, sourceAddress, servPort);
208 clock_t next_cycle_tx =
clock();
209 double duration_tx = (next_cycle_tx - last_cycle_tx) / (
double) CLOCKS_PER_SEC;
210 cout <<
"INFO: Effective FPS TX:" << (1 / duration_tx) <<
" \tkbps:" << (
PACK_SIZE *
211 total_pack / duration_tx / 1024 * 8) << endl;
212 last_cycle_tx = next_cycle_tx;
213 cout <<
"\\___________________________________________________________________/" << endl;
218 }
catch (SocketException & e) {
219 cerr << e.what() << endl;
int main(int argc, char *argv[])