diff --git a/src/http.ts b/src/http.ts index d4f7710..9d067c9 100644 --- a/src/http.ts +++ b/src/http.ts @@ -8,7 +8,7 @@ export default class HttpServer { private httpServer: http.Server; private port: number; private root: string; - public constructor(port: number, root: string, tune: (ch: string, adp?: number) => void, getChannels: ()=>string[]) { + public constructor(port: number, root: string, tune: (ch: string, adp?: number) => void, getChannels: ()=>string[], getSignal: (adapter:number)=>object) { this.port = port; this.root = root; this.httpServer = http.createServer((req, res) => { @@ -27,6 +27,11 @@ export default class HttpServer { body = JSON.stringify(getChannels()); status = 200; break; + case "signal": + const adapter = parseInt(url.searchParams.get('adapter')); + body = JSON.stringify(getSignal(adapter)); + status = 200; + break; } break; diff --git a/src/server.ts b/src/server.ts index 39f6964..17cecfc 100644 --- a/src/server.ts +++ b/src/server.ts @@ -23,7 +23,10 @@ const tune = (reqChannel: string, reqAdapter?: number) => { const getChannels = () => zap.getChannels(); -const httpServer = new HttpServer(HTTP_PORT, STATIC_ROOT, tune, getChannels); +const getSignal = (adapter: number) => + zap.getSignal(adapter) + +const httpServer = new HttpServer(HTTP_PORT, STATIC_ROOT, tune, getChannels, getSignal); const tvWebSocket0 = new TVWebSocket(WS_PORT, TV_DEV_0); const tvWebSocket1 = new TVWebSocket(WS_PORT + 1, TV_DEV_1); httpServer.start(); diff --git a/src/static/css/index.scss b/src/static/css/index.scss index a2db5ac..700d609 100644 --- a/src/static/css/index.scss +++ b/src/static/css/index.scss @@ -26,6 +26,8 @@ body { display: flex; flex-direction: column; text-align: center; + align-items: center; + justify-content: center; h1 {} p {} @@ -35,7 +37,7 @@ body { } .content{ display: flex; - flex-direction: column; + flex-direction: row; gap: 1em; .player{ diff --git a/src/static/index.html b/src/static/index.html index 516f991..6675c38 100644 --- a/src/static/index.html +++ b/src/static/index.html @@ -18,12 +18,17 @@
+

N/A

+
+

N/A

+ +
diff --git a/src/static/js/doc.ts b/src/static/js/doc.ts index 4289e85..aeb66bc 100644 --- a/src/static/js/doc.ts +++ b/src/static/js/doc.ts @@ -1,53 +1,61 @@ const PLAYERS = 2; -const populateChannels = (players:number) => { +const populateChannels = (players: number) => { fetch('/api/list').then(async (res) => { const channelNames: string[] = await res.json() - - - for(let i = 0; i < players; ++i){ + + + for (let i = 0; i < players; ++i) { const radioGroup = document.getElementById(`channel-container-${i}`); if (!radioGroup) { throw new Error("Radio group not found") } radioGroup.innerHTML = '' - channelNames.forEach((channelName,_) => { - const id = `radio-${channelName}`; - + channelNames.forEach((channelName, _) => { + const id = `radio-${i}-${channelName}`; + const input = document.createElement('input'); input.type = "radio" input.name = `channel-radio-${i}`; - input.value = channelName; + input.value = `${channelName}`; input.id = id - - + const lbl = document.createElement("label"); lbl.htmlFor = id; lbl.textContent = channelName; - - // Wrap in a div or line + const wrapper = document.createElement("div"); wrapper.appendChild(input); wrapper.appendChild(lbl); - - - + radioGroup.appendChild(wrapper) }) } - + }).catch(err => { - console.log("nope ",err) + console.log("nope ", err) }) } -const tune = (adapter=0) =>{ +const tune = (adapter = 0) => { const choice = document.querySelector(`input[name="channel-radio-${adapter}"]:checked`) const channel = choice?.value; - if(channel){ - fetch(`/api/tune/${channel}?adapter=${adapter}`, {method:'PUT'}) + if (channel) { + fetch(`/api/tune/${channel}?adapter=${adapter}`, { method: 'PUT' }) } - + +} + +const getSignal = (adapter = 0) => { + const signalElement = document.getElementById(`signal-${adapter}`); + if (!signalElement) { + return; + } + fetch(`/api/signal?adapter=${adapter}`).then(res => + res.json() + ).then((strength: any) => { + signalElement.innerHTML = `Signal: ${strength.signal} C/N: ${strength.cn}` + }) } populateChannels(PLAYERS); \ No newline at end of file diff --git a/src/zap.ts b/src/zap.ts index 686ebad..11397b0 100644 --- a/src/zap.ts +++ b/src/zap.ts @@ -5,6 +5,10 @@ export interface IZap { process: ChildProcessWithoutNullStreams | null, channel: string, adapter: 0 | 1 + strength: { + signal: string; + cn: string; + }, } export default class Zap { @@ -12,16 +16,28 @@ export default class Zap { private zap1: IZap; private channelNameList: string[]; private fileName: string; + + private regex = /Signal=\s*(-?\d+(\.\d+)?dBm)\s+C\/N=\s*(\d+(\.\d+)?dB)/; + + public constructor(fileName = "dvb_channel.conf", channel = "ION") { const zap0: IZap = { process: null, channel, - adapter: 0 + adapter: 0, + strength: { + signal: "None", + cn: "None" + } } const zap1: IZap = { process: null, channel, - adapter: 1 + adapter: 1, + strength: { + signal: "None", + cn: "None" + } } this.zap0 = zap0; this.zap1 = zap1; @@ -37,6 +53,18 @@ export default class Zap { return this.channelNameList; } + public getSignal(adapter: number) { + if(adapter == 0){ + return this.zap0.strength; + } + else if (adapter == 1){ + return this.zap1.strength; + } + else { + return {signal: 'N/A', cn: 'N/A'} + } + } + private nextChannel(channel: string) :string { const size = this.channelNameList.length; const currentIndex = this.channelNameList.indexOf(channel); @@ -108,7 +136,12 @@ export default class Zap { if (/Lock/.test(output)) { clearTimeout(lockTimer); + const match = output.match(this.regex); zap.channel = verifiedChannel; + zap.strength = { + signal: match[1], + cn: match[3] + } resolve(zap); }