├── .gitattributes ├── .github ├── auto_assign.yml ├── dependabot.yml ├── labeler.yml ├── pull_request_template.md └── workflows │ ├── context.yml │ ├── create-merge-pr.yml │ ├── deploy-github-page.yml │ ├── msbuild.yml │ └── on-pull-request.yml ├── .gitignore ├── LICENSE ├── Neosmartpen.Demo ├── App.config ├── Log.cs ├── MainForm.Designer.cs ├── MainForm.cs ├── MainForm.resx ├── Neosmartpen.Net.Demo.csproj ├── PasswordInputForm.Designer.cs ├── PasswordInputForm.cs ├── PasswordInputForm.resx ├── PenCommAgent.cs ├── Program.cs ├── ProgressForm.Designer.cs ├── ProgressForm.cs ├── ProgressForm.resx ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings ├── Renderer.cs ├── Resources │ ├── background.png │ ├── note_603.nproj │ └── shapes1.nproj └── pdf │ └── shapes_pdf4.pdf ├── Neosmartpen.Doc ├── docfx.json ├── images │ ├── favicon.ico │ └── logo.png ├── index.md └── toc.yml ├── Neosmartpen.Net.Usb.Demo ├── DrawingView.Designer.cs ├── DrawingView.cs ├── DrawingView.resx ├── MainForm.Designer.cs ├── MainForm.cs ├── MainForm.resx ├── Neosmartpen.Net.Usb.Demo.csproj ├── OfflineData │ ├── DotData.cs │ ├── DotDataHeader.cs │ ├── OfflineDataReader.cs │ ├── StrokeFileHeader.cs │ └── StrokeRef.cs ├── Program.cs ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings ├── UpdateForm.Designer.cs ├── UpdateForm.cs ├── UpdateForm.resx ├── Util │ ├── MemoryInputStream.cs │ └── MyBitConverter.cs └── app.config ├── Neosmartpen.Net.Usb ├── Neosmarpen │ └── Net │ │ ├── Chunk.cs │ │ ├── Dot.cs │ │ ├── Filter │ │ └── FilterForPaper.cs │ │ ├── OfflineDataStructure.cs │ │ ├── Protocol │ │ └── v1 │ │ │ ├── OfflineData.cs │ │ │ ├── OfflineDataParser.cs │ │ │ ├── OfflineDataSerializer.cs │ │ │ └── OfflineWorker.cs │ │ ├── Stroke.cs │ │ ├── Support │ │ ├── ByteConverter.cs │ │ ├── ByteUtil.cs │ │ ├── PressureCalibration.cs │ │ ├── PressureFilter.cs │ │ ├── Renderer.cs │ │ └── Time.cs │ │ └── Usb │ │ ├── Events │ │ ├── BatteryStatusReceivedEventArgs.cs │ │ ├── ConfigSetupResultReceivedEventArgs.cs │ │ ├── ConnectionStatusChangedEventArgs.cs │ │ ├── DateTimeReceivedEventArgs.cs │ │ ├── FileDownloadResultReceivedEventArgs.cs │ │ ├── FileInfoReceivedEventArgs.cs │ │ ├── FileListReceivedEventArgs.cs │ │ ├── ProgressChangedEventArgs.cs │ │ ├── ResultReceivedEventArgs.cs │ │ ├── StorageStatusReceivedEventArgs.cs │ │ └── UpdateResultReceivedEventArgs.cs │ │ ├── Exceptions │ │ ├── FileCannotLoadException.cs │ │ ├── FileNameIsTooLongException.cs │ │ ├── FirmwareVersionIsTooLongException.cs │ │ ├── IsNotActiveException.cs │ │ ├── NoSuchPenException.cs │ │ ├── NotSupportedVersionException.cs │ │ └── TimeOutOfRangeException.cs │ │ ├── FileBuilder.cs │ │ ├── FileSplitter.cs │ │ ├── Protocol.cs │ │ ├── UsbAdapter.cs │ │ ├── UsbPacket.cs │ │ ├── UsbPenComm.cs │ │ └── UsbProtocolParser.cs ├── Neosmartpen.Net.Usb.csproj └── Properties │ └── AssemblyInfo.cs ├── Neosmartpen.Net ├── Neosmartpen.Net.csproj ├── Neosmartpen │ ├── Framework │ │ └── Net │ │ │ ├── Client │ │ │ ├── IPenClient.cs │ │ │ └── IPenController.cs │ │ │ ├── Data │ │ │ ├── Dot.cs │ │ │ ├── Pds.cs │ │ │ └── Stroke.cs │ │ │ └── IPacket.cs │ └── Implementation │ │ └── Net │ │ ├── Bluetooth │ │ ├── BluetoothPenClient.cs │ │ ├── GenericBluetoothPenClient.cs │ │ ├── Le │ │ │ └── BluetoothLePenClient.cs │ │ └── PenInfomation.cs │ │ ├── Client │ │ ├── Chunk.cs │ │ ├── ChunkEx.cs │ │ ├── DataTransmissionType.cs │ │ ├── Event │ │ │ ├── BatteryAlarmReceivedEventArgs.cs │ │ │ ├── ConnectedEventArgs.cs │ │ │ ├── DotReceivedEventArgs.cs │ │ │ ├── ErrorDetectedEventArgs.cs │ │ │ ├── IPenControllerEvent.cs │ │ │ ├── OfflineDataListReceivedEventArgs.cs │ │ │ ├── OfflineStrokeReceivedEventArgs.cs │ │ │ ├── PasswordRequestedEventArgs.cs │ │ │ ├── PdsReceivedEventArgs.cs │ │ │ ├── PenProfile │ │ │ │ ├── PenProfileCreateEventArgs.cs │ │ │ │ ├── PenProfileDeleteEventArgs.cs │ │ │ │ ├── PenProfileDeleteValueEventArgs.cs │ │ │ │ ├── PenProfileInfoEventArgs.cs │ │ │ │ ├── PenProfileReadValueEventArgs.cs │ │ │ │ ├── PenProfileReceivedEventArgs.cs │ │ │ │ └── PenProfileWriteValueEventArgs.cs │ │ │ ├── PenStatusReceivedEventArgs.cs │ │ │ ├── ProgressChangeEventArgs.cs │ │ │ └── SimpleResultEventArgs.cs │ │ ├── IPenClientParser.cs │ │ ├── ImageProcessErrorInfo.cs │ │ ├── ImageProcessingInfo.cs │ │ ├── OfflineDataStructure.cs │ │ ├── Packet.cs │ │ ├── PenClient.cs │ │ ├── PenCommType.cs │ │ ├── PenController.cs │ │ ├── PenControllerEx.cs │ │ ├── PenProfile.cs │ │ ├── Protocols.cs │ │ ├── UsbMode.cs │ │ ├── Version1 │ │ │ ├── OfflineData.cs │ │ │ ├── OfflineDataParser.cs │ │ │ ├── OfflineDataSerializer.cs │ │ │ ├── OfflineWorker.cs │ │ │ └── PenClientParserV1.cs │ │ └── Version2 │ │ │ └── PenClientParserV2.cs │ │ ├── Encryption │ │ ├── AES256Chiper.cs │ │ ├── PrivateKey.cs │ │ ├── PublicKey.cs │ │ └── RSAChiper.cs │ │ ├── Filter │ │ └── FilterForPaper.cs │ │ └── Support │ │ ├── ByteConverter.cs │ │ ├── ByteUtil.cs │ │ ├── Compression.cs │ │ ├── FloatConverter.cs │ │ ├── PressureCalibration.cs │ │ ├── PressureFilter.cs │ │ └── Time.cs └── Properties │ └── AssemblyInfo.cs ├── NeosmartpenSDK.sln ├── README.md └── google1c521ea3ef54bc08.html /.gitattributes: -------------------------------------------------------------------------------- 1 | Neosmartpen.Doc/* linguist-vendored 2 | -------------------------------------------------------------------------------- /.github/auto_assign.yml: -------------------------------------------------------------------------------- 1 | # Set to true to add reviewers to pull requests 2 | addReviewers: false 3 | 4 | # Set to true to add assignees to pull requests 5 | addAssignees: author 6 | 7 | # A list of team reviewers to be added to pull requests (GitHub team slug) 8 | # reviewers: 9 | # - 10 | 11 | # Number of reviewers has no impact on Github teams 12 | # Set 0 to add all the reviewers (default: 0) 13 | numberOfReviewers: 0 14 | 15 | # A list of assignees, overrides reviewers if set 16 | # assignees: 17 | # - assigneeA 18 | 19 | # A number of assignees to add to the pull request 20 | # Set to 0 to add all of the assignees. 21 | # Uses numberOfReviewers if unset. 22 | # numberOfAssignees: 2 23 | 24 | # A list of keywords to be skipped the process that add reviewers if pull requests include it 25 | # skipKeywords: 26 | # - wip 27 | 28 | # Set to true to enable it to run on draft pull requests 29 | runOnDraft: true 30 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates 5 | 6 | version: 2 7 | updates: 8 | - package-ecosystem: "nuget" # See documentation for possible values 9 | directory: "/" # Location of package manifests 10 | rebase-strategy: "auto" 11 | assignees: 12 | - "chyccs" 13 | reviewers: 14 | - "chyccs" 15 | - "mrlove1" 16 | schedule: 17 | interval: "daily" 18 | time: "09:00" 19 | timezone: "Asia/Seoul" 20 | commit-message: 21 | prefix: "build" 22 | include: "scope" 23 | 24 | - package-ecosystem: "github-actions" 25 | directory: "/" 26 | rebase-strategy: "auto" 27 | assignees: 28 | - "chyccs" 29 | schedule: 30 | interval: "daily" 31 | time: "09:30" 32 | timezone: "Asia/Seoul" 33 | commit-message: 34 | prefix: "build" 35 | include: "scope" 36 | -------------------------------------------------------------------------------- /.github/labeler.yml: -------------------------------------------------------------------------------- 1 | workflows: 2 | - changed-files: 3 | - any-glob-to-any-file: 4 | - .github/workflows/* 5 | 6 | csharp: 7 | - changed-files: 8 | - any-glob-to-any-file: 9 | - "*.cs" 10 | 11 | chore: 12 | - changed-files: 13 | - any-glob-to-any-file: 14 | - .gitattributes 15 | - .gitignore 16 | - .gitconfig 17 | 18 | ui: 19 | - changed-files: 20 | - any-glob-to-any-file: 21 | - "*.xaml" 22 | 23 | resource: 24 | - changed-files: 25 | - any-glob-to-any-file: 26 | - "*.resx" 27 | 28 | manifest: 29 | - changed-files: 30 | - any-glob-to-any-file: 31 | - "*.sln" 32 | - "*.csproj" 33 | 34 | docs: 35 | - changed-files: 36 | - any-glob-to-any-file: 37 | - "*.md" 38 | - "*.html" 39 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | 2 | ## Summary 3 | 4 | 5 | 6 | 7 | ## Remind below lines 8 | 9 | ### Conventional Commits 10 | 11 | ##### 1. Common types 12 | * API relevant changes 13 | * `feat` Commits, that adds a new feature 14 | * `fix` Commits, that fixes a bug 15 | * `refactor` Commits, that rewrite/restructure your code, however does not change any behaviour 16 | * `perf` Commits are special `refactor` commits, that improve performance 17 | * `style` Commits, that do not affect the meaning (white-space, formatting, missing semi-colons, etc) 18 | * `test` Commits, that add missing tests or correcting existing tests 19 | * `docs` Commits, that affect documentation only 20 | * `build` Commits, that affect build components like build tool, ci pipeline, dependencies, project version, ... 21 | * `ops` Commits, that affect operational components like infrastructure, deployment, backup, recovery, ... 22 | * `chore` Miscellaneous commits e.g. modifying `.gitignore` 23 | 24 | ##### 2. Revert Commit 25 | If the commit reverts a previous commit, it should begin with `revert: `, followed by the header of the reverted commit. In the body it should say: `This reverts commit .`, where the hash is the SHA of the commit being reverted. 26 | 27 | ### Merge strategies 28 | * `Create a merge commit` 29 | * `Squash and merge` 30 | -------------------------------------------------------------------------------- /.github/workflows/context.yml: -------------------------------------------------------------------------------- 1 | name: Context testing 2 | on: 3 | push: 4 | pull_request: 5 | 6 | jobs: 7 | dump_contexts_to_log: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - name: Dump GitHub context 11 | id: github_context_step 12 | run: echo '${{ toJSON(github) }}' 13 | - name: Dump job context 14 | run: echo '${{ toJSON(job) }}' 15 | - name: Dump steps context 16 | run: echo '${{ toJSON(steps) }}' 17 | - name: Dump runner context 18 | run: echo '${{ toJSON(runner) }}' 19 | -------------------------------------------------------------------------------- /.github/workflows/create-merge-pr.yml: -------------------------------------------------------------------------------- 1 | name: create-merge-pr 2 | 3 | on: 4 | schedule: 5 | - cron: '0 0 * * 4' 6 | - cron: '0 0 * * 1' 7 | 8 | permissions: 9 | contents: write 10 | pull-requests: write 11 | 12 | jobs: 13 | create-merge-pr: 14 | runs-on: ubuntu-latest 15 | steps: 16 | - uses: actions/checkout@v4 17 | 18 | - name: Set up Node 19 | uses: actions/setup-node@v4 20 | with: 21 | node-version: 12 22 | 23 | - name: Create Sync PR Master into Staging 24 | if: github.event.schedule == '0 0 * * 1' 25 | uses: tretuna/sync-branches@1.4.0 26 | with: 27 | GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} 28 | FROM_BRANCH: "master" 29 | TO_BRANCH: "staging" 30 | PULL_REQUEST_TITLE: "ops: merge `master` into `staging`" 31 | CONTENT_COMPARISON: true 32 | 33 | - name: Create Sync PR Staging into Prod 34 | if: github.event.schedule == '0 0 * * 5' 35 | uses: tretuna/sync-branches@1.4.0 36 | with: 37 | GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} 38 | FROM_BRANCH: "staging" 39 | TO_BRANCH: "prod" 40 | PULL_REQUEST_TITLE: "ops: merge `staging` into `prod`" 41 | CONTENT_COMPARISON: true 42 | -------------------------------------------------------------------------------- /.github/workflows/deploy-github-page.yml: -------------------------------------------------------------------------------- 1 | name: deploy-github-page 2 | # Your GitHub workflow file under .github/workflows/ 3 | # Trigger the action on push to main 4 | on: 5 | push: 6 | branches: 7 | - master 8 | 9 | # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages 10 | permissions: 11 | actions: read 12 | pages: write 13 | id-token: write 14 | 15 | # Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. 16 | # However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. 17 | concurrency: 18 | group: "pages" 19 | cancel-in-progress: false 20 | 21 | jobs: 22 | publish-docs: 23 | environment: 24 | name: github-pages 25 | url: ${{ steps.deployment.outputs.page_url }} 26 | runs-on: windows-latest 27 | steps: 28 | - name: Checkout 29 | uses: actions/checkout@v4 30 | 31 | - name: Dotnet Setup 32 | uses: actions/setup-dotnet@v4 33 | with: 34 | dotnet-version: "8.x" 35 | 36 | - run: dotnet tool update -g docfx 37 | - run: docfx Neosmartpen.Doc/docfx.json --verbose 38 | 39 | - name: Upload artifact 40 | uses: actions/upload-pages-artifact@v3 41 | with: 42 | path: 'Neosmartpen.Doc/_site' 43 | 44 | - name: Deploy to GitHub Pages 45 | id: deployment 46 | uses: actions/deploy-pages@v4 47 | -------------------------------------------------------------------------------- /.github/workflows/msbuild.yml: -------------------------------------------------------------------------------- 1 | name: MSBuild 2 | 3 | on: 4 | pull_request: 5 | 6 | env: 7 | SOLUTION_FILE_PATH: . 8 | BUILD_CONFIGURATION: Release 9 | 10 | permissions: 11 | contents: read 12 | 13 | jobs: 14 | 15 | build: 16 | runs-on: windows-2019 17 | steps: 18 | - uses: actions/checkout@v4 19 | with: 20 | ref: ${{ github.ref }} 21 | fetch-depth: 1 22 | 23 | - name: Add MSBuild to PATH 24 | uses: microsoft/setup-msbuild@v2.0.0 25 | with: 26 | vs-version: '16.11' 27 | 28 | - id: cache-nuget 29 | uses: actions/cache@v4 30 | with: 31 | path: | 32 | .nuget/packages 33 | packages 34 | ~/packages 35 | ~/.nuget/packages 36 | **/obj/*.csproj.nuget.* 37 | **/obj/project.* 38 | key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj', '**/packages.config') }} 39 | 40 | - name: Restore NuGet packages 41 | if: steps.cache-nuget.outputs.cache-hit != 'true' 42 | working-directory: ${{env.GITHUB_WORKSPACE}} 43 | run: nuget restore ${{env.SOLUTION_FILE_PATH}} 44 | 45 | - name: Build 46 | working-directory: ${{env.GITHUB_WORKSPACE}} 47 | run: | 48 | msbuild /m:2 /p:Configuration=${{env.BUILD_CONFIGURATION}} ${{env.SOLUTION_FILE_PATH}} 49 | -------------------------------------------------------------------------------- /.github/workflows/on-pull-request.yml: -------------------------------------------------------------------------------- 1 | name: on-pull-request-action 2 | 3 | on: 4 | pull_request: 5 | 6 | permissions: 7 | contents: write 8 | issues: write 9 | pull-requests: write 10 | 11 | jobs: 12 | add_assignee: 13 | runs-on: ubuntu-latest 14 | steps: 15 | - uses: kentaro-m/auto-assign-action@v2.0.0 16 | continue-on-error: true 17 | 18 | label: 19 | runs-on: ubuntu-latest 20 | steps: 21 | - uses: actions/labeler@v5 22 | continue-on-error: true 23 | with: 24 | repo-token: "${{ secrets.GITHUB_TOKEN }}" 25 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | [Gg]enerated Files/ 19 | x64/ 20 | x86/ 21 | build/ 22 | bld/ 23 | [Bb]in/ 24 | [Oo]bj/ 25 | 26 | # Visual Studo 2015 cache/options directory 27 | .vs/ 28 | 29 | # MSTest test Results 30 | [Tt]est[Rr]esult*/ 31 | [Bb]uild[Ll]og.* 32 | 33 | # NUNIT 34 | *.VisualState.xml 35 | TestResult.xml 36 | 37 | # Build Results of an ATL Project 38 | [Dd]ebugPS/ 39 | [Rr]eleasePS/ 40 | dlldata.c 41 | 42 | *_i.c 43 | *_p.c 44 | *_i.h 45 | *.ilk 46 | *.meta 47 | *.obj 48 | *.pch 49 | *.pdb 50 | *.pgc 51 | *.pgd 52 | *.rsp 53 | *.sbr 54 | *.tlb 55 | *.tli 56 | *.tlh 57 | *.tmp 58 | *.tmp_proj 59 | *.log 60 | *.vspscc 61 | *.vssscc 62 | .builds 63 | *.pidb 64 | *.svclog 65 | *.scc 66 | 67 | # Chutzpah Test files 68 | _Chutzpah* 69 | 70 | # Visual C++ cache files 71 | ipch/ 72 | *.aps 73 | *.ncb 74 | *.opensdf 75 | *.sdf 76 | *.cachefile 77 | *.VC.db 78 | *.VC.VC.opendb 79 | 80 | # Visual Studio profiler 81 | *.psess 82 | *.vsp 83 | *.vspx 84 | 85 | # TFS 2012 Local Workspace 86 | $tf/ 87 | 88 | # Guidance Automation Toolkit 89 | *.gpState 90 | 91 | # ReSharper is a .NET coding add-in 92 | _ReSharper*/ 93 | *.[Rr]e[Ss]harper 94 | *.DotSettings.user 95 | 96 | # JustCode is a .NET coding addin-in 97 | .JustCode 98 | 99 | # TeamCity is a build add-in 100 | _TeamCity* 101 | 102 | # DotCover is a Code Coverage Tool 103 | *.dotCover 104 | 105 | # NCrunch 106 | _NCrunch_* 107 | .*crunch*.local.xml 108 | 109 | # MightyMoose 110 | *.mm.* 111 | AutoTest.Net/ 112 | 113 | # Web workbench (sass) 114 | .sass-cache/ 115 | 116 | # Installshield output folder 117 | [Ee]xpress/ 118 | 119 | # DocProject is a documentation generator add-in 120 | DocProject/buildhelp/ 121 | DocProject/Help/*.HxT 122 | DocProject/Help/*.HxC 123 | DocProject/Help/*.hhc 124 | DocProject/Help/*.hhk 125 | DocProject/Help/*.hhp 126 | DocProject/Help/Html2 127 | DocProject/Help/html 128 | 129 | # Click-Once directory 130 | publish/ 131 | 132 | # Publish Web Output 133 | *.[Pp]ublish.xml 134 | *.azurePubxml 135 | # TODO: Comment the next line if you want to checkin your web deploy settings 136 | # but database connection strings (with potential passwords) will be unencrypted 137 | *.pubxml 138 | *.publishproj 139 | 140 | # NuGet Packages 141 | *.nupkg 142 | # The packages folder can be ignored because of Package Restore 143 | **/packages/* 144 | # except build/, which is used as an MSBuild target. 145 | !**/packages/build/ 146 | # Uncomment if necessary however generally it will be regenerated when needed 147 | #!**/packages/repositories.config 148 | 149 | # Windows Azure Build Output 150 | csx/ 151 | *.build.csdef 152 | 153 | # Windows Store app package directory 154 | AppPackages/ 155 | 156 | # Others 157 | *.[Cc]ache 158 | ClientBin/ 159 | [Ss]tyle[Cc]op.* 160 | ~$* 161 | *~ 162 | *.dbmdl 163 | *.dbproj.schemaview 164 | *.pfx 165 | *.publishsettings 166 | node_modules/ 167 | bower_components/ 168 | 169 | # RIA/Silverlight projects 170 | Generated_Code/ 171 | 172 | # Backup & report files from converting an old project file 173 | # to a newer Visual Studio version. Backup files are not needed, 174 | # because we have git ;-) 175 | _UpgradeReport_Files/ 176 | Backup*/ 177 | UpgradeLog*.XML 178 | UpgradeLog*.htm 179 | 180 | # SQL Server files 181 | *.mdf 182 | *.ldf 183 | 184 | # Business Intelligence projects 185 | *.rdl.data 186 | *.bim.layout 187 | *.bim_*.settings 188 | 189 | # Microsoft Fakes 190 | FakesAssemblies/ 191 | 192 | # Node.js Tools for Visual Studio 193 | .ntvs_analysis.dat 194 | 195 | # Visual Studio 6 build log 196 | *.plg 197 | 198 | # Visual Studio 6 workspace options file 199 | *.opt 200 | 201 | # Custom ignores 202 | gallery.xml 203 | MigrationBackup 204 | Neosmartpen.Doc/_site 205 | Neosmartpen.Doc/api 206 | Neosmartpen.Doc/docs 207 | -------------------------------------------------------------------------------- /Neosmartpen.Demo/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Neosmartpen.Demo/Log.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Windows.Forms; 8 | 9 | namespace PenDemo 10 | { 11 | class Log 12 | { 13 | public static void FileLog(){ 14 | 15 | String path = Application.StartupPath; 16 | Stream debugFile = File.Create(path + "\\PEN_debug.log.txt"); 17 | TextWriterTraceListener debugWriter = new TextWriterTraceListener(debugFile, "file"); 18 | 19 | Debug.Listeners.Add(debugWriter); 20 | Debug.Listeners["file"].TraceOutputOptions |= TraceOptions.Callstack; 21 | Debug.AutoFlush = true; 22 | 23 | Stream logFile = File.Create(path + "\\PEN_consol.log.txt"); 24 | StreamWriter logWriter = new StreamWriter(logFile); 25 | logWriter.AutoFlush = true; 26 | Console.SetOut(logWriter); 27 | 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Neosmartpen.Demo/PasswordInputForm.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace PenDemo 2 | { 3 | partial class PasswordInputForm 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose( bool disposing ) 15 | { 16 | if ( disposing && ( components != null ) ) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose( disposing ); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.PasswordTextbox = new System.Windows.Forms.TextBox(); 32 | this.btnSubmit = new System.Windows.Forms.Button(); 33 | this.groupBox1 = new System.Windows.Forms.GroupBox(); 34 | this.label1 = new System.Windows.Forms.Label(); 35 | this.StatusLabel = new System.Windows.Forms.Label(); 36 | this.groupBox1.SuspendLayout(); 37 | this.SuspendLayout(); 38 | // 39 | // tbPassword 40 | // 41 | this.PasswordTextbox.Location = new System.Drawing.Point(16, 25); 42 | this.PasswordTextbox.Name = "tbPassword"; 43 | this.PasswordTextbox.Size = new System.Drawing.Size(124, 21); 44 | this.PasswordTextbox.TabIndex = 2; 45 | // 46 | // btnSubmit 47 | // 48 | this.btnSubmit.Location = new System.Drawing.Point(149, 24); 49 | this.btnSubmit.Name = "btnSubmit"; 50 | this.btnSubmit.Size = new System.Drawing.Size(75, 23); 51 | this.btnSubmit.TabIndex = 4; 52 | this.btnSubmit.Text = "Submit"; 53 | this.btnSubmit.UseVisualStyleBackColor = true; 54 | this.btnSubmit.Click += new System.EventHandler(this.btnSubmit_Click); 55 | // 56 | // groupBox1 57 | // 58 | this.groupBox1.Controls.Add(this.StatusLabel); 59 | this.groupBox1.Controls.Add(this.label1); 60 | this.groupBox1.Controls.Add(this.PasswordTextbox); 61 | this.groupBox1.Controls.Add(this.btnSubmit); 62 | this.groupBox1.Location = new System.Drawing.Point(5, 5); 63 | this.groupBox1.Name = "groupBox1"; 64 | this.groupBox1.Size = new System.Drawing.Size(237, 85); 65 | this.groupBox1.TabIndex = 5; 66 | this.groupBox1.TabStop = false; 67 | this.groupBox1.Text = "Input your password"; 68 | // 69 | // label1 70 | // 71 | this.label1.AutoSize = true; 72 | this.label1.Font = new System.Drawing.Font("굴림", 8F); 73 | this.label1.ForeColor = System.Drawing.Color.DarkRed; 74 | this.label1.Location = new System.Drawing.Point(18, 70); 75 | this.label1.Name = "label1"; 76 | this.label1.Size = new System.Drawing.Size(156, 11); 77 | this.label1.TabIndex = 5; 78 | this.label1.Text = "* Default Password is 0000"; 79 | // 80 | // statusLabel 81 | // 82 | this.StatusLabel.AutoSize = true; 83 | this.StatusLabel.Location = new System.Drawing.Point(18, 49); 84 | this.StatusLabel.Name = "statusLabel"; 85 | this.StatusLabel.Size = new System.Drawing.Size(23, 12); 86 | this.StatusLabel.TabIndex = 6; 87 | this.StatusLabel.Text = "1/1"; 88 | // 89 | // PasswordInputForm 90 | // 91 | this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F); 92 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 93 | this.ClientSize = new System.Drawing.Size(245, 93); 94 | this.ControlBox = false; 95 | this.Controls.Add(this.groupBox1); 96 | this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; 97 | this.MaximizeBox = false; 98 | this.MinimizeBox = false; 99 | this.Name = "PasswordInputForm"; 100 | this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; 101 | this.Text = "Password"; 102 | this.groupBox1.ResumeLayout(false); 103 | this.groupBox1.PerformLayout(); 104 | this.ResumeLayout(false); 105 | 106 | } 107 | 108 | #endregion 109 | 110 | private System.Windows.Forms.TextBox PasswordTextbox; 111 | private System.Windows.Forms.Button btnSubmit; 112 | private System.Windows.Forms.GroupBox groupBox1; 113 | private System.Windows.Forms.Label label1; 114 | private System.Windows.Forms.Label StatusLabel; 115 | } 116 | } -------------------------------------------------------------------------------- /Neosmartpen.Demo/PasswordInputForm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows.Forms; 3 | 4 | namespace PenDemo 5 | { 6 | public partial class PasswordInputForm : Form 7 | { 8 | public delegate void OnEnterPassword(string password); 9 | 10 | private OnEnterPassword OnEntererdPassword; 11 | 12 | public PasswordInputForm(OnEnterPassword dele) 13 | { 14 | InitializeComponent(); 15 | OnEntererdPassword = dele; 16 | } 17 | 18 | public void SetStatus(int retryCount, int resetCount) 19 | { 20 | StatusLabel.Text = retryCount + "/" + resetCount; 21 | } 22 | 23 | private void btnSubmit_Click(object sender, EventArgs e) 24 | { 25 | if (PasswordTextbox.Text == "") 26 | { 27 | MessageBox.Show("Your device is locked.\r\nEnter your password to unlock it."); 28 | return; 29 | } 30 | 31 | Close(); 32 | OnEntererdPassword(PasswordTextbox.Text); 33 | PasswordTextbox.Text = ""; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Neosmartpen.Demo/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows.Forms; 3 | 4 | namespace PenDemo 5 | { 6 | static class Program 7 | { 8 | /// 9 | /// 해당 응용 프로그램의 주 진입점입니다. 10 | /// 11 | [STAThread] 12 | static void Main() 13 | { 14 | Application.EnableVisualStyles(); 15 | Application.SetCompatibleTextRenderingDefault( false ); 16 | Application.Run( new MainForm() ); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Neosmartpen.Demo/ProgressForm.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace PenDemo 2 | { 3 | partial class ProgressForm 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose( bool disposing ) 15 | { 16 | if ( disposing && ( components != null ) ) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose( disposing ); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.progressBar1 = new System.Windows.Forms.ProgressBar(); 32 | this.label1 = new System.Windows.Forms.Label(); 33 | this.SuspendLayout(); 34 | // 35 | // progressBar1 36 | // 37 | this.progressBar1.Location = new System.Drawing.Point(26, 12); 38 | this.progressBar1.Name = "progressBar1"; 39 | this.progressBar1.Size = new System.Drawing.Size(544, 23); 40 | this.progressBar1.TabIndex = 0; 41 | // 42 | // label1 43 | // 44 | this.label1.AutoSize = true; 45 | this.label1.Location = new System.Drawing.Point(28, 41); 46 | this.label1.Name = "label1"; 47 | this.label1.Size = new System.Drawing.Size(0, 12); 48 | this.label1.TabIndex = 1; 49 | this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; 50 | // 51 | // ProgressForm 52 | // 53 | this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F); 54 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 55 | this.ClientSize = new System.Drawing.Size(594, 63); 56 | this.ControlBox = false; 57 | this.Controls.Add(this.label1); 58 | this.Controls.Add(this.progressBar1); 59 | this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; 60 | this.MaximizeBox = false; 61 | this.MinimizeBox = false; 62 | this.Name = "ProgressForm"; 63 | this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; 64 | this.Text = "ProgressForm"; 65 | this.ResumeLayout(false); 66 | this.PerformLayout(); 67 | 68 | } 69 | 70 | #endregion 71 | 72 | private System.Windows.Forms.ProgressBar progressBar1; 73 | private System.Windows.Forms.Label label1; 74 | } 75 | } -------------------------------------------------------------------------------- /Neosmartpen.Demo/ProgressForm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows.Forms; 3 | 4 | namespace PenDemo 5 | { 6 | public partial class ProgressForm : Form 7 | { 8 | public ProgressForm() 9 | { 10 | InitializeComponent(); 11 | } 12 | 13 | public void SetStatus( string title, int total, int amountDone ) 14 | { 15 | Text = title; 16 | 17 | progressBar1.Maximum = total; 18 | progressBar1.Value = amountDone > total ? total : amountDone; 19 | 20 | label1.Text = total == 0 && amountDone == 0 ? "" : String.Format( "( {0} / {1} )", amountDone, total ); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Neosmartpen.Demo/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 어셈블리의 일반 정보는 다음 특성 집합을 통해 제어됩니다. 6 | // 어셈블리와 관련된 정보를 수정하려면 7 | // 이 특성 값을 변경하십시오. 8 | [assembly: AssemblyTitle( "Neosmartpen.Demo" )] 9 | [assembly: AssemblyDescription( "" )] 10 | [assembly: AssemblyConfiguration( "" )] 11 | [assembly: AssemblyCompany( "" )] 12 | [assembly: AssemblyProduct( "Neosmartpen.Demo" )] 13 | [assembly: AssemblyCopyright( "Copyright © 2014" )] 14 | [assembly: AssemblyTrademark( "" )] 15 | [assembly: AssemblyCulture( "" )] 16 | 17 | // ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에 18 | // 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면 19 | // 해당 형식에 대해 ComVisible 특성을 true로 설정하십시오. 20 | [assembly: ComVisible( false )] 21 | 22 | // 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다. 23 | [assembly: Guid( "d882b3ce-f4e3-4c85-b489-6f0bea1e17ff" )] 24 | 25 | // 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다. 26 | // 27 | // 주 버전 28 | // 부 버전 29 | // 빌드 번호 30 | // 수정 버전 31 | // 32 | // 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 버전이 자동으로 33 | // 지정되도록 할 수 있습니다. 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion( "1.0.0.*" )] 36 | [assembly: AssemblyFileVersion( "1.0.0" )] 37 | -------------------------------------------------------------------------------- /Neosmartpen.Demo/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 이 코드는 도구를 사용하여 생성되었습니다. 4 | // 런타임 버전:4.0.30319.42000 5 | // 6 | // 파일 내용을 변경하면 잘못된 동작이 발생할 수 있으며, 코드를 다시 생성하면 7 | // 이러한 변경 내용이 손실됩니다. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace PenDemo.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// 지역화된 문자열 등을 찾기 위한 강력한 형식의 리소스 클래스입니다. 17 | /// 18 | // 이 클래스는 ResGen 또는 Visual Studio와 같은 도구를 통해 StronglyTypedResourceBuilder 19 | // 클래스에서 자동으로 생성되었습니다. 20 | // 멤버를 추가하거나 제거하려면 .ResX 파일을 편집한 다음 /str 옵션을 사용하여 ResGen을 21 | // 다시 실행하거나 VS 프로젝트를 다시 빌드하십시오. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// 이 클래스에서 사용하는 캐시된 ResourceManager 인스턴스를 반환합니다. 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("PenDemo.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// 이 강력한 형식의 리소스 클래스를 사용하여 모든 리소스 조회에 대해 현재 스레드의 CurrentUICulture 속성을 51 | /// 재정의합니다. 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | 63 | /// 64 | /// System.Drawing.Bitmap 형식의 지역화된 리소스를 찾습니다. 65 | /// 66 | internal static System.Drawing.Bitmap background { 67 | get { 68 | object obj = ResourceManager.GetObject("background", resourceCulture); 69 | return ((System.Drawing.Bitmap)(obj)); 70 | } 71 | } 72 | 73 | /// 74 | /// System.Byte[] 형식의 지역화된 리소스를 찾습니다. 75 | /// 76 | internal static byte[] note_603 { 77 | get { 78 | object obj = ResourceManager.GetObject("note_603", resourceCulture); 79 | return ((byte[])(obj)); 80 | } 81 | } 82 | 83 | /// 84 | /// System.Byte[] 형식의 지역화된 리소스를 찾습니다. 85 | /// 86 | internal static byte[] shapes1 { 87 | get { 88 | object obj = ResourceManager.GetObject("shapes1", resourceCulture); 89 | return ((byte[])(obj)); 90 | } 91 | } 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /Neosmartpen.Demo/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 이 코드는 도구를 사용하여 생성되었습니다. 4 | // 런타임 버전:4.0.30319.42000 5 | // 6 | // 파일 내용을 변경하면 잘못된 동작이 발생할 수 있으며, 코드를 다시 생성하면 7 | // 이러한 변경 내용이 손실됩니다. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace PenDemo.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.11.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Neosmartpen.Demo/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Neosmartpen.Demo/Resources/background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeoSmartpen/Windows-SDK2.0/b47218567fa286f49391c130e187a0c7397791f1/Neosmartpen.Demo/Resources/background.png -------------------------------------------------------------------------------- /Neosmartpen.Demo/pdf/shapes_pdf4.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeoSmartpen/Windows-SDK2.0/b47218567fa286f49391c130e187a0c7397791f1/Neosmartpen.Demo/pdf/shapes_pdf4.pdf -------------------------------------------------------------------------------- /Neosmartpen.Doc/docfx.json: -------------------------------------------------------------------------------- 1 | { 2 | "metadata": [ 3 | { 4 | "src": [ 5 | { 6 | "src": "../Neosmartpen.Net", 7 | "files": [ 8 | "**/*.csproj" 9 | ] 10 | } 11 | ], 12 | "dest": "api", 13 | "shouldSkipMarkup": true, 14 | "allowCompilationErrors": true 15 | } 16 | ], 17 | "build": { 18 | "content": [ 19 | { 20 | "files": [ 21 | "**/*.{md,yml}" 22 | ], 23 | "exclude": [ 24 | "_site/**" 25 | ] 26 | } 27 | ], 28 | "resource": [ 29 | { 30 | "files": [ 31 | "images/**" 32 | ] 33 | } 34 | ], 35 | "output": "_site", 36 | "template": [ 37 | "modern", 38 | "default" 39 | ], 40 | "globalMetadata": { 41 | "_appName": "Neo smartpen SDK for Windows Platform", 42 | "_appLogoPath": "images/logo.png", 43 | "_appFaviconPath": "images/favicon.ico", 44 | "_enableSearch": true, 45 | "pdf": false 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /Neosmartpen.Doc/images/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeoSmartpen/Windows-SDK2.0/b47218567fa286f49391c130e187a0c7397791f1/Neosmartpen.Doc/images/favicon.ico -------------------------------------------------------------------------------- /Neosmartpen.Doc/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeoSmartpen/Windows-SDK2.0/b47218567fa286f49391c130e187a0c7397791f1/Neosmartpen.Doc/images/logo.png -------------------------------------------------------------------------------- /Neosmartpen.Doc/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | _layout: landing 3 | --- 4 | 5 | [!INCLUDE [readme](../README.md)] 6 | -------------------------------------------------------------------------------- /Neosmartpen.Doc/toc.yml: -------------------------------------------------------------------------------- 1 | - name: API 2 | href: api/ 3 | -------------------------------------------------------------------------------- /Neosmartpen.Net.Usb.Demo/Neosmartpen.Net.Usb.Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {AFB4D5E0-AB19-4823-BC5C-4D612E85454F} 8 | WinExe 9 | Neosmartpen.Net.Usb.Demo 10 | Neosmartpen.Net.Usb.Demo 11 | v4.6.2 12 | 512 13 | true 14 | 15 | 16 | 17 | AnyCPU 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | false 26 | 27 | 28 | AnyCPU 29 | pdbonly 30 | true 31 | bin\Release\ 32 | TRACE 33 | prompt 34 | 4 35 | false 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | Form 52 | 53 | 54 | DrawingView.cs 55 | 56 | 57 | Form 58 | 59 | 60 | MainForm.cs 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | Form 71 | 72 | 73 | UpdateForm.cs 74 | 75 | 76 | 77 | 78 | DrawingView.cs 79 | 80 | 81 | MainForm.cs 82 | 83 | 84 | ResXFileCodeGenerator 85 | Resources.Designer.cs 86 | Designer 87 | 88 | 89 | True 90 | Resources.resx 91 | True 92 | 93 | 94 | UpdateForm.cs 95 | 96 | 97 | 98 | SettingsSingleFileGenerator 99 | Settings.Designer.cs 100 | 101 | 102 | True 103 | Settings.settings 104 | True 105 | 106 | 107 | 108 | 109 | {ac2123a7-b4a3-4998-9713-235dd916f93c} 110 | Neosmartpen.Net.Usb 111 | 112 | 113 | 114 | -------------------------------------------------------------------------------- /Neosmartpen.Net.Usb.Demo/OfflineData/DotData.cs: -------------------------------------------------------------------------------- 1 | using Neosmartpen.Net.Usb.Demo.Util; 2 | using System.IO; 3 | 4 | namespace Neosmartpen.Net.Usb.Demo.OfflineData 5 | { 6 | class DotData 7 | { 8 | public static readonly int length = 16; 9 | 10 | public byte timestampDelta; 11 | public short force; //0~1023 12 | public int x, y, fx, fy; //x 3byte, y 3byte 13 | public byte xTilt, yTilt; //reserved 14 | public short twist; //reserved 15 | public byte labelCount; //reserved 16 | public byte brightnessAndProcessTime; //reserved 17 | public byte checkSum; 18 | public bool isLittleEndian = false; 19 | 20 | public DotData(bool isLittleEndian) 21 | { 22 | this.isLittleEndian = isLittleEndian; 23 | } 24 | 25 | public bool readFromStream(FileStream stream) 26 | { 27 | byte[] buffer = new byte[length]; 28 | int result = stream.Read(buffer, 0, buffer.Length); 29 | 30 | if (result != buffer.Length) 31 | return false; 32 | 33 | MemoryInputStream ms = new MemoryInputStream(buffer, isLittleEndian); 34 | 35 | timestampDelta = (byte)ms.ReadByte(); 36 | force = ms.readInt16(); 37 | 38 | x = ms.readInt16() & 0xffff; 39 | y = ms.readInt16() & 0xffff; 40 | fx = ms.ReadByte() & 0xff; 41 | fy = ms.ReadByte() & 0xff; 42 | 43 | xTilt = (byte)ms.ReadByte(); 44 | yTilt = (byte)ms.ReadByte(); 45 | twist = ms.readInt16(); 46 | labelCount = (byte)ms.ReadByte(); 47 | brightnessAndProcessTime = (byte)ms.ReadByte(); 48 | checkSum = (byte)ms.ReadByte(); 49 | 50 | byte sum = ms.getByteCheckSum(0, buffer.Length - 1); 51 | return (sum == checkSum); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Neosmartpen.Net.Usb.Demo/OfflineData/DotDataHeader.cs: -------------------------------------------------------------------------------- 1 | using Neosmartpen.Net.Usb.Demo.Util; 2 | using System.IO; 3 | 4 | namespace Neosmartpen.Net.Usb.Demo.OfflineData 5 | { 6 | class DotDataHeader 7 | { 8 | public static readonly int length = 32; 9 | 10 | public byte fileType; 11 | public short version; 12 | public short fileNumber; //reserved 13 | public int sectionId, ownerId, noteId; //Int64 notebookId 14 | public byte[] macAddress = new byte[6]; 15 | public byte[] reserved = new byte[12]; 16 | public byte checkSum; 17 | public bool isLittleEndian = false; 18 | public static int endianByteIndex = 19; 19 | 20 | public DotDataHeader() 21 | { 22 | } 23 | 24 | public bool readFromStream(FileStream stream) 25 | { 26 | byte[] buffer = new byte[length]; 27 | int result = stream.Read(buffer, 0, buffer.Length); 28 | 29 | if (result != buffer.Length) 30 | return false; 31 | 32 | isLittleEndian = buffer[endianByteIndex] != 0; 33 | 34 | MemoryInputStream ms = new MemoryInputStream(buffer, isLittleEndian); 35 | 36 | fileType = (byte)ms.ReadByte(); 37 | if ((char)fileType != 'C') 38 | return false; 39 | 40 | version = ms.readInt16(); 41 | fileNumber = ms.readInt16(); 42 | 43 | long n = ms.readInt64(); 44 | sectionId = (int)(n >> 56); 45 | ownerId = (int)(n >> 32) & 0x00ffffff; 46 | noteId = (int)(n & 0xffffffff); 47 | 48 | ms.Read(macAddress, 0, macAddress.Length); 49 | ms.Read(reserved, 0, reserved.Length); 50 | checkSum = (byte)ms.ReadByte(); 51 | 52 | byte sum = ms.getByteCheckSum(0, buffer.Length - 1); 53 | return (sum == checkSum); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Neosmartpen.Net.Usb.Demo/OfflineData/OfflineDataReader.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | 5 | namespace Neosmartpen.Net.Usb.Demo.OfflineData 6 | { 7 | class OfflineDataReader 8 | { 9 | private List mDots = new List(); 10 | private DrawingViewLog mLog = null; 11 | 12 | FileStream mStrokeInputStream = null; 13 | FileStream mDotInputStream = null; 14 | 15 | StrokeFileHeader strokeFileHeader = new StrokeFileHeader(); 16 | List strokeRefList = new List(); 17 | DotDataHeader dotDataHeader = new DotDataHeader(); 18 | 19 | private bool isLittleEndian = true; 20 | 21 | public OfflineDataReader(DrawingViewLog log) 22 | { 23 | mLog = log; 24 | } 25 | 26 | public Dot[] Parse(string strokeFile, string statusFile, string dotFile) 27 | { 28 | try 29 | { 30 | mStrokeInputStream = new FileStream(strokeFile, FileMode.Open); 31 | //mStatusInputStream = new FileStream(statusFile, FileMode.Open); 32 | mDotInputStream = new FileStream(dotFile, FileMode.Open); 33 | 34 | ParseHeader(); 35 | ParseBody(); 36 | } 37 | catch (Exception e) 38 | { 39 | mLog("[OfflineDataParser] parsing exception occured." + e.ToString()); 40 | } 41 | 42 | try { mDotInputStream.Close(); } catch (Exception e) {} 43 | //try { mStatusInputStream.Close(); } catch (Exception e) {} 44 | try { mStrokeInputStream.Close(); } catch (Exception e) {} 45 | 46 | if (mDots == null || mDots.Count <= 0) 47 | { 48 | return null; 49 | } 50 | else 51 | { 52 | return mDots.ToArray(); 53 | } 54 | } 55 | 56 | private void ParseHeader() 57 | { 58 | if( strokeFileHeader.readFromStream(mStrokeInputStream) == false ) 59 | throw new Exception("Could not load the stroke file header!"); 60 | 61 | if (dotDataHeader.readFromStream(mDotInputStream) == false) 62 | throw new Exception("Could not load the dot file header!"); 63 | 64 | isLittleEndian = strokeFileHeader.isLittleEndian; 65 | } 66 | 67 | private void ParseBody() 68 | { 69 | mDots.Clear(); 70 | strokeRefList.Clear(); 71 | 72 | while (true) 73 | { 74 | StrokeRef strokeRef = new StrokeRef(isLittleEndian); 75 | 76 | if (strokeRef.readFromStream(mStrokeInputStream)) 77 | strokeRefList.Add(strokeRef); 78 | else 79 | break; 80 | } 81 | 82 | for (int i = 0; i < strokeRefList.Count; i++) 83 | { 84 | StrokeRef strokeRef = strokeRefList[i]; 85 | 86 | for (int n = 0; n < strokeRef.codeCount; n++) 87 | { 88 | DotData dotData = new DotData(isLittleEndian); 89 | 90 | if (dotData.readFromStream(mDotInputStream) == false) 91 | break; 92 | 93 | //if (status == 0x00 || status == 0x01) 94 | { 95 | DotTypes type = (n == 0) ? DotTypes.PEN_DOWN : DotTypes.PEN_MOVE; 96 | 97 | Dot dot = new Dot(strokeFileHeader.ownerId, strokeFileHeader.sectionId, strokeFileHeader.noteId, strokeRef.pageId, 98 | strokeRef.downTime + dotData.timestampDelta, dotData.x, dotData.y, dotData.fx, dotData.fy, dotData.force, 99 | type, strokeRef.penTipColor); 100 | 101 | mDots.Add(dot); 102 | } 103 | } 104 | } 105 | } 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /Neosmartpen.Net.Usb.Demo/OfflineData/StrokeFileHeader.cs: -------------------------------------------------------------------------------- 1 | using Neosmartpen.Net.Usb.Demo.Util; 2 | using System.IO; 3 | 4 | namespace Neosmartpen.Net.Usb.Demo.OfflineData 5 | { 6 | class StrokeFileHeader 7 | { 8 | public static readonly int length = 32; 9 | 10 | public byte fileType; 11 | public short version; 12 | public int sectionId, ownerId, noteId; //Int64 notebookId 13 | public byte[] macAddress = new byte[6]; 14 | public byte[] reserved = new byte[14]; 15 | public byte checkSum; 16 | public bool isLittleEndian = false; 17 | public static int endianByteIndex = 17; 18 | 19 | public StrokeFileHeader() 20 | { 21 | } 22 | 23 | public bool readFromStream(FileStream stream) 24 | { 25 | byte[] buffer = new byte[length]; 26 | int result = stream.Read(buffer, 0, buffer.Length); 27 | 28 | if (result != buffer.Length) 29 | return false; 30 | 31 | isLittleEndian = buffer[endianByteIndex] != 0; 32 | 33 | MemoryInputStream ms = new MemoryInputStream(buffer, isLittleEndian); 34 | 35 | fileType = (byte)ms.ReadByte(); 36 | if ((char)fileType != 'T') 37 | return false; 38 | 39 | version = ms.readInt16(); 40 | 41 | long n = ms.readInt64(); 42 | sectionId = (int)(n >> 56); 43 | ownerId = (int)(n >> 32) & 0x00ffffff; 44 | noteId = (int)(n & 0xffffffff); 45 | 46 | ms.Read(macAddress, 0, macAddress.Length); 47 | ms.Read(reserved, 0, reserved.Length); 48 | checkSum = (byte)ms.ReadByte(); 49 | 50 | byte sum = ms.getByteCheckSum(0, buffer.Length - 1); 51 | return (sum == checkSum); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Neosmartpen.Net.Usb.Demo/OfflineData/StrokeRef.cs: -------------------------------------------------------------------------------- 1 | using Neosmartpen.Net.Usb.Demo.Util; 2 | using System; 3 | using System.IO; 4 | 5 | namespace Neosmartpen.Net.Usb.Demo.OfflineData 6 | { 7 | class StrokeRef 8 | { 9 | public static readonly int length = 32; 10 | 11 | public Int64 downTime; 12 | public int upTimeFromDownTime; //a pen up time is relative value from down time. 13 | public int pageId; 14 | public byte status; //reserved 15 | public byte penTipType; //0: normal, 1: remover 16 | public int penTipColor; //Argb (default: 0xff000000) 17 | public short codeTableFileNumber; //reserved (0 or 1) 18 | public int codeTableFileOffset; //Dot data start offset in a Dot Table file 19 | public short codeCount; //Dot data count in a Dot Table file 20 | public byte successRate; //reserved 21 | public byte checkSum; 22 | public bool isLittleEndian = false; 23 | 24 | public StrokeRef(bool isLittleEndian) 25 | { 26 | this.isLittleEndian = isLittleEndian; 27 | } 28 | 29 | public bool readFromStream(FileStream stream) 30 | { 31 | byte[] buffer = new byte[length]; 32 | int result = stream.Read(buffer, 0, buffer.Length); 33 | 34 | if (result != buffer.Length) 35 | return false; 36 | 37 | MemoryInputStream ms = new MemoryInputStream(buffer, isLittleEndian); 38 | 39 | downTime = ms.readInt64(); 40 | upTimeFromDownTime = ms.readInt32(); 41 | pageId = ms.readInt32(); 42 | status = (byte)ms.ReadByte(); 43 | penTipType = (byte)ms.ReadByte(); 44 | penTipColor = ms.readInt32(); 45 | codeTableFileNumber = ms.readInt16(); 46 | codeTableFileOffset = ms.readInt32(); 47 | codeCount = ms.readInt16(); 48 | successRate = (byte)ms.ReadByte(); 49 | checkSum = (byte)ms.ReadByte(); 50 | 51 | byte sum = ms.getByteCheckSum(0, buffer.Length - 1); 52 | return (sum == checkSum); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Neosmartpen.Net.Usb.Demo/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows.Forms; 3 | 4 | namespace Neosmartpen.Net.Usb.Demo 5 | { 6 | static class Program 7 | { 8 | /// 9 | /// 해당 응용 프로그램의 주 진입점입니다. 10 | /// 11 | [STAThread] 12 | static void Main() 13 | { 14 | Application.EnableVisualStyles(); 15 | Application.SetCompatibleTextRenderingDefault(false); 16 | Application.Run(new MainForm()); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Neosmartpen.Net.Usb.Demo/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 6 | // 제어됩니다. 어셈블리와 관련된 정보를 수정하려면 7 | // 이러한 특성 값을 변경하세요. 8 | [assembly: AssemblyTitle("Neosmartpen.Net.Usb.Demo")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Neosmartpen.Net.Usb.Demo")] 13 | [assembly: AssemblyCopyright("Copyright © 2019")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에 18 | // 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면 19 | // 해당 형식에 대해 ComVisible 특성을 true로 설정하세요. 20 | [assembly: ComVisible(false)] 21 | 22 | // 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다. 23 | [assembly: Guid("afb4d5e0-ab19-4823-bc5c-4d612e85454f")] 24 | 25 | // 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다. 26 | // 27 | // 주 버전 28 | // 부 버전 29 | // 빌드 번호 30 | // 수정 버전 31 | // 32 | // 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호가 자동으로 33 | // 지정되도록 할 수 있습니다. 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Neosmartpen.Net.Usb.Demo/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 이 코드는 도구를 사용하여 생성되었습니다. 4 | // 런타임 버전:4.0.30319.42000 5 | // 6 | // 파일 내용을 변경하면 잘못된 동작이 발생할 수 있으며, 코드를 다시 생성하면 7 | // 이러한 변경 내용이 손실됩니다. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace Neosmartpen.Net.Usb.Demo.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// 지역화된 문자열 등을 찾기 위한 강력한 형식의 리소스 클래스입니다. 17 | /// 18 | // 이 클래스는 ResGen 또는 Visual Studio와 같은 도구를 통해 StronglyTypedResourceBuilder 19 | // 클래스에서 자동으로 생성되었습니다. 20 | // 멤버를 추가하거나 제거하려면 .ResX 파일을 편집한 다음 /str 옵션을 사용하여 ResGen을 21 | // 다시 실행하거나 VS 프로젝트를 다시 빌드하십시오. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// 이 클래스에서 사용하는 캐시된 ResourceManager 인스턴스를 반환합니다. 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Neosmartpen.Net.Usb.Demo.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// 이 강력한 형식의 리소스 클래스를 사용하여 모든 리소스 조회에 대해 현재 스레드의 CurrentUICulture 속성을 51 | /// 재정의합니다. 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Neosmartpen.Net.Usb.Demo/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 이 코드는 도구를 사용하여 생성되었습니다. 4 | // 런타임 버전:4.0.30319.42000 5 | // 6 | // 파일 내용을 변경하면 잘못된 동작이 발생할 수 있으며, 코드를 다시 생성하면 7 | // 이러한 변경 내용이 손실됩니다. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace Neosmartpen.Net.Usb.Demo.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.11.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Neosmartpen.Net.Usb.Demo/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Neosmartpen.Net.Usb.Demo/UpdateForm.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace Neosmartpen.Net.Usb.Demo 2 | { 3 | partial class UpdateForm 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.groupBox1 = new System.Windows.Forms.GroupBox(); 32 | this.pbUpdateProgress = new System.Windows.Forms.ProgressBar(); 33 | this.tbFirmwareFilePath = new System.Windows.Forms.TextBox(); 34 | this.tbFirmwareVersion = new System.Windows.Forms.TextBox(); 35 | this.button1 = new System.Windows.Forms.Button(); 36 | this.groupBox1.SuspendLayout(); 37 | this.SuspendLayout(); 38 | // 39 | // groupBox1 40 | // 41 | this.groupBox1.Controls.Add(this.button1); 42 | this.groupBox1.Controls.Add(this.tbFirmwareVersion); 43 | this.groupBox1.Controls.Add(this.tbFirmwareFilePath); 44 | this.groupBox1.Location = new System.Drawing.Point(15, 16); 45 | this.groupBox1.Name = "groupBox1"; 46 | this.groupBox1.Size = new System.Drawing.Size(388, 134); 47 | this.groupBox1.TabIndex = 0; 48 | this.groupBox1.TabStop = false; 49 | this.groupBox1.Text = "Firmware Information"; 50 | // 51 | // pbUpdateProgress 52 | // 53 | this.pbUpdateProgress.Location = new System.Drawing.Point(15, 161); 54 | this.pbUpdateProgress.Name = "pbUpdateProgress"; 55 | this.pbUpdateProgress.Size = new System.Drawing.Size(387, 31); 56 | this.pbUpdateProgress.Step = 1; 57 | this.pbUpdateProgress.Style = System.Windows.Forms.ProgressBarStyle.Continuous; 58 | this.pbUpdateProgress.TabIndex = 1; 59 | // 60 | // tbFirmwareFilePath 61 | // 62 | this.tbFirmwareFilePath.Location = new System.Drawing.Point(16, 24); 63 | this.tbFirmwareFilePath.Name = "tbFirmwareFilePath"; 64 | this.tbFirmwareFilePath.ReadOnly = true; 65 | this.tbFirmwareFilePath.Size = new System.Drawing.Size(358, 21); 66 | this.tbFirmwareFilePath.TabIndex = 0; 67 | this.tbFirmwareFilePath.Text = "Click here to select new firmware file"; 68 | this.tbFirmwareFilePath.Click += new System.EventHandler(this.tbFirmwareFilePath_Click); 69 | // 70 | // tbFirmwareVersion 71 | // 72 | this.tbFirmwareVersion.Location = new System.Drawing.Point(16, 52); 73 | this.tbFirmwareVersion.Name = "tbFirmwareVersion"; 74 | this.tbFirmwareVersion.Size = new System.Drawing.Size(358, 21); 75 | this.tbFirmwareVersion.TabIndex = 1; 76 | this.tbFirmwareVersion.Text = "Enter new firmware version"; 77 | this.tbFirmwareVersion.Enter += new System.EventHandler(this.tbFirmwareVersion_Enter); 78 | this.tbFirmwareVersion.Leave += new System.EventHandler(this.tbFirmwareVersion_Leave); 79 | // 80 | // button1 81 | // 82 | this.button1.Location = new System.Drawing.Point(16, 86); 83 | this.button1.Name = "button1"; 84 | this.button1.Size = new System.Drawing.Size(358, 32); 85 | this.button1.TabIndex = 2; 86 | this.button1.Text = "Update"; 87 | this.button1.UseVisualStyleBackColor = true; 88 | this.button1.Click += new System.EventHandler(this.button1_Click); 89 | // 90 | // UpdateForm 91 | // 92 | this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F); 93 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 94 | this.ClientSize = new System.Drawing.Size(414, 207); 95 | this.Controls.Add(this.pbUpdateProgress); 96 | this.Controls.Add(this.groupBox1); 97 | this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; 98 | this.MaximizeBox = false; 99 | this.MinimizeBox = false; 100 | this.Name = "UpdateForm"; 101 | this.ShowIcon = false; 102 | this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide; 103 | this.Text = "Firmware Update"; 104 | this.groupBox1.ResumeLayout(false); 105 | this.groupBox1.PerformLayout(); 106 | this.ResumeLayout(false); 107 | 108 | } 109 | 110 | #endregion 111 | 112 | private System.Windows.Forms.GroupBox groupBox1; 113 | private System.Windows.Forms.Button button1; 114 | private System.Windows.Forms.TextBox tbFirmwareVersion; 115 | private System.Windows.Forms.TextBox tbFirmwareFilePath; 116 | private System.Windows.Forms.ProgressBar pbUpdateProgress; 117 | } 118 | } -------------------------------------------------------------------------------- /Neosmartpen.Net.Usb.Demo/UpdateForm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows.Forms; 3 | 4 | namespace Neosmartpen.Net.Usb.Demo 5 | { 6 | public partial class UpdateForm : Form 7 | { 8 | public string PortName { get; set; } 9 | 10 | public delegate void OnClickedUpdate(string portName, string filePath, string firmwareVersion); 11 | 12 | private OnClickedUpdate onClickedUpdate; 13 | 14 | public UpdateForm(string portName, OnClickedUpdate onClickedUpdate) 15 | { 16 | PortName = portName; 17 | this.onClickedUpdate = onClickedUpdate; 18 | InitializeComponent(); 19 | } 20 | 21 | public void SetStatus(int total, int amountDone) 22 | { 23 | pbUpdateProgress.Maximum = total; 24 | pbUpdateProgress.Value = amountDone > total ? total : amountDone; 25 | } 26 | 27 | private void button1_Click(object sender, EventArgs e) 28 | { 29 | if (string.IsNullOrEmpty(tbFirmwareFilePath.Text) || tbFirmwareFilePath.Text == "Click here to select new firmware file") 30 | { 31 | MessageBox.Show("Please select new firmware file"); 32 | return; 33 | } 34 | 35 | if (string.IsNullOrEmpty(tbFirmwareVersion.Text) || tbFirmwareVersion.Text == "Enter new firmware version") 36 | { 37 | MessageBox.Show("Please enter version of new firmware file"); 38 | return; 39 | } 40 | 41 | tbFirmwareFilePath.Enabled = false; 42 | tbFirmwareVersion.Enabled = false; 43 | button1.Enabled = false; 44 | 45 | this.onClickedUpdate?.Invoke(PortName, tbFirmwareFilePath.Text, tbFirmwareVersion.Text); 46 | } 47 | 48 | private void tbFirmwareFilePath_Click(object sender, EventArgs e) 49 | { 50 | OpenFileDialog openFileDialog1 = new OpenFileDialog(); 51 | openFileDialog1.Filter = "Firmware Files (*._v_)|*._v_|Firmware Files (*.bin)|*.bin|All Files|*"; 52 | openFileDialog1.Title = "Select a Firmware File"; 53 | 54 | if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) 55 | { 56 | tbFirmwareFilePath.Text = openFileDialog1.FileName; 57 | } 58 | } 59 | 60 | private void tbFirmwareVersion_Enter(object sender, EventArgs e) 61 | { 62 | if (tbFirmwareVersion.Text == "Enter new firmware version") 63 | tbFirmwareVersion.Text = ""; 64 | } 65 | 66 | private void tbFirmwareVersion_Leave(object sender, EventArgs e) 67 | { 68 | if (string.IsNullOrEmpty(tbFirmwareVersion.Text)) 69 | tbFirmwareVersion.Text = "Enter new firmware version"; 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /Neosmartpen.Net.Usb.Demo/Util/MemoryInputStream.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | 4 | namespace Neosmartpen.Net.Usb.Demo.Util 5 | { 6 | class MemoryInputStream : MemoryStream 7 | { 8 | public bool littleEndian = true; 9 | private byte[] mArray = null; 10 | 11 | public MemoryInputStream(byte[] buffer, bool isLittleEndian = true) 12 | : base(buffer) 13 | { 14 | littleEndian = isLittleEndian; 15 | mArray = buffer; 16 | } 17 | 18 | public byte getByte(int index) 19 | { 20 | return mArray[index]; 21 | } 22 | 23 | public byte getByteCheckSum(int startOfs, int length) 24 | { 25 | byte sum = 0; 26 | int endOfs = startOfs + length - 1; 27 | 28 | for (int i = startOfs; i <= endOfs; i++) 29 | { 30 | sum += mArray[i]; 31 | } 32 | 33 | return sum; 34 | } 35 | 36 | public short readInt16() 37 | { 38 | byte[] buf = new byte[2]; 39 | 40 | if (this.Read(buf, 0, 2) != 2) 41 | throw new Exception("MemoryInputStream: Could not read int16 from a stream"); 42 | 43 | if (littleEndian) 44 | return BitConverter.ToInt16(buf, 0); 45 | else 46 | return MyBitConverter.bigEndian_toInt16(buf, 0); 47 | } 48 | 49 | public int readInt32() 50 | { 51 | byte[] buf = new byte[4]; 52 | 53 | if (this.Read(buf, 0, 4) != 4) 54 | throw new Exception("MemoryInputStream: Could not read int32 from a stream"); 55 | 56 | if (littleEndian) 57 | return BitConverter.ToInt32(buf, 0); 58 | else 59 | return MyBitConverter.bigEndian_toInt32(buf, 0); 60 | } 61 | 62 | public Int64 readInt64() 63 | { 64 | byte[] buf = new byte[8]; 65 | 66 | if (this.Read(buf, 0, 8) != 8) 67 | throw new Exception("MemoryInputStream: Could not read int64 from a stream"); 68 | 69 | if (littleEndian) 70 | return BitConverter.ToInt64(buf, 0); 71 | else 72 | return MyBitConverter.bigEndian_toInt64(buf, 0); 73 | } 74 | 75 | public string readString( int len ) 76 | { 77 | byte[] buf = new byte[len]; 78 | 79 | if (this.Read(buf, 0, len) != len) 80 | throw new Exception("MemoryInputStream: Could not read a string from a stream"); 81 | 82 | return System.Text.Encoding.ASCII.GetString(buf, 0, buf.Length); 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /Neosmartpen.Net.Usb.Demo/Util/MyBitConverter.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace Neosmartpen.Net.Usb.Demo.Util 3 | { 4 | class MyBitConverter 5 | { 6 | public static short bigEndian_toInt16(byte[] buf, int ofs) 7 | { 8 | int a = buf[ofs++]; 9 | int b = buf[ofs] & 0xff; 10 | short n = (short)(((a << 8) | b) & 0xffff); 11 | return n; 12 | } 13 | 14 | public static int bigEndian_toInt32(byte[] buf, int ofs) 15 | { 16 | int s = 0; 17 | 18 | s |= ((int)buf[ofs++] & 0xff) << 24; 19 | s |= ((int)buf[ofs++] & 0xff) << 16; 20 | s |= ((int)buf[ofs++] & 0xff) << 8; 21 | s |= (int)buf[ofs++] & 0xff; 22 | 23 | return s; 24 | } 25 | 26 | public static long bigEndian_toInt64(byte[] buf, int ofs) 27 | { 28 | long s = 0; 29 | 30 | s |= ((long)buf[ofs++] & 0xff) << 56; 31 | s |= ((long)buf[ofs++] & 0xff) << 48; 32 | s |= ((long)buf[ofs++] & 0xff) << 40; 33 | s |= ((long)buf[ofs++] & 0xff) << 32; 34 | s |= ((long)buf[ofs++] & 0xff) << 24; 35 | s |= ((long)buf[ofs++] & 0xff) << 16; 36 | s |= ((long)buf[ofs++] & 0xff) << 8; 37 | s |= (long)buf[ofs++] & 0xff; 38 | 39 | return s; 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Neosmartpen.Net.Usb.Demo/app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Neosmartpen.Net.Usb/Neosmarpen/Net/Chunk.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Neosmartpen.Net 5 | { 6 | public class Chunk 7 | { 8 | // chunk size is 0.5k 9 | private int mSize = 512; 10 | 11 | private int mRows; 12 | 13 | private List mBuffer; 14 | 15 | private int mFileSize = 0; 16 | 17 | private byte mCheckSum; 18 | 19 | public Chunk( int chunksize ) 20 | { 21 | mSize = chunksize; 22 | } 23 | 24 | public Chunk() 25 | { 26 | } 27 | 28 | public static List SplitByteArray( byte[] bytes, int range ) 29 | { 30 | List chunk = new List(); 31 | List result = new List(); 32 | 33 | int i = 1; 34 | int c = 1; 35 | 36 | foreach ( byte b in bytes ) 37 | { 38 | // Put the byte into the bytes array 39 | chunk.Add( b ); 40 | 41 | // If we match the range, add the byte array and create new one 42 | if ( i == range || c == bytes.Length ) 43 | { 44 | // Add as array 45 | result.Add( chunk.ToArray() ); 46 | 47 | // Create again 48 | chunk = new List(); 49 | i = 0; 50 | } 51 | 52 | c++; 53 | i++; 54 | } 55 | 56 | return result; 57 | } 58 | 59 | public bool Load( string filepath ) 60 | { 61 | byte[] datas = null; 62 | 63 | try 64 | { 65 | datas = System.IO.File.ReadAllBytes( filepath ); 66 | mCheckSum = CalcChecksum( datas ); 67 | } 68 | catch 69 | { 70 | return false; 71 | } 72 | 73 | if ( datas == null ) 74 | { 75 | return false; 76 | } 77 | 78 | mFileSize = datas.Length; 79 | 80 | double filesize = datas.Length / mSize; 81 | 82 | mRows = (int)Math.Ceiling( filesize ) + 1; 83 | 84 | mBuffer = SplitByteArray( datas, mSize ); 85 | 86 | return true; 87 | } 88 | 89 | public byte[] Get( int number ) 90 | { 91 | return mBuffer != null && mBuffer.Count > number ? mBuffer[number] : null; 92 | } 93 | 94 | public int GetFileSize() 95 | { 96 | return mFileSize; 97 | } 98 | 99 | public int GetChunkLength() 100 | { 101 | return mRows; 102 | } 103 | 104 | public int GetChunksize() 105 | { 106 | return mSize; 107 | } 108 | 109 | public byte GetChecksum( int number ) 110 | { 111 | return Get( number ) != null ? CalcChecksum( Get( number ) ) : (byte)0x00; 112 | } 113 | 114 | public byte GetTotalChecksum() 115 | { 116 | return mCheckSum; 117 | } 118 | 119 | public static byte CalcChecksum(byte[] bytes) 120 | { 121 | int CheckSum = 0; 122 | 123 | for( int i = 0; i < bytes.Length; i++) 124 | { 125 | CheckSum += (int)(bytes[i] & 0xFF); 126 | } 127 | 128 | return (byte)CheckSum; 129 | } 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /Neosmartpen.Net.Usb/Neosmarpen/Net/OfflineDataStructure.cs: -------------------------------------------------------------------------------- 1 |  using System; 2 | 3 | namespace Neosmartpen.Net 4 | { 5 | public class OfflineDataInfo 6 | { 7 | public int Section { protected set; get; } 8 | 9 | public int Owner { protected set; get; } 10 | 11 | public int Note { protected set; get; } 12 | 13 | public int[] Pages { protected set; get; } 14 | 15 | public OfflineDataInfo( int sectionId, int ownerId, int noteId, int[] pages = null ) 16 | { 17 | Section = sectionId; 18 | Owner = ownerId; 19 | Note = noteId; 20 | Pages = pages; 21 | } 22 | 23 | public override string ToString() 24 | { 25 | return String.Format( "sec:{0}, owner:{1}, note:{2}", Section, Owner, Note ); 26 | } 27 | } 28 | 29 | public class OfflineDataFile 30 | { 31 | public int Section, Owner, Note; 32 | public string FilePath; 33 | 34 | public OfflineDataFile( int sectionId, int ownerId, int noteId, string filePath ) 35 | { 36 | Section = sectionId; 37 | Owner = ownerId; 38 | Note = noteId; 39 | FilePath = filePath; 40 | } 41 | 42 | public void Delete() 43 | { 44 | if ( System.IO.Directory.Exists( FilePath ) ) 45 | { 46 | System.IO.Directory.Delete( FilePath, true ); 47 | } 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Neosmartpen.Net.Usb/Neosmarpen/Net/Protocol/v1/OfflineData.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.IO; 3 | 4 | namespace Neosmartpen.Net.Protocol.v1 5 | { 6 | public abstract class OfflineData 7 | { 8 | public static string CURRENT_DIR; 9 | public static string DEFAULT_PATH; 10 | public static string DEFAULT_ERROR_PATH; 11 | 12 | public readonly string EXT_ZIP = ".zip"; 13 | public readonly string EXT_ERROR = ".err"; 14 | public readonly string EXT_DATA = ".pen"; 15 | public readonly string DIR_ROOT = "offline"; 16 | public readonly string DIR_ERROR = "err"; 17 | public readonly string DIR_TEMP = "temp_"; 18 | 19 | // 기본 디렉토리 생성 20 | public void SetDefaultPath( string basepath ) 21 | { 22 | basepath = basepath == null || basepath == "" ? Directory.GetCurrentDirectory() : basepath; 23 | 24 | OfflineData.DEFAULT_PATH = basepath + "\\" + DIR_ROOT; 25 | OfflineData.DEFAULT_ERROR_PATH = DEFAULT_PATH + "\\" + DIR_ERROR; 26 | } 27 | 28 | public void SetupFileSystem() 29 | { 30 | if ( !System.IO.Directory.Exists( DEFAULT_PATH ) ) 31 | { 32 | System.IO.Directory.CreateDirectory( DEFAULT_PATH ); 33 | } 34 | 35 | // 에러 파일 저장 위치 설정 36 | string errorFilePath = DEFAULT_PATH + "\\" + DIR_ERROR; 37 | 38 | if ( !System.IO.Directory.Exists( errorFilePath ) ) 39 | { 40 | System.IO.Directory.CreateDirectory( errorFilePath ); 41 | } 42 | } 43 | 44 | public string[] GetOfflineFiles() 45 | { 46 | string[] filePaths = Directory.GetFiles( DEFAULT_PATH ); 47 | return filePaths; 48 | } 49 | 50 | public string[] GetErrorFiles() 51 | { 52 | string[] filePaths = Directory.GetFiles( DEFAULT_PATH + "\\" + DIR_ERROR ); 53 | return filePaths; 54 | } 55 | 56 | public static string GetFileFromFullPath( string fullpath ) 57 | { 58 | string[] arr = fullpath.Split( '\\' ); 59 | 60 | if ( arr.Length <= 1 ) 61 | { 62 | return null; 63 | } 64 | 65 | return arr[arr.Length - 1]; 66 | } 67 | 68 | public static string GetFileNameFromFullPath( string fullpath ) 69 | { 70 | string[] arr = GetFileFromFullPath( fullpath ).Split( '.' ); 71 | 72 | if ( arr.Length < 2 ) 73 | { 74 | return null; 75 | } 76 | 77 | return arr[0]; 78 | } 79 | 80 | public static string GetFileExtFromFullPath( string fullpath ) 81 | { 82 | string[] arr = GetFileFromFullPath( fullpath ).Split( '.' ); 83 | 84 | if ( arr.Length < 2 ) 85 | { 86 | return null; 87 | } 88 | 89 | string ext = ""; 90 | 91 | for ( int i=1; i slist = new List(); 102 | 103 | Stroke temp = null; 104 | 105 | foreach ( Dot dot in dots ) 106 | { 107 | if ( dot.DotType == DotTypes.PEN_DOWN ) 108 | { 109 | temp = new Stroke( dot.Section, dot.Owner, dot.Note, dot.Page ); 110 | slist.Add( temp ); 111 | } 112 | 113 | temp.Add( dot ); 114 | } 115 | 116 | return slist.ToArray(); 117 | } 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /Neosmartpen.Net.Usb/Neosmarpen/Net/Protocol/v1/OfflineDataSerializer.cs: -------------------------------------------------------------------------------- 1 | using Neosmartpen.Net.Support; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | 6 | namespace Neosmartpen.Net.Protocol.v1 7 | { 8 | /// 9 | /// OfflineDataSerializer class take offline data fragments and assemble it as a files. 10 | /// 11 | public class OfflineDataSerializer : OfflineData 12 | { 13 | public Dictionary chunks; 14 | 15 | private int mPacketCount; 16 | 17 | private bool IsCompressed = false; 18 | 19 | public int sectionId = 0, ownerId = 0, noteId = 0, pageId = 0; 20 | 21 | public static string DEFAULT_FILE_FORMAT = "{0}_{1}_{2}_{3}_{4}.{5}"; 22 | 23 | public OfflineDataSerializer( string filepath, int packetCount, bool isCompressed ) 24 | { 25 | chunks = new Dictionary(); 26 | 27 | string[] arr = filepath.Split( '\\' ); 28 | 29 | int sectionOwner = int.Parse( arr[2] ); 30 | 31 | byte[] bso = ByteConverter.IntToByte( sectionOwner ); 32 | 33 | sectionId = (int)( bso[3] & 0xFF ); 34 | ownerId = ByteConverter.ByteToInt( new byte[] { bso[0], bso[1], bso[2], (byte)0x00 } ); 35 | 36 | noteId = int.Parse( arr[3] ); 37 | pageId = int.Parse( arr[4] ); 38 | 39 | mPacketCount = packetCount; 40 | IsCompressed = isCompressed; 41 | 42 | base.SetupFileSystem(); 43 | } 44 | 45 | public string MakeFile() 46 | { 47 | lock ( OfflineData.DEFAULT_PATH ) 48 | { 49 | ByteUtil buff = new ByteUtil(); 50 | 51 | for ( int i=0; i < chunks.Count(); i++ ) 52 | { 53 | buff.Put( chunks[i] ); 54 | } 55 | 56 | string filename = String.Format( DEFAULT_FILE_FORMAT, sectionId, ownerId, noteId, pageId, Time.GetUtcTimeStamp(), IsCompressed ? "zip" : "pen" ); 57 | 58 | string fullpath = OfflineData.DEFAULT_PATH + "\\" + filename; 59 | 60 | if ( ByteToFile( buff.ToArray(), fullpath ) ) 61 | { 62 | return fullpath; 63 | } 64 | else 65 | { 66 | return null; 67 | } 68 | } 69 | } 70 | 71 | public void Put( byte[] data, int index ) 72 | { 73 | chunks.Add(index, data); 74 | } 75 | 76 | private bool ByteToFile( byte[] bytes, String filepath ) 77 | { 78 | try 79 | { 80 | System.IO.FileStream fs = new System.IO.FileStream( filepath, System.IO.FileMode.Create, System.IO.FileAccess.Write ); 81 | fs.Write( bytes, 0, bytes.Length ); 82 | fs.Close(); 83 | 84 | return true; 85 | } 86 | catch ( Exception e ) 87 | { 88 | Console.WriteLine( "[OfflineDataSerializer] Exception caught in process: {0}", e.StackTrace ); 89 | } 90 | 91 | // error occured, return false 92 | return false; 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /Neosmartpen.Net.Usb/Neosmarpen/Net/Stroke.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Drawing; 4 | using System.Linq; 5 | 6 | namespace Neosmartpen.Net 7 | { 8 | /// 9 | /// Represents coordinate of stroke. 10 | /// It consist of Dot's Collection. 11 | /// 12 | public class Stroke : List 13 | { 14 | /// 15 | /// Gets the Section Id of the NCode paper 16 | /// 17 | public int Section { get; private set; } 18 | 19 | /// 20 | /// Gets the Owner Id of the NCode paper 21 | /// 22 | public int Owner { get; private set; } 23 | 24 | /// 25 | /// Gets the Note Id of the NCode paper 26 | /// 27 | public int Note { get; private set; } 28 | 29 | /// 30 | /// Gets the Page Number of the NCode paper 31 | /// 32 | public int Page { get; private set; } 33 | 34 | /// 35 | /// Gets the color of the dot 36 | /// 37 | public int Color { get; private set; } 38 | 39 | /// 40 | /// Gets the timestamp of start point 41 | /// 42 | public long TimeStart { get; private set; } 43 | 44 | /// 45 | /// Gets the timestamp of end point 46 | /// 47 | public long TimeEnd { get; private set; } 48 | 49 | /// 50 | /// A constructor that constructs a Stroke object 51 | /// 52 | /// The Section Id of the NCode paper 53 | /// The Owner Id of the NCode paper 54 | /// The Note Id of the NCode paper 55 | /// The Page Number of the NCode paper 56 | public Stroke( int section, int owner, int note, int page ) 57 | { 58 | Section = section; 59 | Owner = owner; 60 | Note = note; 61 | Page = page; 62 | } 63 | 64 | /// 65 | /// Adds a new Dot to the current Stroke object. 66 | /// 67 | /// Dot object 68 | public new void Add( Dot dot ) 69 | { 70 | if ( base.Count <= 0 ) 71 | { 72 | TimeStart = dot.Timestamp; 73 | Color = dot.Color; 74 | } 75 | 76 | TimeEnd = dot.Timestamp; 77 | 78 | base.Add( dot ); 79 | } 80 | 81 | /// 82 | /// A square corresponding to the area of the stroke is obtained. 83 | /// 84 | /// a rectangular object of type float 85 | public RectangleF GetRect() 86 | { 87 | // TODO 여기서 부터 Max 버그 수정하기 88 | if (this.Count == 0) 89 | return RectangleF.Empty; 90 | 91 | float mx = this.Max(d => d.X + d.Fx * 0.01f); 92 | float my = this.Max(d => d.Y + d.Fy * 0.01f); 93 | float sx = this.Min(d => d.X + d.Fx * 0.01f); 94 | float sy = this.Min(d => d.Y + d.Fy * 0.01f); 95 | 96 | return new RectangleF(sx, sy, mx - sx, my - sy); 97 | } 98 | 99 | public override string ToString() 100 | { 101 | return String.Format( "Stroke => sectionId : {0}, ownerId : {1}, noteId : {2}, pageId : {3}, timeStart : {4}, timeEnd : {5}", Section, Owner, Note, Page, TimeStart, TimeEnd ); 102 | } 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /Neosmartpen.Net.Usb/Neosmarpen/Net/Support/ByteConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Neosmartpen.Net.Support 4 | { 5 | /// 6 | ///Data type converter between byte[] and short, int, long 7 | /// 8 | public class ByteConverter 9 | { 10 | public static long ByteToLong(byte[] data) 11 | { 12 | //long result = data[0] + ( data[1] << 8 ) + ( data[2] << 16 ) + ( data[3] << 24 ) 13 | //+ ( data[4] << 32 ) + ( data[5] << 40 ) + ( data[6] << 48 ) + ( data[7] << 56 ); 14 | //return result; 15 | 16 | return BitConverter.ToInt64( data, 0 ); 17 | } 18 | 19 | public static int ByteToInt(byte[] data) 20 | { 21 | int result = data[0] + ( data[1] << 8 ) + ( data[2] << 16 ) + ( data[3] << 24 ); 22 | return result; 23 | } 24 | 25 | public static int SingleByteToInt(byte data) 26 | { 27 | return (int)( data & 0xFF ); 28 | } 29 | 30 | public static short ByteToShort(byte[] data) 31 | { 32 | int result = data[0] + ( data[1] << 8 ); 33 | return (short)result; 34 | } 35 | 36 | public static byte[] ShortToByte(short value) 37 | { 38 | byte[] b = BitConverter.GetBytes( value ); 39 | return b; 40 | } 41 | 42 | public static byte[] LongToByte( long value ) 43 | { 44 | byte[] b = BitConverter.GetBytes( value ); 45 | return b; 46 | } 47 | 48 | public static byte[] IntToByte( int value ) 49 | { 50 | byte[] b = BitConverter.GetBytes( value ); 51 | return b; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Neosmartpen.Net.Usb/Neosmarpen/Net/Support/PressureCalibration.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Neosmartpen.Net.Support 4 | { 5 | internal class PressureCalibration 6 | { 7 | private static PressureCalibration instance; 8 | private static object lockObject = new object(); 9 | public static PressureCalibration Instance 10 | { 11 | get 12 | { 13 | if ( instance == null ) 14 | { 15 | lock(lockObject) 16 | { 17 | if (instance == null) 18 | instance = new PressureCalibration(); 19 | } 20 | } 21 | return instance; 22 | } 23 | } 24 | 25 | public PressureCalibration() 26 | { 27 | } 28 | 29 | #region Calculate Calibration Factor 30 | public readonly int MAX_FACTOR = 1023; 31 | private readonly int MAX_CURVE = 2000; 32 | private float[] pressureCalibrationFactor; 33 | public float[] Factor 34 | { 35 | get 36 | { 37 | return pressureCalibrationFactor; 38 | } 39 | } 40 | public void Clear() 41 | { 42 | pressureCalibrationFactor = null; 43 | } 44 | public void MakeFactor(int cPX1, int cPY1, int cPX2, int cPY2, int cPX3, int cPY3) 45 | { 46 | PointF[] pCurve = new PointF[MAX_CURVE]; 47 | pressureCalibrationFactor = new float[MAX_FACTOR + 1]; 48 | 49 | PointF[] point = new PointF[4] 50 | { 51 | new PointF(cPX1, cPY1), 52 | new PointF(cPX2, cPY2), 53 | new PointF(cPX2, cPY2), 54 | new PointF(cPX3, cPY3), 55 | }; 56 | ComputeBezier(point, MAX_CURVE, pCurve); 57 | 58 | int count = 0; 59 | int prevCount = 0; 60 | int length = pCurve.Length - 1; 61 | for (int i = 0; i < length; i++) 62 | { 63 | if (count < pCurve[i].X) 64 | { 65 | if (Math.Abs(pCurve[prevCount].X - count) > Math.Abs(pCurve[i].X - count)) 66 | pressureCalibrationFactor[count] = pCurve[i].Y; 67 | else 68 | pressureCalibrationFactor[count] = pCurve[prevCount].Y; 69 | if (pressureCalibrationFactor[count] > MAX_FACTOR) pressureCalibrationFactor[count] = MAX_FACTOR; 70 | count++; 71 | if (count > MAX_FACTOR) 72 | count = MAX_FACTOR; 73 | } 74 | else 75 | { 76 | prevCount = count; 77 | } 78 | } 79 | pressureCalibrationFactor[MAX_FACTOR] = pCurve[MAX_CURVE - 1].Y; 80 | if (pressureCalibrationFactor[MAX_FACTOR] > MAX_FACTOR) pressureCalibrationFactor[MAX_FACTOR] = MAX_FACTOR; 81 | 82 | #if DEBUG_LOG 83 | for (int i = 0; i < mModifyPressureFactor.Length; i++) 84 | { 85 | System.Diagnostics.Debug.WriteLine("test mPressureFactor" + i + ":" + mModifyPressureFactor[i]); 86 | } 87 | #endif 88 | } 89 | public float[] GetPressureCalibrateFactor(int cPX1, int cPY1, int cPX2, int cPY2, int cPX3, int cPY3) 90 | { 91 | MakeFactor(cPX1, cPY1, cPX2, cPY2, cPX3, cPY3); 92 | return pressureCalibrationFactor; 93 | } 94 | 95 | private void ComputeBezier(PointF[] cp, int numberOfPoints, PointF[] curve) 96 | { 97 | float dt = 1.0f / (numberOfPoints - 1); 98 | 99 | for (int i = 0; i < numberOfPoints; i++) 100 | curve[i] = PointOnCubicBezier(cp, i * dt); 101 | } 102 | 103 | private PointF PointOnCubicBezier(PointF[] cp, float t) 104 | { 105 | float ax, bx, cx; 106 | float ay, by, cy; 107 | float tSquared, tCubed; 108 | PointF result = new PointF(); 109 | 110 | cx = 3.0f * (cp[1].X - cp[0].X); 111 | bx = 3.0f * (cp[2].X - cp[1].X) - cx; 112 | ax = cp[3].X - cp[0].X - cx - bx; 113 | 114 | cy = 3.0f * (cp[1].Y - cp[0].Y); 115 | by = 3.0f * (cp[2].Y - cp[1].Y) - cy; 116 | ay = cp[3].Y - cp[0].Y - cy - by; 117 | 118 | tSquared = t * t; 119 | tCubed = tSquared * t; 120 | 121 | result.X = (ax * tCubed) + (bx * tSquared) + (cx * t) + cp[0].X; 122 | result.Y = (ay * tCubed) + (by * tSquared) + (cy * t) + cp[0].Y; 123 | 124 | return result; 125 | } 126 | 127 | private struct PointF 128 | { 129 | public PointF(float x, float y) 130 | { 131 | X = x; 132 | Y = y; 133 | } 134 | public float X { get; set; } 135 | public float Y { get; set; } 136 | } 137 | #endregion 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /Neosmartpen.Net.Usb/Neosmarpen/Net/Support/PressureFilter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Neosmartpen.Net.Support 4 | { 5 | public class PressureFilter 6 | { 7 | bool m_bFirst; 8 | 9 | int m_nPrevValue; 10 | 11 | float MAX_PRESSURE_DELTA = 0.1f; 12 | 13 | public readonly int RANGE_MIN=45, RANGE_MAX; 14 | 15 | public readonly double RANGE; 16 | 17 | public PressureFilter(int max) 18 | { 19 | this.m_bFirst = true; 20 | 21 | this.RANGE_MAX = max; 22 | 23 | this.RANGE = (double)( RANGE_MAX - RANGE_MIN ); 24 | } 25 | 26 | private int FitRange( int p ) 27 | { 28 | if ( p > RANGE_MAX ) 29 | { 30 | p = RANGE_MAX; 31 | } 32 | else if ( p < RANGE_MIN ) 33 | { 34 | p = RANGE_MIN; 35 | } 36 | 37 | return p; 38 | } 39 | 40 | public int Filter( int nPressure ) 41 | { 42 | nPressure = FitRange( nPressure ); 43 | 44 | if ( m_bFirst ) 45 | { 46 | this.m_bFirst = false; 47 | this.m_nPrevValue = nPressure; 48 | 49 | return nPressure; 50 | } 51 | 52 | float diffRate = 1.0f - (float)nPressure / (float)m_nPrevValue; 53 | 54 | if ( Math.Abs( diffRate ) > MAX_PRESSURE_DELTA ) 55 | { 56 | float newRate = ( diffRate < 0 ) ? MAX_PRESSURE_DELTA : -( MAX_PRESSURE_DELTA ); 57 | nPressure = (int)( (float)m_nPrevValue * ( 1.0 + newRate ) + 0.5f ); 58 | } 59 | 60 | nPressure = FitRange( nPressure ); 61 | 62 | this.m_nPrevValue = nPressure; 63 | 64 | return nPressure; 65 | } 66 | 67 | public void Reset() 68 | { 69 | m_bFirst = true; 70 | } 71 | 72 | public double ToRate( int nPressure ) 73 | { 74 | double fPressureRate = 0; 75 | 76 | // 필압 강도 측정 (nRangeMin ~ nRangeMax 사이의 값) 77 | if ( nPressure < RANGE_MIN ) 78 | { 79 | nPressure = RANGE_MIN; 80 | } 81 | 82 | if( nPressure == 0 ) 83 | { 84 | //압력값(퍼센트)를 가져온다. 85 | fPressureRate = 1; 86 | } 87 | else 88 | { 89 | //압력값을 퍼센트로 환산한다. 90 | fPressureRate = (double)( nPressure - RANGE_MIN + 1 ) / RANGE; 91 | } 92 | 93 | if ( fPressureRate > 1.0 ) 94 | { 95 | fPressureRate = 1.0; 96 | } 97 | else if ( fPressureRate < 0.01 ) 98 | { 99 | fPressureRate = 0.01; 100 | } 101 | 102 | return fPressureRate; 103 | } 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /Neosmartpen.Net.Usb/Neosmarpen/Net/Support/Time.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Neosmartpen.Net.Support 4 | { 5 | public class Time 6 | { 7 | /// 8 | /// Time gap form 1970.1.1 9 | /// 10 | /// "long Time gap" 11 | public static long GetUtcTimeStamp() 12 | { 13 | TimeSpan t = ( DateTime.UtcNow - new DateTime( 1970, 1, 1 ) ); 14 | long ts = (long)t.TotalMilliseconds; 15 | return ts; 16 | } 17 | 18 | public static long GetUtcTimeStamp(DateTime dateTime) 19 | { 20 | TimeSpan t = (dateTime.ToUniversalTime() - new DateTime(1970, 1, 1)); 21 | long ts = (long)t.TotalMilliseconds; 22 | return ts; 23 | } 24 | 25 | /// 26 | /// Time offset 27 | /// 28 | /// 29 | public static int GetLocalTimeOffset() 30 | { 31 | TimeSpan offset = TimeZoneInfo.Local.GetUtcOffset( DateTime.UtcNow ); 32 | int iofs = (int)offset.TotalSeconds * 1000; 33 | return iofs; 34 | } 35 | 36 | /// 37 | /// 38 | /// 39 | /// 40 | /// 41 | public static DateTime GetDateTime( long timestamp, int offset = 0 ) 42 | { 43 | DateTime start = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); 44 | //DateTime date = start.AddMilliseconds(timestamp).ToLocalTime(); 45 | DateTime date = start.AddMilliseconds( timestamp + offset ); 46 | return date; 47 | } 48 | 49 | public static DateTime GetLocalDateTimeFromUtcTimestamp( long timestamp ) 50 | { 51 | DateTime start = new DateTime( 1970, 1, 1, 0, 0, 0, DateTimeKind.Utc ); 52 | DateTime date = start.AddMilliseconds(timestamp).ToLocalTime(); 53 | return date; 54 | } 55 | 56 | /// 57 | /// 58 | /// 59 | /// 60 | public static long GetTimeGap() 61 | { 62 | // 30day gap 63 | return 2592000000; 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /Neosmartpen.Net.Usb/Neosmarpen/Net/Usb/Events/BatteryStatusReceivedEventArgs.cs: -------------------------------------------------------------------------------- 1 | namespace Neosmartpen.Net.Usb.Events 2 | { 3 | /// 4 | /// Event argument containing the battery status of the connected pen 5 | /// 6 | public class BatteryStatusReceivedEventArgs : System.EventArgs 7 | { 8 | /// 9 | /// Battery current status (0~100%) 10 | /// 11 | public int Battery { get; private set; } 12 | 13 | internal BatteryStatusReceivedEventArgs() 14 | { 15 | } 16 | 17 | internal BatteryStatusReceivedEventArgs(int battery) : base() 18 | { 19 | Battery = battery; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Neosmartpen.Net.Usb/Neosmarpen/Net/Usb/Events/ConfigSetupResultReceivedEventArgs.cs: -------------------------------------------------------------------------------- 1 | namespace Neosmartpen.Net.Usb.Events 2 | { 3 | /// 4 | /// Event argument indicating the result of the pen's configuration change. 5 | /// 6 | public class ConfigSetupResultReceivedEventArgs : System.EventArgs 7 | { 8 | /// 9 | /// Setting type of the pen 10 | /// 11 | public ConfigType Type { get; private set; } 12 | /// 13 | /// Change 14 | /// 15 | public bool IsChanged { get; private set; } 16 | 17 | internal ConfigSetupResultReceivedEventArgs(ConfigType type, bool isChanged) 18 | { 19 | Type = type; 20 | IsChanged = isChanged; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Neosmartpen.Net.Usb/Neosmarpen/Net/Usb/Events/ConnectionStatusChangedEventArgs.cs: -------------------------------------------------------------------------------- 1 | namespace Neosmartpen.Net.Usb.Events 2 | { 3 | /// 4 | /// Event argument that returns a UsbPenComm object that communicates with the pen when there is a change in connectivity with the pen. 5 | /// 6 | public class ConnectionStatusChangedEventArgs : System.EventArgs 7 | { 8 | /// 9 | /// UsbPenComm object for communicating with the pen 10 | /// 11 | public UsbPenComm UsbPenComm { get; private set; } 12 | 13 | internal ConnectionStatusChangedEventArgs(UsbPenComm usbPenComm) : base() 14 | { 15 | UsbPenComm = usbPenComm; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Neosmartpen.Net.Usb/Neosmarpen/Net/Usb/Events/DateTimeReceivedEventArgs.cs: -------------------------------------------------------------------------------- 1 | using Neosmartpen.Net.Support; 2 | using System; 3 | 4 | namespace Neosmartpen.Net.Usb.Events 5 | { 6 | /// 7 | /// Event arguments that contain date and time settings for the pen 8 | /// 9 | public class DateTimeReceivedEventArgs : System.EventArgs 10 | { 11 | /// 12 | /// Current date and time settings for the pen 13 | /// 14 | public System.DateTime DateTime { get; private set; } 15 | 16 | internal DateTimeReceivedEventArgs(long timestamp) 17 | { 18 | DateTime = Time.GetLocalDateTimeFromUtcTimestamp(timestamp); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Neosmartpen.Net.Usb/Neosmarpen/Net/Usb/Events/FileDownloadResultReceivedEventArgs.cs: -------------------------------------------------------------------------------- 1 | namespace Neosmartpen.Net.Usb.Events 2 | { 3 | /// 4 | /// Event argument containing the result of the file download 5 | /// 6 | public class FileDownloadResultReceivedEventArgs : System.EventArgs 7 | { 8 | /// 9 | /// File download result type 10 | /// 11 | public enum ResultType { Success, FileNotExists, Failed, OffsetInvalid, CannotOpenFile, UnknownError } 12 | 13 | /// 14 | /// File download result 15 | /// 16 | public ResultType Result { get; private set; } 17 | 18 | internal FileDownloadResultReceivedEventArgs(ResultType result) 19 | { 20 | Result = result; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Neosmartpen.Net.Usb/Neosmarpen/Net/Usb/Events/FileInfoReceivedEventArgs.cs: -------------------------------------------------------------------------------- 1 | namespace Neosmartpen.Net.Usb.Events 2 | { 3 | /// 4 | /// Event arguments containing file information 5 | /// 6 | public class FileInfoReceivedEventArgs : System.EventArgs 7 | { 8 | /// 9 | /// File information result type 10 | /// 11 | public enum ResultType { Success = 0x00, FileNotExists = 0x01 } 12 | 13 | /// 14 | /// File information result 15 | /// 16 | public ResultType Result { get; private set; } 17 | 18 | /// 19 | /// File name 20 | /// 21 | public string FileName { get; private set; } 22 | 23 | /// 24 | /// Size of file (bytes) 25 | /// 26 | public int FileSize { get; private set; } 27 | 28 | internal FileInfoReceivedEventArgs(ResultType result, string fileName, int fileSize) 29 | { 30 | Result = result; 31 | FileName = fileName; 32 | FileSize = fileSize; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Neosmartpen.Net.Usb/Neosmarpen/Net/Usb/Events/FileListReceivedEventArgs.cs: -------------------------------------------------------------------------------- 1 | namespace Neosmartpen.Net.Usb.Events 2 | { 3 | /// 4 | /// Event arguments containing a list of files 5 | /// 6 | public class FileListReceivedEventArgs : System.EventArgs 7 | { 8 | /// 9 | /// Result type 10 | /// 11 | public enum ResultType { Success, Failed, TooManyFileExists, UnknownError } 12 | 13 | /// 14 | /// Result 15 | /// 16 | public ResultType Result { get; private set; } 17 | 18 | /// 19 | /// List of files 20 | /// 21 | public string[] Files { get; private set; } 22 | 23 | internal FileListReceivedEventArgs(ResultType result, string[] files) 24 | { 25 | Result = result; 26 | Files = files; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Neosmartpen.Net.Usb/Neosmarpen/Net/Usb/Events/ProgressChangedEventArgs.cs: -------------------------------------------------------------------------------- 1 | namespace Neosmartpen.Net.Usb.Events 2 | { 3 | /// 4 | /// Event arguments that contain progress information 5 | /// 6 | public class ProgressChangedEventArgs : System.EventArgs 7 | { 8 | /// 9 | /// Current progress (0~100%) 10 | /// 11 | public int Progress { get; private set; } 12 | 13 | internal ProgressChangedEventArgs(int progress) 14 | { 15 | Progress = progress; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Neosmartpen.Net.Usb/Neosmarpen/Net/Usb/Events/ResultReceivedEventArgs.cs: -------------------------------------------------------------------------------- 1 | namespace Neosmartpen.Net.Usb.Events 2 | { 3 | /// 4 | /// Event arguments that contain simple results for the request 5 | /// 6 | public class ResultReceivedEventArgs : System.EventArgs 7 | { 8 | /// 9 | /// Result type 10 | /// 11 | public enum ResultType { Success, Failed } 12 | 13 | /// 14 | /// Result 15 | /// 16 | public ResultType Result { get; private set; } 17 | 18 | internal ResultReceivedEventArgs(ResultType result) 19 | { 20 | Result = result; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Neosmartpen.Net.Usb/Neosmarpen/Net/Usb/Events/StorageStatusReceivedEventArgs.cs: -------------------------------------------------------------------------------- 1 | namespace Neosmartpen.Net.Usb.Events 2 | { 3 | /// 4 | /// Event argument containing the storage status of the connected pen 5 | /// 6 | public class StorageStatusReceivedEventArgs : System.EventArgs 7 | { 8 | /// 9 | /// Total Storage Size (KB) 10 | /// 11 | public int TotalSize { get; private set; } 12 | 13 | /// 14 | /// Free Storage Size (KB) 15 | /// 16 | public int FreeSize { get; private set; } 17 | 18 | internal StorageStatusReceivedEventArgs(int total, int free) 19 | { 20 | TotalSize = total; 21 | FreeSize = free; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Neosmartpen.Net.Usb/Neosmarpen/Net/Usb/Events/UpdateResultReceivedEventArgs.cs: -------------------------------------------------------------------------------- 1 | namespace Neosmartpen.Net.Usb.Events 2 | { 3 | /// 4 | /// Event argument containing the result of the firmware update request 5 | /// 6 | public class UpdateResultReceivedEventArgs : System.EventArgs 7 | { 8 | /// 9 | /// Result type 10 | /// 11 | public enum ResultType { Complete, DeviceIsNotCorrect, FirmwareVersionIsNotCorrect, UnknownError } 12 | 13 | /// 14 | /// Result 15 | /// 16 | public ResultType Result { get; private set; } 17 | 18 | internal UpdateResultReceivedEventArgs(ResultType result) 19 | { 20 | Result = result; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Neosmartpen.Net.Usb/Neosmarpen/Net/Usb/Exceptions/FileCannotLoadException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Neosmartpen.Net.Usb.Exceptions 4 | { 5 | /// 6 | /// Exception thrown when file cannot be opened at specified location 7 | /// 8 | public class FileCannotLoadException : Exception 9 | { 10 | internal FileCannotLoadException() 11 | { 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Neosmartpen.Net.Usb/Neosmarpen/Net/Usb/Exceptions/FileNameIsTooLongException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Neosmartpen.Net.Usb.Exceptions 4 | { 5 | /// 6 | /// Exception thrown when the specified file name is too long 7 | /// 8 | public class FileNameIsTooLongException : Exception 9 | { 10 | internal FileNameIsTooLongException() 11 | { 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Neosmartpen.Net.Usb/Neosmarpen/Net/Usb/Exceptions/FirmwareVersionIsTooLongException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Neosmartpen.Net.Usb.Exceptions 4 | { 5 | /// 6 | /// Exception that occurs when the specified firmware version name is too long 7 | /// 8 | public class FirmwareVersionIsTooLongException : Exception 9 | { 10 | internal FirmwareVersionIsTooLongException() 11 | { 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Neosmartpen.Net.Usb/Neosmarpen/Net/Usb/Exceptions/IsNotActiveException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Neosmartpen.Net.Usb.Exceptions 4 | { 5 | /// 6 | /// Exception thrown when a connection is not established when requesting a pen command 7 | /// 8 | public class IsNotActiveException : Exception 9 | { 10 | internal IsNotActiveException() 11 | { 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Neosmartpen.Net.Usb/Neosmarpen/Net/Usb/Exceptions/NoSuchPenException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Neosmartpen.Net.Usb.Exceptions 4 | { 5 | /// 6 | /// Exception thrown when pen doesn't exist 7 | /// 8 | public class NoSuchPenException : Exception 9 | { 10 | internal NoSuchPenException() 11 | { 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Neosmartpen.Net.Usb/Neosmarpen/Net/Usb/Exceptions/NotSupportedVersionException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Neosmartpen.Net.Usb.Exceptions 4 | { 5 | /// 6 | /// Exception raised when the pen does not support the function 7 | /// 8 | public class NotSupportedVersionException : Exception 9 | { 10 | internal NotSupportedVersionException() 11 | { 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Neosmartpen.Net.Usb/Neosmarpen/Net/Usb/Exceptions/TimeOutOfRangeException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Neosmartpen.Net.Usb.Exceptions 4 | { 5 | /// 6 | /// Occurs when the entered time value exceeds the range 7 | /// 8 | public class TimeOutOfRangeException : Exception 9 | { 10 | internal TimeOutOfRangeException() 11 | { 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Neosmartpen.Net.Usb/Neosmarpen/Net/Usb/FileBuilder.cs: -------------------------------------------------------------------------------- 1 | using Neosmartpen.Net.Support; 2 | using System; 3 | 4 | namespace Neosmartpen.Net.Usb 5 | { 6 | public class FileBuilder 7 | { 8 | private ByteUtil byteUtil; 9 | 10 | public string FilePath { private set; get; } 11 | public int FileSize { private set; get; } 12 | public int PacketSize { private set; get; } 13 | 14 | public FileBuilder( string filePath, int fileSize, int packetSize ) 15 | { 16 | byteUtil = new ByteUtil(); 17 | FilePath = filePath; 18 | FileSize = fileSize; 19 | PacketSize = packetSize > fileSize ? fileSize : packetSize; 20 | } 21 | 22 | public int GetPacketSize(int index) 23 | { 24 | if (index < FileSize - 1) 25 | { 26 | if ((FileSize - 1 - index) > PacketSize) 27 | { 28 | return PacketSize; 29 | } 30 | else 31 | { 32 | return PacketSize - (FileSize - 1 - index); 33 | } 34 | } 35 | else 36 | { 37 | return -1; 38 | } 39 | } 40 | 41 | public bool MakeFile() 42 | { 43 | return ByteToFile(byteUtil.ToArray(), FilePath); 44 | } 45 | 46 | public bool Put(byte[] data, int offset) 47 | { 48 | if (byteUtil.WritePosition == offset) 49 | { 50 | byteUtil.Put(data); 51 | return true; 52 | } 53 | else 54 | return false; 55 | } 56 | 57 | public int GetNextOffset() 58 | { 59 | return byteUtil.WritePosition; 60 | } 61 | 62 | private bool ByteToFile( byte[] bytes, String filepath ) 63 | { 64 | try 65 | { 66 | System.IO.FileStream fs = new System.IO.FileStream( filepath, System.IO.FileMode.Create, System.IO.FileAccess.Write ); 67 | fs.Write( bytes, 0, bytes.Length ); 68 | fs.Close(); 69 | 70 | return true; 71 | } 72 | catch ( Exception e ) 73 | { 74 | Console.WriteLine( "[FileSerializer] Exception caught in process: {0}", e.StackTrace ); 75 | } 76 | 77 | // error occured, return false 78 | return false; 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /Neosmartpen.Net.Usb/Neosmarpen/Net/Usb/FileSplitter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace Neosmartpen.Net.Usb 6 | { 7 | public class FileSplitter 8 | { 9 | private Dictionary chunks; 10 | 11 | public int PacketCount { private set; get; } 12 | public string FilePath { private set; get; } 13 | public int FileSize { private set; get; } 14 | public int PacketSize { private set; get; } 15 | 16 | private int leftByte = 0; 17 | 18 | private byte[] datas; 19 | 20 | public FileSplitter() 21 | { 22 | } 23 | 24 | public bool Load(string filePath) 25 | { 26 | try 27 | { 28 | FilePath = filePath; 29 | datas = System.IO.File.ReadAllBytes(FilePath); 30 | FileSize = datas.Length; 31 | return true; 32 | } 33 | catch 34 | { 35 | return false; 36 | } 37 | } 38 | 39 | public bool Split(int packetSize) 40 | { 41 | if (datas == null || datas.Length <= 0) 42 | return false; 43 | 44 | try 45 | { 46 | PacketSize = packetSize > FileSize ? FileSize : packetSize; 47 | chunks = new Dictionary(); 48 | if ((leftByte = FileSize % PacketSize) == 0) 49 | PacketCount = FileSize / PacketSize; 50 | else 51 | PacketCount = (FileSize / PacketSize) + 1; 52 | return true; 53 | } 54 | catch 55 | { 56 | return false; 57 | } 58 | } 59 | 60 | public byte[] GetBytes(int offset) 61 | { 62 | return datas.Skip(offset).Take(PacketSize).ToArray(); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /Neosmartpen.Net.Usb/Neosmarpen/Net/Usb/Protocol.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Neosmartpen.Net.Usb 4 | { 5 | public class Const 6 | { 7 | public const char CMD_PRIFIX_1 = 'A'; 8 | public const char CMD_PRIFIX_2 = 'T'; 9 | public const char CMD_PRIFIX_3 = '+'; 10 | 11 | public const char CMD_DELIMITER_REQUEST = '='; 12 | public const char CMD_DELIMITER_RESPONSE = '?'; 13 | public const char CMD_DELIMITER_EVENT = '$'; 14 | 15 | public const char CMD_DELIMITER_DATA = ','; 16 | } 17 | 18 | [Flags] 19 | public enum Cmd 20 | { 21 | START, 22 | GETDEVINFO, 23 | GETCONFIG, 24 | SETCONFIG, 25 | FORMAT, 26 | GETOFFLINEDATALIST, 27 | GETLOGFILELIST, 28 | GETFILE_H, 29 | GETFILE_D, 30 | DELETEFILE, 31 | POWEROFF, 32 | UPDATE_START, 33 | UPDATE_DO, 34 | GETDISKINFO 35 | }; 36 | 37 | [Flags] 38 | public enum PacketType 39 | { 40 | Request, 41 | Response, 42 | Event 43 | }; 44 | 45 | /// 46 | /// An enum indicating the setting type of the pen 47 | /// 48 | [Flags] 49 | public enum ConfigType 50 | { 51 | /// 52 | /// DateTime 53 | /// 54 | DateTime = 0x01, 55 | /// 56 | /// AutoPowerOffTime 57 | /// 58 | AutoPowerOffTime = 0x02, 59 | /// 60 | /// AutoPowerOn 61 | /// 62 | AutoPowerOn = 0x03, 63 | /// 64 | /// PenCapOff 65 | /// 66 | PenCapOff = 0x04, 67 | /// 68 | /// Beep 69 | /// 70 | Beep = 0x05, 71 | /// 72 | /// SaveOfflineData 73 | /// 74 | SaveOfflineData = 0x07, 75 | /// 76 | /// DownSampling 77 | /// 78 | DownSampling = 0x08, 79 | /// 80 | /// Battery 81 | /// 82 | Battery = 0x09 83 | }; 84 | 85 | /// 86 | /// Enum indicating the file type of the pen 87 | /// 88 | [Flags] 89 | public enum FileType 90 | { 91 | /// 92 | /// Data file type 93 | /// 94 | Data, 95 | /// 96 | /// Log file type 97 | /// 98 | Log 99 | }; 100 | } 101 | -------------------------------------------------------------------------------- /Neosmartpen.Net.Usb/Neosmartpen.Net.Usb.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {AC2123A7-B4A3-4998-9713-235DD916F93C} 8 | Library 9 | Properties 10 | Neosmartpen.Net.Usb 11 | Neosmartpen.Net.Usb 12 | v4.6.2 13 | 512 14 | true 15 | 16 | 17 | 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | bin\Debug\Neosmartpen.Net.Usb.xml 26 | false 27 | 28 | 29 | pdbonly 30 | true 31 | bin\Release\ 32 | TRACE 33 | prompt 34 | 4 35 | false 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 1.4.2 94 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /Neosmartpen.Net.Usb/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 6 | // 제어됩니다. 어셈블리와 관련된 정보를 수정하려면 7 | // 이러한 특성 값을 변경하세요. 8 | [assembly: AssemblyTitle("Neosmartpen.Net.Usb")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Neosmartpen.Net.Usb")] 13 | [assembly: AssemblyCopyright("Copyright © 2019")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에 18 | // 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면 19 | // 해당 형식에 대해 ComVisible 특성을 true로 설정하세요. 20 | [assembly: ComVisible(false)] 21 | 22 | // 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다. 23 | [assembly: Guid("ac2123a7-b4a3-4998-9713-235dd916f93c")] 24 | 25 | // 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다. 26 | // 27 | // 주 버전 28 | // 부 버전 29 | // 빌드 번호 30 | // 수정 버전 31 | // 32 | // 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호를 33 | // 기본값으로 할 수 있습니다. 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("2.1.21.0")] 36 | [assembly: AssemblyFileVersion("2.1.21")] 37 | -------------------------------------------------------------------------------- /Neosmartpen.Net/Neosmartpen/Framework/Net/Client/IPenClient.cs: -------------------------------------------------------------------------------- 1 | using Windows.Networking.Sockets; 2 | 3 | namespace Neosmartpen.Net 4 | { 5 | /// 6 | /// 7 | /// IPenClient class provides fuctions that can handle pen. 8 | /// 9 | public interface IPenClient 10 | { 11 | IPenController PenController 12 | { 13 | get; 14 | } 15 | 16 | string Name 17 | { 18 | get; 19 | set; 20 | } 21 | 22 | /// 23 | /// Get the connection status of StreamSocket, ie, whether there is an active connection with remote device. 24 | /// 25 | bool Alive 26 | { 27 | get; 28 | } 29 | 30 | /// 31 | /// unbind a socket instance 32 | /// 33 | System.Threading.Tasks.Task Unbind(); 34 | 35 | 36 | /// 37 | /// To write data to stream 38 | /// 39 | /// 40 | void Write(byte[] data); 41 | 42 | /// 43 | /// To read data when device write something 44 | /// 45 | void Read(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Neosmartpen.Net/Neosmartpen/Framework/Net/Client/IPenController.cs: -------------------------------------------------------------------------------- 1 | namespace Neosmartpen.Net 2 | { 3 | /// 4 | /// 5 | /// Represents a controller of pen 6 | /// 7 | public interface IPenController 8 | { 9 | /// 10 | /// Fired when read data, override to parse data in your implementation 11 | /// 12 | /// byte array of new data 13 | void OnDataReceived( byte[] buff ); 14 | 15 | /// 16 | /// Gets binded PenClient 17 | /// 18 | IPenClient PenClient { get; set; } 19 | 20 | /// 21 | /// Get Protocol version 22 | /// 23 | int Protocol { get; set; } 24 | /// 25 | /// Fired when a connection is made, override to handle in your own code. 26 | /// 27 | void OnConnected(); 28 | 29 | /// 30 | /// Fired when a connection is destroyed, override to handle in your own code. 31 | /// 32 | void OnDisconnected(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Neosmartpen.Net/Neosmartpen/Framework/Net/Data/Pds.cs: -------------------------------------------------------------------------------- 1 | namespace Neosmartpen.Net 2 | { 3 | /// 4 | public class Pds 5 | { 6 | internal Pds() 7 | { 8 | 9 | } 10 | public Pds(int section, int owner, int content, int page, float x, float y) 11 | { 12 | Section = section; 13 | Owner = owner; 14 | Content = content; 15 | Page = page; 16 | X = x; 17 | Y = y; 18 | } 19 | 20 | public int Section { get; set; } 21 | public int Owner { get; set; } 22 | public int Content { get; set; } 23 | public int Page { get; set; } 24 | public float X { get; set; } 25 | public float Y { get; set; } 26 | 27 | public Pds Clone() 28 | { 29 | var pds = new Pds(); 30 | pds.Section = Section; 31 | pds.Owner = Owner; 32 | pds.Content = Content; 33 | pds.Page = Page; 34 | pds.X = X; 35 | pds.Y = Y; 36 | return pds; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Neosmartpen.Net/Neosmartpen/Framework/Net/Data/Stroke.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Neosmartpen.Net 5 | { 6 | /// 7 | /// Represents coordinate of stroke. 8 | /// It consist of Dot's Collection. 9 | /// 10 | public class Stroke : List 11 | { 12 | /// 13 | /// Gets the Section Id of the NCode paper 14 | /// 15 | public int Section { get; private set; } 16 | 17 | /// 18 | /// Gets the Owner Id of the NCode paper 19 | /// 20 | public int Owner { get; private set; } 21 | 22 | /// 23 | /// Gets the Note Id of the NCode paper 24 | /// 25 | public int Note { get; private set; } 26 | 27 | /// 28 | /// Gets the Page Number of the NCode paper 29 | /// 30 | public int Page { get; private set; } 31 | 32 | /// 33 | /// Gets the color of the stroke 34 | /// 35 | public int Color { get; private set; } 36 | 37 | /// 38 | /// Gets the timestamp of start point 39 | /// 40 | public long TimeStart { get; private set; } 41 | 42 | /// 43 | /// Gets the timestamp of end point 44 | /// 45 | public long TimeEnd { get; private set; } 46 | 47 | /// 48 | /// A constructor that constructs a Stroke object 49 | /// 50 | /// The Section Id of the NCode paper 51 | /// The Owner Id of the NCode paper 52 | /// The Note Id of the NCode paper 53 | /// The Page Number of the NCode paper 54 | public Stroke( int section, int owner, int note, int page ) 55 | { 56 | Section = section; 57 | Owner = owner; 58 | Note = note; 59 | Page = page; 60 | } 61 | 62 | /// 63 | /// Adds a new Dot to the current Stroke object. 64 | /// 65 | /// Dot object 66 | public new void Add( Dot dot ) 67 | { 68 | if ( base.Count <= 0 ) 69 | { 70 | TimeStart = dot.Timestamp; 71 | Color = dot.Color; 72 | } 73 | 74 | TimeEnd = dot.Timestamp; 75 | 76 | base.Add( dot ); 77 | } 78 | 79 | public override string ToString() 80 | { 81 | return String.Format( "Stroke => sectionId : {0}, ownerId : {1}, noteId : {2}, pageId : {3}, timeStart : {4}, timeEnd : {5}", Section, Owner, Note, Page, TimeStart, TimeEnd ); 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /Neosmartpen.Net/Neosmartpen/Framework/Net/IPacket.cs: -------------------------------------------------------------------------------- 1 | namespace Neosmartpen.Net 2 | { 3 | /// 4 | public interface IPacket 5 | { 6 | int Cmd { get; } 7 | 8 | byte GetByte(); 9 | 10 | byte[] GetBytes(); 11 | 12 | byte[] GetBytes( int size ); 13 | 14 | int GetByteToInt(); 15 | 16 | byte GetChecksum(); 17 | 18 | byte GetChecksum( int length ); 19 | 20 | int GetInt(); 21 | 22 | long GetLong(); 23 | 24 | short GetShort(); 25 | 26 | string GetString( int length ); 27 | 28 | IPacket Move( int length ); 29 | 30 | IPacket Reset(); 31 | 32 | int Result { get; } 33 | 34 | string ToString(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Neosmartpen.Net/Neosmartpen/Implementation/Net/Bluetooth/PenInfomation.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel; 3 | using System.Runtime.CompilerServices; 4 | using Windows.Devices.Enumeration; 5 | 6 | namespace Neosmartpen.Net.Bluetooth 7 | { 8 | /// 9 | /// Represents Information of smartpen device 10 | /// 11 | public class PenInformation : INotifyPropertyChanged 12 | { 13 | public static PenInformation Create(DeviceInformation devInfo, string name, ulong vMac, string mac, int rssi, int protocol, bool isLe = false) 14 | { 15 | return new PenInformation(devInfo, isLe) 16 | { 17 | name = name, 18 | VirtualMacAddress = vMac, 19 | MacAddress = mac, 20 | Rssi = rssi, 21 | Protocol = protocol 22 | }; 23 | } 24 | internal PenInformation(DeviceInformation devInfo, bool isLe = false) 25 | { 26 | deviceInformation = devInfo; 27 | IsLe = isLe; 28 | } 29 | 30 | public bool IsLe { get; internal set; } 31 | 32 | 33 | /// 34 | /// Gets the device identifier 35 | /// 36 | public string Id 37 | { 38 | get 39 | { 40 | if (deviceInformation == null) 41 | return string.Empty; 42 | return deviceInformation.Id; 43 | } 44 | } 45 | 46 | /// 47 | /// Gets a common name of a device 48 | /// 49 | public string Name 50 | { 51 | get 52 | { 53 | if (IsLe) 54 | { 55 | return name; 56 | } 57 | else 58 | { 59 | if (deviceInformation == null) 60 | return string.Empty; 61 | return deviceInformation.Name; 62 | } 63 | } 64 | } 65 | private string name; 66 | 67 | /// 68 | /// Gets the signal strength for the Bluetooth connection with the peer device 69 | /// 70 | public int Rssi 71 | { 72 | get { return rssi; } 73 | internal set 74 | { 75 | rssi = value; 76 | NotifyPropertyChanged(); 77 | } 78 | } 79 | private int rssi; 80 | 81 | /// 82 | /// Gets the device's mac address 83 | /// 84 | public string MacAddress { get; internal set; } 85 | public ulong BluetoothAddress 86 | { 87 | get 88 | { 89 | string temp = MacAddress.Replace(":", ""); 90 | 91 | return Convert.ToUInt64(temp, 16); 92 | } 93 | } 94 | 95 | public int Protocol 96 | { 97 | get; set; 98 | } 99 | 100 | public void Update(PenUpdateInformation update) 101 | { 102 | if (IsLe) 103 | { 104 | Rssi = update.Rssi; 105 | if (!string.IsNullOrEmpty(update.ModelName)) 106 | { 107 | name = update.ModelName; 108 | NotifyPropertyChanged("Name"); 109 | } 110 | } 111 | else 112 | { 113 | if (deviceInformation != null && update.deviceInformationUpdate != null) 114 | { 115 | deviceInformation.Update(update.deviceInformationUpdate); 116 | } 117 | } 118 | } 119 | 120 | public override string ToString() 121 | { 122 | return "[" + Name + "] " + MacAddress; 123 | } 124 | 125 | internal DeviceInformation deviceInformation; 126 | public ulong VirtualMacAddress { get; set; } 127 | 128 | public event PropertyChangedEventHandler PropertyChanged; 129 | public void NotifyPropertyChanged([CallerMemberName] string propertyName = null) 130 | => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); 131 | } 132 | 133 | public class PenUpdateInformation 134 | { 135 | public static PenUpdateInformation Create(DeviceInformationUpdate update, bool isLe = false) 136 | { 137 | return new PenUpdateInformation(update, isLe); 138 | } 139 | public static PenUpdateInformation Create(string id, bool isLe = false) 140 | { 141 | return new PenUpdateInformation(null, isLe) 142 | { 143 | id = id 144 | }; 145 | } 146 | internal PenUpdateInformation(DeviceInformationUpdate update, bool isLe = false) 147 | { 148 | deviceInformationUpdate = update; 149 | IsLe = isLe; 150 | } 151 | public bool IsLe { get; internal set; } 152 | 153 | internal string id; 154 | public string Id 155 | { 156 | get 157 | { 158 | if (!string.IsNullOrEmpty(id)) 159 | return id; 160 | if (deviceInformationUpdate != null) 161 | return deviceInformationUpdate.Id; 162 | return string.Empty; 163 | } 164 | } 165 | public string ModelName { get; set; } 166 | public int Rssi { get; set; } 167 | 168 | internal DeviceInformationUpdate deviceInformationUpdate; 169 | 170 | } 171 | } 172 | -------------------------------------------------------------------------------- /Neosmartpen.Net/Neosmartpen/Implementation/Net/Client/Chunk.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Threading.Tasks; 5 | using Windows.Storage; 6 | using Windows.Storage.Streams; 7 | 8 | namespace Neosmartpen.Net 9 | { 10 | /// 11 | public class Chunk 12 | { 13 | // chunk size is 0.5k 14 | private int mSize = 512; 15 | 16 | private int mRows; 17 | 18 | private List mBuffer; 19 | 20 | private int mFileSize = 0; 21 | 22 | private byte mCheckSum; 23 | 24 | public Chunk(int chunksize) 25 | { 26 | mSize = chunksize; 27 | } 28 | 29 | public Chunk() 30 | { 31 | } 32 | 33 | public static List SplitByteArray(byte[] bytes, int range) 34 | { 35 | List chunk = new List(); 36 | List result = new List(); 37 | 38 | int i = 1; 39 | int c = 1; 40 | 41 | foreach (byte b in bytes) 42 | { 43 | // Put the byte into the bytes array 44 | chunk.Add(b); 45 | 46 | // If we match the range, add the byte array and create new one 47 | if (i == range || c == bytes.Length) 48 | { 49 | // Add as array 50 | result.Add(chunk.ToArray()); 51 | 52 | // Create again 53 | chunk = new List(); 54 | i = 0; 55 | } 56 | 57 | c++; 58 | i++; 59 | } 60 | 61 | return result; 62 | } 63 | 64 | public async Task Load(string filepath) 65 | { 66 | return await Load(await StorageFile.GetFileFromPathAsync(filepath)); 67 | } 68 | 69 | public async Task Load(StorageFile filepath) 70 | { 71 | byte[] datas = null; 72 | 73 | try 74 | { 75 | IBuffer buffer = await FileIO.ReadBufferAsync(filepath); 76 | datas = System.Runtime.InteropServices.WindowsRuntime.WindowsRuntimeBufferExtensions.ToArray(buffer); 77 | 78 | mCheckSum = CalcChecksum(datas); 79 | } 80 | catch (Exception ex) 81 | { 82 | Debug.WriteLine(ex.Message); 83 | return false; 84 | } 85 | 86 | if (datas == null) 87 | { 88 | return false; 89 | } 90 | 91 | mFileSize = datas.Length; 92 | 93 | double filesize = datas.Length / mSize; 94 | 95 | mRows = (int)Math.Ceiling(filesize) + 1; 96 | 97 | mBuffer = SplitByteArray(datas, mSize); 98 | 99 | return true; 100 | } 101 | 102 | public bool Load(byte[] datas) 103 | { 104 | try 105 | { 106 | mCheckSum = CalcChecksum(datas); 107 | } 108 | catch (Exception ex) 109 | { 110 | Debug.WriteLine(ex.Message); 111 | return false; 112 | } 113 | 114 | if (datas == null) 115 | { 116 | return false; 117 | } 118 | 119 | mFileSize = datas.Length; 120 | 121 | double filesize = datas.Length / mSize; 122 | 123 | mRows = (int)Math.Ceiling(filesize) + 1; 124 | 125 | mBuffer = SplitByteArray(datas, mSize); 126 | 127 | return true; 128 | } 129 | 130 | public byte[] Get(int number) 131 | { 132 | return mBuffer != null && mBuffer.Count > number ? mBuffer[number] : null; 133 | } 134 | 135 | public int GetFileSize() 136 | { 137 | return mFileSize; 138 | } 139 | 140 | public int GetChunkLength() 141 | { 142 | return mRows; 143 | } 144 | 145 | public int GetChunksize() 146 | { 147 | return mSize; 148 | } 149 | 150 | public byte GetChecksum(int number) 151 | { 152 | return Get(number) != null ? CalcChecksum(Get(number)) : (byte)0x00; 153 | } 154 | 155 | public byte GetTotalChecksum() 156 | { 157 | return mCheckSum; 158 | } 159 | 160 | public static byte CalcChecksum(byte[] bytes) 161 | { 162 | int CheckSum = 0; 163 | 164 | for (int i = 0; i < bytes.Length; i++) 165 | { 166 | CheckSum += (int)(bytes[i] & 0xFF); 167 | } 168 | 169 | return (byte)CheckSum; 170 | } 171 | } 172 | } 173 | -------------------------------------------------------------------------------- /Neosmartpen.Net/Neosmartpen/Implementation/Net/Client/ChunkEx.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Windows.Storage; 7 | using Windows.Storage.Streams; 8 | 9 | namespace Neosmartpen.Net 10 | { 11 | /// 12 | public class ChunkEx 13 | { 14 | // chunk size is 0.5k 15 | private int mSize = 1024; 16 | 17 | private int mRows; 18 | 19 | private byte[] mDatas; 20 | 21 | private int mFileSize = 0; 22 | 23 | public ChunkEx(int chunksize) 24 | { 25 | mSize = chunksize; 26 | } 27 | 28 | public async Task Load(string filepath) 29 | { 30 | return await Load(await StorageFile.GetFileFromPathAsync(filepath)); 31 | } 32 | 33 | public async Task Load(StorageFile filepath) 34 | { 35 | byte[] datas = null; 36 | 37 | try 38 | { 39 | IBuffer buffer = await FileIO.ReadBufferAsync(filepath); 40 | datas = System.Runtime.InteropServices.WindowsRuntime.WindowsRuntimeBufferExtensions.ToArray(buffer); 41 | } 42 | catch (Exception ex) 43 | { 44 | Debug.WriteLine(ex.Message); 45 | return false; 46 | } 47 | 48 | if (datas == null) 49 | { 50 | return false; 51 | } 52 | 53 | mFileSize = datas.Length; 54 | 55 | double filesize = datas.Length / mSize; 56 | 57 | mRows = (int)Math.Ceiling(filesize) + 1; 58 | 59 | mDatas = datas; 60 | 61 | return true; 62 | } 63 | 64 | public byte[] Get(int offset, int size) 65 | { 66 | return mDatas.Skip(offset).Take(size).ToArray(); 67 | } 68 | 69 | public byte[] Get(int offset) 70 | { 71 | return Get(offset, mSize); 72 | } 73 | 74 | public int GetFileSize() 75 | { 76 | return mFileSize; 77 | } 78 | 79 | public int GetChunkLength() 80 | { 81 | return mRows; 82 | } 83 | 84 | public int GetChunksize() 85 | { 86 | return mSize; 87 | } 88 | 89 | public byte GetTotalChecksum() 90 | { 91 | return CalcChecksum(mDatas); 92 | } 93 | 94 | public static byte CalcChecksum(byte[] bytes) 95 | { 96 | int CheckSum = 0; 97 | 98 | for (int i = 0; i < bytes.Length; i++) 99 | { 100 | CheckSum += (int)(bytes[i] & 0xFF); 101 | } 102 | 103 | return (byte)CheckSum; 104 | } 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /Neosmartpen.Net/Neosmartpen/Implementation/Net/Client/DataTransmissionType.cs: -------------------------------------------------------------------------------- 1 | namespace Neosmartpen.Net 2 | { 3 | /// 4 | public enum DataTransmissionType : byte { Event = 0, RequestResponse = 1 }; 5 | } 6 | -------------------------------------------------------------------------------- /Neosmartpen.Net/Neosmartpen/Implementation/Net/Client/Event/BatteryAlarmReceivedEventArgs.cs: -------------------------------------------------------------------------------- 1 | namespace Neosmartpen.Net 2 | { 3 | /// 4 | /// Provides battery data for BatteryAlarmReceived event 5 | /// 6 | public sealed class BatteryAlarmReceivedEventArgs 7 | { 8 | internal BatteryAlarmReceivedEventArgs() { } 9 | internal BatteryAlarmReceivedEventArgs(int battery) { Battery = battery; } 10 | 11 | /// 12 | /// Gets battery level of the pen 13 | /// 14 | public int Battery { get; internal set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Neosmartpen.Net/Neosmartpen/Implementation/Net/Client/Event/ConnectedEventArgs.cs: -------------------------------------------------------------------------------- 1 | namespace Neosmartpen.Net 2 | { 3 | /// 4 | /// Contains properties that information of device with the ConnectedEvent event 5 | /// 6 | public sealed class ConnectedEventArgs 7 | { 8 | internal ConnectedEventArgs() { } 9 | internal ConnectedEventArgs(string firmwareVersion, int maxForce) 10 | { 11 | FirmwareVersion = firmwareVersion; 12 | MaxForce = maxForce; 13 | } 14 | internal ConnectedEventArgs(string macAddress, string deviceName, string firmwareVersion, string protocolVersion, string subName, int maxForce) 15 | : this(firmwareVersion, maxForce) 16 | { 17 | MacAddress = macAddress; 18 | DeviceName = deviceName; 19 | ProtocolVersion = protocolVersion; 20 | SubName = subName; 21 | } 22 | 23 | /// 24 | /// Gets the maximum level of force sensor 25 | /// 26 | public int MaxForce { get; internal set; } 27 | 28 | /// 29 | /// Gets current version of pen's firmware 30 | /// 31 | public string FirmwareVersion { get; internal set; } 32 | 33 | /// 34 | /// Gets the device identifier 35 | /// 36 | public string MacAddress { get; internal set; } 37 | 38 | /// 39 | /// Gets a common name of a device 40 | /// 41 | public string DeviceName { get; internal set; } 42 | 43 | /// 44 | /// Gets a version of a protocol 45 | /// 46 | public string ProtocolVersion { get; internal set; } 47 | 48 | /// 49 | /// Gets a subname of a device 50 | /// 51 | public string SubName { get; internal set; } 52 | } 53 | } -------------------------------------------------------------------------------- /Neosmartpen.Net/Neosmartpen/Implementation/Net/Client/Event/DotReceivedEventArgs.cs: -------------------------------------------------------------------------------- 1 | namespace Neosmartpen.Net 2 | { 3 | /// 4 | /// Contains properties that data of coordinate with the DotReceived event 5 | /// 6 | public sealed class DotReceivedEventArgs 7 | { 8 | internal DotReceivedEventArgs() { } 9 | internal DotReceivedEventArgs(Dot dot) 10 | { 11 | Dot = dot; 12 | } 13 | internal DotReceivedEventArgs(Dot dot, ImageProcessingInfo imageProcessingInfo) 14 | { 15 | Dot = dot; 16 | ImageProcessingInfo = imageProcessingInfo; 17 | } 18 | 19 | /// 20 | /// Gets coordinate data of pen 21 | /// 22 | public Dot Dot { get; internal set; } 23 | 24 | public ImageProcessingInfo ImageProcessingInfo { get; internal set; } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Neosmartpen.Net/Neosmartpen/Implementation/Net/Client/Event/ErrorDetectedEventArgs.cs: -------------------------------------------------------------------------------- 1 | namespace Neosmartpen.Net 2 | { 3 | /// 4 | public enum ErrorType 5 | { 6 | MissingPenUp = 1, 7 | MissingPenDown = 2, 8 | InvalidTime = 3, 9 | MissingPenDownPenMove = 4, 10 | ImageProcessingError = 5, 11 | InvalidEventCount = 6, 12 | MissingPageChange = 7, 13 | MissingPenMove = 8 14 | } 15 | 16 | /// 17 | public sealed class ErrorDetectedEventArgs 18 | { 19 | internal ErrorDetectedEventArgs(ErrorType errorType, long ts) 20 | { 21 | ErrorType = errorType; 22 | Timestamp = ts; 23 | } 24 | 25 | internal ErrorDetectedEventArgs(ErrorType errorType, Dot dot, long ts) 26 | { 27 | ErrorType = errorType; 28 | Dot = dot; 29 | Timestamp = ts; 30 | } 31 | 32 | internal ErrorDetectedEventArgs(ErrorType errorType, Dot dot, long ts, string extraData) 33 | { 34 | ErrorType = errorType; 35 | Dot = dot; 36 | Timestamp = ts; 37 | ExtraData = extraData; 38 | } 39 | 40 | internal ErrorDetectedEventArgs(ErrorType errorType, Dot dot, long ts, ImageProcessErrorInfo imageProcessErrorInfo) 41 | { 42 | ErrorType = errorType; 43 | Dot = dot; 44 | Timestamp = ts; 45 | ImageProcessErrorInfo = imageProcessErrorInfo; 46 | } 47 | 48 | public ErrorType ErrorType { get; internal set; } 49 | 50 | public Dot Dot { get; internal set; } 51 | 52 | public long Timestamp { get; internal set; } 53 | 54 | public string ExtraData { get; internal set; } 55 | 56 | public ImageProcessErrorInfo ImageProcessErrorInfo { get; internal set; } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Neosmartpen.Net/Neosmartpen/Implementation/Net/Client/Event/IPenControllerEvent.cs: -------------------------------------------------------------------------------- 1 | using Windows.Foundation; 2 | 3 | namespace Neosmartpen.Net 4 | { 5 | internal interface IPenControllerEvent 6 | { 7 | event TypedEventHandler Connected; 8 | event TypedEventHandler Disconnected; 9 | event TypedEventHandler OfflineDownloadFinished; 10 | event TypedEventHandler Authenticated; 11 | event TypedEventHandler AvailableNoteAdded; 12 | event TypedEventHandler AutoPowerOnChanged; 13 | event TypedEventHandler AutoPowerOffTimeChanged; 14 | event TypedEventHandler BeepSoundChanged; 15 | event TypedEventHandler PenCapPowerOnOffChanged; 16 | event TypedEventHandler PenColorChanged; 17 | event TypedEventHandler HoverChanged; 18 | event TypedEventHandler OfflineDataChanged; 19 | event TypedEventHandler PasswordRequested; 20 | event TypedEventHandler PasswordChanged; 21 | event TypedEventHandler SensitivityChanged; 22 | event TypedEventHandler RtcTimeChanged; 23 | event TypedEventHandler BatteryAlarmReceived; 24 | event TypedEventHandler DotReceived; 25 | event TypedEventHandler FirmwareInstallationStarted; 26 | event TypedEventHandler FirmwareInstallationFinished; 27 | event TypedEventHandler FirmwareInstallationStatusUpdated; 28 | event TypedEventHandler OfflineDataListReceived; 29 | event TypedEventHandler OfflineStrokeReceived; 30 | event TypedEventHandler PenStatusReceived; 31 | event TypedEventHandler OfflineDataRemoved; 32 | event TypedEventHandler OfflineDataDownloadStarted; 33 | event TypedEventHandler PenProfileReceived; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Neosmartpen.Net/Neosmartpen/Implementation/Net/Client/Event/OfflineDataListReceivedEventArgs.cs: -------------------------------------------------------------------------------- 1 | namespace Neosmartpen.Net 2 | { 3 | /// 4 | /// Contains properties that list of offline data for the OfflineDataListReceived event 5 | /// 6 | public sealed class OfflineDataListReceivedEventArgs 7 | { 8 | internal OfflineDataListReceivedEventArgs() { } 9 | internal OfflineDataListReceivedEventArgs(params OfflineDataInfo[] offlineNotes) 10 | { 11 | OfflineNotes = offlineNotes; 12 | } 13 | 14 | /// 15 | /// Gets array of Offline data information in storage of pen 16 | /// 17 | public OfflineDataInfo[] OfflineNotes { get; internal set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Neosmartpen.Net/Neosmartpen/Implementation/Net/Client/Event/OfflineStrokeReceivedEventArgs.cs: -------------------------------------------------------------------------------- 1 | namespace Neosmartpen.Net 2 | { 3 | /// 4 | /// Contains properties that offline data and status of transmission for the OfflineStrokeReceived event 5 | /// 6 | public sealed class OfflineStrokeReceivedEventArgs 7 | { 8 | internal OfflineStrokeReceivedEventArgs() { } 9 | //mTotalOfflineStroke, mReceivedOfflineStroke, result.ToArray()); 10 | internal OfflineStrokeReceivedEventArgs(int total, int amountDone, Stroke[] strokes) 11 | { 12 | Total = total; 13 | AmountDone = amountDone; 14 | Strokes = strokes; 15 | } 16 | /// 17 | /// Gets total of offline data transmission 18 | /// 19 | public int Total { get; internal set; } 20 | /// 21 | /// Gets amount of transmission done 22 | /// 23 | public int AmountDone { get; internal set; } 24 | /// 25 | /// Gets array of offline data's stroke 26 | /// 27 | public Stroke[] Strokes { get; internal set; } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Neosmartpen.Net/Neosmartpen/Implementation/Net/Client/Event/PasswordRequestedEventArgs.cs: -------------------------------------------------------------------------------- 1 | namespace Neosmartpen.Net 2 | { 3 | /// 4 | /// Contains properties that password count for the PasswordRequested 5 | /// When you received this signal, you have to enter password by PenController.InputPassword() 6 | /// 7 | public sealed class PasswordRequestedEventArgs 8 | { 9 | internal PasswordRequestedEventArgs() { } 10 | internal PasswordRequestedEventArgs(int retryCount, int resetCount) 11 | { 12 | RetryCount = retryCount; 13 | ResetCount = resetCount; 14 | } 15 | /// 16 | /// count of enter password 17 | /// 18 | public int RetryCount { get; internal set; } 19 | /// 20 | /// if retry count reached reset count, delete all data in pen 21 | /// 22 | public int ResetCount { get; internal set; } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Neosmartpen.Net/Neosmartpen/Implementation/Net/Client/Event/PdsReceivedEventArgs.cs: -------------------------------------------------------------------------------- 1 | namespace Neosmartpen.Net 2 | { 3 | /// 4 | public sealed class PdsReceivedEventArgs 5 | { 6 | internal PdsReceivedEventArgs() { } 7 | internal PdsReceivedEventArgs(Pds pds) 8 | { 9 | PDS = pds; 10 | } 11 | 12 | public Pds PDS { get; internal set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Neosmartpen.Net/Neosmartpen/Implementation/Net/Client/Event/PenProfile/PenProfileCreateEventArgs.cs: -------------------------------------------------------------------------------- 1 | namespace Neosmartpen.Net 2 | { 3 | /// 4 | public sealed class PenProfileCreateEventArgs : PenProfileReceivedEventArgs 5 | { 6 | internal PenProfileCreateEventArgs() 7 | { 8 | Type = PenProfileType.Create; 9 | Result = ResultType.Success; 10 | } 11 | internal PenProfileCreateEventArgs(string profileName, int status) : this() 12 | { 13 | ProfileName = profileName; 14 | Status = status; 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Neosmartpen.Net/Neosmartpen/Implementation/Net/Client/Event/PenProfile/PenProfileDeleteEventArgs.cs: -------------------------------------------------------------------------------- 1 | namespace Neosmartpen.Net 2 | { 3 | /// 4 | public sealed class PenProfileDeleteEventArgs : PenProfileReceivedEventArgs 5 | { 6 | internal PenProfileDeleteEventArgs() 7 | { 8 | Result = ResultType.Success; 9 | Type = PenProfileType.Delete; 10 | } 11 | internal PenProfileDeleteEventArgs(string profileName, int status) : this() 12 | { 13 | ProfileName = profileName; 14 | Status = status; 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Neosmartpen.Net/Neosmartpen/Implementation/Net/Client/Event/PenProfile/PenProfileDeleteValueEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Neosmartpen.Net 4 | { 5 | /// 6 | public sealed class PenProfileDeleteValueEventArgs : PenProfileReceivedEventArgs 7 | { 8 | internal PenProfileDeleteValueEventArgs() 9 | { 10 | Type = PenProfileType.DeleteValue; 11 | Result = ResultType.Success; 12 | } 13 | internal PenProfileDeleteValueEventArgs(string profileName) : this() 14 | { 15 | ProfileName = profileName; 16 | Data = new List(); 17 | } 18 | 19 | public List Data { get; internal set; } 20 | 21 | public class DeleteValueResult 22 | { 23 | public string Key { get; internal set; } 24 | public int Status { get; internal set; } 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Neosmartpen.Net/Neosmartpen/Implementation/Net/Client/Event/PenProfile/PenProfileInfoEventArgs.cs: -------------------------------------------------------------------------------- 1 | namespace Neosmartpen.Net 2 | { 3 | /// 4 | public sealed class PenProfileInfoEventArgs : PenProfileReceivedEventArgs 5 | { 6 | internal PenProfileInfoEventArgs() 7 | { 8 | Type = PenProfileType.Info; 9 | Result = ResultType.Success; 10 | } 11 | internal PenProfileInfoEventArgs(string profileName, int status) : this() 12 | { 13 | ProfileName = profileName; 14 | Status = status; 15 | } 16 | internal PenProfileInfoEventArgs(string profileName, int status, int totalSectionCount, int sectionSize, int useSectionCount, int useKeyCount) : this() 17 | { 18 | ProfileName = profileName; 19 | Status = status; 20 | TotalSectionCount = totalSectionCount; 21 | SectionSize = sectionSize; 22 | UseSectionCount = useSectionCount; 23 | UseKeyCount = useKeyCount; 24 | } 25 | 26 | public int TotalSectionCount { get; internal set; } 27 | public int SectionSize { get; internal set; } 28 | public int UseSectionCount { get; internal set; } 29 | public int UseKeyCount { get; internal set; } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Neosmartpen.Net/Neosmartpen/Implementation/Net/Client/Event/PenProfile/PenProfileReadValueEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Neosmartpen.Net 4 | { 5 | /// 6 | public sealed class PenProfileReadValueEventArgs : PenProfileReceivedEventArgs 7 | { 8 | internal PenProfileReadValueEventArgs() 9 | { 10 | Type = PenProfileType.ReadValue; 11 | Result = ResultType.Success; 12 | } 13 | 14 | internal PenProfileReadValueEventArgs(string profileName):this() 15 | { 16 | ProfileName = profileName; 17 | Data = new List(); 18 | } 19 | 20 | public List Data { get; internal set; } 21 | 22 | public class ReadValueResult 23 | { 24 | public int Status { get; internal set; } 25 | public string Key { get; internal set; } 26 | public byte[] Data { get; internal set; } 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Neosmartpen.Net/Neosmartpen/Implementation/Net/Client/Event/PenProfile/PenProfileReceivedEventArgs.cs: -------------------------------------------------------------------------------- 1 |  namespace Neosmartpen.Net 2 | { 3 | /// 4 | public class PenProfileReceivedEventArgs 5 | { 6 | internal PenProfileReceivedEventArgs() { } 7 | internal PenProfileReceivedEventArgs(ResultType result) 8 | { 9 | Result = result; 10 | } 11 | 12 | public ResultType Result { get; internal set; } 13 | public enum ResultType 14 | { 15 | Success, 16 | Failed 17 | } 18 | public string ProfileName { get; internal set; } 19 | public int Status { get; internal set; } 20 | 21 | public PenProfileType Type { get; protected set; } 22 | public enum PenProfileType 23 | { 24 | Create, 25 | Delete, 26 | Info, 27 | ReadValue, 28 | WriteValue, 29 | DeleteValue 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Neosmartpen.Net/Neosmartpen/Implementation/Net/Client/Event/PenProfile/PenProfileWriteValueEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Neosmartpen.Net 4 | { 5 | /// 6 | public sealed class PenProfileWriteValueEventArgs : PenProfileReceivedEventArgs 7 | { 8 | internal PenProfileWriteValueEventArgs() 9 | { 10 | Type = PenProfileType.WriteValue; 11 | Result = ResultType.Success; 12 | } 13 | internal PenProfileWriteValueEventArgs(string profileName) : this() 14 | { 15 | ProfileName = profileName; 16 | Data = new List(); 17 | } 18 | 19 | public List Data { get; internal set; } 20 | 21 | public class WriteValueResult 22 | { 23 | public int Status { get; internal set; } 24 | public string Key { get; internal set; } 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Neosmartpen.Net/Neosmartpen/Implementation/Net/Client/Event/PenStatusReceivedEventArgs.cs: -------------------------------------------------------------------------------- 1 | namespace Neosmartpen.Net 2 | { 3 | /// 4 | /// Contains properties that status and setting of pen for the PenStatusReceived 5 | /// 6 | public sealed class PenStatusReceivedEventArgs 7 | { 8 | internal PenStatusReceivedEventArgs() { } 9 | // TODO Check 10 | // for v1 11 | internal PenStatusReceivedEventArgs(int timeoffset, long timetick, int maxForce, int battery, int usedMem, int penColor, bool autoPowerMode, bool accelerationMode, bool hoverMode, bool beep 12 | , short autoShutdownTime, short penSensitivity, string modelName) 13 | { 14 | TimeOffset = timeoffset; 15 | Timestamp = timetick; 16 | MaxForce = maxForce; 17 | Battery = battery; 18 | UsedMem = usedMem; 19 | PenColor = penColor; 20 | AutoPowerOn = autoPowerMode; 21 | AccelerationMode = accelerationMode; 22 | HoverMode = hoverMode; 23 | Beep = beep; 24 | AutoShutdownTime = autoShutdownTime; 25 | PenSensitivity = penSensitivity; 26 | ModelName = modelName; 27 | } 28 | // for v2 29 | internal PenStatusReceivedEventArgs(bool locked, int passwordMaxRetryCount, int passwordRetryCount, long timestamp, short autoShutdownTime 30 | , int maxForce, int battery, int usedMem, bool useOfflineData, bool autoPowerOn, bool penCapPower, bool hover, bool beep, short penSensitivity) 31 | { 32 | Locked = locked; 33 | PasswordMaxRetryCount = passwordMaxRetryCount; 34 | PasswordRetryCount = passwordRetryCount; 35 | Timestamp = timestamp; 36 | AutoShutdownTime = autoShutdownTime; 37 | MaxForce = maxForce; 38 | Battery = battery; 39 | UsedMem = usedMem; 40 | UseOfflineData = useOfflineData; 41 | AutoPowerOn = autoPowerOn; 42 | PenCapPower = penCapPower; 43 | HoverMode = hover; 44 | Beep = beep; 45 | PenSensitivity = penSensitivity; 46 | } 47 | 48 | // common 49 | /// 50 | /// Gets RTC millisecond timestamp of pen (from 1970-01-01) 51 | /// 52 | public long Timestamp { get; internal set; } 53 | 54 | /// 55 | /// Gets the power-off setting when there is no input for a certain period of time 56 | /// 57 | public short AutoShutdownTime { get; internal set; } 58 | 59 | /// 60 | /// Gets maximum level of force sensor 61 | /// 62 | public int MaxForce { get; internal set; } 63 | 64 | /// 65 | /// Gets battery status of pen 66 | /// 67 | public int Battery { get; internal set; } 68 | 69 | /// 70 | /// Gets status of pen's storage 71 | /// 72 | public int UsedMem { get; internal set; } 73 | 74 | /// 75 | /// Gets the power-on setting when the pen tip is pressed 76 | /// 77 | public bool AutoPowerOn { get; internal set; } 78 | public bool HoverMode { get; internal set; } 79 | 80 | /// 81 | /// Gets the status of the beep sound property 82 | /// 83 | public bool Beep { get; internal set; } 84 | 85 | /// 86 | /// Gets the value of the pen's sensitivity property that controls the force sensor of pen 87 | /// 88 | public short PenSensitivity { get; internal set; } 89 | 90 | 91 | // V1 92 | /// 93 | /// timestamp offset 94 | /// In most cases, you can ignore it 95 | /// 96 | public int TimeOffset { get; internal set; } 97 | 98 | /// 99 | /// Gets color of pen's led 100 | /// 101 | public int PenColor { get; internal set; } 102 | 103 | /// 104 | /// Gets the status of the acceleration sensor property 105 | /// 106 | public bool AccelerationMode { get; internal set; } 107 | 108 | // V2 109 | /// 110 | /// Gets the status of pen's authorization 111 | /// true if pen is locked, otherwise false 112 | /// 113 | public bool Locked { get; internal set; } 114 | 115 | /// 116 | /// Gets the maximum password input count 117 | /// 118 | public int PasswordMaxRetryCount { get; internal set; } 119 | 120 | /// 121 | /// Gets the current password input count 122 | /// 123 | public int PasswordRetryCount { get; internal set; } 124 | 125 | /// 126 | /// Gets the usage of offline data 127 | /// true if offline data available, otherwise false 128 | /// 129 | public bool UseOfflineData { get; internal set; } 130 | 131 | /// 132 | /// Gets the property that can be control by cap of pen 133 | /// 134 | public bool PenCapPower { get; internal set; } 135 | /// 136 | /// Model Name 137 | /// This property use in protocol ver 1 138 | /// 139 | public string ModelName { get; internal set; } 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /Neosmartpen.Net/Neosmartpen/Implementation/Net/Client/Event/ProgressChangeEventArgs.cs: -------------------------------------------------------------------------------- 1 | namespace Neosmartpen.Net 2 | { 3 | /// 4 | /// Defines a provider for progress updates 5 | /// 6 | public sealed class ProgressChangeEventArgs 7 | { 8 | internal ProgressChangeEventArgs() { } 9 | internal ProgressChangeEventArgs(int total, int amountDone) 10 | { 11 | Total = total; 12 | AmountDone = amountDone; 13 | } 14 | 15 | /// 16 | /// Gets the amount of work total 17 | /// 18 | public int Total { get; internal set; } 19 | 20 | /// 21 | /// Gets the amount of work done 22 | /// 23 | public int AmountDone { get; internal set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Neosmartpen.Net/Neosmartpen/Implementation/Net/Client/Event/SimpleResultEventArgs.cs: -------------------------------------------------------------------------------- 1 | namespace Neosmartpen.Net 2 | { 3 | /// 4 | /// Contains propertie that a single boolean type result for common purpose 5 | /// 6 | public sealed class SimpleResultEventArgs 7 | { 8 | internal SimpleResultEventArgs() { } 9 | internal SimpleResultEventArgs(bool result) 10 | { 11 | Result = result; 12 | } 13 | /// 14 | /// Gets boolean type result 15 | /// 16 | public bool Result { get; internal set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Neosmartpen.Net/Neosmartpen/Implementation/Net/Client/IPenClientParser.cs: -------------------------------------------------------------------------------- 1 | namespace Neosmartpen.Net 2 | { 3 | internal interface IPenClientParser 4 | { 5 | void ProtocolParse(byte[] buff, int size); 6 | 7 | void ParsePacket(Packet packet); 8 | 9 | IPenClient PenClient { get; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Neosmartpen.Net/Neosmartpen/Implementation/Net/Client/ImageProcessErrorInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Neosmartpen.Net 8 | { 9 | /// 10 | public class ImageProcessErrorInfo 11 | { 12 | public long Timestamp { get; set; } 13 | 14 | public int Force { get; set; } 15 | 16 | public int Brightness { get; set; } 17 | 18 | public int ExposureTime { get; set; } 19 | 20 | public int ProcessTime { get; set; } 21 | 22 | public int LabelCount { get; set; } 23 | 24 | public int ErrorCode { get; set; } 25 | 26 | public int ClassType { get; set; } 27 | 28 | public int ErrorCount { get; set; } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Neosmartpen.Net/Neosmartpen/Implementation/Net/Client/ImageProcessingInfo.cs: -------------------------------------------------------------------------------- 1 | namespace Neosmartpen.Net 2 | { 3 | /// 4 | public class ImageProcessingInfo 5 | { 6 | public int DotCount { get; set; } 7 | /// 8 | /// Number of images received from the image sensor 9 | /// 10 | public int Total { get; set; } 11 | 12 | /// 13 | /// Number of images delivered to the data processor 14 | /// 15 | public int Processed { get; set; } 16 | 17 | /// 18 | /// Number of images processed by the data processor 19 | /// 20 | public int Success { get; set; } 21 | 22 | /// 23 | /// Number of images last used for coordinate recognition 24 | /// 25 | public int Transferred { get; set; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Neosmartpen.Net/Neosmartpen/Implementation/Net/Client/OfflineDataStructure.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Neosmartpen.Net 4 | { 5 | /// 6 | public class OfflineDataInfo 7 | { 8 | public int Section { protected set; get; } 9 | 10 | public int Owner { protected set; get; } 11 | 12 | public int Note { protected set; get; } 13 | 14 | public int[] Pages { protected set; get; } 15 | 16 | public OfflineDataInfo( int sectionId, int ownerId, int noteId, int[] pages = null ) 17 | { 18 | Section = sectionId; 19 | Owner = ownerId; 20 | Note = noteId; 21 | Pages = pages; 22 | } 23 | 24 | public override string ToString() 25 | { 26 | return String.Format( "sec:{0}, owner:{1}, note:{2}", Section, Owner, Note ); 27 | } 28 | } 29 | 30 | /// 31 | public class OfflineDataFile 32 | { 33 | public int Section, Owner, Note; 34 | public int totalDataSize, receiveDataSize; 35 | public string FilePath; 36 | 37 | public OfflineDataFile( int sectionId, int ownerId, int noteId, string filePath, int totalSize, int receiveDataSize ) 38 | { 39 | Section = sectionId; 40 | Owner = ownerId; 41 | Note = noteId; 42 | FilePath = filePath; 43 | totalDataSize = totalSize; 44 | this.receiveDataSize = receiveDataSize; 45 | } 46 | 47 | public void Delete() 48 | { 49 | if ( System.IO.Directory.Exists( FilePath ) ) 50 | { 51 | System.IO.Directory.Delete( FilePath, true ); 52 | } 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Neosmartpen.Net/Neosmartpen/Implementation/Net/Client/Packet.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Neosmartpen.Net 4 | { 5 | /// 6 | public class Packet : IPacket 7 | { 8 | public int Cmd { protected set; get; } 9 | 10 | public int Result { protected set; get; } 11 | 12 | public byte[] Data { protected set; get; } 13 | 14 | private int mIndex = 0; 15 | 16 | public byte GetChecksum( int length ) 17 | { 18 | byte[] bytes = new byte[length]; 19 | 20 | Array.Copy( Data, mIndex, bytes, 0, length ); 21 | 22 | int CheckSum = 0; 23 | 24 | for ( int i = 0; i < bytes.Length; i++ ) 25 | { 26 | CheckSum += (int)( bytes[i] & 0xFF ); 27 | } 28 | 29 | return (byte)CheckSum; 30 | } 31 | 32 | public byte GetChecksum() 33 | { 34 | return GetChecksum( Data.Length - mIndex ); 35 | } 36 | 37 | public bool CheckMoreData() 38 | { 39 | return Data.Length > mIndex; 40 | } 41 | 42 | public int GetInt() 43 | { 44 | return BitConverter.ToInt32( GetBytes(4), 0 ); 45 | } 46 | public uint GetUInt() 47 | { 48 | return BitConverter.ToUInt32( GetBytes(4), 0 ); 49 | } 50 | 51 | public short GetShort() 52 | { 53 | return BitConverter.ToInt16( GetBytes(2), 0 ); 54 | } 55 | 56 | public ushort GetUShort() 57 | { 58 | return BitConverter.ToUInt16(GetBytes(2), 0); 59 | } 60 | 61 | public long GetLong() 62 | { 63 | return BitConverter.ToInt64( GetBytes(8), 0 ); 64 | } 65 | public ulong GetULong() 66 | { 67 | return BitConverter.ToUInt64( GetBytes(8), 0 ); 68 | } 69 | 70 | public int GetByteToInt() 71 | { 72 | return (int)( GetByte() & 0xFF ); 73 | } 74 | 75 | public byte[] GetBytes() 76 | { 77 | return GetBytes( Data.Length - mIndex ); 78 | } 79 | 80 | public byte[] GetBytes( int size ) 81 | { 82 | byte[] result = new byte[size]; 83 | 84 | Array.Copy( Data, mIndex, result, 0, size ); 85 | 86 | Move( size ); 87 | 88 | return result; 89 | } 90 | 91 | public IPacket Move( int size ) 92 | { 93 | mIndex += size; 94 | return this; 95 | } 96 | 97 | public IPacket Reset() 98 | { 99 | mIndex = 0; 100 | return this; 101 | } 102 | 103 | public byte GetByte() 104 | { 105 | return GetBytes(1)[0]; 106 | } 107 | 108 | public string GetString( int length ) 109 | { 110 | return System.Text.Encoding.UTF8.GetString( GetBytes( length ) ).Trim( '\0' ); 111 | } 112 | 113 | public override string ToString() 114 | { 115 | return BitConverter.ToString( Data, 0 ); 116 | } 117 | 118 | public class Builder 119 | { 120 | private Packet mPacket; 121 | 122 | public Builder() 123 | { 124 | mPacket = new Packet(); 125 | } 126 | 127 | public Builder cmd( int cmd ) 128 | { 129 | mPacket.Cmd = cmd; 130 | return this; 131 | } 132 | 133 | public Builder result( int code ) 134 | { 135 | mPacket.Result = code; 136 | return this; 137 | } 138 | 139 | public Builder data( byte[] data ) 140 | { 141 | mPacket.Data = data; 142 | return this; 143 | } 144 | 145 | public Packet Build() 146 | { 147 | return mPacket; 148 | } 149 | } 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /Neosmartpen.Net/Neosmartpen/Implementation/Net/Client/PenClient.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.Threading.Tasks; 4 | using Windows.Networking.Sockets; 5 | using Windows.Storage.Streams; 6 | 7 | namespace Neosmartpen.Net 8 | { 9 | /// 10 | public class PenClient : IPenClient 11 | { 12 | private DataWriter mDataWriter; 13 | private DataReader mDataReader; 14 | 15 | public static readonly uint BufferSize = 1024; 16 | 17 | public string Name 18 | { 19 | get; set; 20 | } 21 | 22 | public StreamSocket Socket 23 | { 24 | get; set; 25 | } 26 | 27 | public PenClient(IPenController penctrl) 28 | { 29 | PenController = penctrl; 30 | } 31 | 32 | public void Bind(StreamSocket socket) 33 | { 34 | try 35 | { 36 | Socket = socket; 37 | 38 | PenController.PenClient = this; 39 | 40 | mDataWriter = new DataWriter(Socket.OutputStream); 41 | mDataReader = new DataReader(Socket.InputStream); 42 | 43 | mDataReader.InputStreamOptions = InputStreamOptions.Partial; 44 | 45 | PenController.OnConnected(); 46 | 47 | ReadSocket(mDataReader); 48 | } 49 | catch (Exception ex) 50 | { 51 | Debug.WriteLine("Exception : " + ex.Message); 52 | 53 | switch ((uint)ex.HResult) 54 | { 55 | case (0x80070490): // ERROR_ELEMENT_NOT_FOUND 56 | break; 57 | default: 58 | throw; 59 | } 60 | } 61 | } 62 | 63 | public async Task Unbind() 64 | { 65 | Socket?.Dispose(); 66 | mDataWriter?.Dispose(); 67 | mDataReader?.Dispose(); 68 | 69 | Socket = null; 70 | mDataWriter = null; 71 | mDataReader = null; 72 | } 73 | 74 | public bool Alive 75 | { 76 | get 77 | { 78 | return mDataReader != null && mDataWriter != null; 79 | } 80 | internal set { } 81 | } 82 | 83 | public IPenController PenController 84 | { 85 | get; set; 86 | } 87 | 88 | private async void WriteSocket(byte[] data) 89 | { 90 | // todo check 91 | mDataWriter.WriteBytes(data); 92 | 93 | try 94 | { 95 | await mDataWriter.StoreAsync(); 96 | } 97 | catch (Exception exception) 98 | { 99 | // todo : disconnect 100 | if (SocketError.GetStatus(exception.HResult) == SocketErrorStatus.Unknown) 101 | { 102 | //throw; 103 | } 104 | } 105 | } 106 | 107 | private async void ReadSocket(DataReader dataReader) 108 | { 109 | try 110 | { 111 | if (mDataReader == null) 112 | return; 113 | 114 | uint size = await dataReader.LoadAsync(BufferSize); 115 | 116 | if (size <= 0) 117 | { 118 | throw new Exception(); 119 | } 120 | 121 | byte[] data = new byte[size]; 122 | 123 | dataReader.ReadBytes(data); 124 | 125 | PenController.OnDataReceived(data); 126 | 127 | ReadSocket(dataReader); 128 | } 129 | catch 130 | { 131 | await onDisconnect(); 132 | } 133 | } 134 | 135 | private async Task onDisconnect() 136 | { 137 | await Unbind(); 138 | PenController.OnDisconnected(); 139 | } 140 | 141 | public void Write(byte[] data) 142 | { 143 | WriteSocket(data); 144 | } 145 | 146 | public void Read() 147 | { 148 | ReadSocket(mDataReader); 149 | } 150 | } 151 | } -------------------------------------------------------------------------------- /Neosmartpen.Net/Neosmartpen/Implementation/Net/Client/PenCommType.cs: -------------------------------------------------------------------------------- 1 | //namespace Neosmartpen.Net.Client 2 | //{ 3 | // public enum PenCommType 4 | // { 5 | // PenCommV1, 6 | // PenCommV2 7 | // } 8 | 9 | // //public class PenCommTypeConverter 10 | // //{ 11 | // // public static uint ParseClassOfDevice(PenCommType penCommType) 12 | // // { 13 | // // switch(penCommType) 14 | // // { 15 | // // case PenCommType.PenCommV1: 16 | // // return 0x0500; 17 | // // case PenCommType.PenCommV2: 18 | // // return 0x2510; 19 | // // default: 20 | // // return 0x00; 21 | // // } 22 | // // } 23 | // // public static uint ParseServiceUUID(PenCommType penCommType) 24 | // // { 25 | // // switch(penCommType) 26 | // // { 27 | // // case PenCommType.PenCommV1: 28 | // // return 0x18F1; 29 | // // case PenCommType.PenCommV2: 30 | // // return 0x19F1; 31 | // // default: 32 | // // return 0x0000; 33 | // // } 34 | // // } 35 | // //} 36 | //} -------------------------------------------------------------------------------- /Neosmartpen.Net/Neosmartpen/Implementation/Net/Client/PenControllerEx.cs: -------------------------------------------------------------------------------- 1 | namespace Neosmartpen.Net 2 | { 3 | /// 4 | public class PenControllerEx : PenController 5 | { 6 | public PenControllerEx(int protocol) 7 | { 8 | base.Protocol = protocol; 9 | } 10 | } 11 | } -------------------------------------------------------------------------------- /Neosmartpen.Net/Neosmartpen/Implementation/Net/Client/PenProfile.cs: -------------------------------------------------------------------------------- 1 | namespace Neosmartpen.Net 2 | { 3 | /// 4 | public class PenProfile 5 | { 6 | public static readonly int LIMIT_BYTE_LENGTH_PROFILE_NAME = 8; 7 | public static readonly int LIMIT_BYTE_LENGTH_PASSWORD = 8; 8 | public static readonly int LIMIT_BYTE_LENGTH_KEY = 16; 9 | /*** 10 | * request type 11 | */ 12 | internal static readonly byte PROFILE_CREATE = 0x01; 13 | internal static readonly byte PROFILE_DELETE = 0x02; 14 | internal static readonly byte PROFILE_INFO = 0x03; 15 | internal static readonly byte PROFILE_READ_VALUE = 0x12; 16 | internal static readonly byte PROFILE_WRITE_VALUE = 0x11; 17 | internal static readonly byte PROFILE_DELETE_VALUE = 0x13; 18 | /*** 19 | * status 20 | */ 21 | public const byte PROFILE_STATUS_SUCCESS = 0x00; 22 | public const byte PROFILE_STATUS_FAILURE = 0x01; 23 | public const byte PROFILE_STATUS_EXIST_PROFILE_ALREADY = 0x10; 24 | public const byte PROFILE_STATUS_NO_EXIST_PROFILE = 0x11; 25 | // public static readonly byte PROFILE_STATUS_EXIST_KEY_ALREADY = 0x20; 26 | public const byte PROFILE_STATUS_NO_EXIST_KEY = 0x21; 27 | public const byte PROFILE_STATUS_NO_PERMISSION = 0x30; 28 | public const byte PROFILE_STATUS_BUFFER_SIZE_ERR = 0x40; 29 | } 30 | } -------------------------------------------------------------------------------- /Neosmartpen.Net/Neosmartpen/Implementation/Net/Client/Protocols.cs: -------------------------------------------------------------------------------- 1 | namespace Neosmartpen.Net 2 | { 3 | /// 4 | public class Protocols 5 | { 6 | public static readonly int NONE = -1; 7 | public static readonly int V1 = 1; 8 | public static readonly int V2 = 2; 9 | } 10 | 11 | //public class PenCommTypeConverter 12 | //{ 13 | // public static uint ParseClassOfDevice(PenCommType penCommType) 14 | // { 15 | // switch(penCommType) 16 | // { 17 | // case PenCommType.PenCommV1: 18 | // return 0x0500; 19 | // case PenCommType.PenCommV2: 20 | // return 0x2510; 21 | // default: 22 | // return 0x00; 23 | // } 24 | // } 25 | // public static uint ParseServiceUUID(PenCommType penCommType) 26 | // { 27 | // switch(penCommType) 28 | // { 29 | // case PenCommType.PenCommV1: 30 | // return 0x18F1; 31 | // case PenCommType.PenCommV2: 32 | // return 0x19F1; 33 | // default: 34 | // return 0x0000; 35 | // } 36 | // } 37 | //} 38 | } -------------------------------------------------------------------------------- /Neosmartpen.Net/Neosmartpen/Implementation/Net/Client/UsbMode.cs: -------------------------------------------------------------------------------- 1 | namespace Neosmartpen.Net 2 | { 3 | public enum UsbMode : byte { Disk = 0, Bulk = 1 }; 4 | } 5 | -------------------------------------------------------------------------------- /Neosmartpen.Net/Neosmartpen/Implementation/Net/Client/Version1/OfflineData.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.IO; 3 | 4 | namespace Neosmartpen.Net 5 | { 6 | /// 7 | public abstract class OfflineData 8 | { 9 | public static string CURRENT_DIR; 10 | public static string DEFAULT_PATH; 11 | public static string DEFAULT_ERROR_PATH; 12 | 13 | public readonly string EXT_ZIP = ".zip"; 14 | public readonly string EXT_ERROR = ".err"; 15 | public readonly string EXT_DATA = ".pen"; 16 | public readonly string DIR_ROOT = "offline"; 17 | public readonly string DIR_ERROR = "err"; 18 | public readonly string DIR_TEMP = "temp_"; 19 | 20 | // 기본 디렉토리 생성 21 | public void SetDefaultPath(string basepath) 22 | { 23 | // uwp에서 아무 폴더에서 접근할 경우 권한 문제 발생, 따라서 MS권고하는 위치를 사용하도록 수정 24 | // 검토 후 basepath를 막아야 할지도 모른다. 25 | basepath = basepath == null || basepath == "" ? Directory.GetCurrentDirectory() : basepath; 26 | 27 | OfflineData.DEFAULT_PATH = basepath + "\\" + DIR_ROOT; 28 | OfflineData.DEFAULT_ERROR_PATH = DEFAULT_PATH + "\\" + DIR_ERROR; 29 | } 30 | 31 | public void SetupFileSystem() 32 | { 33 | if (!System.IO.Directory.Exists(DEFAULT_PATH)) 34 | { 35 | System.IO.Directory.CreateDirectory(DEFAULT_PATH); 36 | } 37 | 38 | // 에러 파일 저장 위치 설정 39 | string errorFilePath = DEFAULT_PATH + "\\" + DIR_ERROR; 40 | 41 | if (!System.IO.Directory.Exists(errorFilePath)) 42 | { 43 | System.IO.Directory.CreateDirectory(errorFilePath); 44 | } 45 | } 46 | 47 | public string[] GetOfflineFiles() 48 | { 49 | string[] filePaths = Directory.GetFiles(DEFAULT_PATH); 50 | return filePaths; 51 | } 52 | 53 | public string[] GetErrorFiles() 54 | { 55 | string[] filePaths = Directory.GetFiles(DEFAULT_PATH + "\\" + DIR_ERROR); 56 | return filePaths; 57 | } 58 | 59 | public static string GetFileFromFullPath(string fullpath) 60 | { 61 | string[] arr = fullpath.Split('\\'); 62 | 63 | if (arr.Length <= 1) 64 | { 65 | return null; 66 | } 67 | 68 | return arr[arr.Length - 1]; 69 | } 70 | 71 | public static string GetFileNameFromFullPath(string fullpath) 72 | { 73 | string[] arr = GetFileFromFullPath(fullpath).Split('.'); 74 | 75 | if (arr.Length < 2) 76 | { 77 | return null; 78 | } 79 | 80 | return arr[0]; 81 | } 82 | 83 | public static string GetFileExtFromFullPath(string fullpath) 84 | { 85 | string[] arr = GetFileFromFullPath(fullpath).Split('.'); 86 | 87 | if (arr.Length < 2) 88 | { 89 | return null; 90 | } 91 | 92 | string ext = ""; 93 | 94 | for (int i = 1; i < arr.Length; i++) 95 | { 96 | ext += arr[i]; 97 | } 98 | 99 | return ext; 100 | } 101 | 102 | public static Stroke[] DotArrayToStrokeArray(Dot[] dots) 103 | { 104 | List slist = new List(); 105 | 106 | Stroke temp = null; 107 | 108 | foreach (Dot dot in dots) 109 | { 110 | if (dot.DotType == DotTypes.PEN_DOWN) 111 | { 112 | temp = new Stroke(dot.Section, dot.Owner, dot.Note, dot.Page); 113 | slist.Add(temp); 114 | } 115 | 116 | temp.Add(dot); 117 | } 118 | 119 | return slist.ToArray(); 120 | } 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /Neosmartpen.Net/Neosmartpen/Implementation/Net/Client/Version1/OfflineDataSerializer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Linq; 5 | using Neosmartpen.Net.Support; 6 | 7 | namespace Neosmartpen.Net 8 | { 9 | /// 10 | public class OfflineDataSerializer : OfflineData 11 | { 12 | public Dictionary chunks; 13 | 14 | private int mPacketCount; 15 | 16 | private bool IsCompressed = false; 17 | 18 | public int sectionId = 0, ownerId = 0, noteId = 0, pageId = 0; 19 | 20 | public static string DEFAULT_FILE_FORMAT = "{0}_{1}_{2}_{3}_{4}.{5}"; 21 | 22 | public OfflineDataSerializer( string filepath, int packetCount, bool isCompressed ) 23 | { 24 | chunks = new Dictionary(); 25 | 26 | string[] arr = filepath.Split( '\\' ); 27 | 28 | int sectionOwner = int.Parse( arr[2] ); 29 | 30 | byte[] bso = ByteConverter.IntToByte( sectionOwner ); 31 | 32 | sectionId = (int)( bso[3] & 0xFF ); 33 | ownerId = ByteConverter.ByteToInt( new byte[] { bso[0], bso[1], bso[2], (byte)0x00 } ); 34 | 35 | noteId = int.Parse( arr[3] ); 36 | pageId = int.Parse( arr[4] ); 37 | 38 | mPacketCount = packetCount; 39 | IsCompressed = isCompressed; 40 | 41 | base.SetupFileSystem(); 42 | } 43 | 44 | public string MakeFile() 45 | { 46 | lock ( OfflineData.DEFAULT_PATH ) 47 | { 48 | ByteUtil buff = new ByteUtil(); 49 | 50 | for ( int i=0; i < chunks.Count(); i++ ) 51 | { 52 | buff.Put( chunks[i] ); 53 | } 54 | 55 | string filename = String.Format( DEFAULT_FILE_FORMAT, sectionId, ownerId, noteId, pageId, Time.GetUtcTimeStamp(), IsCompressed ? "zip" : "pen" ); 56 | 57 | string fullpath = OfflineData.DEFAULT_PATH + "\\" + filename; 58 | 59 | if ( ByteToFile( buff.ToArray(), fullpath ) ) 60 | { 61 | return fullpath; 62 | } 63 | else 64 | { 65 | return null; 66 | } 67 | } 68 | } 69 | 70 | public void Put( byte[] data, int index ) 71 | { 72 | chunks.Add(index, data); 73 | } 74 | 75 | private bool ByteToFile( byte[] bytes, String filepath ) 76 | { 77 | try 78 | { 79 | using (System.IO.FileStream fs = new System.IO.FileStream(filepath, System.IO.FileMode.Create, System.IO.FileAccess.Write)) 80 | { 81 | fs.Write(bytes, 0, bytes.Length); 82 | // 필요하다면... 83 | //fs.Flush(); 84 | } 85 | 86 | return true; 87 | } 88 | catch ( Exception e ) 89 | { 90 | Debug.WriteLine( "[OfflineDataSerializer] Exception caught in process: {0}", e.StackTrace ); 91 | } 92 | 93 | // error occured, return false 94 | return false; 95 | } 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /Neosmartpen.Net/Neosmartpen/Implementation/Net/Encryption/AES256Chiper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Runtime.InteropServices.WindowsRuntime; 4 | using System.Text; 5 | using Windows.Security.Cryptography; 6 | using Windows.Security.Cryptography.Core; 7 | using Windows.Storage.Streams; 8 | 9 | namespace Neosmartpen.Net.Encryption 10 | { 11 | /// 12 | class AES256Chiper 13 | { 14 | /* 15 | public string AES_Encrypt(string input, string pass) 16 | { 17 | SymmetricKeyAlgorithmProvider SAP = SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithmNames.AesEcbPkcs7); 18 | CryptographicKey AES; 19 | HashAlgorithmProvider HAP = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Md5); 20 | CryptographicHash Hash_AES = HAP.CreateHash(); 21 | 22 | try 23 | { 24 | byte[] hash = new byte[32]; 25 | Hash_AES.Append(CryptographicBuffer.CreateFromByteArray(Encoding.UTF8.GetBytes(pass))); 26 | CryptographicBuffer.CopyToByteArray(Hash_AES.GetValueAndReset(), out byte[] temp); 27 | 28 | Array.Copy(temp, 0, hash, 0, 16); 29 | Array.Copy(temp, 0, hash, 15, 16); 30 | 31 | AES = SAP.CreateSymmetricKey(CryptographicBuffer.CreateFromByteArray(hash)); 32 | 33 | IBuffer Buffer = CryptographicBuffer.CreateFromByteArray(Encoding.UTF8.GetBytes(input)); 34 | string encrypted = CryptographicBuffer.EncodeToBase64String(CryptographicEngine.Encrypt(AES, Buffer, null)); 35 | 36 | return encrypted; 37 | } 38 | catch (Exception ex) 39 | { 40 | return null; 41 | } 42 | } 43 | 44 | 45 | public string AES_Decrypt(string input, string pass) 46 | { 47 | SymmetricKeyAlgorithmProvider SAP = SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithmNames.AesEcbPkcs7); 48 | CryptographicKey AES; 49 | HashAlgorithmProvider HAP = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Md5); 50 | CryptographicHash Hash_AES = HAP.CreateHash(); 51 | 52 | try 53 | { 54 | byte[] hash = new byte[32]; 55 | Hash_AES.Append(CryptographicBuffer.CreateFromByteArray(Encoding.UTF8.GetBytes(pass))); 56 | CryptographicBuffer.CopyToByteArray(Hash_AES.GetValueAndReset(), out byte[] temp); 57 | 58 | Array.Copy(temp, 0, hash, 0, 16); 59 | Array.Copy(temp, 0, hash, 15, 16); 60 | 61 | AES = SAP.CreateSymmetricKey(CryptographicBuffer.CreateFromByteArray(hash)); 62 | 63 | IBuffer Buffer = CryptographicBuffer.DecodeFromBase64String(input); 64 | CryptographicBuffer.CopyToByteArray(CryptographicEngine.Decrypt(AES, Buffer, null), out byte[] Decrypted); 65 | string decrypted = Encoding.UTF8.GetString(Decrypted, 0, Decrypted.Length); 66 | 67 | return decrypted; 68 | } 69 | catch (Exception ex) 70 | { 71 | return null; 72 | } 73 | } 74 | */ 75 | 76 | public AES256Chiper(byte[] key) 77 | { 78 | var iv = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; 79 | AesEnDecryption(key); 80 | } 81 | 82 | // Key with 256 and IV with 16 length 83 | private CryptographicKey m_key; 84 | 85 | public void AesEnDecryption(byte[] k) 86 | { 87 | SymmetricKeyAlgorithmProvider provider = SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithmNames.AesEcb); 88 | m_key = provider.CreateSymmetricKey(k.AsBuffer()); 89 | } 90 | 91 | /// 92 | /// 93 | /// 94 | /// Input buffer length must be Multiples of 16 95 | /// 96 | public byte[] Encrypt(byte[] input) 97 | { 98 | IBuffer bufferMsg = CryptographicBuffer.ConvertStringToBinary(Encoding.ASCII.GetString(input), BinaryStringEncoding.Utf8); 99 | try 100 | { 101 | IBuffer bufferEncrypt = CryptographicEngine.Encrypt(m_key, bufferMsg, null); 102 | return bufferEncrypt.ToArray(); 103 | } 104 | catch 105 | { 106 | return null; 107 | } 108 | } 109 | 110 | /// 111 | /// 112 | /// 113 | /// Input buffer length must be Multiples of 16 114 | /// 115 | public byte[] Decrypt(byte[] input) 116 | { 117 | try 118 | { 119 | IBuffer bufferDecrypt = CryptographicEngine.Decrypt(m_key, input.AsBuffer(), null); 120 | return bufferDecrypt.ToArray(); 121 | } 122 | catch 123 | { 124 | return null; 125 | } 126 | } 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /Neosmartpen.Net/Neosmartpen/Implementation/Net/Encryption/PrivateKey.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices.WindowsRuntime; 3 | using Windows.Storage.Streams; 4 | 5 | namespace Neosmartpen.Net.Encryption 6 | { 7 | /// 8 | public class PrivateKey 9 | { 10 | public int Version { get; private set; } 11 | public IBuffer Modulus { get; private set; } 12 | public IBuffer PublicExponent { get; private set; } 13 | public IBuffer PrivateExponent { get; private set; } 14 | 15 | public PrivateKey(IBuffer key) 16 | { 17 | ParseBuffer(key); 18 | } 19 | 20 | private void ParseBuffer(IBuffer key) 21 | { 22 | var dataReader = DataReader.FromBuffer(key); 23 | byte startByte = dataReader.ReadByte(); 24 | if (startByte != 0x30) 25 | throw new FormatException("Indicating Quceqence Failed"); 26 | 27 | uint length = GetLength(dataReader); 28 | 29 | ParseVersion(dataReader); 30 | 31 | ParseModulus(dataReader); 32 | 33 | ParsePublicExponent(dataReader); 34 | 35 | ParsePrivateExponent(dataReader); 36 | } 37 | 38 | private void ParseVersion(DataReader reader) 39 | { 40 | byte tag = reader.ReadByte(); 41 | if (tag == 0x02) 42 | { 43 | var temp = ReadInteger(reader); 44 | 45 | uint length = temp.Length; 46 | var bytes = new byte[length]; 47 | using (var dataReader = DataReader.FromBuffer(temp)) 48 | { 49 | dataReader.ReadBytes(bytes); 50 | } 51 | Version = (int)ByteArrayToInt(bytes); 52 | } 53 | else 54 | throw new Exception("Invalid Tag In PublicExponent"); 55 | 56 | } 57 | private void ParseModulus(DataReader reader) 58 | { 59 | byte tag = reader.ReadByte(); 60 | if (tag == 0x02) 61 | Modulus = ReadInteger(reader); 62 | else 63 | throw new Exception("Invalid Tag In Modulus"); 64 | 65 | } 66 | 67 | private void ParsePublicExponent(DataReader reader) 68 | { 69 | byte tag = reader.ReadByte(); 70 | if (tag == 0x02) 71 | PublicExponent = ReadInteger(reader); 72 | else 73 | throw new Exception("Invalid Tag In PublicExponent"); 74 | 75 | } 76 | private void ParsePrivateExponent(DataReader reader) 77 | { 78 | byte tag = reader.ReadByte(); 79 | if (tag == 0x02) 80 | PrivateExponent = ReadInteger(reader); 81 | else 82 | throw new Exception("Invalid Tag In PublicExponent"); 83 | 84 | } 85 | 86 | private IBuffer ReadInteger(DataReader reader) 87 | { 88 | uint length = GetLength(reader); 89 | var temp = reader.ReadBuffer(length); 90 | var bytes = new byte[temp.Length]; 91 | using (var dataReader = DataReader.FromBuffer(temp)) 92 | { 93 | dataReader.ReadBytes(bytes); 94 | } 95 | if ( bytes[0] == 0x00 ) 96 | { 97 | var newBytes = new byte[bytes.Length - 1]; 98 | System.Buffer.BlockCopy(bytes, 1, newBytes, 0, newBytes.Length); 99 | return newBytes.AsBuffer(); 100 | } 101 | else 102 | { 103 | return bytes.AsBuffer(); 104 | } 105 | } 106 | 107 | private uint GetLength(DataReader reader) 108 | { 109 | byte dataByte = reader.ReadByte(); 110 | if ( (dataByte & 0x80) != 0x80 ) 111 | { 112 | return dataByte; 113 | } 114 | else 115 | { 116 | uint count = (uint)(dataByte & 0x7F); 117 | var lengthBytes = reader.ReadBuffer(count); 118 | 119 | var bytes = new byte[lengthBytes.Length]; 120 | using (var dataReader = DataReader.FromBuffer(lengthBytes)) 121 | { 122 | dataReader.ReadBytes(bytes); 123 | } 124 | return ByteArrayToInt(bytes); 125 | } 126 | } 127 | 128 | private uint ByteArrayToInt(byte[] array) 129 | { 130 | int count = array.Length; 131 | uint length = 0; 132 | for (int i = 0; i < count; ++i) 133 | { 134 | length += (uint)array[count - (i + 1)] << (8 * i); 135 | } 136 | return length; 137 | } 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /Neosmartpen.Net/Neosmartpen/Implementation/Net/Encryption/PublicKey.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices.WindowsRuntime; 3 | using Windows.Storage.Streams; 4 | 5 | namespace Neosmartpen.Net.Encryption 6 | { 7 | /// 8 | public class PublicKey 9 | { 10 | public IBuffer Modulus { get; private set; } 11 | public IBuffer PublicExponent { get; private set; } 12 | public PublicKey(IBuffer key) 13 | { 14 | ParseBuffer(key); 15 | } 16 | 17 | private void ParseBuffer(IBuffer key) 18 | { 19 | var dataReader = DataReader.FromBuffer(key); 20 | byte startByte = dataReader.ReadByte(); 21 | if (startByte != 0x30) 22 | throw new FormatException("Indicating Quceqence Failed"); 23 | 24 | uint length = GetLength(dataReader); 25 | 26 | ParseModulus(dataReader); 27 | 28 | ParsePublicExponent(dataReader); 29 | } 30 | 31 | private void ParseModulus(DataReader reader) 32 | { 33 | byte tag = reader.ReadByte(); 34 | if (tag == 0x02) 35 | Modulus = ReadInteger(reader); 36 | else 37 | throw new Exception("Invalid Tag In Modulus"); 38 | 39 | } 40 | 41 | private void ParsePublicExponent(DataReader reader) 42 | { 43 | byte tag = reader.ReadByte(); 44 | if (tag == 0x02) 45 | PublicExponent = ReadInteger(reader); 46 | else 47 | throw new Exception("Invalid Tag In PublicExponent"); 48 | 49 | } 50 | private IBuffer ReadInteger(DataReader reader) 51 | { 52 | uint length = GetLength(reader); 53 | var temp = reader.ReadBuffer(length); 54 | var bytes = new byte[temp.Length]; 55 | using (var dataReader = DataReader.FromBuffer(temp)) 56 | { 57 | dataReader.ReadBytes(bytes); 58 | } 59 | if ( bytes[0] == 0x00 ) 60 | { 61 | var newBytes = new byte[bytes.Length - 1]; 62 | System.Buffer.BlockCopy(bytes, 1, newBytes, 0, newBytes.Length); 63 | return newBytes.AsBuffer(); 64 | } 65 | else 66 | { 67 | return bytes.AsBuffer(); 68 | } 69 | } 70 | private uint GetLength(DataReader reader) 71 | { 72 | byte dataByte = reader.ReadByte(); 73 | if ( (dataByte & 0x80) != 0x80 ) 74 | { 75 | return dataByte; 76 | } 77 | else 78 | { 79 | uint count = (uint)(dataByte & 0x7F); 80 | var lengthBytes = reader.ReadBuffer(count); 81 | 82 | var bytes = new byte[lengthBytes.Length]; 83 | using (var dataReader = DataReader.FromBuffer(lengthBytes)) 84 | { 85 | dataReader.ReadBytes(bytes); 86 | } 87 | return ByteArrayToInt(bytes); 88 | } 89 | } 90 | 91 | private uint ByteArrayToInt(byte[] array) 92 | { 93 | int count = array.Length; 94 | uint length = 0; 95 | for (int i = 0; i < count; ++i) 96 | { 97 | length += (uint)array[count - (i + 1)] << (8 * i); 98 | } 99 | return length; 100 | } 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /Neosmartpen.Net/Neosmartpen/Implementation/Net/Support/ByteConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Neosmartpen.Net.Support 4 | { 5 | /// 6 | public class ByteConverter 7 | { 8 | public static long ByteToLong(byte[] data) 9 | { 10 | //long result = data[0] + ( data[1] << 8 ) + ( data[2] << 16 ) + ( data[3] << 24 ) 11 | //+ ( data[4] << 32 ) + ( data[5] << 40 ) + ( data[6] << 48 ) + ( data[7] << 56 ); 12 | //return result; 13 | 14 | return BitConverter.ToInt64( data, 0 ); 15 | } 16 | 17 | public static int ByteToInt(byte[] data) 18 | { 19 | int result = data[0] + ( data[1] << 8 ) + ( data[2] << 16 ) + ( data[3] << 24 ); 20 | return result; 21 | } 22 | 23 | public static int SingleByteToInt(byte data) 24 | { 25 | return (int)( data & 0xFF ); 26 | } 27 | 28 | public static short ByteToShort(byte[] data) 29 | { 30 | int result = data[0] + ( data[1] << 8 ); 31 | return (short)result; 32 | } 33 | 34 | public static byte[] ShortToByte(short value) 35 | { 36 | byte[] b = BitConverter.GetBytes( value ); 37 | return b; 38 | } 39 | 40 | public static byte[] LongToByte( long value ) 41 | { 42 | byte[] b = BitConverter.GetBytes( value ); 43 | return b; 44 | } 45 | 46 | public static byte[] IntToByte( int value ) 47 | { 48 | byte[] b = BitConverter.GetBytes( value ); 49 | return b; 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Neosmartpen.Net/Neosmartpen/Implementation/Net/Support/Compression.cs: -------------------------------------------------------------------------------- 1 | using ICSharpCode.SharpZipLib.Zip.Compression.Streams; 2 | using ICSharpCode.SharpZipLib.Zip.Compression; 3 | using System.IO; 4 | 5 | 6 | namespace Neosmartpen.Net.Support 7 | { 8 | internal class Compression 9 | { 10 | public static byte[] Compress(byte[] inbuf) 11 | { 12 | using (MemoryStream ms = new MemoryStream()) 13 | { 14 | using (var outputStream = new DeflaterOutputStream(ms, new Deflater(9, true))) 15 | { 16 | outputStream.Write(inbuf, 0, inbuf.Length); 17 | outputStream.Flush(); 18 | outputStream.Finish(); 19 | return ms.ToArray(); 20 | } 21 | } 22 | } 23 | 24 | public static byte[] Decompress(byte[] inbuf) 25 | { 26 | using (var compressed = new MemoryStream(inbuf)) 27 | { 28 | using (var decompressed = new MemoryStream()) 29 | { 30 | using (var inputStream = new InflaterInputStream(compressed)) 31 | { 32 | inputStream.CopyTo(decompressed); 33 | } 34 | return decompressed.ToArray(); 35 | } 36 | } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Neosmartpen.Net/Neosmartpen/Implementation/Net/Support/FloatConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | 4 | namespace Neosmartpen.Net.Support 5 | { 6 | /// 7 | class FloatConverter 8 | { 9 | private static CultureInfo convertCulture = new CultureInfo("en-US"); 10 | public static double ToDouble(string str) 11 | { 12 | if (string.IsNullOrWhiteSpace(str)) 13 | return 0; 14 | return Convert.ToDouble(str, convertCulture); 15 | } 16 | 17 | public static float ToSingle(string str) 18 | { 19 | if (string.IsNullOrWhiteSpace(str)) 20 | return 0; 21 | return Convert.ToSingle(str, convertCulture); 22 | } 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Neosmartpen.Net/Neosmartpen/Implementation/Net/Support/PressureCalibration.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Neosmartpen.Net.Support 4 | { 5 | /// 6 | internal class PressureCalibration 7 | { 8 | private static PressureCalibration instance; 9 | private static object lockObject = new object(); 10 | public static PressureCalibration Instance 11 | { 12 | get 13 | { 14 | if ( instance == null ) 15 | { 16 | lock(lockObject) 17 | { 18 | if (instance == null) 19 | instance = new PressureCalibration(); 20 | } 21 | } 22 | return instance; 23 | } 24 | } 25 | 26 | public PressureCalibration() 27 | { 28 | } 29 | 30 | #region Calculate Calibration Factor 31 | public readonly int MAX_FACTOR = 1023; 32 | private readonly int MAX_CURVE = 2000; 33 | private float[] pressureCalibrationFactor; 34 | public float[] Factor 35 | { 36 | get 37 | { 38 | return pressureCalibrationFactor; 39 | } 40 | } 41 | public void Clear() 42 | { 43 | pressureCalibrationFactor = null; 44 | } 45 | public void MakeFactor(int cPX1, int cPY1, int cPX2, int cPY2, int cPX3, int cPY3) 46 | { 47 | PointF[] pCurve = new PointF[MAX_CURVE]; 48 | pressureCalibrationFactor = new float[MAX_FACTOR + 1]; 49 | 50 | PointF[] point = new PointF[4] 51 | { 52 | new PointF(cPX1, cPY1), 53 | new PointF(cPX2, cPY2), 54 | new PointF(cPX2, cPY2), 55 | new PointF(cPX3, cPY3), 56 | }; 57 | ComputeBezier(point, MAX_CURVE, pCurve); 58 | 59 | int count = 0; 60 | int prevCount = 0; 61 | int length = pCurve.Length - 1; 62 | for (int i = 0; i < length; i++) 63 | { 64 | if (count < pCurve[i].X) 65 | { 66 | if (Math.Abs(pCurve[prevCount].X - count) > Math.Abs(pCurve[i].X - count)) 67 | pressureCalibrationFactor[count] = pCurve[i].Y; 68 | else 69 | pressureCalibrationFactor[count] = pCurve[prevCount].Y; 70 | if (pressureCalibrationFactor[count] > MAX_FACTOR) pressureCalibrationFactor[count] = MAX_FACTOR; 71 | count++; 72 | if (count > MAX_FACTOR) 73 | count = MAX_FACTOR; 74 | } 75 | else 76 | { 77 | prevCount = count; 78 | } 79 | } 80 | pressureCalibrationFactor[MAX_FACTOR] = pCurve[MAX_CURVE - 1].Y; 81 | if (pressureCalibrationFactor[MAX_FACTOR] > MAX_FACTOR) pressureCalibrationFactor[MAX_FACTOR] = MAX_FACTOR; 82 | 83 | #if DEBUG_LOG 84 | for (int i = 0; i < mModifyPressureFactor.Length; i++) 85 | { 86 | System.Diagnostics.Debug.WriteLine("test mPressureFactor" + i + ":" + mModifyPressureFactor[i]); 87 | } 88 | #endif 89 | } 90 | public float[] GetPressureCalibrateFactor(int cPX1, int cPY1, int cPX2, int cPY2, int cPX3, int cPY3) 91 | { 92 | MakeFactor(cPX1, cPY1, cPX2, cPY2, cPX3, cPY3); 93 | return pressureCalibrationFactor; 94 | } 95 | 96 | private void ComputeBezier(PointF[] cp, int numberOfPoints, PointF[] curve) 97 | { 98 | float dt = 1.0f / (numberOfPoints - 1); 99 | 100 | for (int i = 0; i < numberOfPoints; i++) 101 | curve[i] = PointOnCubicBezier(cp, i * dt); 102 | } 103 | 104 | private PointF PointOnCubicBezier(PointF[] cp, float t) 105 | { 106 | float ax, bx, cx; 107 | float ay, by, cy; 108 | float tSquared, tCubed; 109 | PointF result = new PointF(); 110 | 111 | cx = 3.0f * (cp[1].X - cp[0].X); 112 | bx = 3.0f * (cp[2].X - cp[1].X) - cx; 113 | ax = cp[3].X - cp[0].X - cx - bx; 114 | 115 | cy = 3.0f * (cp[1].Y - cp[0].Y); 116 | by = 3.0f * (cp[2].Y - cp[1].Y) - cy; 117 | ay = cp[3].Y - cp[0].Y - cy - by; 118 | 119 | tSquared = t * t; 120 | tCubed = tSquared * t; 121 | 122 | result.X = (ax * tCubed) + (bx * tSquared) + (cx * t) + cp[0].X; 123 | result.Y = (ay * tCubed) + (by * tSquared) + (cy * t) + cp[0].Y; 124 | 125 | return result; 126 | } 127 | 128 | private struct PointF 129 | { 130 | public PointF(float x, float y) 131 | { 132 | X = x; 133 | Y = y; 134 | } 135 | public float X { get; set; } 136 | public float Y { get; set; } 137 | } 138 | #endregion 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /Neosmartpen.Net/Neosmartpen/Implementation/Net/Support/PressureFilter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Neosmartpen.Net.Support 4 | { 5 | /// 6 | public class PressureFilter 7 | { 8 | bool m_bFirst; 9 | 10 | int m_nPrevValue; 11 | 12 | float MAX_PRESSURE_DELTA = 0.1f; 13 | 14 | public readonly int RANGE_MIN=45, RANGE_MAX; 15 | 16 | public readonly double RANGE; 17 | 18 | public PressureFilter(int max) 19 | { 20 | this.m_bFirst = true; 21 | 22 | this.RANGE_MAX = max; 23 | 24 | this.RANGE = (double)( RANGE_MAX - RANGE_MIN ); 25 | } 26 | 27 | private int FitRange( int p ) 28 | { 29 | if ( p > RANGE_MAX ) 30 | { 31 | p = RANGE_MAX; 32 | } 33 | else if ( p < RANGE_MIN ) 34 | { 35 | p = RANGE_MIN; 36 | } 37 | 38 | return p; 39 | } 40 | 41 | public int Filter( int nPressure ) 42 | { 43 | nPressure = FitRange( nPressure ); 44 | 45 | if ( m_bFirst ) 46 | { 47 | this.m_bFirst = false; 48 | this.m_nPrevValue = nPressure; 49 | 50 | return nPressure; 51 | } 52 | 53 | float diffRate = 1.0f - (float)nPressure / (float)m_nPrevValue; 54 | 55 | if ( Math.Abs( diffRate ) > MAX_PRESSURE_DELTA ) 56 | { 57 | float newRate = ( diffRate < 0 ) ? MAX_PRESSURE_DELTA : -( MAX_PRESSURE_DELTA ); 58 | nPressure = (int)( (float)m_nPrevValue * ( 1.0 + newRate ) + 0.5f ); 59 | } 60 | 61 | nPressure = FitRange( nPressure ); 62 | 63 | this.m_nPrevValue = nPressure; 64 | 65 | return nPressure; 66 | } 67 | 68 | public void Reset() 69 | { 70 | m_bFirst = true; 71 | } 72 | 73 | public double ToRate( int nPressure ) 74 | { 75 | double fPressureRate = 0; 76 | 77 | // 필압 강도 측정 (nRangeMin ~ nRangeMax 사이의 값) 78 | if ( nPressure < RANGE_MIN ) 79 | { 80 | nPressure = RANGE_MIN; 81 | } 82 | 83 | if( nPressure == 0 ) 84 | { 85 | //압력값(퍼센트)를 가져온다. 86 | fPressureRate = 1; 87 | } 88 | else 89 | { 90 | //압력값을 퍼센트로 환산한다. 91 | fPressureRate = (double)( nPressure - RANGE_MIN + 1 ) / RANGE; 92 | } 93 | 94 | if ( fPressureRate > 1.0 ) 95 | { 96 | fPressureRate = 1.0; 97 | } 98 | else if ( fPressureRate < 0.01 ) 99 | { 100 | fPressureRate = 0.01; 101 | } 102 | 103 | return fPressureRate; 104 | } 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /Neosmartpen.Net/Neosmartpen/Implementation/Net/Support/Time.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Neosmartpen.Net.Support 4 | { 5 | /// 6 | public class Time 7 | { 8 | /// 9 | /// Time gap form 1970.1.1 10 | /// 11 | /// "long Time gap" 12 | public static long GetUtcTimeStamp() 13 | { 14 | TimeSpan t = ( DateTime.UtcNow - new DateTime( 1970, 1, 1 ) ); 15 | long ts = (long)t.TotalMilliseconds; 16 | //long ts = (long)t.TotalSeconds * 1000; 17 | return ts; 18 | } 19 | /// 20 | /// Time offset 21 | /// 22 | /// 23 | public static int GetLocalTimeOffset() 24 | { 25 | TimeSpan offset = TimeZoneInfo.Local.GetUtcOffset( DateTime.UtcNow ); 26 | int iofs = (int)offset.TotalSeconds * 1000; 27 | return iofs; 28 | } 29 | 30 | /// 31 | /// 32 | /// 33 | /// 34 | /// 35 | public static DateTime GetDateTime( long timestamp, int offset = 0 ) 36 | { 37 | DateTime start = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); 38 | //DateTime date = start.AddMilliseconds(timestamp).ToLocalTime(); 39 | DateTime date = start.AddMilliseconds( timestamp + offset ); 40 | return date; 41 | } 42 | 43 | public static DateTime GetLocalDateTime( long timestamp ) 44 | { 45 | DateTime start = new DateTime( 1970, 1, 1, 0, 0, 0, DateTimeKind.Utc ); 46 | DateTime date = start.AddMilliseconds(timestamp).ToLocalTime(); 47 | return date; 48 | } 49 | 50 | /// 51 | /// 52 | /// 53 | /// 54 | public static long GetTimeGap() 55 | { 56 | // 30day gap 57 | return 2592000000; 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Neosmartpen.Net/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 6 | // 제어됩니다. 어셈블리와 관련된 정보를 수정하려면 7 | // 이러한 특성 값을 변경하세요. 8 | [assembly: AssemblyTitle("Neosmartpen.Net")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("NeoLAB Convergence")] 12 | [assembly: AssemblyProduct("Neosmartpen.Net")] 13 | [assembly: AssemblyCopyright("Copyright © NeoLAB Convergence 2024")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에 18 | // 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면 19 | // 해당 형식에 대해 ComVisible 특성을 true로 설정하세요. 20 | [assembly: ComVisible(false)] 21 | 22 | // 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다. 23 | [assembly: Guid("f74a67f4-3fd5-41b7-9cf2-6021e29ef40c")] 24 | 25 | // 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다. 26 | // 27 | // 주 버전 28 | // 부 버전 29 | // 빌드 번호 30 | // 수정 버전 31 | // 32 | [assembly: AssemblyVersion("2.5.0.0")] 33 | [assembly: AssemblyFileVersion("2.5.0")] 34 | -------------------------------------------------------------------------------- /google1c521ea3ef54bc08.html: -------------------------------------------------------------------------------- 1 | google-site-verification: google1c521ea3ef54bc08.html --------------------------------------------------------------------------------