1
|
#include <stdio.h>
|
2
|
#include <stdlib.h>
|
3
|
#include <string.h>
|
4
|
#include "serial.h"
|
5
|
#include "osmosdr.h"
|
6
|
#include "utils.h"
|
7
|
|
8
|
static int printSyntax()
|
9
|
{
|
10
|
fprintf(stderr, "Error: Invalid command line!\n\n"
|
11
|
#ifdef WINDOWS
|
12
|
"syntax: sdr-samba com1 command\n"
|
13
|
#else
|
14
|
"syntax: sdr-samba /dev/ttyACM0 command\n"
|
15
|
#endif
|
16
|
"valid commands are:\n"
|
17
|
" - detect: detect OsmoSDR and print unique ID\n"
|
18
|
" - blink: blink LEDs on board\n"
|
19
|
" - ramload image.bin: load image.bin into SRAM and start it\n"
|
20
|
" - flashfpga algo.vme data.vme: write data.vme to FPGA FLASH using algo.vme\n"
|
21
|
" - flashmcu image.bin: write image.bin to MCU FLASH\n");
|
22
|
|
23
|
return EXIT_FAILURE;
|
24
|
}
|
25
|
|
26
|
int main(int argc, char* argv[])
|
27
|
{
|
28
|
HANDLE fd;
|
29
|
int res = -1;
|
30
|
void* bin;
|
31
|
size_t binSize;
|
32
|
|
33
|
if(argc < 3)
|
34
|
return printSyntax();
|
35
|
|
36
|
if(strcmp(argv[2], "detect") == 0) {
|
37
|
if(argc != 3)
|
38
|
return printSyntax();
|
39
|
if((fd = serialOpen(argv[1])) == INVALID_HANDLE_VALUE)
|
40
|
return EXIT_FAILURE;
|
41
|
res = 0;
|
42
|
if(res >= 0)
|
43
|
res = osmoSDRDetect(fd);
|
44
|
if(res >= 0)
|
45
|
res = osmoSDRPrintUID(fd, 0);
|
46
|
if(res >= 0)
|
47
|
res = osmoSDRPrintUID(fd, 1);
|
48
|
serialClose(fd);
|
49
|
} else if(strcmp(argv[2], "blink") == 0) {
|
50
|
if(argc != 3)
|
51
|
return printSyntax();
|
52
|
if((fd = serialOpen(argv[1])) == INVALID_HANDLE_VALUE)
|
53
|
return EXIT_FAILURE;
|
54
|
res = 0;
|
55
|
if(res >= 0)
|
56
|
res = osmoSDRDetect(fd);
|
57
|
if(res >= 0)
|
58
|
res = osmoSDRBlink(fd);
|
59
|
serialClose(fd);
|
60
|
} else if(strcmp(argv[2], "ramload") == 0) {
|
61
|
if(argc != 4)
|
62
|
return printSyntax();
|
63
|
if((bin = loadFile(argv[3], &binSize)) == NULL)
|
64
|
return EXIT_FAILURE;
|
65
|
if((fd = serialOpen(argv[1])) == INVALID_HANDLE_VALUE)
|
66
|
return EXIT_FAILURE;
|
67
|
res = 0;
|
68
|
if(res >= 0)
|
69
|
res = osmoSDRDetect(fd);
|
70
|
if(res >= 0)
|
71
|
res = osmoSDRRamLoad(fd, bin, binSize);
|
72
|
serialClose(fd);
|
73
|
} else if(strcmp(argv[2], "flashfpga") == 0) {
|
74
|
void* algo;
|
75
|
size_t algoSize;
|
76
|
if(argc != 5)
|
77
|
return printSyntax();
|
78
|
if((algo = loadFile(argv[3], &algoSize)) == NULL)
|
79
|
return EXIT_FAILURE;
|
80
|
if((bin = loadFile(argv[4], &binSize)) == NULL)
|
81
|
return EXIT_FAILURE;
|
82
|
if((fd = serialOpen(argv[1])) == INVALID_HANDLE_VALUE)
|
83
|
return EXIT_FAILURE;
|
84
|
res = 0;
|
85
|
if(res >= 0)
|
86
|
res = osmoSDRDetect(fd);
|
87
|
if(res >= 0)
|
88
|
res = osmoSDRFlashFPGA(fd, algo, algoSize, bin, binSize);
|
89
|
serialClose(fd);
|
90
|
} else if(strcmp(argv[2], "flashmcu") == 0) {
|
91
|
if(argc != 4)
|
92
|
return printSyntax();
|
93
|
if((bin = loadFile(argv[3], &binSize)) == NULL)
|
94
|
return EXIT_FAILURE;
|
95
|
if((fd = serialOpen(argv[1])) == INVALID_HANDLE_VALUE)
|
96
|
return EXIT_FAILURE;
|
97
|
res = 0;
|
98
|
if(res >= 0)
|
99
|
res = osmoSDRDetect(fd);
|
100
|
if(res >= 0)
|
101
|
res = osmoSDRFlashMCU(fd, bin, binSize);
|
102
|
serialClose(fd);
|
103
|
} else {
|
104
|
return printSyntax();
|
105
|
}
|
106
|
|
107
|
return (res < 0) ? EXIT_FAILURE : EXIT_SUCCESS;
|
108
|
}
|