-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
65 lines (58 loc) · 1.84 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* File: main.cpp
* Author: wiluite
*
* Created on 27 февраля 2020 г., 8:05
*/
#include "board.hpp"
//#include <chrono>
#include <thread>
#include <fstream>
int main()
{
using namespace spi_adc_client;
try
{
board mov_from;
board b {std::move(mov_from)};
std::atomic io_flag {true};
std::thread io([ & ]()
{
try
{
acquisition_switch s(b);
while (io_flag)
{
static uint8_t rcv_buf[std::numeric_limits<board::max_read_length_type>::max() + std::numeric_limits<board::max_read_length_type>::min() + 1];
static_assert(sizeof (rcv_buf) == 65536);
if (auto const len = b.read_buffer(rcv_buf))
{
// TODO: turn to memory-mapped file
static std::ofstream binary_file{"oscillogram.bin", std::ios::out | std::ios::binary};
binary_file.write((char const*) rcv_buf, len);
} else
{
std::this_thread::sleep_for(std::chrono::microseconds(10));
}
}
} catch (acquisition_switch<board>::acquisition_switch_exception const & e)
{
Log_Wrapper("acquisition_switch_start_exception ", e.what());
return;
}
});
std::this_thread::sleep_for(std::chrono::milliseconds(5000));
io_flag = false;
io.join();
} catch (board::board_error const & e)
{
Log_Wrapper(e.what());
return -1;
}
return 0;
}