make it so
This commit is contained in:
15
README.md
Normal file
15
README.md
Normal 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 program’s CPU utilization every second. A simple POC is
|
||||||
|
included in `main.c` and `observe.sh`. It’s really, really crude. For best
|
||||||
|
results, compile without optimizations.
|
||||||
|
|
||||||
|
<hr/>
|
||||||
|
|
||||||
|
Have fun!
|
11
main.c
Normal file
11
main.c
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#include "morse.h"
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
dit();
|
||||||
|
dah();
|
||||||
|
dit();
|
||||||
|
dit();
|
||||||
|
dah();
|
||||||
|
dit();
|
||||||
|
return 0;
|
||||||
|
}
|
15
observe.sh
Executable file
15
observe.sh
Executable 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
13
src/morse.c
Normal 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
5
src/morse.h
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
#include <time.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
void dit();
|
||||||
|
void dah();
|
Reference in New Issue
Block a user