-
Notifications
You must be signed in to change notification settings - Fork 8
/
radio.c
131 lines (116 loc) · 2.81 KB
/
radio.c
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/**
* GreenPois0n Cynanide - radio.c
* Copyright (C) 2010 Chronic-Dev Team
* Copyright (C) 2010 Joshua Hill
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
**/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "uart.h"
#include "radio.h"
#include "commands.h"
static Bool gRadioReadInit = FALSE;
int radio_init() {
srand(1);
if(uart_read && uart_write) {
cmd_add("radio", &radio_cmd, "send AT commands to baseband radio");
}
return 0;
}
int radio_cmd(int argc, CmdArg* argv) {
int i = 0;
int ret = 0;
char* data = NULL;
if(gRadioReadInit == FALSE) {
//TaskDescriptor* radio_reader_task = task_create("radio_reader", &radio_reader, 0, 0x2000);
//task_start(radio_reader_task);
gRadioReadInit = TRUE;
}
if(argc == 1) {
radio_send_random();
return 0;
}
data = malloc(0x100);
memset(data, '\0', 0x100);
for(i = 1; i < argc; i++) {
if(i > 2) {
strncat(data, " ", 0x100);
}
strncat(data, argv[i].string, 0x100);
}
ret = radio_write(data);
free(data);
return ret;
}
int radio_write(char* command) {
int size = 0;
char data[0x100];
memset(data, '\0', 0x100);
strncpy(data, command, 0x100);
strncat(data, "\r", 0x100);
size = strlen(data);
uart_write(1, data, size);
return size;
}
int radio_read(char* buffer, unsigned int size) {
return size;
}
void radio_set_debug() {
radio_write("at+cmee=1");
radio_write("at+creg=1");
}
int radio_find_commands() {
srand(1);
int i = 0;
char string[8];
char command[32];
memset(string, '\0', 8);
while(1) {
memset(command, '\0', 32);
strcpy(command, "at+");
for(i = 0; i < 4; i++) {
string[0] = (char) (rand() % 26) + 0x61;
strncat(command, string, 32);
}
strncat(command, "=?", 32);
radio_write(command);
//radio_read(response);
}
return 0;
}
int radio_send_random() {
int i = 0;
char string[8];
char command[32];
memset(string, '\0', 8);
memset(command, '\0', 32);
strcpy(command, "at+");
for(i = 0; i < 4; i++) {
string[0] = (char) (rand() % 26) + 0x61;
strncat(command, string, 32);
}
strncat(command, "=?", 32);
printf("Sending \"%s\"\n", command);
radio_write(command);
return 0;
}
void radio_reader(void* arg) {
char byte;
while(1) {
uart_read(1, &byte, 1, 1);
printf("%c", byte);
}
}