https://wiki.gumstix.com/api.php?action=feedcontributions&user=JustinC474&feedformat=atomGumstix User Wiki - User contributions [en]2024-03-28T20:38:20ZUser contributionsMediaWiki 1.25.3https://wiki.gumstix.com/index.php?title=How_to_connect_Palo35&diff=5257How to connect Palo352011-03-23T19:28:32Z<p>JustinC474: /* The Palo35 LCD Connector */</p>
<hr />
<div>==The Palo35 LCD Connector==<br />
<br />
[[http://wiki.gumstix.org/images/0/04/Palo35-2.jpg Pull up the black lock mechanism]] of the LCD connector on the Palo35 (it rotates up), insert the flexible printed circuit from the LCD display into the connector, and finally [[http://wiki.gumstix.org/images/4/46/Palo35-1.jpg push the black mechanism down]] to lock connector. The orientation of the display relative to the board during installation is the same as shown in the Palo43 LCD installation.<br />
<br />
The lock is on the opposite side, and the mechanism is different from the Palo43. Instead of "pulling it out" like in the palo43, you have to pull the lock away from the board (i.e., up if the board is laying flat on a table). The lock hinges on the sides and rotates up. Once it is up you can insert the FPC cable on the other side of the connector, and it does require some force to get it in. Try holding the FPC cable against the board while pushing it in to prevent it from flexing. Pushing the lock down once the FPC cable is in requires some force.<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
[[Category:Connect_hardware]]<br />
[[Category:How_to_-_LCD]]<br />
[[Category:How_to_-_displays]]<br />
[[Category:How_to_-_expansion_boards]]</div>JustinC474https://wiki.gumstix.com/index.php?title=How_to_connect_Palo35&diff=5256How to connect Palo352011-03-23T19:27:43Z<p>JustinC474: /* The Palo35 LCD Connector */</p>
<hr />
<div>==The Palo35 LCD Connector==<br />
<br />
[[http://wiki.gumstix.org/images/0/04/Palo35-2.jpg Pull up the black lock mechanism]] of the LCD connector on the Palo35 (it rotates up), insert the flexible printed circuit from the LCD display into the connector, and finally [[http://www.gumstix.net/wiki/images/4/46/Palo35-1.jpg push the black mechanism down]] to lock connector. The orientation of the display relative to the board during installation is the same as shown in the Palo43 LCD installation.<br />
<br />
The lock is on the opposite side, and the mechanism is different from the Palo43. Instead of "pulling it out" like in the palo43, you have to pull the lock away from the board (i.e., up if the board is laying flat on a table). The lock hinges on the sides and rotates up. Once it is up you can insert the FPC cable on the other side of the connector, and it does require some force to get it in. Try holding the FPC cable against the board while pushing it in to prevent it from flexing. Pushing the lock down once the FPC cable is in requires some force.<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
[[Category:Connect_hardware]]<br />
[[Category:How_to_-_LCD]]<br />
[[Category:How_to_-_displays]]<br />
[[Category:How_to_-_expansion_boards]]</div>JustinC474https://wiki.gumstix.com/index.php?title=File:Palo35-2.jpg&diff=5255File:Palo35-2.jpg2011-03-23T19:24:57Z<p>JustinC474: uploaded a new version of &quot;File:Palo35-2.jpg&quot;</p>
<hr />
<div></div>JustinC474https://wiki.gumstix.com/index.php?title=File:Palo35-1.jpg&diff=5254File:Palo35-1.jpg2011-03-23T19:23:17Z<p>JustinC474: uploaded a new version of &quot;File:Palo35-1.jpg&quot;</p>
<hr />
<div></div>JustinC474https://wiki.gumstix.com/index.php?title=User_talk:Olivlogol&diff=4702User talk:Olivlogol2010-10-26T18:20:54Z<p>JustinC474: Blanked the page</p>
<hr />
<div></div>JustinC474https://wiki.gumstix.com/index.php?title=VerdexPro_U-Boot_Flashing_Fix&diff=4697VerdexPro U-Boot Flashing Fix2010-10-21T21:39:34Z<p>JustinC474: /* Fix Details */</p>
<hr />
<div>== PKI 2010-3 (Product Known Issue) ==<br />
Gumstix created Known Issue PKI 2010-3 in September 2010 because the Numonyx NOR flash memory that Gumstix installed on a small quantity of Verdex Pro XL6P COMs in August 2010, as well as the inventory of Numonyx NOR flash memory that Gumstix has in stock for future builds, show errors when written from u-boot.<br />
<br />
See Gumstix PKI 2010-3 posted [http://www.gumstix.net/Hardware/cat/Known-issues/112.html#faq206 here].<br />
<br />
===Description===<br />
Since the lead time on this Numonyx NOR flash memory has shot out to 6 months, Gumstix could not source replacement memory modules in a timely manner from Numonyx in order to provide a rapid hardware fix.<br />
<br />
So, Gumstix Engineering has endeavoured to develop a software fix so that the recently shipped Verdex Pro XL6P COMs and the current inventory of NOR flash memory can become functional. <br />
<br />
<br />
=== Symptoms ===<br />
This faulty Numonyx NOR flash memory report errors when written from u-boot; this is due to an error in the Numonyx NOR flash memory itself.<br />
<br />
Usually, users discover this problem when trying to replace the [http://www.gumstix.net/Setup-and-Programming/view/Getting-started/Replacing-the-file-system-image/111.html file system image]. U-boot might report any or all of these message after a copy to flash command:<br />
<code><br />
GUM> '''cp.b a2000000 40000 ${filesize}'''<br />
Flash buffer write error at address 40000<br />
Command Sequence Error.<br />
Block locked.<br />
Vpp Low Error.<br />
</code><br />
<br />
=== Affected Parts ===<br />
Verdex Pro XL6P COMs of build R2635 with Numonyx NOR flash memory (U$2) marked 256PF30TF as opposed to 256PF30T likely have this fault. Note, not all memory pages in the flash memory are necessarily affected. More details about affected parts can be found [http://www.gumstix.net/Hardware/cat/Known-issues/112.html#faq206 here]. <br />
<br />
While any software that modifies the block protection status of the Numonyx NOR flash memory is potentially susceptible to this hardware bug, we have only noticed the issue in u-boot.<br />
<br />
==Resolution==<br />
By following the information below, a user can install a new version of u-boot to the NOR Flash memory.<br />
<br />
Please note that this fix <b>slows down writes to flash within u-boot by a factor of 20</b> Note that this fix does NOT affect write performance in Linux.<br />
<br />
Until further testing and customer feedback is received, this resolution is NOT considered to be a final answer to PKI 2010-3 by Gumstix.<br />
<br />
=== Fix Details ===<br />
<br />
The manufacturer [http://www.numonyx.com/Documents/Specification%20Updates/509003_P3X_65nm_3V_256Mbit_Discrete.pdf notes] that the block protection status is incorrectly set when software tries to unlock a flash block. By changing the block locking command sequence as shown in this [http://git.denx.de/?p=u-boot/u-boot-cfi-flash.git;a=commit;h=54652991caedc39b2ec2e5b49e750669bfcd1e2e fix], the silicon behaves correctly. In addition, it is necessary to disable the buffered write mode; '''this slows down writes to flash within u-boot by a factor of 20.'''<br />
This [http://dl.dropbox.com/u/211887/numonyx-256P30TF.patch patch] applies against Verdex Pro u-boot revision 1.2.0.<br />
<br />
As an FYI, unless you need to change the software running in flash memory, it is not necessary to apply this fix---it only affects re-flashing code in u-boot.<br />
<br />
=== Usage ===<br />
Caveats:<br />
* Installing a new version of u-boot to your Flash memory is risky and, if not done correctly, can result in your Verdex Pro XL6P COM being bricked. Proceed with caution.<br />
* This fix will slow down writes to flash within u-boot by a factor of 20<br />
<br />
Download a patched version of u-boot. Most users will want the standard u-boot; for those using the git repository or having a kernel larger than 1MB might want the large kernel version ([http://old.nabble.com/Buildable-U-boot-available-for-VerdexPRO-td28298831.html see] for more details).<br />
{| border="1" cellspacing="0"<br />
! Note !! File !! MD5 <br />
|-<br />
| Standard (katload 100000) || [http://dl.dropbox.com/u/211887/u-boot-verdex600-256P30TF-standard.bin u-boot.bin] || 8f7f905549cd3ba7f2e6a755395e7e16<br />
|-<br />
| Large Kernel (katload 160000) || [http://dl.dropbox.com/u/211887/u-boot-verdex600-256P30TF.bin u-boot.bin] || 55e999c2bb21a5b963473f213c3911cc<br />
|}<br />
<br />
Follow the instructions [http://www.gumstix.net/Setup-and-Programming/view/Developer-how-to-s/Reflashing-using-a-serial-connection/111.html here] to get a serial connection to your Verdex Pro XL6P COM.<br />
<br />
Type these commands to load the new u-boot to RAM and jump to it. This new u-boot will allow you to write to NAND:<br />
<code><br />
GUM> '''loadb a2000000'''<br />
'''CTRL+\, c'''<br />
C-Kermit> '''send u-boot.bin''' (this should be the file you downloaded)<br />
...tranfer for about 20 seconds...<br />
C-Kermit> '''connect'''<br />
GUM> '''go a2000000'''<br />
U-Boot 1.2.0 (Oct 6 2010 - 00:42:27) - PXA270@600 MHz - <br />
<br />
*** Welcome to Gumstix ***<br />
<br />
DRAM: 128 MB<br />
Flash: 32 MB<br />
Using default environment<br />
</code><br />
Test that your new u-boot is working correctly by writing to a non-boot partitions. For example,<br />
<code><br />
GUM> '''protect off 1:2-3'''<br />
Un-Protect Flash Sectors 2-3 in Bank # 1<br />
.. done<br />
GUM> '''erase 1:2-3'''<br />
Erase Flash Sectors 2-3 in Bank # 1 <br />
.. done<br />
GUM> '''loadb a2000000'''<br />
'''CTRL+\, c'''<br />
C-Kermit> '''send u-boot.bin''' (this should be the file you downloaded)<br />
...tranfer for about 20 seconds...<br />
C-Kermit> '''connect'''<br />
GUM> '''cp.b a2000000 40000 ${filesize}'''<br />
Copy to Flash... done<br />
</code><br />
If everything went smoothly in the previous step, the new uboot is working. Let's ''carefully'' reflash the boot partition with the same steps but for sector 1:0-1 (0x0) rather than sector 1:2-3 (0x00040000):<br />
<code><br />
GUM> '''protect off 1:0-1'''<br />
Un-Protect Flash Sectors 0-1 in Bank # 1<br />
.. done<br />
GUM> '''erase 1:0-1'''<br />
Erase Flash Sectors 0-1 in Bank # 1 <br />
.. done<br />
GUM> '''loadb a2000000'''<br />
'''CTRL+\, c'''<br />
C-Kermit> '''send u-boot.bin''' (this should be the file you downloaded)<br />
...tranfer for about 20 seconds...<br />
C-Kermit> '''connect'''<br />
GUM> '''cp.b a2000000 0 ${filesize}'''<br />
Copy to Flash... done<br />
GUM> '''reset'''<br />
</code><br />
The Verdex Pro XL6P COM should now boot into the new u-boot and the ''protect'', ''erase'', and ''cp.b'' commands should behave correctly albeit slowly.<br />
<br />
== Notes ==<br />
<br />
* Please contact ash (at) gumstix.com in case of problems with this procedure.</div>JustinC474https://wiki.gumstix.com/index.php?title=HelloWorld&diff=4556HelloWorld2010-08-06T21:31:06Z<p>JustinC474: /* C++ */</p>
<hr />
<div>This page will provide sample code for writing, compiling, and running HelloWorld in Python and C++ on your Overo COM. To do this it will be assumed you have Console access to your Overo.<br />
<br />
==Python==<br />
To start writing HelloWorld in Python, issue the following command<br />
nano HelloWorld.py<br />
This command opens a text editor nano, which allows you to edit the text in files. In this specific case, it is opening the file HelloWorld.py. If this file has existed before, it would have opened the existing file. However, since it did not, nano opens a new text file with if saved, will be saved as HelloWorld.py.<br />
Write the following code in the file:<br />
print "Hello, Gumstix!"<br />
To write the file (save it) press: <br><br />
Ctrl + O <br><br />
Then to quit back to the command line, press: <br><br />
Ctrl + X <br><br />
And finally, issue this command to run the program:<br />
python HelloWorld.py<br />
The program should output: <br />
Hello Gumstix! <br />
Congratulations! You have programmed your first Python program on your Overo. You may re-open HelloWorld.py using the nano command to change the outgoing text to whatever you would like.<br />
<br />
==C++==<br />
C and C++ code requires compilation which can be done natively---on the Gumstix itself---or on a development machine using a cross-compiler. To do native compilation, you need to install a compiler as well as any required libraries. You'll need to be booting from a microSD card as this installation takes approximately 75MB of space.<br />
opkg update<br />
opkg install task-native-sdk<br />
----<br />
NOTE: Installing task-native-sdk can take 45 minutes to two hours. To do this you will need an active internet connection on your Overo COM<br />
----<br />
<br />
Once you have an environment that is capable of compiling and executing a C++ file, you need to write the file. First, lets write a C++ file. To open a text editor, issue the command:<br />
nano HelloWorld.cpp<br />
Once in the file, copy the following code to make HelloWorld in C++<br />
#include <iostream><br />
using namespace std;<br />
int main () {<br />
cout << "Gumstix runs on C++" << endl;<br />
return 0;<br />
}<br />
Then write the file and exit back to the command line with: <br><br />
Ctrl + O<br />
Ctrl + X<br />
<br />
Next, to compile the program, issue the command:<br />
g++ -o HelloWorld HelloWorld.cpp<br />
This creates an executable object (HelloWorld) by using the g++ compiler on the C++ file HelloWorld.cpp.<br />
Then, run the program using the command:<br />
./HelloWorld<br />
This tells the computer to execute a file named HelloWorld located in the current directory (./). The outputs should be: <br><br />
Gumstix runs on C++<br />
Congratulations! You have successfully written your first C++ program on your Overo COM!<br />
<br />
==C==<br />
Since C is very similar to C++, the following instructions will be very similar to the C++ instructions. If you have already followed the instructions The differences are:<br />
#HelloWorld.cpp becomes HelloWorld.c<br />
#The code is different<br />
#g++ becomes gcc<br />
The rest is the same. Below is the exact same instructions, just modified for writing, compiling and executing a C file.<br />
<br />
C and C++ code requires compilation which can be done natively---on the Gumstix itself---or on a development machine using a cross-compiler. To do native compilation, you need to install a compiler as well as any required libraries. You'll need to be booting from a microSD card as this installation takes approximately 75MB of space.<br />
opkg update<br />
opkg install task-native-sdk<br />
----<br />
NOTE: Installing task-native-sdk can take 45 minutes to two hours. To do this you will need an active internet connection on your Overo COM<br />
----<br />
<br />
Once you have an environment that is capable of compiling and executing a C file, you need to write the file. First, lets write a C file. To open a text editor, issue the command:<br />
nano HelloWorld.c<br />
Once in the file, copy the following code to make HelloWorld in C<br />
#include <stdio.h><br />
int main () {<br />
printf("Gumstix runs on C\n");<br />
return 0;<br />
}<br />
Then write the file and exit back to the command line with: <br><br />
Ctrl + O<br />
Ctrl + X<br />
<br />
Next, to compile the program, issue the command:<br />
gcc -o HelloWorld HelloWorld.c<br />
This creates an executable object (HelloWorld) by using the gcc compiler on the C file HelloWorld.c.<br />
Then, run the program using the command:<br />
./HelloWorld<br />
This tells the computer to execute a file named HelloWorld located in the current directory (./). The outputs should be: <br><br />
Gumstix runs on C<br />
Congratulations! You have successfully written your first C program on your Overo COM!</div>JustinC474https://wiki.gumstix.com/index.php?title=HelloWorld&diff=4555HelloWorld2010-08-06T21:30:52Z<p>JustinC474: /* C */</p>
<hr />
<div>This page will provide sample code for writing, compiling, and running HelloWorld in Python and C++ on your Overo COM. To do this it will be assumed you have Console access to your Overo.<br />
<br />
==Python==<br />
To start writing HelloWorld in Python, issue the following command<br />
nano HelloWorld.py<br />
This command opens a text editor nano, which allows you to edit the text in files. In this specific case, it is opening the file HelloWorld.py. If this file has existed before, it would have opened the existing file. However, since it did not, nano opens a new text file with if saved, will be saved as HelloWorld.py.<br />
Write the following code in the file:<br />
print "Hello, Gumstix!"<br />
To write the file (save it) press: <br><br />
Ctrl + O <br><br />
Then to quit back to the command line, press: <br><br />
Ctrl + X <br><br />
And finally, issue this command to run the program:<br />
python HelloWorld.py<br />
The program should output: <br />
Hello Gumstix! <br />
Congratulations! You have programmed your first Python program on your Overo. You may re-open HelloWorld.py using the nano command to change the outgoing text to whatever you would like.<br />
<br />
==C++==<br />
C and C++ code requires compilation which can be done natively---on the Gumstix itself---or on a development machine using a cross-compiler. To do native compilation, you need to install a compiler as well as any required libraries. You'll need to be booting from a microSD card as this installation takes approximately 75MB of space.<br />
echo 'src/gz angstrom-base http://www.angstromdistribution.org/feeds/unstable/ipk/glibc/armv7a/base' > /etc/opkg/angstrom-base.conf<br />
opkg update<br />
opkg install task-native-sdk<br />
----<br />
NOTE: Installing task-native-sdk can take 45 minutes to two hours. To do this you will need an active internet connection on your Overo COM<br />
----<br />
<br />
Once you have an environment that is capable of compiling and executing a C++ file, you need to write the file. First, lets write a C++ file. To open a text editor, issue the command:<br />
nano HelloWorld.cpp<br />
Once in the file, copy the following code to make HelloWorld in C++<br />
#include <iostream><br />
using namespace std;<br />
int main () {<br />
cout << "Gumstix runs on C++" << endl;<br />
return 0;<br />
}<br />
Then write the file and exit back to the command line with: <br><br />
Ctrl + O<br />
Ctrl + X<br />
<br />
Next, to compile the program, issue the command:<br />
g++ -o HelloWorld HelloWorld.cpp<br />
This creates an executable object (HelloWorld) by using the g++ compiler on the C++ file HelloWorld.cpp.<br />
Then, run the program using the command:<br />
./HelloWorld<br />
This tells the computer to execute a file named HelloWorld located in the current directory (./). The outputs should be: <br><br />
Gumstix runs on C++<br />
Congratulations! You have successfully written your first C++ program on your Overo COM!<br />
<br />
==C==<br />
Since C is very similar to C++, the following instructions will be very similar to the C++ instructions. If you have already followed the instructions The differences are:<br />
#HelloWorld.cpp becomes HelloWorld.c<br />
#The code is different<br />
#g++ becomes gcc<br />
The rest is the same. Below is the exact same instructions, just modified for writing, compiling and executing a C file.<br />
<br />
C and C++ code requires compilation which can be done natively---on the Gumstix itself---or on a development machine using a cross-compiler. To do native compilation, you need to install a compiler as well as any required libraries. You'll need to be booting from a microSD card as this installation takes approximately 75MB of space.<br />
opkg update<br />
opkg install task-native-sdk<br />
----<br />
NOTE: Installing task-native-sdk can take 45 minutes to two hours. To do this you will need an active internet connection on your Overo COM<br />
----<br />
<br />
Once you have an environment that is capable of compiling and executing a C file, you need to write the file. First, lets write a C file. To open a text editor, issue the command:<br />
nano HelloWorld.c<br />
Once in the file, copy the following code to make HelloWorld in C<br />
#include <stdio.h><br />
int main () {<br />
printf("Gumstix runs on C\n");<br />
return 0;<br />
}<br />
Then write the file and exit back to the command line with: <br><br />
Ctrl + O<br />
Ctrl + X<br />
<br />
Next, to compile the program, issue the command:<br />
gcc -o HelloWorld HelloWorld.c<br />
This creates an executable object (HelloWorld) by using the gcc compiler on the C file HelloWorld.c.<br />
Then, run the program using the command:<br />
./HelloWorld<br />
This tells the computer to execute a file named HelloWorld located in the current directory (./). The outputs should be: <br><br />
Gumstix runs on C<br />
Congratulations! You have successfully written your first C program on your Overo COM!</div>JustinC474https://wiki.gumstix.com/index.php?title=HelloWorld_in_Java&diff=4545HelloWorld in Java2010-08-06T18:00:59Z<p>JustinC474: moved HelloWorld in Java to Using Eclipse to Write HelloWorld in Java for the Overo</p>
<hr />
<div>#REDIRECT [[Using Eclipse to Write HelloWorld in Java for the Overo]]</div>JustinC474https://wiki.gumstix.com/index.php?title=Using_Eclipse_to_Write_HelloWorld_in_Java_for_the_Overo&diff=4544Using Eclipse to Write HelloWorld in Java for the Overo2010-08-06T18:00:59Z<p>JustinC474: moved HelloWorld in Java to Using Eclipse to Write HelloWorld in Java for the Overo</p>
<hr />
<div>This page will teach you how to create a simple, graphical, java HelloWorld application in Eclipse, export it to you Overo COM, and subsequently run it. This guide assumes that you have already run through [[Eclipse on Gumstix for new users]] and have Eclipse installed, and your Gumstix properly connected. <br />
<br />
==Writing HelloWorld.java in Eclipse==<br />
First, you need to write your Java program in Eclipse. This section will show you how to write a small graphical HelloWorld program in Eclipse.<br />
<br />
:* Navigate to '''File-> New-> Java Project'''<br />
:* Name the project ''HelloWorld''<br />
:* Select "Finish"<br />
Once the project is created,<br />
:* Select '''File->New->Class'''<br />
:* Name your class ''HelloWorld''<br />
:* click "Finish"<br />
<br />
Add the following code to your class:<br />
<br />
import javax.swing.JFrame;<br />
import javax.swing.JLabel;<br />
public class Hello {<br />
public static void main(String [] args) {<br />
JFrame frame = new JFrame("hello");<br />
final JLabel label = new JLabel("hello from Gumstix");<br />
frame.getContentPane().add(label);<br />
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);<br />
frame.pack();<br />
frame.setVisible(true);<br />
}<br />
}<br />
<br />
Press the green run button to test drive our application on our host machine. You should get something that looks like this:<br />
<br />
[[File:GumstixEclipse12.jpg]]<br />
<br />
Congratulations! You have now written your first graphical program in Java.<br />
<br />
----<br />
Hint:<br />
Eclipse has many auto-completion features. Simply typing /:*<Enter> before a class creates a standard documentation block. Likewise, pressing <Ctrl>+<Space> provides context specific auto-completion options. Many other hints for speedy development are explained in the tutorials [http://www.eclipse.org/resources/?category=Getting%20Started here].<br />
----<br />
<br />
==Upload your Code onto your Overo COM==<br />
Now that you have a graphical program on Eclipse, its time to upload it onto your Overo COM. This will show you how to upload your code onto your Overo COM via ethernet connection. First, you will need to discover to IP Address of your Overo. To do this, see [[Eclipse on Gumstix for new users]]: Connect Your Gumstix. Once you have the IP Address of your Gumstix, it is time to export your Java Program onto your Overo COM. <br />
:*Choose '''File -> Export''' from the drop down menu<br />
:*Choose '''Remote Systems -> Remote File System''' and press '''Next'''<br />
[[File:JavaEclipsePic1.png]]<br />
:*Expand the drop down for the HelloWorld project<br />
::*In the '''bin''' folder choose '''HelloWorld.class'''<br />
[[File:JavaEclipsePic5.png]]<br />
----<br />
Note:<br />
We want to export the HelloWorld.class file and NOT the HelloWorld.java file. This is because our Overo COM can not compile a .java file. A .class file has already been compiled and is ready to run on a Java Virtual Machine, which our Overo COM will have after some necessary installations. <br />
----<br />
:*For Destination Folder, hit the '''Browse''' button<br />
[[File:JavaEclipsePic2.png]]<br />
:*In the Browse For Folder window which will appear:<br />
:*If you have already added a ethernet connection to your Overo COM, it should be in the drop down menu under Local<br />
[[File:JavaEclipsePic3.png]]<br />
:*If it is not, hit '''New'''<br />
::*Choose '''SSH Only'''<br />
::*In the '''HOST Name''', put the IP Address<br />
::*Hit Finish<br />
[[File:JavaEclipsePic4.png]]<br />
:*Under '''My Home''' choose '''Desktop''' and hit OK<br />
:*Back in the Export window, hit '''Finish''' and Eclipse will export your program to your Overo!<br />
<br />
==Installing Necessary Software==<br />
Before we can run our program on the Overo COM, there are some opkg we need installed so that we can run a Java Virtual Machine. To do this issue the following commands:<br />
opkg update<br />
opkg install cacao<br />
opkg install classpath-gtk<br />
This installs the Java Library cacao and the GTK which allows you to run graphical JARs. <br />
<br />
Next, we need to set our Display to be correct. In the Console window for the Overo COM issue the following command<br />
export DISPLAY=:0.0<br />
This enables the Overo to be able to display onto the monitor correctly. Without setting the display correctly our graphical program will not work. <br />
<br />
==Running our Program==<br />
Now that our Overo COM has the program on it and the necessary software to run it, it is time to run our graphical HelloWorld!<br />
----<br />
Note:<br />
You will need a Monitor connected to your Overo COM to run this program. This does not include the local host.<br />
----<br />
To do this you first must go into the '''Remote System Explorer''' Perspective in Eclipse. <br />
:*From the '''Window''' drop down menu, choose '''Open Perspective -> Other -> Remote System Explorer'''<br />
:*Find the Overo's IP address<br />
::*Expand '''(The IP Address) -> My Home -> Desktop -> bin'''<br />
::*Right click on HelloWorld.class, and choose '''User Action -> java''' <br />
::*Hit Enter<br />
:*A Box should appear on your monitor with the text: Hello from Gumstix<br />
<br />
==Minesweeper==<br />
If you wish to move on to something more complex, see the page for [[Minesweeper in Java]]. All the code in provided to make a cool, graphically Minesweeper game that can be run on an Overo with a monitor!</div>JustinC474https://wiki.gumstix.com/index.php?title=Remote_Debugging_with_GDB&diff=4538Remote Debugging with GDB2010-08-06T16:54:17Z<p>JustinC474: /* More Tutorial */</p>
<hr />
<div>In this tutorial we will go over how to perform a basic debugging with GDB, the GNU debugger. This environment allows us to debug C, C++ and Java (compiled to machine code, not for running in a Java Virtual Machine) programs.<br />
*We will complete these tasks step by step<br />
:*Install the GDB debugger<br />
:*Run the debugger<br />
:*Set Breakpoints<br />
:*Navigate the code in your program<br />
:*Diagnose an error and how to fix it<br />
<br />
*Required Items<br />
:*Overo COM with Expansion Board<br />
:*Mini B to Standard A Cable<br />
:*Bootable MicroSD card<br />
:*5V Power Supply<br />
<br />
*Required Reading (things you should know, or tutorials that explain)<br />
:*[[HelloWorld | HelloWorld in Python, C and C++]]<br />
:*[[Eclipse on Gumstix for new users | Eclipse Tutorial]]<br />
::*Although the majority of this tutorial pertains to debugging and C programming, it contains useful information which leads to basic understanding of your Overo COM<br />
<br />
==Installing the GDB Debugger==<br />
Before starting this, you should have Console access to your Overo COM and should know how to program and run a basic C++ program. If you do not know how to do this, see [[HelloWorld | HelloWorld in Python, C and C++]].<br />
<br />
If you haven't yet, install a C/C++ SDK with the following command<br />
opkg update <br />
opkg install task-native-sdk<br />
<br />
To install the GDB debugger, run the following command in your command line:<br />
opkg update<br />
opkg install gdb<br />
Once this has completed, you will have the GNU GDB debugger installed on your Overo COM<br />
<br />
==Creating the Test File==<br />
Now that we have the debugging environment<br />
<br />
Run the following in your command line:<br />
nano broken.cpp<br />
Then copy and paste the code from [http://cs.baylor.edu/~donahoo/tools/gdb/broken.cpp |Broken.cpp] into your shell. When you copy and paste there will be two syntax errors that you must fix at the lines:<br />
cout << "This program is used to compute the value of the following<br />
series : " << endl;<br />
and<br />
cout << "(x^0)/0! + (x^1)/1! + (x^2)/2! + (x^3)/3! + (x^4)/4! + ....<br />
.... + (x^n)/n! " << endl<br />
<br />
Copying and pasting added an extra line break to these two lines, and we want to undo this by deleting one space at the beginning of each second line so it looks like this:<br />
cout << "This program is used to compute the value of the following series : " << endl;<br />
and<br />
cout << "(x^0)/0! + (x^1)/1! + (x^2)/2! + (x^3)/3! + (x^4)/4! + ........ + (x^n)/n! " << endl<br />
<br />
Now save and exit by pressing the following:<br />
:*Ctrl + O<br />
:*<Enter><br />
:*Ctrl + X<br />
<br />
==Compile and Run broken.cpp==<br />
Now that we have our test file (broken.cpp) ready to go, it is time to run it. <br />
<br />
Compile the program to create an executable file (broken) by entering the following command:<br />
g++ -g broken.cpp -o broken<br />
The '-g' switch tells the compiler to include debugging symbols in the executable. Run the program as such:<br />
./broken<br />
----<br />
Note:<br />
Use 'g++ -g broken.cpp -o broken' to compile. If you use g++ -o, g++ --ggdb -Wall, or any other method of compilation the debugging will not follow this tutorial exactly.<br />
----<br />
<br />
Enter any numbers into the program for x and n. Run it a couple times, you should notice that the answer is always the same: infinity. This is obviously wrong.<br />
<br />
Consider: x=1, n=1<br />
(1^0)/0! + (1^1)/1!<br />
1/1 + 1/1<br />
2<br />
<br />
NOT infinity<br />
<br />
==Debugging the Program==<br />
Now, it is time that we debugged our program. <br />
<br />
First, you need to start the GDB environment by issuing the following command:<br />
gdb<br />
You should see the following command line appear:<br />
(gdb)<br />
Then, you need to 'tell' the debugger which file it is that we are debugging, do this by issuing the command:<br />
(gdb) exec-file broken<br />
Now, it is time to run our program by issuing the command:<br />
(gdb) run<br />
<br />
Notice that the program runs normally and again, gives us the answer inf. This is because the error we have is a computation error, and does not cause our program to crash. So, its time to set a Breakpoint in our program.<br />
<br />
===Setting a Breakpoint===<br />
----<br />
Hint:<br />
A breakpoint is a point in the program at which the debugger will stop the code from executing. Then, you can choose to 'step' through the program line by line to 'see' exactly what the CPU is doing. This way, you can effectively watch the program execute and discover where the problem is!<br />
----<br />
Lets set a breakpoint within the program so that we can see what is going on. Lets start by setting a breakpoint at line 43. Do this with the following command:<br />
(gdb) b 43<br />
You could also set a breakpoint to a specific functions call, such as:<br />
(gdb) b ComputeSeriesValue<br />
However, for the purpose of this tutorial, use the line number. If you wish, you can play around with using the function instead, but it will cause you to diverge from this tutorial.<br />
<br />
If the program outputs: No symbol table is loaded. Use the "file" command. Then use the following command:<br />
(gdb) file broken<br />
This will set the file so that you can add a breakpoint without error<br />
<br />
Line 43 is the following:<br />
double seriesValue = ComputeSeriesValue(x, n);<br />
So the program will stop executing immediately before it executes the function ComputeSeriesValue(x, n).<br />
<br />
Now, lets run the program with our command:<br />
(gdb) run<br />
Let's enter the values as x=2 and n=3, with an expected output value is 5. <br />
Here is a snapshot of what the program should output at this point:<br />
This program is used to compute the value of the following series : <br />
(x^0)/0! + (x^1)/1! + (x^2)/2! + (x^3)/3! + (x^4)/4! + ........ + (x^n)/n! <br />
Please enter the value of x : 2<br />
Please enter an integer value for n : 3<br />
Breakpoint 1, main () at broken.cpp:43<br />
43 double seriesValue = ComputeSeriesValue(x, n);<br />
The program has stopped at our breakpoint, line 43.<br />
<br />
===Stepping into a function===<br />
Next, we are going to step into the function ComputeSeriesValue(x, n)<br />
----<br />
Hint:<br />
'Stepping' through a function allows us to go line by line, and see exactly what lines of code are being executed. This way we can manually diagnose the computation problem.<br />
----<br />
To start stepping, issue the following command<br />
(gdb) step<br />
----<br />
Hint:<br />
A nice thing about the GDB Debugger is that it will save the last command you issued so that you don't need to type it over and over. This way you can keep stepping through the function by pressing <enter>. You do not need to retype 'step' <br><br />
Hint:<br />
The GDB Debugger also has nice 'shortcuts'. For example, 'step' and 's' are the same command. So is 'breakpoint' and 'b'. <br />
----<br />
You should see the following outputted:<br />
ComputeSeriesValue (x=2, n=3) at broken.cpp:17<br />
17 double seriesValue=0.0;<br />
At this point, the program has gone to line 17, and is at the first line of the function ComputeSeriesValue, which sets the double seriesValue to 0.0.<br />
<br />
Now, we wish to use the 'next' function until we reach the function CompueFraction(). To do this, use the following commands:<br />
(gdb) next<br />
18 double xpow=1;<br />
(gdb) <enter><br />
20 for (int k = 0; k <= n; k++) {<br />
(gdb) <enter> <br />
21 seriesValue += xpow / ComputeFactorial(k) ;<br />
(gdb) step<br />
ComputeFactorial (number=0) at broken.cpp:7<br />
7 int fact=0;<br />
<br />
==Using Backtrace==<br />
*If you want to know where you are in the program's execution (and how, to some extent, you got there), you can view the contents of the stack using the backtrace command as follows:<br />
(gdb) bt<br />
#0 ComputeFactorial (number=0) at broken.cpp:7<br />
#1 0x08048907 in ComputeSeriesValue (x=3, n=2) at broken.cpp:21<br />
#2 0x08048a31 in main () at broken.cpp:43<br />
----<br />
Hint: <br />
Backtrace lets you see where you have been and what you have done. In case, you get lost or confused it is very useful. <br><br />
Hint: <br />
A stack is a data structure in Computer Science which stores data much like a stack of cards. It is a Last On, First Off data structure. For more explanation of how a stack functions, see the wikipedia article. <br><br />
http://en.wikipedia.org/wiki/Stack_(data_structure)<br />
----<br />
See the error?<br />
<br />
The print command (abbreviated p) reveals that the value of fact never changes. Note that the function is returning a value of 0 for the function call ComputeFactorial(number=0). This is an ERROR! The answer will always equal zero.<br />
<br />
By taking a closer look at the values printed above, we realize that we are computing fact=fact * j where fact has been initialized to 0, (0 = 0 * j); fact should have been initialized to 1. We quit GDB with the quit command. Next we need to change the following line:<br />
<br />
change the line<br />
int fact = 0;<br />
to<br />
int fact =1;<br />
and you're all set!<br />
<br />
==More Tutorial==<br />
For another tutorial which is more in depth, see:<br />
http://www.cs.cmu.edu/~gilpin/tutorial/</div>JustinC474https://wiki.gumstix.com/index.php?title=Remote_Debugging_with_GDB&diff=4537Remote Debugging with GDB2010-08-06T16:52:02Z<p>JustinC474: /* Using Backtrace */</p>
<hr />
<div>In this tutorial we will go over how to perform a basic debugging with GDB, the GNU debugger. This environment allows us to debug C, C++ and Java (compiled to machine code, not for running in a Java Virtual Machine) programs.<br />
*We will complete these tasks step by step<br />
:*Install the GDB debugger<br />
:*Run the debugger<br />
:*Set Breakpoints<br />
:*Navigate the code in your program<br />
:*Diagnose an error and how to fix it<br />
<br />
*Required Items<br />
:*Overo COM with Expansion Board<br />
:*Mini B to Standard A Cable<br />
:*Bootable MicroSD card<br />
:*5V Power Supply<br />
<br />
*Required Reading (things you should know, or tutorials that explain)<br />
:*[[HelloWorld | HelloWorld in Python, C and C++]]<br />
:*[[Eclipse on Gumstix for new users | Eclipse Tutorial]]<br />
::*Although the majority of this tutorial pertains to debugging and C programming, it contains useful information which leads to basic understanding of your Overo COM<br />
<br />
==Installing the GDB Debugger==<br />
Before starting this, you should have Console access to your Overo COM and should know how to program and run a basic C++ program. If you do not know how to do this, see [[HelloWorld | HelloWorld in Python, C and C++]].<br />
<br />
If you haven't yet, install a C/C++ SDK with the following command<br />
opkg update <br />
opkg install task-native-sdk<br />
<br />
To install the GDB debugger, run the following command in your command line:<br />
opkg update<br />
opkg install gdb<br />
Once this has completed, you will have the GNU GDB debugger installed on your Overo COM<br />
<br />
==Creating the Test File==<br />
Now that we have the debugging environment<br />
<br />
Run the following in your command line:<br />
nano broken.cpp<br />
Then copy and paste the code from [http://cs.baylor.edu/~donahoo/tools/gdb/broken.cpp |Broken.cpp] into your shell. When you copy and paste there will be two syntax errors that you must fix at the lines:<br />
cout << "This program is used to compute the value of the following<br />
series : " << endl;<br />
and<br />
cout << "(x^0)/0! + (x^1)/1! + (x^2)/2! + (x^3)/3! + (x^4)/4! + ....<br />
.... + (x^n)/n! " << endl<br />
<br />
Copying and pasting added an extra line break to these two lines, and we want to undo this by deleting one space at the beginning of each second line so it looks like this:<br />
cout << "This program is used to compute the value of the following series : " << endl;<br />
and<br />
cout << "(x^0)/0! + (x^1)/1! + (x^2)/2! + (x^3)/3! + (x^4)/4! + ........ + (x^n)/n! " << endl<br />
<br />
Now save and exit by pressing the following:<br />
:*Ctrl + O<br />
:*<Enter><br />
:*Ctrl + X<br />
<br />
==Compile and Run broken.cpp==<br />
Now that we have our test file (broken.cpp) ready to go, it is time to run it. <br />
<br />
Compile the program to create an executable file (broken) by entering the following command:<br />
g++ -g broken.cpp -o broken<br />
The '-g' switch tells the compiler to include debugging symbols in the executable. Run the program as such:<br />
./broken<br />
----<br />
Note:<br />
Use 'g++ -g broken.cpp -o broken' to compile. If you use g++ -o, g++ --ggdb -Wall, or any other method of compilation the debugging will not follow this tutorial exactly.<br />
----<br />
<br />
Enter any numbers into the program for x and n. Run it a couple times, you should notice that the answer is always the same: infinity. This is obviously wrong.<br />
<br />
Consider: x=1, n=1<br />
(1^0)/0! + (1^1)/1!<br />
1/1 + 1/1<br />
2<br />
<br />
NOT infinity<br />
<br />
==Debugging the Program==<br />
Now, it is time that we debugged our program. <br />
<br />
First, you need to start the GDB environment by issuing the following command:<br />
gdb<br />
You should see the following command line appear:<br />
(gdb)<br />
Then, you need to 'tell' the debugger which file it is that we are debugging, do this by issuing the command:<br />
(gdb) exec-file broken<br />
Now, it is time to run our program by issuing the command:<br />
(gdb) run<br />
<br />
Notice that the program runs normally and again, gives us the answer inf. This is because the error we have is a computation error, and does not cause our program to crash. So, its time to set a Breakpoint in our program.<br />
<br />
===Setting a Breakpoint===<br />
----<br />
Hint:<br />
A breakpoint is a point in the program at which the debugger will stop the code from executing. Then, you can choose to 'step' through the program line by line to 'see' exactly what the CPU is doing. This way, you can effectively watch the program execute and discover where the problem is!<br />
----<br />
Lets set a breakpoint within the program so that we can see what is going on. Lets start by setting a breakpoint at line 43. Do this with the following command:<br />
(gdb) b 43<br />
You could also set a breakpoint to a specific functions call, such as:<br />
(gdb) b ComputeSeriesValue<br />
However, for the purpose of this tutorial, use the line number. If you wish, you can play around with using the function instead, but it will cause you to diverge from this tutorial.<br />
<br />
If the program outputs: No symbol table is loaded. Use the "file" command. Then use the following command:<br />
(gdb) file broken<br />
This will set the file so that you can add a breakpoint without error<br />
<br />
Line 43 is the following:<br />
double seriesValue = ComputeSeriesValue(x, n);<br />
So the program will stop executing immediately before it executes the function ComputeSeriesValue(x, n).<br />
<br />
Now, lets run the program with our command:<br />
(gdb) run<br />
Let's enter the values as x=2 and n=3, with an expected output value is 5. <br />
Here is a snapshot of what the program should output at this point:<br />
This program is used to compute the value of the following series : <br />
(x^0)/0! + (x^1)/1! + (x^2)/2! + (x^3)/3! + (x^4)/4! + ........ + (x^n)/n! <br />
Please enter the value of x : 2<br />
Please enter an integer value for n : 3<br />
Breakpoint 1, main () at broken.cpp:43<br />
43 double seriesValue = ComputeSeriesValue(x, n);<br />
The program has stopped at our breakpoint, line 43.<br />
<br />
===Stepping into a function===<br />
Next, we are going to step into the function ComputeSeriesValue(x, n)<br />
----<br />
Hint:<br />
'Stepping' through a function allows us to go line by line, and see exactly what lines of code are being executed. This way we can manually diagnose the computation problem.<br />
----<br />
To start stepping, issue the following command<br />
(gdb) step<br />
----<br />
Hint:<br />
A nice thing about the GDB Debugger is that it will save the last command you issued so that you don't need to type it over and over. This way you can keep stepping through the function by pressing <enter>. You do not need to retype 'step' <br><br />
Hint:<br />
The GDB Debugger also has nice 'shortcuts'. For example, 'step' and 's' are the same command. So is 'breakpoint' and 'b'. <br />
----<br />
You should see the following outputted:<br />
ComputeSeriesValue (x=2, n=3) at broken.cpp:17<br />
17 double seriesValue=0.0;<br />
At this point, the program has gone to line 17, and is at the first line of the function ComputeSeriesValue, which sets the double seriesValue to 0.0.<br />
<br />
Now, we wish to use the 'next' function until we reach the function CompueFraction(). To do this, use the following commands:<br />
(gdb) next<br />
18 double xpow=1;<br />
(gdb) <enter><br />
20 for (int k = 0; k <= n; k++) {<br />
(gdb) <enter> <br />
21 seriesValue += xpow / ComputeFactorial(k) ;<br />
(gdb) step<br />
ComputeFactorial (number=0) at broken.cpp:7<br />
7 int fact=0;<br />
<br />
==Using Backtrace==<br />
*If you want to know where you are in the program's execution (and how, to some extent, you got there), you can view the contents of the stack using the backtrace command as follows:<br />
(gdb) bt<br />
#0 ComputeFactorial (number=0) at broken.cpp:7<br />
#1 0x08048907 in ComputeSeriesValue (x=3, n=2) at broken.cpp:21<br />
#2 0x08048a31 in main () at broken.cpp:43<br />
----<br />
Hint: <br />
Backtrace lets you see where you have been and what you have done. In case, you get lost or confused it is very useful. <br><br />
Hint: <br />
A stack is a data structure in Computer Science which stores data much like a stack of cards. It is a Last On, First Off data structure. For more explanation of how a stack functions, see the wikipedia article. <br><br />
http://en.wikipedia.org/wiki/Stack_(data_structure)<br />
----<br />
See the error?<br />
<br />
The print command (abbreviated p) reveals that the value of fact never changes. Note that the function is returning a value of 0 for the function call ComputeFactorial(number=0). This is an ERROR! The answer will always equal zero.<br />
<br />
By taking a closer look at the values printed above, we realize that we are computing fact=fact * j where fact has been initialized to 0, (0 = 0 * j); fact should have been initialized to 1. We quit GDB with the quit command. Next we need to change the following line:<br />
<br />
change the line<br />
int fact = 0;<br />
to<br />
int fact =1;<br />
and you're all set!<br />
<br />
==More Tutorial==<br />
For another tutorial see:<br />
http://www.cs.cmu.edu/~gilpin/tutorial/</div>JustinC474https://wiki.gumstix.com/index.php?title=Remote_Debugging_with_GDB&diff=4535Remote Debugging with GDB2010-08-06T16:44:39Z<p>JustinC474: /* Stepping into a function */</p>
<hr />
<div>In this tutorial we will go over how to perform a basic debugging with GDB, the GNU debugger. This environment allows us to debug C, C++ and Java (compiled to machine code, not for running in a Java Virtual Machine) programs.<br />
*We will complete these tasks step by step<br />
:*Install the GDB debugger<br />
:*Run the debugger<br />
:*Set Breakpoints<br />
:*Navigate the code in your program<br />
:*Diagnose an error and how to fix it<br />
<br />
*Required Items<br />
:*Overo COM with Expansion Board<br />
:*Mini B to Standard A Cable<br />
:*Bootable MicroSD card<br />
:*5V Power Supply<br />
<br />
*Required Reading (things you should know, or tutorials that explain)<br />
:*[[HelloWorld | HelloWorld in Python, C and C++]]<br />
:*[[Eclipse on Gumstix for new users | Eclipse Tutorial]]<br />
::*Although the majority of this tutorial pertains to debugging and C programming, it contains useful information which leads to basic understanding of your Overo COM<br />
<br />
==Installing the GDB Debugger==<br />
Before starting this, you should have Console access to your Overo COM and should know how to program and run a basic C++ program. If you do not know how to do this, see [[HelloWorld | HelloWorld in Python, C and C++]].<br />
<br />
If you haven't yet, install a C/C++ SDK with the following command<br />
opkg update <br />
opkg install task-native-sdk<br />
<br />
To install the GDB debugger, run the following command in your command line:<br />
opkg update<br />
opkg install gdb<br />
Once this has completed, you will have the GNU GDB debugger installed on your Overo COM<br />
<br />
==Creating the Test File==<br />
Now that we have the debugging environment<br />
<br />
Run the following in your command line:<br />
nano broken.cpp<br />
Then copy and paste the code from [http://cs.baylor.edu/~donahoo/tools/gdb/broken.cpp |Broken.cpp] into your shell. When you copy and paste there will be two syntax errors that you must fix at the lines:<br />
cout << "This program is used to compute the value of the following<br />
series : " << endl;<br />
and<br />
cout << "(x^0)/0! + (x^1)/1! + (x^2)/2! + (x^3)/3! + (x^4)/4! + ....<br />
.... + (x^n)/n! " << endl<br />
<br />
Copying and pasting added an extra line break to these two lines, and we want to undo this by deleting one space at the beginning of each second line so it looks like this:<br />
cout << "This program is used to compute the value of the following series : " << endl;<br />
and<br />
cout << "(x^0)/0! + (x^1)/1! + (x^2)/2! + (x^3)/3! + (x^4)/4! + ........ + (x^n)/n! " << endl<br />
<br />
Now save and exit by pressing the following:<br />
:*Ctrl + O<br />
:*<Enter><br />
:*Ctrl + X<br />
<br />
==Compile and Run broken.cpp==<br />
Now that we have our test file (broken.cpp) ready to go, it is time to run it. <br />
<br />
Compile the program to create an executable file (broken) by entering the following command:<br />
g++ -g broken.cpp -o broken<br />
The '-g' switch tells the compiler to include debugging symbols in the executable. Run the program as such:<br />
./broken<br />
----<br />
Note:<br />
Use 'g++ -g broken.cpp -o broken' to compile. If you use g++ -o, g++ --ggdb -Wall, or any other method of compilation the debugging will not follow this tutorial exactly.<br />
----<br />
<br />
Enter any numbers into the program for x and n. Run it a couple times, you should notice that the answer is always the same: infinity. This is obviously wrong.<br />
<br />
Consider: x=1, n=1<br />
(1^0)/0! + (1^1)/1!<br />
1/1 + 1/1<br />
2<br />
<br />
NOT infinity<br />
<br />
==Debugging the Program==<br />
Now, it is time that we debugged our program. <br />
<br />
First, you need to start the GDB environment by issuing the following command:<br />
gdb<br />
You should see the following command line appear:<br />
(gdb)<br />
Then, you need to 'tell' the debugger which file it is that we are debugging, do this by issuing the command:<br />
(gdb) exec-file broken<br />
Now, it is time to run our program by issuing the command:<br />
(gdb) run<br />
<br />
Notice that the program runs normally and again, gives us the answer inf. This is because the error we have is a computation error, and does not cause our program to crash. So, its time to set a Breakpoint in our program.<br />
<br />
===Setting a Breakpoint===<br />
----<br />
Hint:<br />
A breakpoint is a point in the program at which the debugger will stop the code from executing. Then, you can choose to 'step' through the program line by line to 'see' exactly what the CPU is doing. This way, you can effectively watch the program execute and discover where the problem is!<br />
----<br />
Lets set a breakpoint within the program so that we can see what is going on. Lets start by setting a breakpoint at line 43. Do this with the following command:<br />
(gdb) b 43<br />
You could also set a breakpoint to a specific functions call, such as:<br />
(gdb) b ComputeSeriesValue<br />
However, for the purpose of this tutorial, use the line number. If you wish, you can play around with using the function instead, but it will cause you to diverge from this tutorial.<br />
<br />
If the program outputs: No symbol table is loaded. Use the "file" command. Then use the following command:<br />
(gdb) file broken<br />
This will set the file so that you can add a breakpoint without error<br />
<br />
Line 43 is the following:<br />
double seriesValue = ComputeSeriesValue(x, n);<br />
So the program will stop executing immediately before it executes the function ComputeSeriesValue(x, n).<br />
<br />
Now, lets run the program with our command:<br />
(gdb) run<br />
Let's enter the values as x=2 and n=3, with an expected output value is 5. <br />
Here is a snapshot of what the program should output at this point:<br />
This program is used to compute the value of the following series : <br />
(x^0)/0! + (x^1)/1! + (x^2)/2! + (x^3)/3! + (x^4)/4! + ........ + (x^n)/n! <br />
Please enter the value of x : 2<br />
Please enter an integer value for n : 3<br />
Breakpoint 1, main () at broken.cpp:43<br />
43 double seriesValue = ComputeSeriesValue(x, n);<br />
The program has stopped at our breakpoint, line 43.<br />
<br />
===Stepping into a function===<br />
Next, we are going to step into the function ComputeSeriesValue(x, n)<br />
----<br />
Hint:<br />
'Stepping' through a function allows us to go line by line, and see exactly what lines of code are being executed. This way we can manually diagnose the computation problem.<br />
----<br />
To start stepping, issue the following command<br />
(gdb) step<br />
----<br />
Hint:<br />
A nice thing about the GDB Debugger is that it will save the last command you issued so that you don't need to type it over and over. This way you can keep stepping through the function by pressing <enter>. You do not need to retype 'step' <br><br />
Hint:<br />
The GDB Debugger also has nice 'shortcuts'. For example, 'step' and 's' are the same command. So is 'breakpoint' and 'b'. <br />
----<br />
You should see the following outputted:<br />
ComputeSeriesValue (x=2, n=3) at broken.cpp:17<br />
17 double seriesValue=0.0;<br />
At this point, the program has gone to line 17, and is at the first line of the function ComputeSeriesValue, which sets the double seriesValue to 0.0.<br />
<br />
Now, we wish to use the 'next' function until we reach the function CompueFraction(). To do this, use the following commands:<br />
(gdb) next<br />
18 double xpow=1;<br />
(gdb) <enter><br />
20 for (int k = 0; k <= n; k++) {<br />
(gdb) <enter> <br />
21 seriesValue += xpow / ComputeFactorial(k) ;<br />
(gdb) step<br />
ComputeFactorial (number=0) at broken.cpp:7<br />
7 int fact=0;<br />
<br />
==Using Backtrace==<br />
*If you want to know where you are in the program's execution (and how, to some extent, you got there), you can view the contents of the stack using the backtrace command as follows:<br />
(gdb) bt<br />
#0 ComputeFactorial (number=0) at broken.cpp:7<br />
#1 0x08048907 in ComputeSeriesValue (x=3, n=2) at broken.cpp:21<br />
#2 0x08048a31 in main () at broken.cpp:43<br />
----<br />
Note: <br />
Backtrace lets you see where you have been and what you have done. In case, you get lost or confused it is very useful.<br />
----<br />
See the error?<br />
<br />
The print command (abbreviated p) reveals that the value of fact never changes. Note that the function is returning a value of 0 for the function call ComputeFactorial(number=0). This is an ERROR! The answer will always equal zero.<br />
<br />
By taking a closer look at the values printed above, we realize that we are computing fact=fact * j where fact has been initialized to 0, (0 = 0 * j); fact should have been initialized to 1. We quit GDB with the quit command. Next we need to change the following line:<br />
<br />
change the line<br />
int fact = 0;<br />
to<br />
int fact =1;<br />
and you're all set!<br />
<br />
==More Tutorial==<br />
For another tutorial see:<br />
http://www.cs.cmu.edu/~gilpin/tutorial/</div>JustinC474https://wiki.gumstix.com/index.php?title=Remote_Debugging_with_GDB&diff=4534Remote Debugging with GDB2010-08-06T16:44:09Z<p>JustinC474: /* Stepping into a function */</p>
<hr />
<div>In this tutorial we will go over how to perform a basic debugging with GDB, the GNU debugger. This environment allows us to debug C, C++ and Java (compiled to machine code, not for running in a Java Virtual Machine) programs.<br />
*We will complete these tasks step by step<br />
:*Install the GDB debugger<br />
:*Run the debugger<br />
:*Set Breakpoints<br />
:*Navigate the code in your program<br />
:*Diagnose an error and how to fix it<br />
<br />
*Required Items<br />
:*Overo COM with Expansion Board<br />
:*Mini B to Standard A Cable<br />
:*Bootable MicroSD card<br />
:*5V Power Supply<br />
<br />
*Required Reading (things you should know, or tutorials that explain)<br />
:*[[HelloWorld | HelloWorld in Python, C and C++]]<br />
:*[[Eclipse on Gumstix for new users | Eclipse Tutorial]]<br />
::*Although the majority of this tutorial pertains to debugging and C programming, it contains useful information which leads to basic understanding of your Overo COM<br />
<br />
==Installing the GDB Debugger==<br />
Before starting this, you should have Console access to your Overo COM and should know how to program and run a basic C++ program. If you do not know how to do this, see [[HelloWorld | HelloWorld in Python, C and C++]].<br />
<br />
If you haven't yet, install a C/C++ SDK with the following command<br />
opkg update <br />
opkg install task-native-sdk<br />
<br />
To install the GDB debugger, run the following command in your command line:<br />
opkg update<br />
opkg install gdb<br />
Once this has completed, you will have the GNU GDB debugger installed on your Overo COM<br />
<br />
==Creating the Test File==<br />
Now that we have the debugging environment<br />
<br />
Run the following in your command line:<br />
nano broken.cpp<br />
Then copy and paste the code from [http://cs.baylor.edu/~donahoo/tools/gdb/broken.cpp |Broken.cpp] into your shell. When you copy and paste there will be two syntax errors that you must fix at the lines:<br />
cout << "This program is used to compute the value of the following<br />
series : " << endl;<br />
and<br />
cout << "(x^0)/0! + (x^1)/1! + (x^2)/2! + (x^3)/3! + (x^4)/4! + ....<br />
.... + (x^n)/n! " << endl<br />
<br />
Copying and pasting added an extra line break to these two lines, and we want to undo this by deleting one space at the beginning of each second line so it looks like this:<br />
cout << "This program is used to compute the value of the following series : " << endl;<br />
and<br />
cout << "(x^0)/0! + (x^1)/1! + (x^2)/2! + (x^3)/3! + (x^4)/4! + ........ + (x^n)/n! " << endl<br />
<br />
Now save and exit by pressing the following:<br />
:*Ctrl + O<br />
:*<Enter><br />
:*Ctrl + X<br />
<br />
==Compile and Run broken.cpp==<br />
Now that we have our test file (broken.cpp) ready to go, it is time to run it. <br />
<br />
Compile the program to create an executable file (broken) by entering the following command:<br />
g++ -g broken.cpp -o broken<br />
The '-g' switch tells the compiler to include debugging symbols in the executable. Run the program as such:<br />
./broken<br />
----<br />
Note:<br />
Use 'g++ -g broken.cpp -o broken' to compile. If you use g++ -o, g++ --ggdb -Wall, or any other method of compilation the debugging will not follow this tutorial exactly.<br />
----<br />
<br />
Enter any numbers into the program for x and n. Run it a couple times, you should notice that the answer is always the same: infinity. This is obviously wrong.<br />
<br />
Consider: x=1, n=1<br />
(1^0)/0! + (1^1)/1!<br />
1/1 + 1/1<br />
2<br />
<br />
NOT infinity<br />
<br />
==Debugging the Program==<br />
Now, it is time that we debugged our program. <br />
<br />
First, you need to start the GDB environment by issuing the following command:<br />
gdb<br />
You should see the following command line appear:<br />
(gdb)<br />
Then, you need to 'tell' the debugger which file it is that we are debugging, do this by issuing the command:<br />
(gdb) exec-file broken<br />
Now, it is time to run our program by issuing the command:<br />
(gdb) run<br />
<br />
Notice that the program runs normally and again, gives us the answer inf. This is because the error we have is a computation error, and does not cause our program to crash. So, its time to set a Breakpoint in our program.<br />
<br />
===Setting a Breakpoint===<br />
----<br />
Hint:<br />
A breakpoint is a point in the program at which the debugger will stop the code from executing. Then, you can choose to 'step' through the program line by line to 'see' exactly what the CPU is doing. This way, you can effectively watch the program execute and discover where the problem is!<br />
----<br />
Lets set a breakpoint within the program so that we can see what is going on. Lets start by setting a breakpoint at line 43. Do this with the following command:<br />
(gdb) b 43<br />
You could also set a breakpoint to a specific functions call, such as:<br />
(gdb) b ComputeSeriesValue<br />
However, for the purpose of this tutorial, use the line number. If you wish, you can play around with using the function instead, but it will cause you to diverge from this tutorial.<br />
<br />
If the program outputs: No symbol table is loaded. Use the "file" command. Then use the following command:<br />
(gdb) file broken<br />
This will set the file so that you can add a breakpoint without error<br />
<br />
Line 43 is the following:<br />
double seriesValue = ComputeSeriesValue(x, n);<br />
So the program will stop executing immediately before it executes the function ComputeSeriesValue(x, n).<br />
<br />
Now, lets run the program with our command:<br />
(gdb) run<br />
Let's enter the values as x=2 and n=3, with an expected output value is 5. <br />
Here is a snapshot of what the program should output at this point:<br />
This program is used to compute the value of the following series : <br />
(x^0)/0! + (x^1)/1! + (x^2)/2! + (x^3)/3! + (x^4)/4! + ........ + (x^n)/n! <br />
Please enter the value of x : 2<br />
Please enter an integer value for n : 3<br />
Breakpoint 1, main () at broken.cpp:43<br />
43 double seriesValue = ComputeSeriesValue(x, n);<br />
The program has stopped at our breakpoint, line 43.<br />
<br />
===Stepping into a function===<br />
Next, we are going to step into the function ComputeSeriesValue(x, n)<br />
----<br />
Hint:<br />
'Stepping' through a function allows us to go line by line, and see exactly what lines of code are being executed. This way we can manually diagnose the computation problem.<br />
----<br />
To start stepping, issue the following command<br />
(gdb) step<br />
----<br />
Hint:<br />
A nice thing about the GDB Debugger is that it will save the last command you issued so that you don't need to type it over and over. This way you can keep stepping through the function by pressing <enter>. You do not need to retype 'step'<br />
Hint:<br />
The GDB Debugger also has nice 'shortcuts'. For example, 'step' and 's' are the same command. So is 'breakpoint' and 'b'. <br />
----<br />
You should see the following outputted:<br />
ComputeSeriesValue (x=2, n=3) at broken.cpp:17<br />
17 double seriesValue=0.0;<br />
At this point, the program has gone to line 17, and is at the first line of the function ComputeSeriesValue, which sets the double seriesValue to 0.0.<br />
<br />
Now, we wish to use the 'next' function until we reach the function CompueFraction(). To do this, use the following commands:<br />
(gdb) next<br />
18 double xpow=1;<br />
(gdb) <enter><br />
20 for (int k = 0; k <= n; k++) {<br />
(gdb) <enter> <br />
21 seriesValue += xpow / ComputeFactorial(k) ;<br />
(gdb) step<br />
ComputeFactorial (number=0) at broken.cpp:7<br />
7 int fact=0;<br />
<br />
==Using Backtrace==<br />
*If you want to know where you are in the program's execution (and how, to some extent, you got there), you can view the contents of the stack using the backtrace command as follows:<br />
(gdb) bt<br />
#0 ComputeFactorial (number=0) at broken.cpp:7<br />
#1 0x08048907 in ComputeSeriesValue (x=3, n=2) at broken.cpp:21<br />
#2 0x08048a31 in main () at broken.cpp:43<br />
----<br />
Note: <br />
Backtrace lets you see where you have been and what you have done. In case, you get lost or confused it is very useful.<br />
----<br />
See the error?<br />
<br />
The print command (abbreviated p) reveals that the value of fact never changes. Note that the function is returning a value of 0 for the function call ComputeFactorial(number=0). This is an ERROR! The answer will always equal zero.<br />
<br />
By taking a closer look at the values printed above, we realize that we are computing fact=fact * j where fact has been initialized to 0, (0 = 0 * j); fact should have been initialized to 1. We quit GDB with the quit command. Next we need to change the following line:<br />
<br />
change the line<br />
int fact = 0;<br />
to<br />
int fact =1;<br />
and you're all set!<br />
<br />
==More Tutorial==<br />
For another tutorial see:<br />
http://www.cs.cmu.edu/~gilpin/tutorial/</div>JustinC474https://wiki.gumstix.com/index.php?title=Remote_Debugging_with_GDB&diff=4533Remote Debugging with GDB2010-08-06T16:40:52Z<p>JustinC474: /* Setting a Breakpoint */</p>
<hr />
<div>In this tutorial we will go over how to perform a basic debugging with GDB, the GNU debugger. This environment allows us to debug C, C++ and Java (compiled to machine code, not for running in a Java Virtual Machine) programs.<br />
*We will complete these tasks step by step<br />
:*Install the GDB debugger<br />
:*Run the debugger<br />
:*Set Breakpoints<br />
:*Navigate the code in your program<br />
:*Diagnose an error and how to fix it<br />
<br />
*Required Items<br />
:*Overo COM with Expansion Board<br />
:*Mini B to Standard A Cable<br />
:*Bootable MicroSD card<br />
:*5V Power Supply<br />
<br />
*Required Reading (things you should know, or tutorials that explain)<br />
:*[[HelloWorld | HelloWorld in Python, C and C++]]<br />
:*[[Eclipse on Gumstix for new users | Eclipse Tutorial]]<br />
::*Although the majority of this tutorial pertains to debugging and C programming, it contains useful information which leads to basic understanding of your Overo COM<br />
<br />
==Installing the GDB Debugger==<br />
Before starting this, you should have Console access to your Overo COM and should know how to program and run a basic C++ program. If you do not know how to do this, see [[HelloWorld | HelloWorld in Python, C and C++]].<br />
<br />
If you haven't yet, install a C/C++ SDK with the following command<br />
opkg update <br />
opkg install task-native-sdk<br />
<br />
To install the GDB debugger, run the following command in your command line:<br />
opkg update<br />
opkg install gdb<br />
Once this has completed, you will have the GNU GDB debugger installed on your Overo COM<br />
<br />
==Creating the Test File==<br />
Now that we have the debugging environment<br />
<br />
Run the following in your command line:<br />
nano broken.cpp<br />
Then copy and paste the code from [http://cs.baylor.edu/~donahoo/tools/gdb/broken.cpp |Broken.cpp] into your shell. When you copy and paste there will be two syntax errors that you must fix at the lines:<br />
cout << "This program is used to compute the value of the following<br />
series : " << endl;<br />
and<br />
cout << "(x^0)/0! + (x^1)/1! + (x^2)/2! + (x^3)/3! + (x^4)/4! + ....<br />
.... + (x^n)/n! " << endl<br />
<br />
Copying and pasting added an extra line break to these two lines, and we want to undo this by deleting one space at the beginning of each second line so it looks like this:<br />
cout << "This program is used to compute the value of the following series : " << endl;<br />
and<br />
cout << "(x^0)/0! + (x^1)/1! + (x^2)/2! + (x^3)/3! + (x^4)/4! + ........ + (x^n)/n! " << endl<br />
<br />
Now save and exit by pressing the following:<br />
:*Ctrl + O<br />
:*<Enter><br />
:*Ctrl + X<br />
<br />
==Compile and Run broken.cpp==<br />
Now that we have our test file (broken.cpp) ready to go, it is time to run it. <br />
<br />
Compile the program to create an executable file (broken) by entering the following command:<br />
g++ -g broken.cpp -o broken<br />
The '-g' switch tells the compiler to include debugging symbols in the executable. Run the program as such:<br />
./broken<br />
----<br />
Note:<br />
Use 'g++ -g broken.cpp -o broken' to compile. If you use g++ -o, g++ --ggdb -Wall, or any other method of compilation the debugging will not follow this tutorial exactly.<br />
----<br />
<br />
Enter any numbers into the program for x and n. Run it a couple times, you should notice that the answer is always the same: infinity. This is obviously wrong.<br />
<br />
Consider: x=1, n=1<br />
(1^0)/0! + (1^1)/1!<br />
1/1 + 1/1<br />
2<br />
<br />
NOT infinity<br />
<br />
==Debugging the Program==<br />
Now, it is time that we debugged our program. <br />
<br />
First, you need to start the GDB environment by issuing the following command:<br />
gdb<br />
You should see the following command line appear:<br />
(gdb)<br />
Then, you need to 'tell' the debugger which file it is that we are debugging, do this by issuing the command:<br />
(gdb) exec-file broken<br />
Now, it is time to run our program by issuing the command:<br />
(gdb) run<br />
<br />
Notice that the program runs normally and again, gives us the answer inf. This is because the error we have is a computation error, and does not cause our program to crash. So, its time to set a Breakpoint in our program.<br />
<br />
===Setting a Breakpoint===<br />
----<br />
Hint:<br />
A breakpoint is a point in the program at which the debugger will stop the code from executing. Then, you can choose to 'step' through the program line by line to 'see' exactly what the CPU is doing. This way, you can effectively watch the program execute and discover where the problem is!<br />
----<br />
Lets set a breakpoint within the program so that we can see what is going on. Lets start by setting a breakpoint at line 43. Do this with the following command:<br />
(gdb) b 43<br />
You could also set a breakpoint to a specific functions call, such as:<br />
(gdb) b ComputeSeriesValue<br />
However, for the purpose of this tutorial, use the line number. If you wish, you can play around with using the function instead, but it will cause you to diverge from this tutorial.<br />
<br />
If the program outputs: No symbol table is loaded. Use the "file" command. Then use the following command:<br />
(gdb) file broken<br />
This will set the file so that you can add a breakpoint without error<br />
<br />
Line 43 is the following:<br />
double seriesValue = ComputeSeriesValue(x, n);<br />
So the program will stop executing immediately before it executes the function ComputeSeriesValue(x, n).<br />
<br />
Now, lets run the program with our command:<br />
(gdb) run<br />
Let's enter the values as x=2 and n=3, with an expected output value is 5. <br />
Here is a snapshot of what the program should output at this point:<br />
This program is used to compute the value of the following series : <br />
(x^0)/0! + (x^1)/1! + (x^2)/2! + (x^3)/3! + (x^4)/4! + ........ + (x^n)/n! <br />
Please enter the value of x : 2<br />
Please enter an integer value for n : 3<br />
Breakpoint 1, main () at broken.cpp:43<br />
43 double seriesValue = ComputeSeriesValue(x, n);<br />
The program has stopped at our breakpoint, line 43.<br />
<br />
===Stepping into a function===<br />
Next, we are going to step into the function ComputeSeriesValue(x, n)<br />
----<br />
Hint:<br />
'Stepping' through a function allows us to go line by line, and see exactly what lines of code are being executed. This way we can manually diagnose the computation problem.<br />
----<br />
To start stepping, issue the following command<br />
(gdb) step<br />
----<br />
Hint:<br />
A nice thing about the GDB Debugger is that it will save the last command you issued so that you don't need to type it over and over. This way you can keep stepping through the function by pressing <enter>. You do not need to retype 'step'<br />
----<br />
You should see the following outputted:<br />
ComputeSeriesValue (x=2, n=3) at broken.cpp:17<br />
17 double seriesValue=0.0;<br />
At this point, the program has gone to line 17, and is at the first line of the function ComputeSeriesValue, which sets the double seriesValue to 0.0.<br />
<br />
Now, we wish to use the 'next' function until we reach the function CompueFraction(). To do this, use the following commands:<br />
(gdb) next<br />
18 double xpow=1;<br />
(gdb) <enter><br />
20 for (int k = 0; k <= n; k++) {<br />
(gdb) <enter> <br />
21 seriesValue += xpow / ComputeFactorial(k) ;<br />
(gdb) step<br />
ComputeFactorial (number=0) at broken.cpp:7<br />
7 int fact=0;<br />
<br />
==Using Backtrace==<br />
*If you want to know where you are in the program's execution (and how, to some extent, you got there), you can view the contents of the stack using the backtrace command as follows:<br />
(gdb) bt<br />
#0 ComputeFactorial (number=0) at broken.cpp:7<br />
#1 0x08048907 in ComputeSeriesValue (x=3, n=2) at broken.cpp:21<br />
#2 0x08048a31 in main () at broken.cpp:43<br />
----<br />
Note: <br />
Backtrace lets you see where you have been and what you have done. In case, you get lost or confused it is very useful.<br />
----<br />
See the error?<br />
<br />
The print command (abbreviated p) reveals that the value of fact never changes. Note that the function is returning a value of 0 for the function call ComputeFactorial(number=0). This is an ERROR! The answer will always equal zero.<br />
<br />
By taking a closer look at the values printed above, we realize that we are computing fact=fact * j where fact has been initialized to 0, (0 = 0 * j); fact should have been initialized to 1. We quit GDB with the quit command. Next we need to change the following line:<br />
<br />
change the line<br />
int fact = 0;<br />
to<br />
int fact =1;<br />
and you're all set!<br />
<br />
==More Tutorial==<br />
For another tutorial see:<br />
http://www.cs.cmu.edu/~gilpin/tutorial/</div>JustinC474https://wiki.gumstix.com/index.php?title=Remote_Debugging_with_GDB&diff=4532Remote Debugging with GDB2010-08-06T16:32:33Z<p>JustinC474: </p>
<hr />
<div>In this tutorial we will go over how to perform a basic debugging with GDB, the GNU debugger. This environment allows us to debug C, C++ and Java (compiled to machine code, not for running in a Java Virtual Machine) programs.<br />
*We will complete these tasks step by step<br />
:*Install the GDB debugger<br />
:*Run the debugger<br />
:*Set Breakpoints<br />
:*Navigate the code in your program<br />
:*Diagnose an error and how to fix it<br />
<br />
*Required Items<br />
:*Overo COM with Expansion Board<br />
:*Mini B to Standard A Cable<br />
:*Bootable MicroSD card<br />
:*5V Power Supply<br />
<br />
*Required Reading (things you should know, or tutorials that explain)<br />
:*[[HelloWorld | HelloWorld in Python, C and C++]]<br />
:*[[Eclipse on Gumstix for new users | Eclipse Tutorial]]<br />
::*Although the majority of this tutorial pertains to debugging and C programming, it contains useful information which leads to basic understanding of your Overo COM<br />
<br />
==Installing the GDB Debugger==<br />
Before starting this, you should have Console access to your Overo COM and should know how to program and run a basic C++ program. If you do not know how to do this, see [[HelloWorld | HelloWorld in Python, C and C++]].<br />
<br />
If you haven't yet, install a C/C++ SDK with the following command<br />
opkg update <br />
opkg install task-native-sdk<br />
<br />
To install the GDB debugger, run the following command in your command line:<br />
opkg update<br />
opkg install gdb<br />
Once this has completed, you will have the GNU GDB debugger installed on your Overo COM<br />
<br />
==Creating the Test File==<br />
Now that we have the debugging environment<br />
<br />
Run the following in your command line:<br />
nano broken.cpp<br />
Then copy and paste the code from [http://cs.baylor.edu/~donahoo/tools/gdb/broken.cpp |Broken.cpp] into your shell. When you copy and paste there will be two syntax errors that you must fix at the lines:<br />
cout << "This program is used to compute the value of the following<br />
series : " << endl;<br />
and<br />
cout << "(x^0)/0! + (x^1)/1! + (x^2)/2! + (x^3)/3! + (x^4)/4! + ....<br />
.... + (x^n)/n! " << endl<br />
<br />
Copying and pasting added an extra line break to these two lines, and we want to undo this by deleting one space at the beginning of each second line so it looks like this:<br />
cout << "This program is used to compute the value of the following series : " << endl;<br />
and<br />
cout << "(x^0)/0! + (x^1)/1! + (x^2)/2! + (x^3)/3! + (x^4)/4! + ........ + (x^n)/n! " << endl<br />
<br />
Now save and exit by pressing the following:<br />
:*Ctrl + O<br />
:*<Enter><br />
:*Ctrl + X<br />
<br />
==Compile and Run broken.cpp==<br />
Now that we have our test file (broken.cpp) ready to go, it is time to run it. <br />
<br />
Compile the program to create an executable file (broken) by entering the following command:<br />
g++ -g broken.cpp -o broken<br />
The '-g' switch tells the compiler to include debugging symbols in the executable. Run the program as such:<br />
./broken<br />
----<br />
Note:<br />
Use 'g++ -g broken.cpp -o broken' to compile. If you use g++ -o, g++ --ggdb -Wall, or any other method of compilation the debugging will not follow this tutorial exactly.<br />
----<br />
<br />
Enter any numbers into the program for x and n. Run it a couple times, you should notice that the answer is always the same: infinity. This is obviously wrong.<br />
<br />
Consider: x=1, n=1<br />
(1^0)/0! + (1^1)/1!<br />
1/1 + 1/1<br />
2<br />
<br />
NOT infinity<br />
<br />
==Debugging the Program==<br />
Now, it is time that we debugged our program. <br />
<br />
First, you need to start the GDB environment by issuing the following command:<br />
gdb<br />
You should see the following command line appear:<br />
(gdb)<br />
Then, you need to 'tell' the debugger which file it is that we are debugging, do this by issuing the command:<br />
(gdb) exec-file broken<br />
Now, it is time to run our program by issuing the command:<br />
(gdb) run<br />
<br />
Notice that the program runs normally and again, gives us the answer inf. This is because the error we have is a computation error, and does not cause our program to crash. So, its time to set a Breakpoint in our program.<br />
<br />
===Setting a Breakpoint===<br />
----<br />
Hint:<br />
A breakpoint is a point in the program at which the debugger will stop the code from executing. Then, you can choose to 'step' through the program line by line to 'see' exactly what the CPU is doing. This way, you can effectively watch the program execute and discover where the problem is!<br />
----<br />
Lets set a breakpoint within the program so that we can see what is going on. Lets start by setting a breakpoint at line 43. Do this with the following command:<br />
(gdb) b 43<br />
----<br />
Note:<br />
If the program outputs: No symbol table is loaded. Use the "file" command. Then use the following command:<br />
(gdb) file broken<br />
This will set the file so that you can add a breakpoint without error<br />
----<br />
Line 43 is the following:<br />
double seriesValue = ComputeSeriesValue(x, n);<br />
So the program will stop executing immediately before it executes the function ComputeSeriesValue(x, n).<br />
<br />
Now, lets run the program with our command:<br />
(gdb) run<br />
Let's enter the values as x=2 and n=3, with an expected output value is 5. <br />
Here is a snapshot of what the program should output at this point:<br />
This program is used to compute the value of the following series : <br />
(x^0)/0! + (x^1)/1! + (x^2)/2! + (x^3)/3! + (x^4)/4! + ........ + (x^n)/n! <br />
Please enter the value of x : 2<br />
Please enter an integer value for n : 3<br />
Breakpoint 1, main () at broken.cpp:43<br />
43 double seriesValue = ComputeSeriesValue(x, n);<br />
The program has stopped at our breakpoint, line 43. <br />
<br />
===Stepping into a function===<br />
Next, we are going to step into the function ComputeSeriesValue(x, n)<br />
----<br />
Hint:<br />
'Stepping' through a function allows us to go line by line, and see exactly what lines of code are being executed. This way we can manually diagnose the computation problem.<br />
----<br />
To start stepping, issue the following command<br />
(gdb) step<br />
----<br />
Hint:<br />
A nice thing about the GDB Debugger is that it will save the last command you issued so that you don't need to type it over and over. This way you can keep stepping through the function by pressing <enter>. You do not need to retype 'step'<br />
----<br />
You should see the following outputted:<br />
ComputeSeriesValue (x=2, n=3) at broken.cpp:17<br />
17 double seriesValue=0.0;<br />
At this point, the program has gone to line 17, and is at the first line of the function ComputeSeriesValue, which sets the double seriesValue to 0.0.<br />
<br />
Now, we wish to use the 'next' function until we reach the function CompueFraction(). To do this, use the following commands:<br />
(gdb) next<br />
18 double xpow=1;<br />
(gdb) <enter><br />
20 for (int k = 0; k <= n; k++) {<br />
(gdb) <enter> <br />
21 seriesValue += xpow / ComputeFactorial(k) ;<br />
(gdb) step<br />
ComputeFactorial (number=0) at broken.cpp:7<br />
7 int fact=0;<br />
<br />
==Using Backtrace==<br />
*If you want to know where you are in the program's execution (and how, to some extent, you got there), you can view the contents of the stack using the backtrace command as follows:<br />
(gdb) bt<br />
#0 ComputeFactorial (number=0) at broken.cpp:7<br />
#1 0x08048907 in ComputeSeriesValue (x=3, n=2) at broken.cpp:21<br />
#2 0x08048a31 in main () at broken.cpp:43<br />
----<br />
Note: <br />
Backtrace lets you see where you have been and what you have done. In case, you get lost or confused it is very useful.<br />
----<br />
See the error?<br />
<br />
The print command (abbreviated p) reveals that the value of fact never changes. Note that the function is returning a value of 0 for the function call ComputeFactorial(number=0). This is an ERROR! The answer will always equal zero.<br />
<br />
By taking a closer look at the values printed above, we realize that we are computing fact=fact * j where fact has been initialized to 0, (0 = 0 * j); fact should have been initialized to 1. We quit GDB with the quit command. Next we need to change the following line:<br />
<br />
change the line<br />
int fact = 0;<br />
to<br />
int fact =1;<br />
and you're all set!<br />
<br />
==More Tutorial==<br />
For another tutorial see:<br />
http://www.cs.cmu.edu/~gilpin/tutorial/</div>JustinC474https://wiki.gumstix.com/index.php?title=Remote_Debugging_with_GDB&diff=4530Remote Debugging with GDB2010-08-06T16:20:23Z<p>JustinC474: </p>
<hr />
<div>In this tutorial we will go over how to perform a basic debugging with GDB, the GNU debugger. This environment allows us to debug C, C++ and Java (compiled to machine code, not for running in a Java Virtual Machine) programs.<br />
*We will complete these tasks step by step<br />
:*Install the GDB debugger<br />
:*Run the debugger<br />
:*Set Breakpoints<br />
:*Navigate the code in your program<br />
:*Diagnose an error and how to fix it<br />
<br />
*Required Items<br />
:*Overo COM with Expansion Board<br />
:*Mini B to Standard A Cable<br />
:*Bootable MicroSD card<br />
:*5V Power Supply<br />
<br />
*Required Reading (things you should know, or tutorials that explain)<br />
:*[[HelloWorld | HelloWorld in Python, C and C++]]<br />
:*[[Eclipse on Gumstix for new users | Eclipse Tutorial]]<br />
::*Although the majority of this tutorial pertains to debugging and C programming, it contains useful information which leads to basic understanding of your Overo COM<br />
<br />
==Installing the GDB Debugger==<br />
Before starting this, you should have Console access to your Overo COM and should know how to program and run a basic C++ program. If you do not know how to do this, see [[HelloWorld | HelloWorld in Python, C and C++]].<br />
<br />
To install the GDB debugger, run the following command in your command line:<br />
opkg update<br />
opkg install gdb<br />
Once this has completed, you will have the GNU GDB debugger installed on your Overo COM<br />
<br />
==Creating the Test File==<br />
Now that we have the debugging environment<br />
<br />
Run the following in your command line:<br />
nano broken.cpp<br />
Then copy and paste the code from [http://cs.baylor.edu/~donahoo/tools/gdb/broken.cpp |Broken.cpp] into your shell. When you copy and paste there will be two syntax errors that you must fix at the lines:<br />
cout << "This program is used to compute the value of the following<br />
series : " << endl;<br />
and<br />
cout << "(x^0)/0! + (x^1)/1! + (x^2)/2! + (x^3)/3! + (x^4)/4! + ....<br />
.... + (x^n)/n! " << endl<br />
<br />
Copying and pasting added an extra line break to these two lines, and we want to undo this by deleting one space at the beginning of each second line so it looks like this:<br />
cout << "This program is used to compute the value of the following series : " << endl;<br />
and<br />
cout << "(x^0)/0! + (x^1)/1! + (x^2)/2! + (x^3)/3! + (x^4)/4! + ........ + (x^n)/n! " << endl<br />
<br />
Now save and exit by pressing the following:<br />
:*Ctrl + O<br />
:*<Enter><br />
:*Ctrl + X<br />
<br />
==Compile and Run broken.cpp==<br />
Now that we have our test file (broken.cpp) ready to go, it is time to run it. <br />
<br />
Compile the program to create an executable file (broken) by entering the following command:<br />
g++ -g broken.cpp -o broken<br />
The '-g' switch tells the compiler to include debugging symbols in the executable. Run the program as such:<br />
./broken<br />
----<br />
Note:<br />
Use 'g++ -g broken.cpp -o broken' to compile. If you use g++ -o, g++ --ggdb -Wall, or any other method of compilation the debugging will not follow this tutorial exactly.<br />
----<br />
<br />
Enter any numbers into the program for x and n. Run it a couple times, you should notice that the answer is always the same: infinity. This is obviously wrong.<br />
<br />
Consider: x=1, n=1<br />
(1^0)/0! + (1^1)/1!<br />
1/1 + 1/1<br />
2<br />
<br />
NOT infinity<br />
<br />
==Debugging the Program==<br />
Now, it is time that we debugged our program. <br />
<br />
First, you need to start the GDB environment by issuing the following command:<br />
gdb<br />
You should see the following command line appear:<br />
(gdb)<br />
Then, you need to 'tell' the debugger which file it is that we are debugging, do this by issuing the command:<br />
(gdb) exec-file broken<br />
Now, it is time to run our program by issuing the command:<br />
(gdb) run<br />
<br />
Notice that the program runs normally and again, gives us the answer inf. This is because the error we have is a computation error, and does not cause our program to crash. So, its time to set a Breakpoint in our program.<br />
<br />
===Setting a Breakpoint===<br />
----<br />
Hint:<br />
A breakpoint is a point in the program at which the debugger will stop the code from executing. Then, you can choose to 'step' through the program line by line to 'see' exactly what the CPU is doing. This way, you can effectively watch the program execute and discover where the problem is!<br />
----<br />
Lets set a breakpoint within the program so that we can see what is going on. Lets start by setting a breakpoint at line 43. Do this with the following command:<br />
(gdb) b 43<br />
----<br />
Note:<br />
If the program outputs: No symbol table is loaded. Use the "file" command. Then use the following command:<br />
(gdb) file broken<br />
This will set the file so that you can add a breakpoint without error<br />
----<br />
Line 43 is the following:<br />
double seriesValue = ComputeSeriesValue(x, n);<br />
So the program will stop executing immediately before it executes the function ComputeSeriesValue(x, n).<br />
<br />
Now, lets run the program with our command:<br />
(gdb) run<br />
Let's enter the values as x=2 and n=3, with an expected output value is 5. <br />
Here is a snapshot of what the program should output at this point:<br />
This program is used to compute the value of the following series : <br />
(x^0)/0! + (x^1)/1! + (x^2)/2! + (x^3)/3! + (x^4)/4! + ........ + (x^n)/n! <br />
Please enter the value of x : 2<br />
Please enter an integer value for n : 3<br />
Breakpoint 1, main () at broken.cpp:43<br />
43 double seriesValue = ComputeSeriesValue(x, n);<br />
The program has stopped at our breakpoint, line 43. <br />
<br />
===Stepping into a function===<br />
Next, we are going to step into the function ComputeSeriesValue(x, n)<br />
----<br />
Hint:<br />
'Stepping' through a function allows us to go line by line, and see exactly what lines of code are being executed. This way we can manually diagnose the computation problem.<br />
----<br />
To start stepping, issue the following command<br />
(gdb) step<br />
----<br />
Hint:<br />
A nice thing about the GDB Debugger is that it will save the last command you issued so that you don't need to type it over and over. This way you can keep stepping through the function by pressing <enter>. You do not need to retype 'step'<br />
----<br />
You should see the following outputted:<br />
ComputeSeriesValue (x=2, n=3) at broken.cpp:17<br />
17 double seriesValue=0.0;<br />
At this point, the program has gone to line 17, and is at the first line of the function ComputeSeriesValue, which sets the double seriesValue to 0.0.<br />
<br />
Now, we wish to use the 'next' function until we reach the function CompueFraction(). To do this, use the following commands:<br />
(gdb) next<br />
18 double xpow=1;<br />
(gdb) <enter><br />
20 for (int k = 0; k <= n; k++) {<br />
(gdb) <enter> <br />
21 seriesValue += xpow / ComputeFactorial(k) ;<br />
(gdb) step<br />
ComputeFactorial (number=0) at broken.cpp:7<br />
7 int fact=0;<br />
<br />
==Using Backtrace==<br />
*If you want to know where you are in the program's execution (and how, to some extent, you got there), you can view the contents of the stack using the backtrace command as follows:<br />
(gdb) bt<br />
#0 ComputeFactorial (number=0) at broken.cpp:7<br />
#1 0x08048907 in ComputeSeriesValue (x=3, n=2) at broken.cpp:21<br />
#2 0x08048a31 in main () at broken.cpp:43<br />
----<br />
Note: <br />
Backtrace lets you see where you have been and what you have done. In case, you get lost or confused it is very useful.<br />
----<br />
See the error?<br />
<br />
The print command (abbreviated p) reveals that the value of fact never changes. Note that the function is returning a value of 0 for the function call ComputeFactorial(number=0). This is an ERROR! The answer will always equal zero.<br />
<br />
By taking a closer look at the values printed above, we realize that we are computing fact=fact * j where fact has been initialized to 0, (0 = 0 * j); fact should have been initialized to 1. We quit GDB with the quit command. Next we need to change the following line:<br />
<br />
change the line<br />
int fact = 0;<br />
to<br />
int fact =1;<br />
and you're all set!<br />
<br />
==More Tutorial==<br />
For another tutorial see:<br />
http://www.cs.cmu.edu/~gilpin/tutorial/</div>JustinC474https://wiki.gumstix.com/index.php?title=Minesweeper_in_Java&diff=4505Minesweeper in Java2010-08-05T22:07:58Z<p>JustinC474: </p>
<hr />
<div>This tutorial gives a brief overview of what to do to get a small, graphical Minesweeper game running on your Overo. If you have not done so, please go through the tutorials [[Eclipse on Gumstix for new users]] and [[HelloWorld in Java]].<br />
<br />
This does not explain the game of MineSweeper, rather just lets use utilize the code to see an example of the graphical possibilities using an Overo COM.<br />
<br />
*Create a new Project in Eclipse <br />
:*'''File -> New Project -> Java Project'''<br />
*Create a class '''Main Class'''<br />
:*Copy and paste the following code to that class:<br />
<pre> <br />
import java.awt.BorderLayout;<br />
import java.awt.Color;<br />
import java.awt.event.ActionEvent;<br />
import java.awt.event.ActionListener;<br />
<br />
import javax.swing.JButton;<br />
import javax.swing.JColorChooser;<br />
import javax.swing.JFrame;<br />
import javax.swing.JOptionPane;<br />
<br />
public class MainClass {<br />
public static void main(String args[]) {<br />
JFrame f = new JFrame("JColorChooser Sample");<br />
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);<br />
final JButton button = new JButton("Pick to Change Background");<br />
<br />
ActionListener actionListener = new ActionListener() {<br />
public void actionPerformed(ActionEvent actionEvent) {<br />
Color initialBackground = button.getBackground();<br />
Color background = JColorChooser.showDialog(null,<br />
"JColorChooser Sample", initialBackground);<br />
if (background != null) {<br />
button.setBackground(background);<br />
}<br />
}<br />
};<br />
button.addActionListener(actionListener);<br />
f.add(button, BorderLayout.CENTER);<br />
f.setSize(300, 200);<br />
f.setVisible(true);<br />
}<br />
<br />
}</pre><br />
*Create a class '''MineSweeper''' (Capital S!)<br />
:*Copy and paste the following code to that class:<br />
<pre>import java.awt.AWTEvent;<br />
import java.awt.BorderLayout;<br />
import java.awt.Color;<br />
import java.awt.Component;<br />
import java.awt.FlowLayout;<br />
import java.awt.GridLayout;<br />
import java.awt.Insets;<br />
import java.awt.Point;<br />
import java.awt.Toolkit;<br />
import java.awt.event.AWTEventListener;<br />
import java.awt.event.ActionEvent;<br />
import java.awt.event.ActionListener;<br />
import java.awt.event.KeyEvent;<br />
import java.awt.event.MouseAdapter;<br />
import java.awt.event.MouseEvent;<br />
import java.util.ArrayList;<br />
import java.util.List;<br />
import java.util.Random;<br />
<br />
import javax.swing.JButton;<br />
import javax.swing.JFrame;<br />
import javax.swing.JLabel;<br />
import javax.swing.JOptionPane;<br />
import javax.swing.JPanel;<br />
<br />
public class MineSweeper extends JPanel implements AWTEventListener, ActionListener {<br />
<br />
public static enum State {<br />
Clicked, Marked, Initial, WrongMarked<br />
}<br />
<br />
public static enum GameState {<br />
NotStarted, Playing, Finished<br />
}<br />
<br />
private static final int MAX_BOMB_COUNT = 10;<br />
private int ROWS = 9, COLUMNS = 9, TOTAL = ROWS * COLUMNS;<br />
private JPanel pnlMain = new JPanel(new GridLayout(ROWS, COLUMNS));<br />
private JLabel lblBombCount = new JLabel(MAX_BOMB_COUNT + "");<br />
private JLabel lblTimer = new JLabel("0");<br />
private boolean isColorCheatOn = false;<br />
private JButton btnReset = new JButton("Reset");<br />
<br />
private void startThread() {<br />
Thread th = new Thread(new Runnable() {<br />
public void run() {<br />
while (state == GameState.Playing) {<br />
lblTimer.setText((Long.parseLong(lblTimer.getText()) + 1) + "");<br />
lblTimer.updateUI();<br />
try {<br />
Thread.sleep(1000);<br />
} catch (InterruptedException e) {<br />
e.printStackTrace();<br />
}<br />
}<br />
}<br />
});<br />
th.start();<br />
}<br />
<br />
private GameState state = GameState.NotStarted;<br />
<br />
public MineSweeper() {<br />
setLayout(new BorderLayout());<br />
add(pnlMain, BorderLayout.CENTER);<br />
createButtons();<br />
addControlPanel();<br />
Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK);<br />
}<br />
<br />
private void showAbout() {<br />
JOptionPane.showMessageDialog(this, "<html>Author : Justin Cowles Cowperthwaite <br>Version : 1.0</html>", "About", JOptionPane.INFORMATION_MESSAGE);<br />
}<br />
<br />
private void restartGame() {<br />
state = GameState.NotStarted;<br />
lblTimer.setText("0");<br />
pnlMain.removeAll();<br />
createButtons();<br />
pnlMain.updateUI();<br />
lblBombCount.setText("" + MAX_BOMB_COUNT);<br />
lblBombCount.updateUI();<br />
}<br />
<br />
private void addControlPanel() {<br />
JPanel pnlTimer = new JPanel(new FlowLayout(FlowLayout.RIGHT));<br />
<br />
pnlTimer.add(lblTimer);<br />
<br />
JPanel pnl = new JPanel(new FlowLayout(FlowLayout.CENTER));<br />
<br />
btnReset.setToolTipText("<HTML>Press <B>F2</B> to reset the current game</HTML>");<br />
pnl.add(lblBombCount);<br />
pnl.add(btnReset);<br />
JPanel pnlN = new JPanel(new GridLayout(1, 3));<br />
<br />
pnlN.add(lblBombCount);<br />
pnlN.add(pnl);<br />
pnlN.add(pnlTimer);<br />
add(pnlN, BorderLayout.NORTH);<br />
btnReset.addActionListener(this);<br />
}<br />
<br />
private void createButtons() {<br />
List<Point> lstBombsLocation = new ArrayList<Point>();<br />
<br />
for (int row = 0; row < ROWS; row++) {<br />
for (int col = 0; col < COLUMNS; col++) {<br />
JButton btn = getButton(lstBombsLocation, TOTAL, new Point(row, col) {<br />
@Override<br />
public String toString() {<br />
return (int) getX() + ", " + (int) getY();<br />
}<br />
<br />
@Override<br />
public boolean equals(Object obj) {<br />
return ((Point) obj).getX() == getX() && ((Point) obj).getY() == getY();<br />
}<br />
});<br />
pnlMain.add(btn);<br />
}<br />
}<br />
while (lstBombsLocation.size() < MAX_BOMB_COUNT) {<br />
updateBomds(lstBombsLocation, pnlMain.getComponents());<br />
}<br />
for (Component c : pnlMain.getComponents()) {<br />
updateBombCount((GameButton) c, pnlMain.getComponents());<br />
}<br />
// System.out.println("Total Bomb Count: " + lstBombsLocation.size());<br />
}<br />
<br />
private void updateBomds(List<Point> lstBombsLocation, Component[] components) {<br />
// int currentPosition = new Double(((location.x) * COLUMNS ) +<br />
// location.getY()).intValue();<br />
Random r = new Random();<br />
for (Component c : components) {<br />
Point location = ((GameButton) c).getPosition();<br />
int currentPosition = new Double(((location.x) * COLUMNS) + location.getY()).intValue();<br />
int bombLocation = r.nextInt(TOTAL);<br />
if (bombLocation == currentPosition) {<br />
((GameButton) c).setBomb(true);<br />
lstBombsLocation.add(((GameButton) c).getPosition());<br />
return;<br />
}<br />
}<br />
}<br />
<br />
private GameButton getButton(List<Point> lstBombsLocation, int totalLocations, Point location) {<br />
GameButton btn = new GameButton(location);<br />
btn.setMargin(new Insets(0, 0, 0, 0));<br />
btn.setFocusable(false);<br />
if (lstBombsLocation.size() < MAX_BOMB_COUNT) {<br />
if (isBomb()) {<br />
btn.setBomb(true);<br />
lstBombsLocation.add(location);<br />
}<br />
}<br />
btn.addMouseListener(new MouseAdapter() {<br />
@Override<br />
public void mouseClicked(MouseEvent mouseEvent) {<br />
if (state != GameState.Playing) {<br />
state = GameState.Playing;<br />
startThread();<br />
}<br />
if (((GameButton) mouseEvent.getSource()).isEnabled() == false) {<br />
return;<br />
}<br />
if (mouseEvent.getButton() == MouseEvent.BUTTON1) {<br />
if (((GameButton) mouseEvent.getSource()).getState() == State.Marked) {<br />
((GameButton) mouseEvent.getSource()).setState(State.Initial);<br />
lblBombCount.setText((Long.parseLong(lblBombCount.getText()) + 1) + "");<br />
((GameButton) mouseEvent.getSource()).updateUI();<br />
return;<br />
}<br />
((GameButton) mouseEvent.getSource()).setState(State.Clicked);<br />
if (((GameButton) mouseEvent.getSource()).isBomb()) {<br />
blastBombs();<br />
return;<br />
} else {<br />
if (((GameButton) mouseEvent.getSource()).getBombCount() == 0) {<br />
updateSurroundingZeros(((GameButton) mouseEvent.getSource()).getPosition());<br />
}<br />
}<br />
if (!checkGameState()) {<br />
((GameButton) mouseEvent.getSource()).setEnabled(false);<br />
}<br />
} else if (mouseEvent.getButton() == MouseEvent.BUTTON3) {<br />
if (((GameButton) mouseEvent.getSource()).getState() == State.Marked) {<br />
((GameButton) mouseEvent.getSource()).setState(State.Initial);<br />
lblBombCount.setText((Long.parseLong(lblBombCount.getText()) + 1) + "");<br />
} else {<br />
((GameButton) mouseEvent.getSource()).setState(State.Marked);<br />
lblBombCount.setText((Long.parseLong(lblBombCount.getText()) - 1) + "");<br />
}<br />
}<br />
((GameButton) mouseEvent.getSource()).updateUI();<br />
}<br />
});<br />
return btn;<br />
}<br />
<br />
private boolean checkGameState() {<br />
boolean isWin = false;<br />
for (Component c : pnlMain.getComponents()) {<br />
GameButton b = (GameButton) c;<br />
if (b.getState() != State.Clicked) {<br />
if (b.isBomb()) {<br />
isWin = true;<br />
} else {<br />
return false;<br />
}<br />
}<br />
}<br />
if (isWin) {<br />
state = GameState.Finished;<br />
for (Component c : pnlMain.getComponents()) {<br />
GameButton b = (GameButton) c;<br />
if (b.isBomb()) {<br />
b.setState(State.Marked);<br />
}<br />
b.setEnabled(false);<br />
<br />
}<br />
JOptionPane.showMessageDialog(this, "You win the game :D", "Congrats", JOptionPane.INFORMATION_MESSAGE, null);<br />
}<br />
return isWin;<br />
}<br />
<br />
private void updateSurroundingZeros(Point currentPoint) {<br />
Point[] points = getSurroundings(currentPoint);<br />
<br />
for (Point p : points) {<br />
GameButton b = getButtonAt(pnlMain.getComponents(), p);<br />
if (b != null && b.getBombCount() == 0 && b.getState() != State.Clicked && b.getState() != State.Marked && b.isBomb() == false) {<br />
b.setState(State.Clicked);<br />
updateSurroundingZeros(b.getPosition());<br />
b.updateUI();<br />
}<br />
if (b != null && b.getBombCount() > 0 && b.getState() != State.Clicked && b.getState() != State.Marked && b.isBomb() == false) {<br />
b.setEnabled(false);<br />
b.setState(State.Clicked);<br />
b.updateUI();<br />
}<br />
}<br />
}<br />
<br />
private void blastBombs() {<br />
int blastCount = 0;<br />
for (Component c : pnlMain.getComponents()) {<br />
((GameButton) c).setEnabled(false);<br />
((GameButton) c).transferFocus();<br />
if (((GameButton) c).isBomb() && ((GameButton) c).getState() != State.Marked) {<br />
((GameButton) c).setState(State.Clicked);<br />
((GameButton) c).updateUI();<br />
blastCount++;<br />
}<br />
if (((GameButton) c).isBomb() == false && ((GameButton) c).getState() == State.Marked) {<br />
((GameButton) c).setState(State.WrongMarked);<br />
}<br />
}<br />
lblBombCount.setText("" + blastCount);<br />
lblBombCount.updateUI();<br />
state = GameState.Finished;<br />
JOptionPane.showMessageDialog(this, "You loose the game :(", "Game Over", JOptionPane.ERROR_MESSAGE, null);<br />
for (Component c : pnlMain.getComponents()) {<br />
GameButton b = (GameButton) c;<br />
b.setEnabled(false);<br />
}<br />
}<br />
<br />
private boolean isBomb() {<br />
Random r = new Random();<br />
return r.nextInt(ROWS) == 1;<br />
}<br />
<br />
public static void main(String[] args) {<br />
JFrame fr = new JFrame("MineSweeper");<br />
fr.setLayout(new BorderLayout());<br />
fr.add(new MineSweeper());<br />
fr.setResizable(false);<br />
fr.setSize(250, 350);<br />
fr.setLocationRelativeTo(null);<br />
fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);<br />
fr.setVisible(true);<br />
}<br />
<br />
class GameButton extends JButton {<br />
private boolean isBomb = false;<br />
private Point position = null;<br />
private int bombCount = 0;<br />
private State state = State.Initial;<br />
<br />
public void setState(State state) {<br />
this.state = state;<br />
if (getBombCount() == 0 && !isBomb) {<br />
setEnabled(false);<br />
}<br />
}<br />
<br />
public State getState() {<br />
return state;<br />
}<br />
<br />
public int getBombCount() {<br />
return bombCount;<br />
}<br />
<br />
public void setBombCount(int bombCount) {<br />
this.bombCount = bombCount;<br />
}<br />
<br />
public GameButton(Point position) {<br />
setPosition(position);<br />
setText(position.toString());<br />
}<br />
<br />
public Point getPosition() {<br />
return position;<br />
}<br />
<br />
public void setPosition(Point position) {<br />
this.position = position;<br />
}<br />
<br />
public boolean isBomb() {<br />
return isBomb;<br />
}<br />
<br />
public void setBomb(boolean isBomb) {<br />
this.isBomb = isBomb;<br />
}<br />
<br />
@Override<br />
public String getText() {<br />
if (state == State.Initial) {<br />
return "";<br />
}<br />
if (state == State.Marked) {<br />
return "\u00B6";<br />
}<br />
if (state == State.Clicked) {<br />
if (isBomb) {<br />
return "<html><font size='16'><b>*</b></font></html>";<br />
} else {<br />
if (getBombCount() > 0)<br />
return getBombCount() + "";<br />
else<br />
return "";<br />
}<br />
}<br />
if (state == State.WrongMarked) {<br />
return "X";<br />
}<br />
return super.getText();<br />
}<br />
<br />
@Override<br />
public Color getBackground() {<br />
if (isColorCheatOn && isBomb) {<br />
return Color.MAGENTA;<br />
}<br />
if (state == State.Clicked) {<br />
if (isBomb) {<br />
return Color.RED;<br />
}<br />
if (getBombCount() > 0) {<br />
return Color.GREEN;<br />
}<br />
}<br />
if (isEnabled()) {<br />
return Color.YELLOW.brighter();<br />
} else {<br />
return super.getBackground();<br />
}<br />
}<br />
}<br />
<br />
private Point[] getSurroundings(Point cPoint) {<br />
int cX = (int) cPoint.getX();<br />
int cY = (int) cPoint.getY();<br />
Point[] points = { new Point(cX - 1, cY - 1), new Point(cX - 1, cY), new Point(cX - 1, cY + 1), new Point(cX, cY - 1), new Point(cX, cY + 1), <br />
new Point(cX + 1, cY - 1), new Point(cX + 1, cY), new Point(cX + 1, cY + 1) };<br />
return points;<br />
}<br />
<br />
private void updateBombCount(GameButton btn, Component[] components) {<br />
Point[] points = getSurroundings(btn.getPosition());<br />
<br />
for (Point p : points) {<br />
GameButton b = getButtonAt(components, p);<br />
if (b != null && b.isBomb()) {<br />
btn.setBombCount(btn.getBombCount() + 1);<br />
}<br />
}<br />
btn.setText(btn.getBombCount() + "");<br />
}<br />
<br />
private GameButton getButtonAt(Component[] components, Point position) {<br />
for (Component btn : components) {<br />
if ((((GameButton) btn).getPosition().equals(position))) {<br />
return (GameButton) btn;<br />
}<br />
}<br />
return null;<br />
}<br />
<br />
public void eventDispatched(AWTEvent event) {<br />
if (KeyEvent.class.isInstance(event) && ((KeyEvent) (event)).getID() == KeyEvent.KEY_RELEASED) {<br />
if (((KeyEvent) (event)).getKeyCode() == KeyEvent.VK_F1) {<br />
showAbout();<br />
}<br />
if (((KeyEvent) (event)).getKeyCode() == KeyEvent.VK_F2) {<br />
restartGame();<br />
}<br />
if (((KeyEvent) (event)).getKeyCode() == KeyEvent.VK_F3) {<br />
isColorCheatOn = !isColorCheatOn;<br />
if (state == GameState.Playing) {<br />
pnlMain.updateUI();<br />
}<br />
}<br />
<br />
if (((KeyEvent) (event)).getKeyCode() == KeyEvent.VK_F12) {<br />
for (Component c : pnlMain.getComponents()) {<br />
GameButton b = (GameButton) c;<br />
if (b.isBomb() == false) {<br />
b.setState(State.Clicked);<br />
} else {<br />
b.setState(State.Marked);<br />
}<br />
b.setEnabled(false);<br />
}<br />
checkGameState();<br />
}<br />
}<br />
}<br />
<br />
public void actionPerformed(ActionEvent actionEvent) {<br />
if (actionEvent.getSource() == btnReset) {<br />
restartGame();<br />
}<br />
}<br />
}</pre><br />
<br />
Go back to [[HelloWorld in Java]] and follow the instructions for Exporting and Running a Java Program on the Over COM. When you are done, you should be able to play a 9x10 colorful game of MineSweeper on the monitor connected to your Overo COM expansion board.</div>JustinC474https://wiki.gumstix.com/index.php?title=Eclipse_on_Gumstix_for_new_users&diff=4504Eclipse on Gumstix for new users2010-08-05T21:56:38Z<p>JustinC474: </p>
<hr />
<div>This guide provides step-by-step instructions for using the Eclipse Integrated Development Environment (IDE) to develop applications for the Gumstix COMs.<br />
<br />
We'll walk through these tasks:<br />
:* setting up Eclipse<br />
:* connection to your Gumstix system<br />
:* creating a simple "Hello, World!" Python program<br />
:* running a web server<br />
:* installing new packages on your Gumstix<br />
:* creating a small graphical Java application<br />
:* remote debugging of your Java application<br />
:* natively-compiling C/C++ code on your Gumstix<br />
:* remote debugging C/C++ using the GDB server interface<br />
<br />
We will also explain how to set up a cross-compilation toolchain so you can develop C/C++ applications on your development computer and upload them to your Gumstix.<br />
<br />
Remember, Gumstix COMs are fully-fledged, albeit tiny, Linux systems so there are many tools we don't cover here. For example, [http://wiki.openembedded.net/index.php/OpenEmbedded_Tools_for_Eclipse_(OTE) this document] explains how to use the powerful OpenEmbedded build system within Eclipse.<br />
<br />
Required Tools:<br />
:* any Windows, Apple or Linux computer with a USB port<br />
:* recent version of the Java Runtime Environment (available [http://java.sun.com/javase/downloads/index.jsp here])<br />
:* a Gumstix COM running [http://www.gumstix.net/Setup-and-Programming/view/Overo-Setup-and-Programming/Downloading-pre-built-images/111.html up-to-date software]<br />
:* any expansion board of the Gumstix Overo series, such as Chestnut or Tobi, that has both a USB console port and a 10/100 <br />
:* Ethernet jack<br />
:* a 5V power supply<br />
:* an ethernet cable and internet connection<br />
:* a mini-A to Standard-A USB cable<br />
:* a [http://www.gumstix.net/Setup-and-Programming/view/Overo-Setup-and-Programming/Creating-a-bootable-microSD-card/111.html bootable microSD card] (only needed for native C/C++ compilation)<br />
<br />
Key Idea:<br />
[[File:GumstixEclipse1.jpg|thumb|right|upright=5]]<br />
<br />
==Download Eclipse==<br />
[http://www.eclipse.org/downloads/ Download] the Eclipse IDE for Java Developers for your Operating System: www.eclipse.org<br />
<br />
[[Image: GumstixEclipse2.jpg | center | 600px]]<br />
<br />
<br />
:* it is ''not'' necessary to install the Eclipse software; just double-click on the application once it has finished downloading<br />
:* when prompted, choose a workspace folder in which you want to store your projects and your configuration information<br />
:* then click through to the Eclipse workbench itself<br />
<br />
==Install Plugins==<br />
For developers, a great variety of additional features can be added to Eclipse from various repositories of plug-ins known as ''Update Sites''.<br />
To install a new plugin in Eclipse, first select the ''Update Site''.<br />
:* navigate to '''Help->Install New Software...'''<br />
:* select the Update Site for your version of Eclipse from the "Work with"dropdown menu<br />
<br />
[[File:GumstixEclipse3.jpg | center | 1000px]]<br />
<br />
:Note: If you are not sure which version of Eclipse you have, you can check by reopening Eclipse, it will be displayed on the loading screen.<br />
<br />
----<br />
Hint:<br />
If the update site is not available, you can add it by clicking the 'Add...' button on the right. For the Galileo release, you can use the URL http://dowload.eclipse.org/releases/galileo<br />
----<br />
<br />
As we are working with a remote system, we'll install the Remote System Explorer plugin.<br />
:* search for the ''Remote System Explorer End-User Runtime'' plugin<br />
:* select it for installation<br />
<br />
[[File:GumstixEclipse4.jpg | center | 600px]]<br />
<br />
Still in Eclipse,<br />
:* select "Next".... twice<br />
:* select the radio button to "ACCEPT" the terms of the license agreement<br />
:* choose "Yes" to restart Eclipse for the changes to take effect<br />
<br />
Once Eclipse has restarted, let's add two other useful plugins that allow connection to the console port of our Gumstix without needing a terminal emulator program such as kermit or TeraTerm.<br />
From within Eclipse,<br />
:* navigate to '''Help->Install New Software'''<br />
:* search on "Target" to find the ''Target Manager Terminal''<br />
<br />
[[File:GumstixEclipse5.jpg | center | 1000px]]<br />
<br />
:* select the ''Target Manager Terminal''<br />
:* click "Next"<br />
:* click "Finish" to complete installation<br />
:* choose "Yes" to restart Eclipse for the changes to take effect<br />
<br />
We'll also need to add a new update site by doing these steps in Eclipse:<br />
:* navigate to '''Help->Install New Software...'''<br />
:* click the "Add..." button<br />
:* type ''http://rxtx.qbang.org/eclipse'' into the ''Location'' field and create a name<br />
<br />
[[File:GumstixEclipse6.jpg | center | 1000px]]<br />
<br />
:* Click the "OK" button<br />
Go into the sub-directory as shown below to select the ''RXTX End-User Runtime'' plugin that this site provides.<br />
<br />
[[File:GumstixEclipse7.jpg | center | 1000px]]<br />
<br />
:* click "Next" twice<br />
:* select the radio button to "ACCEPT" the terms of the license agreement<br />
:* click "OK" at the security warning window<br />
:* click "Finish" to complete installation<br />
:* choose the "Yes" button to restart Eclipse for the changes to take effect<br />
<br />
==Connect Your Gumstix==<br />
Now it is time to connect your Gumstix---let's get started by establishing a console connection.<br />
:* mount your Gumstix COM down on to your expansion board<br />
:* plug the mini-A USB plug into the port marked CONSOLE and end of the cable into a standard USB port on your computer<br />
----<br />
Hint:<br />
Your computer should detect your Gumstix system when you first connect the USB cable, even though the power is not yet turned on. On Macintosh and Windows systems, a pop-up window should appear instructing you to download a new driver (do so) or notifying you that a USBserial device has been detected. If not, you can download drivers from [http://www.ftdichip.com/FTDrivers.htm this site]. Choose the "VCP" driver.<br />
Once you have downloaded this driver, make sure to unplug and then replug the USB cable running from your computer to your Gumstix expansion board so the Gumstix will be recognized by your computer.<br />
----<br />
:* connect your Gumstix to the internet using an ethernet cable<br />
NOTE: You still have NOT plugged the power cable in to the <br />
Gumstix expansion board! This diagram shows the locations<br />
of the USB 'CONSOLE' port and the 'POWER' input port on a <br />
Summit board on which an Overo COM has been mounted.<br />
<br />
[[File:GumstixEclipse8.jpg | center ]]<br />
<br />
:* if you are booting from a microSD card, insert this card now until you hear it click in place.<br />
Before applying power to the board, let's open up a connection to the console port.<br />
In Eclipse,<br />
:* navigate to '''Window->Show View->Other->Terminal->Terminal'''<br />
:* click on the 'N' connection icon in the window that appears<br />
<br />
[[File:GumstixEclipse9.jpg | center ]]<br />
<br />
:* make the connection using the following settings:<br />
Connection Type: Serial<br />
Port: <port to which your Gumstix is connected><br />
Baud Rate: 115200<br />
Data Bits: 8<br />
Stop Bits: 1<br />
Parity: none<br />
Flow Control: none<br />
Timeout: 5<br />
<br />
----<br />
Hint:<br />
The port to which your Gumstix is connected will have a different name depending on your Host operating system.<br />
:* On Windows, it should be ''USB-COM''<br />
:* On Macintosh, it should be ''/dev/tty.usbserial-xxxxxxxx'' where ''xxxxxxxx'' is an arbitrary string of characters<br />
:* On Linux, it should be ''/dev/ttyUSBx'' where ''x'' is a number.<br />
----<br />
<br />
[[File:GumstixEclipse10.jpg | center | 800px]]<br />
<br />
----<br />
Hint:<br />
If this does not work, or you wish to gain Console access via a *nix Shell instead, visit the tutorial on [[Gaining Console Connection via Terminal]]<br />
----<br />
<br />
*Now, it's time to apply power to the Gumstix expansion board so plug the 5V wall adapter into the power input jack on the Gumstix.<br />
<br />
You should see text appear in this window; for now, just let the Gumstix boot. When prompted, you can log in to the root account. The default credentials are:<br />
<br />
'''Overo'''<br />
<br />
username: root<br />
<br />
password: <leave blank><br />
<br />
<br />
'''VerdexPro'''<br />
<br />
username: root<br />
<br />
password: gumstix<br />
<br />
==Create a Web Site==<br />
Each Gumstix comes with a built-in package manager called opkg. A package manager is a useful tool for installing software; you can install everything from media players to GPS mapping tools to the Firefox web browser. In this example, you'll use opkg tool to install a new application for your Gumstix: the Apache web server.<br />
<br />
To make your own Gumstix web site, type the following in the terminal window:<br />
opkg update <Enter><br />
opkg install apache2 <Enter><br />
Before you start using Apache, which is now running, you'll need to find the IP address (internet address) of your Gumstix COM. To do this, type the following command into the terminal window:<br />
ifconfig | grep 'inet addr' <Enter><br />
You should see something like this appear on your screen.<br />
inet addr: 10.0.1.73 Bcast: 192.168.0.255 Mask: 255.255.255.0<br />
The IP address of your Gumstix is the first address shown: ''10.0.1.73'' in this case.<br />
Now,<br />
:* open up a web browser on your host computer<br />
:* type that IP address of your Gumstix into the address bar<br />
You should see something like this which is the default web site for Apache running on your Gumstix.<br />
<br />
[[File:GumstixEclipse11.jpg]]<br />
<br />
To make your web site say something more interesting, do the follow in your terminal window:<br />
:* type: ''nano /usr/share/apache2/htdocs/index.html''<br />
:* replace the words at the top of the screen "It Works" with the words "Gumstix Rocks!"<br />
:* press 'Ctrl+O' <Enter><br />
:* press 'Ctrl+X' to save and exit<br />
:* refresh your web browser<br />
<br />
==Write a Java Application==<br />
So far, you haven't actually used Eclipse other than as a console interface for your Gumstix. It is time to harness the power of Eclipse to write a small graphical Java application.<br />
In Eclipse.<br />
:* Navigate to '''File-> New-> Java Project''',<br />
:* Name the project ''gumstix-java''<br />
:* Select "Finish"<br />
Once the project is created,<br />
:* Select '''File->New->Class'''<br />
:* Name your class ''Hello''<br />
:* click "FINISH"<br />
<br />
Add the following code to your class:<br />
<br />
import javax.swing.JFrame;<br />
import javax.swing.JLabel;<br />
public class Hello {<br />
public static void main(String [] args) {<br />
JFrame frame = new JFrame("hello");<br />
final JLabel label = new JLabel("hello from Gumstix");<br />
frame.getContentPane().add(label);<br />
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);<br />
frame.pack();<br />
frame.setVisible(true);<br />
}<br />
}<br />
<br />
You should get something that looks like this:<br />
<br />
[[File:GumstixEclipse12.jpg | center | 600px]]<br />
<br />
Press the green run button to test drive our application on our host machine.<br />
<br />
----<br />
Hint:<br />
Eclipse has many auto-completion features. Simply typing /:*<Enter> before a class creates a standard documentation block. Likewise, pressing <Ctrl>+<Space> provides context specific auto-completion options. Many other hints for speedy development are explained in the tutorials [http://www.eclipse.org/resources/?category=Getting%20Started here].<br />
----<br />
<br />
==Upload Code==<br />
In Step 5 we discovered the IP address of our Gumstix. With this, we can connect to our Gumstix using the SSH protocol which allows us to rapidly transfer files. For this step, navigate to '''Window->Open Perspective->Other->Remote System Explorer''' and click on the connection icon in the ''Remote Systems'' panel on the left. Select ''SSH without shells'' as the connection type and press Next. Put the internet address you found in Step 5 into the field marked ''Host Name'' and hit finish. To test that everything is working correctly, right-click on the terminal item list under your new connection and select ''Launch Terminal''. A console interface exactly like the USB console interface we set up in Step 3 should pop up.<br />
<br />
<br />
----<br />
Hint:<br />
A 'Perspective' is an arrangement of windows and widgets, that is a specific view of the Eclipse workspace, designed for a particular task. If you wish to focus on any particular widget, double click the tab in Eclipse; return to the previous view by double-clicking again.<br />
----<br />
<br />
<br />
By installing the VNC viewer plugin, we can get a graphical interface to our Gumstix system. Do this by adding the ''Tools for mobile linux runtime'' plugin ('''Help->Install New Software''') from the main update site. To use, select the VNC viewer widget from '''Window->Show View->Other->VNC Category->VNC''' and click on the ''New Connection'' icon in the VNC Viewer panel. Again, the ''Host'' is the internet address of your Gumstix board.<br />
<br />
[[File:GumstixEclipse13.jpg | center | 800px]]<br />
<br />
Finally, we need to upload our java code before we can run it. Switch back to the Java Perspective ('''Window->Open Perspective->Java''') and right-click on our Java file and selecting Export. Choose the option to export file to a remote file system and choose to upload your ''Hello.class'' file.<br />
<br />
[[File:GumstixEclipse14.jpg | center | 600px]]<br />
<br />
You will need to ''Browse'' to find your Gumstix board; you should upload this code to your home directory on the Gumstix.<br />
<br />
==Debug a Java Application==<br />
We can debug our java application remotely from Eclipse. To do this, we need a Java Virtual Machine capable of doing debugging. This time, the package we need isn't available in our package sources however we can fetch the package directly from a web site and install it using the same opkg package management tool.<br />
wget http://bugcommunity.com/downloads/files/phonemeadvanced- personal-debug_mr2-r1_armv6.ipk <Enter><br />
opkg install -force-depends phoneme-advanced-personaldebug_mr2-r1_armv6.ipk <Enter><br />
Let's also update our Java libraries so we have access to the standard graphical libraries.<br />
opkg install classpath-gtk <Enter><br />
Next, let's start our Java code in debugging mode on the Overo:<br />
java-cdc -Xdebug -Xrunjwdp:transport=dHt_socket,server=y,suspend=y,address=1234 Hello <Enter><br />
Finally, let's connect to our debugging session by navigating in Eclipse to '''Run->Debug Configurations''' and double-clicking on Remote Java Application to create a new configuration. Fill in the form as shown below using the internet address found in the previous step.<br />
<br />
==Install a native C/C++ SDK==<br />
When we discussed Python and Java we noted that both are interpreted languages--- neither needs to be compiled. C and C++ code requires compilation which can be done natively---on the Gumstix itself---or on a development machine using a cross-compiler. To do native compilation, you need to install a compiler as well as any required libraries. You'll need to be booting from a microSD card as this installation takes approximately 75MB of space.<br />
$ echo 'src/gz angstrom-base http://www.angstromdistribution.org/feeds/unstable/ipk/glibc/armv7a/base' > /etc/opkg/angstrom-base.conf<br />
$ opkg update<br />
$ opkg install task-native-sdk<br />
Firstly, we are adding a new package repository to our package manager and updating our list of available packages before actually installing the complete package needed to do native development.<br />
<br />
Let's create either of the following files in Eclipse, upload the code and then compile on the Gumstix using our newly installed compiler.<br />
<br />
===C++: HelloWorld.cpp===<br />
#include <iostream><br />
using namespace std;<br />
int main () {<br />
cout << "Gumstix runs on C++" << endl;<br />
return 0;<br />
}<br />
<br />
Save the file and issue the following commands to compile and run HelloWorld.cpp<br />
g++ -o hello hello.cpp <enter><br />
Gumstix runs on C++ <enter><br />
<br />
===C: HelloWorld.c===<br />
#include <stdio.h><br />
int main () {<br />
printf("Gumstix runs on C\n");<br />
return 0;<br />
}<br />
<br />
Save the file and issue the following commands to compile and run HelloWorld.c<br />
gcc -o hello hello.c<br />
Gumstix runs on C<br />
<br />
<TODO: More exciting examples using on-board LEDs.><br />
<br />
==Using GDB as a remote debugger in C/C++==<br />
These instructions will teach you how to download, install, and use the GDB debugger remotely on your Overo COM.<br />
<br />
<pre>NOTE: <br />
remote system - a device that is being operated remotely (via SSH, USB Serial, etc). This means that it is a device that you are operating from a different system <br />
(ie: if you are accessing the Overo COM via connection with your PC, then the Overo COM is a remote system).<br />
For the purpose of this guide, the Overo COM will be the remote system.<br />
<br />
local host - the device that is being used to work on (ie: If you are working on your PC, that is the local host. If you then connect to another computer via VNC, <br />
that is a remote system, and you laptop is still the localhost).<br />
For the purpose of this guide, your Personal Computer will be the local host.</pre><br />
<br />
Before starting, it is important to note there are many different ways to run a remote debugger. The most fundamental choice when debugging remotely is whether you want to:<br />
:*Run the debugger on the remote system or<br />
:*Run the debugger on the local host with a cross debugger on the remote system<br />
<br />
This guide will teach you how to download, install, and run the debugger on the remote system (choice A). If you wish to learn more about the cross debugger option, use Google. Also the wikipedia article on cross compilers (which operate in a very similar fashion) is very good, albeit a bit complicated. None of this is necessary in understanding the contents of this guide. <br />
<br />
For the purposes of this guide, we will be using the GDB: the GNU project debugger. As stated on their website:<br />
<br />
<pre>GDB, the GNU Project debugger, allows you to see what is going on `inside' another program while it executes -- or what another program was doing at the moment it <br />
crashed.<br />
<br />
GDB can do four main kinds of things (plus other things in support of these) to help you catch bugs in the act:<br />
- Start your program, specifying anything that might affect its behavior.<br />
- Make your program stop on specified conditions.<br />
- Examine what has happened, when your program has stopped.<br />
- Change things in your program, so you can experiment with correcting the effects of one bug and go on to learn about another.</pre><br />
<br />
While the reasons for using a debugger instead of trying to debug with the ‘brute force’ method of adding print statements throughout the entire program are enumerable, there are a few that stand out:<br />
# The ability to ‘step’ through a program<br />
#* The GDB debugger allows you to ‘step’ through a program. This means that instead of just executing the program and then leaving you with a final error message, it will execute one line at a time until the program crashes. This allows the user to see exactly where, and why, the program crashed. <br />
# The ability to set breakpoints<br />
#* The GDB debugger allows you to set breakpoints in the program. These are points where the CPU will stop executing the code and allow the user to decide whether to continue. This allows the user to explore what is ‘going on’ at certain points in the execution, something that otherwise is not possible. <br />
# The ability to look at the Backtrace<br />
#* This will show you where, and exactly why, your program crashed. Although SEGFAULT isn’t very useful, the backtrace will tell you what caused the SEGFAULT. Everything from what line, what variable, and even the address that variable was at.<br />
<br />
===Installing the GDB===<br />
Once the Overo COM has been connected to the local host, you should have access to the following command line:<br />
<pre>root@overo:~# </pre><br />
Although you are working on your local host, this command line is for the remote system. It is the same as if you opened up Terminal (for Mac, Linux) or XTerm (for Windows). You now have access and control of the remote system.<br />
<br />
Now there are some packages that must be downloaded and installed onto the Overo so that it can run the GDB environment. To do this issue the following command:<br />
<pre>opkg update <enter><br />
opkg install gdb <enter></pre><br />
This should spew out a bunch of text such as:<br />
<pre>Downloading http://www.angstrom...</pre><br />
Just let it run and once its done, you’ll have the GNU GDB debugger installed on your Overo COM.<br />
<br />
===Creating a C/C++ Program to Debug===<br />
Now, your Overo COM has a debugger installed and ready to use. However, this does not mean you are ready to go. There are two more things required before it is possible to use a GDB debugger.<br />
:* A C/C++ program<br />
:* A SDK to run the program on<br />
To see how to install a SDK and write/run a simple program in C/C++, see [[#Install a native C/C++ SDK]]. <br />
<br />
Once you have a program ready, you first must create an executable file. Lets use for example the C++ program HelloWorld.cpp. To create the executable file HelloWorld, issue the following command:<br />
<pre>g++ -o HelloWorld HelloWorld.cpp <enter></pre><br />
Now, to run the program:<br />
<pre>./HelloWorld <enter></pre><br />
To do the same thing with a C program (HelloWorld.c), issue the command<br />
<pre>gcc -o HelloWorld HelloWorld.c <enter></pre><br />
<pre>./HelloWorld <enter></pre><br />
<br />
What this command does is uses the GNU compiler (either g++ or gcc) and creates an executable object (HelloWorld) out of the C or C++ program file (either HelloWorld.cpp or HelloWorld.c). You may name the executable whatever you like, but it is considered best practice to name it the same thing as the program file.<br />
<br />
===Debugging the Program===<br />
Now that you have GDB installed and a C/C++ program ready to go, its time to debug. To open to GDB environment, run the following command<br />
<pre>gdb <enter></pre><br />
Some text should spit out, and the following command line should appear<br />
<pre>(gdb)</pre><br />
Now that the debugger is running, it is time to tell the debugger what program we want to debug. To do this, first we need to declare our HelloWorld file as an executable file. For this run the following command <br />
<pre>(gdb) exec-file HelloWorld <enter></pre><br />
Now that we have an executable file ready to be debugged, its time to run the program<br />
<pre>(gdb) run HelloWorld <enter></pre><br />
The debugger will now run your program. If the program has no syntax or logic errors, the program should run and end with the line:<br />
Program exited normally.<br />
If there are errors, or the program crashed, it is possible to extract the exact details of that crash by issuing the back trace command.<br />
<pre>(gdb) bt <enter></pre><br />
Once you are done you can quit by issuing the command:<br />
<pre>(gdb) quit <enter></pre><br />
<br />
A complete list of commands in GDB:<br />
www.yolinux.com/TUTORIALS/GDB-Commands.html<br />
<br />
====GDB Debugger Tutorial====<br />
For a complete GDB Debugger tutorial (very good tutorial, comes with sample code they walk you through and extra errors for you to debug yourself!):<br />
http://www.cs.cmu.edu/~gilpin/tutorial/<br />
<br />
Now you have a debugger up and running! Play around with it by putting errors into your program on purpose to see the powers of having a remote debugger!<br />
<br />
==Use a C/C++ cross-compiler==<br />
In order to do C/C++ development on our host machine, we need to add in a plugin to Eclipse. Also, we need to download an appropriate cross-compilation toolchain. For now, I recommend the lovely instructions from<br />
<br />
http://www.designarm.com/quickstart-guide/linux-software/eclipse.html &<br />
<br />
http://www.bugcommunity.com/wiki/index.php/BUG_Kernel_Development_with_Eclipse<br />
<br />
==Further Reading==<br />
===Internal===<br />
[[Gaining Console Connection via Terminal]]<br><br />
[[HelloWorld | HelloWorld in Python, C and C++]]<br><br />
[[Remote Debugging with GDB]] <br><br />
[[HelloWorld in Java]]<br />
<br />
===External===<br />
:* Tutorials built into Eclipse<br />
:* Bitbake commander<br />
:* OpenEmebedded|Poky docs + Bitbake docs<br />
:* Eclipse Plugin Tutorial<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
[[Category:How_to_-_eclipse]]</div>JustinC474https://wiki.gumstix.com/index.php?title=File:JavaEclipsePic4.png&diff=4500File:JavaEclipsePic4.png2010-08-05T19:56:40Z<p>JustinC474: uploaded a new version of "File:JavaEclipsePic4.png"</p>
<hr />
<div></div>JustinC474https://wiki.gumstix.com/index.php?title=File:JavaEclipsePic3.png&diff=4499File:JavaEclipsePic3.png2010-08-05T19:55:37Z<p>JustinC474: uploaded a new version of "File:JavaEclipsePic3.png"</p>
<hr />
<div></div>JustinC474https://wiki.gumstix.com/index.php?title=Using_Eclipse_to_Write_HelloWorld_in_Java_for_the_Overo&diff=4498Using Eclipse to Write HelloWorld in Java for the Overo2010-08-05T19:55:24Z<p>JustinC474: /* Upload your Code onto your Overo COM */</p>
<hr />
<div>This page will teach you how to create a simple, graphical, java HelloWorld application in Eclipse, export it to you Overo COM, and subsequently run it. This guide assumes that you have already run through [[Eclipse on Gumstix for new users]] and have Eclipse installed, and your Gumstix properly connected. <br />
<br />
==Writing HelloWorld.java in Eclipse==<br />
First, you need to write your Java program in Eclipse. This section will show you how to write a small graphical HelloWorld program in Eclipse.<br />
<br />
:* Navigate to '''File-> New-> Java Project'''<br />
:* Name the project ''HelloWorld''<br />
:* Select "Finish"<br />
Once the project is created,<br />
:* Select '''File->New->Class'''<br />
:* Name your class ''HelloWorld''<br />
:* click "Finish"<br />
<br />
Add the following code to your class:<br />
<br />
import javax.swing.JFrame;<br />
import javax.swing.JLabel;<br />
public class Hello {<br />
public static void main(String [] args) {<br />
JFrame frame = new JFrame("hello");<br />
final JLabel label = new JLabel("hello from Gumstix");<br />
frame.getContentPane().add(label);<br />
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);<br />
frame.pack();<br />
frame.setVisible(true);<br />
}<br />
}<br />
<br />
Press the green run button to test drive our application on our host machine. You should get something that looks like this:<br />
<br />
[[File:GumstixEclipse12.jpg]]<br />
<br />
Congratulations! You have now written your first graphical program in Java.<br />
<br />
----<br />
Hint:<br />
Eclipse has many auto-completion features. Simply typing /:*<Enter> before a class creates a standard documentation block. Likewise, pressing <Ctrl>+<Space> provides context specific auto-completion options. Many other hints for speedy development are explained in the tutorials [http://www.eclipse.org/resources/?category=Getting%20Started here].<br />
----<br />
<br />
==Upload your Code onto your Overo COM==<br />
Now that you have a graphical program on Eclipse, its time to upload it onto your Overo COM. This will show you how to upload your code onto your Overo COM via ethernet connection. First, you will need to discover to IP Address of your Overo. To do this, see [[Eclipse on Gumstix for new users]]: Connect Your Gumstix. Once you have the IP Address of your Gumstix, it is time to export your Java Program onto your Overo COM. <br />
:*Choose '''File -> Export''' from the drop down menu<br />
:*Choose '''Remote Systems -> Remote File System''' and press '''Next'''<br />
[[File:JavaEclipsePic1.png]]<br />
:*Expand the drop down for the HelloWorld project<br />
::*In the '''bin''' folder choose '''HelloWorld.class'''<br />
[[File:JavaEclipsePic5.png]]<br />
----<br />
Note:<br />
We want to export the HelloWorld.class file and NOT the HelloWorld.java file. This is because our Overo COM can not compile a .java file. A .class file has already been compiled and is ready to run on a Java Virtual Machine, which our Overo COM will have after some necessary installations. <br />
----<br />
:*For Destination Folder, hit the '''Browse''' button<br />
[[File:JavaEclipsePic2.png]]<br />
:*In the Browse For Folder window which will appear:<br />
:*If you have already added a ethernet connection to your Overo COM, it should be in the drop down menu under Local<br />
[[File:JavaEclipsePic3.png]]<br />
:*If it is not, hit '''New'''<br />
::*Choose '''SSH Only'''<br />
::*In the '''HOST Name''', put the IP Address<br />
::*Hit Finish<br />
[[File:JavaEclipsePic4.png]]<br />
:*Under '''My Home''' choose '''Desktop''' and hit OK<br />
:*Back in the Export window, hit '''Finish''' and Eclipse will export your program to your Overo!<br />
<br />
==Installing Necessary Software==<br />
Before we can run our program on the Overo COM, there are some opkg we need installed so that we can run a Java Virtual Machine. To do this issue the following commands:<br />
opkg update<br />
opkg install cacao<br />
opkg install classpath-gtk<br />
This installs the Java Library cacao and the GTK which allows you to run graphical JARs. <br />
<br />
Next, we need to set our Display to be correct. In the Console window for the Overo COM issue the following command<br />
export DISPLAY=:0.0<br />
This enables the Overo to be able to display onto the monitor correctly. Without setting the display correctly our graphical program will not work. <br />
<br />
==Running our Program==<br />
Now that our Overo COM has the program on it and the necessary software to run it, it is time to run our graphical HelloWorld!<br />
----<br />
Note:<br />
You will need a Monitor connected to your Overo COM to run this program. This does not include the local host.<br />
----<br />
To do this you first must go into the '''Remote System Explorer''' Perspective in Eclipse. <br />
:*From the '''Window''' drop down menu, choose '''Open Perspective -> Other -> Remote System Explorer'''<br />
:*Find the Overo's IP address<br />
::*Expand '''(The IP Address) -> My Home -> Desktop -> bin'''<br />
::*Right click on HelloWorld.class, and choose '''User Action -> java''' <br />
::*Hit Enter<br />
:*A Box should appear on your monitor with the text: Hello from Gumstix<br />
<br />
==Minesweeper==<br />
If you wish to move on to something more complex, see the page for [[Minesweeper in Java]]. All the code in provided to make a cool, graphically Minesweeper game that can be run on an Overo with a monitor!</div>JustinC474https://wiki.gumstix.com/index.php?title=Using_Eclipse_to_Write_HelloWorld_in_Java_for_the_Overo&diff=4497Using Eclipse to Write HelloWorld in Java for the Overo2010-08-05T19:54:34Z<p>JustinC474: /* Upload your Code onto your Overo COM */</p>
<hr />
<div>This page will teach you how to create a simple, graphical, java HelloWorld application in Eclipse, export it to you Overo COM, and subsequently run it. This guide assumes that you have already run through [[Eclipse on Gumstix for new users]] and have Eclipse installed, and your Gumstix properly connected. <br />
<br />
==Writing HelloWorld.java in Eclipse==<br />
First, you need to write your Java program in Eclipse. This section will show you how to write a small graphical HelloWorld program in Eclipse.<br />
<br />
:* Navigate to '''File-> New-> Java Project'''<br />
:* Name the project ''HelloWorld''<br />
:* Select "Finish"<br />
Once the project is created,<br />
:* Select '''File->New->Class'''<br />
:* Name your class ''HelloWorld''<br />
:* click "Finish"<br />
<br />
Add the following code to your class:<br />
<br />
import javax.swing.JFrame;<br />
import javax.swing.JLabel;<br />
public class Hello {<br />
public static void main(String [] args) {<br />
JFrame frame = new JFrame("hello");<br />
final JLabel label = new JLabel("hello from Gumstix");<br />
frame.getContentPane().add(label);<br />
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);<br />
frame.pack();<br />
frame.setVisible(true);<br />
}<br />
}<br />
<br />
Press the green run button to test drive our application on our host machine. You should get something that looks like this:<br />
<br />
[[File:GumstixEclipse12.jpg]]<br />
<br />
Congratulations! You have now written your first graphical program in Java.<br />
<br />
----<br />
Hint:<br />
Eclipse has many auto-completion features. Simply typing /:*<Enter> before a class creates a standard documentation block. Likewise, pressing <Ctrl>+<Space> provides context specific auto-completion options. Many other hints for speedy development are explained in the tutorials [http://www.eclipse.org/resources/?category=Getting%20Started here].<br />
----<br />
<br />
==Upload your Code onto your Overo COM==<br />
Now that you have a graphical program on Eclipse, its time to upload it onto your Overo COM. This will show you how to upload your code onto your Overo COM via ethernet connection. First, you will need to discover to IP Address of your Overo. To do this, see [[Eclipse on Gumstix for new users]]: Connect Your Gumstix. Once you have the IP Address of your Gumstix, it is time to export your Java Program onto your Overo COM. <br />
:*Choose '''File -> Export''' from the drop down menu<br />
:*Choose '''Remote Systems -> Remote File System''' and press '''Next'''<br />
[[File:JavaEclipsePic1.png]]<br />
:*Expand the drop down for the HelloWorld project<br />
::*In the '''bin''' folder choose '''HelloWorld.class'''<br />
[[File:JavaEclipsePic5.png]]<br />
----<br />
Note:<br />
We want to export the HelloWorld.class file and NOT the HelloWorld.java file. This is because our Overo COM can not compile a .java file. A .class file has already been compiled and is ready to run on a Java Virtual Machine, which our Overo COM will have after some necessary installations. <br />
----<br />
:*For Destination Folder, hit the '''Browse''' button<br />
[[File:JavaEclipsePic2.png]]<br />
:*In the Browse For Folder window which will appear:<br />
:*If you have already added a ethernet connection to your Overo COM, it should be in the drop down menu under Local<br />
[[File:JavaEclipsePic5.png]]<br />
:*If it is not, hit '''New'''<br />
::*Choose '''SSH Only'''<br />
::*In the '''HOST Name''', put the IP Address<br />
::*Hit Finish<br />
[[File:JavaEclipsePic4.png]]<br />
:*Under '''My Home''' choose '''Desktop''' and hit OK<br />
:*Back in the Export window, hit '''Finish''' and Eclipse will export your program to your Overo!<br />
<br />
==Installing Necessary Software==<br />
Before we can run our program on the Overo COM, there are some opkg we need installed so that we can run a Java Virtual Machine. To do this issue the following commands:<br />
opkg update<br />
opkg install cacao<br />
opkg install classpath-gtk<br />
This installs the Java Library cacao and the GTK which allows you to run graphical JARs. <br />
<br />
Next, we need to set our Display to be correct. In the Console window for the Overo COM issue the following command<br />
export DISPLAY=:0.0<br />
This enables the Overo to be able to display onto the monitor correctly. Without setting the display correctly our graphical program will not work. <br />
<br />
==Running our Program==<br />
Now that our Overo COM has the program on it and the necessary software to run it, it is time to run our graphical HelloWorld!<br />
----<br />
Note:<br />
You will need a Monitor connected to your Overo COM to run this program. This does not include the local host.<br />
----<br />
To do this you first must go into the '''Remote System Explorer''' Perspective in Eclipse. <br />
:*From the '''Window''' drop down menu, choose '''Open Perspective -> Other -> Remote System Explorer'''<br />
:*Find the Overo's IP address<br />
::*Expand '''(The IP Address) -> My Home -> Desktop -> bin'''<br />
::*Right click on HelloWorld.class, and choose '''User Action -> java''' <br />
::*Hit Enter<br />
:*A Box should appear on your monitor with the text: Hello from Gumstix<br />
<br />
==Minesweeper==<br />
If you wish to move on to something more complex, see the page for [[Minesweeper in Java]]. All the code in provided to make a cool, graphically Minesweeper game that can be run on an Overo with a monitor!</div>JustinC474https://wiki.gumstix.com/index.php?title=File:JavaEclipsePic2.png&diff=4496File:JavaEclipsePic2.png2010-08-05T19:53:08Z<p>JustinC474: uploaded a new version of "File:JavaEclipsePic2.png"</p>
<hr />
<div></div>JustinC474https://wiki.gumstix.com/index.php?title=File:JavaEclipsePic5.png&diff=4495File:JavaEclipsePic5.png2010-08-05T19:52:06Z<p>JustinC474: </p>
<hr />
<div></div>JustinC474https://wiki.gumstix.com/index.php?title=Using_Eclipse_to_Write_HelloWorld_in_Java_for_the_Overo&diff=4494Using Eclipse to Write HelloWorld in Java for the Overo2010-08-05T19:50:07Z<p>JustinC474: /* Upload your Code onto your Overo COM */</p>
<hr />
<div>This page will teach you how to create a simple, graphical, java HelloWorld application in Eclipse, export it to you Overo COM, and subsequently run it. This guide assumes that you have already run through [[Eclipse on Gumstix for new users]] and have Eclipse installed, and your Gumstix properly connected. <br />
<br />
==Writing HelloWorld.java in Eclipse==<br />
First, you need to write your Java program in Eclipse. This section will show you how to write a small graphical HelloWorld program in Eclipse.<br />
<br />
:* Navigate to '''File-> New-> Java Project'''<br />
:* Name the project ''HelloWorld''<br />
:* Select "Finish"<br />
Once the project is created,<br />
:* Select '''File->New->Class'''<br />
:* Name your class ''HelloWorld''<br />
:* click "Finish"<br />
<br />
Add the following code to your class:<br />
<br />
import javax.swing.JFrame;<br />
import javax.swing.JLabel;<br />
public class Hello {<br />
public static void main(String [] args) {<br />
JFrame frame = new JFrame("hello");<br />
final JLabel label = new JLabel("hello from Gumstix");<br />
frame.getContentPane().add(label);<br />
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);<br />
frame.pack();<br />
frame.setVisible(true);<br />
}<br />
}<br />
<br />
Press the green run button to test drive our application on our host machine. You should get something that looks like this:<br />
<br />
[[File:GumstixEclipse12.jpg]]<br />
<br />
Congratulations! You have now written your first graphical program in Java.<br />
<br />
----<br />
Hint:<br />
Eclipse has many auto-completion features. Simply typing /:*<Enter> before a class creates a standard documentation block. Likewise, pressing <Ctrl>+<Space> provides context specific auto-completion options. Many other hints for speedy development are explained in the tutorials [http://www.eclipse.org/resources/?category=Getting%20Started here].<br />
----<br />
<br />
==Upload your Code onto your Overo COM==<br />
Now that you have a graphical program on Eclipse, its time to upload it onto your Overo COM. This will show you how to upload your code onto your Overo COM via ethernet connection. First, you will need to discover to IP Address of your Overo. To do this, see [[Eclipse on Gumstix for new users]]: Connect Your Gumstix. Once you have the IP Address of your Gumstix, it is time to export your Java Program onto your Overo COM. <br />
:*Choose '''File -> Export''' from the drop down menu<br />
:*Choose '''Remote Systems -> Remote File System''' and press '''Next'''<br />
[[File:JavaEclipsePic1.png]]<br />
:*Expand the drop down for the HelloWorld project<br />
::*In the '''bin''' folder choose '''HelloWorld.class'''<br />
[[File:JavaEclipsePic5.png]]<br />
----<br />
Note:<br />
We want to export the HelloWorld.class file and NOT the HelloWorld.java file. This is because our Overo COM can not compile a .java file. A .class file has already been compiled and is ready to run on a Java Virtual Machine, which our Overo COM will have after some necessary installations. <br />
----<br />
:*For Destination Folder, hit the '''Browse''' button<br />
[[File:JavaEclipsePic2.png]]<br />
:*In the Browse For Folder window which will appear:<br />
:*If you have already added a ethernet connection to your Overo COM, it should be in the drop down menu under Local<br />
[[File:JavaEclipsePic3.png]]<br />
:*If it is not, hit '''New'''<br />
::*Choose '''SSH Only'''<br />
::*In the '''HOST Name''', put the IP Address<br />
::*Hit Finish<br />
[[File:JavaEclipsePic4.png]]<br />
:*Under '''My Home''' choose '''Desktop''' and hit OK<br />
:*Back in the Export window, hit '''Finish''' and Eclipse will export your program to your Overo!<br />
<br />
==Installing Necessary Software==<br />
Before we can run our program on the Overo COM, there are some opkg we need installed so that we can run a Java Virtual Machine. To do this issue the following commands:<br />
opkg update<br />
opkg install cacao<br />
opkg install classpath-gtk<br />
This installs the Java Library cacao and the GTK which allows you to run graphical JARs. <br />
<br />
Next, we need to set our Display to be correct. In the Console window for the Overo COM issue the following command<br />
export DISPLAY=:0.0<br />
This enables the Overo to be able to display onto the monitor correctly. Without setting the display correctly our graphical program will not work. <br />
<br />
==Running our Program==<br />
Now that our Overo COM has the program on it and the necessary software to run it, it is time to run our graphical HelloWorld!<br />
----<br />
Note:<br />
You will need a Monitor connected to your Overo COM to run this program. This does not include the local host.<br />
----<br />
To do this you first must go into the '''Remote System Explorer''' Perspective in Eclipse. <br />
:*From the '''Window''' drop down menu, choose '''Open Perspective -> Other -> Remote System Explorer'''<br />
:*Find the Overo's IP address<br />
::*Expand '''(The IP Address) -> My Home -> Desktop -> bin'''<br />
::*Right click on HelloWorld.class, and choose '''User Action -> java''' <br />
::*Hit Enter<br />
:*A Box should appear on your monitor with the text: Hello from Gumstix<br />
<br />
==Minesweeper==<br />
If you wish to move on to something more complex, see the page for [[Minesweeper in Java]]. All the code in provided to make a cool, graphically Minesweeper game that can be run on an Overo with a monitor!</div>JustinC474https://wiki.gumstix.com/index.php?title=File:JavaEclipsePic1.png&diff=4493File:JavaEclipsePic1.png2010-08-05T19:47:41Z<p>JustinC474: uploaded a new version of "File:JavaEclipsePic1.png"</p>
<hr />
<div></div>JustinC474https://wiki.gumstix.com/index.php?title=Eclipse_on_Gumstix_for_new_users&diff=4491Eclipse on Gumstix for new users2010-08-05T18:53:24Z<p>JustinC474: /* Upload Code */</p>
<hr />
<div>This guide provides step-by-step instructions for using the Eclipse Integrated Development Environment (IDE) to develop applications for the Gumstix COMs.<br />
<br />
We'll walk through these tasks:<br />
:* setting up Eclipse<br />
:* connection to your Gumstix system<br />
:* creating a simple "Hello, World!" Python program<br />
:* running a web server<br />
:* installing new packages on your Gumstix<br />
:* creating a small graphical Java application<br />
:* remote debugging of your Java application<br />
:* natively-compiling C/C++ code on your Gumstix<br />
:* remote debugging C/C++ using the GDB server interface<br />
<br />
We will also explain how to set up a cross-compilation toolchain so you can develop C/C++ applications on your development computer and upload them to your Gumstix.<br />
<br />
Remember, Gumstix COMs are fully-fledged, albeit tiny, Linux systems so there are many tools we don't cover here. For example, [http://wiki.openembedded.net/index.php/OpenEmbedded_Tools_for_Eclipse_(OTE) this document] explains how to use the powerful OpenEmbedded build system within Eclipse.<br />
<br />
Required Tools:<br />
:* any Windows, Apple or Linux computer with a USB port<br />
:* recent version of the Java Runtime Environment (available [http://java.sun.com/javase/downloads/index.jsp here])<br />
:* a Gumstix COM running [http://www.gumstix.net/Setup-and-Programming/view/Overo-Setup-and-Programming/Downloading-pre-built-images/111.html up-to-date software]<br />
:* any expansion board of the Gumstix Overo series, such as Chestnut or Tobi, that has both a USB console port and a 10/100 <br />
:* Ethernet jack<br />
:* a 5V power supply<br />
:* an ethernet cable and internet connection<br />
:* a mini-A to Standard-A USB cable<br />
:* a [http://www.gumstix.net/Setup-and-Programming/view/Overo-Setup-and-Programming/Creating-a-bootable-microSD-card/111.html bootable microSD card] (only needed for native C/C++ compilation)<br />
<br />
Key Idea:<br />
[[File:GumstixEclipse1.jpg|thumb|right|upright=5]]<br />
<br />
==Download Eclipse==<br />
[http://www.eclipse.org/downloads/ Download] the Eclipse IDE for Java Developers for your Operating System: www.eclipse.org<br />
<br />
[[Image: GumstixEclipse2.jpg | center | 600px]]<br />
<br />
<br />
:* it is ''not'' necessary to install the Eclipse software; just double-click on the application once it has finished downloading<br />
:* when prompted, choose a workspace folder in which you want to store your projects and your configuration information<br />
:* then click through to the Eclipse workbench itself<br />
<br />
==Install Plugins==<br />
For developers, a great variety of additional features can be added to Eclipse from various repositories of plug-ins known as ''Update Sites''.<br />
To install a new plugin in Eclipse, first select the ''Update Site''.<br />
:* navigate to '''Help->Install New Software...'''<br />
:* select the Update Site for your version of Eclipse from the "Work with"dropdown menu<br />
<br />
[[File:GumstixEclipse3.jpg | center | 1000px]]<br />
<br />
:Note: If you are not sure which version of Eclipse you have, you can check by reopening Eclipse, it will be displayed on the loading screen.<br />
<br />
----<br />
Hint:<br />
If the update site is not available, you can add it by clicking the 'Add...' button on the right. For the Galileo release, you can use the URL http://dowload.eclipse.org/releases/galileo<br />
----<br />
<br />
As we are working with a remote system, we'll install the Remote System Explorer plugin.<br />
:* search for the ''Remote System Explorer End-User Runtime'' plugin<br />
:* select it for installation<br />
<br />
[[File:GumstixEclipse4.jpg | center | 600px]]<br />
<br />
Still in Eclipse,<br />
:* select "Next".... twice<br />
:* select the radio button to "ACCEPT" the terms of the license agreement<br />
:* choose "Yes" to restart Eclipse for the changes to take effect<br />
<br />
Once Eclipse has restarted, let's add two other useful plugins that allow connection to the console port of our Gumstix without needing a terminal emulator program such as kermit or TeraTerm.<br />
From within Eclipse,<br />
:* navigate to '''Help->Install New Software'''<br />
:* search on "Target" to find the ''Target Manager Terminal''<br />
<br />
[[File:GumstixEclipse5.jpg | center | 1000px]]<br />
<br />
:* select the ''Target Manager Terminal''<br />
:* click "Next"<br />
:* click "Finish" to complete installation<br />
:* choose "Yes" to restart Eclipse for the changes to take effect<br />
<br />
We'll also need to add a new update site by doing these steps in Eclipse:<br />
:* navigate to '''Help->Install New Software...'''<br />
:* click the "Add..." button<br />
:* type ''http://rxtx.qbang.org/eclipse'' into the ''Location'' field and create a name<br />
<br />
[[File:GumstixEclipse6.jpg | center | 1000px]]<br />
<br />
:* Click the "OK" button<br />
Go into the sub-directory as shown below to select the ''RXTX End-User Runtime'' plugin that this site provides.<br />
<br />
[[File:GumstixEclipse7.jpg | center | 1000px]]<br />
<br />
:* click "Next" twice<br />
:* select the radio button to "ACCEPT" the terms of the license agreement<br />
:* click "OK" at the security warning window<br />
:* click "Finish" to complete installation<br />
:* choose the "Yes" button to restart Eclipse for the changes to take effect<br />
<br />
==Connect Your Gumstix==<br />
Now it is time to connect your Gumstix---let's get started by establishing a console connection.<br />
:* mount your Gumstix COM down on to your expansion board<br />
:* plug the mini-A USB plug into the port marked CONSOLE and end of the cable into a standard USB port on your computer<br />
----<br />
Hint:<br />
Your computer should detect your Gumstix system when you first connect the USB cable, even though the power is not yet turned on. On Macintosh and Windows systems, a pop-up window should appear instructing you to download a new driver (do so) or notifying you that a USBserial device has been detected. If not, you can download drivers from [http://www.ftdichip.com/FTDrivers.htm this site]. Choose the "VCP" driver.<br />
Once you have downloaded this driver, make sure to unplug and then replug the USB cable running from your computer to your Gumstix expansion board so the Gumstix will be recognized by your computer.<br />
----<br />
:* connect your Gumstix to the internet using an ethernet cable<br />
NOTE: You still have NOT plugged the power cable in to the <br />
Gumstix expansion board! This diagram shows the locations<br />
of the USB 'CONSOLE' port and the 'POWER' input port on a <br />
Summit board on which an Overo COM has been mounted.<br />
<br />
[[File:GumstixEclipse8.jpg | center ]]<br />
<br />
:* if you are booting from a microSD card, insert this card now until you hear it click in place.<br />
Before applying power to the board, let's open up a connection to the console port.<br />
In Eclipse,<br />
:* navigate to '''Window->Show View->Other->Terminal->Terminal'''<br />
:* click on the 'N' connection icon in the window that appears<br />
<br />
[[File:GumstixEclipse9.jpg | center ]]<br />
<br />
:* make the connection using the following settings:<br />
Connection Type: Serial<br />
Port: <port to which your Gumstix is connected><br />
Baud Rate: 115200<br />
Data Bits: 8<br />
Stop Bits: 1<br />
Parity: none<br />
Flow Control: none<br />
Timeout: 5<br />
<br />
----<br />
Hint:<br />
The port to which your Gumstix is connected will have a different name depending on your Host operating system.<br />
:* On Windows, it should be ''USB-COM''<br />
:* On Macintosh, it should be ''/dev/tty.usbserial-xxxxxxxx'' where ''xxxxxxxx'' is an arbitrary string of characters<br />
:* On Linux, it should be ''/dev/ttyUSBx'' where ''x'' is a number.<br />
----<br />
<br />
[[File:GumstixEclipse10.jpg | center | 800px]]<br />
<br />
----<br />
Hint:<br />
If this does not work, or you wish to gain Console access via a Unix Shell instead, visit the tutorial on [[Gaining Console Connection via Terminal]]<br />
----<br />
<br />
*Now, it's time to apply power to the Gumstix expansion board so plug the 5V wall adapter into the power input jack on the Gumstix.<br />
<br />
You should see text appear in this window; for now, just let the Gumstix boot. When prompted, you can log in to the root account. The default credentials are:<br />
<br />
'''Overo'''<br />
<br />
username: root<br />
<br />
password: <leave blank><br />
<br />
<br />
'''VerdexPro'''<br />
<br />
username: root<br />
<br />
password: gumstix<br />
<br />
==Create a Web Site==<br />
Each Gumstix comes with a built-in package manager called opkg. A package manager is a useful tool for installing software; you can install everything from media players to GPS mapping tools to the Firefox web browser. In this example, you'll use opkg tool to install a new application for your Gumstix: the Apache web server.<br />
<br />
To make your own Gumstix web site, type the following in the terminal window:<br />
opkg update <Enter><br />
opkg install apache2 <Enter><br />
Before you start using Apache, which is now running, you'll need to find the IP address (internet address) of your Gumstix COM. To do this, type the following command into the terminal window:<br />
ifconfig | grep 'inet addr' <Enter><br />
You should see something like this appear on your screen.<br />
inet addr: 10.0.1.73 Bcast: 192.168.0.255 Mask: 255.255.255.0<br />
The IP address of your Gumstix is the first address shown: ''10.0.1.73'' in this case.<br />
Now,<br />
:* open up a web browser on your host computer<br />
:* type that IP address of your Gumstix into the address bar<br />
You should see something like this which is the default web site for Apache running on your Gumstix.<br />
<br />
[[File:GumstixEclipse11.jpg]]<br />
<br />
To make your web site say something more interesting, do the follow in your terminal window:<br />
:* type: ''nano /usr/share/apache2/htdocs/index.html''<br />
:* replace the words at the top of the screen "It Works" with the words "Gumstix Rocks!"<br />
:* press 'Ctrl+O' <Enter><br />
:* press 'Ctrl+X' to save and exit<br />
:* refresh your web browser<br />
<br />
==Write a Java Application==<br />
So far, you haven't actually used Eclipse other than as a console interface for your Gumstix. It is time to harness the power of Eclipse to write a small graphical Java application.<br />
In Eclipse.<br />
:* Navigate to '''File-> New-> Java Project''',<br />
:* Name the project ''gumstix-java''<br />
:* Select "Finish"<br />
Once the project is created,<br />
:* Select '''File->New->Class'''<br />
:* Name your class ''Hello''<br />
:* click "FINISH"<br />
<br />
Add the following code to your class:<br />
<br />
import javax.swing.JFrame;<br />
import javax.swing.JLabel;<br />
public class Hello {<br />
public static void main(String [] args) {<br />
JFrame frame = new JFrame("hello");<br />
final JLabel label = new JLabel("hello from Gumstix");<br />
frame.getContentPane().add(label);<br />
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);<br />
frame.pack();<br />
frame.setVisible(true);<br />
}<br />
}<br />
<br />
You should get something that looks like this:<br />
<br />
[[File:GumstixEclipse12.jpg | center | 600px]]<br />
<br />
Press the green run button to test drive our application on our host machine.<br />
<br />
----<br />
Hint:<br />
Eclipse has many auto-completion features. Simply typing /:*<Enter> before a class creates a standard documentation block. Likewise, pressing <Ctrl>+<Space> provides context specific auto-completion options. Many other hints for speedy development are explained in the tutorials [http://www.eclipse.org/resources/?category=Getting%20Started here].<br />
----<br />
<br />
==Upload Code==<br />
In Step 5 we discovered the IP address of our Gumstix. With this, we can connect to our Gumstix using the SSH protocol which allows us to rapidly transfer files. For this step, navigate to '''Window->Open Perspective->Other->Remote System Explorer''' and click on the connection icon in the ''Remote Systems'' panel on the left. Select ''SSH without shells'' as the connection type and press Next. Put the internet address you found in Step 5 into the field marked ''Host Name'' and hit finish. To test that everything is working correctly, right-click on the terminal item list under your new connection and select ''Launch Terminal''. A console interface exactly like the USB console interface we set up in Step 3 should pop up.<br />
<br />
<br />
----<br />
Hint:<br />
A 'Perspective' is an arrangement of windows and widgets, that is a specific view of the Eclipse workspace, designed for a particular task. If you wish to focus on any particular widget, double click the tab in Eclipse; return to the previous view by double-clicking again.<br />
----<br />
<br />
<br />
By installing the VNC viewer plugin, we can get a graphical interface to our Gumstix system. Do this by adding the ''Tools for mobile linux runtime'' plugin ('''Help->Install New Software''') from the main update site. To use, select the VNC viewer widget from '''Window->Show View->Other->VNC Category->VNC''' and click on the ''New Connection'' icon in the VNC Viewer panel. Again, the ''Host'' is the internet address of your Gumstix board.<br />
<br />
[[File:GumstixEclipse13.jpg | center | 800px]]<br />
<br />
Finally, we need to upload our java code before we can run it. Switch back to the Java Perspective ('''Window->Open Perspective->Java''') and right-click on our Java file and selecting Export. Choose the option to export file to a remote file system and choose to upload your ''Hello.class'' file.<br />
<br />
[[File:GumstixEclipse14.jpg | center | 600px]]<br />
<br />
You will need to ''Browse'' to find your Gumstix board; you should upload this code to your home directory on the Gumstix.<br />
<br />
==Debug a Java Application==<br />
We can debug our java application remotely from Eclipse. To do this, we need a Java Virtual Machine capable of doing debugging. This time, the package we need isn't available in our package sources however we can fetch the package directly from a web site and install it using the same opkg package management tool.<br />
wget http://bugcommunity.com/downloads/files/phonemeadvanced- personal-debug_mr2-r1_armv6.ipk <Enter><br />
opkg install -force-depends phoneme-advanced-personaldebug_mr2-r1_armv6.ipk <Enter><br />
Let's also update our Java libraries so we have access to the standard graphical libraries.<br />
opkg install classpath-gtk <Enter><br />
Next, let's start our Java code in debugging mode on the Overo:<br />
java-cdc -Xdebug -Xrunjwdp:transport=dHt_socket,server=y,suspend=y,address=1234 Hello <Enter><br />
Finally, let's connect to our debugging session by navigating in Eclipse to '''Run->Debug Configurations''' and double-clicking on Remote Java Application to create a new configuration. Fill in the form as shown below using the internet address found in the previous step.<br />
<br />
==Install a native C/C++ SDK==<br />
When we discussed Python and Java we noted that both are interpreted languages--- neither needs to be compiled. C and C++ code requires compilation which can be done natively---on the Gumstix itself---or on a development machine using a cross-compiler. To do native compilation, you need to install a compiler as well as any required libraries. You'll need to be booting from a microSD card as this installation takes approximately 75MB of space.<br />
$ echo 'src/gz angstrom-base http://www.angstromdistribution.org/feeds/unstable/ipk/glibc/armv7a/base' > /etc/opkg/angstrom-base.conf<br />
$ opkg update<br />
$ opkg install task-native-sdk<br />
Firstly, we are adding a new package repository to our package manager and updating our list of available packages before actually installing the complete package needed to do native development.<br />
<br />
Let's create either of the following files in Eclipse, upload the code and then compile on the Gumstix using our newly installed compiler.<br />
<br />
===C++: HelloWorld.cpp===<br />
#include <iostream><br />
using namespace std;<br />
int main () {<br />
cout << "Gumstix runs on C++" << endl;<br />
return 0;<br />
}<br />
<br />
Save the file and issue the following commands to compile and run HelloWorld.cpp<br />
g++ -o hello hello.cpp <enter><br />
Gumstix runs on C++ <enter><br />
<br />
===C: HelloWorld.c===<br />
#include <stdio.h><br />
int main () {<br />
printf("Gumstix runs on C\n");<br />
return 0;<br />
}<br />
<br />
Save the file and issue the following commands to compile and run HelloWorld.c<br />
gcc -o hello hello.c<br />
Gumstix runs on C<br />
<br />
<TODO: More exciting examples using on-board LEDs.><br />
<br />
==Using GDB as a remote debugger in C/C++==<br />
These instructions will teach you how to download, install, and use the GDB debugger remotely on your Overo COM.<br />
<br />
<pre>NOTE: <br />
remote system - a device that is being operated remotely (via SSH, USB Serial, etc). This means that it is a device that you are operating from a different system <br />
(ie: if you are accessing the Overo COM via connection with your PC, then the Overo COM is a remote system).<br />
For the purpose of this guide, the Overo COM will be the remote system.<br />
<br />
local host - the device that is being used to work on (ie: If you are working on your PC, that is the local host. If you then connect to another computer via VNC, <br />
that is a remote system, and you laptop is still the localhost).<br />
For the purpose of this guide, your Personal Computer will be the local host.</pre><br />
<br />
Before starting, it is important to note there are many different ways to run a remote debugger. The most fundamental choice when debugging remotely is whether you want to:<br />
:*Run the debugger on the remote system or<br />
:*Run the debugger on the local host with a cross debugger on the remote system<br />
<br />
This guide will teach you how to download, install, and run the debugger on the remote system (choice A). If you wish to learn more about the cross debugger option, use Google. Also the wikipedia article on cross compilers (which operate in a very similar fashion) is very good, albeit a bit complicated. None of this is necessary in understanding the contents of this guide. <br />
<br />
For the purposes of this guide, we will be using the GDB: the GNU project debugger. As stated on their website:<br />
<br />
<pre>GDB, the GNU Project debugger, allows you to see what is going on `inside' another program while it executes -- or what another program was doing at the moment it <br />
crashed.<br />
<br />
GDB can do four main kinds of things (plus other things in support of these) to help you catch bugs in the act:<br />
- Start your program, specifying anything that might affect its behavior.<br />
- Make your program stop on specified conditions.<br />
- Examine what has happened, when your program has stopped.<br />
- Change things in your program, so you can experiment with correcting the effects of one bug and go on to learn about another.</pre><br />
<br />
While the reasons for using a debugger instead of trying to debug with the ‘brute force’ method of adding print statements throughout the entire program are enumerable, there are a few that stand out:<br />
# The ability to ‘step’ through a program<br />
#* The GDB debugger allows you to ‘step’ through a program. This means that instead of just executing the program and then leaving you with a final error message, it will execute one line at a time until the program crashes. This allows the user to see exactly where, and why, the program crashed. <br />
# The ability to set breakpoints<br />
#* The GDB debugger allows you to set breakpoints in the program. These are points where the CPU will stop executing the code and allow the user to decide whether to continue. This allows the user to explore what is ‘going on’ at certain points in the execution, something that otherwise is not possible. <br />
# The ability to look at the Backtrace<br />
#* This will show you where, and exactly why, your program crashed. Although SEGFAULT isn’t very useful, the backtrace will tell you what caused the SEGFAULT. Everything from what line, what variable, and even the address that variable was at.<br />
<br />
===Installing the GDB===<br />
Once the Overo COM has been connected to the local host, you should have access to the following command line:<br />
<pre>root@overo:~# </pre><br />
Although you are working on your local host, this command line is for the remote system. It is the same as if you opened up Terminal (for Mac, Linux) or XTerm (for Windows). You now have access and control of the remote system.<br />
<br />
Now there are some packages that must be downloaded and installed onto the Overo so that it can run the GDB environment. To do this issue the following command:<br />
<pre>opkg update <enter><br />
opkg install gdb <enter></pre><br />
This should spew out a bunch of text such as:<br />
<pre>Downloading http://www.angstrom...</pre><br />
Just let it run and once its done, you’ll have the GNU GDB debugger installed on your Overo COM.<br />
<br />
===Creating a C/C++ Program to Debug===<br />
Now, your Overo COM has a debugger installed and ready to use. However, this does not mean you are ready to go. There are two more things required before it is possible to use a GDB debugger.<br />
:* A C/C++ program<br />
:* A SDK to run the program on<br />
To see how to install a SDK and write/run a simple program in C/C++, see [[#Install a native C/C++ SDK]]. <br />
<br />
Once you have a program ready, you first must create an executable file. Lets use for example the C++ program HelloWorld.cpp. To create the executable file HelloWorld, issue the following command:<br />
<pre>g++ -o HelloWorld HelloWorld.cpp <enter></pre><br />
Now, to run the program:<br />
<pre>./HelloWorld <enter></pre><br />
To do the same thing with a C program (HelloWorld.c), issue the command<br />
<pre>gcc -o HelloWorld HelloWorld.c <enter></pre><br />
<pre>./HelloWorld <enter></pre><br />
<br />
What this command does is uses the GNU compiler (either g++ or gcc) and creates an executable object (HelloWorld) out of the C or C++ program file (either HelloWorld.cpp or HelloWorld.c). You may name the executable whatever you like, but it is considered best practice to name it the same thing as the program file.<br />
<br />
===Debugging the Program===<br />
Now that you have GDB installed and a C/C++ program ready to go, its time to debug. To open to GDB environment, run the following command<br />
<pre>gdb <enter></pre><br />
Some text should spit out, and the following command line should appear<br />
<pre>(gdb)</pre><br />
Now that the debugger is running, it is time to tell the debugger what program we want to debug. To do this, first we need to declare our HelloWorld file as an executable file. For this run the following command <br />
<pre>(gdb) exec-file HelloWorld <enter></pre><br />
Now that we have an executable file ready to be debugged, its time to run the program<br />
<pre>(gdb) run HelloWorld <enter></pre><br />
The debugger will now run your program. If the program has no syntax or logic errors, the program should run and end with the line:<br />
Program exited normally.<br />
If there are errors, or the program crashed, it is possible to extract the exact details of that crash by issuing the back trace command.<br />
<pre>(gdb) bt <enter></pre><br />
Once you are done you can quit by issuing the command:<br />
<pre>(gdb) quit <enter></pre><br />
<br />
A complete list of commands in GDB:<br />
www.yolinux.com/TUTORIALS/GDB-Commands.html<br />
<br />
====GDB Debugger Tutorial====<br />
For a complete GDB Debugger tutorial (very good tutorial, comes with sample code they walk you through and extra errors for you to debug yourself!):<br />
http://www.cs.cmu.edu/~gilpin/tutorial/<br />
<br />
Now you have a debugger up and running! Play around with it by putting errors into your program on purpose to see the powers of having a remote debugger!<br />
<br />
==Use a C/C++ cross-compiler==<br />
In order to do C/C++ development on our host machine, we need to add in a plugin to Eclipse. Also, we need to download an appropriate cross-compilation toolchain. For now, I recommend the lovely instructions from<br />
<br />
http://www.designarm.com/quickstart-guide/linux-software/eclipse.html &<br />
<br />
http://www.bugcommunity.com/wiki/index.php/BUG_Kernel_Development_with_Eclipse<br />
<br />
==Further Reading==<br />
===Internal===<br />
[[Gaining Console Connection via Terminal]]<br><br />
[[HelloWorld | HelloWorld in Python, C and C++]]<br><br />
[[Remote Debugging with GDB]] <br><br />
[[HelloWorld in Java]]<br />
<br />
===External===<br />
:* Tutorials built into Eclipse<br />
:* Bitbake commander<br />
:* OpenEmebedded|Poky docs + Bitbake docs<br />
:* Eclipse Plugin Tutorial<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
[[Category:How_to_-_eclipse]]</div>JustinC474https://wiki.gumstix.com/index.php?title=Eclipse_on_Gumstix_for_new_users&diff=4490Eclipse on Gumstix for new users2010-08-05T18:52:44Z<p>JustinC474: /* Connect Your Gumstix */</p>
<hr />
<div>This guide provides step-by-step instructions for using the Eclipse Integrated Development Environment (IDE) to develop applications for the Gumstix COMs.<br />
<br />
We'll walk through these tasks:<br />
:* setting up Eclipse<br />
:* connection to your Gumstix system<br />
:* creating a simple "Hello, World!" Python program<br />
:* running a web server<br />
:* installing new packages on your Gumstix<br />
:* creating a small graphical Java application<br />
:* remote debugging of your Java application<br />
:* natively-compiling C/C++ code on your Gumstix<br />
:* remote debugging C/C++ using the GDB server interface<br />
<br />
We will also explain how to set up a cross-compilation toolchain so you can develop C/C++ applications on your development computer and upload them to your Gumstix.<br />
<br />
Remember, Gumstix COMs are fully-fledged, albeit tiny, Linux systems so there are many tools we don't cover here. For example, [http://wiki.openembedded.net/index.php/OpenEmbedded_Tools_for_Eclipse_(OTE) this document] explains how to use the powerful OpenEmbedded build system within Eclipse.<br />
<br />
Required Tools:<br />
:* any Windows, Apple or Linux computer with a USB port<br />
:* recent version of the Java Runtime Environment (available [http://java.sun.com/javase/downloads/index.jsp here])<br />
:* a Gumstix COM running [http://www.gumstix.net/Setup-and-Programming/view/Overo-Setup-and-Programming/Downloading-pre-built-images/111.html up-to-date software]<br />
:* any expansion board of the Gumstix Overo series, such as Chestnut or Tobi, that has both a USB console port and a 10/100 <br />
:* Ethernet jack<br />
:* a 5V power supply<br />
:* an ethernet cable and internet connection<br />
:* a mini-A to Standard-A USB cable<br />
:* a [http://www.gumstix.net/Setup-and-Programming/view/Overo-Setup-and-Programming/Creating-a-bootable-microSD-card/111.html bootable microSD card] (only needed for native C/C++ compilation)<br />
<br />
Key Idea:<br />
[[File:GumstixEclipse1.jpg|thumb|right|upright=5]]<br />
<br />
==Download Eclipse==<br />
[http://www.eclipse.org/downloads/ Download] the Eclipse IDE for Java Developers for your Operating System: www.eclipse.org<br />
<br />
[[Image: GumstixEclipse2.jpg | center | 600px]]<br />
<br />
<br />
:* it is ''not'' necessary to install the Eclipse software; just double-click on the application once it has finished downloading<br />
:* when prompted, choose a workspace folder in which you want to store your projects and your configuration information<br />
:* then click through to the Eclipse workbench itself<br />
<br />
==Install Plugins==<br />
For developers, a great variety of additional features can be added to Eclipse from various repositories of plug-ins known as ''Update Sites''.<br />
To install a new plugin in Eclipse, first select the ''Update Site''.<br />
:* navigate to '''Help->Install New Software...'''<br />
:* select the Update Site for your version of Eclipse from the "Work with"dropdown menu<br />
<br />
[[File:GumstixEclipse3.jpg | center | 1000px]]<br />
<br />
:Note: If you are not sure which version of Eclipse you have, you can check by reopening Eclipse, it will be displayed on the loading screen.<br />
<br />
----<br />
Hint:<br />
If the update site is not available, you can add it by clicking the 'Add...' button on the right. For the Galileo release, you can use the URL http://dowload.eclipse.org/releases/galileo<br />
----<br />
<br />
As we are working with a remote system, we'll install the Remote System Explorer plugin.<br />
:* search for the ''Remote System Explorer End-User Runtime'' plugin<br />
:* select it for installation<br />
<br />
[[File:GumstixEclipse4.jpg | center | 600px]]<br />
<br />
Still in Eclipse,<br />
:* select "Next".... twice<br />
:* select the radio button to "ACCEPT" the terms of the license agreement<br />
:* choose "Yes" to restart Eclipse for the changes to take effect<br />
<br />
Once Eclipse has restarted, let's add two other useful plugins that allow connection to the console port of our Gumstix without needing a terminal emulator program such as kermit or TeraTerm.<br />
From within Eclipse,<br />
:* navigate to '''Help->Install New Software'''<br />
:* search on "Target" to find the ''Target Manager Terminal''<br />
<br />
[[File:GumstixEclipse5.jpg | center | 1000px]]<br />
<br />
:* select the ''Target Manager Terminal''<br />
:* click "Next"<br />
:* click "Finish" to complete installation<br />
:* choose "Yes" to restart Eclipse for the changes to take effect<br />
<br />
We'll also need to add a new update site by doing these steps in Eclipse:<br />
:* navigate to '''Help->Install New Software...'''<br />
:* click the "Add..." button<br />
:* type ''http://rxtx.qbang.org/eclipse'' into the ''Location'' field and create a name<br />
<br />
[[File:GumstixEclipse6.jpg | center | 1000px]]<br />
<br />
:* Click the "OK" button<br />
Go into the sub-directory as shown below to select the ''RXTX End-User Runtime'' plugin that this site provides.<br />
<br />
[[File:GumstixEclipse7.jpg | center | 1000px]]<br />
<br />
:* click "Next" twice<br />
:* select the radio button to "ACCEPT" the terms of the license agreement<br />
:* click "OK" at the security warning window<br />
:* click "Finish" to complete installation<br />
:* choose the "Yes" button to restart Eclipse for the changes to take effect<br />
<br />
==Connect Your Gumstix==<br />
Now it is time to connect your Gumstix---let's get started by establishing a console connection.<br />
:* mount your Gumstix COM down on to your expansion board<br />
:* plug the mini-A USB plug into the port marked CONSOLE and end of the cable into a standard USB port on your computer<br />
----<br />
Hint:<br />
Your computer should detect your Gumstix system when you first connect the USB cable, even though the power is not yet turned on. On Macintosh and Windows systems, a pop-up window should appear instructing you to download a new driver (do so) or notifying you that a USBserial device has been detected. If not, you can download drivers from [http://www.ftdichip.com/FTDrivers.htm this site]. Choose the "VCP" driver.<br />
Once you have downloaded this driver, make sure to unplug and then replug the USB cable running from your computer to your Gumstix expansion board so the Gumstix will be recognized by your computer.<br />
----<br />
:* connect your Gumstix to the internet using an ethernet cable<br />
NOTE: You still have NOT plugged the power cable in to the <br />
Gumstix expansion board! This diagram shows the locations<br />
of the USB 'CONSOLE' port and the 'POWER' input port on a <br />
Summit board on which an Overo COM has been mounted.<br />
<br />
[[File:GumstixEclipse8.jpg | center ]]<br />
<br />
:* if you are booting from a microSD card, insert this card now until you hear it click in place.<br />
Before applying power to the board, let's open up a connection to the console port.<br />
In Eclipse,<br />
:* navigate to '''Window->Show View->Other->Terminal->Terminal'''<br />
:* click on the 'N' connection icon in the window that appears<br />
<br />
[[File:GumstixEclipse9.jpg | center ]]<br />
<br />
:* make the connection using the following settings:<br />
Connection Type: Serial<br />
Port: <port to which your Gumstix is connected><br />
Baud Rate: 115200<br />
Data Bits: 8<br />
Stop Bits: 1<br />
Parity: none<br />
Flow Control: none<br />
Timeout: 5<br />
<br />
----<br />
Hint:<br />
The port to which your Gumstix is connected will have a different name depending on your Host operating system.<br />
:* On Windows, it should be ''USB-COM''<br />
:* On Macintosh, it should be ''/dev/tty.usbserial-xxxxxxxx'' where ''xxxxxxxx'' is an arbitrary string of characters<br />
:* On Linux, it should be ''/dev/ttyUSBx'' where ''x'' is a number.<br />
----<br />
<br />
[[File:GumstixEclipse10.jpg | center | 800px]]<br />
<br />
----<br />
Hint:<br />
If this does not work, or you wish to gain Console access via a Unix Shell instead, visit the tutorial on [[Gaining Console Connection via Terminal]]<br />
----<br />
<br />
*Now, it's time to apply power to the Gumstix expansion board so plug the 5V wall adapter into the power input jack on the Gumstix.<br />
<br />
You should see text appear in this window; for now, just let the Gumstix boot. When prompted, you can log in to the root account. The default credentials are:<br />
<br />
'''Overo'''<br />
<br />
username: root<br />
<br />
password: <leave blank><br />
<br />
<br />
'''VerdexPro'''<br />
<br />
username: root<br />
<br />
password: gumstix<br />
<br />
==Create a Web Site==<br />
Each Gumstix comes with a built-in package manager called opkg. A package manager is a useful tool for installing software; you can install everything from media players to GPS mapping tools to the Firefox web browser. In this example, you'll use opkg tool to install a new application for your Gumstix: the Apache web server.<br />
<br />
To make your own Gumstix web site, type the following in the terminal window:<br />
opkg update <Enter><br />
opkg install apache2 <Enter><br />
Before you start using Apache, which is now running, you'll need to find the IP address (internet address) of your Gumstix COM. To do this, type the following command into the terminal window:<br />
ifconfig | grep 'inet addr' <Enter><br />
You should see something like this appear on your screen.<br />
inet addr: 10.0.1.73 Bcast: 192.168.0.255 Mask: 255.255.255.0<br />
The IP address of your Gumstix is the first address shown: ''10.0.1.73'' in this case.<br />
Now,<br />
:* open up a web browser on your host computer<br />
:* type that IP address of your Gumstix into the address bar<br />
You should see something like this which is the default web site for Apache running on your Gumstix.<br />
<br />
[[File:GumstixEclipse11.jpg]]<br />
<br />
To make your web site say something more interesting, do the follow in your terminal window:<br />
:* type: ''nano /usr/share/apache2/htdocs/index.html''<br />
:* replace the words at the top of the screen "It Works" with the words "Gumstix Rocks!"<br />
:* press 'Ctrl+O' <Enter><br />
:* press 'Ctrl+X' to save and exit<br />
:* refresh your web browser<br />
<br />
==Write a Java Application==<br />
So far, you haven't actually used Eclipse other than as a console interface for your Gumstix. It is time to harness the power of Eclipse to write a small graphical Java application.<br />
In Eclipse.<br />
:* Navigate to '''File-> New-> Java Project''',<br />
:* Name the project ''gumstix-java''<br />
:* Select "Finish"<br />
Once the project is created,<br />
:* Select '''File->New->Class'''<br />
:* Name your class ''Hello''<br />
:* click "FINISH"<br />
<br />
Add the following code to your class:<br />
<br />
import javax.swing.JFrame;<br />
import javax.swing.JLabel;<br />
public class Hello {<br />
public static void main(String [] args) {<br />
JFrame frame = new JFrame("hello");<br />
final JLabel label = new JLabel("hello from Gumstix");<br />
frame.getContentPane().add(label);<br />
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);<br />
frame.pack();<br />
frame.setVisible(true);<br />
}<br />
}<br />
<br />
You should get something that looks like this:<br />
<br />
[[File:GumstixEclipse12.jpg | center | 600px]]<br />
<br />
Press the green run button to test drive our application on our host machine.<br />
<br />
----<br />
Hint:<br />
Eclipse has many auto-completion features. Simply typing /:*<Enter> before a class creates a standard documentation block. Likewise, pressing <Ctrl>+<Space> provides context specific auto-completion options. Many other hints for speedy development are explained in the tutorials [http://www.eclipse.org/resources/?category=Getting%20Started here].<br />
----<br />
<br />
==Upload Code==<br />
In Step 5 we discovered the IP address of our Gumstix. With this, we can connect to our Gumstix using the SSH protocol which allows us to rapidly transfer files. For this step, navigate to '''Window->Open Perspective->Other->Remote System Explorer''' and click on the connection icon in the ''Remote Systems'' panel on the left. Select ''SSH without shells'' as the connection type and press Next. Put the internet address you found in Step 5 into the field marked ''Host Name'' and hit finish. To test that everything is working correctly, right-click on the terminal item list under your new connection and select ''Launch Terminal''. A console interface exactly like the USB console interface we set up in Step 3 should pop up.<br />
<br />
<br />
----<br />
Hint:<br />
A 'Perspective' is an arrangement of windows and widgets, that is a specific view of the Eclipse workspace, designed for a particular task. If you wish to focus on any particular widget, double click the tab in Eclipse; return to the previous view by double-clicking again.<br />
----<br />
<br />
<br />
By installing the VNC viewer plugin, we can get a graphical interface to our Gumstix system. Do this by adding the ''Tools for mobile linux runtime'' plugin ('''Help->Install New Software''') from the main update site. To use, select the VNC viewer widget from '''Window->Show View->Other->VNC Category->VNC''' and click on the ''New Connection'' icon in the VNC Viewer panel. Again, the ''Host'' is the internet address of your Gumstix board.<br />
<br />
[[File:GumstixEclipse13.jpg | center | 600px]]<br />
<br />
Finally, we need to upload our java code before we can run it. Switch back to the Java Perspective ('''Window->Open Perspective->Java''') and right-click on our Java file and selecting Export. Choose the option to export file to a remote file system and choose to upload your ''Hello.class'' file.<br />
<br />
[[File:GumstixEclipse14.jpg | center | 600px]]<br />
<br />
You will need to ''Browse'' to find your Gumstix board; you should upload this code to your home directory on the Gumstix.<br />
<br />
==Debug a Java Application==<br />
We can debug our java application remotely from Eclipse. To do this, we need a Java Virtual Machine capable of doing debugging. This time, the package we need isn't available in our package sources however we can fetch the package directly from a web site and install it using the same opkg package management tool.<br />
wget http://bugcommunity.com/downloads/files/phonemeadvanced- personal-debug_mr2-r1_armv6.ipk <Enter><br />
opkg install -force-depends phoneme-advanced-personaldebug_mr2-r1_armv6.ipk <Enter><br />
Let's also update our Java libraries so we have access to the standard graphical libraries.<br />
opkg install classpath-gtk <Enter><br />
Next, let's start our Java code in debugging mode on the Overo:<br />
java-cdc -Xdebug -Xrunjwdp:transport=dHt_socket,server=y,suspend=y,address=1234 Hello <Enter><br />
Finally, let's connect to our debugging session by navigating in Eclipse to '''Run->Debug Configurations''' and double-clicking on Remote Java Application to create a new configuration. Fill in the form as shown below using the internet address found in the previous step.<br />
<br />
==Install a native C/C++ SDK==<br />
When we discussed Python and Java we noted that both are interpreted languages--- neither needs to be compiled. C and C++ code requires compilation which can be done natively---on the Gumstix itself---or on a development machine using a cross-compiler. To do native compilation, you need to install a compiler as well as any required libraries. You'll need to be booting from a microSD card as this installation takes approximately 75MB of space.<br />
$ echo 'src/gz angstrom-base http://www.angstromdistribution.org/feeds/unstable/ipk/glibc/armv7a/base' > /etc/opkg/angstrom-base.conf<br />
$ opkg update<br />
$ opkg install task-native-sdk<br />
Firstly, we are adding a new package repository to our package manager and updating our list of available packages before actually installing the complete package needed to do native development.<br />
<br />
Let's create either of the following files in Eclipse, upload the code and then compile on the Gumstix using our newly installed compiler.<br />
<br />
===C++: HelloWorld.cpp===<br />
#include <iostream><br />
using namespace std;<br />
int main () {<br />
cout << "Gumstix runs on C++" << endl;<br />
return 0;<br />
}<br />
<br />
Save the file and issue the following commands to compile and run HelloWorld.cpp<br />
g++ -o hello hello.cpp <enter><br />
Gumstix runs on C++ <enter><br />
<br />
===C: HelloWorld.c===<br />
#include <stdio.h><br />
int main () {<br />
printf("Gumstix runs on C\n");<br />
return 0;<br />
}<br />
<br />
Save the file and issue the following commands to compile and run HelloWorld.c<br />
gcc -o hello hello.c<br />
Gumstix runs on C<br />
<br />
<TODO: More exciting examples using on-board LEDs.><br />
<br />
==Using GDB as a remote debugger in C/C++==<br />
These instructions will teach you how to download, install, and use the GDB debugger remotely on your Overo COM.<br />
<br />
<pre>NOTE: <br />
remote system - a device that is being operated remotely (via SSH, USB Serial, etc). This means that it is a device that you are operating from a different system <br />
(ie: if you are accessing the Overo COM via connection with your PC, then the Overo COM is a remote system).<br />
For the purpose of this guide, the Overo COM will be the remote system.<br />
<br />
local host - the device that is being used to work on (ie: If you are working on your PC, that is the local host. If you then connect to another computer via VNC, <br />
that is a remote system, and you laptop is still the localhost).<br />
For the purpose of this guide, your Personal Computer will be the local host.</pre><br />
<br />
Before starting, it is important to note there are many different ways to run a remote debugger. The most fundamental choice when debugging remotely is whether you want to:<br />
:*Run the debugger on the remote system or<br />
:*Run the debugger on the local host with a cross debugger on the remote system<br />
<br />
This guide will teach you how to download, install, and run the debugger on the remote system (choice A). If you wish to learn more about the cross debugger option, use Google. Also the wikipedia article on cross compilers (which operate in a very similar fashion) is very good, albeit a bit complicated. None of this is necessary in understanding the contents of this guide. <br />
<br />
For the purposes of this guide, we will be using the GDB: the GNU project debugger. As stated on their website:<br />
<br />
<pre>GDB, the GNU Project debugger, allows you to see what is going on `inside' another program while it executes -- or what another program was doing at the moment it <br />
crashed.<br />
<br />
GDB can do four main kinds of things (plus other things in support of these) to help you catch bugs in the act:<br />
- Start your program, specifying anything that might affect its behavior.<br />
- Make your program stop on specified conditions.<br />
- Examine what has happened, when your program has stopped.<br />
- Change things in your program, so you can experiment with correcting the effects of one bug and go on to learn about another.</pre><br />
<br />
While the reasons for using a debugger instead of trying to debug with the ‘brute force’ method of adding print statements throughout the entire program are enumerable, there are a few that stand out:<br />
# The ability to ‘step’ through a program<br />
#* The GDB debugger allows you to ‘step’ through a program. This means that instead of just executing the program and then leaving you with a final error message, it will execute one line at a time until the program crashes. This allows the user to see exactly where, and why, the program crashed. <br />
# The ability to set breakpoints<br />
#* The GDB debugger allows you to set breakpoints in the program. These are points where the CPU will stop executing the code and allow the user to decide whether to continue. This allows the user to explore what is ‘going on’ at certain points in the execution, something that otherwise is not possible. <br />
# The ability to look at the Backtrace<br />
#* This will show you where, and exactly why, your program crashed. Although SEGFAULT isn’t very useful, the backtrace will tell you what caused the SEGFAULT. Everything from what line, what variable, and even the address that variable was at.<br />
<br />
===Installing the GDB===<br />
Once the Overo COM has been connected to the local host, you should have access to the following command line:<br />
<pre>root@overo:~# </pre><br />
Although you are working on your local host, this command line is for the remote system. It is the same as if you opened up Terminal (for Mac, Linux) or XTerm (for Windows). You now have access and control of the remote system.<br />
<br />
Now there are some packages that must be downloaded and installed onto the Overo so that it can run the GDB environment. To do this issue the following command:<br />
<pre>opkg update <enter><br />
opkg install gdb <enter></pre><br />
This should spew out a bunch of text such as:<br />
<pre>Downloading http://www.angstrom...</pre><br />
Just let it run and once its done, you’ll have the GNU GDB debugger installed on your Overo COM.<br />
<br />
===Creating a C/C++ Program to Debug===<br />
Now, your Overo COM has a debugger installed and ready to use. However, this does not mean you are ready to go. There are two more things required before it is possible to use a GDB debugger.<br />
:* A C/C++ program<br />
:* A SDK to run the program on<br />
To see how to install a SDK and write/run a simple program in C/C++, see [[#Install a native C/C++ SDK]]. <br />
<br />
Once you have a program ready, you first must create an executable file. Lets use for example the C++ program HelloWorld.cpp. To create the executable file HelloWorld, issue the following command:<br />
<pre>g++ -o HelloWorld HelloWorld.cpp <enter></pre><br />
Now, to run the program:<br />
<pre>./HelloWorld <enter></pre><br />
To do the same thing with a C program (HelloWorld.c), issue the command<br />
<pre>gcc -o HelloWorld HelloWorld.c <enter></pre><br />
<pre>./HelloWorld <enter></pre><br />
<br />
What this command does is uses the GNU compiler (either g++ or gcc) and creates an executable object (HelloWorld) out of the C or C++ program file (either HelloWorld.cpp or HelloWorld.c). You may name the executable whatever you like, but it is considered best practice to name it the same thing as the program file.<br />
<br />
===Debugging the Program===<br />
Now that you have GDB installed and a C/C++ program ready to go, its time to debug. To open to GDB environment, run the following command<br />
<pre>gdb <enter></pre><br />
Some text should spit out, and the following command line should appear<br />
<pre>(gdb)</pre><br />
Now that the debugger is running, it is time to tell the debugger what program we want to debug. To do this, first we need to declare our HelloWorld file as an executable file. For this run the following command <br />
<pre>(gdb) exec-file HelloWorld <enter></pre><br />
Now that we have an executable file ready to be debugged, its time to run the program<br />
<pre>(gdb) run HelloWorld <enter></pre><br />
The debugger will now run your program. If the program has no syntax or logic errors, the program should run and end with the line:<br />
Program exited normally.<br />
If there are errors, or the program crashed, it is possible to extract the exact details of that crash by issuing the back trace command.<br />
<pre>(gdb) bt <enter></pre><br />
Once you are done you can quit by issuing the command:<br />
<pre>(gdb) quit <enter></pre><br />
<br />
A complete list of commands in GDB:<br />
www.yolinux.com/TUTORIALS/GDB-Commands.html<br />
<br />
====GDB Debugger Tutorial====<br />
For a complete GDB Debugger tutorial (very good tutorial, comes with sample code they walk you through and extra errors for you to debug yourself!):<br />
http://www.cs.cmu.edu/~gilpin/tutorial/<br />
<br />
Now you have a debugger up and running! Play around with it by putting errors into your program on purpose to see the powers of having a remote debugger!<br />
<br />
==Use a C/C++ cross-compiler==<br />
In order to do C/C++ development on our host machine, we need to add in a plugin to Eclipse. Also, we need to download an appropriate cross-compilation toolchain. For now, I recommend the lovely instructions from<br />
<br />
http://www.designarm.com/quickstart-guide/linux-software/eclipse.html &<br />
<br />
http://www.bugcommunity.com/wiki/index.php/BUG_Kernel_Development_with_Eclipse<br />
<br />
==Further Reading==<br />
===Internal===<br />
[[Gaining Console Connection via Terminal]]<br><br />
[[HelloWorld | HelloWorld in Python, C and C++]]<br><br />
[[Remote Debugging with GDB]] <br><br />
[[HelloWorld in Java]]<br />
<br />
===External===<br />
:* Tutorials built into Eclipse<br />
:* Bitbake commander<br />
:* OpenEmebedded|Poky docs + Bitbake docs<br />
:* Eclipse Plugin Tutorial<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
[[Category:How_to_-_eclipse]]</div>JustinC474https://wiki.gumstix.com/index.php?title=Eclipse_on_Gumstix_for_new_users&diff=4489Eclipse on Gumstix for new users2010-08-05T18:52:03Z<p>JustinC474: /* Connect Your Gumstix */</p>
<hr />
<div>This guide provides step-by-step instructions for using the Eclipse Integrated Development Environment (IDE) to develop applications for the Gumstix COMs.<br />
<br />
We'll walk through these tasks:<br />
:* setting up Eclipse<br />
:* connection to your Gumstix system<br />
:* creating a simple "Hello, World!" Python program<br />
:* running a web server<br />
:* installing new packages on your Gumstix<br />
:* creating a small graphical Java application<br />
:* remote debugging of your Java application<br />
:* natively-compiling C/C++ code on your Gumstix<br />
:* remote debugging C/C++ using the GDB server interface<br />
<br />
We will also explain how to set up a cross-compilation toolchain so you can develop C/C++ applications on your development computer and upload them to your Gumstix.<br />
<br />
Remember, Gumstix COMs are fully-fledged, albeit tiny, Linux systems so there are many tools we don't cover here. For example, [http://wiki.openembedded.net/index.php/OpenEmbedded_Tools_for_Eclipse_(OTE) this document] explains how to use the powerful OpenEmbedded build system within Eclipse.<br />
<br />
Required Tools:<br />
:* any Windows, Apple or Linux computer with a USB port<br />
:* recent version of the Java Runtime Environment (available [http://java.sun.com/javase/downloads/index.jsp here])<br />
:* a Gumstix COM running [http://www.gumstix.net/Setup-and-Programming/view/Overo-Setup-and-Programming/Downloading-pre-built-images/111.html up-to-date software]<br />
:* any expansion board of the Gumstix Overo series, such as Chestnut or Tobi, that has both a USB console port and a 10/100 <br />
:* Ethernet jack<br />
:* a 5V power supply<br />
:* an ethernet cable and internet connection<br />
:* a mini-A to Standard-A USB cable<br />
:* a [http://www.gumstix.net/Setup-and-Programming/view/Overo-Setup-and-Programming/Creating-a-bootable-microSD-card/111.html bootable microSD card] (only needed for native C/C++ compilation)<br />
<br />
Key Idea:<br />
[[File:GumstixEclipse1.jpg|thumb|right|upright=5]]<br />
<br />
==Download Eclipse==<br />
[http://www.eclipse.org/downloads/ Download] the Eclipse IDE for Java Developers for your Operating System: www.eclipse.org<br />
<br />
[[Image: GumstixEclipse2.jpg | center | 600px]]<br />
<br />
<br />
:* it is ''not'' necessary to install the Eclipse software; just double-click on the application once it has finished downloading<br />
:* when prompted, choose a workspace folder in which you want to store your projects and your configuration information<br />
:* then click through to the Eclipse workbench itself<br />
<br />
==Install Plugins==<br />
For developers, a great variety of additional features can be added to Eclipse from various repositories of plug-ins known as ''Update Sites''.<br />
To install a new plugin in Eclipse, first select the ''Update Site''.<br />
:* navigate to '''Help->Install New Software...'''<br />
:* select the Update Site for your version of Eclipse from the "Work with"dropdown menu<br />
<br />
[[File:GumstixEclipse3.jpg | center | 1000px]]<br />
<br />
:Note: If you are not sure which version of Eclipse you have, you can check by reopening Eclipse, it will be displayed on the loading screen.<br />
<br />
----<br />
Hint:<br />
If the update site is not available, you can add it by clicking the 'Add...' button on the right. For the Galileo release, you can use the URL http://dowload.eclipse.org/releases/galileo<br />
----<br />
<br />
As we are working with a remote system, we'll install the Remote System Explorer plugin.<br />
:* search for the ''Remote System Explorer End-User Runtime'' plugin<br />
:* select it for installation<br />
<br />
[[File:GumstixEclipse4.jpg | center | 600px]]<br />
<br />
Still in Eclipse,<br />
:* select "Next".... twice<br />
:* select the radio button to "ACCEPT" the terms of the license agreement<br />
:* choose "Yes" to restart Eclipse for the changes to take effect<br />
<br />
Once Eclipse has restarted, let's add two other useful plugins that allow connection to the console port of our Gumstix without needing a terminal emulator program such as kermit or TeraTerm.<br />
From within Eclipse,<br />
:* navigate to '''Help->Install New Software'''<br />
:* search on "Target" to find the ''Target Manager Terminal''<br />
<br />
[[File:GumstixEclipse5.jpg | center | 1000px]]<br />
<br />
:* select the ''Target Manager Terminal''<br />
:* click "Next"<br />
:* click "Finish" to complete installation<br />
:* choose "Yes" to restart Eclipse for the changes to take effect<br />
<br />
We'll also need to add a new update site by doing these steps in Eclipse:<br />
:* navigate to '''Help->Install New Software...'''<br />
:* click the "Add..." button<br />
:* type ''http://rxtx.qbang.org/eclipse'' into the ''Location'' field and create a name<br />
<br />
[[File:GumstixEclipse6.jpg | center | 1000px]]<br />
<br />
:* Click the "OK" button<br />
Go into the sub-directory as shown below to select the ''RXTX End-User Runtime'' plugin that this site provides.<br />
<br />
[[File:GumstixEclipse7.jpg | center | 1000px]]<br />
<br />
:* click "Next" twice<br />
:* select the radio button to "ACCEPT" the terms of the license agreement<br />
:* click "OK" at the security warning window<br />
:* click "Finish" to complete installation<br />
:* choose the "Yes" button to restart Eclipse for the changes to take effect<br />
<br />
==Connect Your Gumstix==<br />
Now it is time to connect your Gumstix---let's get started by establishing a console connection.<br />
:* mount your Gumstix COM down on to your expansion board<br />
:* plug the mini-A USB plug into the port marked CONSOLE and end of the cable into a standard USB port on your computer<br />
----<br />
Hint:<br />
Your computer should detect your Gumstix system when you first connect the USB cable, even though the power is not yet turned on. On Macintosh and Windows systems, a pop-up window should appear instructing you to download a new driver (do so) or notifying you that a USBserial device has been detected. If not, you can download drivers from [http://www.ftdichip.com/FTDrivers.htm this site]. Choose the "VCP" driver.<br />
Once you have downloaded this driver, make sure to unplug and then replug the USB cable running from your computer to your Gumstix expansion board so the Gumstix will be recognized by your computer.<br />
----<br />
:* connect your Gumstix to the internet using an ethernet cable<br />
NOTE: You still have NOT plugged the power cable in to the <br />
Gumstix expansion board! This diagram shows the locations<br />
of the USB 'CONSOLE' port and the 'POWER' input port on a <br />
Summit board on which an Overo COM has been mounted.<br />
<br />
[[File:GumstixEclipse8.jpg | center ]]<br />
<br />
:* if you are booting from a microSD card, insert this card now until you hear it click in place.<br />
Before applying power to the board, let's open up a connection to the console port.<br />
In Eclipse,<br />
:* navigate to '''Window->Show View->Other->Terminal->Terminal'''<br />
:* click on the 'N' connection icon in the window that appears<br />
<br />
[[File:GumstixEclipse9.jpg | center ]]<br />
<br />
:* make the connection using the following settings:<br />
Connection Type: Serial<br />
Port: <port to which your Gumstix is connected><br />
Baud Rate: 115200<br />
Data Bits: 8<br />
Stop Bits: 1<br />
Parity: none<br />
Flow Control: none<br />
Timeout: 5<br />
<br />
----<br />
Hint:<br />
The port to which your Gumstix is connected will have a different name depending on your Host operating system.<br />
:* On Windows, it should be ''USB-COM''<br />
:* On Macintosh, it should be ''/dev/tty.usbserial-xxxxxxxx'' where ''xxxxxxxx'' is an arbitrary string of characters<br />
:* On Linux, it should be ''/dev/ttyUSBx'' where ''x'' is a number.<br />
----<br />
<br />
[[File:GumstixEclipse10.jpg | center | 1000px]]<br />
<br />
----<br />
Hint:<br />
If this does not work, or you wish to gain Console access via a Unix Shell instead, visit the tutorial on [[Gaining Console Connection via Terminal]]<br />
----<br />
<br />
*Now, it's time to apply power to the Gumstix expansion board so plug the 5V wall adapter into the power input jack on the Gumstix.<br />
<br />
You should see text appear in this window; for now, just let the Gumstix boot. When prompted, you can log in to the root account. The default credentials are:<br />
<br />
'''Overo'''<br />
<br />
username: root<br />
<br />
password: <leave blank><br />
<br />
<br />
'''VerdexPro'''<br />
<br />
username: root<br />
<br />
password: gumstix<br />
<br />
==Create a Web Site==<br />
Each Gumstix comes with a built-in package manager called opkg. A package manager is a useful tool for installing software; you can install everything from media players to GPS mapping tools to the Firefox web browser. In this example, you'll use opkg tool to install a new application for your Gumstix: the Apache web server.<br />
<br />
To make your own Gumstix web site, type the following in the terminal window:<br />
opkg update <Enter><br />
opkg install apache2 <Enter><br />
Before you start using Apache, which is now running, you'll need to find the IP address (internet address) of your Gumstix COM. To do this, type the following command into the terminal window:<br />
ifconfig | grep 'inet addr' <Enter><br />
You should see something like this appear on your screen.<br />
inet addr: 10.0.1.73 Bcast: 192.168.0.255 Mask: 255.255.255.0<br />
The IP address of your Gumstix is the first address shown: ''10.0.1.73'' in this case.<br />
Now,<br />
:* open up a web browser on your host computer<br />
:* type that IP address of your Gumstix into the address bar<br />
You should see something like this which is the default web site for Apache running on your Gumstix.<br />
<br />
[[File:GumstixEclipse11.jpg]]<br />
<br />
To make your web site say something more interesting, do the follow in your terminal window:<br />
:* type: ''nano /usr/share/apache2/htdocs/index.html''<br />
:* replace the words at the top of the screen "It Works" with the words "Gumstix Rocks!"<br />
:* press 'Ctrl+O' <Enter><br />
:* press 'Ctrl+X' to save and exit<br />
:* refresh your web browser<br />
<br />
==Write a Java Application==<br />
So far, you haven't actually used Eclipse other than as a console interface for your Gumstix. It is time to harness the power of Eclipse to write a small graphical Java application.<br />
In Eclipse.<br />
:* Navigate to '''File-> New-> Java Project''',<br />
:* Name the project ''gumstix-java''<br />
:* Select "Finish"<br />
Once the project is created,<br />
:* Select '''File->New->Class'''<br />
:* Name your class ''Hello''<br />
:* click "FINISH"<br />
<br />
Add the following code to your class:<br />
<br />
import javax.swing.JFrame;<br />
import javax.swing.JLabel;<br />
public class Hello {<br />
public static void main(String [] args) {<br />
JFrame frame = new JFrame("hello");<br />
final JLabel label = new JLabel("hello from Gumstix");<br />
frame.getContentPane().add(label);<br />
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);<br />
frame.pack();<br />
frame.setVisible(true);<br />
}<br />
}<br />
<br />
You should get something that looks like this:<br />
<br />
[[File:GumstixEclipse12.jpg | center | 600px]]<br />
<br />
Press the green run button to test drive our application on our host machine.<br />
<br />
----<br />
Hint:<br />
Eclipse has many auto-completion features. Simply typing /:*<Enter> before a class creates a standard documentation block. Likewise, pressing <Ctrl>+<Space> provides context specific auto-completion options. Many other hints for speedy development are explained in the tutorials [http://www.eclipse.org/resources/?category=Getting%20Started here].<br />
----<br />
<br />
==Upload Code==<br />
In Step 5 we discovered the IP address of our Gumstix. With this, we can connect to our Gumstix using the SSH protocol which allows us to rapidly transfer files. For this step, navigate to '''Window->Open Perspective->Other->Remote System Explorer''' and click on the connection icon in the ''Remote Systems'' panel on the left. Select ''SSH without shells'' as the connection type and press Next. Put the internet address you found in Step 5 into the field marked ''Host Name'' and hit finish. To test that everything is working correctly, right-click on the terminal item list under your new connection and select ''Launch Terminal''. A console interface exactly like the USB console interface we set up in Step 3 should pop up.<br />
<br />
<br />
----<br />
Hint:<br />
A 'Perspective' is an arrangement of windows and widgets, that is a specific view of the Eclipse workspace, designed for a particular task. If you wish to focus on any particular widget, double click the tab in Eclipse; return to the previous view by double-clicking again.<br />
----<br />
<br />
<br />
By installing the VNC viewer plugin, we can get a graphical interface to our Gumstix system. Do this by adding the ''Tools for mobile linux runtime'' plugin ('''Help->Install New Software''') from the main update site. To use, select the VNC viewer widget from '''Window->Show View->Other->VNC Category->VNC''' and click on the ''New Connection'' icon in the VNC Viewer panel. Again, the ''Host'' is the internet address of your Gumstix board.<br />
<br />
[[File:GumstixEclipse13.jpg | center | 600px]]<br />
<br />
Finally, we need to upload our java code before we can run it. Switch back to the Java Perspective ('''Window->Open Perspective->Java''') and right-click on our Java file and selecting Export. Choose the option to export file to a remote file system and choose to upload your ''Hello.class'' file.<br />
<br />
[[File:GumstixEclipse14.jpg | center | 600px]]<br />
<br />
You will need to ''Browse'' to find your Gumstix board; you should upload this code to your home directory on the Gumstix.<br />
<br />
==Debug a Java Application==<br />
We can debug our java application remotely from Eclipse. To do this, we need a Java Virtual Machine capable of doing debugging. This time, the package we need isn't available in our package sources however we can fetch the package directly from a web site and install it using the same opkg package management tool.<br />
wget http://bugcommunity.com/downloads/files/phonemeadvanced- personal-debug_mr2-r1_armv6.ipk <Enter><br />
opkg install -force-depends phoneme-advanced-personaldebug_mr2-r1_armv6.ipk <Enter><br />
Let's also update our Java libraries so we have access to the standard graphical libraries.<br />
opkg install classpath-gtk <Enter><br />
Next, let's start our Java code in debugging mode on the Overo:<br />
java-cdc -Xdebug -Xrunjwdp:transport=dHt_socket,server=y,suspend=y,address=1234 Hello <Enter><br />
Finally, let's connect to our debugging session by navigating in Eclipse to '''Run->Debug Configurations''' and double-clicking on Remote Java Application to create a new configuration. Fill in the form as shown below using the internet address found in the previous step.<br />
<br />
==Install a native C/C++ SDK==<br />
When we discussed Python and Java we noted that both are interpreted languages--- neither needs to be compiled. C and C++ code requires compilation which can be done natively---on the Gumstix itself---or on a development machine using a cross-compiler. To do native compilation, you need to install a compiler as well as any required libraries. You'll need to be booting from a microSD card as this installation takes approximately 75MB of space.<br />
$ echo 'src/gz angstrom-base http://www.angstromdistribution.org/feeds/unstable/ipk/glibc/armv7a/base' > /etc/opkg/angstrom-base.conf<br />
$ opkg update<br />
$ opkg install task-native-sdk<br />
Firstly, we are adding a new package repository to our package manager and updating our list of available packages before actually installing the complete package needed to do native development.<br />
<br />
Let's create either of the following files in Eclipse, upload the code and then compile on the Gumstix using our newly installed compiler.<br />
<br />
===C++: HelloWorld.cpp===<br />
#include <iostream><br />
using namespace std;<br />
int main () {<br />
cout << "Gumstix runs on C++" << endl;<br />
return 0;<br />
}<br />
<br />
Save the file and issue the following commands to compile and run HelloWorld.cpp<br />
g++ -o hello hello.cpp <enter><br />
Gumstix runs on C++ <enter><br />
<br />
===C: HelloWorld.c===<br />
#include <stdio.h><br />
int main () {<br />
printf("Gumstix runs on C\n");<br />
return 0;<br />
}<br />
<br />
Save the file and issue the following commands to compile and run HelloWorld.c<br />
gcc -o hello hello.c<br />
Gumstix runs on C<br />
<br />
<TODO: More exciting examples using on-board LEDs.><br />
<br />
==Using GDB as a remote debugger in C/C++==<br />
These instructions will teach you how to download, install, and use the GDB debugger remotely on your Overo COM.<br />
<br />
<pre>NOTE: <br />
remote system - a device that is being operated remotely (via SSH, USB Serial, etc). This means that it is a device that you are operating from a different system <br />
(ie: if you are accessing the Overo COM via connection with your PC, then the Overo COM is a remote system).<br />
For the purpose of this guide, the Overo COM will be the remote system.<br />
<br />
local host - the device that is being used to work on (ie: If you are working on your PC, that is the local host. If you then connect to another computer via VNC, <br />
that is a remote system, and you laptop is still the localhost).<br />
For the purpose of this guide, your Personal Computer will be the local host.</pre><br />
<br />
Before starting, it is important to note there are many different ways to run a remote debugger. The most fundamental choice when debugging remotely is whether you want to:<br />
:*Run the debugger on the remote system or<br />
:*Run the debugger on the local host with a cross debugger on the remote system<br />
<br />
This guide will teach you how to download, install, and run the debugger on the remote system (choice A). If you wish to learn more about the cross debugger option, use Google. Also the wikipedia article on cross compilers (which operate in a very similar fashion) is very good, albeit a bit complicated. None of this is necessary in understanding the contents of this guide. <br />
<br />
For the purposes of this guide, we will be using the GDB: the GNU project debugger. As stated on their website:<br />
<br />
<pre>GDB, the GNU Project debugger, allows you to see what is going on `inside' another program while it executes -- or what another program was doing at the moment it <br />
crashed.<br />
<br />
GDB can do four main kinds of things (plus other things in support of these) to help you catch bugs in the act:<br />
- Start your program, specifying anything that might affect its behavior.<br />
- Make your program stop on specified conditions.<br />
- Examine what has happened, when your program has stopped.<br />
- Change things in your program, so you can experiment with correcting the effects of one bug and go on to learn about another.</pre><br />
<br />
While the reasons for using a debugger instead of trying to debug with the ‘brute force’ method of adding print statements throughout the entire program are enumerable, there are a few that stand out:<br />
# The ability to ‘step’ through a program<br />
#* The GDB debugger allows you to ‘step’ through a program. This means that instead of just executing the program and then leaving you with a final error message, it will execute one line at a time until the program crashes. This allows the user to see exactly where, and why, the program crashed. <br />
# The ability to set breakpoints<br />
#* The GDB debugger allows you to set breakpoints in the program. These are points where the CPU will stop executing the code and allow the user to decide whether to continue. This allows the user to explore what is ‘going on’ at certain points in the execution, something that otherwise is not possible. <br />
# The ability to look at the Backtrace<br />
#* This will show you where, and exactly why, your program crashed. Although SEGFAULT isn’t very useful, the backtrace will tell you what caused the SEGFAULT. Everything from what line, what variable, and even the address that variable was at.<br />
<br />
===Installing the GDB===<br />
Once the Overo COM has been connected to the local host, you should have access to the following command line:<br />
<pre>root@overo:~# </pre><br />
Although you are working on your local host, this command line is for the remote system. It is the same as if you opened up Terminal (for Mac, Linux) or XTerm (for Windows). You now have access and control of the remote system.<br />
<br />
Now there are some packages that must be downloaded and installed onto the Overo so that it can run the GDB environment. To do this issue the following command:<br />
<pre>opkg update <enter><br />
opkg install gdb <enter></pre><br />
This should spew out a bunch of text such as:<br />
<pre>Downloading http://www.angstrom...</pre><br />
Just let it run and once its done, you’ll have the GNU GDB debugger installed on your Overo COM.<br />
<br />
===Creating a C/C++ Program to Debug===<br />
Now, your Overo COM has a debugger installed and ready to use. However, this does not mean you are ready to go. There are two more things required before it is possible to use a GDB debugger.<br />
:* A C/C++ program<br />
:* A SDK to run the program on<br />
To see how to install a SDK and write/run a simple program in C/C++, see [[#Install a native C/C++ SDK]]. <br />
<br />
Once you have a program ready, you first must create an executable file. Lets use for example the C++ program HelloWorld.cpp. To create the executable file HelloWorld, issue the following command:<br />
<pre>g++ -o HelloWorld HelloWorld.cpp <enter></pre><br />
Now, to run the program:<br />
<pre>./HelloWorld <enter></pre><br />
To do the same thing with a C program (HelloWorld.c), issue the command<br />
<pre>gcc -o HelloWorld HelloWorld.c <enter></pre><br />
<pre>./HelloWorld <enter></pre><br />
<br />
What this command does is uses the GNU compiler (either g++ or gcc) and creates an executable object (HelloWorld) out of the C or C++ program file (either HelloWorld.cpp or HelloWorld.c). You may name the executable whatever you like, but it is considered best practice to name it the same thing as the program file.<br />
<br />
===Debugging the Program===<br />
Now that you have GDB installed and a C/C++ program ready to go, its time to debug. To open to GDB environment, run the following command<br />
<pre>gdb <enter></pre><br />
Some text should spit out, and the following command line should appear<br />
<pre>(gdb)</pre><br />
Now that the debugger is running, it is time to tell the debugger what program we want to debug. To do this, first we need to declare our HelloWorld file as an executable file. For this run the following command <br />
<pre>(gdb) exec-file HelloWorld <enter></pre><br />
Now that we have an executable file ready to be debugged, its time to run the program<br />
<pre>(gdb) run HelloWorld <enter></pre><br />
The debugger will now run your program. If the program has no syntax or logic errors, the program should run and end with the line:<br />
Program exited normally.<br />
If there are errors, or the program crashed, it is possible to extract the exact details of that crash by issuing the back trace command.<br />
<pre>(gdb) bt <enter></pre><br />
Once you are done you can quit by issuing the command:<br />
<pre>(gdb) quit <enter></pre><br />
<br />
A complete list of commands in GDB:<br />
www.yolinux.com/TUTORIALS/GDB-Commands.html<br />
<br />
====GDB Debugger Tutorial====<br />
For a complete GDB Debugger tutorial (very good tutorial, comes with sample code they walk you through and extra errors for you to debug yourself!):<br />
http://www.cs.cmu.edu/~gilpin/tutorial/<br />
<br />
Now you have a debugger up and running! Play around with it by putting errors into your program on purpose to see the powers of having a remote debugger!<br />
<br />
==Use a C/C++ cross-compiler==<br />
In order to do C/C++ development on our host machine, we need to add in a plugin to Eclipse. Also, we need to download an appropriate cross-compilation toolchain. For now, I recommend the lovely instructions from<br />
<br />
http://www.designarm.com/quickstart-guide/linux-software/eclipse.html &<br />
<br />
http://www.bugcommunity.com/wiki/index.php/BUG_Kernel_Development_with_Eclipse<br />
<br />
==Further Reading==<br />
===Internal===<br />
[[Gaining Console Connection via Terminal]]<br><br />
[[HelloWorld | HelloWorld in Python, C and C++]]<br><br />
[[Remote Debugging with GDB]] <br><br />
[[HelloWorld in Java]]<br />
<br />
===External===<br />
:* Tutorials built into Eclipse<br />
:* Bitbake commander<br />
:* OpenEmebedded|Poky docs + Bitbake docs<br />
:* Eclipse Plugin Tutorial<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
[[Category:How_to_-_eclipse]]</div>JustinC474https://wiki.gumstix.com/index.php?title=Eclipse_on_Gumstix_for_new_users&diff=4488Eclipse on Gumstix for new users2010-08-05T18:50:08Z<p>JustinC474: /* Install Plugins */</p>
<hr />
<div>This guide provides step-by-step instructions for using the Eclipse Integrated Development Environment (IDE) to develop applications for the Gumstix COMs.<br />
<br />
We'll walk through these tasks:<br />
:* setting up Eclipse<br />
:* connection to your Gumstix system<br />
:* creating a simple "Hello, World!" Python program<br />
:* running a web server<br />
:* installing new packages on your Gumstix<br />
:* creating a small graphical Java application<br />
:* remote debugging of your Java application<br />
:* natively-compiling C/C++ code on your Gumstix<br />
:* remote debugging C/C++ using the GDB server interface<br />
<br />
We will also explain how to set up a cross-compilation toolchain so you can develop C/C++ applications on your development computer and upload them to your Gumstix.<br />
<br />
Remember, Gumstix COMs are fully-fledged, albeit tiny, Linux systems so there are many tools we don't cover here. For example, [http://wiki.openembedded.net/index.php/OpenEmbedded_Tools_for_Eclipse_(OTE) this document] explains how to use the powerful OpenEmbedded build system within Eclipse.<br />
<br />
Required Tools:<br />
:* any Windows, Apple or Linux computer with a USB port<br />
:* recent version of the Java Runtime Environment (available [http://java.sun.com/javase/downloads/index.jsp here])<br />
:* a Gumstix COM running [http://www.gumstix.net/Setup-and-Programming/view/Overo-Setup-and-Programming/Downloading-pre-built-images/111.html up-to-date software]<br />
:* any expansion board of the Gumstix Overo series, such as Chestnut or Tobi, that has both a USB console port and a 10/100 <br />
:* Ethernet jack<br />
:* a 5V power supply<br />
:* an ethernet cable and internet connection<br />
:* a mini-A to Standard-A USB cable<br />
:* a [http://www.gumstix.net/Setup-and-Programming/view/Overo-Setup-and-Programming/Creating-a-bootable-microSD-card/111.html bootable microSD card] (only needed for native C/C++ compilation)<br />
<br />
Key Idea:<br />
[[File:GumstixEclipse1.jpg|thumb|right|upright=5]]<br />
<br />
==Download Eclipse==<br />
[http://www.eclipse.org/downloads/ Download] the Eclipse IDE for Java Developers for your Operating System: www.eclipse.org<br />
<br />
[[Image: GumstixEclipse2.jpg | center | 600px]]<br />
<br />
<br />
:* it is ''not'' necessary to install the Eclipse software; just double-click on the application once it has finished downloading<br />
:* when prompted, choose a workspace folder in which you want to store your projects and your configuration information<br />
:* then click through to the Eclipse workbench itself<br />
<br />
==Install Plugins==<br />
For developers, a great variety of additional features can be added to Eclipse from various repositories of plug-ins known as ''Update Sites''.<br />
To install a new plugin in Eclipse, first select the ''Update Site''.<br />
:* navigate to '''Help->Install New Software...'''<br />
:* select the Update Site for your version of Eclipse from the "Work with"dropdown menu<br />
<br />
[[File:GumstixEclipse3.jpg | center | 1000px]]<br />
<br />
:Note: If you are not sure which version of Eclipse you have, you can check by reopening Eclipse, it will be displayed on the loading screen.<br />
<br />
----<br />
Hint:<br />
If the update site is not available, you can add it by clicking the 'Add...' button on the right. For the Galileo release, you can use the URL http://dowload.eclipse.org/releases/galileo<br />
----<br />
<br />
As we are working with a remote system, we'll install the Remote System Explorer plugin.<br />
:* search for the ''Remote System Explorer End-User Runtime'' plugin<br />
:* select it for installation<br />
<br />
[[File:GumstixEclipse4.jpg | center | 600px]]<br />
<br />
Still in Eclipse,<br />
:* select "Next".... twice<br />
:* select the radio button to "ACCEPT" the terms of the license agreement<br />
:* choose "Yes" to restart Eclipse for the changes to take effect<br />
<br />
Once Eclipse has restarted, let's add two other useful plugins that allow connection to the console port of our Gumstix without needing a terminal emulator program such as kermit or TeraTerm.<br />
From within Eclipse,<br />
:* navigate to '''Help->Install New Software'''<br />
:* search on "Target" to find the ''Target Manager Terminal''<br />
<br />
[[File:GumstixEclipse5.jpg | center | 1000px]]<br />
<br />
:* select the ''Target Manager Terminal''<br />
:* click "Next"<br />
:* click "Finish" to complete installation<br />
:* choose "Yes" to restart Eclipse for the changes to take effect<br />
<br />
We'll also need to add a new update site by doing these steps in Eclipse:<br />
:* navigate to '''Help->Install New Software...'''<br />
:* click the "Add..." button<br />
:* type ''http://rxtx.qbang.org/eclipse'' into the ''Location'' field and create a name<br />
<br />
[[File:GumstixEclipse6.jpg | center | 1000px]]<br />
<br />
:* Click the "OK" button<br />
Go into the sub-directory as shown below to select the ''RXTX End-User Runtime'' plugin that this site provides.<br />
<br />
[[File:GumstixEclipse7.jpg | center | 1000px]]<br />
<br />
:* click "Next" twice<br />
:* select the radio button to "ACCEPT" the terms of the license agreement<br />
:* click "OK" at the security warning window<br />
:* click "Finish" to complete installation<br />
:* choose the "Yes" button to restart Eclipse for the changes to take effect<br />
<br />
==Connect Your Gumstix==<br />
Now it is time to connect your Gumstix---let's get started by establishing a console connection.<br />
:* mount your Gumstix COM down on to your expansion board<br />
:* plug the mini-A USB plug into the port marked CONSOLE and end of the cable into a standard USB port on your computer<br />
----<br />
Hint:<br />
Your computer should detect your Gumstix system when you first connect the USB cable, even though the power is not yet turned on. On Macintosh and Windows systems, a pop-up window should appear instructing you to download a new driver (do so) or notifying you that a USBserial device has been detected. If not, you can download drivers from [http://www.ftdichip.com/FTDrivers.htm this site]. Choose the "VCP" driver.<br />
Once you have downloaded this driver, make sure to unplug and then replug the USB cable running from your computer to your Gumstix expansion board so the Gumstix will be recognized by your computer.<br />
----<br />
:* connect your Gumstix to the internet using an ethernet cable<br />
NOTE: You still have NOT plugged the power cable in to the <br />
Gumstix expansion board! This diagram shows the locations<br />
of the USB 'CONSOLE' port and the 'POWER' input port on a <br />
Summit board on which an Overo COM has been mounted.<br />
<br />
[[File:GumstixEclipse8.jpg | center | 600px]]<br />
<br />
:* if you are booting from a microSD card, insert this card now until you hear it click in place.<br />
Before applying power to the board, let's open up a connection to the console port.<br />
In Eclipse,<br />
:* navigate to '''Window->Show View->Other->Terminal->Terminal'''<br />
:* click on the 'N' connection icon in the window that appears<br />
<br />
[[File:GumstixEclipse9.jpg | center | 600px]]<br />
<br />
:* make the connection using the following settings:<br />
Connection Type: Serial<br />
Port: <port to which your Gumstix is connected><br />
Baud Rate: 115200<br />
Data Bits: 8<br />
Stop Bits: 1<br />
Parity: none<br />
Flow Control: none<br />
Timeout: 5<br />
<br />
----<br />
Hint:<br />
The port to which your Gumstix is connected will have a different name depending on your Host operating system.<br />
:* On Windows, it should be ''USB-COM''<br />
:* On Macintosh, it should be ''/dev/tty.usbserial-xxxxxxxx'' where ''xxxxxxxx'' is an arbitrary string of characters<br />
:* On Linux, it should be ''/dev/ttyUSBx'' where ''x'' is a number.<br />
----<br />
<br />
[[File:GumstixEclipse10.jpg | center | 600px]]<br />
<br />
----<br />
Hint:<br />
If this does not work, or you wish to gain Console access via a Unix Shell instead, visit the tutorial on [[Gaining Console Connection via Terminal]]<br />
----<br />
<br />
*Now, it's time to apply power to the Gumstix expansion board so plug the 5V wall adapter into the power input jack on the Gumstix.<br />
<br />
You should see text appear in this window; for now, just let the Gumstix boot. When prompted, you can log in to the root account. The default credentials are:<br />
<br />
'''Overo'''<br />
<br />
username: root<br />
<br />
password: <leave blank><br />
<br />
<br />
'''VerdexPro'''<br />
<br />
username: root<br />
<br />
password: gumstix<br />
<br />
==Create a Web Site==<br />
Each Gumstix comes with a built-in package manager called opkg. A package manager is a useful tool for installing software; you can install everything from media players to GPS mapping tools to the Firefox web browser. In this example, you'll use opkg tool to install a new application for your Gumstix: the Apache web server.<br />
<br />
To make your own Gumstix web site, type the following in the terminal window:<br />
opkg update <Enter><br />
opkg install apache2 <Enter><br />
Before you start using Apache, which is now running, you'll need to find the IP address (internet address) of your Gumstix COM. To do this, type the following command into the terminal window:<br />
ifconfig | grep 'inet addr' <Enter><br />
You should see something like this appear on your screen.<br />
inet addr: 10.0.1.73 Bcast: 192.168.0.255 Mask: 255.255.255.0<br />
The IP address of your Gumstix is the first address shown: ''10.0.1.73'' in this case.<br />
Now,<br />
:* open up a web browser on your host computer<br />
:* type that IP address of your Gumstix into the address bar<br />
You should see something like this which is the default web site for Apache running on your Gumstix.<br />
<br />
[[File:GumstixEclipse11.jpg]]<br />
<br />
To make your web site say something more interesting, do the follow in your terminal window:<br />
:* type: ''nano /usr/share/apache2/htdocs/index.html''<br />
:* replace the words at the top of the screen "It Works" with the words "Gumstix Rocks!"<br />
:* press 'Ctrl+O' <Enter><br />
:* press 'Ctrl+X' to save and exit<br />
:* refresh your web browser<br />
<br />
==Write a Java Application==<br />
So far, you haven't actually used Eclipse other than as a console interface for your Gumstix. It is time to harness the power of Eclipse to write a small graphical Java application.<br />
In Eclipse.<br />
:* Navigate to '''File-> New-> Java Project''',<br />
:* Name the project ''gumstix-java''<br />
:* Select "Finish"<br />
Once the project is created,<br />
:* Select '''File->New->Class'''<br />
:* Name your class ''Hello''<br />
:* click "FINISH"<br />
<br />
Add the following code to your class:<br />
<br />
import javax.swing.JFrame;<br />
import javax.swing.JLabel;<br />
public class Hello {<br />
public static void main(String [] args) {<br />
JFrame frame = new JFrame("hello");<br />
final JLabel label = new JLabel("hello from Gumstix");<br />
frame.getContentPane().add(label);<br />
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);<br />
frame.pack();<br />
frame.setVisible(true);<br />
}<br />
}<br />
<br />
You should get something that looks like this:<br />
<br />
[[File:GumstixEclipse12.jpg | center | 600px]]<br />
<br />
Press the green run button to test drive our application on our host machine.<br />
<br />
----<br />
Hint:<br />
Eclipse has many auto-completion features. Simply typing /:*<Enter> before a class creates a standard documentation block. Likewise, pressing <Ctrl>+<Space> provides context specific auto-completion options. Many other hints for speedy development are explained in the tutorials [http://www.eclipse.org/resources/?category=Getting%20Started here].<br />
----<br />
<br />
==Upload Code==<br />
In Step 5 we discovered the IP address of our Gumstix. With this, we can connect to our Gumstix using the SSH protocol which allows us to rapidly transfer files. For this step, navigate to '''Window->Open Perspective->Other->Remote System Explorer''' and click on the connection icon in the ''Remote Systems'' panel on the left. Select ''SSH without shells'' as the connection type and press Next. Put the internet address you found in Step 5 into the field marked ''Host Name'' and hit finish. To test that everything is working correctly, right-click on the terminal item list under your new connection and select ''Launch Terminal''. A console interface exactly like the USB console interface we set up in Step 3 should pop up.<br />
<br />
<br />
----<br />
Hint:<br />
A 'Perspective' is an arrangement of windows and widgets, that is a specific view of the Eclipse workspace, designed for a particular task. If you wish to focus on any particular widget, double click the tab in Eclipse; return to the previous view by double-clicking again.<br />
----<br />
<br />
<br />
By installing the VNC viewer plugin, we can get a graphical interface to our Gumstix system. Do this by adding the ''Tools for mobile linux runtime'' plugin ('''Help->Install New Software''') from the main update site. To use, select the VNC viewer widget from '''Window->Show View->Other->VNC Category->VNC''' and click on the ''New Connection'' icon in the VNC Viewer panel. Again, the ''Host'' is the internet address of your Gumstix board.<br />
<br />
[[File:GumstixEclipse13.jpg | center | 600px]]<br />
<br />
Finally, we need to upload our java code before we can run it. Switch back to the Java Perspective ('''Window->Open Perspective->Java''') and right-click on our Java file and selecting Export. Choose the option to export file to a remote file system and choose to upload your ''Hello.class'' file.<br />
<br />
[[File:GumstixEclipse14.jpg | center | 600px]]<br />
<br />
You will need to ''Browse'' to find your Gumstix board; you should upload this code to your home directory on the Gumstix.<br />
<br />
==Debug a Java Application==<br />
We can debug our java application remotely from Eclipse. To do this, we need a Java Virtual Machine capable of doing debugging. This time, the package we need isn't available in our package sources however we can fetch the package directly from a web site and install it using the same opkg package management tool.<br />
wget http://bugcommunity.com/downloads/files/phonemeadvanced- personal-debug_mr2-r1_armv6.ipk <Enter><br />
opkg install -force-depends phoneme-advanced-personaldebug_mr2-r1_armv6.ipk <Enter><br />
Let's also update our Java libraries so we have access to the standard graphical libraries.<br />
opkg install classpath-gtk <Enter><br />
Next, let's start our Java code in debugging mode on the Overo:<br />
java-cdc -Xdebug -Xrunjwdp:transport=dHt_socket,server=y,suspend=y,address=1234 Hello <Enter><br />
Finally, let's connect to our debugging session by navigating in Eclipse to '''Run->Debug Configurations''' and double-clicking on Remote Java Application to create a new configuration. Fill in the form as shown below using the internet address found in the previous step.<br />
<br />
==Install a native C/C++ SDK==<br />
When we discussed Python and Java we noted that both are interpreted languages--- neither needs to be compiled. C and C++ code requires compilation which can be done natively---on the Gumstix itself---or on a development machine using a cross-compiler. To do native compilation, you need to install a compiler as well as any required libraries. You'll need to be booting from a microSD card as this installation takes approximately 75MB of space.<br />
$ echo 'src/gz angstrom-base http://www.angstromdistribution.org/feeds/unstable/ipk/glibc/armv7a/base' > /etc/opkg/angstrom-base.conf<br />
$ opkg update<br />
$ opkg install task-native-sdk<br />
Firstly, we are adding a new package repository to our package manager and updating our list of available packages before actually installing the complete package needed to do native development.<br />
<br />
Let's create either of the following files in Eclipse, upload the code and then compile on the Gumstix using our newly installed compiler.<br />
<br />
===C++: HelloWorld.cpp===<br />
#include <iostream><br />
using namespace std;<br />
int main () {<br />
cout << "Gumstix runs on C++" << endl;<br />
return 0;<br />
}<br />
<br />
Save the file and issue the following commands to compile and run HelloWorld.cpp<br />
g++ -o hello hello.cpp <enter><br />
Gumstix runs on C++ <enter><br />
<br />
===C: HelloWorld.c===<br />
#include <stdio.h><br />
int main () {<br />
printf("Gumstix runs on C\n");<br />
return 0;<br />
}<br />
<br />
Save the file and issue the following commands to compile and run HelloWorld.c<br />
gcc -o hello hello.c<br />
Gumstix runs on C<br />
<br />
<TODO: More exciting examples using on-board LEDs.><br />
<br />
==Using GDB as a remote debugger in C/C++==<br />
These instructions will teach you how to download, install, and use the GDB debugger remotely on your Overo COM.<br />
<br />
<pre>NOTE: <br />
remote system - a device that is being operated remotely (via SSH, USB Serial, etc). This means that it is a device that you are operating from a different system <br />
(ie: if you are accessing the Overo COM via connection with your PC, then the Overo COM is a remote system).<br />
For the purpose of this guide, the Overo COM will be the remote system.<br />
<br />
local host - the device that is being used to work on (ie: If you are working on your PC, that is the local host. If you then connect to another computer via VNC, <br />
that is a remote system, and you laptop is still the localhost).<br />
For the purpose of this guide, your Personal Computer will be the local host.</pre><br />
<br />
Before starting, it is important to note there are many different ways to run a remote debugger. The most fundamental choice when debugging remotely is whether you want to:<br />
:*Run the debugger on the remote system or<br />
:*Run the debugger on the local host with a cross debugger on the remote system<br />
<br />
This guide will teach you how to download, install, and run the debugger on the remote system (choice A). If you wish to learn more about the cross debugger option, use Google. Also the wikipedia article on cross compilers (which operate in a very similar fashion) is very good, albeit a bit complicated. None of this is necessary in understanding the contents of this guide. <br />
<br />
For the purposes of this guide, we will be using the GDB: the GNU project debugger. As stated on their website:<br />
<br />
<pre>GDB, the GNU Project debugger, allows you to see what is going on `inside' another program while it executes -- or what another program was doing at the moment it <br />
crashed.<br />
<br />
GDB can do four main kinds of things (plus other things in support of these) to help you catch bugs in the act:<br />
- Start your program, specifying anything that might affect its behavior.<br />
- Make your program stop on specified conditions.<br />
- Examine what has happened, when your program has stopped.<br />
- Change things in your program, so you can experiment with correcting the effects of one bug and go on to learn about another.</pre><br />
<br />
While the reasons for using a debugger instead of trying to debug with the ‘brute force’ method of adding print statements throughout the entire program are enumerable, there are a few that stand out:<br />
# The ability to ‘step’ through a program<br />
#* The GDB debugger allows you to ‘step’ through a program. This means that instead of just executing the program and then leaving you with a final error message, it will execute one line at a time until the program crashes. This allows the user to see exactly where, and why, the program crashed. <br />
# The ability to set breakpoints<br />
#* The GDB debugger allows you to set breakpoints in the program. These are points where the CPU will stop executing the code and allow the user to decide whether to continue. This allows the user to explore what is ‘going on’ at certain points in the execution, something that otherwise is not possible. <br />
# The ability to look at the Backtrace<br />
#* This will show you where, and exactly why, your program crashed. Although SEGFAULT isn’t very useful, the backtrace will tell you what caused the SEGFAULT. Everything from what line, what variable, and even the address that variable was at.<br />
<br />
===Installing the GDB===<br />
Once the Overo COM has been connected to the local host, you should have access to the following command line:<br />
<pre>root@overo:~# </pre><br />
Although you are working on your local host, this command line is for the remote system. It is the same as if you opened up Terminal (for Mac, Linux) or XTerm (for Windows). You now have access and control of the remote system.<br />
<br />
Now there are some packages that must be downloaded and installed onto the Overo so that it can run the GDB environment. To do this issue the following command:<br />
<pre>opkg update <enter><br />
opkg install gdb <enter></pre><br />
This should spew out a bunch of text such as:<br />
<pre>Downloading http://www.angstrom...</pre><br />
Just let it run and once its done, you’ll have the GNU GDB debugger installed on your Overo COM.<br />
<br />
===Creating a C/C++ Program to Debug===<br />
Now, your Overo COM has a debugger installed and ready to use. However, this does not mean you are ready to go. There are two more things required before it is possible to use a GDB debugger.<br />
:* A C/C++ program<br />
:* A SDK to run the program on<br />
To see how to install a SDK and write/run a simple program in C/C++, see [[#Install a native C/C++ SDK]]. <br />
<br />
Once you have a program ready, you first must create an executable file. Lets use for example the C++ program HelloWorld.cpp. To create the executable file HelloWorld, issue the following command:<br />
<pre>g++ -o HelloWorld HelloWorld.cpp <enter></pre><br />
Now, to run the program:<br />
<pre>./HelloWorld <enter></pre><br />
To do the same thing with a C program (HelloWorld.c), issue the command<br />
<pre>gcc -o HelloWorld HelloWorld.c <enter></pre><br />
<pre>./HelloWorld <enter></pre><br />
<br />
What this command does is uses the GNU compiler (either g++ or gcc) and creates an executable object (HelloWorld) out of the C or C++ program file (either HelloWorld.cpp or HelloWorld.c). You may name the executable whatever you like, but it is considered best practice to name it the same thing as the program file.<br />
<br />
===Debugging the Program===<br />
Now that you have GDB installed and a C/C++ program ready to go, its time to debug. To open to GDB environment, run the following command<br />
<pre>gdb <enter></pre><br />
Some text should spit out, and the following command line should appear<br />
<pre>(gdb)</pre><br />
Now that the debugger is running, it is time to tell the debugger what program we want to debug. To do this, first we need to declare our HelloWorld file as an executable file. For this run the following command <br />
<pre>(gdb) exec-file HelloWorld <enter></pre><br />
Now that we have an executable file ready to be debugged, its time to run the program<br />
<pre>(gdb) run HelloWorld <enter></pre><br />
The debugger will now run your program. If the program has no syntax or logic errors, the program should run and end with the line:<br />
Program exited normally.<br />
If there are errors, or the program crashed, it is possible to extract the exact details of that crash by issuing the back trace command.<br />
<pre>(gdb) bt <enter></pre><br />
Once you are done you can quit by issuing the command:<br />
<pre>(gdb) quit <enter></pre><br />
<br />
A complete list of commands in GDB:<br />
www.yolinux.com/TUTORIALS/GDB-Commands.html<br />
<br />
====GDB Debugger Tutorial====<br />
For a complete GDB Debugger tutorial (very good tutorial, comes with sample code they walk you through and extra errors for you to debug yourself!):<br />
http://www.cs.cmu.edu/~gilpin/tutorial/<br />
<br />
Now you have a debugger up and running! Play around with it by putting errors into your program on purpose to see the powers of having a remote debugger!<br />
<br />
==Use a C/C++ cross-compiler==<br />
In order to do C/C++ development on our host machine, we need to add in a plugin to Eclipse. Also, we need to download an appropriate cross-compilation toolchain. For now, I recommend the lovely instructions from<br />
<br />
http://www.designarm.com/quickstart-guide/linux-software/eclipse.html &<br />
<br />
http://www.bugcommunity.com/wiki/index.php/BUG_Kernel_Development_with_Eclipse<br />
<br />
==Further Reading==<br />
===Internal===<br />
[[Gaining Console Connection via Terminal]]<br><br />
[[HelloWorld | HelloWorld in Python, C and C++]]<br><br />
[[Remote Debugging with GDB]] <br><br />
[[HelloWorld in Java]]<br />
<br />
===External===<br />
:* Tutorials built into Eclipse<br />
:* Bitbake commander<br />
:* OpenEmebedded|Poky docs + Bitbake docs<br />
:* Eclipse Plugin Tutorial<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
[[Category:How_to_-_eclipse]]</div>JustinC474https://wiki.gumstix.com/index.php?title=Eclipse_on_Gumstix_for_new_users&diff=4487Eclipse on Gumstix for new users2010-08-05T18:48:40Z<p>JustinC474: </p>
<hr />
<div>This guide provides step-by-step instructions for using the Eclipse Integrated Development Environment (IDE) to develop applications for the Gumstix COMs.<br />
<br />
We'll walk through these tasks:<br />
:* setting up Eclipse<br />
:* connection to your Gumstix system<br />
:* creating a simple "Hello, World!" Python program<br />
:* running a web server<br />
:* installing new packages on your Gumstix<br />
:* creating a small graphical Java application<br />
:* remote debugging of your Java application<br />
:* natively-compiling C/C++ code on your Gumstix<br />
:* remote debugging C/C++ using the GDB server interface<br />
<br />
We will also explain how to set up a cross-compilation toolchain so you can develop C/C++ applications on your development computer and upload them to your Gumstix.<br />
<br />
Remember, Gumstix COMs are fully-fledged, albeit tiny, Linux systems so there are many tools we don't cover here. For example, [http://wiki.openembedded.net/index.php/OpenEmbedded_Tools_for_Eclipse_(OTE) this document] explains how to use the powerful OpenEmbedded build system within Eclipse.<br />
<br />
Required Tools:<br />
:* any Windows, Apple or Linux computer with a USB port<br />
:* recent version of the Java Runtime Environment (available [http://java.sun.com/javase/downloads/index.jsp here])<br />
:* a Gumstix COM running [http://www.gumstix.net/Setup-and-Programming/view/Overo-Setup-and-Programming/Downloading-pre-built-images/111.html up-to-date software]<br />
:* any expansion board of the Gumstix Overo series, such as Chestnut or Tobi, that has both a USB console port and a 10/100 <br />
:* Ethernet jack<br />
:* a 5V power supply<br />
:* an ethernet cable and internet connection<br />
:* a mini-A to Standard-A USB cable<br />
:* a [http://www.gumstix.net/Setup-and-Programming/view/Overo-Setup-and-Programming/Creating-a-bootable-microSD-card/111.html bootable microSD card] (only needed for native C/C++ compilation)<br />
<br />
Key Idea:<br />
[[File:GumstixEclipse1.jpg|thumb|right|upright=5]]<br />
<br />
==Download Eclipse==<br />
[http://www.eclipse.org/downloads/ Download] the Eclipse IDE for Java Developers for your Operating System: www.eclipse.org<br />
<br />
[[Image: GumstixEclipse2.jpg | center | 600px]]<br />
<br />
<br />
:* it is ''not'' necessary to install the Eclipse software; just double-click on the application once it has finished downloading<br />
:* when prompted, choose a workspace folder in which you want to store your projects and your configuration information<br />
:* then click through to the Eclipse workbench itself<br />
<br />
==Install Plugins==<br />
For developers, a great variety of additional features can be added to Eclipse from various repositories of plug-ins known as ''Update Sites''.<br />
To install a new plugin in Eclipse, first select the ''Update Site''.<br />
:* navigate to '''Help->Install New Software...'''<br />
:* select the Update Site for your version of Eclipse from the "Work with"dropdown menu<br />
<br />
[[File:GumstixEclipse3.jpg | center | 600px]]<br />
<br />
:Note: If you are not sure which version of Eclipse you have, you can check by reopening Eclipse, it will be displayed on the loading screen.<br />
<br />
----<br />
Hint:<br />
If the update site is not available, you can add it by clicking the 'Add...' button on the right. For the Galileo release, you can use the URL http://dowload.eclipse.org/releases/galileo<br />
----<br />
<br />
As we are working with a remote system, we'll install the Remote System Explorer plugin.<br />
:* search for the ''Remote System Explorer End-User Runtime'' plugin<br />
:* select it for installation<br />
<br />
[[File:GumstixEclipse4.jpg | center | 600px]]<br />
<br />
Still in Eclipse,<br />
:* select "Next".... twice<br />
:* select the radio button to "ACCEPT" the terms of the license agreement<br />
:* choose "Yes" to restart Eclipse for the changes to take effect<br />
<br />
Once Eclipse has restarted, let's add two other useful plugins that allow connection to the console port of our Gumstix without needing a terminal emulator program such as kermit or TeraTerm.<br />
From within Eclipse,<br />
:* navigate to '''Help->Install New Software'''<br />
:* search on "Target" to find the ''Target Manager Terminal''<br />
<br />
[[File:GumstixEclipse5.jpg | center | 600px]]<br />
<br />
:* select the ''Target Manager Terminal''<br />
:* click "Next"<br />
:* click "Finish" to complete installation<br />
:* choose "Yes" to restart Eclipse for the changes to take effect<br />
<br />
We'll also need to add a new update site by doing these steps in Eclipse:<br />
:* navigate to '''Help->Install New Software...'''<br />
:* click the "Add..." button<br />
:* type ''http://rxtx.qbang.org/eclipse'' into the ''Location'' field and create a name<br />
<br />
[[File:GumstixEclipse6.jpg | center | 600px]]<br />
<br />
:* Click the "OK" button<br />
Go into the sub-directory as shown below to select the ''RXTX End-User Runtime'' plugin that this site provides.<br />
<br />
[[File:GumstixEclipse7.jpg | center | 600px]]<br />
<br />
:* click "Next" twice<br />
:* select the radio button to "ACCEPT" the terms of the license agreement<br />
:* click "OK" at the security warning window<br />
:* click "Finish" to complete installation<br />
:* choose the "Yes" button to restart Eclipse for the changes to take effect<br />
<br />
==Connect Your Gumstix==<br />
Now it is time to connect your Gumstix---let's get started by establishing a console connection.<br />
:* mount your Gumstix COM down on to your expansion board<br />
:* plug the mini-A USB plug into the port marked CONSOLE and end of the cable into a standard USB port on your computer<br />
----<br />
Hint:<br />
Your computer should detect your Gumstix system when you first connect the USB cable, even though the power is not yet turned on. On Macintosh and Windows systems, a pop-up window should appear instructing you to download a new driver (do so) or notifying you that a USBserial device has been detected. If not, you can download drivers from [http://www.ftdichip.com/FTDrivers.htm this site]. Choose the "VCP" driver.<br />
Once you have downloaded this driver, make sure to unplug and then replug the USB cable running from your computer to your Gumstix expansion board so the Gumstix will be recognized by your computer.<br />
----<br />
:* connect your Gumstix to the internet using an ethernet cable<br />
NOTE: You still have NOT plugged the power cable in to the <br />
Gumstix expansion board! This diagram shows the locations<br />
of the USB 'CONSOLE' port and the 'POWER' input port on a <br />
Summit board on which an Overo COM has been mounted.<br />
<br />
[[File:GumstixEclipse8.jpg | center | 600px]]<br />
<br />
:* if you are booting from a microSD card, insert this card now until you hear it click in place.<br />
Before applying power to the board, let's open up a connection to the console port.<br />
In Eclipse,<br />
:* navigate to '''Window->Show View->Other->Terminal->Terminal'''<br />
:* click on the 'N' connection icon in the window that appears<br />
<br />
[[File:GumstixEclipse9.jpg | center | 600px]]<br />
<br />
:* make the connection using the following settings:<br />
Connection Type: Serial<br />
Port: <port to which your Gumstix is connected><br />
Baud Rate: 115200<br />
Data Bits: 8<br />
Stop Bits: 1<br />
Parity: none<br />
Flow Control: none<br />
Timeout: 5<br />
<br />
----<br />
Hint:<br />
The port to which your Gumstix is connected will have a different name depending on your Host operating system.<br />
:* On Windows, it should be ''USB-COM''<br />
:* On Macintosh, it should be ''/dev/tty.usbserial-xxxxxxxx'' where ''xxxxxxxx'' is an arbitrary string of characters<br />
:* On Linux, it should be ''/dev/ttyUSBx'' where ''x'' is a number.<br />
----<br />
<br />
[[File:GumstixEclipse10.jpg | center | 600px]]<br />
<br />
----<br />
Hint:<br />
If this does not work, or you wish to gain Console access via a Unix Shell instead, visit the tutorial on [[Gaining Console Connection via Terminal]]<br />
----<br />
<br />
*Now, it's time to apply power to the Gumstix expansion board so plug the 5V wall adapter into the power input jack on the Gumstix.<br />
<br />
You should see text appear in this window; for now, just let the Gumstix boot. When prompted, you can log in to the root account. The default credentials are:<br />
<br />
'''Overo'''<br />
<br />
username: root<br />
<br />
password: <leave blank><br />
<br />
<br />
'''VerdexPro'''<br />
<br />
username: root<br />
<br />
password: gumstix<br />
<br />
==Create a Web Site==<br />
Each Gumstix comes with a built-in package manager called opkg. A package manager is a useful tool for installing software; you can install everything from media players to GPS mapping tools to the Firefox web browser. In this example, you'll use opkg tool to install a new application for your Gumstix: the Apache web server.<br />
<br />
To make your own Gumstix web site, type the following in the terminal window:<br />
opkg update <Enter><br />
opkg install apache2 <Enter><br />
Before you start using Apache, which is now running, you'll need to find the IP address (internet address) of your Gumstix COM. To do this, type the following command into the terminal window:<br />
ifconfig | grep 'inet addr' <Enter><br />
You should see something like this appear on your screen.<br />
inet addr: 10.0.1.73 Bcast: 192.168.0.255 Mask: 255.255.255.0<br />
The IP address of your Gumstix is the first address shown: ''10.0.1.73'' in this case.<br />
Now,<br />
:* open up a web browser on your host computer<br />
:* type that IP address of your Gumstix into the address bar<br />
You should see something like this which is the default web site for Apache running on your Gumstix.<br />
<br />
[[File:GumstixEclipse11.jpg]]<br />
<br />
To make your web site say something more interesting, do the follow in your terminal window:<br />
:* type: ''nano /usr/share/apache2/htdocs/index.html''<br />
:* replace the words at the top of the screen "It Works" with the words "Gumstix Rocks!"<br />
:* press 'Ctrl+O' <Enter><br />
:* press 'Ctrl+X' to save and exit<br />
:* refresh your web browser<br />
<br />
==Write a Java Application==<br />
So far, you haven't actually used Eclipse other than as a console interface for your Gumstix. It is time to harness the power of Eclipse to write a small graphical Java application.<br />
In Eclipse.<br />
:* Navigate to '''File-> New-> Java Project''',<br />
:* Name the project ''gumstix-java''<br />
:* Select "Finish"<br />
Once the project is created,<br />
:* Select '''File->New->Class'''<br />
:* Name your class ''Hello''<br />
:* click "FINISH"<br />
<br />
Add the following code to your class:<br />
<br />
import javax.swing.JFrame;<br />
import javax.swing.JLabel;<br />
public class Hello {<br />
public static void main(String [] args) {<br />
JFrame frame = new JFrame("hello");<br />
final JLabel label = new JLabel("hello from Gumstix");<br />
frame.getContentPane().add(label);<br />
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);<br />
frame.pack();<br />
frame.setVisible(true);<br />
}<br />
}<br />
<br />
You should get something that looks like this:<br />
<br />
[[File:GumstixEclipse12.jpg | center | 600px]]<br />
<br />
Press the green run button to test drive our application on our host machine.<br />
<br />
----<br />
Hint:<br />
Eclipse has many auto-completion features. Simply typing /:*<Enter> before a class creates a standard documentation block. Likewise, pressing <Ctrl>+<Space> provides context specific auto-completion options. Many other hints for speedy development are explained in the tutorials [http://www.eclipse.org/resources/?category=Getting%20Started here].<br />
----<br />
<br />
==Upload Code==<br />
In Step 5 we discovered the IP address of our Gumstix. With this, we can connect to our Gumstix using the SSH protocol which allows us to rapidly transfer files. For this step, navigate to '''Window->Open Perspective->Other->Remote System Explorer''' and click on the connection icon in the ''Remote Systems'' panel on the left. Select ''SSH without shells'' as the connection type and press Next. Put the internet address you found in Step 5 into the field marked ''Host Name'' and hit finish. To test that everything is working correctly, right-click on the terminal item list under your new connection and select ''Launch Terminal''. A console interface exactly like the USB console interface we set up in Step 3 should pop up.<br />
<br />
<br />
----<br />
Hint:<br />
A 'Perspective' is an arrangement of windows and widgets, that is a specific view of the Eclipse workspace, designed for a particular task. If you wish to focus on any particular widget, double click the tab in Eclipse; return to the previous view by double-clicking again.<br />
----<br />
<br />
<br />
By installing the VNC viewer plugin, we can get a graphical interface to our Gumstix system. Do this by adding the ''Tools for mobile linux runtime'' plugin ('''Help->Install New Software''') from the main update site. To use, select the VNC viewer widget from '''Window->Show View->Other->VNC Category->VNC''' and click on the ''New Connection'' icon in the VNC Viewer panel. Again, the ''Host'' is the internet address of your Gumstix board.<br />
<br />
[[File:GumstixEclipse13.jpg | center | 600px]]<br />
<br />
Finally, we need to upload our java code before we can run it. Switch back to the Java Perspective ('''Window->Open Perspective->Java''') and right-click on our Java file and selecting Export. Choose the option to export file to a remote file system and choose to upload your ''Hello.class'' file.<br />
<br />
[[File:GumstixEclipse14.jpg | center | 600px]]<br />
<br />
You will need to ''Browse'' to find your Gumstix board; you should upload this code to your home directory on the Gumstix.<br />
<br />
==Debug a Java Application==<br />
We can debug our java application remotely from Eclipse. To do this, we need a Java Virtual Machine capable of doing debugging. This time, the package we need isn't available in our package sources however we can fetch the package directly from a web site and install it using the same opkg package management tool.<br />
wget http://bugcommunity.com/downloads/files/phonemeadvanced- personal-debug_mr2-r1_armv6.ipk <Enter><br />
opkg install -force-depends phoneme-advanced-personaldebug_mr2-r1_armv6.ipk <Enter><br />
Let's also update our Java libraries so we have access to the standard graphical libraries.<br />
opkg install classpath-gtk <Enter><br />
Next, let's start our Java code in debugging mode on the Overo:<br />
java-cdc -Xdebug -Xrunjwdp:transport=dHt_socket,server=y,suspend=y,address=1234 Hello <Enter><br />
Finally, let's connect to our debugging session by navigating in Eclipse to '''Run->Debug Configurations''' and double-clicking on Remote Java Application to create a new configuration. Fill in the form as shown below using the internet address found in the previous step.<br />
<br />
==Install a native C/C++ SDK==<br />
When we discussed Python and Java we noted that both are interpreted languages--- neither needs to be compiled. C and C++ code requires compilation which can be done natively---on the Gumstix itself---or on a development machine using a cross-compiler. To do native compilation, you need to install a compiler as well as any required libraries. You'll need to be booting from a microSD card as this installation takes approximately 75MB of space.<br />
$ echo 'src/gz angstrom-base http://www.angstromdistribution.org/feeds/unstable/ipk/glibc/armv7a/base' > /etc/opkg/angstrom-base.conf<br />
$ opkg update<br />
$ opkg install task-native-sdk<br />
Firstly, we are adding a new package repository to our package manager and updating our list of available packages before actually installing the complete package needed to do native development.<br />
<br />
Let's create either of the following files in Eclipse, upload the code and then compile on the Gumstix using our newly installed compiler.<br />
<br />
===C++: HelloWorld.cpp===<br />
#include <iostream><br />
using namespace std;<br />
int main () {<br />
cout << "Gumstix runs on C++" << endl;<br />
return 0;<br />
}<br />
<br />
Save the file and issue the following commands to compile and run HelloWorld.cpp<br />
g++ -o hello hello.cpp <enter><br />
Gumstix runs on C++ <enter><br />
<br />
===C: HelloWorld.c===<br />
#include <stdio.h><br />
int main () {<br />
printf("Gumstix runs on C\n");<br />
return 0;<br />
}<br />
<br />
Save the file and issue the following commands to compile and run HelloWorld.c<br />
gcc -o hello hello.c<br />
Gumstix runs on C<br />
<br />
<TODO: More exciting examples using on-board LEDs.><br />
<br />
==Using GDB as a remote debugger in C/C++==<br />
These instructions will teach you how to download, install, and use the GDB debugger remotely on your Overo COM.<br />
<br />
<pre>NOTE: <br />
remote system - a device that is being operated remotely (via SSH, USB Serial, etc). This means that it is a device that you are operating from a different system <br />
(ie: if you are accessing the Overo COM via connection with your PC, then the Overo COM is a remote system).<br />
For the purpose of this guide, the Overo COM will be the remote system.<br />
<br />
local host - the device that is being used to work on (ie: If you are working on your PC, that is the local host. If you then connect to another computer via VNC, <br />
that is a remote system, and you laptop is still the localhost).<br />
For the purpose of this guide, your Personal Computer will be the local host.</pre><br />
<br />
Before starting, it is important to note there are many different ways to run a remote debugger. The most fundamental choice when debugging remotely is whether you want to:<br />
:*Run the debugger on the remote system or<br />
:*Run the debugger on the local host with a cross debugger on the remote system<br />
<br />
This guide will teach you how to download, install, and run the debugger on the remote system (choice A). If you wish to learn more about the cross debugger option, use Google. Also the wikipedia article on cross compilers (which operate in a very similar fashion) is very good, albeit a bit complicated. None of this is necessary in understanding the contents of this guide. <br />
<br />
For the purposes of this guide, we will be using the GDB: the GNU project debugger. As stated on their website:<br />
<br />
<pre>GDB, the GNU Project debugger, allows you to see what is going on `inside' another program while it executes -- or what another program was doing at the moment it <br />
crashed.<br />
<br />
GDB can do four main kinds of things (plus other things in support of these) to help you catch bugs in the act:<br />
- Start your program, specifying anything that might affect its behavior.<br />
- Make your program stop on specified conditions.<br />
- Examine what has happened, when your program has stopped.<br />
- Change things in your program, so you can experiment with correcting the effects of one bug and go on to learn about another.</pre><br />
<br />
While the reasons for using a debugger instead of trying to debug with the ‘brute force’ method of adding print statements throughout the entire program are enumerable, there are a few that stand out:<br />
# The ability to ‘step’ through a program<br />
#* The GDB debugger allows you to ‘step’ through a program. This means that instead of just executing the program and then leaving you with a final error message, it will execute one line at a time until the program crashes. This allows the user to see exactly where, and why, the program crashed. <br />
# The ability to set breakpoints<br />
#* The GDB debugger allows you to set breakpoints in the program. These are points where the CPU will stop executing the code and allow the user to decide whether to continue. This allows the user to explore what is ‘going on’ at certain points in the execution, something that otherwise is not possible. <br />
# The ability to look at the Backtrace<br />
#* This will show you where, and exactly why, your program crashed. Although SEGFAULT isn’t very useful, the backtrace will tell you what caused the SEGFAULT. Everything from what line, what variable, and even the address that variable was at.<br />
<br />
===Installing the GDB===<br />
Once the Overo COM has been connected to the local host, you should have access to the following command line:<br />
<pre>root@overo:~# </pre><br />
Although you are working on your local host, this command line is for the remote system. It is the same as if you opened up Terminal (for Mac, Linux) or XTerm (for Windows). You now have access and control of the remote system.<br />
<br />
Now there are some packages that must be downloaded and installed onto the Overo so that it can run the GDB environment. To do this issue the following command:<br />
<pre>opkg update <enter><br />
opkg install gdb <enter></pre><br />
This should spew out a bunch of text such as:<br />
<pre>Downloading http://www.angstrom...</pre><br />
Just let it run and once its done, you’ll have the GNU GDB debugger installed on your Overo COM.<br />
<br />
===Creating a C/C++ Program to Debug===<br />
Now, your Overo COM has a debugger installed and ready to use. However, this does not mean you are ready to go. There are two more things required before it is possible to use a GDB debugger.<br />
:* A C/C++ program<br />
:* A SDK to run the program on<br />
To see how to install a SDK and write/run a simple program in C/C++, see [[#Install a native C/C++ SDK]]. <br />
<br />
Once you have a program ready, you first must create an executable file. Lets use for example the C++ program HelloWorld.cpp. To create the executable file HelloWorld, issue the following command:<br />
<pre>g++ -o HelloWorld HelloWorld.cpp <enter></pre><br />
Now, to run the program:<br />
<pre>./HelloWorld <enter></pre><br />
To do the same thing with a C program (HelloWorld.c), issue the command<br />
<pre>gcc -o HelloWorld HelloWorld.c <enter></pre><br />
<pre>./HelloWorld <enter></pre><br />
<br />
What this command does is uses the GNU compiler (either g++ or gcc) and creates an executable object (HelloWorld) out of the C or C++ program file (either HelloWorld.cpp or HelloWorld.c). You may name the executable whatever you like, but it is considered best practice to name it the same thing as the program file.<br />
<br />
===Debugging the Program===<br />
Now that you have GDB installed and a C/C++ program ready to go, its time to debug. To open to GDB environment, run the following command<br />
<pre>gdb <enter></pre><br />
Some text should spit out, and the following command line should appear<br />
<pre>(gdb)</pre><br />
Now that the debugger is running, it is time to tell the debugger what program we want to debug. To do this, first we need to declare our HelloWorld file as an executable file. For this run the following command <br />
<pre>(gdb) exec-file HelloWorld <enter></pre><br />
Now that we have an executable file ready to be debugged, its time to run the program<br />
<pre>(gdb) run HelloWorld <enter></pre><br />
The debugger will now run your program. If the program has no syntax or logic errors, the program should run and end with the line:<br />
Program exited normally.<br />
If there are errors, or the program crashed, it is possible to extract the exact details of that crash by issuing the back trace command.<br />
<pre>(gdb) bt <enter></pre><br />
Once you are done you can quit by issuing the command:<br />
<pre>(gdb) quit <enter></pre><br />
<br />
A complete list of commands in GDB:<br />
www.yolinux.com/TUTORIALS/GDB-Commands.html<br />
<br />
====GDB Debugger Tutorial====<br />
For a complete GDB Debugger tutorial (very good tutorial, comes with sample code they walk you through and extra errors for you to debug yourself!):<br />
http://www.cs.cmu.edu/~gilpin/tutorial/<br />
<br />
Now you have a debugger up and running! Play around with it by putting errors into your program on purpose to see the powers of having a remote debugger!<br />
<br />
==Use a C/C++ cross-compiler==<br />
In order to do C/C++ development on our host machine, we need to add in a plugin to Eclipse. Also, we need to download an appropriate cross-compilation toolchain. For now, I recommend the lovely instructions from<br />
<br />
http://www.designarm.com/quickstart-guide/linux-software/eclipse.html &<br />
<br />
http://www.bugcommunity.com/wiki/index.php/BUG_Kernel_Development_with_Eclipse<br />
<br />
==Further Reading==<br />
===Internal===<br />
[[Gaining Console Connection via Terminal]]<br><br />
[[HelloWorld | HelloWorld in Python, C and C++]]<br><br />
[[Remote Debugging with GDB]] <br><br />
[[HelloWorld in Java]]<br />
<br />
===External===<br />
:* Tutorials built into Eclipse<br />
:* Bitbake commander<br />
:* OpenEmebedded|Poky docs + Bitbake docs<br />
:* Eclipse Plugin Tutorial<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
[[Category:How_to_-_eclipse]]</div>JustinC474https://wiki.gumstix.com/index.php?title=File:GumstixEclipse14.jpg&diff=4486File:GumstixEclipse14.jpg2010-08-05T18:37:42Z<p>JustinC474: uploaded a new version of "File:GumstixEclipse14.jpg"</p>
<hr />
<div></div>JustinC474https://wiki.gumstix.com/index.php?title=File:GumstixEclipse13.jpg&diff=4485File:GumstixEclipse13.jpg2010-08-05T18:37:24Z<p>JustinC474: uploaded a new version of "File:GumstixEclipse13.jpg"</p>
<hr />
<div></div>JustinC474https://wiki.gumstix.com/index.php?title=File:GumstixEclipse12.jpg&diff=4484File:GumstixEclipse12.jpg2010-08-05T18:35:54Z<p>JustinC474: uploaded a new version of "File:GumstixEclipse12.jpg"</p>
<hr />
<div></div>JustinC474https://wiki.gumstix.com/index.php?title=File:GumstixEclipse11.jpg&diff=4483File:GumstixEclipse11.jpg2010-08-05T18:33:36Z<p>JustinC474: uploaded a new version of "File:GumstixEclipse11.jpg"</p>
<hr />
<div></div>JustinC474https://wiki.gumstix.com/index.php?title=File:GumstixEclipse10.jpg&diff=4482File:GumstixEclipse10.jpg2010-08-05T18:32:33Z<p>JustinC474: uploaded a new version of "File:GumstixEclipse10.jpg"</p>
<hr />
<div></div>JustinC474https://wiki.gumstix.com/index.php?title=File:GumstixEclipse9.jpg&diff=4481File:GumstixEclipse9.jpg2010-08-05T18:31:49Z<p>JustinC474: uploaded a new version of "File:GumstixEclipse9.jpg"</p>
<hr />
<div></div>JustinC474https://wiki.gumstix.com/index.php?title=File:GumstixEclipse8.jpg&diff=4480File:GumstixEclipse8.jpg2010-08-05T18:31:05Z<p>JustinC474: uploaded a new version of "File:GumstixEclipse8.jpg"</p>
<hr />
<div></div>JustinC474https://wiki.gumstix.com/index.php?title=File:GumstixEclipse7.jpg&diff=4479File:GumstixEclipse7.jpg2010-08-05T18:30:32Z<p>JustinC474: uploaded a new version of "File:GumstixEclipse7.jpg"</p>
<hr />
<div></div>JustinC474https://wiki.gumstix.com/index.php?title=File:GumstixEclipse6.jpg&diff=4478File:GumstixEclipse6.jpg2010-08-05T18:28:07Z<p>JustinC474: uploaded a new version of "File:GumstixEclipse6.jpg"</p>
<hr />
<div></div>JustinC474https://wiki.gumstix.com/index.php?title=File:GumstixEclipse5.jpg&diff=4477File:GumstixEclipse5.jpg2010-08-05T18:25:10Z<p>JustinC474: uploaded a new version of "File:GumstixEclipse5.jpg"</p>
<hr />
<div></div>JustinC474https://wiki.gumstix.com/index.php?title=File:GumstixEclipse4.jpg&diff=4476File:GumstixEclipse4.jpg2010-08-05T18:24:39Z<p>JustinC474: uploaded a new version of "File:GumstixEclipse4.jpg"</p>
<hr />
<div></div>JustinC474https://wiki.gumstix.com/index.php?title=File:GumstixEclipse3.jpg&diff=4475File:GumstixEclipse3.jpg2010-08-05T18:24:13Z<p>JustinC474: uploaded a new version of "File:GumstixEclipse3.jpg"</p>
<hr />
<div></div>JustinC474https://wiki.gumstix.com/index.php?title=File:GumstixEclipse2.jpg&diff=4474File:GumstixEclipse2.jpg2010-08-05T17:47:57Z<p>JustinC474: uploaded a new version of "File:GumstixEclipse2.jpg"</p>
<hr />
<div></div>JustinC474https://wiki.gumstix.com/index.php?title=Eclipse_on_Gumstix_for_new_users&diff=4469Eclipse on Gumstix for new users2010-08-05T16:49:18Z<p>JustinC474: </p>
<hr />
<div>This guide provides step-by-step instructions for using the Eclipse Integrated Development Environment (IDE) to develop applications for the Gumstix COMs.<br />
<br />
We'll walk through these tasks:<br />
:* setting up Eclipse<br />
:* connection to your Gumstix system<br />
:* creating a simple "Hello, World!" Python program<br />
:* running a web server<br />
:* installing new packages on your Gumstix<br />
:* creating a small graphical Java application<br />
:* remote debugging of your Java application<br />
:* natively-compiling C/C++ code on your Gumstix<br />
:* remote debugging C/C++ using the GDB server interface<br />
<br />
We will also explain how to set up a cross-compilation toolchain so you can develop C/C++ applications on your development computer and upload them to your Gumstix.<br />
<br />
Remember, Gumstix COMs are fully-fledged, albeit tiny, Linux systems so there are many tools we don't cover here. For example, [http://wiki.openembedded.net/index.php/OpenEmbedded_Tools_for_Eclipse_(OTE) this document] explains how to use the powerful OpenEmbedded build system within Eclipse.<br />
<br />
Required Tools:<br />
:* any Windows, Apple or Linux computer with a USB port<br />
:* recent version of the Java Runtime Environment (available [http://java.sun.com/javase/downloads/index.jsp here])<br />
:* a Gumstix COM running [http://www.gumstix.net/Setup-and-Programming/view/Overo-Setup-and-Programming/Downloading-pre-built-images/111.html up-to-date software]<br />
:* any expansion board of the Gumstix Overo series, such as Chestnut or Tobi, that has both a USB console port and a 10/100 <br />
:* Ethernet jack<br />
:* a 5V power supply<br />
:* an ethernet cable and internet connection<br />
:* a mini-A to Standard-A USB cable<br />
:* a [http://www.gumstix.net/Setup-and-Programming/view/Overo-Setup-and-Programming/Creating-a-bootable-microSD-card/111.html bootable microSD card] (only needed for native C/C++ compilation)<br />
<br />
Key Idea:<br />
[[File:GumstixEclipse1.jpg|thumb|right|upright=5]]<br />
<br />
==Download Eclipse==<br />
[http://www.eclipse.org/downloads/ Download] the Eclipse IDE for Java Developers for your Operating System: www.eclipse.org<br />
<br />
[[Image: GumstixEclipse2.jpg | thumb | left]]<br />
<br />
:* it is ''not'' necessary to install the Eclipse software; just double-click on the application once it has finished downloading<br />
:* when prompted, choose a workspace folder in which you want to store your projects and your configuration information<br />
:* then click through to the Eclipse workbench itself<br />
<br />
==Install Plugins==<br />
For developers, a great variety of additional features can be added to Eclipse from various repositories of plug-ins known as ''Update Sites''.<br />
To install a new plugin in Eclipse, first select the ''Update Site''.<br />
:* navigate to '''Help->Install New Software...'''<br />
:* select the Update Site for your version of Eclipse from the "Work with"dropdown menu<br />
<br />
[[File:GumstixEclipse3.jpg]]<br />
<br />
:Note: If you are not sure which version of Eclipse you have, you can check by reopening Eclipse, it will be displayed on the loading screen.<br />
<br />
----<br />
Hint:<br />
If the update site is not available, you can add it by clicking the 'Add...' button on the right. For the Galileo release, you can use the URL http://dowload.eclipse.org/releases/galileo<br />
----<br />
<br />
As we are working with a remote system, we'll install the Remote System Explorer plugin.<br />
:* search for the ''Remote System Explorer End-User Runtime'' plugin<br />
:* select it for installation<br />
<br />
[[File:GumstixEclipse4.jpg]]<br />
<br />
Still in Eclipse,<br />
:* select "Next".... twice<br />
:* select the radio button to "ACCEPT" the terms of the license agreement<br />
:* choose "Yes" to restart Eclipse for the changes to take effect<br />
<br />
Once Eclipse has restarted, let's add two other useful plugins that allow connection to the console port of our Gumstix without needing a terminal emulator program such as kermit or TeraTerm.<br />
From within Eclipse,<br />
:* navigate to '''Help->Install New Software'''<br />
:* search on "Target" to find the ''Target Manager Terminal''<br />
<br />
[[File:GumstixEclipse5.jpg]]<br />
<br />
:* select the ''Target Manager Terminal''<br />
:* click "Next"<br />
:* click "Finish" to complete installation<br />
:* choose "Yes" to restart Eclipse for the changes to take effect<br />
<br />
We'll also need to add a new update site by doing these steps in Eclipse:<br />
:* navigate to '''Help->Install New Software...'''<br />
:* click the "Add..." button<br />
:* type ''http://rxtx.qbang.org/eclipse'' into the ''Location'' field and create a name<br />
<br />
[[File:GumstixEclipse6.jpg]]<br />
<br />
:* Click the "OK" button<br />
Go into the sub-directory as shown below to select the ''RXTX End-User Runtime'' plugin that this site provides.<br />
<br />
[[File:GumstixEclipse7.jpg]]<br />
<br />
:* click "Next" twice<br />
:* select the radio button to "ACCEPT" the terms of the license agreement<br />
:* click "OK" at the security warning window<br />
:* click "Finish" to complete installation<br />
:* choose the "Yes" button to restart Eclipse for the changes to take effect<br />
<br />
==Connect Your Gumstix==<br />
Now it is time to connect your Gumstix---let's get started by establishing a console connection.<br />
:* mount your Gumstix COM down on to your expansion board<br />
:* plug the mini-A USB plug into the port marked CONSOLE and end of the cable into a standard USB port on your computer<br />
----<br />
Hint:<br />
Your computer should detect your Gumstix system when you first connect the USB cable, even though the power is not yet turned on. On Macintosh and Windows systems, a pop-up window should appear instructing you to download a new driver (do so) or notifying you that a USBserial device has been detected. If not, you can download drivers from [http://www.ftdichip.com/FTDrivers.htm this site]. Choose the "VCP" driver.<br />
Once you have downloaded this driver, make sure to unplug and then replug the USB cable running from your computer to your Gumstix expansion board so the Gumstix will be recognized by your computer.<br />
----<br />
:* connect your Gumstix to the internet using an ethernet cable<br />
NOTE: You still have NOT plugged the power cable in to the <br />
Gumstix expansion board! This diagram shows the locations<br />
of the USB 'CONSOLE' port and the 'POWER' input port on a <br />
Summit board on which an Overo COM has been mounted.<br />
<br />
[[File:GumstixEclipse8.jpg]]<br />
<br />
:* if you are booting from a microSD card, insert this card now until you hear it click in place.<br />
Before applying power to the board, let's open up a connection to the console port.<br />
In Eclipse,<br />
:* navigate to '''Window->Show View->Other->Terminal->Terminal'''<br />
:* click on the 'N' connection icon in the window that appears<br />
<br />
[[File:GumstixEclipse9.jpg]]<br />
<br />
:* make the connection using the following settings:<br />
Connection Type: Serial<br />
Port: <port to which your Gumstix is connected><br />
Baud Rate: 115200<br />
Data Bits: 8<br />
Stop Bits: 1<br />
Parity: none<br />
Flow Control: none<br />
Timeout: 5<br />
<br />
----<br />
Hint:<br />
The port to which your Gumstix is connected will have a different name depending on your Host operating system.<br />
:* On Windows, it should be ''USB-COM''<br />
:* On Macintosh, it should be ''/dev/tty.usbserial-xxxxxxxx'' where ''xxxxxxxx'' is an arbitrary string of characters<br />
:* On Linux, it should be ''/dev/ttyUSBx'' where ''x'' is a number.<br />
----<br />
<br />
[[File:GumstixEclipse10.jpg]]<br />
<br />
----<br />
Hint:<br />
If this does not work, or you wish to gain Console access via a Unix Shell instead, visit the tutorial on [[Gaining Console Connection via Terminal]]<br />
----<br />
<br />
*Now, it's time to apply power to the Gumstix expansion board so plug the 5V wall adapter into the power input jack on the Gumstix.<br />
<br />
You should see text appear in this window; for now, just let the Gumstix boot. When prompted, you can log in to the root account. The default credentials are:<br />
<br />
'''Overo'''<br />
<br />
username: root<br />
<br />
password: <leave blank><br />
<br />
<br />
'''VerdexPro'''<br />
<br />
username: root<br />
<br />
password: gumstix<br />
<br />
==Create a Web Site==<br />
Each Gumstix comes with a built-in package manager called opkg. A package manager is a useful tool for installing software; you can install everything from media players to GPS mapping tools to the Firefox web browser. In this example, you'll use opkg tool to install a new application for your Gumstix: the Apache web server.<br />
<br />
To make your own Gumstix web site, type the following in the terminal window:<br />
opkg update <Enter><br />
opkg install apache2 <Enter><br />
Before you start using Apache, which is now running, you'll need to find the IP address (internet address) of your Gumstix COM. To do this, type the following command into the terminal window:<br />
ifconfig | grep 'inet addr' <Enter><br />
You should see something like this appear on your screen.<br />
inet addr: 10.0.1.73 Bcast: 192.168.0.255 Mask: 255.255.255.0<br />
The IP address of your Gumstix is the first address shown: ''10.0.1.73'' in this case.<br />
Now,<br />
:* open up a web browser on your host computer<br />
:* type that IP address of your Gumstix into the address bar<br />
You should see something like this which is the default web site for Apache running on your Gumstix.<br />
<br />
[[File:GumstixEclipse11.jpg]]<br />
<br />
To make your web site say something more interesting, do the follow in your terminal window:<br />
:* type: ''nano /usr/share/apache2/htdocs/index.html''<br />
:* replace the words at the top of the screen "It Works" with the words "Gumstix Rocks!"<br />
:* press 'Ctrl+O' <Enter><br />
:* press 'Ctrl+X' to save and exit<br />
:* refresh your web browser<br />
<br />
==Write a Java Application==<br />
So far, you haven't actually used Eclipse other than as a console interface for your Gumstix. It is time to harness the power of Eclipse to write a small graphical Java application.<br />
In Eclipse.<br />
:* Navigate to '''File-> New-> Java Project''',<br />
:* Name the project ''gumstix-java''<br />
:* Select "Finish"<br />
Once the project is created,<br />
:* Select '''File->New->Class'''<br />
:* Name your class ''Hello''<br />
:* click "FINISH"<br />
<br />
Add the following code to your class:<br />
<br />
import javax.swing.JFrame;<br />
import javax.swing.JLabel;<br />
public class Hello {<br />
public static void main(String [] args) {<br />
JFrame frame = new JFrame("hello");<br />
final JLabel label = new JLabel("hello from Gumstix");<br />
frame.getContentPane().add(label);<br />
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);<br />
frame.pack();<br />
frame.setVisible(true);<br />
}<br />
}<br />
<br />
You should get something that looks like this:<br />
<br />
[[File:GumstixEclipse12.jpg]]<br />
<br />
Press the green run button to test drive our application on our host machine.<br />
<br />
----<br />
Hint:<br />
Eclipse has many auto-completion features. Simply typing /:*<Enter> before a class creates a standard documentation block. Likewise, pressing <Ctrl>+<Space> provides context specific auto-completion options. Many other hints for speedy development are explained in the tutorials [http://www.eclipse.org/resources/?category=Getting%20Started here].<br />
----<br />
<br />
==Upload Code==<br />
In Step 5 we discovered the IP address of our Gumstix. With this, we can connect to our Gumstix using the SSH protocol which allows us to rapidly transfer files. For this step, navigate to '''Window->Open Perspective->Other->Remote System Explorer''' and click on the connection icon in the ''Remote Systems'' panel on the left. Select ''SSH without shells'' as the connection type and press Next. Put the internet address you found in Step 5 into the field marked ''Host Name'' and hit finish. To test that everything is working correctly, right-click on the terminal item list under your new connection and select ''Launch Terminal''. A console interface exactly like the USB console interface we set up in Step 3 should pop up.<br />
<br />
<br />
----<br />
Hint:<br />
A 'Perspective' is an arrangement of windows and widgets, that is a specific view of the Eclipse workspace, designed for a particular task. If you wish to focus on any particular widget, double click the tab in Eclipse; return to the previous view by double-clicking again.<br />
----<br />
<br />
<br />
By installing the VNC viewer plugin, we can get a graphical interface to our Gumstix system. Do this by adding the ''Tools for mobile linux runtime'' plugin ('''Help->Install New Software''') from the main update site. To use, select the VNC viewer widget from '''Window->Show View->Other->VNC Category->VNC''' and click on the ''New Connection'' icon in the VNC Viewer panel. Again, the ''Host'' is the internet address of your Gumstix board.<br />
<br />
[[File:GumstixEclipse13.jpg]]<br />
<br />
Finally, we need to upload our java code before we can run it. Switch back to the Java Perspective ('''Window->Open Perspective->Java''') and right-click on our Java file and selecting Export. Choose the option to export file to a remote file system and choose to upload your ''Hello.class'' file.<br />
<br />
[[File:GumstixEclipse14.jpg]]<br />
<br />
You will need to ''Browse'' to find your Gumstix board; you should upload this code to your home directory on the Gumstix.<br />
<br />
==Debug a Java Application==<br />
We can debug our java application remotely from Eclipse. To do this, we need a Java Virtual Machine capable of doing debugging. This time, the package we need isn't available in our package sources however we can fetch the package directly from a web site and install it using the same opkg package management tool.<br />
wget http://bugcommunity.com/downloads/files/phonemeadvanced- personal-debug_mr2-r1_armv6.ipk <Enter><br />
opkg install -force-depends phoneme-advanced-personaldebug_mr2-r1_armv6.ipk <Enter><br />
Let's also update our Java libraries so we have access to the standard graphical libraries.<br />
opkg install classpath-gtk <Enter><br />
Next, let's start our Java code in debugging mode on the Overo:<br />
java-cdc -Xdebug -Xrunjwdp:transport=dHt_socket,server=y,suspend=y,address=1234 Hello <Enter><br />
Finally, let's connect to our debugging session by navigating in Eclipse to '''Run->Debug Configurations''' and double-clicking on Remote Java Application to create a new configuration. Fill in the form as shown below using the internet address found in the previous step.<br />
<br />
==Install a native C/C++ SDK==<br />
When we discussed Python and Java we noted that both are interpreted languages--- neither needs to be compiled. C and C++ code requires compilation which can be done natively---on the Gumstix itself---or on a development machine using a cross-compiler. To do native compilation, you need to install a compiler as well as any required libraries. You'll need to be booting from a microSD card as this installation takes approximately 75MB of space.<br />
$ echo 'src/gz angstrom-base http://www.angstromdistribution.org/feeds/unstable/ipk/glibc/armv7a/base' > /etc/opkg/angstrom-base.conf<br />
$ opkg update<br />
$ opkg install task-native-sdk<br />
Firstly, we are adding a new package repository to our package manager and updating our list of available packages before actually installing the complete package needed to do native development.<br />
<br />
Let's create either of the following files in Eclipse, upload the code and then compile on the Gumstix using our newly installed compiler.<br />
<br />
===C++: HelloWorld.cpp===<br />
#include <iostream><br />
using namespace std;<br />
int main () {<br />
cout << "Gumstix runs on C++" << endl;<br />
return 0;<br />
}<br />
<br />
Save the file and issue the following commands to compile and run HelloWorld.cpp<br />
g++ -o hello hello.cpp <enter><br />
Gumstix runs on C++ <enter><br />
<br />
===C: HelloWorld.c===<br />
#include <stdio.h><br />
int main () {<br />
printf("Gumstix runs on C\n");<br />
return 0;<br />
}<br />
<br />
Save the file and issue the following commands to compile and run HelloWorld.c<br />
gcc -o hello hello.c<br />
Gumstix runs on C<br />
<br />
<TODO: More exciting examples using on-board LEDs.><br />
<br />
==Using GDB as a remote debugger in C/C++==<br />
These instructions will teach you how to download, install, and use the GDB debugger remotely on your Overo COM.<br />
<br />
<pre>NOTE: <br />
remote system - a device that is being operated remotely (via SSH, USB Serial, etc). This means that it is a device that you are operating from a different system <br />
(ie: if you are accessing the Overo COM via connection with your PC, then the Overo COM is a remote system).<br />
For the purpose of this guide, the Overo COM will be the remote system.<br />
<br />
local host - the device that is being used to work on (ie: If you are working on your PC, that is the local host. If you then connect to another computer via VNC, <br />
that is a remote system, and you laptop is still the localhost).<br />
For the purpose of this guide, your Personal Computer will be the local host.</pre><br />
<br />
Before starting, it is important to note there are many different ways to run a remote debugger. The most fundamental choice when debugging remotely is whether you want to:<br />
:*Run the debugger on the remote system or<br />
:*Run the debugger on the local host with a cross debugger on the remote system<br />
<br />
This guide will teach you how to download, install, and run the debugger on the remote system (choice A). If you wish to learn more about the cross debugger option, use Google. Also the wikipedia article on cross compilers (which operate in a very similar fashion) is very good, albeit a bit complicated. None of this is necessary in understanding the contents of this guide. <br />
<br />
For the purposes of this guide, we will be using the GDB: the GNU project debugger. As stated on their website:<br />
<br />
<pre>GDB, the GNU Project debugger, allows you to see what is going on `inside' another program while it executes -- or what another program was doing at the moment it <br />
crashed.<br />
<br />
GDB can do four main kinds of things (plus other things in support of these) to help you catch bugs in the act:<br />
- Start your program, specifying anything that might affect its behavior.<br />
- Make your program stop on specified conditions.<br />
- Examine what has happened, when your program has stopped.<br />
- Change things in your program, so you can experiment with correcting the effects of one bug and go on to learn about another.</pre><br />
<br />
While the reasons for using a debugger instead of trying to debug with the ‘brute force’ method of adding print statements throughout the entire program are enumerable, there are a few that stand out:<br />
# The ability to ‘step’ through a program<br />
#* The GDB debugger allows you to ‘step’ through a program. This means that instead of just executing the program and then leaving you with a final error message, it will execute one line at a time until the program crashes. This allows the user to see exactly where, and why, the program crashed. <br />
# The ability to set breakpoints<br />
#* The GDB debugger allows you to set breakpoints in the program. These are points where the CPU will stop executing the code and allow the user to decide whether to continue. This allows the user to explore what is ‘going on’ at certain points in the execution, something that otherwise is not possible. <br />
# The ability to look at the Backtrace<br />
#* This will show you where, and exactly why, your program crashed. Although SEGFAULT isn’t very useful, the backtrace will tell you what caused the SEGFAULT. Everything from what line, what variable, and even the address that variable was at.<br />
<br />
===Installing the GDB===<br />
Once the Overo COM has been connected to the local host, you should have access to the following command line:<br />
<pre>root@overo:~# </pre><br />
Although you are working on your local host, this command line is for the remote system. It is the same as if you opened up Terminal (for Mac, Linux) or XTerm (for Windows). You now have access and control of the remote system.<br />
<br />
Now there are some packages that must be downloaded and installed onto the Overo so that it can run the GDB environment. To do this issue the following command:<br />
<pre>opkg update <enter><br />
opkg install gdb <enter></pre><br />
This should spew out a bunch of text such as:<br />
<pre>Downloading http://www.angstrom...</pre><br />
Just let it run and once its done, you’ll have the GNU GDB debugger installed on your Overo COM.<br />
<br />
===Creating a C/C++ Program to Debug===<br />
Now, your Overo COM has a debugger installed and ready to use. However, this does not mean you are ready to go. There are two more things required before it is possible to use a GDB debugger.<br />
:* A C/C++ program<br />
:* A SDK to run the program on<br />
To see how to install a SDK and write/run a simple program in C/C++, see [[#Install a native C/C++ SDK]]. <br />
<br />
Once you have a program ready, you first must create an executable file. Lets use for example the C++ program HelloWorld.cpp. To create the executable file HelloWorld, issue the following command:<br />
<pre>g++ -o HelloWorld HelloWorld.cpp <enter></pre><br />
Now, to run the program:<br />
<pre>./HelloWorld <enter></pre><br />
To do the same thing with a C program (HelloWorld.c), issue the command<br />
<pre>gcc -o HelloWorld HelloWorld.c <enter></pre><br />
<pre>./HelloWorld <enter></pre><br />
<br />
What this command does is uses the GNU compiler (either g++ or gcc) and creates an executable object (HelloWorld) out of the C or C++ program file (either HelloWorld.cpp or HelloWorld.c). You may name the executable whatever you like, but it is considered best practice to name it the same thing as the program file.<br />
<br />
===Debugging the Program===<br />
Now that you have GDB installed and a C/C++ program ready to go, its time to debug. To open to GDB environment, run the following command<br />
<pre>gdb <enter></pre><br />
Some text should spit out, and the following command line should appear<br />
<pre>(gdb)</pre><br />
Now that the debugger is running, it is time to tell the debugger what program we want to debug. To do this, first we need to declare our HelloWorld file as an executable file. For this run the following command <br />
<pre>(gdb) exec-file HelloWorld <enter></pre><br />
Now that we have an executable file ready to be debugged, its time to run the program<br />
<pre>(gdb) run HelloWorld <enter></pre><br />
The debugger will now run your program. If the program has no syntax or logic errors, the program should run and end with the line:<br />
Program exited normally.<br />
If there are errors, or the program crashed, it is possible to extract the exact details of that crash by issuing the back trace command.<br />
<pre>(gdb) bt <enter></pre><br />
Once you are done you can quit by issuing the command:<br />
<pre>(gdb) quit <enter></pre><br />
<br />
A complete list of commands in GDB:<br />
www.yolinux.com/TUTORIALS/GDB-Commands.html<br />
<br />
====GDB Debugger Tutorial====<br />
For a complete GDB Debugger tutorial (very good tutorial, comes with sample code they walk you through and extra errors for you to debug yourself!):<br />
http://www.cs.cmu.edu/~gilpin/tutorial/<br />
<br />
Now you have a debugger up and running! Play around with it by putting errors into your program on purpose to see the powers of having a remote debugger!<br />
<br />
==Use a C/C++ cross-compiler==<br />
In order to do C/C++ development on our host machine, we need to add in a plugin to Eclipse. Also, we need to download an appropriate cross-compilation toolchain. For now, I recommend the lovely instructions from<br />
<br />
http://www.designarm.com/quickstart-guide/linux-software/eclipse.html &<br />
<br />
http://www.bugcommunity.com/wiki/index.php/BUG_Kernel_Development_with_Eclipse<br />
<br />
==Further Reading==<br />
===Internal===<br />
[[Gaining Console Connection via Terminal]]<br><br />
[[HelloWorld | HelloWorld in Python, C and C++]]<br><br />
[[Remote Debugging with GDB]] <br><br />
[[HelloWorld in Java]]<br />
<br />
===External===<br />
:* Tutorials built into Eclipse<br />
:* Bitbake commander<br />
:* OpenEmebedded|Poky docs + Bitbake docs<br />
:* Eclipse Plugin Tutorial<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
[[Category:How_to_-_eclipse]]</div>JustinC474https://wiki.gumstix.com/index.php?title=Eclipse_on_Gumstix_for_new_users&diff=4468Eclipse on Gumstix for new users2010-08-05T16:48:52Z<p>JustinC474: </p>
<hr />
<div>This guide provides step-by-step instructions for using the Eclipse Integrated Development Environment (IDE) to develop applications for the Gumstix COMs.<br />
<br />
We'll walk through these tasks:<br />
:* setting up Eclipse<br />
:* connection to your Gumstix system<br />
:* creating a simple "Hello, World!" Python program<br />
:* running a web server<br />
:* installing new packages on your Gumstix<br />
:* creating a small graphical Java application<br />
:* remote debugging of your Java application<br />
:* natively-compiling C/C++ code on your Gumstix<br />
:* remote debugging C/C++ using the GDB server interface<br />
<br />
We will also explain how to set up a cross-compilation toolchain so you can develop C/C++ applications on your development computer and upload them to your Gumstix.<br />
<br />
Remember, Gumstix COMs are fully-fledged, albeit tiny, Linux systems so there are many tools we don't cover here. For example, [http://wiki.openembedded.net/index.php/OpenEmbedded_Tools_for_Eclipse_(OTE) this document] explains how to use the powerful OpenEmbedded build system within Eclipse.<br />
<br />
Required Tools:<br />
:* any Windows, Apple or Linux computer with a USB port<br />
:* recent version of the Java Runtime Environment (available [http://java.sun.com/javase/downloads/index.jsp here])<br />
:* a Gumstix COM running [http://www.gumstix.net/Setup-and-Programming/view/Overo-Setup-and-Programming/Downloading-pre-built-images/111.html up-to-date software]<br />
:* any expansion board of the Gumstix Overo series, such as Chestnut or Tobi, that has both a USB console port and a 10/100 <br />
:* Ethernet jack<br />
:* a 5V power supply<br />
:* an ethernet cable and internet connection<br />
:* a mini-A to Standard-A USB cable<br />
:* a [http://www.gumstix.net/Setup-and-Programming/view/Overo-Setup-and-Programming/Creating-a-bootable-microSD-card/111.html bootable microSD card] (only needed for native C/C++ compilation)<br />
<br />
Key Idea:<br />
[[File:GumstixEclipse1.jpg|thumb|left|upright=5]]<br />
<br />
==Download Eclipse==<br />
[http://www.eclipse.org/downloads/ Download] the Eclipse IDE for Java Developers for your Operating System: www.eclipse.org<br />
<br />
[[Image: GumstixEclipse2.jpg | thumb | left]]<br />
<br />
:* it is ''not'' necessary to install the Eclipse software; just double-click on the application once it has finished downloading<br />
:* when prompted, choose a workspace folder in which you want to store your projects and your configuration information<br />
:* then click through to the Eclipse workbench itself<br />
<br />
==Install Plugins==<br />
For developers, a great variety of additional features can be added to Eclipse from various repositories of plug-ins known as ''Update Sites''.<br />
To install a new plugin in Eclipse, first select the ''Update Site''.<br />
:* navigate to '''Help->Install New Software...'''<br />
:* select the Update Site for your version of Eclipse from the "Work with"dropdown menu<br />
<br />
[[File:GumstixEclipse3.jpg]]<br />
<br />
:Note: If you are not sure which version of Eclipse you have, you can check by reopening Eclipse, it will be displayed on the loading screen.<br />
<br />
----<br />
Hint:<br />
If the update site is not available, you can add it by clicking the 'Add...' button on the right. For the Galileo release, you can use the URL http://dowload.eclipse.org/releases/galileo<br />
----<br />
<br />
As we are working with a remote system, we'll install the Remote System Explorer plugin.<br />
:* search for the ''Remote System Explorer End-User Runtime'' plugin<br />
:* select it for installation<br />
<br />
[[File:GumstixEclipse4.jpg]]<br />
<br />
Still in Eclipse,<br />
:* select "Next".... twice<br />
:* select the radio button to "ACCEPT" the terms of the license agreement<br />
:* choose "Yes" to restart Eclipse for the changes to take effect<br />
<br />
Once Eclipse has restarted, let's add two other useful plugins that allow connection to the console port of our Gumstix without needing a terminal emulator program such as kermit or TeraTerm.<br />
From within Eclipse,<br />
:* navigate to '''Help->Install New Software'''<br />
:* search on "Target" to find the ''Target Manager Terminal''<br />
<br />
[[File:GumstixEclipse5.jpg]]<br />
<br />
:* select the ''Target Manager Terminal''<br />
:* click "Next"<br />
:* click "Finish" to complete installation<br />
:* choose "Yes" to restart Eclipse for the changes to take effect<br />
<br />
We'll also need to add a new update site by doing these steps in Eclipse:<br />
:* navigate to '''Help->Install New Software...'''<br />
:* click the "Add..." button<br />
:* type ''http://rxtx.qbang.org/eclipse'' into the ''Location'' field and create a name<br />
<br />
[[File:GumstixEclipse6.jpg]]<br />
<br />
:* Click the "OK" button<br />
Go into the sub-directory as shown below to select the ''RXTX End-User Runtime'' plugin that this site provides.<br />
<br />
[[File:GumstixEclipse7.jpg]]<br />
<br />
:* click "Next" twice<br />
:* select the radio button to "ACCEPT" the terms of the license agreement<br />
:* click "OK" at the security warning window<br />
:* click "Finish" to complete installation<br />
:* choose the "Yes" button to restart Eclipse for the changes to take effect<br />
<br />
==Connect Your Gumstix==<br />
Now it is time to connect your Gumstix---let's get started by establishing a console connection.<br />
:* mount your Gumstix COM down on to your expansion board<br />
:* plug the mini-A USB plug into the port marked CONSOLE and end of the cable into a standard USB port on your computer<br />
----<br />
Hint:<br />
Your computer should detect your Gumstix system when you first connect the USB cable, even though the power is not yet turned on. On Macintosh and Windows systems, a pop-up window should appear instructing you to download a new driver (do so) or notifying you that a USBserial device has been detected. If not, you can download drivers from [http://www.ftdichip.com/FTDrivers.htm this site]. Choose the "VCP" driver.<br />
Once you have downloaded this driver, make sure to unplug and then replug the USB cable running from your computer to your Gumstix expansion board so the Gumstix will be recognized by your computer.<br />
----<br />
:* connect your Gumstix to the internet using an ethernet cable<br />
NOTE: You still have NOT plugged the power cable in to the <br />
Gumstix expansion board! This diagram shows the locations<br />
of the USB 'CONSOLE' port and the 'POWER' input port on a <br />
Summit board on which an Overo COM has been mounted.<br />
<br />
[[File:GumstixEclipse8.jpg]]<br />
<br />
:* if you are booting from a microSD card, insert this card now until you hear it click in place.<br />
Before applying power to the board, let's open up a connection to the console port.<br />
In Eclipse,<br />
:* navigate to '''Window->Show View->Other->Terminal->Terminal'''<br />
:* click on the 'N' connection icon in the window that appears<br />
<br />
[[File:GumstixEclipse9.jpg]]<br />
<br />
:* make the connection using the following settings:<br />
Connection Type: Serial<br />
Port: <port to which your Gumstix is connected><br />
Baud Rate: 115200<br />
Data Bits: 8<br />
Stop Bits: 1<br />
Parity: none<br />
Flow Control: none<br />
Timeout: 5<br />
<br />
----<br />
Hint:<br />
The port to which your Gumstix is connected will have a different name depending on your Host operating system.<br />
:* On Windows, it should be ''USB-COM''<br />
:* On Macintosh, it should be ''/dev/tty.usbserial-xxxxxxxx'' where ''xxxxxxxx'' is an arbitrary string of characters<br />
:* On Linux, it should be ''/dev/ttyUSBx'' where ''x'' is a number.<br />
----<br />
<br />
[[File:GumstixEclipse10.jpg]]<br />
<br />
----<br />
Hint:<br />
If this does not work, or you wish to gain Console access via a Unix Shell instead, visit the tutorial on [[Gaining Console Connection via Terminal]]<br />
----<br />
<br />
*Now, it's time to apply power to the Gumstix expansion board so plug the 5V wall adapter into the power input jack on the Gumstix.<br />
<br />
You should see text appear in this window; for now, just let the Gumstix boot. When prompted, you can log in to the root account. The default credentials are:<br />
<br />
'''Overo'''<br />
<br />
username: root<br />
<br />
password: <leave blank><br />
<br />
<br />
'''VerdexPro'''<br />
<br />
username: root<br />
<br />
password: gumstix<br />
<br />
==Create a Web Site==<br />
Each Gumstix comes with a built-in package manager called opkg. A package manager is a useful tool for installing software; you can install everything from media players to GPS mapping tools to the Firefox web browser. In this example, you'll use opkg tool to install a new application for your Gumstix: the Apache web server.<br />
<br />
To make your own Gumstix web site, type the following in the terminal window:<br />
opkg update <Enter><br />
opkg install apache2 <Enter><br />
Before you start using Apache, which is now running, you'll need to find the IP address (internet address) of your Gumstix COM. To do this, type the following command into the terminal window:<br />
ifconfig | grep 'inet addr' <Enter><br />
You should see something like this appear on your screen.<br />
inet addr: 10.0.1.73 Bcast: 192.168.0.255 Mask: 255.255.255.0<br />
The IP address of your Gumstix is the first address shown: ''10.0.1.73'' in this case.<br />
Now,<br />
:* open up a web browser on your host computer<br />
:* type that IP address of your Gumstix into the address bar<br />
You should see something like this which is the default web site for Apache running on your Gumstix.<br />
<br />
[[File:GumstixEclipse11.jpg]]<br />
<br />
To make your web site say something more interesting, do the follow in your terminal window:<br />
:* type: ''nano /usr/share/apache2/htdocs/index.html''<br />
:* replace the words at the top of the screen "It Works" with the words "Gumstix Rocks!"<br />
:* press 'Ctrl+O' <Enter><br />
:* press 'Ctrl+X' to save and exit<br />
:* refresh your web browser<br />
<br />
==Write a Java Application==<br />
So far, you haven't actually used Eclipse other than as a console interface for your Gumstix. It is time to harness the power of Eclipse to write a small graphical Java application.<br />
In Eclipse.<br />
:* Navigate to '''File-> New-> Java Project''',<br />
:* Name the project ''gumstix-java''<br />
:* Select "Finish"<br />
Once the project is created,<br />
:* Select '''File->New->Class'''<br />
:* Name your class ''Hello''<br />
:* click "FINISH"<br />
<br />
Add the following code to your class:<br />
<br />
import javax.swing.JFrame;<br />
import javax.swing.JLabel;<br />
public class Hello {<br />
public static void main(String [] args) {<br />
JFrame frame = new JFrame("hello");<br />
final JLabel label = new JLabel("hello from Gumstix");<br />
frame.getContentPane().add(label);<br />
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);<br />
frame.pack();<br />
frame.setVisible(true);<br />
}<br />
}<br />
<br />
You should get something that looks like this:<br />
<br />
[[File:GumstixEclipse12.jpg]]<br />
<br />
Press the green run button to test drive our application on our host machine.<br />
<br />
----<br />
Hint:<br />
Eclipse has many auto-completion features. Simply typing /:*<Enter> before a class creates a standard documentation block. Likewise, pressing <Ctrl>+<Space> provides context specific auto-completion options. Many other hints for speedy development are explained in the tutorials [http://www.eclipse.org/resources/?category=Getting%20Started here].<br />
----<br />
<br />
==Upload Code==<br />
In Step 5 we discovered the IP address of our Gumstix. With this, we can connect to our Gumstix using the SSH protocol which allows us to rapidly transfer files. For this step, navigate to '''Window->Open Perspective->Other->Remote System Explorer''' and click on the connection icon in the ''Remote Systems'' panel on the left. Select ''SSH without shells'' as the connection type and press Next. Put the internet address you found in Step 5 into the field marked ''Host Name'' and hit finish. To test that everything is working correctly, right-click on the terminal item list under your new connection and select ''Launch Terminal''. A console interface exactly like the USB console interface we set up in Step 3 should pop up.<br />
<br />
<br />
----<br />
Hint:<br />
A 'Perspective' is an arrangement of windows and widgets, that is a specific view of the Eclipse workspace, designed for a particular task. If you wish to focus on any particular widget, double click the tab in Eclipse; return to the previous view by double-clicking again.<br />
----<br />
<br />
<br />
By installing the VNC viewer plugin, we can get a graphical interface to our Gumstix system. Do this by adding the ''Tools for mobile linux runtime'' plugin ('''Help->Install New Software''') from the main update site. To use, select the VNC viewer widget from '''Window->Show View->Other->VNC Category->VNC''' and click on the ''New Connection'' icon in the VNC Viewer panel. Again, the ''Host'' is the internet address of your Gumstix board.<br />
<br />
[[File:GumstixEclipse13.jpg]]<br />
<br />
Finally, we need to upload our java code before we can run it. Switch back to the Java Perspective ('''Window->Open Perspective->Java''') and right-click on our Java file and selecting Export. Choose the option to export file to a remote file system and choose to upload your ''Hello.class'' file.<br />
<br />
[[File:GumstixEclipse14.jpg]]<br />
<br />
You will need to ''Browse'' to find your Gumstix board; you should upload this code to your home directory on the Gumstix.<br />
<br />
==Debug a Java Application==<br />
We can debug our java application remotely from Eclipse. To do this, we need a Java Virtual Machine capable of doing debugging. This time, the package we need isn't available in our package sources however we can fetch the package directly from a web site and install it using the same opkg package management tool.<br />
wget http://bugcommunity.com/downloads/files/phonemeadvanced- personal-debug_mr2-r1_armv6.ipk <Enter><br />
opkg install -force-depends phoneme-advanced-personaldebug_mr2-r1_armv6.ipk <Enter><br />
Let's also update our Java libraries so we have access to the standard graphical libraries.<br />
opkg install classpath-gtk <Enter><br />
Next, let's start our Java code in debugging mode on the Overo:<br />
java-cdc -Xdebug -Xrunjwdp:transport=dHt_socket,server=y,suspend=y,address=1234 Hello <Enter><br />
Finally, let's connect to our debugging session by navigating in Eclipse to '''Run->Debug Configurations''' and double-clicking on Remote Java Application to create a new configuration. Fill in the form as shown below using the internet address found in the previous step.<br />
<br />
==Install a native C/C++ SDK==<br />
When we discussed Python and Java we noted that both are interpreted languages--- neither needs to be compiled. C and C++ code requires compilation which can be done natively---on the Gumstix itself---or on a development machine using a cross-compiler. To do native compilation, you need to install a compiler as well as any required libraries. You'll need to be booting from a microSD card as this installation takes approximately 75MB of space.<br />
$ echo 'src/gz angstrom-base http://www.angstromdistribution.org/feeds/unstable/ipk/glibc/armv7a/base' > /etc/opkg/angstrom-base.conf<br />
$ opkg update<br />
$ opkg install task-native-sdk<br />
Firstly, we are adding a new package repository to our package manager and updating our list of available packages before actually installing the complete package needed to do native development.<br />
<br />
Let's create either of the following files in Eclipse, upload the code and then compile on the Gumstix using our newly installed compiler.<br />
<br />
===C++: HelloWorld.cpp===<br />
#include <iostream><br />
using namespace std;<br />
int main () {<br />
cout << "Gumstix runs on C++" << endl;<br />
return 0;<br />
}<br />
<br />
Save the file and issue the following commands to compile and run HelloWorld.cpp<br />
g++ -o hello hello.cpp <enter><br />
Gumstix runs on C++ <enter><br />
<br />
===C: HelloWorld.c===<br />
#include <stdio.h><br />
int main () {<br />
printf("Gumstix runs on C\n");<br />
return 0;<br />
}<br />
<br />
Save the file and issue the following commands to compile and run HelloWorld.c<br />
gcc -o hello hello.c<br />
Gumstix runs on C<br />
<br />
<TODO: More exciting examples using on-board LEDs.><br />
<br />
==Using GDB as a remote debugger in C/C++==<br />
These instructions will teach you how to download, install, and use the GDB debugger remotely on your Overo COM.<br />
<br />
<pre>NOTE: <br />
remote system - a device that is being operated remotely (via SSH, USB Serial, etc). This means that it is a device that you are operating from a different system <br />
(ie: if you are accessing the Overo COM via connection with your PC, then the Overo COM is a remote system).<br />
For the purpose of this guide, the Overo COM will be the remote system.<br />
<br />
local host - the device that is being used to work on (ie: If you are working on your PC, that is the local host. If you then connect to another computer via VNC, <br />
that is a remote system, and you laptop is still the localhost).<br />
For the purpose of this guide, your Personal Computer will be the local host.</pre><br />
<br />
Before starting, it is important to note there are many different ways to run a remote debugger. The most fundamental choice when debugging remotely is whether you want to:<br />
:*Run the debugger on the remote system or<br />
:*Run the debugger on the local host with a cross debugger on the remote system<br />
<br />
This guide will teach you how to download, install, and run the debugger on the remote system (choice A). If you wish to learn more about the cross debugger option, use Google. Also the wikipedia article on cross compilers (which operate in a very similar fashion) is very good, albeit a bit complicated. None of this is necessary in understanding the contents of this guide. <br />
<br />
For the purposes of this guide, we will be using the GDB: the GNU project debugger. As stated on their website:<br />
<br />
<pre>GDB, the GNU Project debugger, allows you to see what is going on `inside' another program while it executes -- or what another program was doing at the moment it <br />
crashed.<br />
<br />
GDB can do four main kinds of things (plus other things in support of these) to help you catch bugs in the act:<br />
- Start your program, specifying anything that might affect its behavior.<br />
- Make your program stop on specified conditions.<br />
- Examine what has happened, when your program has stopped.<br />
- Change things in your program, so you can experiment with correcting the effects of one bug and go on to learn about another.</pre><br />
<br />
While the reasons for using a debugger instead of trying to debug with the ‘brute force’ method of adding print statements throughout the entire program are enumerable, there are a few that stand out:<br />
# The ability to ‘step’ through a program<br />
#* The GDB debugger allows you to ‘step’ through a program. This means that instead of just executing the program and then leaving you with a final error message, it will execute one line at a time until the program crashes. This allows the user to see exactly where, and why, the program crashed. <br />
# The ability to set breakpoints<br />
#* The GDB debugger allows you to set breakpoints in the program. These are points where the CPU will stop executing the code and allow the user to decide whether to continue. This allows the user to explore what is ‘going on’ at certain points in the execution, something that otherwise is not possible. <br />
# The ability to look at the Backtrace<br />
#* This will show you where, and exactly why, your program crashed. Although SEGFAULT isn’t very useful, the backtrace will tell you what caused the SEGFAULT. Everything from what line, what variable, and even the address that variable was at.<br />
<br />
===Installing the GDB===<br />
Once the Overo COM has been connected to the local host, you should have access to the following command line:<br />
<pre>root@overo:~# </pre><br />
Although you are working on your local host, this command line is for the remote system. It is the same as if you opened up Terminal (for Mac, Linux) or XTerm (for Windows). You now have access and control of the remote system.<br />
<br />
Now there are some packages that must be downloaded and installed onto the Overo so that it can run the GDB environment. To do this issue the following command:<br />
<pre>opkg update <enter><br />
opkg install gdb <enter></pre><br />
This should spew out a bunch of text such as:<br />
<pre>Downloading http://www.angstrom...</pre><br />
Just let it run and once its done, you’ll have the GNU GDB debugger installed on your Overo COM.<br />
<br />
===Creating a C/C++ Program to Debug===<br />
Now, your Overo COM has a debugger installed and ready to use. However, this does not mean you are ready to go. There are two more things required before it is possible to use a GDB debugger.<br />
:* A C/C++ program<br />
:* A SDK to run the program on<br />
To see how to install a SDK and write/run a simple program in C/C++, see [[#Install a native C/C++ SDK]]. <br />
<br />
Once you have a program ready, you first must create an executable file. Lets use for example the C++ program HelloWorld.cpp. To create the executable file HelloWorld, issue the following command:<br />
<pre>g++ -o HelloWorld HelloWorld.cpp <enter></pre><br />
Now, to run the program:<br />
<pre>./HelloWorld <enter></pre><br />
To do the same thing with a C program (HelloWorld.c), issue the command<br />
<pre>gcc -o HelloWorld HelloWorld.c <enter></pre><br />
<pre>./HelloWorld <enter></pre><br />
<br />
What this command does is uses the GNU compiler (either g++ or gcc) and creates an executable object (HelloWorld) out of the C or C++ program file (either HelloWorld.cpp or HelloWorld.c). You may name the executable whatever you like, but it is considered best practice to name it the same thing as the program file.<br />
<br />
===Debugging the Program===<br />
Now that you have GDB installed and a C/C++ program ready to go, its time to debug. To open to GDB environment, run the following command<br />
<pre>gdb <enter></pre><br />
Some text should spit out, and the following command line should appear<br />
<pre>(gdb)</pre><br />
Now that the debugger is running, it is time to tell the debugger what program we want to debug. To do this, first we need to declare our HelloWorld file as an executable file. For this run the following command <br />
<pre>(gdb) exec-file HelloWorld <enter></pre><br />
Now that we have an executable file ready to be debugged, its time to run the program<br />
<pre>(gdb) run HelloWorld <enter></pre><br />
The debugger will now run your program. If the program has no syntax or logic errors, the program should run and end with the line:<br />
Program exited normally.<br />
If there are errors, or the program crashed, it is possible to extract the exact details of that crash by issuing the back trace command.<br />
<pre>(gdb) bt <enter></pre><br />
Once you are done you can quit by issuing the command:<br />
<pre>(gdb) quit <enter></pre><br />
<br />
A complete list of commands in GDB:<br />
www.yolinux.com/TUTORIALS/GDB-Commands.html<br />
<br />
====GDB Debugger Tutorial====<br />
For a complete GDB Debugger tutorial (very good tutorial, comes with sample code they walk you through and extra errors for you to debug yourself!):<br />
http://www.cs.cmu.edu/~gilpin/tutorial/<br />
<br />
Now you have a debugger up and running! Play around with it by putting errors into your program on purpose to see the powers of having a remote debugger!<br />
<br />
==Use a C/C++ cross-compiler==<br />
In order to do C/C++ development on our host machine, we need to add in a plugin to Eclipse. Also, we need to download an appropriate cross-compilation toolchain. For now, I recommend the lovely instructions from<br />
<br />
http://www.designarm.com/quickstart-guide/linux-software/eclipse.html &<br />
<br />
http://www.bugcommunity.com/wiki/index.php/BUG_Kernel_Development_with_Eclipse<br />
<br />
==Further Reading==<br />
===Internal===<br />
[[Gaining Console Connection via Terminal]]<br><br />
[[HelloWorld | HelloWorld in Python, C and C++]]<br><br />
[[Remote Debugging with GDB]] <br><br />
[[HelloWorld in Java]]<br />
<br />
===External===<br />
:* Tutorials built into Eclipse<br />
:* Bitbake commander<br />
:* OpenEmebedded|Poky docs + Bitbake docs<br />
:* Eclipse Plugin Tutorial<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
[[Category:How_to_-_eclipse]]</div>JustinC474https://wiki.gumstix.com/index.php?title=Minesweeper_in_Java&diff=4401Minesweeper in Java2010-07-29T16:02:29Z<p>JustinC474: </p>
<hr />
<div>This tutorial gives a brief overview of what to do to get a small, graphical Minesweeper game running on your Overo. If you have not done so, please go through the tutorials [[Eclipse on Gumstix for new users]] and [[HelloWorld in Java]].<br />
<br />
*Create a new Project in Eclipse <br />
:*'''File -> New Project -> Java Project'''<br />
*Create a class '''Main Class'''<br />
:*Copy and paste the following code to that class:<br />
<pre> <br />
import java.awt.BorderLayout;<br />
import java.awt.Color;<br />
import java.awt.event.ActionEvent;<br />
import java.awt.event.ActionListener;<br />
<br />
import javax.swing.JButton;<br />
import javax.swing.JColorChooser;<br />
import javax.swing.JFrame;<br />
import javax.swing.JOptionPane;<br />
<br />
public class MainClass {<br />
public static void main(String args[]) {<br />
JFrame f = new JFrame("JColorChooser Sample");<br />
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);<br />
final JButton button = new JButton("Pick to Change Background");<br />
<br />
ActionListener actionListener = new ActionListener() {<br />
public void actionPerformed(ActionEvent actionEvent) {<br />
Color initialBackground = button.getBackground();<br />
Color background = JColorChooser.showDialog(null,<br />
"JColorChooser Sample", initialBackground);<br />
if (background != null) {<br />
button.setBackground(background);<br />
}<br />
}<br />
};<br />
button.addActionListener(actionListener);<br />
f.add(button, BorderLayout.CENTER);<br />
f.setSize(300, 200);<br />
f.setVisible(true);<br />
}<br />
<br />
}</pre><br />
*Create a class '''MineSweeper''' (Capital S!)<br />
:*Copy and paste the following code to that class:<br />
<pre>import java.awt.AWTEvent;<br />
import java.awt.BorderLayout;<br />
import java.awt.Color;<br />
import java.awt.Component;<br />
import java.awt.FlowLayout;<br />
import java.awt.GridLayout;<br />
import java.awt.Insets;<br />
import java.awt.Point;<br />
import java.awt.Toolkit;<br />
import java.awt.event.AWTEventListener;<br />
import java.awt.event.ActionEvent;<br />
import java.awt.event.ActionListener;<br />
import java.awt.event.KeyEvent;<br />
import java.awt.event.MouseAdapter;<br />
import java.awt.event.MouseEvent;<br />
import java.util.ArrayList;<br />
import java.util.List;<br />
import java.util.Random;<br />
<br />
import javax.swing.JButton;<br />
import javax.swing.JFrame;<br />
import javax.swing.JLabel;<br />
import javax.swing.JOptionPane;<br />
import javax.swing.JPanel;<br />
<br />
public class MineSweeper extends JPanel implements AWTEventListener, ActionListener {<br />
<br />
public static enum State {<br />
Clicked, Marked, Initial, WrongMarked<br />
}<br />
<br />
public static enum GameState {<br />
NotStarted, Playing, Finished<br />
}<br />
<br />
private static final int MAX_BOMB_COUNT = 10;<br />
private int ROWS = 9, COLUMNS = 9, TOTAL = ROWS * COLUMNS;<br />
private JPanel pnlMain = new JPanel(new GridLayout(ROWS, COLUMNS));<br />
private JLabel lblBombCount = new JLabel(MAX_BOMB_COUNT + "");<br />
private JLabel lblTimer = new JLabel("0");<br />
private boolean isColorCheatOn = false;<br />
private JButton btnReset = new JButton("Reset");<br />
<br />
private void startThread() {<br />
Thread th = new Thread(new Runnable() {<br />
public void run() {<br />
while (state == GameState.Playing) {<br />
lblTimer.setText((Long.parseLong(lblTimer.getText()) + 1) + "");<br />
lblTimer.updateUI();<br />
try {<br />
Thread.sleep(1000);<br />
} catch (InterruptedException e) {<br />
e.printStackTrace();<br />
}<br />
}<br />
}<br />
});<br />
th.start();<br />
}<br />
<br />
private GameState state = GameState.NotStarted;<br />
<br />
public MineSweeper() {<br />
setLayout(new BorderLayout());<br />
add(pnlMain, BorderLayout.CENTER);<br />
createButtons();<br />
addControlPanel();<br />
Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK);<br />
}<br />
<br />
private void showAbout() {<br />
JOptionPane.showMessageDialog(this, "<html>Author : Justin Cowles Cowperthwaite <br>Version : 1.0</html>", "About", JOptionPane.INFORMATION_MESSAGE);<br />
}<br />
<br />
private void restartGame() {<br />
state = GameState.NotStarted;<br />
lblTimer.setText("0");<br />
pnlMain.removeAll();<br />
createButtons();<br />
pnlMain.updateUI();<br />
lblBombCount.setText("" + MAX_BOMB_COUNT);<br />
lblBombCount.updateUI();<br />
}<br />
<br />
private void addControlPanel() {<br />
JPanel pnlTimer = new JPanel(new FlowLayout(FlowLayout.RIGHT));<br />
<br />
pnlTimer.add(lblTimer);<br />
<br />
JPanel pnl = new JPanel(new FlowLayout(FlowLayout.CENTER));<br />
<br />
btnReset.setToolTipText("<HTML>Press <B>F2</B> to reset the current game</HTML>");<br />
pnl.add(lblBombCount);<br />
pnl.add(btnReset);<br />
JPanel pnlN = new JPanel(new GridLayout(1, 3));<br />
<br />
pnlN.add(lblBombCount);<br />
pnlN.add(pnl);<br />
pnlN.add(pnlTimer);<br />
add(pnlN, BorderLayout.NORTH);<br />
btnReset.addActionListener(this);<br />
}<br />
<br />
private void createButtons() {<br />
List<Point> lstBombsLocation = new ArrayList<Point>();<br />
<br />
for (int row = 0; row < ROWS; row++) {<br />
for (int col = 0; col < COLUMNS; col++) {<br />
JButton btn = getButton(lstBombsLocation, TOTAL, new Point(row, col) {<br />
@Override<br />
public String toString() {<br />
return (int) getX() + ", " + (int) getY();<br />
}<br />
<br />
@Override<br />
public boolean equals(Object obj) {<br />
return ((Point) obj).getX() == getX() && ((Point) obj).getY() == getY();<br />
}<br />
});<br />
pnlMain.add(btn);<br />
}<br />
}<br />
while (lstBombsLocation.size() < MAX_BOMB_COUNT) {<br />
updateBomds(lstBombsLocation, pnlMain.getComponents());<br />
}<br />
for (Component c : pnlMain.getComponents()) {<br />
updateBombCount((GameButton) c, pnlMain.getComponents());<br />
}<br />
// System.out.println("Total Bomb Count: " + lstBombsLocation.size());<br />
}<br />
<br />
private void updateBomds(List<Point> lstBombsLocation, Component[] components) {<br />
// int currentPosition = new Double(((location.x) * COLUMNS ) +<br />
// location.getY()).intValue();<br />
Random r = new Random();<br />
for (Component c : components) {<br />
Point location = ((GameButton) c).getPosition();<br />
int currentPosition = new Double(((location.x) * COLUMNS) + location.getY()).intValue();<br />
int bombLocation = r.nextInt(TOTAL);<br />
if (bombLocation == currentPosition) {<br />
((GameButton) c).setBomb(true);<br />
lstBombsLocation.add(((GameButton) c).getPosition());<br />
return;<br />
}<br />
}<br />
}<br />
<br />
private GameButton getButton(List<Point> lstBombsLocation, int totalLocations, Point location) {<br />
GameButton btn = new GameButton(location);<br />
btn.setMargin(new Insets(0, 0, 0, 0));<br />
btn.setFocusable(false);<br />
if (lstBombsLocation.size() < MAX_BOMB_COUNT) {<br />
if (isBomb()) {<br />
btn.setBomb(true);<br />
lstBombsLocation.add(location);<br />
}<br />
}<br />
btn.addMouseListener(new MouseAdapter() {<br />
@Override<br />
public void mouseClicked(MouseEvent mouseEvent) {<br />
if (state != GameState.Playing) {<br />
state = GameState.Playing;<br />
startThread();<br />
}<br />
if (((GameButton) mouseEvent.getSource()).isEnabled() == false) {<br />
return;<br />
}<br />
if (mouseEvent.getButton() == MouseEvent.BUTTON1) {<br />
if (((GameButton) mouseEvent.getSource()).getState() == State.Marked) {<br />
((GameButton) mouseEvent.getSource()).setState(State.Initial);<br />
lblBombCount.setText((Long.parseLong(lblBombCount.getText()) + 1) + "");<br />
((GameButton) mouseEvent.getSource()).updateUI();<br />
return;<br />
}<br />
((GameButton) mouseEvent.getSource()).setState(State.Clicked);<br />
if (((GameButton) mouseEvent.getSource()).isBomb()) {<br />
blastBombs();<br />
return;<br />
} else {<br />
if (((GameButton) mouseEvent.getSource()).getBombCount() == 0) {<br />
updateSurroundingZeros(((GameButton) mouseEvent.getSource()).getPosition());<br />
}<br />
}<br />
if (!checkGameState()) {<br />
((GameButton) mouseEvent.getSource()).setEnabled(false);<br />
}<br />
} else if (mouseEvent.getButton() == MouseEvent.BUTTON3) {<br />
if (((GameButton) mouseEvent.getSource()).getState() == State.Marked) {<br />
((GameButton) mouseEvent.getSource()).setState(State.Initial);<br />
lblBombCount.setText((Long.parseLong(lblBombCount.getText()) + 1) + "");<br />
} else {<br />
((GameButton) mouseEvent.getSource()).setState(State.Marked);<br />
lblBombCount.setText((Long.parseLong(lblBombCount.getText()) - 1) + "");<br />
}<br />
}<br />
((GameButton) mouseEvent.getSource()).updateUI();<br />
}<br />
});<br />
return btn;<br />
}<br />
<br />
private boolean checkGameState() {<br />
boolean isWin = false;<br />
for (Component c : pnlMain.getComponents()) {<br />
GameButton b = (GameButton) c;<br />
if (b.getState() != State.Clicked) {<br />
if (b.isBomb()) {<br />
isWin = true;<br />
} else {<br />
return false;<br />
}<br />
}<br />
}<br />
if (isWin) {<br />
state = GameState.Finished;<br />
for (Component c : pnlMain.getComponents()) {<br />
GameButton b = (GameButton) c;<br />
if (b.isBomb()) {<br />
b.setState(State.Marked);<br />
}<br />
b.setEnabled(false);<br />
<br />
}<br />
JOptionPane.showMessageDialog(this, "You win the game :D", "Congrats", JOptionPane.INFORMATION_MESSAGE, null);<br />
}<br />
return isWin;<br />
}<br />
<br />
private void updateSurroundingZeros(Point currentPoint) {<br />
Point[] points = getSurroundings(currentPoint);<br />
<br />
for (Point p : points) {<br />
GameButton b = getButtonAt(pnlMain.getComponents(), p);<br />
if (b != null && b.getBombCount() == 0 && b.getState() != State.Clicked && b.getState() != State.Marked && b.isBomb() == false) {<br />
b.setState(State.Clicked);<br />
updateSurroundingZeros(b.getPosition());<br />
b.updateUI();<br />
}<br />
if (b != null && b.getBombCount() > 0 && b.getState() != State.Clicked && b.getState() != State.Marked && b.isBomb() == false) {<br />
b.setEnabled(false);<br />
b.setState(State.Clicked);<br />
b.updateUI();<br />
}<br />
}<br />
}<br />
<br />
private void blastBombs() {<br />
int blastCount = 0;<br />
for (Component c : pnlMain.getComponents()) {<br />
((GameButton) c).setEnabled(false);<br />
((GameButton) c).transferFocus();<br />
if (((GameButton) c).isBomb() && ((GameButton) c).getState() != State.Marked) {<br />
((GameButton) c).setState(State.Clicked);<br />
((GameButton) c).updateUI();<br />
blastCount++;<br />
}<br />
if (((GameButton) c).isBomb() == false && ((GameButton) c).getState() == State.Marked) {<br />
((GameButton) c).setState(State.WrongMarked);<br />
}<br />
}<br />
lblBombCount.setText("" + blastCount);<br />
lblBombCount.updateUI();<br />
state = GameState.Finished;<br />
JOptionPane.showMessageDialog(this, "You loose the game :(", "Game Over", JOptionPane.ERROR_MESSAGE, null);<br />
for (Component c : pnlMain.getComponents()) {<br />
GameButton b = (GameButton) c;<br />
b.setEnabled(false);<br />
}<br />
}<br />
<br />
private boolean isBomb() {<br />
Random r = new Random();<br />
return r.nextInt(ROWS) == 1;<br />
}<br />
<br />
public static void main(String[] args) {<br />
JFrame fr = new JFrame("MineSweeper");<br />
fr.setLayout(new BorderLayout());<br />
fr.add(new MineSweeper());<br />
fr.setResizable(false);<br />
fr.setSize(250, 350);<br />
fr.setLocationRelativeTo(null);<br />
fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);<br />
fr.setVisible(true);<br />
}<br />
<br />
class GameButton extends JButton {<br />
private boolean isBomb = false;<br />
private Point position = null;<br />
private int bombCount = 0;<br />
private State state = State.Initial;<br />
<br />
public void setState(State state) {<br />
this.state = state;<br />
if (getBombCount() == 0 && !isBomb) {<br />
setEnabled(false);<br />
}<br />
}<br />
<br />
public State getState() {<br />
return state;<br />
}<br />
<br />
public int getBombCount() {<br />
return bombCount;<br />
}<br />
<br />
public void setBombCount(int bombCount) {<br />
this.bombCount = bombCount;<br />
}<br />
<br />
public GameButton(Point position) {<br />
setPosition(position);<br />
setText(position.toString());<br />
}<br />
<br />
public Point getPosition() {<br />
return position;<br />
}<br />
<br />
public void setPosition(Point position) {<br />
this.position = position;<br />
}<br />
<br />
public boolean isBomb() {<br />
return isBomb;<br />
}<br />
<br />
public void setBomb(boolean isBomb) {<br />
this.isBomb = isBomb;<br />
}<br />
<br />
@Override<br />
public String getText() {<br />
if (state == State.Initial) {<br />
return "";<br />
}<br />
if (state == State.Marked) {<br />
return "\u00B6";<br />
}<br />
if (state == State.Clicked) {<br />
if (isBomb) {<br />
return "<html><font size='16'><b>*</b></font></html>";<br />
} else {<br />
if (getBombCount() > 0)<br />
return getBombCount() + "";<br />
else<br />
return "";<br />
}<br />
}<br />
if (state == State.WrongMarked) {<br />
return "X";<br />
}<br />
return super.getText();<br />
}<br />
<br />
@Override<br />
public Color getBackground() {<br />
if (isColorCheatOn && isBomb) {<br />
return Color.MAGENTA;<br />
}<br />
if (state == State.Clicked) {<br />
if (isBomb) {<br />
return Color.RED;<br />
}<br />
if (getBombCount() > 0) {<br />
return Color.GREEN;<br />
}<br />
}<br />
if (isEnabled()) {<br />
return Color.YELLOW.brighter();<br />
} else {<br />
return super.getBackground();<br />
}<br />
}<br />
}<br />
<br />
private Point[] getSurroundings(Point cPoint) {<br />
int cX = (int) cPoint.getX();<br />
int cY = (int) cPoint.getY();<br />
Point[] points = { new Point(cX - 1, cY - 1), new Point(cX - 1, cY), new Point(cX - 1, cY + 1), new Point(cX, cY - 1), new Point(cX, cY + 1), <br />
new Point(cX + 1, cY - 1), new Point(cX + 1, cY), new Point(cX + 1, cY + 1) };<br />
return points;<br />
}<br />
<br />
private void updateBombCount(GameButton btn, Component[] components) {<br />
Point[] points = getSurroundings(btn.getPosition());<br />
<br />
for (Point p : points) {<br />
GameButton b = getButtonAt(components, p);<br />
if (b != null && b.isBomb()) {<br />
btn.setBombCount(btn.getBombCount() + 1);<br />
}<br />
}<br />
btn.setText(btn.getBombCount() + "");<br />
}<br />
<br />
private GameButton getButtonAt(Component[] components, Point position) {<br />
for (Component btn : components) {<br />
if ((((GameButton) btn).getPosition().equals(position))) {<br />
return (GameButton) btn;<br />
}<br />
}<br />
return null;<br />
}<br />
<br />
public void eventDispatched(AWTEvent event) {<br />
if (KeyEvent.class.isInstance(event) && ((KeyEvent) (event)).getID() == KeyEvent.KEY_RELEASED) {<br />
if (((KeyEvent) (event)).getKeyCode() == KeyEvent.VK_F1) {<br />
showAbout();<br />
}<br />
if (((KeyEvent) (event)).getKeyCode() == KeyEvent.VK_F2) {<br />
restartGame();<br />
}<br />
if (((KeyEvent) (event)).getKeyCode() == KeyEvent.VK_F3) {<br />
isColorCheatOn = !isColorCheatOn;<br />
if (state == GameState.Playing) {<br />
pnlMain.updateUI();<br />
}<br />
}<br />
<br />
if (((KeyEvent) (event)).getKeyCode() == KeyEvent.VK_F12) {<br />
for (Component c : pnlMain.getComponents()) {<br />
GameButton b = (GameButton) c;<br />
if (b.isBomb() == false) {<br />
b.setState(State.Clicked);<br />
} else {<br />
b.setState(State.Marked);<br />
}<br />
b.setEnabled(false);<br />
}<br />
checkGameState();<br />
}<br />
}<br />
}<br />
<br />
public void actionPerformed(ActionEvent actionEvent) {<br />
if (actionEvent.getSource() == btnReset) {<br />
restartGame();<br />
}<br />
}<br />
}</pre><br />
<br />
Go back to [[HelloWorld in Java]] and follow the instructions for Exporting and Running a Java Program on the Over COM. When you are done, you should be able to play a 9x10 colorful game of MineSweeper on the monitor connected to your Overo COM expansion board.</div>JustinC474https://wiki.gumstix.com/index.php?title=Minesweeper_in_Java&diff=4400Minesweeper in Java2010-07-29T16:01:47Z<p>JustinC474: </p>
<hr />
<div>This tutorial gives a brief overview of what to do to get a small, graphical Minesweeper game running on your Overo. If you have not done so, please go through the tutorials [[Eclipse on Gumstix for new users]] and [[HelloWorld in Java]].<br />
<br />
*Create a new Project in Eclipse <br />
:*'''File -> New Project -> Java Project'''<br />
*Create a class '''Main Class'''<br />
:*Copy and paste the following code to that class:<br />
<pre> <br />
import java.awt.BorderLayout;<br />
import java.awt.Color;<br />
import java.awt.event.ActionEvent;<br />
import java.awt.event.ActionListener;<br />
<br />
import javax.swing.JButton;<br />
import javax.swing.JColorChooser;<br />
import javax.swing.JFrame;<br />
import javax.swing.JOptionPane;<br />
<br />
public class MainClass {<br />
public static void main(String args[]) {<br />
JFrame f = new JFrame("JColorChooser Sample");<br />
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);<br />
final JButton button = new JButton("Pick to Change Background");<br />
<br />
ActionListener actionListener = new ActionListener() {<br />
public void actionPerformed(ActionEvent actionEvent) {<br />
Color initialBackground = button.getBackground();<br />
Color background = JColorChooser.showDialog(null,<br />
"JColorChooser Sample", initialBackground);<br />
if (background != null) {<br />
button.setBackground(background);<br />
}<br />
}<br />
};<br />
button.addActionListener(actionListener);<br />
f.add(button, BorderLayout.CENTER);<br />
f.setSize(300, 200);<br />
f.setVisible(true);<br />
}<br />
<br />
}</pre><br />
*Create a class '''MineSweeper''' (Capital S!)<br />
:*Copy and paste the following code to that class:<br />
<pre>import java.awt.AWTEvent;<br />
import java.awt.BorderLayout;<br />
import java.awt.Color;<br />
import java.awt.Component;<br />
import java.awt.FlowLayout;<br />
import java.awt.GridLayout;<br />
import java.awt.Insets;<br />
import java.awt.Point;<br />
import java.awt.Toolkit;<br />
import java.awt.event.AWTEventListener;<br />
import java.awt.event.ActionEvent;<br />
import java.awt.event.ActionListener;<br />
import java.awt.event.KeyEvent;<br />
import java.awt.event.MouseAdapter;<br />
import java.awt.event.MouseEvent;<br />
import java.util.ArrayList;<br />
import java.util.List;<br />
import java.util.Random;<br />
<br />
import javax.swing.JButton;<br />
import javax.swing.JFrame;<br />
import javax.swing.JLabel;<br />
import javax.swing.JOptionPane;<br />
import javax.swing.JPanel;<br />
<br />
public class MineSweeper extends JPanel implements AWTEventListener, ActionListener {<br />
<br />
public static enum State {<br />
Clicked, Marked, Initial, WrongMarked<br />
}<br />
<br />
public static enum GameState {<br />
NotStarted, Playing, Finished<br />
}<br />
<br />
private static final int MAX_BOMB_COUNT = 10;<br />
private int ROWS = 9, COLUMNS = 9, TOTAL = ROWS * COLUMNS;<br />
private JPanel pnlMain = new JPanel(new GridLayout(ROWS, COLUMNS));<br />
private JLabel lblBombCount = new JLabel(MAX_BOMB_COUNT + "");<br />
private JLabel lblTimer = new JLabel("0");<br />
private boolean isColorCheatOn = false;<br />
private JButton btnReset = new JButton("Reset");<br />
<br />
private void startThread() {<br />
Thread th = new Thread(new Runnable() {<br />
public void run() {<br />
while (state == GameState.Playing) {<br />
lblTimer.setText((Long.parseLong(lblTimer.getText()) + 1) + "");<br />
lblTimer.updateUI();<br />
try {<br />
Thread.sleep(1000);<br />
} catch (InterruptedException e) {<br />
e.printStackTrace();<br />
}<br />
}<br />
}<br />
});<br />
th.start();<br />
}<br />
<br />
private GameState state = GameState.NotStarted;<br />
<br />
public MineSweeper() {<br />
setLayout(new BorderLayout());<br />
add(pnlMain, BorderLayout.CENTER);<br />
createButtons();<br />
addControlPanel();<br />
Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK);<br />
}<br />
<br />
private void showAbout() {<br />
JOptionPane.showMessageDialog(this, "<html>Author : Justin Cowles Cowperthwaite <br>Version : 1.0</html>", "About", JOptionPane.INFORMATION_MESSAGE);<br />
}<br />
<br />
private void restartGame() {<br />
state = GameState.NotStarted;<br />
lblTimer.setText("0");<br />
pnlMain.removeAll();<br />
createButtons();<br />
pnlMain.updateUI();<br />
lblBombCount.setText("" + MAX_BOMB_COUNT);<br />
lblBombCount.updateUI();<br />
}<br />
<br />
private void addControlPanel() {<br />
JPanel pnlTimer = new JPanel(new FlowLayout(FlowLayout.RIGHT));<br />
<br />
pnlTimer.add(lblTimer);<br />
<br />
JPanel pnl = new JPanel(new FlowLayout(FlowLayout.CENTER));<br />
<br />
btnReset.setToolTipText("<HTML>Press <B>F2</B> to reset the current game</HTML>");<br />
pnl.add(lblBombCount);<br />
pnl.add(btnReset);<br />
JPanel pnlN = new JPanel(new GridLayout(1, 3));<br />
<br />
pnlN.add(lblBombCount);<br />
pnlN.add(pnl);<br />
pnlN.add(pnlTimer);<br />
add(pnlN, BorderLayout.NORTH);<br />
btnReset.addActionListener(this);<br />
}<br />
<br />
private void createButtons() {<br />
List<Point> lstBombsLocation = new ArrayList<Point>();<br />
<br />
for (int row = 0; row < ROWS; row++) {<br />
for (int col = 0; col < COLUMNS; col++) {<br />
JButton btn = getButton(lstBombsLocation, TOTAL, new Point(row, col) {<br />
@Override<br />
public String toString() {<br />
return (int) getX() + ", " + (int) getY();<br />
}<br />
<br />
@Override<br />
public boolean equals(Object obj) {<br />
return ((Point) obj).getX() == getX() && ((Point) obj).getY() == getY();<br />
}<br />
});<br />
pnlMain.add(btn);<br />
}<br />
}<br />
while (lstBombsLocation.size() < MAX_BOMB_COUNT) {<br />
updateBomds(lstBombsLocation, pnlMain.getComponents());<br />
}<br />
for (Component c : pnlMain.getComponents()) {<br />
updateBombCount((GameButton) c, pnlMain.getComponents());<br />
}<br />
// System.out.println("Total Bomb Count: " + lstBombsLocation.size());<br />
}<br />
<br />
private void updateBomds(List<Point> lstBombsLocation, Component[] components) {<br />
// int currentPosition = new Double(((location.x) * COLUMNS ) +<br />
// location.getY()).intValue();<br />
Random r = new Random();<br />
for (Component c : components) {<br />
Point location = ((GameButton) c).getPosition();<br />
int currentPosition = new Double(((location.x) * COLUMNS) + location.getY()).intValue();<br />
int bombLocation = r.nextInt(TOTAL);<br />
if (bombLocation == currentPosition) {<br />
((GameButton) c).setBomb(true);<br />
lstBombsLocation.add(((GameButton) c).getPosition());<br />
return;<br />
}<br />
}<br />
}<br />
<br />
private GameButton getButton(List<Point> lstBombsLocation, int totalLocations, Point location) {<br />
GameButton btn = new GameButton(location);<br />
btn.setMargin(new Insets(0, 0, 0, 0));<br />
btn.setFocusable(false);<br />
if (lstBombsLocation.size() < MAX_BOMB_COUNT) {<br />
if (isBomb()) {<br />
btn.setBomb(true);<br />
lstBombsLocation.add(location);<br />
}<br />
}<br />
btn.addMouseListener(new MouseAdapter() {<br />
@Override<br />
public void mouseClicked(MouseEvent mouseEvent) {<br />
if (state != GameState.Playing) {<br />
state = GameState.Playing;<br />
startThread();<br />
}<br />
if (((GameButton) mouseEvent.getSource()).isEnabled() == false) {<br />
return;<br />
}<br />
if (mouseEvent.getButton() == MouseEvent.BUTTON1) {<br />
if (((GameButton) mouseEvent.getSource()).getState() == State.Marked) {<br />
((GameButton) mouseEvent.getSource()).setState(State.Initial);<br />
lblBombCount.setText((Long.parseLong(lblBombCount.getText()) + 1) + "");<br />
((GameButton) mouseEvent.getSource()).updateUI();<br />
return;<br />
}<br />
((GameButton) mouseEvent.getSource()).setState(State.Clicked);<br />
if (((GameButton) mouseEvent.getSource()).isBomb()) {<br />
blastBombs();<br />
return;<br />
} else {<br />
if (((GameButton) mouseEvent.getSource()).getBombCount() == 0) {<br />
updateSurroundingZeros(((GameButton) mouseEvent.getSource()).getPosition());<br />
}<br />
}<br />
if (!checkGameState()) {<br />
((GameButton) mouseEvent.getSource()).setEnabled(false);<br />
}<br />
} else if (mouseEvent.getButton() == MouseEvent.BUTTON3) {<br />
if (((GameButton) mouseEvent.getSource()).getState() == State.Marked) {<br />
((GameButton) mouseEvent.getSource()).setState(State.Initial);<br />
lblBombCount.setText((Long.parseLong(lblBombCount.getText()) + 1) + "");<br />
} else {<br />
((GameButton) mouseEvent.getSource()).setState(State.Marked);<br />
lblBombCount.setText((Long.parseLong(lblBombCount.getText()) - 1) + "");<br />
}<br />
}<br />
((GameButton) mouseEvent.getSource()).updateUI();<br />
}<br />
});<br />
return btn;<br />
}<br />
<br />
private boolean checkGameState() {<br />
boolean isWin = false;<br />
for (Component c : pnlMain.getComponents()) {<br />
GameButton b = (GameButton) c;<br />
if (b.getState() != State.Clicked) {<br />
if (b.isBomb()) {<br />
isWin = true;<br />
} else {<br />
return false;<br />
}<br />
}<br />
}<br />
if (isWin) {<br />
state = GameState.Finished;<br />
for (Component c : pnlMain.getComponents()) {<br />
GameButton b = (GameButton) c;<br />
if (b.isBomb()) {<br />
b.setState(State.Marked);<br />
}<br />
b.setEnabled(false);<br />
<br />
}<br />
JOptionPane.showMessageDialog(this, "You win the game :D", "Congrats", JOptionPane.INFORMATION_MESSAGE, null);<br />
}<br />
return isWin;<br />
}<br />
<br />
private void updateSurroundingZeros(Point currentPoint) {<br />
Point[] points = getSurroundings(currentPoint);<br />
<br />
for (Point p : points) {<br />
GameButton b = getButtonAt(pnlMain.getComponents(), p);<br />
if (b != null && b.getBombCount() == 0 && b.getState() != State.Clicked && b.getState() != State.Marked && b.isBomb() == false) {<br />
b.setState(State.Clicked);<br />
updateSurroundingZeros(b.getPosition());<br />
b.updateUI();<br />
}<br />
if (b != null && b.getBombCount() > 0 && b.getState() != State.Clicked && b.getState() != State.Marked && b.isBomb() == false) {<br />
b.setEnabled(false);<br />
b.setState(State.Clicked);<br />
b.updateUI();<br />
}<br />
}<br />
}<br />
<br />
private void blastBombs() {<br />
int blastCount = 0;<br />
for (Component c : pnlMain.getComponents()) {<br />
((GameButton) c).setEnabled(false);<br />
((GameButton) c).transferFocus();<br />
if (((GameButton) c).isBomb() && ((GameButton) c).getState() != State.Marked) {<br />
((GameButton) c).setState(State.Clicked);<br />
((GameButton) c).updateUI();<br />
blastCount++;<br />
}<br />
if (((GameButton) c).isBomb() == false && ((GameButton) c).getState() == State.Marked) {<br />
((GameButton) c).setState(State.WrongMarked);<br />
}<br />
}<br />
lblBombCount.setText("" + blastCount);<br />
lblBombCount.updateUI();<br />
state = GameState.Finished;<br />
JOptionPane.showMessageDialog(this, "You loose the game :(", "Game Over", JOptionPane.ERROR_MESSAGE, null);<br />
for (Component c : pnlMain.getComponents()) {<br />
GameButton b = (GameButton) c;<br />
b.setEnabled(false);<br />
}<br />
}<br />
<br />
private boolean isBomb() {<br />
Random r = new Random();<br />
return r.nextInt(ROWS) == 1;<br />
}<br />
<br />
public static void main(String[] args) {<br />
JFrame fr = new JFrame("MineSweeper");<br />
fr.setLayout(new BorderLayout());<br />
fr.add(new MineSweeper());<br />
fr.setResizable(false);<br />
fr.setSize(250, 350);<br />
fr.setLocationRelativeTo(null);<br />
fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);<br />
fr.setVisible(true);<br />
}<br />
<br />
class GameButton extends JButton {<br />
private boolean isBomb = false;<br />
private Point position = null;<br />
private int bombCount = 0;<br />
private State state = State.Initial;<br />
<br />
public void setState(State state) {<br />
this.state = state;<br />
if (getBombCount() == 0 && !isBomb) {<br />
setEnabled(false);<br />
}<br />
}<br />
<br />
public State getState() {<br />
return state;<br />
}<br />
<br />
public int getBombCount() {<br />
return bombCount;<br />
}<br />
<br />
public void setBombCount(int bombCount) {<br />
this.bombCount = bombCount;<br />
}<br />
<br />
public GameButton(Point position) {<br />
setPosition(position);<br />
setText(position.toString());<br />
}<br />
<br />
public Point getPosition() {<br />
return position;<br />
}<br />
<br />
public void setPosition(Point position) {<br />
this.position = position;<br />
}<br />
<br />
public boolean isBomb() {<br />
return isBomb;<br />
}<br />
<br />
public void setBomb(boolean isBomb) {<br />
this.isBomb = isBomb;<br />
}<br />
<br />
@Override<br />
public String getText() {<br />
if (state == State.Initial) {<br />
return "";<br />
}<br />
if (state == State.Marked) {<br />
return "\u00B6";<br />
}<br />
if (state == State.Clicked) {<br />
if (isBomb) {<br />
return "<html><font size='16'><b>*</b></font></html>";<br />
} else {<br />
if (getBombCount() > 0)<br />
return getBombCount() + "";<br />
else<br />
return "";<br />
}<br />
}<br />
if (state == State.WrongMarked) {<br />
return "X";<br />
}<br />
return super.getText();<br />
}<br />
<br />
@Override<br />
public Color getBackground() {<br />
if (isColorCheatOn && isBomb) {<br />
return Color.MAGENTA;<br />
}<br />
if (state == State.Clicked) {<br />
if (isBomb) {<br />
return Color.RED;<br />
}<br />
if (getBombCount() > 0) {<br />
return Color.GREEN;<br />
}<br />
}<br />
if (isEnabled()) {<br />
return Color.YELLOW.brighter();<br />
} else {<br />
return super.getBackground();<br />
}<br />
}<br />
}<br />
<br />
private Point[] getSurroundings(Point cPoint) {<br />
int cX = (int) cPoint.getX();<br />
int cY = (int) cPoint.getY();<br />
Point[] points = { new Point(cX - 1, cY - 1), new Point(cX - 1, cY), new Point(cX - 1, cY + 1), new Point(cX, cY - 1), new Point(cX, cY + 1), new Point(cX + 1, cY - 1), <br />
new Point(cX + 1, cY), new Point(cX + 1, cY + 1) };<br />
return points;<br />
}<br />
<br />
private void updateBombCount(GameButton btn, Component[] components) {<br />
Point[] points = getSurroundings(btn.getPosition());<br />
<br />
for (Point p : points) {<br />
GameButton b = getButtonAt(components, p);<br />
if (b != null && b.isBomb()) {<br />
btn.setBombCount(btn.getBombCount() + 1);<br />
}<br />
}<br />
btn.setText(btn.getBombCount() + "");<br />
}<br />
<br />
private GameButton getButtonAt(Component[] components, Point position) {<br />
for (Component btn : components) {<br />
if ((((GameButton) btn).getPosition().equals(position))) {<br />
return (GameButton) btn;<br />
}<br />
}<br />
return null;<br />
}<br />
<br />
public void eventDispatched(AWTEvent event) {<br />
if (KeyEvent.class.isInstance(event) && ((KeyEvent) (event)).getID() == KeyEvent.KEY_RELEASED) {<br />
if (((KeyEvent) (event)).getKeyCode() == KeyEvent.VK_F1) {<br />
showAbout();<br />
}<br />
if (((KeyEvent) (event)).getKeyCode() == KeyEvent.VK_F2) {<br />
restartGame();<br />
}<br />
if (((KeyEvent) (event)).getKeyCode() == KeyEvent.VK_F3) {<br />
isColorCheatOn = !isColorCheatOn;<br />
if (state == GameState.Playing) {<br />
pnlMain.updateUI();<br />
}<br />
}<br />
<br />
if (((KeyEvent) (event)).getKeyCode() == KeyEvent.VK_F12) {<br />
for (Component c : pnlMain.getComponents()) {<br />
GameButton b = (GameButton) c;<br />
if (b.isBomb() == false) {<br />
b.setState(State.Clicked);<br />
} else {<br />
b.setState(State.Marked);<br />
}<br />
b.setEnabled(false);<br />
}<br />
checkGameState();<br />
}<br />
}<br />
}<br />
<br />
public void actionPerformed(ActionEvent actionEvent) {<br />
if (actionEvent.getSource() == btnReset) {<br />
restartGame();<br />
}<br />
}<br />
}</pre><br />
<br />
Go back to [[HelloWorld in Java]] and follow the instructions for Exporting and Running a Java Program on the Over COM. When you are done, you should be able to play a 9x10 colorful game of MineSweeper on the monitor connected to your Overo COM expansion board.</div>JustinC474https://wiki.gumstix.com/index.php?title=Minesweeper_in_Java&diff=4399Minesweeper in Java2010-07-29T16:00:15Z<p>JustinC474: Created page with 'This tutorial gives a brief overview of what to do to get a small, graphical Minesweeper game running on your Overo. If you have not done so, please go through the tutorials [[Ec…'</p>
<hr />
<div>This tutorial gives a brief overview of what to do to get a small, graphical Minesweeper game running on your Overo. If you have not done so, please go through the tutorials [[Eclipse on Gumstix for new users]] and [[HelloWorld in Java]].<br />
<br />
*Create a new Project in Eclipse <br />
:*'''File -> New Project -> Java Project'''<br />
*Create a class '''Main Class'''<br />
:*Copy and paste the following code to that class:<br />
<pre> <br />
import java.awt.BorderLayout;<br />
import java.awt.Color;<br />
import java.awt.event.ActionEvent;<br />
import java.awt.event.ActionListener;<br />
<br />
import javax.swing.JButton;<br />
import javax.swing.JColorChooser;<br />
import javax.swing.JFrame;<br />
import javax.swing.JOptionPane;<br />
<br />
public class MainClass {<br />
public static void main(String args[]) {<br />
JFrame f = new JFrame("JColorChooser Sample");<br />
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);<br />
final JButton button = new JButton("Pick to Change Background");<br />
<br />
ActionListener actionListener = new ActionListener() {<br />
public void actionPerformed(ActionEvent actionEvent) {<br />
Color initialBackground = button.getBackground();<br />
Color background = JColorChooser.showDialog(null,<br />
"JColorChooser Sample", initialBackground);<br />
if (background != null) {<br />
button.setBackground(background);<br />
}<br />
}<br />
};<br />
button.addActionListener(actionListener);<br />
f.add(button, BorderLayout.CENTER);<br />
f.setSize(300, 200);<br />
f.setVisible(true);<br />
}<br />
<br />
}</pre><br />
*Create a class '''MineSweeper''' (Capital S!)<br />
:*Copy and paste the following code to that class:<br />
<pre>import java.awt.AWTEvent;<br />
import java.awt.BorderLayout;<br />
import java.awt.Color;<br />
import java.awt.Component;<br />
import java.awt.FlowLayout;<br />
import java.awt.GridLayout;<br />
import java.awt.Insets;<br />
import java.awt.Point;<br />
import java.awt.Toolkit;<br />
import java.awt.event.AWTEventListener;<br />
import java.awt.event.ActionEvent;<br />
import java.awt.event.ActionListener;<br />
import java.awt.event.KeyEvent;<br />
import java.awt.event.MouseAdapter;<br />
import java.awt.event.MouseEvent;<br />
import java.util.ArrayList;<br />
import java.util.List;<br />
import java.util.Random;<br />
<br />
import javax.swing.JButton;<br />
import javax.swing.JFrame;<br />
import javax.swing.JLabel;<br />
import javax.swing.JOptionPane;<br />
import javax.swing.JPanel;<br />
<br />
public class MineSweeper extends JPanel implements AWTEventListener, ActionListener {<br />
<br />
public static enum State {<br />
Clicked, Marked, Initial, WrongMarked<br />
}<br />
<br />
public static enum GameState {<br />
NotStarted, Playing, Finished<br />
}<br />
<br />
private static final int MAX_BOMB_COUNT = 10;<br />
private int ROWS = 9, COLUMNS = 9, TOTAL = ROWS * COLUMNS;<br />
private JPanel pnlMain = new JPanel(new GridLayout(ROWS, COLUMNS));<br />
private JLabel lblBombCount = new JLabel(MAX_BOMB_COUNT + "");<br />
private JLabel lblTimer = new JLabel("0");<br />
private boolean isColorCheatOn = false;<br />
private JButton btnReset = new JButton("Reset");<br />
<br />
private void startThread() {<br />
Thread th = new Thread(new Runnable() {<br />
public void run() {<br />
while (state == GameState.Playing) {<br />
lblTimer.setText((Long.parseLong(lblTimer.getText()) + 1) + "");<br />
lblTimer.updateUI();<br />
try {<br />
Thread.sleep(1000);<br />
} catch (InterruptedException e) {<br />
e.printStackTrace();<br />
}<br />
}<br />
}<br />
});<br />
th.start();<br />
}<br />
<br />
private GameState state = GameState.NotStarted;<br />
<br />
public MineSweeper() {<br />
setLayout(new BorderLayout());<br />
add(pnlMain, BorderLayout.CENTER);<br />
createButtons();<br />
addControlPanel();<br />
Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK);<br />
}<br />
<br />
private void showAbout() {<br />
JOptionPane.showMessageDialog(this, "<html>Author : Justin Cowles Cowperthwaite <br>Version : 1.0</html>", "About", JOptionPane.INFORMATION_MESSAGE);<br />
}<br />
<br />
private void restartGame() {<br />
state = GameState.NotStarted;<br />
lblTimer.setText("0");<br />
pnlMain.removeAll();<br />
createButtons();<br />
pnlMain.updateUI();<br />
lblBombCount.setText("" + MAX_BOMB_COUNT);<br />
lblBombCount.updateUI();<br />
}<br />
<br />
private void addControlPanel() {<br />
JPanel pnlTimer = new JPanel(new FlowLayout(FlowLayout.RIGHT));<br />
<br />
pnlTimer.add(lblTimer);<br />
<br />
JPanel pnl = new JPanel(new FlowLayout(FlowLayout.CENTER));<br />
<br />
btnReset.setToolTipText("<HTML>Press <B>F2</B> to reset the current game</HTML>");<br />
pnl.add(lblBombCount);<br />
pnl.add(btnReset);<br />
JPanel pnlN = new JPanel(new GridLayout(1, 3));<br />
<br />
pnlN.add(lblBombCount);<br />
pnlN.add(pnl);<br />
pnlN.add(pnlTimer);<br />
add(pnlN, BorderLayout.NORTH);<br />
btnReset.addActionListener(this);<br />
}<br />
<br />
private void createButtons() {<br />
List<Point> lstBombsLocation = new ArrayList<Point>();<br />
<br />
for (int row = 0; row < ROWS; row++) {<br />
for (int col = 0; col < COLUMNS; col++) {<br />
JButton btn = getButton(lstBombsLocation, TOTAL, new Point(row, col) {<br />
@Override<br />
public String toString() {<br />
return (int) getX() + ", " + (int) getY();<br />
}<br />
<br />
@Override<br />
public boolean equals(Object obj) {<br />
return ((Point) obj).getX() == getX() && ((Point) obj).getY() == getY();<br />
}<br />
});<br />
pnlMain.add(btn);<br />
}<br />
}<br />
while (lstBombsLocation.size() < MAX_BOMB_COUNT) {<br />
updateBomds(lstBombsLocation, pnlMain.getComponents());<br />
}<br />
for (Component c : pnlMain.getComponents()) {<br />
updateBombCount((GameButton) c, pnlMain.getComponents());<br />
}<br />
// System.out.println("Total Bomb Count: " + lstBombsLocation.size());<br />
}<br />
<br />
private void updateBomds(List<Point> lstBombsLocation, Component[] components) {<br />
// int currentPosition = new Double(((location.x) * COLUMNS ) +<br />
// location.getY()).intValue();<br />
Random r = new Random();<br />
for (Component c : components) {<br />
Point location = ((GameButton) c).getPosition();<br />
int currentPosition = new Double(((location.x) * COLUMNS) + location.getY()).intValue();<br />
int bombLocation = r.nextInt(TOTAL);<br />
if (bombLocation == currentPosition) {<br />
((GameButton) c).setBomb(true);<br />
lstBombsLocation.add(((GameButton) c).getPosition());<br />
return;<br />
}<br />
}<br />
}<br />
<br />
private GameButton getButton(List<Point> lstBombsLocation, int totalLocations, Point location) {<br />
GameButton btn = new GameButton(location);<br />
btn.setMargin(new Insets(0, 0, 0, 0));<br />
btn.setFocusable(false);<br />
if (lstBombsLocation.size() < MAX_BOMB_COUNT) {<br />
if (isBomb()) {<br />
btn.setBomb(true);<br />
lstBombsLocation.add(location);<br />
}<br />
}<br />
btn.addMouseListener(new MouseAdapter() {<br />
@Override<br />
public void mouseClicked(MouseEvent mouseEvent) {<br />
if (state != GameState.Playing) {<br />
state = GameState.Playing;<br />
startThread();<br />
}<br />
if (((GameButton) mouseEvent.getSource()).isEnabled() == false) {<br />
return;<br />
}<br />
if (mouseEvent.getButton() == MouseEvent.BUTTON1) {<br />
if (((GameButton) mouseEvent.getSource()).getState() == State.Marked) {<br />
((GameButton) mouseEvent.getSource()).setState(State.Initial);<br />
lblBombCount.setText((Long.parseLong(lblBombCount.getText()) + 1) + "");<br />
((GameButton) mouseEvent.getSource()).updateUI();<br />
return;<br />
}<br />
((GameButton) mouseEvent.getSource()).setState(State.Clicked);<br />
if (((GameButton) mouseEvent.getSource()).isBomb()) {<br />
blastBombs();<br />
return;<br />
} else {<br />
if (((GameButton) mouseEvent.getSource()).getBombCount() == 0) {<br />
updateSurroundingZeros(((GameButton) mouseEvent.getSource()).getPosition());<br />
}<br />
}<br />
if (!checkGameState()) {<br />
((GameButton) mouseEvent.getSource()).setEnabled(false);<br />
}<br />
} else if (mouseEvent.getButton() == MouseEvent.BUTTON3) {<br />
if (((GameButton) mouseEvent.getSource()).getState() == State.Marked) {<br />
((GameButton) mouseEvent.getSource()).setState(State.Initial);<br />
lblBombCount.setText((Long.parseLong(lblBombCount.getText()) + 1) + "");<br />
} else {<br />
((GameButton) mouseEvent.getSource()).setState(State.Marked);<br />
lblBombCount.setText((Long.parseLong(lblBombCount.getText()) - 1) + "");<br />
}<br />
}<br />
((GameButton) mouseEvent.getSource()).updateUI();<br />
}<br />
});<br />
return btn;<br />
}<br />
<br />
private boolean checkGameState() {<br />
boolean isWin = false;<br />
for (Component c : pnlMain.getComponents()) {<br />
GameButton b = (GameButton) c;<br />
if (b.getState() != State.Clicked) {<br />
if (b.isBomb()) {<br />
isWin = true;<br />
} else {<br />
return false;<br />
}<br />
}<br />
}<br />
if (isWin) {<br />
state = GameState.Finished;<br />
for (Component c : pnlMain.getComponents()) {<br />
GameButton b = (GameButton) c;<br />
if (b.isBomb()) {<br />
b.setState(State.Marked);<br />
}<br />
b.setEnabled(false);<br />
<br />
}<br />
JOptionPane.showMessageDialog(this, "You win the game :D", "Congrats", JOptionPane.INFORMATION_MESSAGE, null);<br />
}<br />
return isWin;<br />
}<br />
<br />
private void updateSurroundingZeros(Point currentPoint) {<br />
Point[] points = getSurroundings(currentPoint);<br />
<br />
for (Point p : points) {<br />
GameButton b = getButtonAt(pnlMain.getComponents(), p);<br />
if (b != null && b.getBombCount() == 0 && b.getState() != State.Clicked && b.getState() != State.Marked && b.isBomb() == false) {<br />
b.setState(State.Clicked);<br />
updateSurroundingZeros(b.getPosition());<br />
b.updateUI();<br />
}<br />
if (b != null && b.getBombCount() > 0 && b.getState() != State.Clicked && b.getState() != State.Marked && b.isBomb() == false) {<br />
b.setEnabled(false);<br />
b.setState(State.Clicked);<br />
b.updateUI();<br />
}<br />
}<br />
}<br />
<br />
private void blastBombs() {<br />
int blastCount = 0;<br />
for (Component c : pnlMain.getComponents()) {<br />
((GameButton) c).setEnabled(false);<br />
((GameButton) c).transferFocus();<br />
if (((GameButton) c).isBomb() && ((GameButton) c).getState() != State.Marked) {<br />
((GameButton) c).setState(State.Clicked);<br />
((GameButton) c).updateUI();<br />
blastCount++;<br />
}<br />
if (((GameButton) c).isBomb() == false && ((GameButton) c).getState() == State.Marked) {<br />
((GameButton) c).setState(State.WrongMarked);<br />
}<br />
}<br />
lblBombCount.setText("" + blastCount);<br />
lblBombCount.updateUI();<br />
state = GameState.Finished;<br />
JOptionPane.showMessageDialog(this, "You loose the game :(", "Game Over", JOptionPane.ERROR_MESSAGE, null);<br />
for (Component c : pnlMain.getComponents()) {<br />
GameButton b = (GameButton) c;<br />
b.setEnabled(false);<br />
}<br />
}<br />
<br />
private boolean isBomb() {<br />
Random r = new Random();<br />
return r.nextInt(ROWS) == 1;<br />
}<br />
<br />
public static void main(String[] args) {<br />
JFrame fr = new JFrame("MineSweeper");<br />
fr.setLayout(new BorderLayout());<br />
fr.add(new MineSweeper());<br />
fr.setResizable(false);<br />
fr.setSize(250, 350);<br />
fr.setLocationRelativeTo(null);<br />
fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);<br />
fr.setVisible(true);<br />
}<br />
<br />
class GameButton extends JButton {<br />
private boolean isBomb = false;<br />
private Point position = null;<br />
private int bombCount = 0;<br />
private State state = State.Initial;<br />
<br />
public void setState(State state) {<br />
this.state = state;<br />
if (getBombCount() == 0 && !isBomb) {<br />
setEnabled(false);<br />
}<br />
}<br />
<br />
public State getState() {<br />
return state;<br />
}<br />
<br />
public int getBombCount() {<br />
return bombCount;<br />
}<br />
<br />
public void setBombCount(int bombCount) {<br />
this.bombCount = bombCount;<br />
}<br />
<br />
public GameButton(Point position) {<br />
setPosition(position);<br />
setText(position.toString());<br />
}<br />
<br />
public Point getPosition() {<br />
return position;<br />
}<br />
<br />
public void setPosition(Point position) {<br />
this.position = position;<br />
}<br />
<br />
public boolean isBomb() {<br />
return isBomb;<br />
}<br />
<br />
public void setBomb(boolean isBomb) {<br />
this.isBomb = isBomb;<br />
}<br />
<br />
@Override<br />
public String getText() {<br />
if (state == State.Initial) {<br />
return "";<br />
}<br />
if (state == State.Marked) {<br />
return "\u00B6";<br />
}<br />
if (state == State.Clicked) {<br />
if (isBomb) {<br />
return "<html><font size='16'><b>*</b></font></html>";<br />
} else {<br />
if (getBombCount() > 0)<br />
return getBombCount() + "";<br />
else<br />
return "";<br />
}<br />
}<br />
if (state == State.WrongMarked) {<br />
return "X";<br />
}<br />
return super.getText();<br />
}<br />
<br />
@Override<br />
public Color getBackground() {<br />
if (isColorCheatOn && isBomb) {<br />
return Color.MAGENTA;<br />
}<br />
if (state == State.Clicked) {<br />
if (isBomb) {<br />
return Color.RED;<br />
}<br />
if (getBombCount() > 0) {<br />
return Color.GREEN;<br />
}<br />
}<br />
if (isEnabled()) {<br />
return Color.YELLOW.brighter();<br />
} else {<br />
return super.getBackground();<br />
}<br />
}<br />
}<br />
<br />
private Point[] getSurroundings(Point cPoint) {<br />
int cX = (int) cPoint.getX();<br />
int cY = (int) cPoint.getY();<br />
Point[] points = { new Point(cX - 1, cY - 1), new Point(cX - 1, cY), new Point(cX - 1, cY + 1), new Point(cX, cY - 1), new Point(cX, cY + 1), new Point(cX + 1, cY - 1), new Point(cX + 1, cY), new Point(cX + 1, cY + 1) };<br />
return points;<br />
}<br />
<br />
private void updateBombCount(GameButton btn, Component[] components) {<br />
Point[] points = getSurroundings(btn.getPosition());<br />
<br />
for (Point p : points) {<br />
GameButton b = getButtonAt(components, p);<br />
if (b != null && b.isBomb()) {<br />
btn.setBombCount(btn.getBombCount() + 1);<br />
}<br />
}<br />
btn.setText(btn.getBombCount() + "");<br />
}<br />
<br />
private GameButton getButtonAt(Component[] components, Point position) {<br />
for (Component btn : components) {<br />
if ((((GameButton) btn).getPosition().equals(position))) {<br />
return (GameButton) btn;<br />
}<br />
}<br />
return null;<br />
}<br />
<br />
public void eventDispatched(AWTEvent event) {<br />
if (KeyEvent.class.isInstance(event) && ((KeyEvent) (event)).getID() == KeyEvent.KEY_RELEASED) {<br />
if (((KeyEvent) (event)).getKeyCode() == KeyEvent.VK_F1) {<br />
showAbout();<br />
}<br />
if (((KeyEvent) (event)).getKeyCode() == KeyEvent.VK_F2) {<br />
restartGame();<br />
}<br />
if (((KeyEvent) (event)).getKeyCode() == KeyEvent.VK_F3) {<br />
isColorCheatOn = !isColorCheatOn;<br />
if (state == GameState.Playing) {<br />
pnlMain.updateUI();<br />
}<br />
}<br />
<br />
if (((KeyEvent) (event)).getKeyCode() == KeyEvent.VK_F12) {<br />
for (Component c : pnlMain.getComponents()) {<br />
GameButton b = (GameButton) c;<br />
if (b.isBomb() == false) {<br />
b.setState(State.Clicked);<br />
} else {<br />
b.setState(State.Marked);<br />
}<br />
b.setEnabled(false);<br />
}<br />
checkGameState();<br />
}<br />
}<br />
}<br />
<br />
public void actionPerformed(ActionEvent actionEvent) {<br />
if (actionEvent.getSource() == btnReset) {<br />
restartGame();<br />
}<br />
}<br />
}</pre><br />
<br />
Go back to [[HelloWorld in Java]] and follow the instructions for Exporting and Running a Java Program on the Over COM. When you are done, you should be able to play a 9x10 colorful game of MineSweeper on the monitor connected to your Overo COM expansion board.</div>JustinC474