Add files via upload

master
Wojciech Kaczmarski 2020-08-30 16:50:38 +02:00 committed by GitHub
parent ec501f3170
commit 8be70b2d70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 49 additions and 12 deletions

61
main.c
View File

@ -16,7 +16,7 @@
uint16_t port_num=17000; //default port
//UDP packet
uint8_t bits[40];
uint8_t bits[50];
//for reconstructed speech samples, 2x160 (2x20ms)
uint16_t speech_buff[320];
@ -31,6 +31,32 @@ int s, i, slen = sizeof(si_other) , rcv_len;
//test
//FILE *fp;
//stream info
uint8_t src[10];
uint8_t dst[10];
uint16_t type=0;
uint8_t* decode_callsign_base40(uint64_t encoded, uint8_t *callsign)
{
if(encoded >= 262144000000000)
{
*callsign=0;
return callsign;
}
uint8_t *p = callsign;
for (; encoded>0; p++)
{
*p = "xABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-/."[encoded % 40];
encoded/=40;
}
*p = 0;
return callsign;
}
int main(int argc, char *argv[])
{
if(argc==2)
@ -45,13 +71,14 @@ int main(int argc, char *argv[])
//init
cod = codec2_create(CODEC2_MODE_3200);
memset(bits, 0, 40);
memset(bits, 0, 50);
memset(speech_buff, 0, 320);
s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if(s==-1)
{
fprintf(stderr, "Socket error\n");
return 1;
}
@ -64,20 +91,35 @@ int main(int argc, char *argv[])
if(bind(s, (struct sockaddr*)&si_me, sizeof(si_me))==-1)
{
fprintf(stderr, "Can't bind to port %d\n", port_num);
return 1;
}
printf("Listening for M17 frames on port %d:\n", port_num);
printf("Src\t\tDst\t\tType\n");
while(1)
{
//receive packet via UDP
if((rcv_len=recvfrom(s, bits, 40, 0, (struct sockaddr*)&si_other, &slen))==-1)
if((rcv_len=recvfrom(s, bits, 50, 0, (struct sockaddr*)&si_other, &slen))==-1)
{
fprintf(stderr, "What the hell?\n");
return 1;
}
if(rcv_len==34)
{/*
if(rcv_len==15)
{
uint64_t tmp;
tmp=(bits[0]<<(5*8))|(bits[1]<<(4*8))|(bits[2]<<(3*8))|(bits[3]<<(2*8))|(bits[4]<<(1*8))|bits[5];
decode_callsign_base40(tmp, src);
tmp=(bits[6]<<(5*8))|(bits[7]<<(4*8))|(bits[8]<<(3*8))|(bits[9]<<(2*8))|(bits[10]<<(1*8))|bits[11];
decode_callsign_base40(tmp, dst);
type=(bits[12]<<8)|bits[13];
//info
printf("%s\t\t%s\t\t%04X\n", src, dst, type);
/*
//reconstruct speech
codec2_decode(cod, &speech_buff[0], &bits[0]);
codec2_decode(cod, &speech_buff[160], &bits[8]);
@ -91,15 +133,10 @@ int main(int argc, char *argv[])
else
printf("%c", (uint8_t)(speech_buff[i/2]>>8));
}
/*fp=fopen("out.raw", "a");
fwrite(speech_buff, 2, 160, fp);
fclose(fp);*/
printf("Frame recv'd!\n");
}
else if(rcv_len==40)
{
printf("LICH recv'd!\n");
}
}