#!/bin/sh

# A script to produce small modulations of environmental monitors

addr_lst="0x110 0x112 0x113 0x114 0x115 0x11a 0x11d 0x11e"
declare -a loc step

step=(10 -4 9 -2 5 6 7 8 2 2 3 5 6 7 2 1 100 1 2)
sign=1

step_len=${#step[*]}
k=0
cp mem0.dat mem1.dat
while true; do
  for addr in $addr_lst; do
    loc=(`grep $addr mem1.dat`)
    let newval=${loc[1]}+${step[k]}*$sign
    let k=($k+1)%$step_len
    sed -e "s/${loc[0]} ${loc[1]}/$addr $newval/" mem1.dat > mem2.dat
    mv mem2.dat mem1.dat
  done
  let sign=-$sign
  cp mem1.dat mem.dat
  sleep 1
done
