kopia lustrzana https://github.com/F5OEO/rpitx
Add support to sendook to read bit and duration from file
rodzic
5fce7fc94a
commit
aaefebc8ee
|
@ -10,6 +10,13 @@
|
|||
|
||||
bool running = true;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
double active;
|
||||
uint32_t duration; //nano seconds
|
||||
uint32_t padding;
|
||||
} Bitdata;
|
||||
|
||||
void print_usage(void)
|
||||
{
|
||||
/** Future options :
|
||||
|
@ -30,6 +37,7 @@ Options:\n\
|
|||
-r nb : repeat nb times the message (default : 3)\n\
|
||||
-p nb : pause between each message (default : 1000us=1ms)\n\
|
||||
-m nb : modulation type 0=OOK, 1=OOK_PWM, 2=OOK_PPM (default : 0=OOK)\n\
|
||||
-i : filemode : read from file\n\
|
||||
\n\
|
||||
\"binary code\":\n\
|
||||
a serie of 0 or 1 char (space allowed and ignored)\n\
|
||||
|
@ -75,6 +83,10 @@ int main(int argc, char *argv[])
|
|||
int dryrun = 0; // if 1 : hte message is not really transmitted
|
||||
int modulation = 0; // 0=OOK, 1=OOK_PWM, 2=OOK_PPM
|
||||
char *bits = NULL;
|
||||
int filemode = 0;
|
||||
char *filename = NULL;
|
||||
uint8_t *data = NULL;
|
||||
int size;
|
||||
|
||||
for (int i = 0; i < 64; i++)
|
||||
{
|
||||
|
@ -85,7 +97,7 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
while(1)
|
||||
{
|
||||
a = getopt(argc, argv, "f:0:1:g:r:p:m:hvd");
|
||||
a = getopt(argc, argv, "f:0:1:g:r:p:m:hvdi");
|
||||
if(a == -1)
|
||||
{
|
||||
if(anyargs) break;
|
||||
|
@ -125,6 +137,9 @@ int main(int argc, char *argv[])
|
|||
case 'd': // Dry run
|
||||
dryrun = 1;
|
||||
break;
|
||||
case 'i': // filemode
|
||||
filemode = 1;
|
||||
break;
|
||||
case -1:
|
||||
break;
|
||||
default:
|
||||
|
@ -136,12 +151,26 @@ int main(int argc, char *argv[])
|
|||
if (optind >= argc) {
|
||||
FATAL_ERROR(-2, "Missing bit message.\n");
|
||||
}
|
||||
if (filemode)
|
||||
{
|
||||
filename = argv[optind];
|
||||
}
|
||||
else
|
||||
{
|
||||
bits = argv[optind];
|
||||
}
|
||||
printf("Frequency set to : %" PRIu64 "Hz \n", Freq);
|
||||
if(!filemode)
|
||||
{
|
||||
printf("Modulation: %d \n", modulation);
|
||||
printf("Bit duration 0 : %" PRIu64 "us ; 1 : %" PRIu64 "us\n",
|
||||
bit0duration, bit1duration);
|
||||
printf("Bit gap = %" PRIu64 "us \n", bitgap);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Reading data from file %s.\n", filename);
|
||||
}
|
||||
printf("Send message %d times with a pause of %dus\n", nbrepeat, pause);
|
||||
if (dryrun)
|
||||
printf("Dry run mode enabled : no message will be sent\n");
|
||||
|
@ -149,6 +178,8 @@ int main(int argc, char *argv[])
|
|||
// Simplify the message to send
|
||||
int computed_duration = 0; // in us
|
||||
int nbbits = 0;
|
||||
if(!filemode)
|
||||
{
|
||||
for(size_t i = 0; i < strlen(bits); i++)
|
||||
{
|
||||
char c = bits[i];
|
||||
|
@ -171,6 +202,30 @@ int main(int argc, char *argv[])
|
|||
// any other char is ignored (it allows to speparate nibble with a space for example)
|
||||
// improvement : allow "." and "-" or "i" and "a" to create a MORSE sender
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
FILE *p_file = NULL;
|
||||
p_file = fopen(filename,"rb");
|
||||
if(p_file == NULL)
|
||||
{
|
||||
FATAL_ERROR(-2, "Can't open file %s.\n", filename);
|
||||
}
|
||||
fseek(p_file,0,SEEK_END);
|
||||
size = ftell(p_file);
|
||||
data = (uint8_t *)malloc(size);
|
||||
rewind(p_file);
|
||||
fread(data,sizeof(uint8_t),size,p_file);
|
||||
Bitdata *p_bitdata = (Bitdata *)data;
|
||||
|
||||
nbbits = size/sizeof(Bitdata);
|
||||
for(int i = 0; i < nbbits; i++)
|
||||
{
|
||||
computed_duration += p_bitdata[i].duration/1000; //nano to us
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
dbg_printf(1, "Send %d bits, with a total duration of %d us.\n", nbbits, computed_duration);
|
||||
if (computed_duration == 0 || nbbits == 0)
|
||||
{
|
||||
|
@ -184,6 +239,8 @@ int main(int argc, char *argv[])
|
|||
// Prepare the message
|
||||
ookbursttiming ooksender(Freq, computed_duration);
|
||||
ookbursttiming::SampleOOKTiming Message[nbbits];
|
||||
if(!filemode)
|
||||
{
|
||||
for(size_t i = 0; i < strlen(bits); i++)
|
||||
{
|
||||
char c = bits[i];
|
||||
|
@ -239,6 +296,16 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Bitdata *p_bitdata = (Bitdata *)data;
|
||||
for(int i = 0; i < nbbits; i++)
|
||||
{
|
||||
Message[i].value = p_bitdata[i].active;
|
||||
Message[i].duration = p_bitdata[i].duration/1000; //nano to us
|
||||
}
|
||||
}
|
||||
|
||||
// Send the message
|
||||
for (int i = 0; i < nbrepeat; i++)
|
||||
|
|
Ładowanie…
Reference in New Issue