1 |
a59a9825
|
Christian Daniel
|
#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 |
4cd82c23
|
Christian Daniel
|
#ifdef WINDOWS
|
12 |
|
|
"syntax: sdr-samba com1 command\n"
|
13 |
|
|
#else
|
14 |
a59a9825
|
Christian Daniel
|
"syntax: sdr-samba /dev/ttyACM0 command\n"
|
15 |
4cd82c23
|
Christian Daniel
|
#endif
|
16 |
a59a9825
|
Christian Daniel
|
"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 |
4cd82c23
|
Christian Daniel
|
" - 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 |
a59a9825
|
Christian Daniel
|
|
23 |
|
|
return EXIT_FAILURE;
|
24 |
|
|
}
|
25 |
|
|
|
26 |
|
|
int main(int argc, char* argv[])
|
27 |
|
|
{
|
28 |
4cd82c23
|
Christian Daniel
|
HANDLE fd;
|
29 |
a59a9825
|
Christian Daniel
|
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 |
4cd82c23
|
Christian Daniel
|
if((fd = serialOpen(argv[1])) == INVALID_HANDLE_VALUE)
|
40 |
a59a9825
|
Christian Daniel
|
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 |
4cd82c23
|
Christian Daniel
|
if((fd = serialOpen(argv[1])) == INVALID_HANDLE_VALUE)
|
53 |
a59a9825
|
Christian Daniel
|
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 |
4cd82c23
|
Christian Daniel
|
if((fd = serialOpen(argv[1])) == INVALID_HANDLE_VALUE)
|
66 |
a59a9825
|
Christian Daniel
|
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 |
4cd82c23
|
Christian Daniel
|
} 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 |
a59a9825
|
Christian Daniel
|
if(argc != 4)
|
92 |
|
|
return printSyntax();
|
93 |
|
|
if((bin = loadFile(argv[3], &binSize)) == NULL)
|
94 |
|
|
return EXIT_FAILURE;
|
95 |
4cd82c23
|
Christian Daniel
|
if((fd = serialOpen(argv[1])) == INVALID_HANDLE_VALUE)
|
96 |
a59a9825
|
Christian Daniel
|
return EXIT_FAILURE;
|
97 |
|
|
res = 0;
|
98 |
|
|
if(res >= 0)
|
99 |
|
|
res = osmoSDRDetect(fd);
|
100 |
|
|
if(res >= 0)
|
101 |
4cd82c23
|
Christian Daniel
|
res = osmoSDRFlashMCU(fd, bin, binSize);
|
102 |
a59a9825
|
Christian Daniel
|
serialClose(fd);
|
103 |
|
|
} else {
|
104 |
|
|
return printSyntax();
|
105 |
|
|
}
|
106 |
|
|
|
107 |
|
|
return (res < 0) ? EXIT_FAILURE : EXIT_SUCCESS;
|
108 |
|
|
}
|