diff --git a/docs/README.md b/README.md similarity index 100% rename from docs/README.md rename to README.md diff --git a/docs/usage_examples.md b/docs/usage_examples.md index 40f8535..eaf5c42 100644 --- a/docs/usage_examples.md +++ b/docs/usage_examples.md @@ -69,102 +69,56 @@ Console.WriteLine($"大气湍流强度: {turbulence:E2}"); ### 项目配置 1. 在 Visual Studio 中创建新的 C++ 项目 -2. 将 AirTransmission.dll 复制到项目的输出目录(或可执行文件所在目录) -3. 在代码中使用 LoadLibrary 和 GetProcAddress 动态加载 DLL 函数 +2. 将以下文件复制到项目目录: + - `AirTransmission.dll` - 动态链接库文件 + - `include/AirTransmission.h` - 头文件 +3. 在项目设置中添加 include 目录 +4. 在代码中包含头文件并使用导出函数 ### 代码示例 ```cpp -#include +#include "AirTransmission.h" #include -// 定义函数指针类型 -typedef double (__cdecl *CalculateTransmittanceFunc)( - double wavelength, - double distance, - double temperature, - double humidity, - double pressure, - double visibility, - int weatherType -); - -typedef double (__cdecl *CalculateAtmosphericTurbulenceFunc)( - double wavelength, - double distance, - double temperature, - double humidity, - double pressure, - double visibility, - int weatherType -); - int main() { - // 加载 DLL - HMODULE hDll = LoadLibrary(L"AirTransmission.dll"); - if (hDll == NULL) { - std::cout << "无法加载 DLL" << std::endl; - return 1; - } - - // 获取函数地址 - auto calculateTransmittance = (CalculateTransmittanceFunc)GetProcAddress(hDll, "CalculateTransmittance"); - auto calculateTurbulence = (CalculateAtmosphericTurbulenceFunc)GetProcAddress(hDll, "CalculateAtmosphericTurbulence"); - - if (calculateTransmittance == NULL || calculateTurbulence == NULL) { - std::cout << "无法获取函数地址" << std::endl; - FreeLibrary(hDll); - return 1; - } - // 设置参数 double wavelength = 1.064; // 波长(微米) double distance = 1000.0; // 距离(米) double temperature = 20.0; // 温度(摄氏度) - double humidity = 0.65; // 相对湿度(0-1) + double relativeHumidity = 0.65; // 相对湿度(0-1) double pressure = 101.325; // 大气压力(kPa) double visibility = 10000.0; // 能见度(米) - int weatherType = 0; // 天气类型(0=晴天) + int weatherType = WeatherType::Clear; // 天气类型(晴天) // 计算透过率 - double transmittance = calculateTransmittance( - wavelength, distance, temperature, humidity, + double transmittance = CalculateTransmittance( + wavelength, distance, temperature, relativeHumidity, pressure, visibility, weatherType ); std::cout << "透过率: " << transmittance * 100.0 << "%" << std::endl; // 计算湍流影响 - double turbulence = calculateTurbulence( - wavelength, distance, temperature, humidity, + double turbulence = CalculateAtmosphericTurbulence( + wavelength, distance, temperature, relativeHumidity, pressure, visibility, weatherType ); std::cout << "湍流强度: " << turbulence << std::endl; - // 卸载 DLL - FreeLibrary(hDll); return 0; } ``` -## 注意事项 +### 注意事项 -1. 所有浮点数输入都使用 double 类型 -2. 波长单位为微米(μm) -3. 距离单位为米(m) -4. 温度单位为摄氏度(℃) -5. 压力单位为千帕(kPa) -6. 相对湿度范围为 0-1 -7. 确保输入参数在合理范围内: - - 波长:0.2-20 μm - - 距离:> 0 m - - 温度:-40 到 +60 ℃ +1. 确保 AirTransmission.dll 在程序运行目录下 +2. 头文件中已定义了所有必要的类型和函数 +3. 使用 WeatherType 枚举来指定天气类型 +4. 所有浮点数参数都使用 double 类型 +5. 参数单位说明: + - 波长:微米(μm) + - 距离:米(m) + - 温度:摄氏度(℃) - 相对湿度:0-1 - - 压力:80-120 kPa -8. C++ 调用注意事项: - - 确保 DLL 文件在正确的路径下 - - 所有导出函数使用 __cdecl 调用约定 - - 处理好错误情况(DLL 加载失败、函数获取失败等) - - 天气类型枚举值: - - 0 = 晴天 (Clear) - - 1 = 多云 (Cloudy) - - 2 = 雨天 (Rain) + - 压力:千帕(kPa) + - 能见度:米(m) diff --git a/include/AirTransmission.h b/include/AirTransmission.h new file mode 100644 index 0000000..3c06fe8 --- /dev/null +++ b/include/AirTransmission.h @@ -0,0 +1,64 @@ +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +// 天气类型枚举 +enum WeatherType { + Clear = 0, // 晴天 + Cloudy = 1, // 多云 + Rain = 2, // 雨天 + Fog = 3, // 雾天 + Dust = 4, // 沙尘 + Snow = 5 // 雪天 +}; + +// 导出函数声明 +#ifdef _WIN32 + #define DLLEXPORT __declspec(dllimport) +#else + #define DLLEXPORT +#endif + +/// @brief 计算大气透过率 +/// @param wavelength 波长(微米) +/// @param distance 距离(米) +/// @param temperature 温度(摄氏度) +/// @param relativeHumidity 相对湿度(0-1) +/// @param pressure 大气压力(kPa) +/// @param visibility 能见度(米) +/// @param weatherType 天气类型(参见 WeatherType 枚举) +/// @return 大气透过率(0-1) +DLLEXPORT double __cdecl CalculateTransmittance( + double wavelength, + double distance, + double temperature, + double relativeHumidity, + double pressure, + double visibility, + int weatherType +); + +/// @brief 计算大气湍流影响 +/// @param wavelength 波长(微米) +/// @param distance 距离(米) +/// @param temperature 温度(摄氏度) +/// @param relativeHumidity 相对湿度(0-1) +/// @param pressure 大气压力(kPa) +/// @param visibility 能见度(米) +/// @param weatherType 天气类型(参见 WeatherType 枚举) +/// @return 湍流影响系数(0-1) +DLLEXPORT double __cdecl CalculateAtmosphericTurbulence( + double wavelength, + double distance, + double temperature, + double relativeHumidity, + double pressure, + double visibility, + int weatherType +); + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/publish/AirTransmissionLibrary-1.0.0.zip b/publish/AirTransmissionLibrary-1.0.0.zip new file mode 100644 index 0000000..46df64f Binary files /dev/null and b/publish/AirTransmissionLibrary-1.0.0.zip differ diff --git a/release/AirTransmission-API-Doc.pdf b/release/AirTransmission-API-Doc.pdf deleted file mode 100644 index 79d101b..0000000 Binary files a/release/AirTransmission-API-Doc.pdf and /dev/null differ diff --git a/release/AirTransmission-Library.zip b/release/AirTransmission-Library.zip deleted file mode 100644 index f86e223..0000000 Binary files a/release/AirTransmission-Library.zip and /dev/null differ diff --git a/scripts/pack_release.sh b/scripts/pack_release.sh new file mode 100755 index 0000000..371e367 --- /dev/null +++ b/scripts/pack_release.sh @@ -0,0 +1,70 @@ +#!/bin/bash + +# 版本号 +VERSION="1.0.0" +PACKAGE_NAME="AirTransmissionLibrary-${VERSION}" + +# 创建临时目录和发布目录 +rm -rf temp publish +mkdir -p temp/${PACKAGE_NAME}/{lib,include,doc} +mkdir -p publish + +# 编译项目 +echo "Building project..." +dotnet build src/AirTransmission/AirTransmission.csproj -c Release + +# 复制必要文件 +echo "Copying files..." +cp src/AirTransmission/bin/Release/net8.0/AirTransmission.dll temp/${PACKAGE_NAME}/lib/ +cp src/AirTransmission/bin/Release/net8.0/AirTransmission.xml temp/${PACKAGE_NAME}/lib/ +cp include/AirTransmission.h temp/${PACKAGE_NAME}/include/ + +# 生成文档 +echo "Generating documentation..." +docfx metadata docfx.json +docfx build docfx.json +wkhtmltopdf --enable-local-file-access \ + --page-size A4 \ + --margin-top 20 \ + --margin-bottom 20 \ + --margin-left 20 \ + --margin-right 20 \ + --footer-left "大气传输计算库 API 文档" \ + --footer-right "[page]/[topage]" \ + --footer-spacing 8 \ + --user-style-sheet docs/custom.css \ + _site/docs/introduction.html \ + _site/docs/API.html \ + _site/api/AirTransmission.AtmosphericTransmittanceCalculator.html \ + _site/api/AirTransmission.WeatherCondition.html \ + _site/api/AirTransmission.WeatherType.html \ + _site/docs/usage_examples.html \ + temp/${PACKAGE_NAME}/doc/AirTransmission-API-Doc.pdf + +# 创建 README +cat > temp/${PACKAGE_NAME}/README.txt << EOL +大气传输计算库 v${VERSION} + +目录结构: +lib/ - 库文件 + AirTransmission.dll - 主库文件 + AirTransmission.xml - API 文档(用于 IDE 智能提示) +include/ - 头文件 + AirTransmission.h - C++ 头文件 +doc/ - 文档 + AirTransmission-API-Doc.pdf - API 文档 + +使用说明请参考 doc/AirTransmission-API-Doc.pdf +EOL + +# 打包 +echo "Creating package..." +cd temp +zip -r ../publish/${PACKAGE_NAME}.zip ${PACKAGE_NAME} +cd .. + +# 清理临时文件 +echo "Cleaning up..." +rm -rf temp + +echo "Package created at publish/${PACKAGE_NAME}.zip" \ No newline at end of file