tag:blogger.com,1999:blog-14278154393616461472024-02-19T04:55:48.171-08:00man hackinghacking hardware, software, and stuff in life at largeUnknownnoreply@blogger.comBlogger11125tag:blogger.com,1999:blog-1427815439361646147.post-33018676395988365302014-08-27T17:36:00.000-07:002014-11-29T19:47:49.644-08:00Chuck Norris-ing a .pkg installer into submission (Updated 28-11-2014)<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg552VhPNKsPO4WvA-QN6Rl9B4oAS4vo81VotItgMJCLUbFQnWNCQ2QBnA8THMucj686Jnz4RANl_5rXs90q327-cY2W5F5fBDnKiDM33XhNVWHNNuVAGTmw9kz-B6BHq-kM9D4BLdtrH4/s1600/metapackage+copy.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg552VhPNKsPO4WvA-QN6Rl9B4oAS4vo81VotItgMJCLUbFQnWNCQ2QBnA8THMucj686Jnz4RANl_5rXs90q327-cY2W5F5fBDnKiDM33XhNVWHNNuVAGTmw9kz-B6BHq-kM9D4BLdtrH4/s1600/metapackage+copy.png" height="320" width="320" /></a>Or: How to install Legacy Mac OS X SDKs for Xcode<br />
<br />
As you explore open-source Mac software, you will eventually have to build for older versions of OS X.<br />
<br />
But you will need older OS X SDKs.<br />
<br />
The solution? Roundhouse-kick an old, defenseless Xcode installer into a bloody mess, of course! Then you can find all its subinstallers—including the legacy SDKs!<br />
<a name='more'></a><br />
<br />
The easy way is to use <a href="https://www.charlessoft.com/">Pacifist</a> (shareware $20), which is a great piece of software designed to do exactly this sort of thing. If the Terminal scares you, I highly recommend it!<br />
<br />
But, if you are a Terminal junkie, here is how I added the SDKs for 10.6 and 10.7, using only free software. The technique can really be applied to any .pkg installer.<br />
<h3>
Mac OS X 10.6 and 10.7 SDKs</h3>
<ol>
<li>Download "Xcode 4.2.1 for Lion" from <a href="https://developer.apple.com/downloads">https://developer.apple.com/downloads</a> and mount the disk image.</li>
<li>Now switch to the Terminal. From now on, commands inline with the paragraph text are optional and commands indented in code blocks are required.<br /><br />If you run <span class="code">file /Volumes/Install\ Xcode/InstallXcodeLion.pkg</span>, you will see that the installer is a xar archive. To unpack it, run <div class="code">
<pre>cd ~/Desktop
mkdir Xcode421
cd Xcode421
xar -xf /Volumes/Install\ Xcode/InstallXcodeLion.pkg</pre>
</div>
</li>
<li>Now, run <div class="code">
<pre>cd InstallXcodeLion.pkg</pre>
</div>
</li>
<li>Running <span class="code">ls -lh</span> shows that Payload is the largest file. If we again run <span class="code">file Payload</span>, we see that we have a gzip archive, which is in fact a tarball. Unpack it with <div class="code">
<pre>mv Payload{,.tar.gz}
tar -xf Payload.tar.gz</pre>
</div>
</li>
<li>Now run <div class="code">
<pre>open Applications/Install\ Xcode.app/Contents/Resources/Packages</pre>
</div>
You will see a Finder window with all the sub-installers for Xcode. Score!</li>
<li>Run MacOSX10.7.pkg, MacOSX10.6.pkg, then MacOSX10.6.Patch1.pkg from the Finder. (Hint: If you keep a previously-authenticated installer open after it completes, you can run the next installer without a password.) <br />
<br />
(Updated 28-11-2014:) If the system complains about the .pkg being from an unrecognized developer, you can open it anyway by right-clicking, and selecting open. This will give a different warning dialog, in which you have an "Open" button.</li>
<li>Back in the Terminal, run <div class="code">
<pre>cd /Applications/Xcode.app/Contents/Developer/Platforms/
sudo mv /SDKs/*.sdk MacOSX.platform/Developer/SDKs/</pre>
</div>
If it takes a while, you can hit ctrl-T to see the progress. That sends a SIGINFO signal to the frontmost process, which causes it to show what's happening.
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuM_AhuXafW_5GmbPqzcaXX7cbEKwOoFZsugjAKXynWD7p_ss8qRYCNrzG-ivOF-9m44vAaXSgBBKBgu_6TdWgy2lIfgpI0fGpbRyMcsEAhXGzf9k41wVKp_Mv9EZVk-zwlvmnf-lvlJU/s1600/Screen+Shot+2014-08-27+at+5.18.24+PM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuM_AhuXafW_5GmbPqzcaXX7cbEKwOoFZsugjAKXynWD7p_ss8qRYCNrzG-ivOF-9m44vAaXSgBBKBgu_6TdWgy2lIfgpI0fGpbRyMcsEAhXGzf9k41wVKp_Mv9EZVk-zwlvmnf-lvlJU/s1600/Screen+Shot+2014-08-27+at+5.18.24+PM.png" height="211" width="640" /></a></div>
</li>
</ol>
<div class="separator" style="clear: both; text-align: center;">
</div>
And finished! If you try configuring a project to build in Xcode using the new SDKs, keep in mind that you may need to build for 32-bit architecture only.
<br />
<h3>
Mac OS X 10.5 SDK</h3>
The older installers are a bit simpler. I think that this is because they didn't need to be packaged for the App Store like the new ones. Without further ado, we'll Chuck Norris this one too!<br />
<ol>
<li>Download "Xcode 3.2.6 and iOS SDK 4.3 for Snow Leopard" from <a href="https://developer.apple.com/downloads">https://developer.apple.com/downloads</a> and mount the disk image.</li>
<li>Still in the Finder, with the window for the disk image in the front, hit Cmd-Shift-G and type "Packages" in the box.</li>
<li>Double-click and install MacOSX10.5.pkg.</li>
<li>In the Terminal, run <div class="code">
<pre>cd /Applications/Xcode.app/Contents/Developer/Platforms/
sudo mv /SDKs/MacOSX10.5.sdk MacOSX.platform/Developer/SDKs/</pre>
</div>
</li>
</ol>
<h3>
Bonus: Hiding and un-hiding files</h3>
That was pretty sneaky of Apple, hiding the Packages folder like that. If you want to be able to do that too, add these lines to your .bashrc: <br />
<div class="code">
<pre>alias hide='sudo chflags hidden'
alias unhide='sudo chflags nohidden'</pre>
</div>
And again, happy hacking!
<br />
<h3>
PS: Older .pkgs (added 28-11-2014):</h3>
For even older SDKs, the installer might get in your way, since your system is too new. The answer is to Chuck Norris it some more.
<br />
<ol>
<li>Copy the .pkg to a writeable location.</li>
<li>Right-click and open the package contents.</li>
<li>Go to Contents/Resources.</li>
<li>Move VolumeCheck to the Trash.</li>
<li>Right-click on the .pkg, and click Open. This lets you open it despite the package not being signed.</li>
</ol>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1427815439361646147.post-46285910690464054062014-02-13T02:57:00.001-08:002014-08-27T17:46:27.301-07:00Fixing a broken medium-current power brick<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Some time ago, I bought a 7-port USB hub from Plugable, and it came with a pretty decent power supply. Most cheap hubs provide a correspondingly cheap wall-wart which will only give half an amp of current. But this one from Plugable was a proper beast that gave me 4 whole amps of current! Wow! Until it broke after 6 months of use.</div>
<br />
Plugable was really on the ball, and immediately sent me a new power supply. So props to them. But I was curious about what went wrong in the faulty supply, so I popped it open. Here are the pics:<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEguWehQ7QuoGZQOnBQ0DbvSYTz81INe9OI6DTMzm8r5PVPy7E2A69mfwOXbdJdDrYAtFOv5-r8UpAwXoOTpFNl5wc1qt_glEyw8h0nI3OVgOQbj0PgBeW1KYk6svDap3lOYtTuyncBuZFs/s1600/IMG_0653.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEguWehQ7QuoGZQOnBQ0DbvSYTz81INe9OI6DTMzm8r5PVPy7E2A69mfwOXbdJdDrYAtFOv5-r8UpAwXoOTpFNl5wc1qt_glEyw8h0nI3OVgOQbj0PgBeW1KYk6svDap3lOYtTuyncBuZFs/s1600/IMG_0653.JPG" height="240" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">On the operating table.</td></tr>
</tbody></table>
<br />
<a name='more'></a><br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPQlJ0GxCYaZjor87CHKdC8vtFEpd6rrApQDF4uXxLNTxeOuIvfooIEdezpf-3Dw0jCmDu_my5O3Z7RZKw-Al1YM7bpS74Oa5YzheJLV1Gyo-ws0p2vLnSPbn9ZTZRLu0FM10ocyNU4o8/s1600/IMG_0654.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPQlJ0GxCYaZjor87CHKdC8vtFEpd6rrApQDF4uXxLNTxeOuIvfooIEdezpf-3Dw0jCmDu_my5O3Z7RZKw-Al1YM7bpS74Oa5YzheJLV1Gyo-ws0p2vLnSPbn9ZTZRLu0FM10ocyNU4o8/s1600/IMG_0654.jpg" height="320" width="240" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Lightly tapping with a hammer and a<br />
small flathead driver on the seam<br />
broke open the case with minimal<br />
damage.</td></tr>
</tbody></table>
I think that the seams were ultrasonically welded, because the halves were joined continuously, all around. I think it's really cool that we can seal plastic with sound; I wonder what frequency they use?<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh0jT9gS3zOk9eSklXXG_6cpM_ZsFX36YVQTpGc4_HVrfz-_aM6YCRr-TBdaSGTAJHj751RdPqqSlLMmi-ksfB-wmuk117LddcWB5W0YXA4sjaHSr875L33TIGqisjTzIfo7kx0NRq0qdI/s1600/IMG_0657.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh0jT9gS3zOk9eSklXXG_6cpM_ZsFX36YVQTpGc4_HVrfz-_aM6YCRr-TBdaSGTAJHj751RdPqqSlLMmi-ksfB-wmuk117LddcWB5W0YXA4sjaHSr875L33TIGqisjTzIfo7kx0NRq0qdI/s1600/IMG_0657.jpg" height="320" width="240" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Checking the caps. Nice shielding!<br />
I approve.</td></tr>
</tbody></table>
<div>
The first thing I checked after popping it open were the capacitors, which will leak if they are used at too high temperatures or at too high voltages. They all seemed fine, and none of them were swollen. No burn marks anywhere.<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1jht8f2E106pWMapl-mypLVrCa-ldAnPMFv3b6vkafI0lVA-P-7bWLRf5b9qO7JcqE7ic5qaEa5IcK5mgykAzDl62o75YaDRIXDQgH7-khj7fVI3nSefo0O-ZSbtouuSp6fgjDaDgjC4/s1600/IMG_0656.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto; text-align: center;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1jht8f2E106pWMapl-mypLVrCa-ldAnPMFv3b6vkafI0lVA-P-7bWLRf5b9qO7JcqE7ic5qaEa5IcK5mgykAzDl62o75YaDRIXDQgH7-khj7fVI3nSefo0O-ZSbtouuSp6fgjDaDgjC4/s1600/IMG_0656.jpg" height="320" width="240" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">On the copper side.</td></tr>
</tbody></table>
<div>
</div>
<div>
The next suspect was a broken connection somewhere, probably due to thermal stress. (I was there when the power brick stopped working, and it was completely still, so there was no mechanical shock.) After a little while, I found this:</div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjyEKDsZsVzjDKibMIy5lMDsGlRa7FsqoY53NGp1UUL3s29MxQGxUc-SxffKZfM_FgPIb93QzdDyJvNwhMOLUMSBgxhudE6l35xZPg2xcAvmiLkC5IXLcTwXMVPSK2ibdV0QUOwLF8T4BA/s1600/IMG_0655.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjyEKDsZsVzjDKibMIy5lMDsGlRa7FsqoY53NGp1UUL3s29MxQGxUc-SxffKZfM_FgPIb93QzdDyJvNwhMOLUMSBgxhudE6l35xZPg2xcAvmiLkC5IXLcTwXMVPSK2ibdV0QUOwLF8T4BA/s1600/IMG_0655.jpg" height="640" width="480" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Can you find the lifted pad?</td></tr>
</tbody></table>
<div class="separator" style="clear: both; text-align: left;">
It looks like the thermal stress popped a pad off the board and broke its connection. Would reconnecting it fix the problem? I desoldered the lifted pad and cleaned the component lead with my solder sucker. Then I clinched the lead in the direction of the trace and soldered it to a nearby component which it used to be connected to:</div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiUzdjRN-8Hmo6y3AG7iNVNpSmUDaSA9Y68ZcaCJKkfZwKD49KWo9gy692V7GYlsE2hGFpR6KfW_EJoMpl7A6v4ZwCkNXTn_XuEPjNMMc-jGpfKz6tGQI3fHi0neF8swtPyBT31zLXG1G4/s1600/IMG_0658.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiUzdjRN-8Hmo6y3AG7iNVNpSmUDaSA9Y68ZcaCJKkfZwKD49KWo9gy692V7GYlsE2hGFpR6KfW_EJoMpl7A6v4ZwCkNXTn_XuEPjNMMc-jGpfKz6tGQI3fHi0neF8swtPyBT31zLXG1G4/s1600/IMG_0658.jpg" height="320" width="240" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">The fix. Look at the top of R12, where a<br />
solder bridge reconnects the component.</td></tr>
</tbody></table>
I buttoned up the enclosure without glue just in case it didn't work to test it. And it passed the smoke test! The hub was powered as if nothing had happened! SUCCESS!!</div>
<div>
<br /></div>
<div>
I then dabbed a bit with my hot glue gun to make a more permanent seal, and now I have a nice 5V@4A power brick!</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLl0HFI6VWkCnljcbRYzsp01le47isX0-M4SRxbpJW8jyqfyI2Ve5uB5pnrTMK-5q8qqbJjpjohsXHZXuGgEr0UoFzZb4JvDWmEWDatHPYHZp0lSqmn8FKqKenVxm1Qv0Y2Mzfw_v_syI/s1600/IMG_0659.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLl0HFI6VWkCnljcbRYzsp01le47isX0-M4SRxbpJW8jyqfyI2Ve5uB5pnrTMK-5q8qqbJjpjohsXHZXuGgEr0UoFzZb4JvDWmEWDatHPYHZp0lSqmn8FKqKenVxm1Qv0Y2Mzfw_v_syI/s1600/IMG_0659.jpg" height="320" width="240" /></a></div>
<div>
<br />
<div class="separator" style="clear: both; text-align: left;">
Plugable's replacement power brick came soon after and I switched to that one. I sent my diagnosis and repair pics to them, and they said that they would forward it on to their engineering team. Great!</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
I think that this illustrates how important it is to seat components properly on the board, and avoid stressing them at all during the initial assembly process. Thermal changes during operation will only make the stress worse and weaken the connections. Also, if you can, try to use a through-plated double-sided circuit board, since the through-plating helps lock pads to the substrate and mechanically reinforces the traces. These tips can help you avoid a circuit failure like this power brick.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
That's all till next time! And Plugable's service and gadgets are great - check them out!</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
EDIT (02/15/2014): Featured on <a href="http://hackaday.com/2014/02/14/troubleshooting-a-broken-power-supply/">Hackaday</a>!</div>
</div>
Unknownnoreply@blogger.com2tag:blogger.com,1999:blog-1427815439361646147.post-66982170382090244742013-07-12T02:46:00.000-07:002014-08-27T17:46:40.688-07:00Reading the Microsoft Word docx file format<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGRCUAk8Zal87HB0fZVnvcMpOwqhYWoUpujNN-MySmpQHhZAwqPQ3deoxjum7wyZPX-eqeBT37YIxK4xrtY0MvABgF-mmB7TxnDxIDGKtiud4BniVP2z_HTFOuXok6Py2TFWMemqGoIo0/s1600/Screen+Shot+2013-07-12+at+2.48.03+AM.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGRCUAk8Zal87HB0fZVnvcMpOwqhYWoUpujNN-MySmpQHhZAwqPQ3deoxjum7wyZPX-eqeBT37YIxK4xrtY0MvABgF-mmB7TxnDxIDGKtiud4BniVP2z_HTFOuXok6Py2TFWMemqGoIo0/s200/Screen+Shot+2013-07-12+at+2.48.03+AM.png" height="174" width="200" /></a></div>
After having done some programming to read Microsoft Word files, I thought I'd write about how the Word 2007 or Office Open XML file format is put together. This isn't complete, but this will get you started.<br />
<h3>
Cracking the door open</h3>
When investigating a mystery file, the first thing a Unix junkie does is run <span class="code">file</span> on it. file is a nifty program that will try to identify what sort of data it's looking at, without paying any attention to the file extension. Let's do that now:<br />
<div class="code" style="color: #99cc99;">
<pre>$ <b style="color: white;">ls</b>
Lecture 1.docx
$ <b style="color: white;">file Lecture\ 1.docx</b>
Lecture 1.docx: Zip archive data, at least v2.0 to extract
</pre>
<pre><a name='more'></a>
</pre>
</div>
That's cool. It's really a zip archive! Let's unzip it:<br />
<div class="code" style="color: #99cc99;">
<pre>$ <b style="color: white;">mkdir data</b>
$ <b style="color: white;">cd data</b>
$ <b style="color: white;">unzip ../Lecture\ 1.docx</b>
Archive: ../Lecture 1.docx
inflating: [Content_Types].xml
inflating: _rels/.rels
inflating: word/_rels/document.xml.rels
inflating: word/document.xml
inflating: word/footnotes.xml
inflating: word/endnotes.xml
inflating: word/header1.xml
inflating: word/theme/theme1.xml
extracting: docProps/thumbnail.jpeg
inflating: word/settings.xml
inflating: word/fontTable.xml
inflating: word/styles.xml
inflating: word/stylesWithEffects.xml
inflating: docProps/app.xml
inflating: docProps/core.xml
inflating: word/webSettings.xml
inflating: word/numbering.xml
$ <b style="color: white;">ls -F</b>
[Content_Types].xml _rels/ docProps/ word/
</pre>
</div>
<h3>
Delve deeper and deeper, for all is in it</h3>
Alright! Now we are getting somewhere. The most important directory is the word directory, so I'll cd there:<br />
<div class="code" style="color: #99cc99;">
<pre>$ <b style="color: white;">cd word</b>
$ <b style="color: white;">ls -F</b>
_rels/ footnotes.xml styles.xml
document.xml header1.xml stylesWithEffects.xml
endnotes.xml numbering.xml theme/
fontTable.xml settings.xml webSettings.xml
</pre>
</div>
There are a bunch of useful files here. Some highlights:<br />
<dl>
<dt>document.xml</dt>
<dd>Contains the text of the document. In my case, it also holds the audio notes I recorded during the lecture.</dd>
<dt>media/</dt>
<dd>This folder may or may not be present, depending on whether you have inserted any pictures. Yep. They're stored here.</dd>
<dt>numbering.xml</dt>
<dd>Tells Word how to indent and number or bullet any auto-lists you might have. Also, tells it how to number or bullet any lists you don't have. To 8 levels of indentation. Yeah.</dd>
<dt>_rels/document.xml.rels</dt>
<dd>If you have hyperlinks or embedded pictures, the hyperlink URLs and internal paths to the pictures are here.</dd>
<dt>styles.xml</dt>
<dd>Contains info about default font face and size in the document. If you are one of the few people that bother to use Styles in Word instead of manually choosing fonts and colors, that info is here too.</dd>
</dl>
<h3>
Rubber Ducky, you're the one... You make bath time so much fun...</h3>
If we open one of these files up, it's going to look nasty: all the tags are smooshed together. Use your favorite text editor to tidy it with pretty indents and line breaks. Since I'm using <a href="http://www.vim.org/">vim</a> and I have <a href="http://www.xmlsoft.org/downloads.html">xmllint</a>, I added this key mapping to my .vimrc:<br />
<div class="code">
<pre><span style="color: #9999ff;">map</span> <span style="color: magenta;">,x</span> :silent <span style="color: orange;">1,$</span>!xmllint --format --recover - <span style="color: orange;">2</span>><span style="color: #99cc99;">/dev/null</span> <span style="color: magenta;"><CR></span>
</pre>
</div>
The lone dash after --recover is important! That lets it know to use standard input.<br />
To invoke the command, I get out of edit mode and press the comma and x in sequence. Works great! (Or so I thought, until I fed it my monster document.xml with 17MB of embedded audio data. More on that later. You probably won't have a 17 MB xml document, though.)<br />
If you don't have xmllint, you can get it on most Linux systems with:<br />
<div class="code" style="color: #99cc99;">
<pre>$ <b style="color: white;">sudo apt-get install libxml2-utils</b>
</pre>
</div>
If you decide to modify things and zip it up into a docx again, Microsoft Word won't care about the new whitespace. It'll read the document just fine, then cheerfully obliterate the indents and newlines when saving again.<br />
<h3>
OOXML in a nutshell</h3>
For most programs reading OOXML (<a href="http://en.wikipedia.org/wiki/Office_Open_XML">Office Open XML</a>), you only need to know about a handful of different tags. I've made a tree of some of them for convenience, and bolded the most important ones:<br />
<ul>
<li>w:document</li>
<ul>
<li>w:body</li>
<ul>
<li><b>w:p</b> - paragraph</li>
<ul>
<li><b>w:pPr</b> - paragraph properties</li>
<ul>
<li><b>w:ind</b> - indent</li>
<li><b>w:jc</b> - justification</li>
<li>w:pStyle - paragraph style name</li>
<li>w:numPr - numbered/bulleted list properties. Links against word/numbering.xml</li>
<ul>
<li>w:ilvl - indent level into the list</li>
<li>w:numId - abstract num id</li>
</ul>
<li>w:tabs - tabstops</li>
<ul>
<li>w:tab - tabstop position</li>
</ul>
</ul>
<li><b>w:r</b> - styled text run</li>
<ul>
<li><b>w:t</b> - the actual text itself</li>
<li><b>w:tab</b> - a tab character (different than w:tab above!)</li>
<li><b>w:rPr</b> - run properties</li>
<ul>
<li><b>w:b</b> - bold</li>
<li>w:color - text color</li>
<li>w:highlight</li>
<li><b>w:i</b> - italic</li>
<li><b>w:rFonts</b> - font name</li>
<li>w:strike - strikethrough</li>
<li><b>w:sz</b> - font size</li>
<li>w:u - underline</li>
</ul>
</ul>
<li>w:hyperlink - contains 1 or more w:r's, as above. Links against word/_rels/document.xml.rels</li>
</ul>
</ul>
</ul>
</ul>
Since different runs of text may have different styling, each paragraph (w:p) contains several runs (w:r). Since a run may contain a tab in the middle, each run may have multiple tabs (w:tab) and texts (w:t).<br />
Font sizes seem to be in halves of a point, and indent values are measured in an interesting unit - twips. There are 1440 twips per inch, or about 567 per cm.<br />
If you don't see how to encode something here, create different Word documents and experiment. That's how I found all of these. It's possible to create Word documents programmatically by copying everything but the document.xml file, and then creating that one component from scratch! (In fact, that's exactly what <a href="https://github.com/mikemaccana/python-docx">python-docx</a> does....)<br />
<h3>
Special stuff: Extracting the audio</h3>
In my file, I had recorded a lecture , but when listening to it, I discovered that it was too soft to hear easily. So, I mucked around with it.<br />
In the first step, I Googled the tag name (w:fldData) where I found the audio data. That turned up <a href="http://msdn.microsoft.com/en-us/library/ff534978(v=office.12).aspx">this nice little gem</a>:<br />
<blockquote>
...fldData... Word expects Base64 encoded data....</blockquote>
And that told me everything I needed to know. I copied and pasted the base64 data into a new text file, saved it, and then ran it through base64 to decode it in the terminal:<br />
<div class="code" style="color: #99cc99;">
<pre>$ <b style="color: white;">base64 -D -i base64audio.txt -o audio</b>
$ <b style="color: white;">file audio</b>
audio: ISO Media, Apple QuickTime movie
</pre>
</div>
Aha! I'll just stick on the correct file extension now.<br />
<div class="code" style="color: #99cc99;">
<pre>$ <b style="color: white;">mv audio audio.mov</b>
</pre>
</div>
And now I can double-click it and open it! Great!<br />
I modified it in Audacity, saved it as an AAC (which is how the original was), and ran the result through base64 to encode it again:<br />
<div class="code" style="color: #99cc99;">
<pre>$ <b style="color: white;">base64 audio2 -o audio2.txt -b 80</b>
</pre>
</div>
Unfortunately, sticking this into the OOXML hasn't been working; there are evidently several ways of encoding AAC, and Word is expecting a particular format of AAC. If anyone's got any ideas, please comment!Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1427815439361646147.post-70352268084538470132013-05-14T19:01:00.000-07:002013-07-12T02:40:44.213-07:00Getting started with FPGAs<br />
FPGAs are pretty awesome. But what are they, and how do you use one? Search no further than here!<br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: right; margin-left: 1em; text-align: right;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnTYf9yutn6kQIj1o5eaojC9jJIMTGI4rqIrUxTxwvDleDeBefrT5-OwZuAe_Nayt6UoYDMzq8KE0z3qxmYNwiaYMmlOUDnB7HUVZbeyePgqqGDcT38YDxCy7PKAUiwhv7_oX-rmYKAis/s1600/IMG_0579.jpg" imageanchor="1" style="clear: right; margin-bottom: 1em; margin-left: auto; margin-right: auto;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnTYf9yutn6kQIj1o5eaojC9jJIMTGI4rqIrUxTxwvDleDeBefrT5-OwZuAe_Nayt6UoYDMzq8KE0z3qxmYNwiaYMmlOUDnB7HUVZbeyePgqqGDcT38YDxCy7PKAUiwhv7_oX-rmYKAis/s320/IMG_0579.jpg" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">A Cyclone III FPGA chip on an <a href="http://www.altera.com/education/univ/materials/boards/de0/unv-de0-board.html">Altera DE0</a> dev<br />
board, up close.</td></tr>
</tbody></table>
<br />
An FPGA is kind of like a CPU, but more awesome. Just like you can reprogram a CPU to <i>do</i> different things, you can reprogram an FPGA to <i>be</i> different things. In other words, you are given a whole bunch of logic gates and the complete freedom to hook them up however you want. Think about that for a moment.<br />
<br />
That's the awesomeness of FPGAs.<br />
<br />
You can make audio processors, password crackers, Bitcoin miners, and even parallelizable GPUs and CPUs - all on an FPGA.<br />
<br />
The question is, how?<br />
<a name='more'></a><br />
Just like a CPU is programmed with a number of different special languages, an FPGA is also programmed with a kind of special language - a Hardware Description Language, or HDL for short. Unlike a procedural language like Python, C or Java, an HDL tells the FPGA how to hook up its logic gates.<br />
<br />
This means that, more often than not, a bunch of things are happening at the same exact time, and that, primarily, is what FPGAs are good at. When learning to program FPGAs, you will be learning to think in parallel, and that is a powerful thing. FEEL THE POWER!!!<br />
<br />
There are two main HDLs out there: Verilog, and VHDL. Because Verilog is the first language I learned, and it is less verbose than VHDL, I'll talk about that. First, look at the commented code below.<br />
<br />
<div class="code">
<pre class="code"><span style="color: #e66170; font-weight: bold;">module FPGA_TOP</span><span style="color: #d2cd86;">(</span>
<span style="color: #e66170; font-weight: bold;">input</span> CLOCK<span style="color: #d2cd86;">,</span> <span style="color: #9999a9;">// from the hardware clock generator</span>
<span style="color: #e66170; font-weight: bold;">output</span> <span style="color: #d2cd86;">[</span><span style="color: #00a800;">7</span><span style="color: #d2cd86;">:</span><span style="color: #00a800;">0</span><span style="color: #d2cd86;">]</span> GPIO_LED <span style="color: #9999a9;">// blinky lights!</span>
)<span style="color: #e66170; font-weight: bold;">;</span>
<span style="color: #9999a9;">// ### DECLARATIONS ###</span>
<span style="color: #e66170; font-weight: bold;">reg</span> <span style="color: #d2cd86;">[</span><span style="color: #00a800;">7</span><span style="color: #d2cd86;">:</span><span style="color: #00a800;">0</span><span style="color: #d2cd86;">]</span> count<span style="color: #e66170; font-weight: bold;">;</span> <span style="color: #9999a9;">// 8 bits</span>
<span style="color: #9999a9;">// ### LOGIC ###</span>
<span style="color: #9999a9;">/* Continuous assignment; the wire GPIO_LED is driven by</span>
<span style="color: #9999a9;"> * count, no matter what else is happening.</span>
<span style="color: #9999a9;"> */</span>
<span style="color: #e66170; font-weight: bold;">assign</span> GPIO_LED <span style="color: #d2cd86;">=</span> count<span style="color: #e66170; font-weight: bold;">;</span>
<span style="color: #9999a9;">/* The stuff in this always block happens on the rising clock edge.</span>
<span style="color: #9999a9;"> * Thus the funny <= assignment operator below; above was </span>
<span style="color: #9999a9;"> * a continuous assignment. Here, it's an edge-triggered </span>
<span style="color: #9999a9;"> * assignment. Why? BECAUSE THIS IS NOT C. Above, we were driving a</span>
<span style="color: #9999a9;"> * wire. Here, we are clocking data into a register.</span>
<span style="color: #9999a9;"> */</span>
<span style="color: #e66170; font-weight: bold;">always</span> @(<span style="color: #00c4c4;">posedge CLOCK</span>) <span style="color: #e66170; font-weight: bold;">begin</span>
count <span style="color: #d2cd86;"><</span><span style="color: #d2cd86;">=</span> count<span style="color: #d2cd86;">+</span><span style="color: #00a800;">1</span><span style="color: #d2cd86;">;</span>
<span style="color: #e66170; font-weight: bold;">end</span> <span style="color: #9999a9;">// always @(posedge CLOCK)</span>
endmodule
</pre>
</div>
<br />
What do you think this does?
It counts in binary using the 8 LEDs on the dev board. Some things to notice about this code:
<br />
<ul>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimmcmchsYaqEYCZ85FAGQN5qen6yaOAaQ6qcLaxMAdd86drCEgNut4tetFDTHkQSgzPBGxb5qkNRCqUJhLyojHRRuX3tq4ynt_exkJ0Dbc4dMQJAJKTX7joj-4Q0iQd3Wg0BeLDqlmo6g/s1600/counter.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><br /></a>
<li>It begins with <code>module MODULE_NAME(...);</code> and ends with <code>endmodule</code>.</li>
<li>You must declare the size of your regs and wires, or they will be one bit wide. (You can do some pretty wacky stuff, like making a 39-bit CPU, similar to what <a href="http://history.nasa.gov/computers/Ch1-2.html">NASA did</a> 50 years ago!)</li>
<li>Use <code>begin</code> to begin blocks, and <code>end</code> to end them. Makes sense, no?</li>
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: right; text-align: right;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimmcmchsYaqEYCZ85FAGQN5qen6yaOAaQ6qcLaxMAdd86drCEgNut4tetFDTHkQSgzPBGxb5qkNRCqUJhLyojHRRuX3tq4ynt_exkJ0Dbc4dMQJAJKTX7joj-4Q0iQd3Wg0BeLDqlmo6g/s1600/counter.png" imageanchor="1" style="clear: right; margin-bottom: 1em; margin-left: auto; margin-right: auto;"><img border="0" height="175" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimmcmchsYaqEYCZ85FAGQN5qen6yaOAaQ6qcLaxMAdd86drCEgNut4tetFDTHkQSgzPBGxb5qkNRCqUJhLyojHRRuX3tq4ynt_exkJ0Dbc4dMQJAJKTX7joj-4Q0iQd3Wg0BeLDqlmo6g/s320/counter.png" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">The Verilog code, translated into circuits.<br />
<a href="http://ozark.hendrix.edu/~burch/logisim/">Logisim</a> is great.</td></tr>
</tbody></table>
<li>It looks a lot like C. <b>BUT IT'S NOT! THIS IS NOT C! THIS IS PARALLEL, DUDE! C IS PROCEDURAL! VERILOG IS AWESOMER!!!</b></li>
</ul>
<div>
<br /></div>
OK. The first thing you might want to do is translate this into C or Python. <b>DON'T.</b> Behaviorally, this is <b>NOT C, OR ANYTHING LIKE IT.</b> Instead, translate this code into circuits. This is what the Verilog compiler does. We are coding circuits, not programs. Look at the diagram at the right, and convince yourself that it is the same as the Verilog.<br />
<ul>
</ul>
<div>
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: left; text-align: left;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjw8hyphenhyphenYAAMJO8cLjueBq-cStve-CKnVi9SGXrR2Ab-Yi1BTgsst8wfKTvQWj_tiexBQd_VXk19xPqExr34vECd2aLbzzq2f5STHRejlfHYi31kJ2RFH9jN4wW1ARt_MMsh3hYAndLG9-5g/s1600/badcounter.png" imageanchor="1" style="clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;"><img border="0" height="92" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjw8hyphenhyphenYAAMJO8cLjueBq-cStve-CKnVi9SGXrR2Ab-Yi1BTgsst8wfKTvQWj_tiexBQd_VXk19xPqExr34vECd2aLbzzq2f5STHRejlfHYi31kJ2RFH9jN4wW1ARt_MMsh3hYAndLG9-5g/s200/badcounter.png" width="200" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">An uncontrolled counter. <b>Does<br />not work.</b> Logisim didn't like<br />
it either, and refused to<br />
simulate it.</td></tr>
</tbody></table>
</div>
<div>
Note the CLOCK signal in the diagram and in the Verilog. Things only change on the <i>rising edge</i> of CLOCK; even if the CLOCK stays high, there will only be one change until the clock goes low and goes high a second time. That is why we use <code>always @(posedge CLOCK)</code> in our Verilog. We could have put the code in an <code>always @(*)</code> instead without waiting for the CLOCK edge, but then the count would increment over and over again very fast and without control. In the diagram, this would be the same as removing the count register and connecting the input and output of the +1 block together.</div>
<div>
<br /></div>
<div>
So, registers are like locks in a canal; they hold data still until ready to be changed.</div>
<div>
<br /></div>
<div>
How did you like your first taste of Verilog? Please leave a comment if you are interested in more; I'll write more about it.</div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1427815439361646147.post-17236613951668068592013-05-07T23:07:00.002-07:002013-05-21T20:10:58.892-07:00Building a home workshop<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: right; margin-left: 1em; text-align: right;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjiwMyyQtXDdDugD9pk6KUMPAQEmDNVOi-NuKEscVVAou9SDmaeXNhfOgIEV-pxd1_KwFuOv4_y3kKvnx9NtApk9XaqhPyQWtg0siSonamYp8ZhN7qGpehWfXx2RyQNrc5Cwo6upesdJOI/s1600/IMG_0575.jpg" imageanchor="1" style="clear: right; margin-bottom: 1em; margin-left: auto; margin-right: auto;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjiwMyyQtXDdDugD9pk6KUMPAQEmDNVOi-NuKEscVVAou9SDmaeXNhfOgIEV-pxd1_KwFuOv4_y3kKvnx9NtApk9XaqhPyQWtg0siSonamYp8ZhN7qGpehWfXx2RyQNrc5Cwo6upesdJOI/s320/IMG_0575.jpg" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><b>My work table.</b> The pill bottles at top left<br />
are for storing SMD components. The adhesive<br />
labels Digikey sends with these components<br />
are the perfect size! </td></tr>
</tbody></table>
This post is for all the serious hackers and EE majors out there who want to build cool stuff at home. Some of my friends have seen the mess that is my apartment/workshop, and began wanting to build up their own home workshop. So they ask, "What should I get first?"<br />
<div style="text-align: right;">
</div>
<br />
<br />
To begin, you can check out a list of things I think a serious hobbyist should have on SparkFun. I am assuming that you have maybe a few basic tools, but you want to do some more advanced stuff. Of course, I'm not giving a Divine command ("Thou shalt buy a temperature-controlled soldering iron with a brass sponge and a chisel tip!"); this is just a strong recommendation.<br />
<a href="https://www.sparkfun.com/wish_lists/62754">https://www.sparkfun.com/wish_lists/62754</a><br />
<br />
<a name='more'></a><br />
There are some items not in that list that have to be purchased elsewhere (<a href="http://www.sears.com/">Sears</a> seems to have the best combination of prices and quality at the time of this writing):<br />
<br />
<ul>
<li><b>Mini pliers set</b> - While <a href="http://www.sparkfun.com/">Sparkfun</a> does have some pliers, reviews have remarked negatively on their quality. Beware of cheap pliers, because their grips will rip over time, their springs can slip out, and they will get loose easily. Look for molded handles that won't rip; otherwise, if the handles are jacketed in rubberized plastic sheaths, make sure the coating is thick (~2mm, thicker is better) and hard to tear at the edges. Try to get <a href="http://www.sears.com/shc/s/p_10153_12605_00945671000P">a set with a carry case</a>; this helps avoid losing them. Expect to pay roughly $30 for a set of five, and around $10 individually. In order of importance: long-nose, diagonal cutters, bent-nose, end cutters, flat-nose and needle-nose.</li>
<li><b>Wire strippers</b> - Same warnings as the pliers set. I'm suspicious of any hand tool much less than $10, especially ones with blades. Strippers with adjustable screws are somewhat less quality-sensitive, but are harder to use than strippers with different apertures for different gauges. Look for a set that strips 30-20 AWG wire, between <a href="http://www.sears.com/gb-electrical-wire-stripper-1630-awg/p-SPM2285277203">$12</a> and <a href="http://www.sears.com/paladin-tools-1118-gripp-20-wire-stripper-cutter-30/p-SPM7468450411">$30</a>. You will probably use them more times than any other tool; get something good and rugged.<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: right; margin-left: 1em; text-align: right;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJoEqXWWjDHs8MbSEcBi9NyJxTkmniR46w-kzi21kbxrrhFjKq3Mi-Ngu9nhiayYdirEFsFL_RZJ5N555USQjjy1lJQidnP-L7mDbIK0yxcHWvStQoslvXek4NFlIq9MZ5hEgwlLuLVCY/s1600/IMG_0578.jpg" imageanchor="1" style="clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJoEqXWWjDHs8MbSEcBi9NyJxTkmniR46w-kzi21kbxrrhFjKq3Mi-Ngu9nhiayYdirEFsFL_RZJ5N555USQjjy1lJQidnP-L7mDbIK0yxcHWvStQoslvXek4NFlIq9MZ5hEgwlLuLVCY/s320/IMG_0578.jpg" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><b>Bad, cheap tools.</b> The mini screwdrivers at<br />
left are poorly made, often too thick for the<br />
screws they are supposed to drive. The orange<br />
Torx driver was made of soft metal and<br />
became nearly useless, wearing down after<br />
about three uses. Note the broken needle file<br />
in the middle. And, the wire stripper/crimper<br />
on the right is fully closed, but there is a<br />
huge gap between the wire stripping<br />
apertures. Not to mention, the cutting<br />
surfaces have been painted over at the<br />
factory and are hardly sharp at all.</td></tr>
</tbody></table>
</li>
<li><b>Screwdrivers</b> - Medium and small ones are the most important. Again, avoid cheap brands - they are made of softer metal and will get damaged easily. They will even damage your screws. I use small screwdrivers most often, so I don't like ones with interchangeable bits - it's too fiddly for me. Medium screwdrivers, I can get away with interchangeable bits, since I use them less often. But if you have the space, drivers without interchangeable bits are the most convenient; there's less stuff to use, and it's quicker to switch between them. (And, having more than one flat head driver is great for prying things open!) Although Craftsman is not as well-known for quality these days as they used to be, screwdrivers are not as quality-critical as bladed tools or tools with moving parts; they have a <a href="http://www.sears.com/craftsman-28-pc-screwdriver-set/p-00931797000P">decent 28-piece set</a> that covers the medium and small screwdriver range for about $40 (they even throw in Torx drivers!).</li>
<li>A <b>Dremel clone</b> is useful for making project enclosures. Dremel itself is grossly overpriced, and their cheapest 7.2V battery-powered unit doesn't last long enough. Don't get ultra cheap ones (<$25), because they vibrate too much and usually aren't speed-adjustable. You NEED the continuous speed adjustment control, or you will likely break your cutting wheels and/or your project. I prefer corded models so that I don't have to fiddle with and wait for batteries. Use the slowest speed reasonable, and brace it well with both hands against your project and your workbench. Don't hold it with your fingers; use your whole fist. A reasonable speed for cutting plastic cleanly is 1mm in 3 seconds. I use a <a href="http://www.sears.com/apollo-tools-electric-rotary-tool-kit-with-100/p-00931036000P">Dremel clone</a> that has served me well for about five years. A basic unit with continuous speed control is about $30, and the price goes up to about 60 or $70 for better craftsmanship. I recommend using thicker (~2mm) cutting wheels when you are starting out; ultra fine wheels require a steadier hand, or they will break even on plastic. Of course, use safety goggles; even with safety-rated glasses and side shields, dust and shards of the cutting wheel can still get in your eyes from above or below the lenses.</li>
<li><b>Needle files</b> are also useful for making project enclosures and cleaning up Dremel cuts. Beware: cheap files will break and separate easily from their handles, so don't go ultra-cheap here, either. Around <a href="http://www.sears.com/universal-tool-diamond-file-5pc-set/p-SPM6524904701">$12</a> for a set of four or five is reasonable, and you don't need more than that. I mostly use the half-round file since it is good for straight edges and corners, and occasionally the round and flat files for widening holes.</li>
</ul>
Further notes:<br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: right; margin-left: 1em; text-align: right;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgcutWpOFkBPZCv-X9A_FOQvY6kXo0YCd2x7vYtwT4V6M6PTrOKV-cDUVNv-HMRpghl9j_PPugI4HCs7TocuQx59Uk3P_vO8ZYYQTXk3yaPe6C4cgeV7w_BJUWNWE3JCMS5xDZSYiSv-Vw/s1600/IMG_0576.jpg" imageanchor="1" style="clear: right; margin-bottom: 1em; margin-left: auto; margin-right: auto;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgcutWpOFkBPZCv-X9A_FOQvY6kXo0YCd2x7vYtwT4V6M6PTrOKV-cDUVNv-HMRpghl9j_PPugI4HCs7TocuQx59Uk3P_vO8ZYYQTXk3yaPe6C4cgeV7w_BJUWNWE3JCMS5xDZSYiSv-Vw/s320/IMG_0576.jpg" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><b>Two breadboards and a jumper wire box.</b><br />
The small breadboard at the right is an RF<br />
carrier wave generator for an AM radio<br />
transmitter. The bottom board is an AM<br />
radio receiver and a few audio amplifier<br />
circuits under test.</td></tr>
</tbody></table>
<ul>
<li>It's hard to have too many <b>breadboards</b>. I have four full-length breadboards, some of them with two columns, and I use nearly all of them all the time. </li>
<li>If you are experienced with a soldering iron and have a temperature-controlled unit, you may prefer <b>unleaded solder</b> for personal health and the environment. However, it is harder to work with.</li>
<li>In my soldering iron, I use <b>chisel tips</b> almost exclusively. They present a wider face to the component and transfer heat more efficiently. <b><a href="http://www.youtube.com/watch?v=W4gmLFLYeiQ">Clean your tips</a></b> as often as you can! This extends their life by preventing oxidation.</li>
<li>For tiny surfaces, and surfaces that solder just can't seem to stick to, use <b>solder flux</b>. It cleans off the top layer of oxidation and helps the solder wet the metal. This is a more advanced soldering technique; for a very deep understanding of the soldering process, see <a href="http://www.youtube.com/watch?v=vIT4ra6Mo0s">this video series</a>. Even though I have been soldering for 14 years, I still learned many things from it.</li>
<li>For components (that are not in assortment kits), it's usually cheaper to shop on <a href="http://www.ebay.com/">eBay</a>, <a href="http://www.digikey.com/">Digikey</a> or <a href="http://www.mouser.com/">Mouser</a>. You can also get free samples from many manufacturers, like <a href="https://myportal.ti.com/portal/dt?provider=TIPassLoginSingleContainer&lt=myti&j5=2&j3=1&goto=https%3A%2F%2Fwww-a.ti.com%3A443%2Fapps%2Fsamp%2Fbasket.asp">TI</a>, <a href="http://www.analog.com/">Analog Devices</a>, and even <a href="http://www.molex.com/">Molex</a>. Unfortunately, many parts are not breadboard-friendly nowadays, so I'd suggest looking for a predesigned <a href="https://www.sparkfun.com/search/results?term=breakout+board&what=products">Sparkfun breakout</a>. Failing that, you can design your own adapter boards in <a href="http://www.cadsoftusa.com/download-eagle/">Eagle CAD</a> (free to download, see the <a href="http://www.youtube.com/watch?v=qG0O9LKH-_E">tutorial series</a>) and send the design off to <a href="http://www.oshpark.com/">OSH Park</a> for manufacture ($5 per square inch for three double-sided PCBs).</li>
<li>If you are doing analog and have the money, a digital storage oscilloscope is essential. The <a href="http://www.rigolna.com/products/digital-oscilloscopes/ds1000e/ds1052e/?gclid=CNiywZzAhbcCFcXe4AodjRIA1g">Rigol 1052e</a> is famous for being inexpensive and easily (software-) <a href="http://hackaday.com/2010/03/31/update-50mhz-to-100mhz-scope-conversion/">modified to work up to 100MHz</a>.</li>
</ul>
And finally:<br />
<br />
<b>Never, never shop for tools at the Dollar Store. Or anything like it.</b> That is worth repeating: NEVER, NEVER shop for tools at the Dollar Store, or anything like it. You WILL regret it.<br />
<br />
Happy hacking!Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1427815439361646147.post-44417692171878175852012-07-20T16:18:00.001-07:002014-08-27T17:47:14.229-07:00Taking apart the 2006 Honda Odyssey dashboard, part 1 of ?I got it into my head that a true hacker must know how to hack his car. Especially the dash. You've got the connection to the car's diagnostic computer, DC power (without occupying a cigarette lighter port), auxiliary audio, and the ability to use any blank switchplates you might find there.<br />
<br />
I found that the average hacker can probably figure it out, but with a caveat: you have to use much more force than when building a computer (for example). The car's retaining snaps and bolts were designed to stay in place in a vibrating environment, extreme temperatures, and in the event of an accident. HOWEVER! The force you apply must be at the correct time and place. The same force you use to disengage a connector or snap could end up tearing a tab somewhere if you force it too much. If you feel inordinate resistance, check for screws. Basically, it's the same as disassembling your garden variety coffee pot, but with more prying force and snap tabs. Be careful!<br />
<br />
<a name='more'></a><br />
<br />
<h3>
Top center - the radio and A/C control panel</h3>
<div>
If you intend to remove the radio, you will need to move the shifting stick out of the way first. Start the engine and engage the parking brake with your left foot. Put the car in neutral, and turn the engine off; your key will be retained.</div>
<div>
<br /></div>
<div>
Then, open the top glove compartment on the passenger side. Towards the left of the compartment, you should see a gap to stick your flathead driver in. Pry there to pull the first tab loose, then firmly and carefully pull the air conditioning control unit towards you. Just release the tabs all around; there will be three cables still connected. Two green connectors will be towards the right at top and bottom; one grey one will be towards the left. To release them, press a button on the side of each connector. I found the grey one to be quite difficult to remove.</div>
<div>
<br /></div>
<div>
Now, pull the air conditioning control panel over the shift stick. The A/C panel is free.</div>
<div>
<br /></div>
<div>
Next, remove the two steel bolts in plain sight. Get low and look up at the middle part near the top of where the LCD panel was. There is a third steel bolt there, quite deep. Remove this one. (When I tried to put it in, it dropped and I heard it knock against things until it stopped near the floor of the car. I don't know if this was by design or not, but when I opened the bottom knicknack compartment, I found the bolt. Keep that knicknack compartment closed to catch your bolt!)</div>
<div>
<br /></div>
<div>
Now you can pull the radio out. Unplug the cables, and your radio is free.</div>
<br />
<h3>
Middle center - the GPS and cell phone compartment</h3>
<div>
Remove the two black screws below where the two steel bolts were. Extend the cup holder, and remove the two black screws at the top right and left. Now, pull firmly at the right and left of the GPS compartment; two snaps should release. Pull out the GPS compartment, angling it up at the end. The GPS compartment is free.</div>
<h3>
Bottom center - the knicknack compartment and DC outlets</h3>
<div>
To remove this part, you must remove the roughly triangular panels to the right and left sides. Take a smallish flathead screwdriver, and find a circular cover a bit bigger than a nickel on these triangle panels. Stick the blade into the gap kindly provided and pry the blunt, tack-like pin out. (When putting the panels back, note that the tack has two parts; it is easiest to pull the top away from the bottom first before reinserting this pin. once the bottom of the pin is in, lock it by pushing the top in.)</div>
<div>
<br /></div>
<div>
Now, pull the panel away from the center column. There are snap tabs at the bottom and top corners nearest to you. Once those are undone, pull the panels toward the back of the car. There is a threaded post at the far corners of each panel. There is no nut holding that corner - simply pull.</div>
<div>
<br /></div>
<div>
Next, on each of the bottom, near corners where your panels used to be, there is a black screw - remove it.</div>
<div>
<br /></div>
<div>
After that, extend the cup holder. At the bottom corners, there are two more black screws just like the previous two. Remove them. Now, pull firmly on the DC power and knicknack compartment assembly, first on the right, then on the left. They should snap loose.</div>
<div>
<br /></div>
<div>
Finally unplug the cables. The DC power panel and knicknack compartment is free.</div>
<div>
<br /></div>
<h3>
Bottom left - the fuse panel and driver's footboard</h3>
<div>
The driver's footboard is held in place with three snap pins: right, left and center. Pull these up until they snap free.</div>
<div>
<br /></div>
<div>
The fuse panel is held in with three snap pins, too. One is near the bottom, the next at middle height, and the third is at the top. (To reassemble, I found it easiest to pull these pins out with long-nose pliers and slide them into the fuse panel. Then, I could simply press the fuse panel in place, instead of having to slide it.) The fuse panel is free.</div>
<div>
<br /></div>
<h3>
Main dashboard (in progress)</h3>
<div>
There is a screw near the door and directly in front of the chair, under the steering wheel. Another screw is near the knicknack compartment. The panel under the steering column is now held in by snaps. Work from left to right. Try as much as possible to pull straight towards the back of the car, especially at the corner. There is some sort of sensor behind a grille which will get in the way. Pull the sensor towards the front of the car to remove it from its bracket. I may have forgotten to mention some screws; be careful.</div>
<div>
<br /></div>
<div>
More to come?</div>
Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-1427815439361646147.post-67204959328960834262010-05-24T12:16:00.000-07:002010-05-24T21:49:34.681-07:00Cryptap: rhythmic combo lock<object height="297" width="360"><param name="movie" value="http://www.youtube.com/v/XAEane4SckA&hl=en_US&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/XAEane4SckA&hl=en_US&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="360" height="297"></embed></object><br />
<br />
A while ago in December, I posted something at <a href="http://www.hackaday.com/">hackaday.com</a>: a rhythmic door lock. I had in mind to use a keypad at the beginning, but I didn't have enough buttons and wanted to keep this a very low-budget project. For instance, the buttons were free samples and the filter capacitor was pulled from a TV or CRT monitor, I can't remember which.<a name='more'></a><br />
<br />
Being limited to two buttons, I drew inspiration from other hackaday projects to make a rhythm-based code system. The rhythm must fulfill two criteria to be accepted:<br />
<ol><li>It must have the right number of beats.</li>
<li>The beats must be spaced correctly, +/- 30%. This algorithm measures the beats proportionally.</li>
</ol>It's saved me many times from running to the front desk and asking them to unlock my door for me. I like it a lot.<br />
<br />
<b>Hardware</b><br />
The brains behind this is the <a href="http://www.pjrc.com/teensy">Teensy</a> microcontroller, which is programmed via a direct USB connection. At the time I built this project, I didn't want to pay more for a programmer module, so this was good. Other parts were things I had lying around. The door strike was already installed, which made things easy.<br />
<br />
<b>Software</b><br />
I relied on interrupts for the buttons and the built-in delay functions to time the beats. Debouncing the inputs in software was awful, and I don't want to go through that again. Next time, hardware. Because the buttons would do different things at different times, I used function pointers in C to configure their behavior at different stages in the program.<br />
<br />
If you want to see my code and learn more, see my <a href="http://www.instructables.com/id/Cryptap-A-password-protected-door-unlocker/">Instructable</a> and the Hackaday <a href="http://hackaday.com/2009/12/22/rhythmic-combo-lock/">article</a> about it.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1427815439361646147.post-40870821248921571782010-05-21T11:13:00.000-07:002010-05-22T23:04:10.850-07:00Hacking in martial artsYou don't have to be a computer expert to be a hacker. According to many definitions that hackers use among themselves (like <a href="http://www.rfc-editor.org/rfc/rfc1392.txt">RFC1392</a>, aka The Internet User's Glossary, for example) a hacker is "A person who delights in having an intimate understanding of the internal workings of a system."<br />
<br />
So, all you really need to be called a hacker is a love of knowing how things tick. The specialty doesn't need to be programming and <a href="http://www.hackaday.com/">circuits</a>. The very authoritative <a href="http://catb.org/jargon/">Jargon file</a> says that a person could be an astronomy <a href="http://catb.org/jargon/html/H/hacker.html">hacker</a>, for example.<a name='more'></a><br />
<br />
So, a martial artist is a hacker of sorts--let's say, a biomechanical hacker. Some martial artists even create their own weapons or adapt them from everyday objects, which makes them hackers in a very traditional sense: "one who enjoys creatively overcoming or circumventing limitations," again in the words of the Jargon File.<br />
<br />
As a martial artist and programmer myself, I can say that there are big similarities between those fields. It takes finesse. It takes knowledge. It takes an instinctive feel of the playing ground. It's engineering. And I love it.<br />
<br />
My favorite way to hack the body involves controlling something that Aikidoists call the "center", or "ki". In the dojo, I've learned that when two people make contact, they become a single physical system, and the point of contact becomes the "center" of that system. Whoever controls that "center" controls all the movement of the system. This idea is common to all martial arts, but is especially important in Judo, karate, wrestling, and Aikido.<br />
<br />
In general, there are a few ways to control movement:<br />
<ol><li>Change the location of the Center.</li>
<li>Change the direction of your pressure on the Center.</li>
<li>Overpower opposing forces on the Center.</li>
</ol>For instance, take a certain throw involving head-control. In Aikido, they call it <a href="http://www.youtube.com/watch?v=EyJT8v6gqSo&feature=related">irimi-nage</a>. In the vid the attacker starts with a knife attack, trying to engage the defender with the point of his blade in his partner's belly. The defender changes the point of contact instead to the wrist, the armpit, the back of the head, the front of the head, and so on. This technique is <i>all</i> about controlling the Center. (BTW, with small modifications, this technique also works on punches, kicks, swords, guns, you name it. If you're trained in it. :-D )<br />
<br />
In a more usual sense of "hacking," the adaptation of common items as weapons is a classic idea in martial arts. The <a href="http://en.wikipedia.org/wiki/Kama_(weapon)">kama</a>, for instance, started out as a sickle for farming before it was adopted into Okinawan Karate as a practical weapon. The famous <a href="http://en.wikipedia.org/wiki/Nunchaku">nunchaku</a>, commonly called "nunchucks," were originally tools for threshing grain. The jo staff was just a walking stick. And the list goes on. Martial artists have been hacking from the beginning of time.<br />
<br />
I think this might be why many computer hackers are also martial artists. It appeals to the hacker aesthetic of using things in unusual ways to solve problems in a beautiful, functionally perfect, or clever way.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1427815439361646147.post-10337061964241781852010-05-18T10:13:00.000-07:002013-05-07T23:45:42.673-07:00Customizing grub, Part 3Here I am again with grub 2. In <a href="http://manhacking.blogspot.com/2010/05/customizing-grub-part-2.html">Part 2</a>, I was cleaning up the boot menu that chooses which OS or kernel you want to use. But, that time, I only showed how to modify entries for OSes besides the one you are currently booted into. (Which is Linux, right? Right.) <br />
<br />
This time, I'll show you how to modify /etc/grub.d/10_linux to clean up the menu entries for the OS that you will be running update-grub from.<br />
<a name='more'></a><br />
<br />
Opening that file, it looks like the default behavior is to rely on variables provided by grub itself to generate the menu entry. Unfortunately, those strings are ugly. In case you don't remember from <a href="http://manhacking.blogspot.com/2010/05/customizing-grub-part-2.html">Part 2</a>, the format I used for Linux entries was:<br />
<br />
<div class="code">
Ubuntu 9.10 (2.6.31-21-generic)<br />
Ubuntu 9.10 (2.6.31-21-generic, recovery mode)</div>
<br />
We can't use os-prober or linux-boot-prober to get the OS string, because those only work on disks that you haven't booted from. Instead, we will get the info we need from /etc/lsb-release, which looks like this:<br />
<br />
<div class="code">
DISTRIB_ID=Ubuntu<br />
DISTRIB_RELEASE=10.04<br />
DISTRIB_CODENAME=lucid<br />
DISTRIB_DESCRIPTION="Ubuntu 10.04 LTS"</div>
<br />
That last line has what we want, so we'll put this line into 10_linux to extract the info we want and store it to a variable:<br />
<br />
<div class="code">
args="$4"<br />
<b>LONGNAME="`grep DESCRIPTION /etc/lsb-release | cut -d '"' -f 2`"</b></div>
<br />
The script already has an if-statement that detects whether this is a recovery image we are dealing with, so we'll just change that if-statement to handle recovery systems the way we want:<br />
<br />
<div class="code">
if ${recovery} ; then<br />
<b>title="${LONGNAME} (${version}, recovery mode)"</b><br />
else<br />
<b>title="${LONGNAME} (${version})"</b><br />
fi</div>
<br />
And that should do it! All the menu entries are now nicely formatted.<br />
<br />
If you want to go further, you can use the shell's printf to organize the system info into columns. How about adding a column showing which disk and partition each OS is on? Now you can do it!<br />
<br />
Happy hacking!Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1427815439361646147.post-43194532556013097572010-05-17T13:05:00.000-07:002011-07-26T09:15:57.932-07:00Customizing grub, Part 2In the <a href="http://manhacking.blogspot.com/2010/05/customizing-grub-part-1.html">last post</a>, I talked about the general approach to customizing grub. Now I'll get into the details fix up those messy grub menus.<br />
<br />
First, before mucking inside the config files, I'd like to change the order of the menu; I think that memtest should be after the other OS entries, so I'll run<br />
<br />
<div class="code">$ <b>sudo mv /etc/grub.d/20_memtest86+ \</b><br />
<b>/etc/grub.d/50_memtest86+</b><br />
</div><a name='more'></a><br />
<br />
Next, I hate how the entries in the boot menu are really bloated and non-user-friendly. I mean, when I'm choosing between Jaunty and Karmic and Lucid, I might not remember that kernel 2.6.31-21 is for Karmic. In any case, the menu entry format is ugly and I want to clean that up.<br />
<br />
Let's do 30_os-prober first. That's the easier one. Scanning the file tells me that it chops up the output from os-prober and linux-boot-prober to build the menu entries. Let's run them to see what kind of stuff they spit out.<br />
<br />
<div class="code">$ <b>sudo os-prober</b><br />
/dev/sda1:Windows 7 (loader):Windows:chain<br />
/dev/sda3:Ubuntu 9.10 (9.10):Ubuntu:linux<br />
$ <b>sudo linux-boot-prober /dev/sda3</b><br />
/dev/sda3:/dev/sda3:Ubuntu, Linux 2.6.31-21-generic:/boot/vmlinuz-2.6.31-21-generic:/boot/initrd.img-2.6.31-21-generic:root=UUID=d97e0b98-5e2e-4d91-9968-ee9f206eed3a ro quiet splash<br />
/dev/sda3:/dev/sda3:Ubuntu, Linux 2.6.31-21-generic (recovery mode):/boot/vmlinuz-2.6.31-21-generic:/boot/initrd.img-2.6.31-21-generic:root=UUID=d97e0b98-5e2e-4d91-9968-ee9f206eed3a ro single<br />
</div><br />
All the info is there, so all we have to do is chop it up and stick it back together differently. I want my menu entries from 30_os-prober to look like this:<br />
<br />
<div class="code">Windows 7<br />
Ubuntu 9.10 (2.6.31-21-generic)<br />
Ubuntu 9.10 (2.6.31-21-generic, recovery mode)<br />
</div><br />
instead of like this:<br />
<br />
<div class="code">Windows 7 (loader) (on /dev/sda1)<br />
Ubuntu, Linux 2.6.31-21-generic (on /dev/sda3)<br />
Ubuntu, Linux 2.6.31-21-generic (recovery mode) (on /dev/sda3)<br />
</div><br />
So, I'm going to use cut and sed. The man page for cut is good enough get a feel for it; cut is a tiny program. Not so for sed, especially if you don't know regular expressions yet. Bruce Barnett has some good info on <a href="http://www.grymoire.com/Unix/Sed.html">sed</a> and <a href="http://www.grymoire.com/Unix/Regular.html">regular expressions</a>.<br />
<br />
To get a nice, clean string containing the OS name, just change the line that sets LONGNAME. Unmodified, LONGNAME holds the name of the OS like "Windows 7 (loader)" and "Ubuntu 9.10 (9.10)", which is rather bloated and ugly. So, we will cut off the stuff that matches the space, open-parenthesis, and anything afterwards:<br />
<br />
<div class="code">DEVICE="`echo ${OS} | cut -d ':' -f 1`" # no change; just for bearings<br />
<b>LONGNAME="`echo ${OS} | cut -d ':' -f 2 | tr '^' ' ' | sed 's/ (.*$//'`"</b><br />
</div><br />
That alone will fix the entry for Windows.<br />
<br />
The Linux entry takes a bit more advanced hacking, because I want to display three bits of info:<ol><li>the OS name</li>
<li>the kernel version</li>
<li>whether this is a recovery kernel image</li>
</ol>Right now, I can only check off number 1. To get the kernel version, we'll make a new variable:<br />
<br />
<div class="code">LKERNEL="`echo ${LINUX} | cut -d ':' -f 4`"<br />
<b>LKERNELVERSION="`echo ${LKERNEL} | sed 's/^[^0-9]*\(.*$\)/\1/'`"</b><br />
</div><br />
That will give a string like "2.6.31-21-generic". Yay! Number 2 is checked off.<br />
<br />
For number 3 (is this a recovery image?) we'll use grep in the if-statement below. After the fi, we'll build the string for the menu entry.<br />
<br />
<div class="code">LKERNELVERSION="`echo ${LKERNEL} | sed 's/^[^0-9]*\(.*$\)/\1/'`" # added in previous step by Chaim Leib<br />
<b>if [ "`echo ${LINUX} | grep 'recovery'`" ] ; then<br />
LRECOVERY=", recovery mode"</b><br />
else<br />
<b>LRECOVERY=""</b><br />
fi<br />
<b>LLABEL="${LONGNAME} (${LKERNELVERSION}${LRECOVERY})"</b><br />
</div><br />
<a href="http://manhacking.blogspot.com/2010/05/customizing-grub-part-3.html">Next post</a>, I'll be showing how to modify 10_linux, so that the main boot entry is cleaned up as well! See you next time!Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1427815439361646147.post-67197216186001656622010-05-14T11:32:00.000-07:002010-05-18T03:58:28.448-07:00Customizing grub, Part 1Ubuntu has upgraded grub to version 2 in their default install. The new version is more powerful than the old one, but the config interface has changed.<br />
<br />
Aaargh! Where is menu.lst?!<a name='more'></a><br />
<br />
The bad news is that it has been moved (to /boot/grub/grub.cfg), and you aren't supposed to modify it. The really good news is that it is automatically generated by scripts--which you can hack!<br />
<br />
This is really nice, because now, whenever Ubuntu releases a kernel upgrade, you don't have to modify menu.lst anymore to get rid of those extra boot entries. Instead, just run<br />
<br />
<div class="code">$ <b>sudo rm *</b><old kernel version><b>*</b><br />
$ <b>sudo update-grub</b><br />
</div><br />
and grub will regenerate grub.cfg, removing the old entries!<br />
<br />
Now, where are the config scripts? They are in /etc/grub.d. When you run update-grub, each of the scripts in /etc/grub.d are run in order and their output is dumped into /boot/grub/grub.cfg.<br />
<br />
To change the boot options, just change the scripts in /etc/grub.d. For example, I was having some display problems, so I went into 10_linux to set up some kernel boot arguments like so:<br />
<br />
<div class="code">linux_entry ()<br />
{<br />
os="$1"<br />
version="$2"<br />
recovery="$3"<br />
<b>args="$4 radeon.new_pll=0"</b><br />
...<br />
</div><br />
<a href="http://manhacking.blogspot.com/2010/05/customizing-grub-part-2.html">Next post</a>, I'm going to be doing some advanced stuff to automatically generate cleaner boot menu entries. See you then!Unknownnoreply@blogger.com0