Global

Members

(constant) WebSocket

Import WebSocket library
Source:

(constant) WebSocket

Import WebSocket library
Source:

(constant) app

Create an instance of the Express application
Source:

(constant) app

Import application module
Source:

(constant) bodyParser

Middleware for parsing JSON request bodies
Source:

carState :Object

Represents the current state of the car.
Type:
  • Object
Source:

(constant) confirmationPhrases :Array.<string>

List of phrases indicating user confirmation.
Type:
  • Array.<string>
Source:

(constant) cors

Middleware for enabling Cross-Origin Resource Sharing (CORS)
Source:

currentDriveLogName

Current drive log filename
Source:

currentDriveObject

Current drive object containing log data
Source:

detectionUnitData

Holds data from the detection unit
Source:

(constant) express

Import Express framework
Source:

(constant) express

Import Express framework
Source:

(constant) fs

Import file system and path modules
Source:

locks :Object

Locks used for controlling various application states.
Type:
  • Object
Source:

(constant) logsDir :string

Directory for storing log files (relative to this module's __dirname). Ensures the logs directory exists.
Type:
  • string
Source:

(constant) noResponsePhrases :Array.<string>

List of phrases indicating no response from the user.
Type:
  • Array.<string>
Source:

(constant) path

Import path module for handling file and directory paths
Source:

(constant) path

Import path module
Source:

(constant) sounds :Object

Paths to sound assets used for various alerts and notifications.
Type:
  • Object
Source:

speed

Current speed of the car, starting from 0
Source:

(constant) status :Object

Status codes for application operations.
Type:
  • Object
Source:

(constant) stemmedConfirmationPhrases

Preprocesses confirmation phrases with stemming.
Source:

(constant) stemmedNoResponsePhrases

Preprocesses no-response phrases with stemming.
Source:

(constant) units :Object

Time units used in the application.
Type:
  • Object
Source:

(constant) user_status :Object

User response statuses for various prompts or actions.
Type:
  • Object
Source:

Methods

accelerateCar()

Accelerates the car and updates its state.
Source:

(async) askForUserConfirmation() → {Promise.<number>}

Prompts the user for a confirmation of alertness by recording and analyzing audio.
Source:
Returns:
- User status based on their response.
Type
Promise.<number>

broadcast(wss, data)

Sends a message to all connected WebSocket clients.
Parameters:
Name Type Description
wss WebSocket.Server The WebSocket server instance.
data object The data to broadcast.
Source:

broadcastSpeed(wss, speed)

Broadcasts the current speed to all connected WebSocket clients.
Parameters:
Name Type Description
wss WebSocket.Server The WebSocket server instance.
speed number The current speed of the car.
Source:

createDriveLogFile()

Creates a log file with a timestamped filename and initializes it with default data.
Source:

cruiseDrive()

Sets the car to cruise mode and updates its state.
Source:

decelerateCar()

Decelerates the car and updates its state.
Source:

generateDriveFileName() → {string}

Generates a custom timestamped filename for the log file.
Source:
Returns:
Timestamped filename.
Type
string

getRandomInt(max) → {number}

Generates a random integer between 0 (inclusive) and the specified maximum value (exclusive).
Parameters:
Name Type Description
max number The upper bound (exclusive) for the random integer.
Source:
Returns:
A random integer between 0 and max.
Type
number

getSystemData() → {Object}

Retrieves system data including CPU model, memory usage, and Hailo device information.
Source:
Returns:
System data containing CPU model, memory usage, and Hailo info.
Type
Object

handleClientMessage(ws, message, wss)

Handles incoming messages from WebSocket clients.
Parameters:
Name Type Description
ws WebSocket The WebSocket instance of the client sending the message.
message string The received message in JSON format.
wss WebSocket.Server The WebSocket server instance.
Source:

hasAlertConfirmation(lines) → {number}

Checks if the transcription includes a confirmation of alertness.
Parameters:
Name Type Description
lines Array.<string> Parsed transcription lines.
Source:
Returns:
- User status indicating the response type.
Type
number

initWebSocket(server) → {WebSocket.Server}

Initializes the WebSocket server and sets up event listeners for client communication.
Parameters:
Name Type Description
server object The HTTP server instance to attach the WebSocket server.
Source:
Returns:
The WebSocket server instance.
Type
WebSocket.Server

logStatus()

Logs the current state of the car to the console.
Source:

muteAllStreams()

Mutes all audio streams using a linux command.
Source:

parseHailoData(hailoInfo) → {Object}

Parses the raw output of Hailo device information into a structured object.
Parameters:
Name Type Description
hailoInfo string Raw output from Hailo CLI.
Source:
Returns:
Parsed Hailo device information.
Type
Object

parseMemoryData(memory) → {Object}

Parses memory usage data from the `free -h` command output, some irrelevant data was excluded to send less data.
Parameters:
Name Type Description
memory string Raw memory data output.
Source:
Returns:
Parsed memory usage information.
Type
Object

parseWhisperOutput(rawOutput) → {Array.<string>}

Parses the raw transcription lines from whisper-cli output.
Parameters:
Name Type Description
rawOutput string Raw output from whisper-cli.
Source:
Returns:
- Parsed transcription lines.
Type
Array.<string>

playSound(filePath) → {Promise.<void>}

Plays a sound file.
Parameters:
Name Type Description
filePath string Path to the WAV file to play.
Source:
Returns:
- Resolves when the sound has finished playing.
Type
Promise.<void>

printToConsole(message)

Logs a message to the console if debugging is enabled.
Parameters:
Name Type Description
message string The message to log.
Source:

recordAudioWithFFmpeg(outputFilePath, durationInSeconds) → {Promise.<void>}

Records audio using ffmpeg and saves it as a WAV file in 16kHz mono format.
Parameters:
Name Type Default Description
outputFilePath string Path to save the recorded WAV file.
durationInSeconds number 5 Duration to record in seconds.
Source:
Returns:
Type
Promise.<void>

(async) removeFile(path) → {Promise.<void>}

Deletes a file at the specified path.
Parameters:
Name Type Description
path string The path of the file to delete.
Source:
Returns:
- Resolves when the file is successfully deleted.
Type
Promise.<void>

sendWelcomeMessage(ws)

Sends a welcome message to the connected client, including system data and gauge configuration.
Parameters:
Name Type Description
ws WebSocket The WebSocket instance of the connected client.
Source:

startApp()

Initializes the server, serves static frontend files, and integrates the WebSocket server.
Source:

startSpeedBroadcast(wss)

Starts broadcasting the car's speed to all connected WebSocket clients.
Parameters:
Name Type Description
wss WebSocket.Server The WebSocket server instance.
Source:

(async) transcribeWithWhisper(audioFilePath) → {Promise.<string>}

Transcribes a WAV file using whisper-cli.
Parameters:
Name Type Description
audioFilePath string The path to the .wav file.
Source:
Returns:
- The raw transcription output from whisper-cli.
Type
Promise.<string>

unmuteAllStreams()

Unmutes all audio streams using a linux command.
Source:

updateDriveDataLog()

Updates the existing log file with the current drive object.
Source:

updateSpeed()

Updates the car's speed based on its state.
Source:

Type Definitions

MessageData

Type:
  • object
Properties:
Name Type Description
type string Type of the message.
msgData object Data associated with the message.
Source:

ProcessEnv

Type:
  • Object
Properties:
Name Type Description
PORT string Port number for the server to listen on.
IP string IP address for the server to bind to.
Source: