Skip to content

Commit

Permalink
feat: ZigBee on Host
Browse files Browse the repository at this point in the history
  • Loading branch information
Nerivec committed Jan 20, 2025
1 parent 57c94c5 commit 860a505
Show file tree
Hide file tree
Showing 7 changed files with 734 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/adapter/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export abstract class Adapter extends events.EventEmitter<AdapterEventMap> {
zstack: ['./z-stack/adapter/zStackAdapter', 'ZStackAdapter'],
zboss: ['./zboss/adapter/zbossAdapter', 'ZBOSSAdapter'],
zigate: ['./zigate/adapter/zigateAdapter', 'ZiGateAdapter'],
zoh: ['./zoh/adapter/zohAdapter', 'ZoHAdapter'],
};
const [adapter, path] = await discoverAdapter(serialPortOptions.adapter, serialPortOptions.path);
const detectedAdapter = adapterLookup[adapter];
Expand Down
5 changes: 5 additions & 0 deletions src/adapter/adapterDiscovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,11 @@ function matchUSBFingerprint(
}

export async function matchUSBAdapter(adapter: Adapter, path: string): Promise<boolean> {
// no point in matching this
if (adapter === 'zoh') {
return false;
}

const isWindows = platform() === 'win32';
const portList = await getSerialPortList();

Expand Down
4 changes: 2 additions & 2 deletions src/adapter/socketPortUtils.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
function isTcpPath(path: string): boolean {
export function isTcpPath(path: string): boolean {
// tcp path must be:
// tcp://<host>:<port>
const regex = /^(?:tcp:\/\/)[\w.-]+[:][\d]+$/gm;
return regex.test(path);
}

function parseTcpPath(path: string): {host: string; port: number} {
export function parseTcpPath(path: string): {host: string; port: number} {
const str = path.replace('tcp://', '');
return {
host: str.substring(0, str.indexOf(':')),
Expand Down
2 changes: 1 addition & 1 deletion src/adapter/tstype.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type Adapter = 'deconz' | 'ember' | 'zstack' | 'zboss' | 'zigate' | 'ezsp';
export type Adapter = 'deconz' | 'ember' | 'zstack' | 'zboss' | 'zigate' | 'ezsp' | 'zoh';
export type DiscoverableUSBAdapter = 'deconz' | 'ember' | 'zstack' | 'zboss' | 'zigate';

export type USBAdapterFingerprint = {
Expand Down
27 changes: 27 additions & 0 deletions src/adapter/zoh/adapter/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* @param value 64-bit bigint
* @returns 16-length hex string in big-endian
*/
export function bigUInt64ToHexBE(value: bigint): string {
return value.toString(16).padStart(16, '0');
}

/**
* @param value 64-bit bigint
* @returns 8-bytelength buffer in little-endian
*/
export function bigUInt64ToBufferLE(value: bigint): Buffer {
const b = Buffer.alloc(8);
b.writeBigUInt64LE(value, 0);
return b;
}

/**
* @param value 64-bit bigint
* @returns 8-bytelength buffer in big-endian
*/
export function bigUInt64ToBufferBE(value: bigint): Buffer {
const b = Buffer.alloc(8);
b.writeBigUInt64BE(value, 0);
return b;
}
Loading

0 comments on commit 860a505

Please sign in to comment.