Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Frequency sweeping application created

  • Loading branch information...
commit 0a7323355b4ac629e20112774c0ec4c3a6a06f81 1 parent f3a9c9b
@anroOfCode authored
View
3  android/core-lib/AndroidManifest.xml
@@ -3,8 +3,9 @@
android:versionCode="1"
android:versionName="1.0">
- <uses-sdk android:minSdkVersion="10" android:targetSdkVersion="15" />
+ <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="15" />
+ <uses-permission android:name="android.permission.RECORD_AUDIO" />
<application android:label="@string/app_name"
android:icon="@drawable/ic_launcher"
android:theme="@style/AppTheme">
View
2  android/core-lib/src/umich/framjack/core/AudioReceiver.java
@@ -168,7 +168,7 @@ else if (!isHigh[currentBit] && isHigh[currentBit+1]) {
// Toss the power signal on there. We keep a running signal across calls to this function
// with the _powerFrequencyPos var to ensure the wave is continuous.
_stereoBuffer[i*2+1] = (short) boundToShort(
- Math.sin(powerMutiplier * _powerFrequencyPos++) * 32786
+ Math.sin(powerMutiplier * _powerFrequencyPos++) * 32760
);
}
View
4 android/core-lib/src/umich/framjack/core/SerialDecoder.java
@@ -194,6 +194,10 @@ public int readByte() {
}
}
+ public void setFreq(int freq) {
+ _audioReceiver.setPowerFrequency(freq);
+ }
+
/////////////////////////////
// Listener Functions
/////////////////////////////
View
4 android/freqSweep-app/AndroidManifest.xml
@@ -4,9 +4,11 @@
android:versionName="1.0" >
<uses-sdk
- android:minSdkVersion="8"
+ android:minSdkVersion="14"
android:targetSdkVersion="15" />
+ <uses-permission android:name="android.permission.RECORD_AUDIO" />
+
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
View
1  android/freqSweep-app/project.properties
@@ -12,3 +12,4 @@
# Project target.
target=android-16
+android.library.reference.1=../core-lib
View
79 android/freqSweep-app/res/layout/activity_main.xml
@@ -1,14 +1,79 @@
-<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
- android:layout_height="match_parent" >
+ android:layout_height="match_parent"
+ android:orientation="vertical" >
<TextView
+ android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_centerHorizontal="true"
- android:layout_centerVertical="true"
- android:text="@string/hello_world"
- tools:context=".MainActivity" />
+ android:text="Start Frequency"
+ android:textAppearance="?android:attr/textAppearanceLarge" />
-</RelativeLayout>
+ <EditText
+ android:id="@+id/startFreq"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:inputType="phone"
+ android:text="20"
+ android:ems="10" />
+
+ <TextView
+ android:id="@+id/textView2"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="End Frequency"
+ android:textAppearance="?android:attr/textAppearanceLarge" />
+
+ <EditText
+ android:id="@+id/endFreq"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:inputType="phone"
+ android:text="21000"
+ android:ems="10" />
+
+ <TextView
+ android:id="@+id/textView2"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="Step (ms) (enter 0 for manual)"
+ android:textAppearance="?android:attr/textAppearanceLarge" />
+
+ <EditText
+ android:id="@+id/stepMs"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:inputType="phone"
+ android:text="500"
+ android:ems="10" />
+
+ <TextView
+ android:id="@+id/textView2"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="Step (Hz)"
+ android:textAppearance="?android:attr/textAppearanceLarge" />
+
+ <EditText
+ android:id="@+id/stepHz"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:inputType="phone"
+ android:text="1000"
+ android:ems="10" />
+
+ <Button
+ android:id="@+id/button1"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="Start" />
+
+ <Button
+ android:id="@+id/button2"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="Step" />
+
+</LinearLayout>
View
2  android/freqSweep-app/res/values/strings.xml
@@ -3,6 +3,6 @@
<string name="app_name">FreqSweep</string>
<string name="hello_world">Hello world!</string>
<string name="menu_settings">Settings</string>
- <string name="title_activity_main">MainActivity</string>
+ <string name="title_activity_main">FreqSweep</string>
</resources>
View
154 android/freqSweep-app/src/umich/framjack/apps/freqsweep/MainActivity.java
@@ -1,18 +1,172 @@
package umich.framjack.apps.freqsweep;
+import umich.framjack.core.FramingEngine;
+import umich.framjack.core.OnByteSentListener;
+import umich.framjack.core.OnBytesAvailableListener;
+import umich.framjack.core.SerialDecoder;
+import umich.framjack.core.FramingEngine.IncomingPacketListener;
+import umich.framjack.core.FramingEngine.OutgoingByteListener;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+import android.widget.EditText;
public class MainActivity extends Activity {
+ private SerialDecoder _serialDecoder;
+ private FramingEngine _framer;
+
+ private boolean _nextFlag = false;
+
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
+
+ _framer = new FramingEngine();
+ _serialDecoder = new SerialDecoder();
+
+ _serialDecoder.registerBytesAvailableListener(_bytesAvailableListener);
+ _serialDecoder.registerByteSentListener(_byteSentListener);
+ _framer.registerIncomingPacketListener(_incomingPacketListener);
+ _framer.registerOutgoingByteListener(_outgoingByteListener);
+
+ final Button b1 = (Button)findViewById(R.id.button1);
+ b1.setOnClickListener(new View.OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ EditText startFreqEditText = (EditText)findViewById(R.id.startFreq);
+ EditText endFreqEditText = (EditText)findViewById(R.id.endFreq);
+ EditText msStepEditText = (EditText)findViewById(R.id.stepMs);
+ EditText hzStepEditText = (EditText)findViewById(R.id.stepHz);
+
+ final int startFreq = Integer.parseInt(startFreqEditText.getText().toString());
+ final int endFreq = Integer.parseInt(endFreqEditText.getText().toString());
+ final int msStep = Integer.parseInt(msStepEditText.getText().toString());
+ final int hzStep = Integer.parseInt(hzStepEditText.getText().toString());
+
+ b1.setText("Running...");
+
+ Thread t = new Thread(new Runnable() {
+ @Override
+ public void run() {
+ int currentFreq = startFreq;
+
+ while (currentFreq <= endFreq) {
+ _serialDecoder.setFreq(currentFreq);
+ currentFreq += hzStep;
+
+ if (msStep == 0) {
+ while (!_nextFlag) {
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+
+ _nextFlag = false;
+ }
+ else {
+ try {
+ Thread.sleep(msStep);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ MainActivity.this.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ b1.setText("Start");
+ }
+ });
+ }
+ });
+
+ t.start();
+ }
+ });
+
+ final Button b2 = (Button)findViewById(R.id.button2);
+ b2.setOnClickListener(new OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ _nextFlag = true;
+ }
+ });
}
@Override
+ public void onPause() {
+ _serialDecoder.stop();
+ super.onPause();
+ }
+
+ @Override
+ public void onResume() {
+ _serialDecoder.start();
+ super.onResume();
+ }
+
+ ///////////////////////////////////////////////
+ // Listeners
+ ///////////////////////////////////////////////
+ private OutgoingByteListener _outgoingByteListener = new OutgoingByteListener() {
+ public void OutgoingByteTransmit(int[] outgoingRaw) {
+ synchronized (MainActivity.this) {
+ //_pendingTransmitBytes += outgoingRaw.length;
+ }
+
+ for (int i = 0; i < outgoingRaw.length; i++) {
+ _serialDecoder.sendByte(outgoingRaw[i]);
+ }
+ }
+ };
+
+ private IncomingPacketListener _incomingPacketListener = new IncomingPacketListener() {
+ public void IncomingPacketReceive(int[] packet) {
+ for (int i = 0; i < packet.length; i++) {
+ System.out.print(Integer.toHexString(packet[i]) + " ");
+ }
+ System.out.println();
+ //decodeAndUpdate(packet);
+ }
+ };
+
+ private OnByteSentListener _byteSentListener = new OnByteSentListener() {
+ public void onByteSent() {
+ synchronized (MainActivity.this) {
+ //_pendingTransmitBytes--;
+ //if (_pendingTransmitBytes == 0) {
+ // int[] toSend = encode();
+ // for (int i = 0; i < toSend.length; i++) {
+ // _framer.transmitByte(toSend[i]);
+ // }
+ // _framer.transmitEnd();
+ //}
+ }
+ }
+ };
+
+ private OnBytesAvailableListener _bytesAvailableListener = new OnBytesAvailableListener() {
+ public void onBytesAvailable(int count) {
+ while(count > 0) {
+ int byteVal = _serialDecoder.readByte();
+ //System.out.println("Received: " + byteVal);
+ _framer.receiveByte(byteVal);
+ count--;
+ }
+ }
+ };
+
+ @Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
View
2  android/rpc-app/src/umich/framjack/ApplicationInterface.java
@@ -49,7 +49,6 @@ public ApplicationInterface() {
_framer = new FramingEngine();
_serialDecoder = new SerialDecoder();
-
_serialDecoder.registerBytesAvailableListener(_bytesAvailableListener);
_serialDecoder.registerByteSentListener(_byteSentListener);
_framer.registerIncomingPacketListener(_incomingPacketListener);
@@ -60,7 +59,6 @@ public ApplicationInterface() {
_framer.transmitByte(toSend[i]);
}
_framer.transmitEnd();
-
}
///////////////////////////////////////////////
Please sign in to comment.
Something went wrong with that request. Please try again.