]>
git.defcon.no Git - hm-trp-tool/blob - hm-trp.c
6 #define CBUFFER_SIZE 32
9 const int count_devtype
= 4;
10 const char* dev_name
[4] = {
17 const uint32_t freq_min
[4] = {
23 const uint32_t freq_max
[4] = {
29 const uint32_t freq_default
[4] = {
36 const int count_recv_bw
= 12;
37 // Values selected somewhat randomly...
38 const int recv_bw
[12] = {
53 const int count_freq_dev
= 10;
54 // Values selected somewhat randomly...
55 const int freq_dev
[10] = { // Values as kHz ..
68 const int count_powerlevel
= 8;
69 const int powerlevel
[8] = { 1, 2, 5, 8, 11, 14, 17, 20 };
71 const int count_rates
= 9;
72 const int port_rate_value
[9] = {
84 const int port_rates
[9] = {
96 const char cmd_reset
[3] = { 0xAA, 0xFA, 0xF0 };
97 const char cmd_config
[3] = { 0xAA, 0xFA, 0xE1 };
98 const char cmd_frequency
[3] = { 0xAA, 0xFA, 0xD2 };
99 const char cmd_air_rate
[3] = { 0xAA, 0xFA, 0xC3 };
100 const char cmd_bw
[3] = { 0xAA, 0xFA, 0xB4 };
101 const char cmd_deviation
[3] = { 0xAA, 0xFA, 0xA5 };
102 const char cmd_power
[3] = { 0xAA, 0xFA, 0x96 };
103 const char cmd_uart_rate
[3] = { 0xAA, 0xFA, 0x1E };
104 const char cmd_RSSI
[3] = { 0xAA, 0xFA, 0x87 };
105 const char cmd_SNR
[3] = { 0xAA, 0xFA, 0x78 };
107 int write_uint32_t ( int f
, uint32_t v
)
110 unsigned char buf
[4];
112 for ( i
= 0; i
< 4; i
++ )
113 buf
[i
] = (v
>>(8*i
) & 0xff );
115 return write( f
, buf
, 4 );
118 int write_uint16_t ( int f
, uint16_t v
)
121 unsigned char buf
[2];
123 for ( i
= 0; i
< 2; i
++ )
124 buf
[i
] = (v
>>(8*i
) & 0xff );
126 return write( f
, buf
, 2 );
129 int write_uint8_t ( int f
, uint8_t v
)
132 unsigned char buf
[2];
134 //for ( i = 0; i < 2; i++ )
135 // buf[i] = (v>>(8*i) & 0xff );
137 return write( f
, &v
, 1 );
140 int write_cmd ( int f
, const char* buf
)
142 return write( f
, buf
, 3 ); // Send the command to the device
145 int read_config ( int fd
, config_t
* config
)
148 unsigned char buf
[CBUFFER_SIZE
];
151 res
= write_cmd( fd
, cmd_config
); // Send the command to the device
152 if ( res
< 0 ) return(-1); // and die on failure..
155 uint8_t* tmp_config
= (uint8_t*)config
;
157 bzero(buf
, CBUFFER_SIZE
);
158 res
= read( fd
, buf
, 1 );
162 *tmp_config
++ = (uint8_t)buf
[0];
163 // Make sure wo don't overflow the config struct.
164 if ( (void*)tmp_config
> ((void*)config
+sizeof(config_t
)) ) return(-2);
176 config
->freq
= __bswap_32( config
->freq
);
177 config
->air_rate
= __bswap_32( config
->air_rate
);
178 config
->bw
= __bswap_16( config
->bw
);
179 config
->uart_rate
= __bswap_32( config
->uart_rate
);
183 return 0; // No errors, but no valid config
186 int read_ok ( int fd
)
193 while( (read( fd
, &c
, 1 ) > 0 ) && ( i
< 4) ) ok
[i
++] = c
;
194 if ( strcmp( ok
, "OK\r\n" ) == 0 ) return 1;