-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathllrf.cpp
117 lines (101 loc) · 3.35 KB
/
llrf.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include <yaml-cpp/yaml.h>
#include <arpa/inet.h>
#include <iostream>
#include <string>
#include "LlrfAmcLogger.h"
#include "LlrfAmc.h"
#include "helpers.h"
void usage(const char* name)
{
std::cout << "Usage: " << name << "-a <IP_address> -Y <Yaml_top> [-i <App_ID>] [-e <Enable>] [-c] [-h]" << std::endl;
std::cout << " -h : show this message." << std::endl;
std::cout << " -a <IP_address> : IP address of the target FPGA." << std::endl;
std::cout << " -Y <yaml_file> : Path to YAML top level file." << std::endl;
std::cout << " -d <defaults_file> : Path to YAML defaults file." << std::endl;
std::cout << std::endl;
}
int main(int argc, char **argv)
{
unsigned char buf[sizeof(struct in6_addr)];
std::string ipAddr;
std::string yamlDoc;
std::string defaultsDoc;
int c;
while((c = getopt(argc, argv, "a:Y:d:")) != -1)
{
switch (c)
{
case 'a':
if (!inet_pton(AF_INET, optarg, buf))
{
std::cout << "Invalid IP address..." << std::endl;
exit(1);
}
ipAddr = std::string(optarg);
break;
case 'Y':
yamlDoc = std::string(optarg);
break;
case 'd':
defaultsDoc = std::string(optarg);
break;
default:
usage(argv[0]);
exit(1);
break;
}
}
if (ipAddr.empty())
{
std::cout << "Must specify an IP address." << std::endl;
exit(1);
}
if (yamlDoc.empty())
{
std::cout << "Must specify a YAML top path." << std::endl;
exit(1);
}
IYamlSetIP setIP(ipAddr);
Path root = IPath::loadYamlFile( yamlDoc.c_str(), "NetIODev", NULL, &setIP );
if ( defaultsDoc.empty() )
{
std::cout << "Not defaults file was specified. Omitting..." << std::endl;
}
else
{
std::string configPath { "mmio" };
Path configRoot = root->findByName( configPath.c_str() );
std::cout << "Loading '" << defaultsDoc << "'..." << std::endl;
std::size_t n = configRoot->loadConfigFromYamlFile(defaultsDoc.c_str());
std::cout << "Done. " << n << " entries were loaded" << std::endl;
}
std::cout << std::endl;
// Set logger level to "Debug"
ILogger::setLevel(LoggerLevel::Debug);
// Create LlrfAmc object
std::cout << "Creating an LlrfAmc object..." << std::endl;
LlrfAmc llrf { ILlrfAmc::create(root) };
std::cout << std::endl;
// Print the down and up converter module names
std::cout << "Down converter module name : " << llrf->getDownConv()->getModuleName() << std::endl;
std::cout << "Up converter module name : " << llrf->getUpConv()->getModuleName() << std::endl;
std::cout << std::endl;
// Initialize it
std::cout << "Initializing the LlrfAmc object..." << std::endl;
bool success;
if ( success = llrf->init() )
{
success &= llrf->isLocked();
}
std::cout << std::endl;
// Check if the initialization succeed
std::cout << std::endl;
if ( !success )
{
std::cerr << "Initialization failed!" << std::endl;
return 1;
}
std::cout << "Initialization succeed!" << std::endl;
std::cout << std::endl;
return 0;
}