forked from wd5gnr/cwbeacon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
text2vector.c
57 lines (50 loc) · 1.19 KB
/
text2vector.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
#include <stdio.h>
#include <ctype.h>
#include <string.h>
// Convert Morse code to a vector suitable for CW generation in GNU Radio
// Williams WD5GNR -- Hackaday
// A-Z then 0-9 -- could add some prosigns
char *cw[] =
{
".-","-...","-.-.","-..",".","..-.","--.","....","..",".---",".-.",".-..",
"--","-.","---",".--.","--.-",".-.","...","-","..-","..._",".--","-..-","-.--","--..",
"-----",".----","..---","...--","....-",".....","-....","--...","---..","----."
};
char *dit="1,0";
char *dah="1,1,1,0";
char *cspace="0";
char *wspace="0,0";
void emit(int index)
{
int i;
int l;
if (isspace(index))
{
printf(",%s",wspace);
return;
}
index=toupper(index);
if (isalpha(index)) index-='A'; // point to letter
else if (isdigit(index)) index=index+26-'0'; // point to number
else
{
fprintf(stderr,"Warning: Unknown character %c\n",index);
return; // skip unknown
}
l=strlen(cw[index]);
for (i=0;i<l;i++)
printf(",%s",cw[index][i]=='.'?dit:dah);
printf(",%s",cspace);
return;
}
int main(int argc, char *argv[])
{
int c;
printf("(0,");
while ((c=getchar())!=EOF)
{
emit(c);
}
printf(")\n");
return 0;
}