Skip to content

Commit 07128b5

Browse files
authored
Merge pull request #40 from gkjohnson/support-lite-build
Add support lite build (down to 20MB)
2 parents 187d723 + fcfadf4 commit 07128b5

13 files changed

+884
-52
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,6 @@ dist
121121
cjs/
122122
example/bundle
123123
generation/cspice/
124+
generation/cspice-full/
125+
generation/cspice-lite/
124126
generation/cspice.js

README.md

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
<!--[![lgtm code quality](https://img.shields.io/lgtm/grade/javascript/g/NASA-AMMOS/timecraftjs.svg?style=flat-square&label=code-quality)](https://lgtm.com/projects/g/NASA-AMMOS/timecraftjs/)-->
1515

16-
TimeCraftJS is a time conversion library that uses [NAIF's CSPICE](https://naif.jpl.nasa.gov/naif/). It exposes functions to execute operations to convert [SCET](https://en.wikipedia.org/wiki/Spacecraft_Event_Time), ET, SCT, furnish Kernels, among others, on the client side. This avoid unnecessary trips to the backend and allows for important time operations to happen if network connectivity is not immediately available.
16+
TimeCraftJS is a time conversion library that uses [NAIF's CSPICE](https://naif.jpl.nasa.gov/naif/). It exposes functions to execute operations to convert [SCET](https://en.wikipedia.org/wiki/Spacecraft_Event_Time), ET, SCT, furnish Kernels, among others, on the client side. This avoid unnecessary trips to the backend and allows for important time operations to happen if network connectivity is not immediately available. Multiple variants of the built CSPICE library are provided, including a limited, low-memory "lite" version with lesser functionality which is loaded by default. See [Constants](#Constants) section and [init](#init) function description for more information on the options.
1717

1818
Some basic kernels are provided in this repo for performing time conversions. More kernels for other missions can be found [here](https://naif.jpl.nasa.gov/pub/naif/pds/data/).
1919

@@ -135,16 +135,28 @@ See example-timecraftjs.html for a simple demo of TimeCraftJS working.
135135

136136
This section lists the files included in this package and describes what each of them does. This section is mainly for people who wish to modify this package, if you simply wish to use it you can likely skip this section.
137137

138-
#### cspice.js
138+
#### src/cspice/*.js
139139

140-
This file contains the ported CSPICE source code. It is extremely large and should not be modified. This file must begin executing after spice.js and timecraft.js, so make sure to include it last. If running in Node, import timecraft.js, not this file.
140+
These files contain the emscripten-converted CSPICE source code. It is extremely large and should not be modified. Both a "full" and "lite" version of converted CSPICE is provided. See the [Constants](#Constants) section for more information on the variants.
141141

142-
#### spice.js
142+
#### src/spice.js
143143

144144
This file contains the wrapper class that allows access to the functionality in cspice.js. The version of spice.js here is focused on time conversions, but the rest of the CSPICE functionality could be exposed if needed.
145145

146146
## API
147147

148+
### Constants
149+
150+
Constants for use in the [Spice.init](#init) function to intialize the library to use either a full or lite version of the SPICE library.
151+
152+
#### ASM_SPICE_FULL
153+
154+
Use this constant to load and use the full asm.js version of the SPICE library with full functionality. Run time memory requirement is around 100 MB.
155+
156+
#### ASM_SPICE_LITE
157+
158+
Use this constant to load and use an asm.js version of an unofficial "lite" version of the SPICE library with some missing functonality to improve memory requirements. Specifically all `ek*` functions have been removed and various internal constants have been lowered to reduce memory use. Not all NAIF kernels can be guaranteed to function when using this reduced memory of the package. If an error occurs due to overrunning memory use the "full" version, instead. Run time memory requirement is around 20 MB.
159+
148160
### Spice
149161

150162
Class used to instantiate an instance of Spice. Multiple instances can be created to load different kernels if desired. [init](#init) must be called before use.
@@ -198,28 +210,30 @@ This is the raw Emscripten compiled module that is used to call CSpice functions
198210
#### .init
199211

200212
```js
201-
init() : Promise<this>
213+
init( type : ( ASM_SPICE_LITE | ASM_SPICE_FULL ) = ASM_SPICE_LITE ) : Promise<this>
202214
```
203215

204216
Loads and initializes the CSpice module. The class is ready to use once the promise has resolved.
205217

206-
#### loadKernel
218+
The "type" parameter can be used to dictate which version of the compiled CSPICE module to use. See the [Constants](#Constants) section for available options and more information. Defaults to using the "lite" version of the module.
219+
220+
#### .loadKernel
207221

208222
```js
209223
loadKernel( buffer : ArrayBuffer | Uint8Array, key : String = null ) : void
210224
```
211225

212226
Load the provided buffer into Spice as a kernel. The provided key can be used to unload the kernel using [unloadKernel](#unloadKernel). Throws an error if the key has already been used. Details of kernel management can be found in the [Kernel Management](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/req/kernel.html#Section%205%20--%20Kernel%20Management) section of the SPICE docs.
213227

214-
#### unloadKernel
228+
#### .unloadKernel
215229

216230
```js
217231
unloadKernel( key : String ) : void
218232
```
219233

220234
Unload the kernel that was loaded with the given key. Throws an error if a kernel has not been loaded with the given key.
221235

222-
#### chronos
236+
#### .chronos
223237

224238
```js
225239
chronos( inptim : String, cmdlin : String ) : String
@@ -334,16 +348,34 @@ spiceInstance.loadKernel(buffer);
334348

335349
## Recompiling cspice.js
336350

337-
`cspice.js` is the massive Javascript file resulting from the automatic porting via Emscripten. As such, if CSPICE updates, this file will need to be recompiled. The current version of cspice.js was created from the [Mac/OSX 64 Bit Toolkit](https://naif.jpl.nasa.gov/naif/toolkit_C_MacIntel_OSX_AppleC_64bit.html) on April 12, 2021 with version emscripten version 2.0.17.
351+
The files in `src/cspice/` are the massive Javascript files resulting from the automatic porting via Emscripten. As such, if CSPICE updates, these files will need to be recompiled. In order to recompile any of the JS CSPICE files, follow these steps:
338352

339-
In order to recompile cspice.js, follow these steps:
353+
### Setting Up Emscripten
340354

341355
1. Download relevant toolkit from [the NAIF website](https://naif.jpl.nasa.gov/naif/toolkit_C.html).
342356
1. Download [emsdk](https://github.com/emscripten-core/emsdk) to download and manage "emscripten" versions.
343357
1. Install the latest version of emscripten and source the emsdk environment variables from `emsdk_env.sh`.
344-
1. Unzip the CSpice source folder and put the contents into the `generation/cspice` folder.
358+
359+
### CSPICE Full (asm_full.js)
360+
361+
The current version was created from the [Mac/OSX 64 Bit Toolkit](https://naif.jpl.nasa.gov/naif/toolkit_C_MacIntel_OSX_AppleC_64bit.html) on April 12, 2021 with emscripten version 2.0.17.
362+
363+
1. Unzip the CSPICE source folder and put the contents into the `generation/cspice-full` folder.
364+
1. Ensure the `LITE_BUILD` variable is set to `False` in `generation/generate-cspice.sh`.
365+
1. Run `generation/generate-cspice.sh` to generate the js library file in the folder.
366+
1. Move the newly generated `asm_full.js` file into the `src/cspice` folder.
367+
368+
### CSPICE Lite (asm_lite.js)
369+
370+
_INTERNAL ONLY_
371+
372+
The modified lite version of the CSPICE used was dervied from the latest version of CSPICE on April 27, 2021 with emscripten version 2.0.17. The CSPICE lite code only provides modified `src/cspice` functions so necessary chronos functionality is copied from the latest public version.
373+
374+
1. Unzip the latest CSPICE source folder (see above) and put the contents into the `generation/cspice-full` folder.
375+
1. Unzip the CSPICE lite source folder and put the contents into the `generation/cspice-lite` folder. Modified CSPICE lite source available [here](https://github.jpl.nasa.gov/gkjohnso/cspice-lite) (internal only).
376+
1. Ensure the `LITE_BUILD` variable is set to `True` in `generation/generate-cspice.sh`.
345377
1. Run `generation/generate-cspice.sh` to generate the js library file in the folder.
346-
1. Move the newly generated `cspice.js` file into the `src/` folder.
378+
1. Move the newly generated `asm_lite.js` file into the `src/cspice` folder.
347379

348380
## License
349381

0 commit comments

Comments
 (0)