Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Api v2 for dwafII #3

Open
wants to merge 36 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
51e8bd1
add TimeZone Call and Use number for Ra and Rec
stevejcl Aug 29, 2023
58de60f
version 0.0.2-alpha.10
stevejcl Aug 29, 2023
fd19c81
Version 0.0.2-alpha.10
stevejcl Aug 30, 2023
eba6030
0.0.2-alpha.11
stevejcl Aug 30, 2023
aed7759
0.0.2-alpha.12
stevejcl Sep 3, 2023
66387a5
0.0.2-beta.1
stevejcl Sep 6, 2023
9e26d64
0.0.2-beta.2
stevejcl Sep 8, 2023
a660cc2
0.0.2-beta.2
stevejcl Sep 10, 2023
114b962
0.0.2-beta.3
stevejcl Sep 11, 2023
5d13281
0.0.2-beta.4
stevejcl Sep 19, 2023
af50b33
First Test Version Api v2
stevejcl Feb 1, 2024
117de8b
Beta Version
stevejcl Feb 6, 2024
dfd2b25
First Test Version Api V2
stevejcl Feb 9, 2024
2129efe
set proto file compatible with python
stevejcl Feb 10, 2024
e5de997
Beta Version 2.0
stevejcl Feb 15, 2024
74083bd
2.0.1-beta
stevejcl Feb 20, 2024
05b4a5a
Add bluetooth connection
stevejcl Mar 12, 2024
09864f6
Minor corrections bluetooth
stevejcl Mar 13, 2024
0cc62dc
correction in websocket
stevejcl Mar 13, 2024
e60749d
Add moto and tracking functions
stevejcl Mar 21, 2024
1efece3
Generate Docs
stevejcl Mar 21, 2024
69a263c
Add Reconnect Function
stevejcl Mar 23, 2024
30450e1
Coorections on reconnect and closing functions
stevejcl Mar 26, 2024
ba684af
add SetHos command and correction in Open Wide Camera
stevejcl Mar 27, 2024
5bbafc5
Version 2.0.5
stevejcl Mar 29, 2024
4e74612
Version 2.0.6
stevejcl Mar 30, 2024
08c1038
Oups! remove reconnection function! restore it
stevejcl Mar 30, 2024
bf564a8
add Motor function and Plain Text for command and error Messages
stevejcl Apr 4, 2024
58852e8
Add Panorama Link
stevejcl Apr 17, 2024
7e0f94a
change in API, add Motor function
stevejcl Jun 22, 2024
6b7d218
add Mootor Error code
stevejcl Jun 23, 2024
933ee08
Add function to change device ID
stevejcl Aug 30, 2024
aa9fc29
Ignore Cmd not known from the Dwarf
stevejcl Sep 5, 2024
57151e9
Update api_utils.js
stevejcl Sep 5, 2024
479069e
docs update
stevejcl Sep 5, 2024
b4a5221
Update Dwarf_api
stevejcl Oct 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 5 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,10 @@
"sourceType": "module",
"ecmaVersion": 2020
},
"env": {
"node":true
},
// Add an exception for the generated protobuf.js file
"ignorePatterns": ["src/protobuf/protobuf/*.*", "src/proto/*.*"],
"root": true
}
151 changes: 85 additions & 66 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,84 +1,103 @@
# Dwarf II

Wrapper functions for Dwarf II (aka Dwarf 2) API V1. This library and the API are a work in progress.
Wrapper functions for Dwarf II (aka Dwarf 2) API V2.

Dwarf Lab's [API V1 documentation](https://hj433clxpv.feishu.cn/docx/MiRidJmKOobM2SxZRVGcPCVknQg).
Dwarf Lab's [API V2 documentation](https://tinyphoton.feishu.cn/docx/GBkcdldTIo3SrdxFJDscYVYDnvf?fbclid=IwAR0_Vypm8DPk1PPtwllptpWDZmxbCgi3NKVQKV8khDXIvnNay_o67AUgtq4).

