make it so

This commit is contained in:
2017-10-10 16:30:00 +02:00
commit 36a526a95b
5 changed files with 59 additions and 0 deletions

15
README.md Normal file
View File

@@ -0,0 +1,15 @@
# morse
Morse Code through CPU utilization.
## Usage
The API exposes two simple functions, `dit` and `dah`. `dit` will utilize the
CPU for a second, `dah` will sleep. Knowing this, we can exchange information
by looking at the programs CPU utilization every second. A simple POC is
included in `main.c` and `observe.sh`. Its really, really crude. For best
results, compile without optimizations.
<hr/>
Have fun!

11
main.c Normal file
View File

@@ -0,0 +1,11 @@
#include "morse.h"
int main() {
dit();
dah();
dit();
dit();
dah();
dit();
return 0;
}

15
observe.sh Executable file
View File

@@ -0,0 +1,15 @@
PID=$1
RET=0
while [ "$RET" == 0 ]; do
INP=`ps -o pcpu -p $PID`
RET=$?
ARR=($INP)
echo ${ARR[1]}
if [ `echo "${ARR[1]}"'>'50 | bc -l` == 1 ]; then
echo dit
else
echo dah
fi
sleep 1
done

13
src/morse.c Normal file
View File

@@ -0,0 +1,13 @@
#include "morse.h"
void dit() {
time_t t0, t1;
time(&t0);
t1 = t0;
while(difftime(t1, t0) < 1) time(&t1);
}
void dah() {
sleep(1);
}

5
src/morse.h Normal file
View File

@@ -0,0 +1,5 @@
#include <time.h>
#include <unistd.h>
void dit();
void dah();