Skip to content

Core API

Overview

The Core API provides the fundamental functionality for the ECO SDK components.

Memory Manager API

Functions

allocate(size: number): Pointer

Allocates memory of the specified size.

Parameters:

  • size: The size of memory to allocate in bytes

Returns:

  • Pointer: A pointer to the allocated memory

Example:

javascript
const ptr = allocate(1024); // Allocate 1KB

deallocate(pointer: Pointer): void

Deallocates the memory at the specified pointer.

Parameters:

  • pointer: The pointer to the memory to deallocate

Example:

javascript
deallocate(ptr); // Free allocated memory

File System API

Functions

readFile(path: string): Buffer

Reads the contents of a file.

Parameters:

  • path: The path to the file to read

Returns:

  • Buffer: The contents of the file

Example:

javascript
const contents = readFile('/path/to/file.txt');

writeFile(path: string, data: Buffer): void

Writes data to a file.

Parameters:

  • path: The path to the file to write
  • data: The data to write to the file

Example:

javascript
writeFile('/path/to/file.txt', Buffer.from('Hello World'));

Interface Bus API

Functions

sendMessage(target: string, message: Message): void

Sends a message to a target component.

Parameters:

  • target: The target component identifier
  • message: The message to send

Example:

javascript
sendMessage('memory-manager', { type: 'allocate', size: 1024 });

registerHandler messageType: string, handler: Function): void

Registers a handler for a specific message type.

Parameters:

  • messageType: The message type to handle
  • handler: The handler function

Example:

javascript
registerHandler('allocation-request', (message) => {
  // Handle allocation request
});

DateTime API

Functions

getCurrentTime(): Date

Gets the current date and time.

Returns:

  • Date: The current date and time

Example:

javascript
const now = getCurrentTime();

formatDate(date: Date, format: string): string

Formats a date according to the specified format.

Parameters:

  • date: The date to format
  • format: The format string

Returns:

  • string: The formatted date string

Example:

javascript
const formatted = formatDate(new Date(), 'YYYY-MM-DD');

Logging API

Functions

log(level: LogLevel, message: string): void

Logs a message at the specified level.

Parameters:

  • level: The log level (DEBUG, INFO, WARN, ERROR)
  • message: The message to log

Example:

javascript
log('INFO', 'Application started successfully');

setLogLevel(level: LogLevel): void

Sets the minimum log level.

Parameters:

  • level: The minimum log level to output

Example:

javascript
setLogLevel('DEBUG'); // Show all log levels

Math FFT API

Functions

fft(input: Float32Array): Float32Array

Performs Fast Fourier Transform on the input data.

Parameters:

  • input: The input data array

Returns:

  • Float32Array: The FFT result

Example:

javascript
const result = fft(signalData);

ifft(input: Float32Array): Float32Array

Performs Inverse Fast Fourier Transform on the input data.

Parameters:

  • input: The input data array

Returns:

  • Float32Array: The IFFT result

Example:

javascript
const result = ifft(fftData);