-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f25f6de
commit 4af8718
Showing
13 changed files
with
847 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 15 | ||
VisualStudioVersion = 15.0.27004.2002 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CSV_Converter", "CSV_Converter\CSV_Converter.csproj", "{0885067F-5EA8-4AC0-8644-7809BCF11AB2}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{0885067F-5EA8-4AC0-8644-7809BCF11AB2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{0885067F-5EA8-4AC0-8644-7809BCF11AB2}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{0885067F-5EA8-4AC0-8644-7809BCF11AB2}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{0885067F-5EA8-4AC0-8644-7809BCF11AB2}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {EA3D6233-FDA7-41E4-9EEA-A26B305EB418} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/> | ||
</startup> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{0885067F-5EA8-4AC0-8644-7809BCF11AB2}</ProjectGuid> | ||
<OutputType>WinExe</OutputType> | ||
<RootNamespace>CSV_Converter</RootNamespace> | ||
<AssemblyName>CSV_Converter</AssemblyName> | ||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> | ||
<TargetFrameworkProfile /> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.IO.Compression" /> | ||
<Reference Include="System.IO.Compression.FileSystem" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Deployment" /> | ||
<Reference Include="System.Drawing" /> | ||
<Reference Include="System.Net.Http" /> | ||
<Reference Include="System.Windows.Forms" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Form1.cs"> | ||
<SubType>Form</SubType> | ||
</Compile> | ||
<Compile Include="Form1.Designer.cs"> | ||
<DependentUpon>Form1.cs</DependentUpon> | ||
</Compile> | ||
<Compile Include="Program.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
<EmbeddedResource Include="Form1.resx"> | ||
<DependentUpon>Form1.cs</DependentUpon> | ||
</EmbeddedResource> | ||
<EmbeddedResource Include="Properties\Resources.resx"> | ||
<Generator>ResXFileCodeGenerator</Generator> | ||
<LastGenOutput>Resources.Designer.cs</LastGenOutput> | ||
<SubType>Designer</SubType> | ||
</EmbeddedResource> | ||
<Compile Include="Properties\Resources.Designer.cs"> | ||
<AutoGen>True</AutoGen> | ||
<DependentUpon>Resources.resx</DependentUpon> | ||
<DesignTime>True</DesignTime> | ||
</Compile> | ||
<None Include="Properties\Settings.settings"> | ||
<Generator>SettingsSingleFileGenerator</Generator> | ||
<LastGenOutput>Settings.Designer.cs</LastGenOutput> | ||
</None> | ||
<Compile Include="Properties\Settings.Designer.cs"> | ||
<AutoGen>True</AutoGen> | ||
<DependentUpon>Settings.settings</DependentUpon> | ||
<DesignTimeSharedInput>True</DesignTimeSharedInput> | ||
</Compile> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="App.config" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
</Project> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Data; | ||
using System.Drawing; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows.Forms; | ||
using System.IO; | ||
using System.IO.Compression; | ||
namespace CSV_Converter { | ||
public partial class Form1 : Form { | ||
public Form1() { | ||
InitializeComponent(); | ||
} | ||
private void btn_load_Click(object sender, EventArgs e) { | ||
OpenFileDialog fileDialog = new OpenFileDialog(); | ||
fileDialog.Filter = "CSV & Text|*.txt; *.csv|Alles|*"; | ||
if(fileDialog.ShowDialog() == DialogResult.OK) { | ||
txt_load.Text = fileDialog.FileName; | ||
} | ||
} | ||
private void btn_save_Click(object sender, EventArgs e) { | ||
SaveFileDialog fileDialog = new SaveFileDialog(); | ||
fileDialog.Filter = "SR|*.sr|ZIP|*.zip"; | ||
if (fileDialog.ShowDialog() == DialogResult.OK) { | ||
txt_save.Text = fileDialog.FileName; | ||
} | ||
} | ||
private void btn_start_Click(object sender, EventArgs e) { | ||
string filepath_input = txt_load.Text; | ||
string filepath_output = txt_save.Text; | ||
if (File.Exists(filepath_input)) { | ||
if (File.Exists(filepath_output)) | ||
File.Delete(filepath_output); | ||
ZipArchive zipArchive = ZipFile.Open(filepath_output, ZipArchiveMode.Create); | ||
int file_lenght = File.ReadAllLines(filepath_input).Length; | ||
StreamReader reader = new StreamReader(filepath_input); | ||
string[] parts = reader.ReadLine().Split(','); | ||
int channels = parts.Length - 3; | ||
string[] channel_names = new string[channels]; | ||
for(int i = 0; i < channels; i++) | ||
channel_names[i] = parts[i + 1]; | ||
parts = reader.ReadLine().Split(','); | ||
double frequency; | ||
frequency = 1/ Convert.ToDouble(parts[parts.Length - 1].Replace('.', ',')); | ||
string samplerate = Convert.ToInt32(frequency).ToString() + " Hz"; | ||
ZipArchiveEntry archiveEntry; | ||
StreamWriter streamWriter; // generate some metadata | ||
archiveEntry = zipArchive.CreateEntry("version"); | ||
streamWriter = new StreamWriter(archiveEntry.Open()); | ||
streamWriter.WriteLine("2"); | ||
streamWriter.Close(); | ||
streamWriter.Dispose(); | ||
archiveEntry = zipArchive.CreateEntry("metadata"); | ||
streamWriter = new StreamWriter(archiveEntry.Open()); | ||
streamWriter.WriteLine("[global]"); | ||
streamWriter.WriteLine("[device 1]"); | ||
streamWriter.WriteLine("samplerate = " + samplerate); | ||
streamWriter.WriteLine("total analog = " + channels); | ||
int channel_num = 1; | ||
foreach(string channel_name in channel_names) | ||
streamWriter.WriteLine("analog" + channel_num++ + " = " + channel_name); | ||
streamWriter.WriteLine("unitsize=1"); | ||
streamWriter.Close(); | ||
streamWriter.Dispose(); | ||
int byte_count = 4 * (file_lenght - 2); // generate buffer and other variables | ||
byte[][] analog_output = new byte[channels][]; | ||
for (int i = 0; i < channels; i++) | ||
analog_output[i] = new byte[byte_count]; | ||
int index = 0; | ||
float value; | ||
byte[] b; | ||
while (!reader.EndOfStream) { // convert line by line to float and store values in byte arrays (easy to save) | ||
parts = reader.ReadLine().Split(','); | ||
for (int i = 0; i < channels; i++) { | ||
value = Convert.ToSingle(parts[i + 1].Replace('.', ',')); | ||
b = BitConverter.GetBytes(value); | ||
analog_output[i][index +0] = b[0]; | ||
analog_output[i][index +1] = b[1]; | ||
analog_output[i][index +2] = b[2]; | ||
analog_output[i][index +3] = b[3]; | ||
} | ||
index += 4; | ||
} | ||
Stream stream_analog; // save compressed streams | ||
for (int i = 0; i < channels; i++) { | ||
archiveEntry = zipArchive.CreateEntry("analog-1-" + (i + 1) + "-1"); | ||
stream_analog = archiveEntry.Open(); | ||
stream_analog.Write(analog_output[i], 0, byte_count); | ||
stream_analog.Close(); | ||
} | ||
zipArchive.Dispose(); | ||
} | ||
} | ||
} | ||
} | ||
// in under 100 lines ;-) |
Oops, something went wrong.