[Documentation](https://dwarftelescopeusers.github.io/dwarfii_api/) for this package.
[Documentation](https://stevejcl.github.io/dwarfii_api/) for this package.

## Install

```
npm install dwarfii_api
```

## Install for Javascript
Using this library in pure javascript is possible.
Use the dist_js repertory and follow the instructions in the file index.html

## Usage

The Dwarf API uses websockets. The URL of the websockets depends on if you use Dwarf wifi or if you use the Dwarf in STA mode.
The Dwarf API uses websockets with binary protobuf format.

The URL of the websockets depends on if you use Dwarf wifi or if you use the Dwarf in STA mode.

Example of sending a Goto command using the Dwarf wifi.
Example of sending a Goto command.

```js
import { startGoto, wsURL, DwarfIP, socketSend } from "dwarfii_api";

const socket = new WebSocket(wsURL(DwarfIP));
socket.addEventListener("open", () => {
let planet = null;
let RA = 10.6;
let dec = 41.2;
let lat = 40.0;
let lon = 90.0;
let options = startGoto(planet, RA, dec, lat, lon);
socketSend(socket, options);
});

socket.addEventListener("message", (event) => {
let message = JSON.parse(event.data);
console.log(message);
});

socket.addEventListener("error", (message) => {
console.log("error:", message);
});
```
import { messageAstroStartGotoDso, WebSocketHandler } from "dwarfii_api";

// Create WebSocketHandler if need
const webSocketHandler = new WebSocketHandler(IPDwarf);

// define a customMessageHandler to handle the message in return send by the API
let goto_end_status = false;

const customMessageHandler = (txt_info, result_data) => {
if ( result_data.cmd == Dwarfii_Api.DwarfCMD.CMD_ASTRO_START_GOTO_DSO ) {
if (result_data.data.code != Dwarfii_Api.DwarfErrorCode.OK) {
console.error("Error GOTO : " + result_data.data.errorTxt);
if (
result_data.data.code ==
Dwarfii_Api.DwarfErrorCode.CODE_ASTRO_GOTO_FAILED ||
result_data.data.code ==
Dwarfii_Api.DwarfErrorCode.CODE_ASTRO_FUNCTION_BUSY
)
goto_end_status = true;
}
} else if (
!goto_end_status &&
result_data.cmd == Dwarfii_Api.DwarfCMD.CMD_NOTIFY_STATE_ASTRO_GOTO
) {
console.log(result_data.data.stateText);
}
} else if (
!goto_end_status &&
result_data.cmd == Dwarfii_Api.DwarfCMD.CMD_NOTIFY_STATE_ASTRO_TRACKING
) {
if (
result_data.data.state ==
Dwarfii_Api.OperationState.OPERATION_STATE_RUNNING &&
result_data.data.targetName == targetName
) {
goto_end_status = true;
console.info("Start Tracking");
}
} else {
// other frame result
console.log(txt_info + ": " + result_data);
return;
}
// log frame result
console.log(txt_info + ": " + result_data);
};


let txtInfoCommand = "Start Goto";

// create a packet message for the command, you can send a tabs of Packets also
let WS_Packet = messageAstroStartGotoDso(
RA_number,
declination_number,
targetName
);

// prepre the messages to send
webSocketHandler.prepare(
WS_Packet,
txtInfoCommand,
// Tab of commands to listen to, can be "*" for getting All received Data
// the others are not sending back to customMessageHandler
[
Dwarfii_Api.DwarfCMD.CMD_ASTRO_START_GOTO_DSO,
Dwarfii_Api.DwarfCMD.CMD_NOTIFY_STATE_ASTRO_GOTO,
Dwarfii_Api.DwarfCMD.CMD_NOTIFY_STATE_ASTRO_TRACKING,
],
customMessageHandler
);
// start sending and receiving
if (!webSocketHandler.run()) {
console.error(" Can't launch Web Socket Run Action!");
}

Example of sending a take astro photos command using the Dwarf in STA mode. You need to provide the IP of your Dwarf II.

```js
import {
wsURL,
socketSend,
binning2x2,
takeAstroPhoto,
fileFits,
} from "dwarfii_api";

let myIP = "192.123.45.6";
const socket = new WebSocket(wsURL(myIP));
socket.addEventListener("open", () => {
let RA = 10.6;
let dec = 41.2;
let exposure = 10;
let gain = 60;
let count = 100;
let options = takeAstroPhoto(
RA,
dec,
exposure,
gain,
binning2x2,
count,
fileFits
);
socketSend(socket, options);
});

socket.addEventListener("message", (event) => {
let message = JSON.parse(event.data);
console.log(message);
});

socket.addEventListener("error", (message) => {
console.log("error:", message);
});
```
17 changes: 9 additions & 8 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
export * from "./src/api_codes.js";
export * from "./src/api_utils.js";
export * from "./src/astro.js";
export * from "./src/camera_settings.js";
export * from "./src/image_transmission.js";
export * from "./src/motion_control.js";
export * from "./src/panoramic.js";
export * from "./src/photo_video.js";
export * from "./src/set_isp_settings.js";
export * from "./src/system_settings.js";
export * from "./src/tracking.js";
export * from "./src/camera_tele.js";
export * from "./src/camera_wide.js";
export * from "./src/panorama.js";
export * from "./src/focus.js";
export * from "./src/rgb_power.js";
export * from "./src/system.js";
export * from "./src/websocket_class.js";
export * from "./src/bluetooth.js";
export * from "./src/motor.js";
//# sourceMappingURL=index.d.ts.map
17 changes: 9 additions & 8 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
export * from "./src/api_codes.js";
export * from "./src/api_utils.js";
export * from "./src/astro.js";
export * from "./src/camera_settings.js";
export * from "./src/image_transmission.js";
export * from "./src/motion_control.js";
export * from "./src/panoramic.js";
export * from "./src/photo_video.js";
export * from "./src/set_isp_settings.js";
export * from "./src/system_settings.js";
export * from "./src/tracking.js";
export * from "./src/camera_tele.js";
export * from "./src/camera_wide.js";
export * from "./src/panorama.js";
export * from "./src/focus.js";
export * from "./src/rgb_power.js";
export * from "./src/system.js";
export * from "./src/websocket_class.js";
export * from "./src/bluetooth.js";
export * from "./src/motor.js";
95 changes: 10 additions & 85 deletions dist/src/api_codes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,14 @@ export function wsURL(IP: string): string;
export function wideangleURL(IP: string): string;
export function telephotoURL(IP: string): string;
export function rawPreviewURL(IP: string): string;
export function utcURL(IP: string): string;
export const turnOnCameraCmd: 10000;
export const turnOffCameraCmd: 10017;
export const telephotoCamera: 0;
export const wideangleCamera: 1;
export const previewImageQuality: 10016;
export const takePhotoCmd: 10006;
export const photoSingleShot: 0;
export const photoContinuous: 1;
export const startRecordingCmd: 10007;
export const stopRecordingCmd: 10009;
export const startTimelapseCmd: 10018;
export const stopTimelapseCmd: 10019;
export function firmwareVersion(IP: string): string;
export function getDefaultParamsConfig(IP: string): string;
export const modeAuto: 0;
export const modeManual: 1;
export const setBrightnessValueCmd: 10204;
export const setContrastValueCmd: 10205;
export const setSaturationValueCmd: 10206;
export const setHueValueCmd: 10207;
export const setSharpnessValueCmd: 10208;
export const setExposureModeCmd: 10001;
export const setExposureValueCmd: 10003;
export const exposureTelephotoModeAuto: 0;
export const exposureWideangleModeAuto: 3;
export const setGainModeCmd: 10004;
export const setGainValueCmd: 10005;
export const autofocusCmd: 10211;
export const autofocusGlobal: 0;
export const autofocusArea: 1;
export const setWhiteBalanceModeCmd: 10212;
export const setWhiteBalanceScenceCmd: 10213;
export const exposureTelephotoModeAuto: 0;
export const exposureWideangleModeAuto: 3;
export const whiteBalanceScenesIDValue: {
0: string;
1: string;
Expand All @@ -45,81 +22,29 @@ export const whiteBalanceScenesIDValue: {
6: string;
};
export const whiteBalanceScenesValueID: {
"incandescent lamp": number;
"fluorescent lamp": number;
"warm fluorescent lamp": number;
incandescent: number;
"warm fluorescent": number;
fluorescent: number;
sunlight: number;
"overcast sky": number;
"evening twilight": number;
cloudy: number;
shadow: number;
twilight: number;
};
export const setWhiteBalanceColorCmd: 10214;
export const setIRCmd: 10203;
export const IRCut: 0;
export const IRPass: 3;
export const statusTelephotoCmd: 10215;
export const statusIRTelephotoCmd: 10216;
export const statusWorkingStateTelephotoCmd: 10022;
export const statusWideangleCmd: 10217;
export const calibrateGotoCmd: 11205;
export const startGotoCmd: 11203;
export namespace planetsValueId {
let Mercury: number;
let Venus: number;
let Mars: number;
let Jupiter: number;
let Saturn: number;
let Uranus: number;
let Neptune: number;
let Moon: number;
}
export const planetsIdValue: {
0: string;
1: string;
2: string;
3: string;
4: string;
5: string;
6: string;
7: string;
};
export const takeAstroPhotoCmd: 10011;
export const stopAstroPhotoCmd: 10015;
export const IRPass: 1;
export const binning1x1: 0;
export const binning2x2: 1;
export const fileFits: 0;
export const fileTiff: 1;
export const numberRawImagesCmd: 10014;
export const numberSuperImposedImages: 10023;
export const setRAWPreviewCmd: 10020;
export const rawPreviewContinousSuperimpose: 0;
export const rawPreviewSingle15: 1;
export const rawPreviewSingleComposite: 2;
export const takeAstroDarkFramesCmd: 10026;
export const darkGainDefault: 65528;
export const queryShotFieldCmd: 10027;
export const traceInitCmd: 11200;
export const startTrackingCmd: 11201;
export const stopTrackingCmd: 11202;
export const startPanoCmd: 10103;
export const stopPanoCmd: 10106;
export const startMotionCmd: 10100;
export const continuous_mode: 1;
export const pulse_mode: 2;
export const stopMotionCmd: 10101;
export const setSpeedCmd: 10107;
export const speedDecelerate: 0;
export const speedAccelerate: 1;
export const setDirectionCmd: 10108;
export const anticlockwise: 0;
export const clockwise: 1;
export const setSubdivideCmd: 10109;
export const spinMotor: 1;
export const pitchMotor: 2;
export const systemStatusCmd: 11407;
export const microsdStatusCmd: 11405;
export const microsdAvailableCmd: 11409;
export const dwarfSoftwareVersionCmd: 11410;
export const dwarfChargingStatusCmd: 11011;
export const shutDownCmd: 11004;
//# sourceMappingURL=api_codes.d.ts.map
2 changes: 1 addition & 1 deletion dist/src/api_codes.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading