Skip to content
This repository has been archived by the owner on May 20, 2024. It is now read-only.

Commit

Permalink
constants + schemas + types
Browse files Browse the repository at this point in the history
  • Loading branch information
crisconru committed Jan 9, 2024
1 parent 891cae0 commit cf9dcbb
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// GENERATE NUMBERS
export const UINT8_MAX = Uint8Array.from([0b1111_1111])[0]
export const UINT16_MAX = Uint16Array.from([0b1111_1111_1111_1111])[0]
export const UINT32_MAX = Uint32Array.from([0b1111_1111_1111_1111_1111_1111_1111_1111])[0]
// export const UINT64_MAX = Uint64Array.from([0b11111111_11111111_11111111_11111111_11111111_11111111_11111111_11111111])[0]

export const [INT8_MIN, INT8_MAX] = Int8Array.from([0b1000_0000, 0b0111_1111])
export const [INT16_MIN, INT16_MAX] = Int16Array.from([0b1000_0000_0000_0000, 0b0111_1111_1111_1111])
export const [INT32_MIN, INT32_MAX] = Int32Array.from([0b1000_0000_0000_0000_0000_0000_0000_0000, 0b0111_1111_1111_1111_1111_1111_1111_1111])
// export const [INT64_MIN, INT64_MAX] = Int64Array.from([0b10000000_00000000_00000000_00000000_00000000_00000000_00000000_00000000, 0b01111111_11111111_11111111_11111111_11111111_11111111_11111111_11111111])

export const MAX_FLOAT = 999999999999999
export const MIN_FLOAT = -999999999999999
28 changes: 28 additions & 0 deletions src/schemas.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { z } from 'zod'
import { INT16_MAX, INT16_MIN, INT32_MAX, INT32_MIN, INT8_MAX, INT8_MIN, UINT16_MAX, UINT32_MAX, UINT8_MAX } from './constants'

export const StringSchema = z.string()
export const StringArraySchema = z.array(StringSchema)
export const BooleanSchema = z.boolean()
export const NumberSchema = z.number()
export const IntegerSchema = NumberSchema.int()
export const NaturalSchema = IntegerSchema.nonnegative()

export const Uint8Schema = NaturalSchema.max(UINT8_MAX)
export const Uint16Schema = NaturalSchema.max(UINT16_MAX)
export const Uint32Schema = NaturalSchema.max(UINT32_MAX)
// export const Uint64Schema = NaturalSchema.max(UINT64_MAX)
export const Int8Schema = IntegerSchema.min(INT8_MIN).max(INT8_MAX)
export const Int16Schema = IntegerSchema.min(INT16_MIN).max(INT16_MAX)
export const Int32Schema = IntegerSchema.min(INT32_MIN).max(INT32_MAX)
// export const Int64Schema = IntegerSchema.min(INT64_MIN).max(INT64_MAX)

export const BigIntegerSchema = z.bigint()
export const BigNaturalSchema = BigIntegerSchema.positive()


export const StatusInputSchema = z.object({
status: Uint32Schema.optional(),
status_a: Uint16Schema.optional(),
status_b: Uint16Schema.optional()
})
79 changes: 79 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { z } from 'zod'
import { Int16Schema, Int32Schema, Int8Schema, IntegerSchema, NumberSchema, StatusInputSchema, Uint16Schema, Uint32Schema, Uint8Schema } from './schemas'

// NUMBERS
export type Integer = z.infer<typeof NumberSchema>
export type Natural = z.infer<typeof IntegerSchema>

export type Uint8 = z.infer<typeof Uint8Schema>
export type Uint16 = z.infer<typeof Uint16Schema>
export type Uint32 = z.infer<typeof Uint32Schema>
// export type Uint64 = z.infer<typeof Uint64Schema>
export type Int8 = z.infer<typeof Int8Schema>
export type Int16 = z.infer<typeof Int16Schema>
export type Int32 = z.infer<typeof Int32Schema>
// export type Int64 = z.infer<typeof Int64Schema>

// STATUS
export type StatusInput = z.infer<typeof StatusInputSchema>

export type Status = {
main: {
ok: boolean,
health: boolean,
},
health: {
ok: boolean,
health: boolean,
synchronized_time: boolean,
synchronized_clock: boolean,
cpu: boolean,
},
sensor: {
ok: boolean,
health: boolean,
limits: boolean,
environmental: {
vibration: boolean,
temperature: boolean,
}
},
algorithms: {
ok: boolean,
health: boolean,
initialization: {
observer: boolean,
heading: boolean
},
roll_pitch: {
ok: boolean,
health: boolean,
},
heading: {
ok: boolean,
health: boolean,
},
surge_sway: {
ok: boolean,
health: boolean,
},
heave: {
ok: boolean,
health: boolean,
},
},
aiding: {
received: {
position: boolean,
velocity: boolean,
heading: boolean,
},
valid: {
position: boolean,
velocity: boolean,
heading: boolean,
vertical: boolean,
horizontal: boolean,
}
}
}

0 comments on commit cf9dcbb

Please sign in to comment.