34 #include "PracticalSockets.h"
36 #include "opencv2/opencv.hpp"
46 int main(
int argc,
char * argv[]) {
48 if ((argc < 2) || (argc > 3)) {
49 cerr <<
"Usage: " << argv[0] <<
" <Server Port> <optional simulation mode>" << endl;
54 cerr <<
"ERROR: Unidentified provided port : " << argv[1] <<
" . Aborting..." << endl;
58 unsigned short servPort = atoi(argv[1]);
63 namedWindow(
"tb_recv", WINDOW_AUTOSIZE);
68 UDPSocket sock(servPort);
70 TCPServerSocket servSock(servPort);
71 TCPSocket *servsock = servSock.accept();
79 cout <<
"Handling client ";
81 cout << servsock->getForeignAddress() <<
":";
82 }
catch (SocketException e) {
83 cerr <<
"Unable to get foreign address" << endl;
86 cout << servsock->getForeignPort();
87 }
catch (SocketException e) {
88 cerr <<
"Unable to get foreign port" << endl;
95 clock_t last_cycle_rx =
clock();
102 cout <<
" ___________________________________________________________________ " << endl;
103 cout <<
"/ \\" << endl;
104 cout <<
"INFO: Proxy tb Frame # " << ++
num_frame << endl;
105 cout <<
"INFO: Expecting length of packs:" << total_pack << endl;
106 char * longbuf =
new char[
PACK_SIZE * total_pack];
109 for (
int i = 0; i < total_pack; i++) {
110 if ( i == total_pack - 1 ) {
111 receiving_now = bytes_in_last_pack;
114 recvMsgSize = sock.recvFrom(buffer,
BUF_LEN, sourceAddress, servPort);
116 recvMsgSize = servsock->recv(buffer, receiving_now);
118 if (recvMsgSize != receiving_now) {
119 cerr <<
"ERROR: Received unexpected size pack:" << recvMsgSize << endl;
122 memcpy( & longbuf[i *
PACK_SIZE], buffer, receiving_now);
125 cout <<
"INFO: Received packet from " << sourceAddress <<
":" << servPort << endl;
128 if (
frame.size().width == 0) {
129 cerr <<
"ERROR: receive failure!" << endl;
133 imshow(
"tb_recv",
frame);
137 imwrite(
"../../../../../../ROLE/vision/hls/median_blur/test/input_from_udp_to_fpga.png",
frame);
140 string synth_cmd =
" ";
141 string exec_cmd =
"make fcsim -j 4";
142 string ouf_file =
"../../../../../../ROLE/vision/hls/median_blur/median_blur_prj/solution1/fcsim/build/hls_out.jpg";
144 if (atoi(argv[2]) == 2) {
145 exec_cmd =
"make csim";
146 ouf_file =
"../../../../../../ROLE/vision/hls/median_blur/median_blur_prj/solution1/csim/build/hls_out.jpg";
148 else if (atoi(argv[2]) == 3) {
149 synth_cmd =
"make csynth && ";
150 exec_cmd =
"make cosim";
151 ouf_file =
"../../../../../../ROLE/vision/hls/median_blur/median_blur_prj/solution1/sim/wrapc_pc/hls_out.jpg";
153 else if (atoi(argv[2]) == 4) {
154 exec_cmd =
"make kcachegrind";
155 ouf_file =
"../../../../../../ROLE/vision/hls/median_blur/median_blur_prj/solution1/fcsim/build/hls_out.jpg";
163 clean_cmd =
"make clean && ";
165 string str_command =
"cd ../../../../../../ROLE/vision/hls/median_blur/ && " + clean_cmd + synth_cmd +
"\
166 INPUT_IMAGE=./test/input_from_udp_to_fpga.png " + exec_cmd +
" && \
167 cd ../../../../HOST/vision/median_blur/languages/cplusplus/build/ ";
168 const char *command = str_command.c_str();
169 cout <<
"Calling TB with command:" << command << endl;
174 clock_t next_cycle_rx =
clock();
175 double duration_rx = (next_cycle_rx - last_cycle_rx) / (
double) CLOCKS_PER_SEC;
176 cout <<
"INFO: Effective FPS RX:" << (1 / duration_rx) <<
" \tkbps:" << (
PACK_SIZE *
177 total_pack / duration_rx / 1024 * 8) << endl;
178 last_cycle_rx = next_cycle_rx;
182 frame = cv::imread(ouf_file, cv::IMREAD_GRAYSCALE);
184 cerr <<
"ERROR: Failed to load the image " << ouf_file << endl;
188 cout <<
"INFO: Succesfully loaded image " << ouf_file << endl;
193 imshow(
"tb_send",
frame);
197 assert(
frame.isContinuous());
201 clock_t last_cycle_tx =
clock();
202 for (
int i = 0; i < total_pack; i++) {
203 if ( i == total_pack - 1 ) {
204 sending_now = bytes_in_last_pack;
207 sock.sendTo( &
frame.data[i *
PACK_SIZE], sending_now, sourceAddress, servPort);
214 clock_t next_cycle_tx =
clock();
215 double duration_tx = (next_cycle_tx - last_cycle_tx) / (
double) CLOCKS_PER_SEC;
216 cout <<
"INFO: Effective FPS TX:" << (1 / duration_tx) <<
" \tkbps:" << (
PACK_SIZE *
217 total_pack / duration_tx / 1024 * 8) << endl;
218 last_cycle_tx = next_cycle_tx;
219 cout <<
"\\___________________________________________________________________/" << endl;
224 }
catch (SocketException & e) {
225 cerr << e.what() << endl;
Common utility functions headers, i.e. timing, printing wrappers.
bool isNumeric(const std::string str)