Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/Build_VIPM_Library.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ on:
- '**.svg'
- '**.json'
- '**.yml'
- 'c/**'

push:
paths-ignore:
Expand All @@ -27,6 +28,7 @@ on:
- '**.svg'
- '**.json'
- '**.yml'
- 'c/**'

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/Check_Broken_VIs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ on:
- '**.svg'
- '**.json'
- '**.yml'
- 'c/**'

pull_request:
branches:
Expand All @@ -29,6 +30,7 @@ on:
- '**.svg'
- '**.json'
- '**.yml'
- 'c/**'

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
Expand Down
17 changes: 16 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
*.aliases
*.lvlps
*.vip
*.vip

# C / Visual Studio build artefacts (under c/)
c/**/Debug/
c/**/Release/
c/**/x64/
c/**/x86/
c/**/.vs/
c/**/*.user
c/**/*.suo
c/**/*.obj
c/**/*.exe
c/**/*.pdb
c/**/*.ilk
c/**/*.idb
c/**/*.tlog
85 changes: 85 additions & 0 deletions c/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# CSM MassData Parameter Support —— C 语言移植

本目录提供 CSM MassData Parameter Support 插件的 C 语言实现,
接口与 [`addons/MassData-Parameter`](../addons/MassData-Parameter)
中的 LabVIEW VI 一一对应,可与 LabVIEW 端无缝互通。

## 目录结构

```
c/
├── include/csm_massdata.h # 公开 C 接口(中文 Doxygen 注释)
├── src/csm_massdata.c # 跨平台实现(Win32 / POSIX)
├── _test/
│ └── vs/
│ ├── csm_massdata_test.sln # Visual Studio 2026 解决方案
│ ├── csm_massdata_test.vcxproj # 测试工程(按 C 编译)
│ ├── csm_massdata_test.vcxproj.filters
│ └── test_main.c # 独立测试程序
└── README.md # 本文件
```

## 接口对应关系

每个 C 函数都是对应 LabVIEW VI 的逐字翻译:名称相同、参数顺序相同、
语义相同。

| LabVIEW VI | C 函数 |
| --------------------------------------------------- | ----------------------------------------------------- |
| `CSM - Config MassData Parameter Cache Size.vi` | `CSM_ConfigMassDataParameterCacheSize` |
| `CSM - Convert MassData to Argument.vim` | `CSM_ConvertMassDataToArgument` |
| `CSM - Convert MassData to Argument With DataType.vim` | `CSM_ConvertMassDataToArgumentWithDataType` |
| `CSM - Convert Argument to MassData.vim` | `CSM_ConvertArgumentToMassData` |
| `CSM - MassData Data Type String.vi` | `CSM_MassDataDataTypeString` |
| `CSM - MassData Parameter Status.vi` | `CSM_MassDataParameterStatus` |

参考字符串格式与 LabVIEW 端完全相同:

```
<MassData>Start:<N>;Size:<N>[;DataType:<T>]
```

## 构建与运行测试

### Visual Studio 2026(推荐)

1. 用 Visual Studio 2026 打开 `c/_test/vs/csm_massdata_test.sln`。
2. 选择任意配置(例如 `Debug|x64`),按 <kbd>F5</kbd> 启动。
3. 控制台会逐条打印断言结果,并在最后输出 `N/N 个断言通过` 摘要。

工程使用 `v145` 平台工具集(Visual Studio 2026 默认)。

### 命令行(任意支持 C99 的编译器)

```bash
cd c
cc -std=c99 -Wall -Wextra -Iinclude src/csm_massdata.c _test/vs/test_main.c -o csm_test -lpthread
./csm_test
```

Windows 下可用 `cl /I include src\csm_massdata.c _test\vs\test_main.c`,
不需要 `-lpthread`(实现会自动改用 `CRITICAL_SECTION`)。

## 在自己的工程中链接

1. 将 `c/include` 加入工程的头文件搜索路径。
2. 编译并链接 `c/src/csm_massdata.c`(除标准 C 库与 POSIX
平台上的 pthreads 之外没有其它依赖)。
3. `#include "csm_massdata.h"` 后即可调用头文件中文档化的所有函数。

典型的编码 / 解码往返如下:

```c
#include "csm_massdata.h"

double samples[1024] = { /* ... */ };
char arg[CSM_MASSDATA_MAX_ARGUMENT_LEN];
double restored[1024];
size_t restored_size = 0;

CSM_ConfigMassDataParameterCacheSize(64u * 1024u * 1024u); /* 64 MiB 缓冲区 */
CSM_ConvertMassDataToArgumentWithDataType(samples, sizeof(samples),
"1D DBL", arg, sizeof(arg));
/* ... 通过 CSM 总线传递 `arg` ... */
CSM_ConvertArgumentToMassData(arg, restored, sizeof(restored), &restored_size);
```
27 changes: 27 additions & 0 deletions c/_test/vs/csm_massdata_test.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 18
VisualStudioVersion = 18.0.0.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "csm_massdata_test", "csm_massdata_test.vcxproj", "{A1B2C3D4-E5F6-4789-A012-3456789ABCDE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A1B2C3D4-E5F6-4789-A012-3456789ABCDE}.Debug|x64.ActiveCfg = Debug|x64
{A1B2C3D4-E5F6-4789-A012-3456789ABCDE}.Debug|x64.Build.0 = Debug|x64
{A1B2C3D4-E5F6-4789-A012-3456789ABCDE}.Debug|x86.ActiveCfg = Debug|Win32
{A1B2C3D4-E5F6-4789-A012-3456789ABCDE}.Debug|x86.Build.0 = Debug|Win32
{A1B2C3D4-E5F6-4789-A012-3456789ABCDE}.Release|x64.ActiveCfg = Release|x64
{A1B2C3D4-E5F6-4789-A012-3456789ABCDE}.Release|x64.Build.0 = Release|x64
{A1B2C3D4-E5F6-4789-A012-3456789ABCDE}.Release|x86.ActiveCfg = Release|Win32
{A1B2C3D4-E5F6-4789-A012-3456789ABCDE}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
84 changes: 84 additions & 0 deletions c/_test/vs/csm_massdata_test.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>18.0</VCProjectVersion>
<ProjectGuid>{A1B2C3D4-E5F6-4789-A012-3456789ABCDE}</ProjectGuid>
<RootNamespace>csm_massdata_test</RootNamespace>
<Keyword>Win32Proj</Keyword>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)'=='Debug'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v145</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Release'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v145</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>$(ProjectDir)..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<WarningLevel>Level4</WarningLevel>
<LanguageStandard_C>stdc11</LanguageStandard_C>
<CompileAs>CompileAsC</CompileAs>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)'=='Debug'">
<ClCompile>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)'=='Release'">
<ClCompile>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\src\csm_massdata.c" />
<ClCompile Include="test_main.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\include\csm_massdata.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
</Project>
26 changes: 26 additions & 0 deletions c/_test/vs/csm_massdata_test.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{1f3a9e8f-1234-4abc-9def-111111111111}</UniqueIdentifier>
<Extensions>c;cpp</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{1f3a9e8f-1234-4abc-9def-222222222222}</UniqueIdentifier>
<Extensions>h;hpp</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\src\csm_massdata.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="test_main.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\include\csm_massdata.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
Loading
Loading