32#include <condition_variable>
37#define STREAM_WITH_TCP
38#define SocType nsukit::NSUSoc <nsukit::SimCmdUItf, nsukit::SimCmdUItf, nsukit::SimStreamUItf>
40#ifdef STREAM_WITH_PCIE
41#define SocType nsukit::NSUSoc <nsukit::TCPCmdUItf, nsukit::TCPCmdUItf, nsukit::PCIEStreamUItf>
45#define SocType nsukit::NSUSoc <nsukit::TCPCmdUItf, nsukit::TCPCmdUItf, nsukit::TCPStreamUItf>
60 std::unique_lock<std::mutex> lock(mutex_);
63 condition_.notify_one();
68 std::unique_lock<std::mutex> lock(mutex_);
69 condition_.wait(lock, [
this] {
return !queue_.empty(); });
70 auto value = (T *)queue_.front();
76 std::queue<T *> queue_;
78 std::condition_variable condition_;
101 std::unique_lock<std::mutex> *lock;
106 auto s = _kit->
open_recv(0, mem, block, 0);
108 std::cout <<
"Establish CS and CR connections: " << std::endl;
109 std::cout <<
"Failed to enable data uplink " <<
nsukit::status2_string(s) <<
", currently uplinked: " << current << std::endl;
118 if (current == total) {
122 lock =
new std::unique_lock<std::mutex>(*mu);
137 std::unique_lock<std::mutex> *lock;
140 outF.open(path, std::ofstream::binary);
143 auto st = std::chrono::steady_clock::now();
146 lock =
new std::unique_lock<std::mutex>(*mu);
152 outF.write((
char *)_kit->
get_buffer(mem, block), block);
155 speed_count += block;
158 auto count = std::chrono::steady_clock::now() - st;
159 std::cout << std::flush <<
'\r' <<
"current write file speed: " << speed_count*1000./(count.count()) <<
"MB/s" << std::endl;
161 st = std::chrono::steady_clock::now();
165 std::cout << std::endl;
170int main(
int argc,
char *argv[]) {
171 unsigned int ds_block = 1024*1024;
177 std::cout <<
"Unsupported parameter passing method" << std::endl;
179 std::cout << argv[0] <<
" {IP} {totalBytes} {filePath}" << std::endl;
182 nsuSize_t total_len = std::atoi(argv[2]);
183 if (total_len % ds_block != 0) {
184 std::cout <<
"The total length of upstream data total_len "
185 << total_len <<
" Bytes should be "
186 << ds_block <<
"Integer multiple of Bytes" << std::endl;
194#ifdef STREAM_WITH_TCP
195 auto ip = std::string(argv[1]);
197 std::string port_str{};
198 port_str += ip[ip.length()-2];
200 port_str += ip[ip.length()-1];
201 int port = std::atoi(port_str.data());
217 std::cout <<
"SocLink Successful!!! now alloc buffer" << std::endl;
218 for (
int i=0; i<10; i++) {
223 res = kit->
execute(
"RFConfig");
224 std::cout <<
"Soc Init Successful!!!" << std::endl;
226 kit->
set_param(
"TotalTriggerPoints", 128);
230 res = kit->
execute(
"ADTriggerConfig");
231 std::cout <<
"ADTrigger Config Successful!!!" << std::endl;
239 std::thread up_trd(
upload_thread, kit, &q, ds_block, total_len, &mu);
242 std::cout <<
"Stream thread start successful!!!" << std::endl;
244#ifdef STREAM_WITH_TCP
246 std::cout <<
"Use TCP get data stream" << std::endl;
249 std::cout <<
"Use PCIE get data stream" << std::endl;
252 res = kit->
execute(
"SocStart");
265 std::cout <<
"Data upload completed" << std::endl;
virtual nsukitStatus_t open_recv(nsuChnlNum_t chnl, nsuMemory_p fd, nsuStreamLen_t length, nsuStreamLen_t offset=0)
virtual nsuVoidBuf_p get_buffer(nsuMemory_p fd, nsuStreamLen_t length=0)
virtual nsukitStatus_t wait_stream(nsuMemory_p fd, float timeout=0.)
nsukitStatus_t execute(nsuCSParam_t cname) override
nsukitStatus_t set_param(nsuCSParam_t ¶m_name, const uint8_t &value) override
nsukitStatus_t link_cmd(nsuInitParam_t *param) override
nsukitStatus_t link_stream(nsuInitParam_t *param) override
nsuMemory_p alloc_buffer(nsuStreamLen_t length, nsuVoidBuf_p buf=nullptr) override
void upload_thread(nsukit::BaseKit *_kit, Deque *q, nsuSize_t block, nsuSize_t total, std::mutex *mu)
void write_file_thread(nsukit::BaseKit *_kit, Deque *q, nsuSize_t block, const std::string &path, std::mutex *mu)
ThreadSafeQueue< void > memQueue
std::string NSU_DLLEXPORT status2_string(nsukitStatus_t status)
uint32_t stream_tcp_block
nsuBoardNum_t stream_board
@ NSUKIT_STATUS_STREAM_RUNNING
DLLEXTERN typedef size_t nsuSize_t
DLLEXTERN typedef void * nsuMemory_p