diff --git a/.gitignore b/.gitignore index 4d40434..f0f4d72 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ *.ko *.obj *.elf +obj # Libraries *.lib @@ -21,3 +22,11 @@ *.i*86 *.x86_64 *.hex + +# Others +.metadata +.vs +bin +Debug +Release +.settings diff --git a/DSP_API/.cproject b/DSP_API/.cproject index 13dbe50..91dc741 100644 --- a/DSP_API/.cproject +++ b/DSP_API/.cproject @@ -1,182 +1,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -190,7 +14,7 @@ - + @@ -201,21 +25,21 @@ @@ -267,7 +91,7 @@ - + @@ -282,13 +106,12 @@ - + - + - + @@ -354,6 +178,73 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -418,4 +309,5 @@ + diff --git a/DSP_API/Release/CODEC2_FREEDV/codebook.d b/DSP_API/Release/CODEC2_FREEDV/codebook.d deleted file mode 100644 index dc5f6f2..0000000 --- a/DSP_API/Release/CODEC2_FREEDV/codebook.d +++ /dev/null @@ -1,4 +0,0 @@ -CODEC2_FREEDV/codebook.d: ../CODEC2_FREEDV/codebook.c \ - ../CODEC2_FREEDV/defines.h - -../CODEC2_FREEDV/defines.h: diff --git a/DSP_API/Release/CODEC2_FREEDV/subdir.mk b/DSP_API/Release/CODEC2_FREEDV/subdir.mk deleted file mode 100644 index 01a752c..0000000 --- a/DSP_API/Release/CODEC2_FREEDV/subdir.mk +++ /dev/null @@ -1,96 +0,0 @@ -################################################################################ -# Automatically-generated file. Do not edit! -################################################################################ - -# Add inputs and outputs from these tool invocations to the build variables -C_SRCS += \ -../CODEC2_FREEDV/codebook.c \ -../CODEC2_FREEDV/codebookd.c \ -../CODEC2_FREEDV/codebookdt.c \ -../CODEC2_FREEDV/codebookge.c \ -../CODEC2_FREEDV/codebookjnd.c \ -../CODEC2_FREEDV/codebookjvm.c \ -../CODEC2_FREEDV/codebookvq.c \ -../CODEC2_FREEDV/codebookvqanssi.c \ -../CODEC2_FREEDV/codec2.c \ -../CODEC2_FREEDV/dump.c \ -../CODEC2_FREEDV/fdmdv.c \ -../CODEC2_FREEDV/fifo.c \ -../CODEC2_FREEDV/freedv_api.c \ -../CODEC2_FREEDV/golay23.c \ -../CODEC2_FREEDV/interp.c \ -../CODEC2_FREEDV/kiss_fft.c \ -../CODEC2_FREEDV/lpc.c \ -../CODEC2_FREEDV/lsp.c \ -../CODEC2_FREEDV/nlp.c \ -../CODEC2_FREEDV/pack.c \ -../CODEC2_FREEDV/phase.c \ -../CODEC2_FREEDV/postfilter.c \ -../CODEC2_FREEDV/quantise.c \ -../CODEC2_FREEDV/sine.c \ -../CODEC2_FREEDV/varicode.c - -OBJS += \ -./CODEC2_FREEDV/codebook.o \ -./CODEC2_FREEDV/codebookd.o \ -./CODEC2_FREEDV/codebookdt.o \ -./CODEC2_FREEDV/codebookge.o \ -./CODEC2_FREEDV/codebookjnd.o \ -./CODEC2_FREEDV/codebookjvm.o \ -./CODEC2_FREEDV/codebookvq.o \ -./CODEC2_FREEDV/codebookvqanssi.o \ -./CODEC2_FREEDV/codec2.o \ -./CODEC2_FREEDV/dump.o \ -./CODEC2_FREEDV/fdmdv.o \ -./CODEC2_FREEDV/fifo.o \ -./CODEC2_FREEDV/freedv_api.o \ -./CODEC2_FREEDV/golay23.o \ -./CODEC2_FREEDV/interp.o \ -./CODEC2_FREEDV/kiss_fft.o \ -./CODEC2_FREEDV/lpc.o \ -./CODEC2_FREEDV/lsp.o \ -./CODEC2_FREEDV/nlp.o \ -./CODEC2_FREEDV/pack.o \ -./CODEC2_FREEDV/phase.o \ -./CODEC2_FREEDV/postfilter.o \ -./CODEC2_FREEDV/quantise.o \ -./CODEC2_FREEDV/sine.o \ -./CODEC2_FREEDV/varicode.o - -C_DEPS += \ -./CODEC2_FREEDV/codebook.d \ -./CODEC2_FREEDV/codebookd.d \ -./CODEC2_FREEDV/codebookdt.d \ -./CODEC2_FREEDV/codebookge.d \ -./CODEC2_FREEDV/codebookjnd.d \ -./CODEC2_FREEDV/codebookjvm.d \ -./CODEC2_FREEDV/codebookvq.d \ -./CODEC2_FREEDV/codebookvqanssi.d \ -./CODEC2_FREEDV/codec2.d \ -./CODEC2_FREEDV/dump.d \ -./CODEC2_FREEDV/fdmdv.d \ -./CODEC2_FREEDV/fifo.d \ -./CODEC2_FREEDV/freedv_api.d \ -./CODEC2_FREEDV/golay23.d \ -./CODEC2_FREEDV/interp.d \ -./CODEC2_FREEDV/kiss_fft.d \ -./CODEC2_FREEDV/lpc.d \ -./CODEC2_FREEDV/lsp.d \ -./CODEC2_FREEDV/nlp.d \ -./CODEC2_FREEDV/pack.d \ -./CODEC2_FREEDV/phase.d \ -./CODEC2_FREEDV/postfilter.d \ -./CODEC2_FREEDV/quantise.d \ -./CODEC2_FREEDV/sine.d \ -./CODEC2_FREEDV/varicode.d - - -# Each subdirectory must supply rules for building sources it contributes -CODEC2_FREEDV/%.o: ../CODEC2_FREEDV/%.c - @echo 'Building file: $<' - @echo 'Invoking: GCC C Compiler' - arm-linux-gnueabihf-gcc -static -I"/home/graham/workspace/smartsdr-dsp/DSP_API" -I"/home/graham/workspace/smartsdr-dsp/DSP_API/SmartSDR_Interface" -I"/home/graham/workspace/smartsdr-dsp/DSP_API/CODEC2_FREEDV" -O3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" - @echo 'Finished building: $<' - @echo ' ' - - diff --git a/DSP_API/Release/SmartSDR_Interface/subdir.mk b/DSP_API/Release/SmartSDR_Interface/subdir.mk deleted file mode 100644 index 80b1a54..0000000 --- a/DSP_API/Release/SmartSDR_Interface/subdir.mk +++ /dev/null @@ -1,60 +0,0 @@ -################################################################################ -# Automatically-generated file. Do not edit! -################################################################################ - -# Add inputs and outputs from these tool invocations to the build variables -C_SRCS += \ -../SmartSDR_Interface/cmd_basics.c \ -../SmartSDR_Interface/cmd_engine.c \ -../SmartSDR_Interface/discovery_client.c \ -../SmartSDR_Interface/hal_buffer.c \ -../SmartSDR_Interface/hal_listener.c \ -../SmartSDR_Interface/hal_vita.c \ -../SmartSDR_Interface/io_utils.c \ -../SmartSDR_Interface/sched_waveform.c \ -../SmartSDR_Interface/smartsdr_dsp_api.c \ -../SmartSDR_Interface/status_processor.c \ -../SmartSDR_Interface/traffic_cop.c \ -../SmartSDR_Interface/utils.c \ -../SmartSDR_Interface/vita_output.c - -OBJS += \ -./SmartSDR_Interface/cmd_basics.o \ -./SmartSDR_Interface/cmd_engine.o \ -./SmartSDR_Interface/discovery_client.o \ -./SmartSDR_Interface/hal_buffer.o \ -./SmartSDR_Interface/hal_listener.o \ -./SmartSDR_Interface/hal_vita.o \ -./SmartSDR_Interface/io_utils.o \ -./SmartSDR_Interface/sched_waveform.o \ -./SmartSDR_Interface/smartsdr_dsp_api.o \ -./SmartSDR_Interface/status_processor.o \ -./SmartSDR_Interface/traffic_cop.o \ -./SmartSDR_Interface/utils.o \ -./SmartSDR_Interface/vita_output.o - -C_DEPS += \ -./SmartSDR_Interface/cmd_basics.d \ -./SmartSDR_Interface/cmd_engine.d \ -./SmartSDR_Interface/discovery_client.d \ -./SmartSDR_Interface/hal_buffer.d \ -./SmartSDR_Interface/hal_listener.d \ -./SmartSDR_Interface/hal_vita.d \ -./SmartSDR_Interface/io_utils.d \ -./SmartSDR_Interface/sched_waveform.d \ -./SmartSDR_Interface/smartsdr_dsp_api.d \ -./SmartSDR_Interface/status_processor.d \ -./SmartSDR_Interface/traffic_cop.d \ -./SmartSDR_Interface/utils.d \ -./SmartSDR_Interface/vita_output.d - - -# Each subdirectory must supply rules for building sources it contributes -SmartSDR_Interface/%.o: ../SmartSDR_Interface/%.c - @echo 'Building file: $<' - @echo 'Invoking: GCC C Compiler' - arm-linux-gnueabihf-gcc -static -I"/home/graham/workspace/smartsdr-dsp/DSP_API" -I"/home/graham/workspace/smartsdr-dsp/DSP_API/SmartSDR_Interface" -I"/home/graham/workspace/smartsdr-dsp/DSP_API/CODEC2_FREEDV" -O3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" - @echo 'Finished building: $<' - @echo ' ' - - diff --git a/DSP_API/Release/makefile b/DSP_API/Release/makefile deleted file mode 100644 index 2872af3..0000000 --- a/DSP_API/Release/makefile +++ /dev/null @@ -1,51 +0,0 @@ -################################################################################ -# Automatically-generated file. Do not edit! -################################################################################ - --include ../makefile.init - -RM := rm -rf - -# All of the sources participating in the build are defined here --include sources.mk --include SmartSDR_Interface/subdir.mk --include CODEC2_FREEDV/subdir.mk --include subdir.mk --include objects.mk - -ifneq ($(MAKECMDGOALS),clean) -ifneq ($(strip $(C_DEPS)),) --include $(C_DEPS) -endif -endif - --include ../makefile.defs - -# Add inputs and outputs from these tool invocations to the build variables - -# All Target -all: freedv - -# Tool invocations -freedv: $(OBJS) $(USER_OBJS) - @echo 'Building target: $@' - @echo 'Invoking: GCC C Linker' - arm-linux-gnueabihf-gcc -static -o "freedv" $(OBJS) $(USER_OBJS) $(LIBS) - @echo 'Finished building target: $@' - @echo ' ' - $(MAKE) --no-print-directory post-build - -# Other Targets -clean: - -$(RM) $(OBJS)$(C_DEPS)$(EXECUTABLES) freedv - -@echo ' ' - -post-build: - -@echo 'Install in BeagleBone at /home/debian/bin' - -scp freedv root@192.168.20.33:/home/debian/bin/ - -@echo ' ' - -.PHONY: all clean dependents -.SECONDARY: post-build - --include ../makefile.targets diff --git a/DSP_API/Release/objects.mk b/DSP_API/Release/objects.mk deleted file mode 100644 index 61d364b..0000000 --- a/DSP_API/Release/objects.mk +++ /dev/null @@ -1,8 +0,0 @@ -################################################################################ -# Automatically-generated file. Do not edit! -################################################################################ - -USER_OBJS := - -LIBS := -lm -lpthread -lrt - diff --git a/DSP_API/Release/sources.mk b/DSP_API/Release/sources.mk deleted file mode 100644 index 7dc98a2..0000000 --- a/DSP_API/Release/sources.mk +++ /dev/null @@ -1,19 +0,0 @@ -################################################################################ -# Automatically-generated file. Do not edit! -################################################################################ - -O_SRCS := -C_SRCS := -S_UPPER_SRCS := -OBJ_SRCS := -ASM_SRCS := -OBJS := -C_DEPS := -EXECUTABLES := - -# Every subdirectory with source files must be described here -SUBDIRS := \ -. \ -SmartSDR_Interface \ -CODEC2_FREEDV \ - diff --git a/DSP_API/Release/subdir.mk b/DSP_API/Release/subdir.mk deleted file mode 100644 index d466154..0000000 --- a/DSP_API/Release/subdir.mk +++ /dev/null @@ -1,30 +0,0 @@ -################################################################################ -# Automatically-generated file. Do not edit! -################################################################################ - -# Add inputs and outputs from these tool invocations to the build variables -C_SRCS += \ -../circular_buffer.c \ -../main.c \ -../resampler.c - -OBJS += \ -./circular_buffer.o \ -./main.o \ -./resampler.o - -C_DEPS += \ -./circular_buffer.d \ -./main.d \ -./resampler.d - - -# Each subdirectory must supply rules for building sources it contributes -%.o: ../%.c - @echo 'Building file: $<' - @echo 'Invoking: GCC C Compiler' - arm-linux-gnueabihf-gcc -static -I"/home/graham/workspace/smartsdr-dsp/DSP_API" -I"/home/graham/workspace/smartsdr-dsp/DSP_API/SmartSDR_Interface" -I"/home/graham/workspace/smartsdr-dsp/DSP_API/CODEC2_FREEDV" -O3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" - @echo 'Finished building: $<' - @echo ' ' - - diff --git a/DSP_API/SmartSDR_Interface/sched_waveform.c b/DSP_API/SmartSDR_Interface/sched_waveform.c index 01d189e..485529c 100644 --- a/DSP_API/SmartSDR_Interface/sched_waveform.c +++ b/DSP_API/SmartSDR_Interface/sched_waveform.c @@ -304,52 +304,53 @@ void sched_waveform_setOwnCall1( uint32 slice , const char * owncall1 ) { } void sched_waveform_setOwnCall2( uint32 slice , const char * owncall2 ) { - /* Ignore slice for now */ - char string[10]; - strncpy( string, owncall2, 5 ); - charReplace( string, ' ', ( char ) 0x7F ); - memset( _dstar->outgoing_header.own_call2, ' ', 4 ); /* We limit the copy to the string length so that * we can fill the rest of the string with spaces to * comply with DSTAR */ - uint32 copy_len = strlen( owncall2 ); - - if ( copy_len > 5 ) - copy_len = 5; - - strncpy( _dstar->outgoing_header.own_call2, string, copy_len ); - + memset( _dstar->outgoing_header.own_call2, ' ', 4 ); /* Enforce termination */ _dstar->outgoing_header.own_call2[4] = '\0'; + if (strlen(owncall2) > 0) + { + strncpy( string, owncall2, 4); + string[4] = 0; + charReplace( string, ( char ) 0x7F, ' ' ); + uint32 copy_len = strlen( owncall2 ); + if ( copy_len > 4 ) + copy_len = 4; + strncpy( _dstar->outgoing_header.own_call2, string, copy_len ); + } + dstar_dumpHeader( &( _dstar->outgoing_header ) ); } void sched_waveform_setMessage( uint32 slice, const char * message) { - /* Ignore slice for now */ char string[SLOW_DATA_MESSAGE_LENGTH_BYTES + 1 ]; - strncpy( string, message, SLOW_DATA_MESSAGE_LENGTH_BYTES + 1); - charReplace( string, ' ', ( char ) 0x7F ); - memset(_dstar->slow_encoder->message, ' ', SLOW_DATA_MESSAGE_LENGTH_BYTES); - /* We limit the copy to the string length so that * we can fill the rest of the string with spaces to * comply with DSTAR */ - - uint32 copy_len = strlen( string ); - - if ( copy_len > SLOW_DATA_MESSAGE_LENGTH_BYTES ) - copy_len = SLOW_DATA_MESSAGE_LENGTH_BYTES; - - strncpy(_dstar->slow_encoder->message, string, copy_len); - + memset(_dstar->slow_encoder->message, ' ', SLOW_DATA_MESSAGE_LENGTH_BYTES); /* Enforce termination */ _dstar->slow_encoder->message[SLOW_DATA_MESSAGE_LENGTH_BYTES] = '\0'; + /* Ignore slice for now */ + if (strlen(message) > 0) + { + strncpy( string, message, SLOW_DATA_MESSAGE_LENGTH_BYTES); + string[SLOW_DATA_MESSAGE_LENGTH_BYTES] = 0; + charReplace( string, ( char ) 0x7F, ' ' ); + uint32 copy_len = strlen( string ); + if ( copy_len > SLOW_DATA_MESSAGE_LENGTH_BYTES ) + copy_len = SLOW_DATA_MESSAGE_LENGTH_BYTES; + strncpy(_dstar->slow_encoder->message, string, copy_len); + } + + output( "TX Message: '%s'\n", _dstar->slow_encoder->message ); } void sched_waveform_setFD( int fd ) { @@ -520,8 +521,16 @@ static void * _sched_waveform_thread( void * param ) { for ( j = 0 ; j < nout ; j++ ) cbWriteShort( RX3_cb, speech_out[j] ); } + + if (_dstar->rx_state == END_PATTERN) + { + char msg[64]; + sprintf( msg, "waveform status slice=%d RX=END", _dstar->slice); + tc_sendSmartSDRcommand( msg, FALSE, NULL ); + } } + // Check for >= 160 samples in RX3_cb, convert to floats // and spin the upsampler. Move output to RX4_cb. diff --git a/DSP_API/ThumbDV/dstar.c b/DSP_API/ThumbDV/dstar.c index e3a82bd..300e619 100644 --- a/DSP_API/ThumbDV/dstar.c +++ b/DSP_API/ThumbDV/dstar.c @@ -603,7 +603,8 @@ void dstar_updateStatus( DSTAR_MACHINE machine, uint32 slice, enum STATUS_TYPE } char status[200] = {0}; - char header_string[200] = {0}; + char header_string[256] = {0}; + char message_string[21]; /* Make copy to replace spaces with special char */ @@ -634,19 +635,30 @@ void dstar_updateStatus( DSTAR_MACHINE machine, uint32 slice, enum STATUS_TYPE charReplace( ( char * )h.destination_rptr, ' ', ( char ) 0x7F ); charReplace( ( char * )h.departure_rptr, ' ', ( char ) 0x7F ); - charReplace( ( char * )h.companion_call, ' ', ( char ) 0x7F ); + charReplace((char *) h.companion_call, ' ', ( char ) 0x7F ); charReplace( ( char * )h.own_call1, ' ', ( char ) 0x7F ); charReplace( ( char * )h.own_call2, ' ', ( char ) 0x7F ); sprintf( header_string, "destination_rptr_tx=%s departure_rptr_tx=%s companion_call_tx=%s own_call1_tx=%s own_call2_tx=%s", h.destination_rptr, h.departure_rptr, h.companion_call, h.own_call1, h.own_call2 ); + if (machine->slow_encoder != NULL && machine->slow_encoder->message[0] != 0) + { + memcpy( message_string, machine->slow_encoder->message, sizeof( message_string ) ); + message_string[sizeof( message_string ) - 1] = 0; + charReplace( message_string, ' ', ( char ) 0x7F ); + sprintf( header_string + strlen(header_string), " message_tx=%s", message_string); + } + sprintf( status, "waveform status slice=%d %s", slice, header_string ); tc_sendSmartSDRcommand( status, FALSE, NULL ); break; case STATUS_SLOW_DATA_MESSAGE: - sprintf( status, "waveform status slice=%d message=%s", slice, machine->slow_decoder->message_string); + memcpy( message_string, machine->slow_decoder->message_string, sizeof( message_string ) ); + message_string[sizeof( message_string ) - 1] = 0; + charReplace( message_string, ' ', ( char ) 0x7F ); + sprintf( status, "waveform status slice=%d message=%s", slice, message_string); tc_sendSmartSDRcommand( status, FALSE, NULL ); break; } diff --git a/pc/CODEC2 GUI/CODEC2 GUI/App.config b/pc/CODEC2 GUI/CODEC2 GUI/App.config new file mode 100644 index 0000000..c67a3ad --- /dev/null +++ b/pc/CODEC2 GUI/CODEC2 GUI/App.config @@ -0,0 +1,43 @@ + + + + +
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1000 + + + + diff --git a/pc/CODEC2 GUI/CODEC2 GUI/AssemblyInfo.cs b/pc/CODEC2 GUI/CODEC2 GUI/AssemblyInfo.cs new file mode 100644 index 0000000..a360720 --- /dev/null +++ b/pc/CODEC2 GUI/CODEC2 GUI/AssemblyInfo.cs @@ -0,0 +1,120 @@ +/******************************************************************************* + * AssemblyInfo.cs + * + * Helper class that holds Assembly Info + * + * Created on: 2015-08-23 + * Author: Mark Hanson / AA3RK / MKCM Software, LLC. + * + * + ******************************************************************************* + * + * Copyright (C) 2015 FlexRadio Systems. + * 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 . + * + * Contact: gplflexradiocom or + * + * GPL C/O FlexRadio Systems + * 4616 W. Howard Lane + * Suite 1-150 + * Austin, TX USA 78728 + * + ******************************************************************************/ +using System; +using System.IO; +using System.Reflection; + +namespace CODEC2_GUI +{ + public class AssemblyInfo + { + public AssemblyInfo(Assembly assembly) + { + if (assembly == null) + throw new ArgumentNullException("assembly"); + this.assembly = assembly; + } + + private readonly Assembly assembly; + + /// + /// Gets the title property + /// + public string ProductTitle + { + get + { + return GetAttributeValue(a => a.Title, + Path.GetFileNameWithoutExtension(assembly.CodeBase)); + } + } + + /// + /// Gets the application's version + /// + public string Version + { + get + { + string result = string.Empty; + Version version = assembly.GetName().Version; + if (version != null) + return version.ToString(); + else + return "1.0.0.0"; + } + } + + /// + /// Gets the description about the application. + /// + public string Description + { + get { return GetAttributeValue(a => a.Description); } + } + + + /// + /// Gets the product's full name. + /// + public string Product + { + get { return GetAttributeValue(a => a.Product); } + } + + /// + /// Gets the copyright information for the product. + /// + public string Copyright + { + get { return GetAttributeValue(a => a.Copyright); } + } + + /// + /// Gets the company information for the product. + /// + public string Company + { + get { return GetAttributeValue(a => a.Company); } + } + + protected string GetAttributeValue(Func resolveFunc, string defaultResult = null) where TAttr : Attribute + { + object[] attributes = assembly.GetCustomAttributes(typeof(TAttr), false); + if (attributes.Length > 0) + return resolveFunc((TAttr)attributes[0]); + else + return defaultResult; + } + } +} diff --git a/pc/CODEC2 GUI/CODEC2 GUI/DstarInfo.cs b/pc/CODEC2 GUI/CODEC2 GUI/DstarInfo.cs new file mode 100644 index 0000000..8b18fd7 --- /dev/null +++ b/pc/CODEC2 GUI/CODEC2 GUI/DstarInfo.cs @@ -0,0 +1,524 @@ +/******************************************************************************* + * DstarInfo.cs + * + * Helper class which collects DSTAR information + * + * Created on: 2015-08-22 + * Author: Mark Hanson / AA3RK / MKCM Software, LLC. + * + * + ******************************************************************************* + * + * Copyright (C) 2015 FlexRadio Systems. + * 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 . + * + * Contact: gplflexradiocom or + * + * GPL C/O FlexRadio Systems + * 4616 W. Howard Lane + * Suite 1-150 + * Austin, TX USA 78728 + * + ******************************************************************************/ + + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Net; +using System.Net.Http; +using System.Threading.Tasks; +using System.IO; +using System.Net.Http.Headers; +using System.Reflection; +using System.Xml; + +namespace CODEC2_GUI +{ + public class DstarInfo + { + public DstarInfo() + { + + } + + private static HttpClient _client; + private static HttpClient client + { + get + { + if (_client == null) + _client = new HttpClient() { BaseAddress = new Uri("http://apps.dstarinfo.com") }; + return _client; + } + } + private static string eventvalidation; + private static string viewstate; + private static string viewstategenerator; + + + private List Repeaters_; + public List Repeaters + { + get + { + if (Repeaters_ == null) + { + LoadRepeaters(); + if (Repeaters_ == null) + Repeaters_ = new List(); + + } + return Repeaters_; + } + } + + private List Reflectors_; + public List Refelectors + { + get + { + if (Reflectors_ == null) + { + LoadReflectors(); + if (Reflectors_ == null || Reflectors_.Count == 0) + { + try + { + FetchAndSaveReflectorList(); + } + catch { } + } + } + return Reflectors_; + } + } + + public bool FetchAndSaveRepeaterList(string area) + { + bool result = false; + try + { + List rptrs = GetDStarRepeaterByArea(area); + if (rptrs != null && rptrs.Count > 0) + { + SaveRepeaters(rptrs); + Repeaters_ = rptrs; + result = true; + } + } + catch (Exception ex) + { + string msg = "Fetch and save Repeater list failed!"; + System.Diagnostics.Debug.WriteLine(string.Format("{0} {1}", msg, ex.Message)); + throw new ApplicationException(msg, ex); + } + return result; + } + + public bool FetchAndSaveReflectorList() + { + bool result = false; + try + { + List refs = GetDStarInfoReflectors(); + if (refs != null && refs.Count > 0) + { + SaveReflectors(refs); + Reflectors_ = refs; + result = true; + } + } + catch(Exception ex) + { + string msg = "Fetch and save Relflector list failed!"; + System.Diagnostics.Debug.WriteLine(string.Format("{0} {1}", msg, ex.Message)); + throw new ApplicationException(msg, ex); + } + return result; + } + + public List GetDStarRepeaterAreas() + { + List rptareas = new List(); + string htmlAreas = string.Empty; + + try + { + if (client != null) + { + HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "D-STAR_Repeater_List.aspx"); + Task resp = client.SendAsync(request); + resp.Wait(); + resp.Result.EnsureSuccessStatusCode(); + + Task strm = resp.Result.Content.ReadAsStreamAsync(); + strm.Wait(); + using (StreamReader sr = new StreamReader(strm.Result, System.Text.Encoding.UTF8)) + { + htmlAreas = sr.ReadToEnd(); + } + } + + viewstate = getHiddenValues(htmlAreas, "id=\"__VIEWSTATE\" value=\""); + viewstategenerator = getHiddenValues(htmlAreas, "id=\"__VIEWSTATEGENERATOR\" value=\""); + eventvalidation = getHiddenValues(htmlAreas, "id=\"__EVENTVALIDATION\" value=\""); + + // parsing HTML select of areas + // start by finding "", ofs + 23); + if (ofs2 > 0) + { + string selVals = htmlAreas.Substring(ofs, ofs2 - ofs); + int ofs3 = 0; + int ofs4 = 0; + while (ofs4 < selVals.Length) + { + ofs4 = selVals.IndexOf("