diff options
-rw-r--r-- | prog/fourier/.gdb_history | 7 | ||||
-rw-r--r-- | prog/fourier/.gitignore | 2 | ||||
-rw-r--r-- | prog/fourier/dft.c | 101 | ||||
-rw-r--r-- | prog/fourier/ldft.c | 8 | ||||
-rw-r--r-- | prog/inventar/.gitignore | 1 | ||||
-rw-r--r-- | prog/inventar/h.php | 8 | ||||
-rw-r--r-- | prog/inventar/index.php | 82 | ||||
-rwxr-xr-x | skripti/download-changes-to-website.sh | 2 | ||||
-rwxr-xr-x | skripti/p.py | 11 |
9 files changed, 221 insertions, 1 deletions
diff --git a/prog/fourier/.gdb_history b/prog/fourier/.gdb_history new file mode 100644 index 0000000..b3967fe --- /dev/null +++ b/prog/fourier/.gdb_history @@ -0,0 +1,7 @@ +bt +list +p najv +p val +quit +q +quit diff --git a/prog/fourier/.gitignore b/prog/fourier/.gitignore new file mode 100644 index 0000000..90989b8 --- /dev/null +++ b/prog/fourier/.gitignore @@ -0,0 +1,2 @@ +a.out +core diff --git a/prog/fourier/dft.c b/prog/fourier/dft.c new file mode 100644 index 0000000..598a7b3 --- /dev/null +++ b/prog/fourier/dft.c @@ -0,0 +1,101 @@ +// v stdin piši S8 zvočne podatke z 8000 vzorci na sekundo +// frekvence: +// 2100 Hz BAND +// 800 Hz MONI +// 1000 Hz CALL +// 1450 Hz VFO/MR +// 1750 Hz A/B +// DTMF: +// 1209 Hz 1336 Hz 1477 Hz 1633 Hz +// 697 1 2 3 A +// 770 4 5 6 B +// 852 7 8 9 C +// 941 * 0 # D +// ffmpeg -f alsa -ac 1 -i hw:5 -f s8 -ar 8000 - | ./a.out +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <complex.h> +#include <error.h> +#include <errno.h> +#include <sys/param.h> // for MIN, MAX +int main (void) { + if (setvbuf(stdout, NULL, _IOFBF, 0)) + error_at_line(1, errno, __FILE__, __LINE__, "setvbuf"); +#define SAMPLES 256 + int samples[SAMPLES] = { 0 }; + double povprečje = 0; + int frekvence[] = {1209, 1336, 1477, 1633, 697, 770, 852, 941, 2100, 800, 1000, 1450, 1750}; + #define FREKVENC 13 + // int frekvence[] = {2100, 800, 1000, 1450, 1750, 1208, 1209, 1210, 1335, 1336, 1337, 1476, 1477, 1478, 1632, 1633, 1634, 696, 697, 698, 769, 770, 771, 851, 852, 853, 940, 941, 942}; +/* #define FREKVENC 60 + int frekvence[FREKVENC+1]; + for (int i = 0; i < FREKVENC; i++) + // frekvence[i] = 1000-(FREKVENC*10/2)+i*10; + frekvence[i] = i*100; */ + complex sums[FREKVENC] = { 0 }; + unsigned sample = 0; + int received = 0; + char znak = '\0'; + while ((received = getchar()) != EOF) { + unsigned char intermed = received; + char recvd = *(char *) &intermed; + povprečje = (povprečje*SAMPLES+abs(recvd)-abs(samples[sample % SAMPLES]))/SAMPLES; + if (!(sample % SAMPLES)) + printf("\033[2J\npovprečje: %f\n", povprečje); + for (int frekvenca = 0; frekvenca < FREKVENC; frekvenca++) { +#define RATE 8000 + // sums[frekvenca] -= (complex) samples[sample % SAMPLES]*cpow(M_E, (complex) -2*M_PI*I*(complex) frekvence[frekvenca]/(complex) RATE); + sums[frekvenca] += recvd*cpow(M_E, -2*M_PI*I*frekvence[frekvenca]*sample/RATE); + sums[frekvenca] -= samples[sample % SAMPLES]*cpow(M_E, -2*M_PI*I*frekvence[frekvenca]*(sample-SAMPLES)/RATE); + if (!(sample % SAMPLES)) { + printf("%d\t", frekvence[frekvenca]); + // for (int i = 0; i < pow(cabs(sums[frekvenca])/100, 2)/100; i++) + for (int i = 0; i < cabs(sums[frekvenca])/256; i++) + printf("#"); + printf("\n"); + } + } + if (!(sample % SAMPLES)) { + int najv[3] = {0}; + double val[3] = {0}; + for (int i = 0; i < FREKVENC; i++) + for (int j = 0; j < 3; j++) + if (cabs(sums[i]) > val[j]) { + for (int k = 2; k > j; k--) { + najv[k] = najv[k-1]; + val[k] = val[k-1]; + } + najv[j] = i; + val[j] = cabs(sums[i]); + break; + } + char trenutni = '\0'; + if (val[1] > val[0]/3 && val[2] < val[1]/3) { + int večja = MAX(frekvence[najv[0]], frekvence[najv[1]]); + int manjša = MIN(frekvence[najv[0]], frekvence[najv[1]]); + char znaki[4][4] = {{'1', '2', '3', 'A'}, {'4', '5', '6', 'B'}, {'7', '8', '9', 'C'}, {'*', '0', '#', 'D'}}; + int getidx (int freq) { + int i; + for (i = 0; i < 8; i++) + if (freq == frekvence[i]) + return i%4; + return -1; + } + if (getidx(manjša) == -1 || getidx(večja) == -1) + trenutni = '\0'; + else + trenutni = znaki[getidx(manjša)][getidx(večja)]; + } + if (val[1] < val[0]/3 && najv[0] > 7) { + char znaki[] = "PSZVM"; + trenutni = znaki[najv[0]-8]; + } + if (znak == trenutni && znak) + printf("tipka: %c\n", znak); + znak = trenutni; + fflush(stdout); + } + samples[sample++ % SAMPLES] = recvd; + } +} diff --git a/prog/fourier/ldft.c b/prog/fourier/ldft.c new file mode 100644 index 0000000..1420bc8 --- /dev/null +++ b/prog/fourier/ldft.c @@ -0,0 +1,8 @@ +// lying discrete fourier transformation +// this has no mathematical proofs behind it +// key difference is that it operates in a sliding window mode without holding the window buffer itself +// instead it works in a faucet way, with a single scalar complex state for every frequency that you want to monitor stored and operates with this state one sample at a time +// absolute value of the state directly correlates with freqency domain ordinate value +// temelji na diskretni fourierjevi transformaciji in na weighted moving average +// namesto izhodnega vektorja ob množenju ... +// nvm najprej bom poizkusil narediti dft po krščansko, potem se bomo šli glupe optimizacije diff --git a/prog/inventar/.gitignore b/prog/inventar/.gitignore new file mode 100644 index 0000000..dd5199b --- /dev/null +++ b/prog/inventar/.gitignore @@ -0,0 +1 @@ +*db diff --git a/prog/inventar/h.php b/prog/inventar/h.php new file mode 100644 index 0000000..2cba303 --- /dev/null +++ b/prog/inventar/h.php @@ -0,0 +1,8 @@ +<?php +header("Content-Security-Policy: script-src 'none'"); // disable js +$db = new PDO("sqlite:db", null, null, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]); +if (!$db) + die("db: " . htmlspecialchars($e->getMessage())); +$ro = new PDO("sqlite:db", null, null, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::SQLITE_ATTR_OPEN_FLAGS => PDO::SQLITE_OPEN_READONLY]); +if (!$ro) + die("ro: " . htmlspecialchars($e->getMessage())); diff --git a/prog/inventar/index.php b/prog/inventar/index.php new file mode 100644 index 0000000..4dd38dd --- /dev/null +++ b/prog/inventar/index.php @@ -0,0 +1,82 @@ +<?php +$auth = ["test" => "test"]; +if ((isset($_REQUEST["prijava"]) && (empty($_SERVER["PHP_AUTH_USER"]) || $auth[$_SERVER['PHP_AUTH_USER']] != $_SERVER['PHP_AUTH_PW'])) || (isset($_SERVER['PHP_AUTH_USER']) && $auth[$_SERVER['PHP_AUTH_USER']] != $_SERVER['PHP_AUTH_PW'])) { + header("WWW-Authenticate: Basic realm=inventar"); + header("HTTP/1.0 401 Neprijavljen"); + die("401"); +} +?> +<style> +table, td, tr, th { + border: 1px solid red; +} +</style> +<form> +<input autofocus placeholder="where expression" name=q value="<?= htmlspecialchars($_REQUEST["q"]) ?>" /> +<input type=submit /> +</form> +<table> +<?php +if (empty($_SERVER['PHP_AUTH_USER'])) + echo "<a href=?prijava=1>prijava</a>"; +else + echo "<form method=post><input type=submit name=dodaj value='dodaj stvar kot {$_SERVER['PHP_AUTH_USER']}' /></form>"; +require_once "h.php"; +$passed = []; +if (!empty($_POST["izbriši"])) + $db->exec("delete from stvari where lastnik = '{$_SERVER["PHP_AUTH_USER"]}' and id = '{$_POST["id"]}'"); +if (!empty($_POST["dodaj"]) && !empty($_SERVER["PHP_AUTH_USER"])) + $db->exec("insert into stvari (lastnik) values ('{$_SERVER["PHP_AUTH_USER"]}')"); +foreach ($_POST as $k => $v) + if (is_numeric($k)) { + foreach ($_POST as $k2 => $v2) { + $sp = strpos($k2, $k); + if ($sp) { + $passed[] = substr($k2, 0, $sp); + } + } + $par = []; + foreach ($passed as $p) { + if (!str_contains(strtolower($p), "id")) + $par[] = "'" . SQLite3::escapeString($p) . "' = '" . SQLite3::escapeString($_POST[$p . $k]) . "'"; + } + $s = "update stvari set " . implode(", ", $par) . " where lastnik='{$_SERVER["PHP_AUTH_USER"]}' and id={$k}"; + $db->exec($s); + } +if (!empty($_REQUEST["q"])) + $ret = $ro->query("select * from stvari where " . $_REQUEST["q"]); +else + $ret = $ro->query("select * from stvari"); +$i = 0; +foreach ($ret as $row) { + if ($i == 0) + foreach ($row as $k => $v) + if ($k != "id" && !is_numeric($k)) + echo "<th>$k</th>"; + echo "<form method=post><tr>"; + foreach ($row as $k => $v) { + if ($k == "id" || is_numeric($k)) + continue; + echo "<td id=$k$i>"; + $ok = false; + foreach (["input", "name"] as $w) + if (!str_contains(strtolower($v), $w)) + $ok = true; + if ($k == "slika" && !empty($v)) + echo "<img src=$v></img>"; + if ($k == "lastnik" && $v == $_SERVER['PHP_AUTH_USER']) { + echo "<input type=submit value=shrani name={$row["id"]} />"; + echo "<input type=hidden name=id value={$row["id"]} />"; + echo "<input type=submit value=izbriši name=izbriši /></td>"; + } + $last = true; + if ($row["lastnik"] == $_SERVER['PHP_AUTH_USER'] && $k != "lastnik") { + echo "<input name=$k{$row["id"]} value=" . htmlspecialchars($v) . " />"; + $last = false; + } else + if ($last && $k != "slika") + echo "$v</td>"; + } + echo "</form></tr>"; + $i++; +} diff --git a/skripti/download-changes-to-website.sh b/skripti/download-changes-to-website.sh index 2d5dce4..6059267 100755 --- a/skripti/download-changes-to-website.sh +++ b/skripti/download-changes-to-website.sh @@ -8,6 +8,6 @@ do t=`mktemp -p "" $n.XXX` wget -O$t $1 f=`sha256sum $t | cut -d\ -f1` - mv $t $f + [ -f $f ] && rm $t || mv $t $f sleep $s done diff --git a/skripti/p.py b/skripti/p.py new file mode 100755 index 0000000..82263bc --- /dev/null +++ b/skripti/p.py @@ -0,0 +1,11 @@ +#!/usr/bin/python3 +from sys import argv +s = 0 +m = [x for x in range(3,14)] +for z in argv[1]: + x = m.pop() + s += x * int(z) +k = 11-s%11; +if k > 9: + k = 0 +print(f"{argv[1]}{k}") |