Skip to content

Commit

Permalink
Update contents for new api
Browse files Browse the repository at this point in the history
  • Loading branch information
parksb committed Nov 17, 2023
1 parent cd77828 commit 914c72f
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ On the server device, the server instance can retrieve the data from acceleromet
(new class extends ZapServer {
// Define the method that is called whenever accelerometer sensor data is
// received from client devices.
onAccelerometerChanged(info: MetaInfo, data: ZapAccelerometer) {
onAccelerometerReceived(info: MetaInfo, data: ZapAccelerometer) {
console.log(`Data received from ${info.dgram.address}: (${data.x}, ${data.y}, ${data.z})`);
}
}).listen();
Expand Down
2 changes: 1 addition & 1 deletion src/architectures/zap-protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ The header consists of a timestamp and a resource field. The first 64 bits of th

Following the timestamp, the next 8 bits constitute the resource field. The resource field informs which resource the payload represents and simultaneously implies how the payload is encoded. This field can be interpreted as an unsigned integer.

After the 72-bit header, there is the payload part. The format of the payload varies depending on the resource. It can be a simple primitive type, text with delimiters, or JSON. The maximum length of the payload is theoretically up to 65,518 bytes, although it may vary depending on the implementation of Zap server.
After the 72-bit header, there is the payload part. The format of the payload varies depending on the resource. It can be a simple primitive type, text with delimiters, or JSON. Refer to the [Resources](../specifications/resources.md) page for information on the payload format each resource takes. The maximum length of the payload is theoretically up to 65,518 bytes, although it may vary depending on the implementation of Zap server.
2 changes: 1 addition & 1 deletion src/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Now, simply create an index.js file and write the Zap server. This server will r
import { ZapServer } from 'zap-lib-js';

(new class extends ZapServer {
onAccelerometerChanged(info, data) {
onAccelerometerReceived(info, data) {
console.log(`Data received from ${info.dgram.address}: (${data.x}, ${data.y}, ${data.z})`);
}
}).listen();
Expand Down
2 changes: 1 addition & 1 deletion src/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ On the server device, the server instance can retrieve the data from acceleromet
(new class extends ZapServer {
// Define the method that is called whenever accelerometer sensor data is
// received from client devices.
onAccelerometerChanged(info: MetaInfo, data: ZapAccelerometer) {
onAccelerometerReceived(info: MetaInfo, data: ZapAccelerometer) {
console.log(`Data received from ${info.dgram.address}:
(${data.x}, ${data.y}, ${data.z})`);
}
Expand Down
9 changes: 7 additions & 2 deletions src/specifications/client-and-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@ A server receives data from client. The 'open function' refers to a callback fun
|------|-----------|-------------|
| function | `listen(port: int): void` | Start listening the transmitted data from clients on the given port. <hr> `port`: A port number for receiving data (default: `65500`). |
| function | `stop(): void` | Stop listening to clients. |
| open function | `onAccelerometerChanged(info: MetaInfo, data: ZapAccelerometer): void` | A callback function called whenever accelerometer sensor data is received. |
| open function | `onAccelerometerReceived(info: MetaInfo, data: ZapAccelerometer): void` | A callback function called whenever accelerometer sensor data is received. |
| open function | `onGeoPointReceived(info: MetaInfo, data: ZapGeoPoint): void` | A callback function called whenever geological point is received. |
| open function | `onGravityReceived(info: MetaInfo, data: ZapGravity): void` | A callback function called whenever gravity data is received. |
| open function | `onGyroscopeReceived(info: MetaInfo, data: ZapGyroscope): void` | A callback function called whenever gyroscope data is received. |
| open function | `onIlluminanceReceived(info: MetaInfo, data: ZapIlluminance): void` | A callback function called whenever illuminance data is received. |
| open function | `onMagneticFieldReceived(info: MetaInfo, data: ZapMagneticField): void` | A callback function called whenever magnetic field data is received. |
| open function | `onUIEventReceived(info: MetaInfo, data: ZapUiEvent): void` | A callback function called whenever UI event data is received. |
| open function | `onTextReceived(info: MetaInfo, data: ZapText): void` | A callback function called whenever text data is received.|
| open function | `onTextReceived(info: MetaInfo, data: ZapText): void` | A callback function called whenever text data is received. |

The server implementation, upon receiving a datagram, MUST reference the `ZappHeader` to identify the resource and then invoke the corresponding callback function for that resource. For detailed specifications on supported resources, please refer to [Resources](./resources.md) section.

Expand Down
114 changes: 101 additions & 13 deletions src/specifications/resources.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,94 @@

A registry of resources supported by Zap and their identification keys.

| property | key<br>(8-bit uint) | description |
| property | key<br>(8-bit uint) | type |
|------|-----------|-------------|
| `ACCELEROMETER` | 10 | A data measured by an accelerometer sensor. |
| `UI_EVENT` | 20 | A data related to event raised by the user interface. |
| `TEXT` | 30 | A simple text data. |
| `ACCELEROMETER` | 10 | `ZapAccelerometer` |
| `GRAVITY` | 11 | `ZapGravity` |
| `GYROSCOPE` | 12 | `ZapGyroscope` |
| `ILLUMINANCE` | 13 | `ZapIlluminance` |
| `MAGNETIC_FIELD` | 14 | `ZapMagneticField` |
| `UI_EVENT` | 20 | `ZapUiEvent` |
| `TEXT` | 30 | `ZapText` |
| `GEO_POINT` | 31 | `ZapGeoPoint` |

## `ZapText`
## `ZapAccelerometer`

Represent simple text.
Represent values measured by accelerometer sensor

```text
+-------------+-------------+-------------+
| x (32 bits) | y (32 bits) | z (32 bits) |
+-------------+-------------+-------------+
```

| type | signature | description |
|------|-----------|-------------|
| property | `str: string` | Just string. |
| property | `charset` | A character set of `str`. (default: UTF-8) |
| property | `x: float` | Acceleration force along the x axis. (m/s²) |
| property | `y: float` | Acceleration force along the y axis. (m/s²) |
| property | `z: float` | Acceleration force along the z axis. (m/s²) |

## `ZapAccelerometer`
## `ZapGravity`

Represent the force of gravity that is applied to a device.

Represent values measured by accelerometer sensor.
```text
+-------------+-------------+-------------+
| x (32 bits) | y (32 bits) | z (32 bits) |
+-------------+-------------+-------------+
```

| type | signature | description |
|------|-----------|-------------|
| property | `x: float` | Acceleration force along the x axis. (m/s²) |
| property | `y: float` | Acceleration force along the y axis. (m/s²) |
| property | `z: float` | Acceleration force along the z axis. (m/s²) |
| property | `x: float` | Force of gravity along the x axis. (m/s²) |
| property | `y: float` | Force of gravity along the y axis. (m/s²) |
| property | `z: float` | Force of gravity along the z axis. (m/s²) |

## `ZapGyroscope`

Represent a device's rate of rotation.

```text
+-------------+-------------+-------------+
| x (32 bits) | y (32 bits) | z (32 bits) |
+-------------+-------------+-------------+
```

| type | signature | description |
|------|-----------|-------------|
| property | `x: float` | Rate of rotation around the x axis. (rad/s) |
| property | `y: float` | Rate of rotation around the y axis. (rad/s) |
| property | `z: float` | Rate of rotation around the z axis. (rad/s) |

## `ZapIlluminance`

Represent the ambient light level.

```text
+--------------+
| lx (32 bits) |
+--------------+
```

| type | signature | description |
|------|-----------|-------------|
| property | `lx: float` | Ambient light level. (lx) |

## `ZapMagneticField`

Represent a ambient geomagnetic field.

```text
+-------------+-------------+-------------+
| x (32 bits) | y (32 bits) | z (32 bits) |
+-------------+-------------+-------------+
```

| type | signature | description |
|------|-----------|-------------|
| property | `x: float` | Geomagnetic field strength along the x axis. (μT) |
| property | `y: float` | Geomagnetic field strength along the y axis. (μT) |
| property | `z: float` | Geomagnetic field strength along the z axis. (μT) |

## `ZapUiEvent`

Expand All @@ -45,3 +109,27 @@ Represent data related to event raised by the user interface.
|------|-----------|-------------|
| `CLICK_DOWN` | `CLICK_DOWN` | An event triggered when a click (or touch) is initiated on the UI. |
| `CLICK_UP` | `CLICK_UP` | An event triggered when a click (or touch) on the UI has ended. |

## `ZapText`

Represent simple text.

| type | signature | description |
|------|-----------|-------------|
| property | `str: string` | Just string. |
| property | `charset` | A character set of `str`. (default: UTF-8) |

## `ZapGeoPoint`

Represent a point on earth in geological coordinates.

```text
+--------------------+---------------------+
| latitude (64 bits) | longitude (64 bits) |
+--------------------+---------------------+
```

| type | signature | description |
|------|-----------|-------------|
| property | `latitude: double` | A latitude of the point. |
| property | `longitude: double` | A longitude of the point. |

0 comments on commit 914c72f

Please sign in to comment.