tag:blogger.com,1999:blog-20020033433238757632024-03-27T16:53:14.768-07:00Thoughts of a TechieAnonymoushttp://www.blogger.com/profile/13196480231236274690noreply@blogger.comBlogger58125tag:blogger.com,1999:blog-2002003343323875763.post-57424708423999541072016-10-22T20:54:00.000-07:002016-10-22T20:54:04.689-07:00[Intellij] Configure Go to Implementation with CNTRL+ Left Click<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="p1">
<span class="s1"><span style="font-family: Verdana, sans-serif;">This is not available out of the box, We need to configure this with Quicklists and keymap </span></span></div>
<ol class="ol1">
<li class="li1"><span class="s1"><span style="font-family: Verdana, sans-serif;">Preferences/Settings-> Appearance & Behavior -> "Quick Lists" </span></span></li>
<li class="li1"><span style="font-family: Verdana, sans-serif;">Give a name and save it.</span></li>
<li class="li1"><span class="s1"><span style="font-family: Verdana, sans-serif;">Add an action in the right side panel bottom (Click on the + at the bottom)</span></span></li>
<li class="li1"><span class="s1"><span style="font-family: Verdana, sans-serif;">Add the Go to Declaration action (Main Menu > Navigate > Declaration )</span></span></li>
<li class="li1"><span class="s1"><span style="font-family: Verdana, sans-serif;">Add the Go to Declaration action (Main Menu > Navigate > Implementation )</span></span></li>
<li class="li1"><span class="s1"><span style="font-family: Verdana, sans-serif;">Click Apply</span></span></li>
<li class="li1"><span class="s1"><span style="font-family: Verdana, sans-serif;">Go to Keymap in the settings</span></span></li>
<li class="li1"><span class="s1"><span style="font-family: Verdana, sans-serif;">"Quick List" -> Add a shortcut with (COMMAND/CNTRL+Click)</span></span></li>
<li class="li1"><span class="s1"><span style="font-family: Verdana, sans-serif;">If it is already assigned to something, do the needful.</span></span></li>
</ol>
<div class="p1">
<span style="font-family: Verdana, sans-serif;">Then you can try the shortcut</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhh1p-8XjCKFWbpn42NjdjS2nlmkJWBLhqRX9NFMqHaZEcmhyvjfJD_O_F83ODnWYy9FH4RairlIaBFTipX65TXACtWzdH3kXBWvnvh5BMRnqCG3ihRYMD5N-t0uRY9OU6r1k11tO7X4K7-/s1600/goto_impl.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="95" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhh1p-8XjCKFWbpn42NjdjS2nlmkJWBLhqRX9NFMqHaZEcmhyvjfJD_O_F83ODnWYy9FH4RairlIaBFTipX65TXACtWzdH3kXBWvnvh5BMRnqCG3ihRYMD5N-t0uRY9OU6r1k11tO7X4K7-/s320/goto_impl.png" width="320" /></a></div>
<div class="p1">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
</div>
Anonymoushttp://www.blogger.com/profile/13196480231236274690noreply@blogger.com0tag:blogger.com,1999:blog-2002003343323875763.post-81420463088578594652016-07-29T05:40:00.001-07:002016-07-29T05:40:10.077-07:00[Solution] How to embed images from dropbox in blogger<div dir="ltr" style="text-align: left;" trbidi="on">
When we try to embed images uploaded in dropbox in your blog, when composing with Blogger.com.<br />
<br />
Your public link will not work. As your link may look as below -<br />
<br />
<span style="color: red;"><b><u>INCORRECT :</u></b> https://www.dropbox.com/s/fbgl0r024v4vmbd/Android%20N%20Error.png?dl=0</span><br />
<br />
This is not a actual link instead an embedded page. To resolve this you postfix ?raw=1 in your URL and the problem will be resolved.<br />
<br />
The new URL looks as below<br />
<br />
<span style="color: #38761d;"><b><u>CORRECT :</u> </b>https://www.dropbox.com/s/fbgl0r024v4vmbd/Android%20N%20Error.png<b>?<span style="background-color: yellow;">raw=1</span></b></span><br />
<span style="color: #38761d;"><b><span style="background-color: yellow;"><br /></span></b></span>
<b><span style="background-color: yellow;">Happy Blogging !!</span></b></div>
Anonymoushttp://www.blogger.com/profile/13196480231236274690noreply@blogger.com2tag:blogger.com,1999:blog-2002003343323875763.post-51727279741033365262016-07-29T05:35:00.001-07:002016-07-29T05:42:28.915-07:00[Android Studio] Solution : Android N requires the IDE to be running with JDK 1.8 <div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Android N Requires the IDE To be running with Java 1.8 or later. Install a supported JDK.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Eventhough we install the JDK 1.8, this error comes up, and we are not able to work on Design view of a Mobile Phone.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://www.dropbox.com/s/fbgl0r024v4vmbd/Android%20N%20Error.png?raw=1" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="388" src="https://www.dropbox.com/s/fbgl0r024v4vmbd/Android%20N%20Error.png?raw=1" width="640" /></a></div>
<br />
<br />
<br />
Solution to the Problem :<br />
<br />
Found a solution here<a href="http://stackoverflow.com/questions/35928580/android-n-requires-the-ide-to-be-running-with-java-1-8-or-later/35935433#35935433" target="_blank"> http://stackoverflow.com/questions/35928580/android-n-requires-the-ide-to-be-running-with-java-1-8-or-later/35935433#35935433</a><br />
<br />
<br />
<ul style="text-align: left;">
<li><span style="background-color: white; color: #242729; font-family: "arial" , "helvetica neue" , "helvetica" , sans-serif; font-size: 15px; line-height: 19px;">Quit Android Studio</span></li>
<li><span style="background-color: white; color: #242729; font-family: "arial" , "helvetica neue" , "helvetica" , sans-serif; font-size: 15px; line-height: 19px;">Edit the file </span><code style="background-color: #eff0f1; border: 0px; color: #242729; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; font-size: 13px; margin: 0px; padding: 1px 5px; white-space: pre-wrap;">/Applications/Android\ Studio.app/Contents/Info.plist</code><span style="background-color: white; color: #242729; font-family: "arial" , "helvetica neue" , "helvetica" , sans-serif; font-size: 15px; line-height: 19px;">, </span></li>
<li><span style="background-color: white; color: #242729; font-family: "arial" , "helvetica neue" , "helvetica" , sans-serif; font-size: 15px; line-height: 19px;">remove the versions and change it to 1.8</span></li>
<li><span style="color: #242729; font-family: "arial" , "helvetica neue" , "helvetica" , sans-serif;"><span style="background-color: white; font-size: 15px; line-height: 19px;">The changes in my file looks as below</span></span></li>
</ul>
<span style="font-family: "menlo"; font-size: 11px;"> <key>JVMVersion</key></span><br />
<span style="background-color: white; color: #242729; font-family: "menlo"; font-size: 11px;"> <string>1.8</string></span><br />
<br />
<ul style="text-align: left;">
<li>Restart Android Studio.</li>
</ul>
<div>
<br /></div>
<div>
Now the problem will be resolved in the Design view of the Activity View</div>
<br />
<br /></div>
Anonymoushttp://www.blogger.com/profile/13196480231236274690noreply@blogger.com0tag:blogger.com,1999:blog-2002003343323875763.post-76958730621314574872016-06-15T00:46:00.002-07:002016-06-15T00:46:48.621-07:00Run Pinned Shortcut in Taskbar as Administrator in Windows<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="_zXc" style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 16px; line-height: 19.2px; margin-bottom: 15px;">
<b>Luckily you can set Run as administrator option from the shortcut in this case.</b></div>
<div class="_yXc" style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 16px; line-height: 19.2px; padding: 0px 20px;">
<ol class="_jYe" style="border: 0px; margin: 0px; padding: 0px;">
<li class="_AXc" style="border: 0px; list-style: inherit; margin: 0px 0px 4px; padding: 0px;">Right-click the shortcut in your task bar.</li>
<li class="_AXc" style="border: 0px; list-style: inherit; margin: 0px 0px 4px; padding: 0px;">Right-click the program's name (say Command prompt for instance)</li>
<li class="_AXc" style="border: 0px; list-style: inherit; margin: 0px 0px 4px; padding: 0px;">Click on Properties.</li>
<li class="_AXc" style="border: 0px; list-style: inherit; margin: 0px 0px 4px; padding: 0px;">Click the Shortcut tab.</li>
<li class="_AXc" style="border: 0px; list-style: inherit; margin: 0px 0px 4px; padding: 0px;">Click the Advanced... ...</li>
<li class="_AXc" style="border: 0px; list-style: inherit; margin: 0px 0px 4px; padding: 0px;">Check the Run as administrator check box.</li>
<li class="_AXc" style="border: 0px; list-style: inherit; margin: 0px 0px 4px; padding: 0px;">Click the OK button.</li>
</ol>
</div>
</div>
Anonymoushttp://www.blogger.com/profile/13196480231236274690noreply@blogger.com0tag:blogger.com,1999:blog-2002003343323875763.post-45409558901006390192015-07-06T03:48:00.003-07:002015-07-06T03:49:22.787-07:00[MCU] Microcontroller Packaging <div dir="ltr" style="text-align: left;" trbidi="on">
<h4 style="text-align: left;">
QFN : Quad Flat No Leads:</h4>
These connect IC's to PCB's without through-holes.<br />
The figure shows with lead frame and wire bonding. <span style="background-color: white; color: #252525; font-family: sans-serif; font-size: 14px; line-height: 22px;">Flat no-lead packages include an exposed thermal pad to improve heat transfer out of the </span><a href="https://en.wikipedia.org/wiki/Integrated_circuit" style="background-image: none; color: #0b0080; font-family: sans-serif; font-size: 14px; line-height: 22px; text-decoration: none;" title="Integrated circuit">IC</a><span style="background-color: white; color: #252525; font-family: sans-serif; font-size: 14px; line-height: 22px;"> (into the PCB). Hand soldering is not possible with this package</span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi6uT3V844Baeihya4Alm4S_I_ZwvMjWlj9J9AwhshIkT1ctJhfhXuIBmuwrNxVJN1jd-4aXhXCVJzlZlD76lJmnCLx68ylewBfxVJmWG_zbVxyKy07Ll9-v11uB-Bn3JghQXx9DMWUG1fG/s1600/QFN.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi6uT3V844Baeihya4Alm4S_I_ZwvMjWlj9J9AwhshIkT1ctJhfhXuIBmuwrNxVJN1jd-4aXhXCVJzlZlD76lJmnCLx68ylewBfxVJmWG_zbVxyKy07Ll9-v11uB-Bn3JghQXx9DMWUG1fG/s200/QFN.jpg" width="200" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<br />
<br />
<h4 style="text-align: left;">
QFP: Quad Flat Package</h4>
A surface mounted IC, pins extending for all the 4 sides. <span style="background-color: white; color: #252525; font-family: sans-serif; font-size: 14px; line-height: 22px;">Socketing such packages is rare and through-hole mounting is not possible.</span><br />
<span style="background-color: white; color: #252525; font-family: sans-serif; font-size: 14px; line-height: 22px;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgbj9pVzuZRBJUV5GE9Nno2x47h67wY32wb2dTOxeYL6BVs5LJAwDHQJrdwA1qgRvoVBWBFB31PbwtwGxkQCqr0z4gLWkYMSrQcebYXaqpAFfiwkMdDNvJPbrLwFp5-P75qIF9mkOAuiRd6/s1600/qfp.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgbj9pVzuZRBJUV5GE9Nno2x47h67wY32wb2dTOxeYL6BVs5LJAwDHQJrdwA1qgRvoVBWBFB31PbwtwGxkQCqr0z4gLWkYMSrQcebYXaqpAFfiwkMdDNvJPbrLwFp5-P75qIF9mkOAuiRd6/s1600/qfp.png" /></a></div>
<br />
<br />
<h4 style="text-align: left;">
<span style="background-color: #f9f9f9; font-family: sans-serif; font-size: 14px; line-height: 22px;">LQFP: Low Profile Quad Flat Package (1.4mm)</span></h4>
<span style="background-color: #f9f9f9; font-family: sans-serif; font-size: 14px; line-height: 22px;"><br /></span>
<br />
<h4 style="text-align: left;">
<span style="background-color: #f9f9f9; font-family: sans-serif; font-size: 14px; line-height: 22px;">TQFP: Thin Quad Flat Package (1.0 mm) </span></h4>
<span style="background-color: #f9f9f9; font-family: sans-serif; font-size: 14px; line-height: 22px;">Has shorter leads than the LQFP. To be used in a space constrained designs.</span><br />
<span style="font-family: sans-serif;"><span style="background-color: #f9f9f9; font-size: 14px; line-height: 22px;">Helps in solving increased board density.</span></span><br />
<br />
<h4 style="text-align: left;">
<span style="background-color: #f9f9f9; font-family: sans-serif; font-size: 14px; line-height: 22px;">References</span></h4>
https://en.wikipedia.org/wiki/Quad_Flat_No-leads_package<br />
https://en.wikipedia.org/wiki/Quad_Flat_Package<br />
<br />
<br /></div>
Anonymoushttp://www.blogger.com/profile/13196480231236274690noreply@blogger.com4tag:blogger.com,1999:blog-2002003343323875763.post-19392586660230877392015-06-12T03:33:00.003-07:002015-06-12T03:33:39.894-07:00[Exploring Freescale MCU Programming] #5 RTC (Real time clock) set and Time and alarm<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: Verdana, sans-serif; font-size: x-small;">#2 - next one in my pipeline is Realtime Clock (RTC) initialize and get it working.</span><br />
<div>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span></div>
<div>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><b><u>What is RTC?</u></b></span></div>
<div>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span></div>
<div>
<span style="font-family: Verdana, sans-serif; font-size: x-small;">1. <a href="http://en.wikipedia.org/wiki/Real-time_clock" target="_blank">Wikipedia</a></span></div>
<div>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span></div>
<div>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><span style="background-color: white; color: #252525; line-height: 24.8888893127441px;">A </span><b style="background-color: white; color: #252525; line-height: 24.8888893127441px;">real-time clock</b><span style="background-color: white; color: #252525; line-height: 24.8888893127441px;"> (</span><b style="background-color: white; color: #252525; line-height: 24.8888893127441px;">RTC</b><span style="background-color: white; color: #252525; line-height: 24.8888893127441px;">) is a </span><a href="http://en.wikipedia.org/wiki/Computer" style="background: none rgb(255, 255, 255); color: #0b0080; line-height: 24.8888893127441px; text-decoration: none;" title="Computer">computer</a><span style="background-color: white; color: #252525; line-height: 24.8888893127441px;"> </span><a href="http://en.wikipedia.org/wiki/Clock" style="background: none rgb(255, 255, 255); color: #0b0080; line-height: 24.8888893127441px; text-decoration: none;" title="Clock">clock</a><span style="background-color: white; color: #252525; line-height: 24.8888893127441px;"> (most often in the form of an </span><a href="http://en.wikipedia.org/wiki/Integrated_circuit" style="background: none rgb(255, 255, 255); color: #0b0080; line-height: 24.8888893127441px; text-decoration: none;" title="Integrated circuit">integrated circuit</a><span style="background-color: white; color: #252525; line-height: 24.8888893127441px;">) that keeps track of the current </span><a href="http://en.wikipedia.org/wiki/Time" style="background: none rgb(255, 255, 255); color: #0b0080; line-height: 24.8888893127441px; text-decoration: none;" title="Time">time</a><span style="background-color: white; color: #252525; line-height: 24.8888893127441px;">. Although the term often refers to the devices in </span><a href="http://en.wikipedia.org/wiki/Personal_computer" style="background: none rgb(255, 255, 255); color: #0b0080; line-height: 24.8888893127441px; text-decoration: none;" title="Personal computer">personal computers</a><span style="background-color: white; color: #252525; line-height: 24.8888893127441px;">,</span><a href="http://en.wikipedia.org/wiki/Server_(computing)" style="background: none rgb(255, 255, 255); color: #0b0080; line-height: 24.8888893127441px; text-decoration: none;" title="Server (computing)">servers</a><span style="background-color: white; color: #252525; line-height: 24.8888893127441px;"> and </span><a href="http://en.wikipedia.org/wiki/Embedded_system" style="background: none rgb(255, 255, 255); color: #0b0080; line-height: 24.8888893127441px; text-decoration: none;" title="Embedded system">embedded systems</a><span style="background-color: white; color: #252525; line-height: 24.8888893127441px;">, RTCs are present in almost any electronic device which needs to keep accurate time.</span></span></div>
<div>
<h3 style="text-align: left;">
<span style="background-color: white; color: #252525; line-height: 24.8888893127441px;"><span style="font-family: Verdana, sans-serif; font-size: x-small;"><u>RTC in K20D Freescale Board</u></span></span></h3>
</div>
<div>
<br />
<div class="page" title="Page 10">
<div class="layoutArea">
<div class="column">
<span style="font-family: Verdana, sans-serif; font-size: x-small;">The Real Time Clock (RTC) module on the K20 has two modes of operation, system power‐up and system power‐
down. In system power‐up mode, the RTC may be powered by either the MCU regulator or the backup power
supply, VBAT. During system power‐down, the RTC is only powered from the backup power supply, VBAT</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;">I have used RTC with a FRDM-K20D50 Board to schedule an alarm at regular intervals.</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;">The CPU Settings should enable the RTC Oscillator. Otherwise RTC will not work.</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjVmlYwprjEvr1Dp6ZKIFc0E1JCUm_nxynZ8evL_EtjyrMMjDU1g0IQRdUOUsuCLGZW1pRrIiJfhq8-uRStk9I8YmydC6zn6E610-OPSisEzMwkWO96j-6gSFVxLlDzdZJmGxGPpckX4JP_/s1600/CPU-RTC-Enabled.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="403" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjVmlYwprjEvr1Dp6ZKIFc0E1JCUm_nxynZ8evL_EtjyrMMjDU1g0IQRdUOUsuCLGZW1pRrIiJfhq8-uRStk9I8YmydC6zn6E610-OPSisEzMwkWO96j-6gSFVxLlDzdZJmGxGPpckX4JP_/s640/CPU-RTC-Enabled.png" width="640" /></a></div>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span><span style="font-family: Verdana, sans-serif; font-size: x-small;">RTC Component added.</span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2Eyl6x9cTZ8EwucdxL40FW5UvgjdppwqImqHmlHfswJf0UodYVvJaKcTqWBZAB_48S8IDxSwYovDfnDa98b0-6mbo1E2wrLx9pVgN_RUXNSMgpbNOFgZyxZs-D2K1UE9AuOKmi9hBfd4H/s1600/RTC-Add-Component.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="496" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2Eyl6x9cTZ8EwucdxL40FW5UvgjdppwqImqHmlHfswJf0UodYVvJaKcTqWBZAB_48S8IDxSwYovDfnDa98b0-6mbo1E2wrLx9pVgN_RUXNSMgpbNOFgZyxZs-D2K1UE9AuOKmi9hBfd4H/s640/RTC-Add-Component.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
Setting Properties for the RTC Component<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsXHPEIqsDBU8LYT6STiurDiPe_KzUHmWyFwrsb9m7Dai0VLtSGIe_SGfaKAic5BtKVznQMhos3_CXLhE78qrfLwnUt2mY022Mo3LFVar3AFMdCK9VnWit8a-IluWuchkUaX7bBGP20le4/s1600/RTC-Set+properties.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="450" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsXHPEIqsDBU8LYT6STiurDiPe_KzUHmWyFwrsb9m7Dai0VLtSGIe_SGfaKAic5BtKVznQMhos3_CXLhE78qrfLwnUt2mY022Mo3LFVar3AFMdCK9VnWit8a-IluWuchkUaX7bBGP20le4/s640/RTC-Set+properties.png" width="640" /></a></div>
<br />
<br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;">Now lets add the code to set the RTC time and get it back, the main.c</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<br />
<h4 style="text-align: left;">
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><u>Code to set and get time</u></span></h4>
<span style="color: #793d93; font-family: 'Courier New'; font-size: 10px;"><b>printf</b></span><span style="font-family: 'Courier New'; font-size: 10px;">(</span><span style="color: #3933ff; font-family: 'Courier New'; font-size: 10px;">"--Test </span><span style="color: #3933ff; font-family: 'Courier New'; font-size: 10px; text-decoration: underline;">init</span><span style="color: #3933ff; font-family: 'Courier New'; font-size: 10px;">--\n"</span><span style="font-family: 'Courier New'; font-size: 10px;">);</span><br />
<div style="color: #006141; font-family: 'Courier New'; font-size: 10px;">
LDD_RTC_TTime<span style="color: black;"> ttime;</span></div>
<div style="font-family: 'Courier New'; font-size: 10px;">
ttime.<span style="color: #0326cc;">Day</span> = 11;</div>
<div style="font-family: 'Courier New'; font-size: 10px;">
ttime.<span style="color: #0326cc;">Month</span> = 06;</div>
<div style="font-family: 'Courier New'; font-size: 10px;">
ttime.<span style="color: #0326cc;">Year</span> = 2015;</div>
<div style="font-family: 'Courier New'; font-size: 10px;">
ttime.<span style="color: #0326cc;">Hour</span> = 17;</div>
<div style="font-family: 'Courier New'; font-size: 10px;">
ttime.<span style="color: #0326cc;">Minute</span> = 45;</div>
<div style="font-family: 'Courier New'; font-size: 10px;">
ttime.<span style="color: #0326cc;">Second</span> = 15;</div>
<div style="font-family: 'Courier New'; font-size: 10px; min-height: 11px;">
<br /></div>
<div style="font-family: 'Courier New'; font-size: 10px;">
RTC1_SetTime(NULL, &ttime);</div>
<div style="font-family: 'Courier New'; font-size: 10px; min-height: 11px;">
<br />
<br />
<span style="color: #931a68;"><b>int</b></span> i;<br />
<span style="color: #931a68;"><b>for</b></span>(i=1;i<=3000000;i++)<br />
{<br />
<div style="min-height: 11px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span></div>
<br />
}<br />
<br /></div>
<div style="color: #006141; font-family: 'Courier New'; font-size: 10px;">
LDD_RTC_TTime<span style="color: black;"> ttime1;</span></div>
<div style="font-family: 'Courier New'; font-size: 10px;">
RTC1_GetTime(NULL, &ttime1);</div>
<div style="font-family: 'Courier New'; font-size: 10px; min-height: 11px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span></div>
<br />
<div style="font-family: 'Courier New'; font-size: 10px;">
<span style="color: #793d93; text-decoration: underline;"><b>printf</b></span><span style="text-decoration: underline;">(</span><span style="color: #3933ff; text-decoration: underline;">"%d-%d-%d %d:%d:%d\n"</span><span style="text-decoration: underline;">, ttime1.</span><span style="color: #0326cc; text-decoration: underline;">Day</span><span style="text-decoration: underline;">, ttime1.</span><span style="color: #0326cc; text-decoration: underline;">Month</span><span style="text-decoration: underline;">, ttime1.</span><span style="color: #0326cc; text-decoration: underline;">Year</span><span style="text-decoration: underline;">, ttime1.</span><span style="color: #0326cc; text-decoration: underline;">Hour</span><span style="text-decoration: underline;">, ttime1.</span><span style="color: #0326cc; text-decoration: underline;">Minute</span><span style="text-decoration: underline;">, ttime1.</span><span style="color: #0326cc; text-decoration: underline;">Second</span><span style="text-decoration: underline;">);</span></div>
<div style="font-family: 'Courier New'; font-size: 10px;">
<span style="text-decoration: underline;"><br /></span></div>
<div style="font-family: 'Courier New'; font-size: 10px;">
<span style="text-decoration: underline;"><br /></span></div>
<div style="font-family: 'Courier New'; font-size: 10px;">
<span style="text-decoration: underline;"><br /></span></div>
<h4 style="text-align: left;">
<span style="text-decoration: underline;">Output</span></h4>
<div style="font-family: 'Courier New'; font-size: 9px;">
--Test init--</div>
<div style="font-family: 'Courier New'; font-size: 10px;">
</div>
<div style="font-family: 'Courier New'; font-size: 9px;">
11-6-2015 17:45:16<br />
<br /></div>
<div style="font-family: 'Courier New'; font-size: 9px;">
<br /></div>
<div>
- Printed the RTC time that is set</div>
<div>
<br /></div>
<h4 style="text-align: left;">
<u>Lets try setting RTC alarm and triggering it</u></h4>
<div>
<div>
Enable the methods setAlarm and enable onAlarm Event and generate code</div>
</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLuCU7vJxYFHV7aLBBzoVITJRfMhXtnjGVRqXjvMb0iKefMeVxKIphDXDnqUjfaobTlSB_2ExVOGSjQUnhQYjElZQ1SKEmROuCJK52ijuXdumqKn8ZJ4Rz7xz3Cyz2ZIJtLh2vEg-j6IS9/s1600/RTC_Enable_alarm.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="244" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLuCU7vJxYFHV7aLBBzoVITJRfMhXtnjGVRqXjvMb0iKefMeVxKIphDXDnqUjfaobTlSB_2ExVOGSjQUnhQYjElZQ1SKEmROuCJK52ijuXdumqKn8ZJ4Rz7xz3Cyz2ZIJtLh2vEg-j6IS9/s320/RTC_Enable_alarm.png" width="320" /></a></div>
<div>
<br /></div>
<div>
<br />
<h4 style="text-align: left;">
main.c</h4>
<div style="font-family: 'Courier New'; font-size: 10px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>ttime1.<span style="color: #0326cc;">Second</span> += 30;</div>
<br />
<div style="font-family: 'Courier New'; font-size: 10px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>RTC1_SetAlarm(NULL, &ttime);</div>
<br />
<h4 style="text-align: left;">
Event.c</h4>
<div style="font-family: 'Courier New'; font-size: 10px;">
<span style="color: #931a68;"><b>void</b></span> <b>RTC1_OnAlarm</b>(<span style="color: #006141;">LDD_TUserData</span> *UserDataPtr)</div>
<div style="font-family: 'Courier New'; font-size: 10px;">
{</div>
<div style="color: #3933ff; font-family: 'Courier New'; font-size: 10px;">
<span style="color: black;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="color: #793d93;"><b>printf</b></span><span style="color: black;">(</span>"---Alarm Triggered--\n"<span style="color: black;">);</span></div>
<div style="font-family: 'Courier New'; font-size: 10px; min-height: 11px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span></div>
<div style="color: #006141; font-family: 'Courier New'; font-size: 10px;">
<span style="color: black;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span>LDD_RTC_TTime<span style="color: black;"> ttime1;</span></div>
<div style="font-family: 'Courier New'; font-size: 10px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>RTC1_GetTime(NULL, &ttime1);</div>
<div style="font-family: 'Courier New'; font-size: 10px; min-height: 11px;">
<br /></div>
<div style="font-family: 'Courier New'; font-size: 10px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span><span style="color: #793d93;"><b>printf</b></span>(<span style="color: #3933ff;">"%d-%d-%d %d:%d:%d\n"</span>, ttime1.<span style="color: #0326cc;">Day</span>, ttime1.<span style="color: #0326cc;">Month</span>, ttime1.<span style="color: #0326cc;">Year</span>,</div>
<div style="color: #3933ff; font-family: 'Courier New'; font-size: 10px;">
</div>
<div style="font-family: 'Courier New'; font-size: 10px;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>ttime1.<span style="color: #0326cc;">Hour</span>, ttime1.<span style="color: #0326cc;">Minute</span>, ttime1.<span style="color: #0326cc;">Second</span>);</div>
<br />
<div style="font-family: 'Courier New'; font-size: 10px;">
}</div>
<div style="font-family: 'Courier New'; font-size: 10px;">
<br /></div>
<div style="font-family: 'Courier New'; font-size: 10px;">
<br /></div>
<h4>
Output after alarm</h4>
<div style="font-family: 'Courier New'; font-size: 10px;">
<br /></div>
<div style="font-family: 'Courier New'; font-size: 9px;">
---Alarm Triggered--</div>
<div style="font-family: 'Courier New'; font-size: 10px;">
</div>
<div style="font-family: 'Courier New'; font-size: 9px;">
11-6-2015 17:45:26</div>
<div>
<br /></div>
<div style="font-family: 'Courier New'; font-size: 10px;">
<br /></div>
<h4>
Project:</h4>
</div>
<div>
<a href="https://www.dropbox.com/s/mwj9hq9mj7b4jaj/RTC.zip?dl=0" target="_blank">Project</a></div>
<div>
<br /></div>
</div>
</div>
</div>
</div>
</div>
Anonymoushttp://www.blogger.com/profile/13196480231236274690noreply@blogger.com0tag:blogger.com,1999:blog-2002003343323875763.post-29293223078245016032015-05-20T07:28:00.002-07:002016-02-29T04:04:55.642-08:00[Codewarrior 10.6 Solution] printf(%f) Does not work<div dir="ltr" style="text-align: left;" trbidi="on">
printf("-Value %f\n", floatValue) - prints -Value %f as such, instead of the float value in the console.<br />
<br />
Solution : Change a project settings<br />
<br />
<b>Project -> Properties -> C/C++ Build -> Settings -> Tool Settings Tab -> Librarian -> </b><br />
<br />
Change<span style="background-color: yellow;"> print formats to int_FP </span><br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiG6Kn8tpOyR-COJjFiO2nfsTfouM8xuFf-DnPWlDs_P4RhxSkJbL4uWC3_aC0imkkX-gk-Kn-VI2U_nSfkmfgXsnCwwhz3rVcv9nQbacytGsJNn9OC9Sn0NNC7BOabvtSjcC9tHAZxanCu/s1600/floating+point.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="203" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiG6Kn8tpOyR-COJjFiO2nfsTfouM8xuFf-DnPWlDs_P4RhxSkJbL4uWC3_aC0imkkX-gk-Kn-VI2U_nSfkmfgXsnCwwhz3rVcv9nQbacytGsJNn9OC9Sn0NNC7BOabvtSjcC9tHAZxanCu/s640/floating+point.png" width="640" /></a></div>
<br /></div>
Anonymoushttp://www.blogger.com/profile/13196480231236274690noreply@blogger.com0tag:blogger.com,1999:blog-2002003343323875763.post-5144501027779854312015-04-30T09:34:00.002-07:002015-04-30T09:36:05.690-07:00[Freescale K20D50M MCU Programming] #4 External LED controlled by a GPIO Switch<div dir="ltr" style="text-align: left;" trbidi="on">
<h2>
<span style="font-family: Verdana, sans-serif; font-size: x-small;">#4 External LED controlled by a GPIO Switch</span></h2>
<span style="font-family: Verdana, sans-serif; font-size: x-small;">We tried blinking of an LED. Now we will create a switch using one of the GPIO Pins. The Reset Button in FRDM-K20D50 does not have an alternate function. Hence I wanted to try out a Input switch.</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span><span style="font-family: Verdana, sans-serif; font-size: x-small;">Take a look at the <a href="http://techie-experience.blogspot.com/2015/04/exploring-freescale-mcu-programming-1.html" target="_blank">[Freescale K20D50M MCU Programming] #1 Helloworld on the Console using Processor Expert</a> </span><span style="font-family: Verdana, sans-serif; font-size: x-small;">for quickstart </span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span><span style="font-family: Verdana, sans-serif; font-size: x-small;">Lets get started.</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span><span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span><span style="font-family: Verdana, sans-serif; font-size: x-small;">First we need 2 things. </span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<br />
<ul style="text-align: left;">
<li><span style="font-family: Verdana, sans-serif; font-size: x-small;">Identify the PIN for the external LED and a ground pin</span></li>
<li><span style="font-family: Verdana, sans-serif; font-size: x-small;">then another PIN to act as a Switch Input and a ground pin</span></li>
</ul>
<br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;">I identified PTC0 and PTB2 respectively.</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-e7S9nNcHPK8/VUJU3oPvgSI/AAAAAAAAA1E/5ObuNqh1hOM/s1600/gpio_input.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: Verdana, sans-serif; font-size: x-small;"><img border="0" src="http://2.bp.blogspot.com/-e7S9nNcHPK8/VUJU3oPvgSI/AAAAAAAAA1E/5ObuNqh1hOM/s1600/gpio_input.png" height="640" width="464" /></span></a></div>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;">to see the <a href="http://cache.freescale.com/files/microcontrollers/hardware_tools/schematics/FRDM-K20D50M_SCH.pdf?fpsp=1" target="_blank">schematic </a>to identify the PINS. There is a good <a href="https://www.youtube.com/watch?v=AuiYUaHgSRo" target="_blank">youtube video</a> which gives an example on K25Z board.</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;">Next we will be adding the BITIO_LDD for the LDD configured to the PTC0 PIN.</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-l6f54wc23kI/VUJVkc60O2I/AAAAAAAAA1M/00plzYwSzpI/s1600/led_bitio_ldd.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: Verdana, sans-serif; font-size: x-small;"><img border="0" src="http://1.bp.blogspot.com/-l6f54wc23kI/VUJVkc60O2I/AAAAAAAAA1M/00plzYwSzpI/s1600/led_bitio_ldd.png" height="148" width="400" /></span></a></div>
<br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;">Then a BITIO_LDD for the switch on PTB2</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-_p2eXM_gZ4A/VUJWAC7LJHI/AAAAAAAAA1U/-0cYOkQesls/s1600/sw1_bitio_ldd.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: Verdana, sans-serif; font-size: x-small;"><img border="0" src="http://3.bp.blogspot.com/-_p2eXM_gZ4A/VUJWAC7LJHI/AAAAAAAAA1U/-0cYOkQesls/s1600/sw1_bitio_ldd.png" height="135" width="400" /></span></a></div>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;">Setting up the BITIO_LDD isn't enough for the acting with in PTB2. We need to initialize the GPIO for the PIN. We will add a init_GPIO component and configure it to PTB</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><a href="http://3.bp.blogspot.com/-4TtS2nS3RXk/VUJXAYmpGYI/AAAAAAAAA1g/zCqObSLm6O0/s1600/gpio_init.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://3.bp.blogspot.com/-4TtS2nS3RXk/VUJXAYmpGYI/AAAAAAAAA1g/zCqObSLm6O0/s1600/gpio_init.png" height="640" width="544" /></a></span></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: Verdana, sans-serif; font-size: x-small;">Generate the Pex code, and then add then lets add the below logic to toggle the led based on whether a wire between PTB2 and the GRND is connected or not..</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: Verdana, sans-serif; font-size: x-small;">The Pin's are connected to cathode, so 0 means high and 1 means low.</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: Verdana, sans-serif; font-size: x-small;">Code in main.c </span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span></div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="color: #931a68;"><b> for</b></span>(;;)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> <span style="color: #931a68;"><b>if</b></span>(SW1_GetVal(NULL)==0) // CONNECTED </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> {</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> led_SetVal(led_DeviceData);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> }</span><br />
<div style="color: #931a68;">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="color: black;"><span class="Apple-tab-span" style="white-space: pre;"> </span> </span><b>else</b></span></div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> {</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> led_ClrVal(led_DeviceData);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> }</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> WAIT1_Waitms(1000);</span><br />
<div class="separator" style="clear: both;">
</div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span><br />
<br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;">Now build the code and lets test it. </span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;">Here is how the pins are connected on the board</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-a1NL2eMvKEk/VUJYxSvHbGI/AAAAAAAAA1s/PLMPW2KnAVg/s1600/pins.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://1.bp.blogspot.com/-a1NL2eMvKEk/VUJYxSvHbGI/AAAAAAAAA1s/PLMPW2KnAVg/s1600/pins.jpg" height="320" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Now lets see what happens with ehe pins at PTB0 is connected, the red wires on the top side is connected.. and you see the LED glowing</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-fWXDzY-89Bw/VUJY9bffYGI/AAAAAAAAA10/whflCzvnNcw/s1600/connected.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://1.bp.blogspot.com/-fWXDzY-89Bw/VUJY9bffYGI/AAAAAAAAA10/whflCzvnNcw/s1600/connected.jpg" height="320" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Now lets see what happens when one of the wire on top is pulled out..</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-92-AfjMvMDI/VUJZMvDLPFI/AAAAAAAAA18/-tLZds6xQZ0/s1600/disconnected.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://2.bp.blogspot.com/-92-AfjMvMDI/VUJZMvDLPFI/AAAAAAAAA18/-tLZds6xQZ0/s1600/disconnected.jpg" height="320" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<span style="font-family: Verdana, sans-serif; font-size: x-small;">Do you see only 1 wire on top is connected, and the LED is off.</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;">This is an example of how you use a GPIO pin as a switch to control through software.</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<br />
<div style="font-family: 'Courier New'; font-size: 10px;">
<br /></div>
</div>
Anonymoushttp://www.blogger.com/profile/13196480231236274690noreply@blogger.com0tag:blogger.com,1999:blog-2002003343323875763.post-59417759739087930672015-04-22T22:43:00.001-07:002015-04-30T09:36:21.263-07:00[Freescale K20D50M MCU Programming] #3 Blinky GPIO - External LED<div dir="ltr" style="text-align: left;" trbidi="on">
<h2>
<span style="font-size: small;"><span style="font-family: Verdana, sans-serif;">#3 Blinky External </span><span style="font-family: Verdana, sans-serif;">LED</span><span style="font-family: Verdana, sans-serif;"> </span></span></h2>
<span style="font-family: Verdana, sans-serif;"><br /></span><span style="font-family: Verdana, sans-serif;">In <a href="http://techie-experience.blogspot.com/2015/04/freescale-k20d50m-mcu-programming-2.html" target="_blank">[Freescale K20D50M MCU Programming] #2 Blinky Red LED onboard</a>, We tried blinky with onboard LED. Lets try out blinking the external LED connected to a GPIO pin.. We are going to use Codewarrior and processorexpert with FRDM-K20D50M board</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span><span style="font-family: Verdana, sans-serif;">Take a look at the <a href="http://techie-experience.blogspot.com/2015/04/exploring-freescale-mcu-programming-1.html" target="_blank">[Freescale K20D50M MCU Programming] #1 Helloworld on the Console using Processor Expert</a> </span><span style="font-family: Verdana, sans-serif;">for quickstart </span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span><span style="font-family: Verdana, sans-serif;">Lets get started.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span><span style="font-family: Verdana, sans-serif;">First we need to see the <a href="http://cache.freescale.com/files/microcontrollers/hardware_tools/schematics/FRDM-K20D50M_SCH.pdf?fpsp=1" target="_blank">schematic </a>to identify the GPIO pin for our </span><span style="font-family: Verdana, sans-serif;">external</span><span style="font-family: Verdana, sans-serif;"> </span><span style="font-family: Verdana, sans-serif;">LED. There is a good</span><span style="font-family: Verdana, sans-serif;"> </span><a href="https://www.youtube.com/watch?v=AuiYUaHgSRo" style="font-family: Verdana, sans-serif;" target="_blank">youtube video</a><span style="font-family: Verdana, sans-serif;"> </span><span style="font-family: Verdana, sans-serif;">which gives an example on K25Z board.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-pZ8vss0OyFo/VTh-DX_JjrI/AAAAAAAAAz4/zIubHq1FoXM/s1600/schematic.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://1.bp.blogspot.com/-pZ8vss0OyFo/VTh-DX_JjrI/AAAAAAAAAz4/zIubHq1FoXM/s1600/schematic.png" height="134" width="640" /></a></div>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">and the pin connectivity as below</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-KclVKH8cfPE/VTiE2yC2-DI/AAAAAAAAA0Y/GHYpfHwmUV4/s1600/pin_connection.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://3.bp.blogspot.com/-KclVKH8cfPE/VTiE2yC2-DI/AAAAAAAAA0Y/GHYpfHwmUV4/s1600/pin_connection.png" height="640" width="476" /></a></div>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">Now Lets create a new project as mentioned in </span><a href="http://techie-experience.blogspot.com/2015/04/freescale-k20d50m-mcu-programming-2.html" style="font-family: Verdana, sans-serif;" target="_blank">[Freescale K20D50M MCU Programming] #2 Blinky Red LED onboard</a><span style="font-family: Verdana, sans-serif;"> we add a BITIO_LDD Component</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-nyFdwqtyPcE/VTh-j82Il2I/AAAAAAAAA0I/owoa4dGmoLA/s1600/BITIO_LDD.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://4.bp.blogspot.com/-nyFdwqtyPcE/VTh-j82Il2I/AAAAAAAAA0I/owoa4dGmoLA/s1600/BITIO_LDD.png" height="316" width="640" /></a></div>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">And setting the properties to <b><u>PTD0</u></b></span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-17HBGMRcOAA/VTh9aMsaxgI/AAAAAAAAAzw/7n5oZorBuns/s1600/ptd0.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://4.bp.blogspot.com/-17HBGMRcOAA/VTh9aMsaxgI/AAAAAAAAAzw/7n5oZorBuns/s1600/ptd0.png" height="270" width="640" /></a></div>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">I have added a WAIT custom component from processor expert to show a delay</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">And add this code in main.c</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="color: blue; font-family: Courier New, Courier, monospace;"> gpio_led_NegVal(NULL);</span><br />
<span style="color: blue; font-family: Courier New, Courier, monospace;"> WAIT1_Waitms(1000);</span><br />
<br />
<span style="color: blue; font-family: Courier New, Courier, monospace;"> gpio_led_NegVal(NULL);</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">And you see the external LED Blinking.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<iframe allowfullscreen='allowfullscreen' webkitallowfullscreen='webkitallowfullscreen' mozallowfullscreen='mozallowfullscreen' width='320' height='266' src='https://www.blogger.com/video.g?token=AD6v5dxl8Ln33cmvzCeyCvL5lTtDIEz3WevlJsl2JoPux1xyGZaKTwJNu4FU3cl0ExBGZEwCvg-ficChUAMmqqhb' class='b-hbp-video b-uploaded' frameborder='0'></iframe></div>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span></div>
Anonymoushttp://www.blogger.com/profile/13196480231236274690noreply@blogger.com0tag:blogger.com,1999:blog-2002003343323875763.post-46397185470165712342015-04-15T09:33:00.001-07:002015-04-15T09:42:33.487-07:00[Freescale K20D50M MCU Programming] #2 Blinky Red LED onboard <div dir="ltr" style="text-align: left;" trbidi="on">
<h2 style="text-align: left;">
<span style="font-family: Verdana, sans-serif; font-size: x-small;">#2 Blinky Red LED onboard</span></h2>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;">Lets try out blinking the RED onboard LED. We are going to use Codewarrior and processorexpert with FRDM-K20D50M board</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;">Take a look at the <a href="http://techie-experience.blogspot.com/2015/04/exploring-freescale-mcu-programming-1.html" target="_blank">[Freescale K20D50M MCU Programming] #1 Helloworld on the Console using Processor Expert</a> </span><span style="font-family: Verdana, sans-serif; font-size: x-small;">for quickstart </span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;">Lets get started.</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;">First we need to see the <a href="http://cache.freescale.com/files/microcontrollers/hardware_tools/schematics/FRDM-K20D50M_SCH.pdf?fpsp=1" target="_blank">schematic </a>to identify the onboard LED. There is a good <a href="https://www.youtube.com/watch?v=AuiYUaHgSRo" target="_blank">youtube video</a> which gives an example on K25Z board.</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<br />
<h3 style="text-align: left;">
<span style="font-family: Verdana, sans-serif; font-size: x-small;">LED </span><span style="font-family: Verdana, sans-serif; font-size: x-small;">Schematic :</span></h3>
<br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-7FbgpcLK7PU/VS04O-b_nHI/AAAAAAAAAxE/-IFgNTttp8Y/s1600/LED.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://1.bp.blogspot.com/-7FbgpcLK7PU/VS04O-b_nHI/AAAAAAAAAxE/-IFgNTttp8Y/s1600/LED.png" /></a></div>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span><span style="font-family: Verdana, sans-serif; font-size: x-small;">Red LED connected to D6.</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;">Green LED connected to D3</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;">Blue LED connected to D9</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<br />
<h3 style="text-align: left;">
<span style="font-family: Verdana, sans-serif; font-size: x-small;">Identify the Ports and Pins for the LED's :</span></h3>
<br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;">Red, look for D6</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-t799uxcI3n8/VS09W-FXGzI/AAAAAAAAAxU/B4b5DJq73F0/s1600/red.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://1.bp.blogspot.com/-t799uxcI3n8/VS09W-FXGzI/AAAAAAAAAxU/B4b5DJq73F0/s1600/red.png" height="125" width="640" /></a></div>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><b><u>Green, Look for D3</u></b></span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-9Gq5e_EOqzI/VS09hN4CLcI/AAAAAAAAAxc/nxj_YVUQOjw/s1600/green.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://1.bp.blogspot.com/-9Gq5e_EOqzI/VS09hN4CLcI/AAAAAAAAAxc/nxj_YVUQOjw/s1600/green.png" height="136" width="640" /></a></div>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><b><u>Blue, Look for D9</u></b></span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-F0clK9Pdiaw/VS09tP_n-sI/AAAAAAAAAxs/KGCGb8O6xPw/s1600/blue.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://3.bp.blogspot.com/-F0clK9Pdiaw/VS09tP_n-sI/AAAAAAAAAxs/KGCGb8O6xPw/s1600/blue.png" height="102" width="640" /></a></div>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;">The FRDM-K20D50 CPU uses the Blue LED. So, this has to be disabled to get this on-board LED to work.</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-W0YMGejaXUU/VS4j6Oh5XBI/AAAAAAAAAyA/A97woASGD6s/s1600/disable_blue_led.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://4.bp.blogspot.com/-W0YMGejaXUU/VS4j6Oh5XBI/AAAAAAAAAyA/A97woASGD6s/s1600/disable_blue_led.png" height="186" width="640" /></a></div>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;">Then Lets add BITIO_LDD component, 1 for each LED to control them.</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;">Now lets setup the Bit_IO pins for the 3 LED's. LED Cathode is connected to the microcontroller pin. i.e., Low Level (0) turns it on, and (1) turns it off. By default we need to set all the 3 LED's to (1) to turn it off.</span><br />
<div>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span></div>
<div>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span></div>
<div>
<span style="font-family: Verdana, sans-serif; font-size: x-small;">WE add 3 BitIO_LDD Components, for RED, Green and Blue. </span></div>
<div>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span></div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-77a1MntEyNs/VS4kcmbiQsI/AAAAAAAAAyY/B4DaUBdemxU/s1600/BITIO_LDD.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://1.bp.blogspot.com/-77a1MntEyNs/VS4kcmbiQsI/AAAAAAAAAyY/B4DaUBdemxU/s1600/BITIO_LDD.png" height="197" width="400" /></a></div>
<div>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span></div>
<div>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span></div>
<div>
<span style="font-family: Verdana, sans-serif; font-size: x-small;">Green LED -> Switch off by Default. Cathode connected. So 1 is Off</span></div>
<div>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-AgyTNjSj4xY/VS4kRYK5VrI/AAAAAAAAAyQ/eHBAsC7btu8/s1600/green_led.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://4.bp.blogspot.com/-AgyTNjSj4xY/VS4kRYK5VrI/AAAAAAAAAyQ/eHBAsC7btu8/s1600/green_led.png" height="162" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<span style="font-family: Verdana, sans-serif; font-size: x-small;">Blue LED -> Switch off by Default. Cathode connected. So 1 is Off. But this pin is used by CPU, so enable PIN Sharing.</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-Dls8rgs8mQs/VS4kKusawKI/AAAAAAAAAyI/B2bCrOpM3v4/s1600/blue_led.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://1.bp.blogspot.com/-Dls8rgs8mQs/VS4kKusawKI/AAAAAAAAAyI/B2bCrOpM3v4/s1600/blue_led.png" height="145" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-kEYvOcmkY5k/VS5A-dMgZiI/AAAAAAAAAy4/Q7rhdNJICfY/s1600/pin_shared.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://3.bp.blogspot.com/-kEYvOcmkY5k/VS5A-dMgZiI/AAAAAAAAAy4/Q7rhdNJICfY/s1600/pin_shared.png" height="158" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="font-family: Verdana, sans-serif; font-size: x-small; text-align: left;">Red LED -> Switch ON by Default. Cathode connected. So 0 is On.</span></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-VFXANs60Xgk/VS4ktQrLOaI/AAAAAAAAAyo/fTOdT7imZw0/s1600/red_led.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://2.bp.blogspot.com/-VFXANs60Xgk/VS4ktQrLOaI/AAAAAAAAAyo/fTOdT7imZw0/s1600/red_led.png" height="132" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;">Now build and Run the Main.c you will see the RED LED glowing by the code is flashed.</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-UH0ozob_844/VS6P51F6V4I/AAAAAAAAAzI/cHBw75Zd_lU/s1600/FullSizeRender.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://3.bp.blogspot.com/-UH0ozob_844/VS6P51F6V4I/AAAAAAAAAzI/cHBw75Zd_lU/s1600/FullSizeRender.jpg" height="320" width="232" /></a></div>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br />Now lets make a blinky. :-)</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;">We need to enable the NegVal() method of the BitIO_LDD</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-PQASaWeWqkM/VS6RrBB7XJI/AAAAAAAAAzU/K3ABSIohtHU/s1600/negVal.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://2.bp.blogspot.com/-PQASaWeWqkM/VS6RrBB7XJI/AAAAAAAAAzU/K3ABSIohtHU/s1600/negVal.png" height="179" width="640" /></a></div>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;">And add this code in the main.c or processorexpert.c</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">int main(void)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">/*lint -restore Enable MISRA rule (6.3) checking. */</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> /* Write your local variable definition here */</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> PE_low_level_init();</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> /*** End of Processor Expert internal initialization. ***/</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> <span style="color: blue;"> <b>for(;;)</b></span></span><br />
<span style="color: blue; font-family: Courier New, Courier, monospace; font-size: xx-small;"><b> {</b></span><br />
<span style="color: blue; font-family: Courier New, Courier, monospace; font-size: xx-small;"><b><span class="Apple-tab-span" style="white-space: pre;"> </span> int i =0;</b></span><br />
<span style="color: blue; font-family: Courier New, Courier, monospace; font-size: xx-small;"><b><span class="Apple-tab-span" style="white-space: pre;"> </span> for(i=0;i<=1000000;i++)</b></span><br />
<span style="color: blue; font-family: Courier New, Courier, monospace; font-size: xx-small;"><b><span class="Apple-tab-span" style="white-space: pre;"> </span> {</b></span><br />
<span style="color: blue; font-family: Courier New, Courier, monospace; font-size: xx-small;"><b><span class="Apple-tab-span" style="white-space: pre;"> </span> }</b></span><br />
<span style="color: blue; font-family: Courier New, Courier, monospace; font-size: xx-small;"><b><span class="Apple-tab-span" style="white-space: pre;"> </span> RED_LED_NegVal(NULL); <span style="background-color: cyan;">// Blink the RED Led</span></b></span><br />
<span style="color: blue; font-family: Courier New, Courier, monospace; font-size: xx-small;"><b> }</b></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> </span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"></span><span style="font-family: Verdana, sans-serif; font-size: x-small;">Here is the blinky.</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<iframe allowfullscreen='allowfullscreen' webkitallowfullscreen='webkitallowfullscreen' mozallowfullscreen='mozallowfullscreen' width='320' height='266' src='https://www.blogger.com/video.g?token=AD6v5dzVRyAl7jFl323Z5scjnBm_8D8GYNBY-d3oc3wGnurYqiDHjaia_lgcH069jXwifKaIR2uagfP0aCBUH8C7HA' class='b-hbp-video b-uploaded' frameborder='0'></iframe></div>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;">CodeWarrior, PEX Project : <a href="https://www.dropbox.com/s/eavc3as140ubftw/onboard_blinky.zip?dl=0" target="_blank">Download onboard_blinky.zip</a></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span></div>
Anonymoushttp://www.blogger.com/profile/13196480231236274690noreply@blogger.com0tag:blogger.com,1999:blog-2002003343323875763.post-24198623226464453652015-04-04T00:56:00.000-07:002016-02-29T04:16:26.309-08:00[Freescale K20D50M MCU Programming] #1 Helloworld on the Console using Processor Expert.<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;">Just starting exploring the world of MCU programming. I was referred a <a href="http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=FRDM-K20D50M" target="_blank">freescale board K20D50M</a></span><br />
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEik-gJmWty3TOQQlKI4hdqZBtp2M4dxT7KKVmKFUQwuJuPQZYXzupuQzAqKlipVeKjVd21QcPWX3x6pvO7Dh6yqdHiOTpVp6aSd9ftGi8b4YPfztLlcKtpVqgFSn_sCGqT9H3PB9GgHqqjm/s1600/2294097-40.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEik-gJmWty3TOQQlKI4hdqZBtp2M4dxT7KKVmKFUQwuJuPQZYXzupuQzAqKlipVeKjVd21QcPWX3x6pvO7Dh6yqdHiOTpVp6aSd9ftGi8b4YPfztLlcKtpVqgFSn_sCGqT9H3PB9GgHqqjm/s1600/2294097-40.jpg" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small; margin-left: 1em; margin-right: 1em;"></span></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: justify;">
<span style="text-align: left;"><span style="font-family: "verdana" , sans-serif; font-size: x-small;">Being a hardcore java/j2ee developer, Looking at this was little scary. Followed the steps in <a href="http://cache.freescale.com/files/32bit/software/board_support_packages/FRDM-K20D50M_QSP.zip?fpsp=1" target="_blank">QuickStart package</a> in a OpenSDA Mode. Now comes the time to write some code. I was told that Processor Expert in Codewarrior can do wonders. You do not need to be a hardcore Embedded developer who knows Bits/Registers/MUXing. ;-)</span></span></div>
<div class="separator" style="clear: both; text-align: justify;">
<span style="text-align: left;"><span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></span></div>
<div class="separator" style="clear: both; text-align: justify;">
<span style="text-align: left;"><span style="font-family: "verdana" , sans-serif; font-size: x-small;">As a beginner. Codewarrior is the best place to start with. Code, test the device from one place. Later you can jump into the Processor Expert Driver suite to write code, while to test you need to use IAR workbench for Kinetics or a Kinetics Design Studio.</span></span></div>
<div class="separator" style="clear: both; text-align: justify;">
<span style="text-align: left;"><span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></span></div>
<div class="separator" style="clear: both; text-align: justify;">
<span style="text-align: left;"><span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></span></div>
<h3 style="clear: both; text-align: justify;">
<span style="text-align: left;"><span style="font-family: "verdana" , sans-serif; font-size: x-small;">Tools you need </span></span></h3>
<div class="separator" style="clear: both; text-align: justify;">
<span style="text-align: left;"><span style="font-family: "verdana" , sans-serif; font-size: x-small;">1. FRDM-K20D50M board</span></span></div>
<div class="separator" style="clear: both; text-align: justify;">
<span style="text-align: left;"><span style="font-family: "verdana" , sans-serif; font-size: x-small;">2. <a href="http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=CW-MCU10#" target="_blank">Codewarrior </a>or other similar tools</span></span></div>
<div class="separator" style="clear: both; text-align: justify;">
<span style="text-align: left;"><span style="font-family: "verdana" , sans-serif; font-size: x-small;">3. <a href="http://realterm.sourceforge.net/index.html#downloads_Download" target="_blank">Realterm</a> - Terminal viewer tool</span></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;">Assuming, you got your openSDA configuration done on the bootloader mode. </span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;">Lets get into action. </span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></div>
<h3 style="clear: both; text-align: left;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;">Create a Bareboard Project -</span></h3>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-7m1AY2tAT88/VR92WsreHaI/AAAAAAAAAtA/_IiwNl3I8mU/s1600/project.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: "verdana" , sans-serif; font-size: x-small;"><img border="0" height="167" src="https://4.bp.blogspot.com/-7m1AY2tAT88/VR92WsreHaI/AAAAAAAAAtA/_IiwNl3I8mU/s1600/project.png" width="400" /></span></a></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></div>
<h3 style="clear: both; text-align: left;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;">Name the project</span></h3>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-RANgbtyKgJI/VR92xbeo3GI/AAAAAAAAAtI/ThDd790E3c4/s1600/2-project.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: "verdana" , sans-serif; font-size: x-small;"><img border="0" height="170" src="https://4.bp.blogspot.com/-RANgbtyKgJI/VR92xbeo3GI/AAAAAAAAAtI/ThDd790E3c4/s1600/2-project.png" width="400" /></span></a></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></div>
<h3 style="clear: both; text-align: left;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;">Select the device - K20D50 - <span style="background-color: yellow;">MK20DX128:</span></span></h3>
<div class="separator" style="clear: both; text-align: left;">
<span style="background-color: yellow;"><span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></span></div>
<div class="separator" style="clear: both; text-align: left;">
<a href="http://2.bp.blogspot.com/-390sZNsuK6c/VR93F8qdJcI/AAAAAAAAAtQ/-zZzN0O217U/s1600/3-device.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em; text-align: center;"><span style="font-family: "verdana" , sans-serif; font-size: x-small;"><img border="0" height="275" src="https://2.bp.blogspot.com/-390sZNsuK6c/VR93F8qdJcI/AAAAAAAAAtQ/-zZzN0O217U/s1600/3-device.png" width="400" /></span></a></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="background-color: yellow;"><span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="background-color: yellow;"><span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="background-color: yellow;"><span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></span></div>
<h3 style="clear: both; text-align: left;">
<span style="background-color: white;"><span style="font-family: "verdana" , sans-serif; font-size: x-small;">Select Connections :</span></span></h3>
<div class="separator" style="clear: both; text-align: left;">
<span style="background-color: white;"><span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-SRMx1qWNjrI/VR939Gs7D_I/AAAAAAAAAtc/ulHsAIUi7dc/s1600/4-connections.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: "verdana" , sans-serif; font-size: x-small;"><img border="0" height="290" src="https://3.bp.blogspot.com/-SRMx1qWNjrI/VR939Gs7D_I/AAAAAAAAAtc/ulHsAIUi7dc/s1600/4-connections.png" width="400" /></span></a></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="background-color: white;"><span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="background-color: white;"><span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></span></div>
<h3 style="clear: both; text-align: left;">
<span style="background-color: white;"><span style="font-family: "verdana" , sans-serif; font-size: x-small;">Build and Debug Selection:</span></span></h3>
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-yauKjxAlCc0/VR-EIQTLCRI/AAAAAAAAAvA/sbHwKttJ3rA/s1600/5-build.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: "verdana" , sans-serif; font-size: x-small;"><img border="0" height="373" src="https://3.bp.blogspot.com/-yauKjxAlCc0/VR-EIQTLCRI/AAAAAAAAAvA/sbHwKttJ3rA/s1600/5-build.png" width="400" /></span></a></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="background-color: white;"><span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></span></div>
<h3 style="clear: both; text-align: left;">
<span style="background-color: white;"><span style="font-family: "verdana" , sans-serif; font-size: x-small;">RAD :</span></span></h3>
<div class="separator" style="clear: both; text-align: left;">
<span style="background-color: white;"><span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-M5hkeV-6VLw/VR94rVoyQjI/AAAAAAAAAts/1Jx1SQIlUy0/s1600/6-RAD.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: "verdana" , sans-serif; font-size: x-small;"><img border="0" height="208" src="https://3.bp.blogspot.com/-M5hkeV-6VLw/VR94rVoyQjI/AAAAAAAAAts/1Jx1SQIlUy0/s1600/6-RAD.png" width="400" /></span></a></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<b><span style="font-family: "verdana" , sans-serif; font-size: x-small;">FINISH</span></b></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="background-color: white;"><span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="background-color: white;"><span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></span></div>
<h3 style="clear: both; text-align: left;">
<span style="background-color: white;"><span style="font-family: "verdana" , sans-serif; font-size: x-small;">CodeWarrior Perspective :</span></span></h3>
<div class="separator" style="clear: both; text-align: left;">
<span style="background-color: white;"><span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="background-color: white;"><span style="font-family: "verdana" , sans-serif; font-size: x-small;">This is what you will see in your codewarrior. You can read more about the perspectivies, look for videos in Youtube if you are not used to the eclipse environment.</span></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="background-color: white;"><span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-v3Isvs8jnsk/VR95AzVjDdI/AAAAAAAAAt0/AIwpCV1b9kE/s1600/07-setup.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: "verdana" , sans-serif; font-size: x-small;"><img border="0" height="460" src="https://3.bp.blogspot.com/-v3Isvs8jnsk/VR95AzVjDdI/AAAAAAAAAt0/AIwpCV1b9kE/s1600/07-setup.png" width="640" /></span></a></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="background-color: white;"><span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="background-color: yellow;"><span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="background-color: yellow;"><span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;">Now comes the real usecase to print Helloworld by writing code, run it on the freescale board, and see it on the terminal.</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></div>
<h3 style="clear: both; text-align: left;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;">Add the ConsoleIO component to the project:</span></h3>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-cKpfvvyU1AM/VR96hPJhb7I/AAAAAAAAAuA/PXV_5aeX6sQ/s1600/08-consoleio.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: "verdana" , sans-serif; font-size: x-small;"><img border="0" height="420" src="https://2.bp.blogspot.com/-cKpfvvyU1AM/VR96hPJhb7I/AAAAAAAAAuA/PXV_5aeX6sQ/s1600/08-consoleio.png" width="640" /></span></a></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></div>
<h3 style="clear: both; text-align: left;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;">Component (Advanced) Properties:</span></h3>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-btZIoTuQVPM/VR99YKsbY-I/AAAAAAAAAuM/F3FB57bD3Ro/s1600/09-component-properties.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: "verdana" , sans-serif; font-size: x-small;"><img border="0" height="368" src="https://1.bp.blogspot.com/-btZIoTuQVPM/VR99YKsbY-I/AAAAAAAAAuM/F3FB57bD3Ro/s1600/09-component-properties.png" width="640" /></span></a></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></div>
<h3 style="clear: both; text-align: left;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;">Serial_LDD Changes :</span></h3>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;">You need to change the Serial to UART0. Lets check the schematic pdf for their pins</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-0R5Ke9jPqB0/VR9-6uJMyXI/AAAAAAAAAuY/u1ceYaMjsts/s1600/11-uart.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: "verdana" , sans-serif; font-size: x-small;"><img border="0" height="184" src="https://1.bp.blogspot.com/-0R5Ke9jPqB0/VR9-6uJMyXI/AAAAAAAAAuY/u1ceYaMjsts/s1600/11-uart.png" width="640" /></span></a></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;">Now lets fix the errors in the properties by setting the in and out appropriately, and the baud rate error will be gone.</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-L88XrPlBA_s/VR9_a8_RSvI/AAAAAAAAAug/KKUZObbIFYA/s1600/12-Pins.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: "verdana" , sans-serif; font-size: x-small;"><img border="0" height="260" src="https://4.bp.blogspot.com/-L88XrPlBA_s/VR9_a8_RSvI/AAAAAAAAAug/KKUZObbIFYA/s1600/12-Pins.png" width="640" /></span></a></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></div>
<h3 style="clear: both; text-align: left;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;">Locate the main.c:</span></h3>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-VSqR9MFKr2k/VR-AV4Kht7I/AAAAAAAAAus/LLXm6OtR1TQ/s1600/13-main.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: "verdana" , sans-serif; font-size: x-small;"><img border="0" height="384" src="https://1.bp.blogspot.com/-VSqR9MFKr2k/VR-AV4Kht7I/AAAAAAAAAus/LLXm6OtR1TQ/s1600/13-main.png" width="640" /></span></a></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></div>
<h3 style="clear: both; text-align: left;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;">Add your Printf :</span></h3>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-hmEpQZHo5NY/VR-WOfzvCuI/AAAAAAAAAvQ/-jg-k4bZJQg/s1600/14-print.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: "verdana" , sans-serif; font-size: x-small;"><img border="0" height="172" src="https://4.bp.blogspot.com/-hmEpQZHo5NY/VR-WOfzvCuI/AAAAAAAAAvQ/-jg-k4bZJQg/s1600/14-print.png" width="400" /></span></a></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></div>
<h3 style="clear: both; text-align: left;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;">Lets build :</span></h3>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small; margin-left: 1em; margin-right: 1em;"><img border="0" height="285" src="https://4.bp.blogspot.com/-iJ1he66bqdw/VR-WdXdkjWI/AAAAAAAAAvY/bdzr_b-UVXI/s1600/15-build.png" width="400" /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></div>
<h3 style="clear: both; text-align: left;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;">Run it : </span></h3>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-rZftWFSlU1Q/VR-WiQX_eQI/AAAAAAAAAvg/lULd-dgGi08/s1600/15-runas.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: "verdana" , sans-serif; font-size: x-small;"><img border="0" height="170" src="https://1.bp.blogspot.com/-rZftWFSlU1Q/VR-WiQX_eQI/AAAAAAAAAvg/lULd-dgGi08/s1600/15-runas.png" width="400" /></span></a></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></div>
<h3 style="clear: both; text-align: left;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;">If device/board is not connected to your USB.</span></h3>
<div class="separator" style="clear: both; text-align: center;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-1ofs4_wydPQ/VR-WxtOBNHI/AAAAAAAAAvw/Re0zSDlPvF4/s1600/16-notfound.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: "verdana" , sans-serif; font-size: x-small;"><img border="0" height="233" src="https://3.bp.blogspot.com/-1ofs4_wydPQ/VR-WxtOBNHI/AAAAAAAAAvw/Re0zSDlPvF4/s1600/16-notfound.png" width="640" /></span></a></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></div>
<h3 style="clear: both; text-align: left;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;">Connect, Refresh and Retry:</span></h3>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-8of5gZChLJ0/VR-WpZ9mXTI/AAAAAAAAAvo/maV4BRVjKVw/s1600/17-refresh.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: "verdana" , sans-serif; font-size: x-small;"><img border="0" height="215" src="https://2.bp.blogspot.com/-8of5gZChLJ0/VR-WpZ9mXTI/AAAAAAAAAvo/maV4BRVjKVw/s1600/17-refresh.png" width="640" /></span></a></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></div>
<h3 style="clear: both; text-align: left;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;">Console Output: </span></h3>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-89SD8_Tiweo/VR-W371Y0tI/AAAAAAAAAv4/PT7V_I-DG_s/s1600/18-target%2Brunning.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: "verdana" , sans-serif; font-size: x-small;"><img border="0" src="https://2.bp.blogspot.com/-89SD8_Tiweo/VR-W371Y0tI/AAAAAAAAAv4/PT7V_I-DG_s/s1600/18-target%2Brunning.png" /></span></a></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></div>
<h3 style="clear: both; text-align: left;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;">Realterm Configuration:</span></h3>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-Rfs-Ux1ei2k/VR-W7bqaemI/AAAAAAAAAwA/OQ970ThRTkk/s1600/19-realterm-1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: "verdana" , sans-serif; font-size: x-small;"><img border="0" height="443" src="https://2.bp.blogspot.com/-Rfs-Ux1ei2k/VR-W7bqaemI/AAAAAAAAAwA/OQ970ThRTkk/s1600/19-realterm-1.png" width="640" /></span></a></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></div>
<h3 style="clear: both; text-align: left;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;">Realterm Output Configuration:</span></h3>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/--GyRZjHi2H8/VR-XAtI1gmI/AAAAAAAAAwI/7ur7RAFM8nM/s1600/20-realterm-2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: "verdana" , sans-serif; font-size: x-small;"><img border="0" src="https://3.bp.blogspot.com/--GyRZjHi2H8/VR-XAtI1gmI/AAAAAAAAAwI/7ur7RAFM8nM/s1600/20-realterm-2.png" /></span></a></div>
<div class="separator" style="clear: both;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></div>
<div class="separator" style="clear: both;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></div>
<div class="separator" style="clear: both;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;"><b><u style="background-color: yellow;">Realterm Output </u></b>when you run the program. Press the reset button, you will see the program restarting.</span></div>
<div class="separator" style="clear: both;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-idsMFNvG4oE/VR-XMmgws1I/AAAAAAAAAwQ/oXNIZKNguP0/s1600/21-output.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: "verdana" , sans-serif; font-size: x-small;"><img border="0" height="432" src="https://2.bp.blogspot.com/-idsMFNvG4oE/VR-XMmgws1I/AAAAAAAAAwQ/oXNIZKNguP0/s1600/21-output.png" width="640" /></span></a></div>
<div class="separator" style="clear: both;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span></div>
<div class="separator" style="clear: both;">
<span style="font-family: "verdana" , sans-serif; font-size: x-small;">You can add the printf in a for loop.</span></div>
<div class="separator" style="clear: both; text-align: justify;">
<span style="text-align: left;"><span style="font-family: "verdana" , sans-serif; font-size: x-small;">there you go! The 1st MCU Hello world is done.</span></span></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
</div>
Anonymoushttp://www.blogger.com/profile/13196480231236274690noreply@blogger.com2tag:blogger.com,1999:blog-2002003343323875763.post-33489929097602673892015-02-17T02:12:00.001-08:002015-02-17T02:18:32.929-08:00Simple RabbitMQ Sender and Listener<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: Verdana, sans-serif; font-size: x-small;">Assuming RabbitMQ server is running on localhost, and requires user-id and password to connect.</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;">This example has</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<ul style="text-align: left;">
<li><span style="font-family: Verdana, sans-serif; font-size: x-small;">a sender which sends the message (line) typed in the command line, to a specific exchange and a routing key</span></li>
<li><span style="font-family: Verdana, sans-serif; font-size: x-small;">Reciever, which listens to the message send to a specific queue</span></li>
</ul>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;">The working maven project for this example can be downloaded <a href="https://www.dropbox.com/s/jk4b8bs0lp29w59/rabbitmq-test.zip?dl=0" target="_blank">here</a>.</span><br />
<br />
<b><u>SENDER</u></b><br />
<b><u><br /></u></b>
<br />
<pre brush="java">import java.io.IOException;
import java.util.Scanner;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
public class RabbitSender {
private static final String TEST_EXCHANGE = "test-exchange";
private static final String TEST_QUEUE = "test-queue";
public static void main(String args[]) throws Exception {
Connection connection = null;
Channel channel = null;
try (Scanner sc = new Scanner(System.in)) {
while (true) {
System.out.print("--Type in the message to send--");
String s = sc.nextLine();
ConnectionFactory factory = new ConnectionFactory();
factory.setUri("amqp://localhost");
factory.setUsername("userid");
factory.setPassword("password");
System.out.println("-- Creating Connection--");
connection = factory.newConnection();
System.out.println("-- Creating channel--");
channel = connection.createChannel();
System.out.println("-- Creating Exchange--");
channel.exchangeDeclare(TEST_EXCHANGE, "topic");
System.out.println("-- Creating queue--");
channel.queueDeclare(TEST_QUEUE, false, false, false, null);
channel.queueBind(TEST_QUEUE, TEST_EXCHANGE, "test.#");
System.out.println("-- Sending Message--");
channel.basicPublish(TEST_EXCHANGE, "test.route", null,
s.getBytes());
System.out.println("-- Message sent to--" + TEST_EXCHANGE
+ " with routing key:" + "test.route");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (channel != null)
channel.close();
if (connection != null)
connection.close();
}
}
}
</pre>
<pre brush="java"><div style="font-family: 'Times New Roman'; white-space: normal;">
<b><u>RECEIVER</u></b></div>
<div>
<b><u>
</u></b></div>
</pre>
<pre brush="java">import java.util.Scanner;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.QueueingConsumer;
import com.rabbitmq.client.QueueingConsumer.Delivery;
public class RabbitListener {
private static final String TEST_EXCHANGE = "test-exchange";
private static final String TEST_QUEUE = "test-queue";
public static void main(String args[]) throws Exception {
Connection connection = null;
Channel channel = null;
try {
ConnectionFactory factory = new ConnectionFactory();
factory.setUri("amqp://localhost");
factory.setUsername("userid");
factory.setPassword("password");
System.out.println("-- Creating Connection--");
connection = factory.newConnection();
System.out.println("-- Creating channel--");
channel = connection.createChannel();
QueueingConsumer consumer = new QueueingConsumer(channel);
channel.basicConsume(TEST_QUEUE, true, consumer);
System.out.println("-- Waiting for message--");
Delivery delivery = null;
while ((delivery = consumer.nextDelivery()) != null) {
System.out.println("--Message received --"
+ new String(delivery.getBody()));
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (channel != null)
channel.close();
if (connection != null)
connection.close();
}
}
}
</pre>
</div>
Anonymoushttp://www.blogger.com/profile/13196480231236274690noreply@blogger.com2tag:blogger.com,1999:blog-2002003343323875763.post-91393420490442968452015-02-16T00:23:00.000-08:002015-02-16T08:20:13.549-08:00ACID vs CAP <div dir="ltr" style="text-align: left;" trbidi="on">
ACID - set of properties that define the quality of database transactions.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMubbHLUH6S_7m2BAH7sXakWItYKJcq_RGyK8Cr5sOxa6vgtCUTBCERv9mu7Ls_2xUSgnEe_zpIgaOIKKErgp1DmxlOrdurT3UYRzasrTNJ6TvAeBILs4GvDqv3KUgAuesrcCK8S7YSbUm/s1600/2015-02-16+13_44_29-PowerPoint+Slide+Show+-+%5BPresentation1%5D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMubbHLUH6S_7m2BAH7sXakWItYKJcq_RGyK8Cr5sOxa6vgtCUTBCERv9mu7Ls_2xUSgnEe_zpIgaOIKKErgp1DmxlOrdurT3UYRzasrTNJ6TvAeBILs4GvDqv3KUgAuesrcCK8S7YSbUm/s1600/2015-02-16+13_44_29-PowerPoint+Slide+Show+-+%5BPresentation1%5D.png" height="320" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<b><u>CAP - Consistency, Availability, Partition Tolerance</u></b><br />
<br />
3 basic properties or requirements for distributed System. Assuming a Distributed Database system, where data is distributed/partitioned across nodes/servers<br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2beTvfpxGlec4uunaaooROn8wKPp0cmZfR0uRJvzc3DQE_ha4Mdc1q0483UcirruVfCWnArU_lnVhz6cwJKVYC4jNFZ__Tuzi837_CXWZi0mHCETBvBrLdx1BjgQetc_7oWQLiagnEyVp/s1600/2015-02-16+21_43_17-Presentation1+-+PowerPoint.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2beTvfpxGlec4uunaaooROn8wKPp0cmZfR0uRJvzc3DQE_ha4Mdc1q0483UcirruVfCWnArU_lnVhz6cwJKVYC4jNFZ__Tuzi837_CXWZi0mHCETBvBrLdx1BjgQetc_7oWQLiagnEyVp/s1600/2015-02-16+21_43_17-Presentation1+-+PowerPoint.png" height="150" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
All 3 properties is hard to achieve. So at least a combination 2 properties from the above is acceptable.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<br />
<br />
<br /></div>
Anonymoushttp://www.blogger.com/profile/13196480231236274690noreply@blogger.com0tag:blogger.com,1999:blog-2002003343323875763.post-27556826370429306582015-02-14T10:17:00.006-08:002015-02-17T02:39:40.548-08:00Setup ELK on Linux (Elasticsearch 1.4.2 /Logstash 1.4.2/Kibana 3.1.2)<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: Verdana, sans-serif; font-size: x-small;">Below are instructions to setup ELK stack, in 8 simple steps.</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;">1. Install JDK Httpd</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;">2. Download and extract necessary components</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;">3. Configure and start httpd and elasticsearch servers</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;">3. Verify httpd,elasticsearch</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;">4. Setup Kibana on HTTPD path.</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;">5. Test Kibana and get it working with few changes to elasticsearch.</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;">6. Add logstash configuration</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;">7. Run logstash to push to Elasticsearch.</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;">8. Advanced Logstash configurations to parse access_log.</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<br />
<div class="MsoNormal">
<b><u><span style="font-family: Verdana, sans-serif; font-size: x-small;">Install JDK and Httpd</span></u></b></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: x-small; text-indent: 0.5in;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: x-small; text-indent: 0.5in;">Make sure appropriate yum repo's are updated.</span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: x-small; text-indent: 0.5in;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: x-small; text-indent: 0.5in;">yum install java-1.7.0-openjdk</span></div>
<div class="MsoNormal" style="text-indent: 0.5in;">
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><o:p></o:p></span></div>
<div class="MsoNormal">
</div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: x-small;">yum install httpd<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span></div>
<div class="MsoNormal">
<b><u><span style="font-family: Verdana, sans-serif; font-size: x-small;">Disable Firewall </span></u></b></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: x-small;">service iptables stop</span></div>
<div>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span></div>
<div>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span></div>
<b><u><span style="font-family: Verdana, sans-serif; font-size: x-small;">Downloads:</span></u></b><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<br />
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><b>elasticsearch-1.4.2.zip </b>
- <a href="https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.4.2.zip">https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.4.2.zip</a></span></div>
<div class="MsoNormal">
</div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><b>elasticsearch-head-master.zip - </b><a href="https://github.com/mobz/elasticsearch-head/archive/master.zip">https://github.com/mobz/elasticsearch-head/archive/master.zip</a><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><b>kibana-3.1.2.tar</b> - <a href="https://download.elasticsearch.org/kibana/kibana/kibana-3.1.2.tar.gz">https://download.elasticsearch.org/kibana/kibana/kibana-3.1.2.tar.gz</a></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><b>logstash-1.4.2.tar </b>- <a href="https://download.elasticsearch.org/logstash/logstash/logstash-1.4.2.tar.gz">https://download.elasticsearch.org/logstash/logstash/logstash-1.4.2.tar.gz</a></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span></div>
<div class="MsoNormal">
<b><u><span style="font-family: Verdana, sans-serif; font-size: x-small;">Copy the files to a linux machine to /root folder</span></u></b></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><b><u>ElasticSearch: </u></b>unzip elasticsearch-1.4.2.zip<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><b><u>Kibana: </u></b>tar -zxvf kibana-3.1.2.tar<o:p></o:p></span></div>
<div class="MsoNormal">
</div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><b><u>Logstash: </u></b>tar -zxvf logstash-1.4.2.tar<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><b><u>Head Plugin: </u></b>elasticsearch-1.4.2/bin/plugin --url
file:///root/elasticsearch-head-master.zip --install mobz/elasticsearch-head<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span></div>
<div class="MsoNormal">
<b><u><span style="font-family: Verdana, sans-serif; font-size: x-small;">Configure Elasticsaerch</span></u></b></div>
<div class="MsoNormal">
<b><u><span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span></u></b></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: x-small;">vi /root/elasticsearch-1.4.2/config/elasticsearch.yml<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: x-small;">uncomment cluster-name and give a name. <b><i>don't use the default</i></b></span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><b><i><br /></i></b></span>
<span style="color: blue; font-family: Verdana, sans-serif; font-size: x-small;"><b><i>################################### Cluster ###################################</i></b></span><br />
<span style="color: blue; font-family: Verdana, sans-serif; font-size: x-small;"><b><i><br /></i></b></span>
<span style="color: blue; font-family: Verdana, sans-serif; font-size: x-small;"><b><i># Cluster name identifies your cluster for auto-discovery. If you're running</i></b></span><br />
<span style="color: blue; font-family: Verdana, sans-serif; font-size: x-small;"><b><i># multiple clusters on the same network, make sure you're using unique names.</i></b></span><br />
<span style="color: blue; font-family: Verdana, sans-serif; font-size: x-small;"><b><i>#</i></b></span><br />
<span style="color: blue; font-family: Verdana, sans-serif; font-size: x-small;"><b><i></i></b></span><br />
<span style="color: blue; font-family: Verdana, sans-serif; font-size: x-small;"><b><i style="background-color: #ffe599;">cluster.name: vidhya-elk</i></b></span><br />
<div>
<br /></div>
<div>
<br /></div>
</div>
<div class="MsoNormal">
<b><i><span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span></i></b></div>
<div class="MsoNormal">
<b><u><span style="font-family: Verdana, sans-serif; font-size: x-small;">Start Servers</span></u></b></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: x-small;">service httpd restart</span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: x-small; line-height: 107%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: x-small; line-height: 107%;"><b><u>Verify the server Installation</u></b></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: x-small; line-height: 107%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: x-small; line-height: 107%;">Httpd: http://<IP/hostname></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: x-small; line-height: 107%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: x-small; line-height: 107%;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjEFIsisUTUTD5Qq-qWNGdHaqZ7vdQWwrPY5zuJR2izpVmJiqJQ_8rIE0SVN4z-4UASC7WaawBP3Dipwa1X4Ik-8qP0hAm4BE2fX0IV4RKB1CUadWwmc4uGxT5YaIa-4-AguYzqvNPQunWG/s1600/httpd.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: Verdana, sans-serif; font-size: x-small;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjEFIsisUTUTD5Qq-qWNGdHaqZ7vdQWwrPY5zuJR2izpVmJiqJQ_8rIE0SVN4z-4UASC7WaawBP3Dipwa1X4Ik-8qP0hAm4BE2fX0IV4RKB1CUadWwmc4uGxT5YaIa-4-AguYzqvNPQunWG/s1600/httpd.png" height="116" width="400" /></span></a></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: x-small; line-height: 107%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span></div>
<div class="MsoNormal">
<b><u><span style="font-family: Verdana, sans-serif; font-size: x-small;">Start Elasticsearch</span></u></b></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: x-small;">/root/<span style="line-height: 15.6933336257935px;">elasticsearch-1.4.2/</span><span style="line-height: 15.6933336257935px;">bin/elasticsearch</span></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: x-small; line-height: 15.6933336257935px;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh71XzHlOuh8G7HdQAUWrOZ9zkJQorEuJvwipW1uH_d3z5aoUeeYsRsIQehn3JMxzlPzLcd2oo8sZuNea0Xgw_QWRN2BB3OPlaPmNJtOzXEQR8bvE-7xkPm7awsZYY1RNESgyyqJiUr5Qkb/s1600/es.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: Verdana, sans-serif; font-size: x-small;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh71XzHlOuh8G7HdQAUWrOZ9zkJQorEuJvwipW1uH_d3z5aoUeeYsRsIQehn3JMxzlPzLcd2oo8sZuNea0Xgw_QWRN2BB3OPlaPmNJtOzXEQR8bvE-7xkPm7awsZYY1RNESgyyqJiUr5Qkb/s1600/es.png" height="99" width="640" /></span></a></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><b><u>Verify Elasticsearch : </u></b> http://<ip/hostname>:9200/</span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiruaFEGbnmg8kiitWuHZkv2h6UYgUK40NUHvyQqbw2l8BrlMzzvIE-LAsEU7P8cwWZ8E6TfIU3qAqntDbfAsVMWmfdQtd-QqiG_MHJouAtBFnSuzekDqBbM4vVp5U3NXAWiCpgQr9SgUmo/s1600/es_browser.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: Verdana, sans-serif; font-size: x-small;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiruaFEGbnmg8kiitWuHZkv2h6UYgUK40NUHvyQqbw2l8BrlMzzvIE-LAsEU7P8cwWZ8E6TfIU3qAqntDbfAsVMWmfdQtd-QqiG_MHJouAtBFnSuzekDqBbM4vVp5U3NXAWiCpgQr9SgUmo/s1600/es_browser.png" height="221" width="400" /></span></a></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><b><u>Verify Elasticsearch head :</u> </b>http://<ip/hostname>:9200/_plugin/head</span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOi-OindTkFwaDBlBDj91ZK9x08_n5VCPqDwzqyfYViUFYAAYx8J4rlY8iE2w5b6HOLzepLJ19Qk3pStFHCE1s49eIZ30ZdWB8-4Dtj4ovZHdmIYrKcUmwapwTXCtvtGn5FiPUNeUB8mhh/s1600/head.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: Verdana, sans-serif; font-size: x-small;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOi-OindTkFwaDBlBDj91ZK9x08_n5VCPqDwzqyfYViUFYAAYx8J4rlY8iE2w5b6HOLzepLJ19Qk3pStFHCE1s49eIZ30ZdWB8-4Dtj4ovZHdmIYrKcUmwapwTXCtvtGn5FiPUNeUB8mhh/s1600/head.png" height="160" width="400" /></span></a></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="font-family: Verdana, sans-serif; font-size: x-small; text-align: left;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span></div>
<div class="MsoNormal">
<b><u><span style="font-family: Verdana, sans-serif; font-size: x-small;">Kibana Setup</span></u></b><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><b><u><br /></u></b>
</span><br />
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: x-small;">mkdir /var/www/kibana3<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: x-small;">cp -r /root/kibana-3.1.2/*
/var/www/kibana3/<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><i><b>vi /etc/httpd/conf/httpd.conf</b></i><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: x-small;">alias /kibana /var/www/kibana3<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><Directory /var/www/kibana3><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: x-small;"> AllowOverride All<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: x-small;"> Require all granted<o:p></o:p></span></div>
<div class="MsoNormal">
</div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: x-small;"></Directory><o:p></o:p></span></div>
</div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;">Verify Kibana : </span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<br />
<div class="MsoNormal">
<a href="http://%3Chostname/ip%3e/kibana">http://<hostname/ip>/kibana</a> <o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsYYSxiolRUkqaJWuB7Kc7Mm9ZR_1cf_loQpS1Dq1HC-6Ry2Jvz0KlB2wigzCyFPff-2-Y8bNeD84moI0gv_66f60DZMZwl6C8aRskqYn-C32hFp3KZ2MmWKZgfaj111Wu3l976x4Z4ZXs/s1600/kibana_error.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsYYSxiolRUkqaJWuB7Kc7Mm9ZR_1cf_loQpS1Dq1HC-6Ry2Jvz0KlB2wigzCyFPff-2-Y8bNeD84moI0gv_66f60DZMZwl6C8aRskqYn-C32hFp3KZ2MmWKZgfaj111Wu3l976x4Z4ZXs/s1600/kibana_error.png" height="166" width="400" /></a></div>
<div class="MsoNormal">
<br /></div>
</div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><b><i>To fix this error, changes are required in elasticsearch.yml, by adding the below mentioned line at the end of the file.</i></b></span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;">vi /root/elasticsearch-1.4.2/config/elasticsearch.yml</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><b><i></i></b></span><br />
<span style="color: blue; font-family: Verdana, sans-serif; font-size: x-small;"><b><i>http.cors.enabled: true</i></b></span><br />
<span style="color: blue; font-family: Verdana, sans-serif; font-size: x-small;"><b><i><br /></i></b></span>
<span style="color: blue; font-family: Verdana, sans-serif; font-size: x-small;"><b><i>Restart elasticsearch</i></b></span><br />
<span style="color: blue; font-family: Verdana, sans-serif; font-size: x-small;"><b><i><br /></i></b></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOmFobSw0PokQoyMH5ywgKlxh4PKNsnKGyKu4yA7FCBAnEfneMb-mMP61kXTFzaCN7J8qp8oyC-9JtK47d1x7K_3S2dADmQCdiPF1sjwMDbt13flkbO1KnCxiZ3DKX8lkaa9iZWNBC5_7i/s1600/kibana.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOmFobSw0PokQoyMH5ywgKlxh4PKNsnKGyKu4yA7FCBAnEfneMb-mMP61kXTFzaCN7J8qp8oyC-9JtK47d1x7K_3S2dADmQCdiPF1sjwMDbt13flkbO1KnCxiZ3DKX8lkaa9iZWNBC5_7i/s1600/kibana.png" height="228" width="400" /></a></div>
<span style="color: blue; font-family: Verdana, sans-serif; font-size: x-small;"><b><i><br /></i></b></span>
<br />
<div>
<br /></div>
<div>
<b><u><span style="font-family: Verdana, sans-serif; font-size: x-small;">Logstash Setup</span></u></b></div>
<div>
<b><u><span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span></u></b></div>
<div>
<b><u><span style="font-family: Verdana, sans-serif; font-size: x-small;">Create a configuration file:</span></u></b></div>
<div class="MsoNormal">
<i><b>vi /root/logstash-1.4.2/conf/es.conf</b></i><o:p></o:p></div>
<pre brush="java">input { stdin { }}
output {
stdout { }
elasticsearch {
bind_host => "127.0.0.1"
protocol => http
}
}
</pre>
<pre brush="java"><span style="font-family: Times New Roman;"><span style="white-space: normal;">The above configuration takes any standard input and publishes to elasticsearch as well as prints it on the command line.</span></span></pre>
<pre brush="java"><span style="font-family: Times New Roman;"><span style="white-space: normal;">
</span></span></pre>
<pre brush="java"><b style="font-family: 'Times New Roman'; white-space: normal;"><u><span style="font-family: Verdana, sans-serif; font-size: x-small;">Verify Logstash</span></u></b></pre>
<pre brush="java"><b style="font-family: 'Times New Roman'; white-space: normal;"><u><span style="font-family: Verdana, sans-serif; font-size: x-small;">
</span></u></b></pre>
<pre brush="java"><div class="MsoNormal">
<b><i>/root/logstash-1.4.2/bin/logstash agent -f /root/logstash-1.4.2/conf/es.conf --configtest</i></b><o:p></o:p></div>
<div class="MsoNormal">
<b><i>
</i></b></div>
<div class="MsoNormal">
<b><i>-- This verifies the configuration file</i></b></div>
<div class="MsoNormal">
<b><i>
</i></b></div>
<div class="MsoNormal">
</div>
<div class="MsoNormal">
<i><b>./logstash-1.4.2/bin/logstash agent -f logstash-1.4.2/conf/es.conf </b></i><o:p></o:p></div>
<div class="MsoNormal">
<i><b>
</b></i></div>
<div class="MsoNormal">
<i><b>-- This pushes whatever is typed on the command-line to elasticsearch, you can see indexes getting created using the elasticsearch head plugin.</b></i></div>
<div class="MsoNormal">
</div>
<pre brush="java"><b style="font-family: 'Times New Roman'; white-space: normal;"><u><span style="font-family: Verdana, sans-serif; font-size: x-small;">Advanced Logstash configuration</span></u></b></pre>
<pre brush="java"><b style="font-family: 'Times New Roman'; white-space: normal;"><u><span style="font-family: Verdana, sans-serif; font-size: x-small;">
</span></u></b></pre>
<pre brush="java"><b style="font-family: 'Times New Roman'; white-space: normal;"><u><span style="font-family: Verdana, sans-serif; font-size: x-small;">
</span></u></b></pre>
<pre brush="java"><b style="font-family: 'Times New Roman'; white-space: normal;"><u><span style="font-family: Verdana, sans-serif; font-size: x-small;">1. Parse the access_log and publish to elasticsearch for log analysis </span></u></b></pre>
<pre brush="java"><b style="font-family: 'Times New Roman'; white-space: normal;"><u><span style="font-family: Verdana, sans-serif; font-size: x-small;">
</span></u></b></pre>
<span style="font-family: 'Times New Roman'; white-space: normal;"><b><i>vi /root/logstash-1.4.2/conf/access_log.conf</i></b></span>
<pre brush="java">input {
file {
path => "/var/log/httpd/access_log"
start_position => "beginning"
sincedb_path => "/dev/null"
type => "apache-access"
}
}
output {
stdout { }
elasticsearch {
bind_host => "127.0.0.1"
protocol => http
}
}
</pre>
<div>
</div>
<div class="MsoNormal">
<i><b>
</b></i></div>
<pre brush="java"><pre brush="java"><b style="font-family: 'Times New Roman'; white-space: normal;"><u><span style="font-family: Verdana, sans-serif; font-size: x-small;">2. Parse the access_log and publish to elasticsearch for log analysis, custom grok filters </span></u></b></pre>
<pre brush="java"><b style="font-family: 'Times New Roman'; white-space: normal;"><u><span style="font-family: Verdana, sans-serif; font-size: x-small;">
</span></u></b></pre>
<span style="font-family: 'Times New Roman'; white-space: normal;"><b><i>vi /root/logstash-1.4.2/conf/access_grok_log.conf</i></b></span>
<pre brush="java"></pre>
<pre brush="java">input {
file {
path => "/root/log/access_log"
start_position => "beginning"
sincedb_path => "/dev/null"
type => "apache-access"
}
}
filter {
if ([message] =~ "^::") {
drop {}
}
grok {
match => ["%{COMBINEDAPACHELOG}"]
}
date {
match => [ "timestamp" ,"dd/MMM/yyyy:HH:mm:ss Z"]
}
}
output {
stdout { }
elasticsearch {
bind_host => "127.0.0.1"
protocol => http
}
}
</pre>
<div>
</div>
<div>
</div>
</pre>
<div class="MsoNormal">
</div>
<div class="MsoNormal">
<b><i>
</i></b></div>
</pre>
<pre brush="java"><span style="font-family: Times New Roman;"><span style="white-space: normal;">
</span></span></pre>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
</div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span></div>
<div class="MsoNormal">
<br /></div>
</div>
Anonymoushttp://www.blogger.com/profile/13196480231236274690noreply@blogger.com0tag:blogger.com,1999:blog-2002003343323875763.post-30176144053264936372015-01-30T07:05:00.000-08:002015-01-30T07:05:57.566-08:00AOP introduction<div dir="ltr" style="text-align: left;" trbidi="on">
Aspects are generic feature that cuts across classes/methods/modules etc. It smells the execution of matching methods that it is expected to handle and executes as per different strategies that are defined later. The actual classes/methods are not aware of the logic being applied.<br />
<br />
The cross cutting solutions may be exception handling, activity logging, transaction management, etc.<br />
These can be defined as aspects which can work based on some configuration defined/or can be applied for any code matching its criteria.<br />
<br />
Where are Aspects Used:<br />
<br />
<ul style="text-align: left;">
<li>In legacy applications, which needs adapters across classes, which cannot be touched. Say, the tracing was missing in a legacy application. To get the tracing plugged in, we may need every class/method to be modified to add entering/existing. Instead - A trace Aspect would do that by trapping all/certain method invocation, and introduce tracing before. Execute method using reflection. then add after tracing. <br /> </li>
<li> Generic logic that needs to be handled in a detached class, keeping the intercepted classes unaware of</li>
</ul>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi653wx98VBdsk8aqm6WeitVxUbjyPKsgVr3_rV48JtI7uuqo394FxSvHog0v6gHmi0WzpkrmqSwNBPkdZ3Ue_giHBTeS72_4p8DOCYYGX56h10Y9I_OEMp-HpjCZCA7BbYfs5cVGoKgyjv/s1600/AOP1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi653wx98VBdsk8aqm6WeitVxUbjyPKsgVr3_rV48JtI7uuqo394FxSvHog0v6gHmi0WzpkrmqSwNBPkdZ3Ue_giHBTeS72_4p8DOCYYGX56h10Y9I_OEMp-HpjCZCA7BbYfs5cVGoKgyjv/s1600/AOP1.png" height="268" width="640" /> </a></div>
<div class="separator" style="clear: both; text-align: center;">
Crosscutting Across modules/classes/etc/, </div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<br />
How does Aspects work.<br />
<br />
The aspects and their pointcuts are preloaded. When a method is invoked, The call goes to a Proxy, which hands off the method to be executed to the aspects, which is applicable to this method based on the pointcuts. Aspect chaining occurs and the actual method is executed at the necessary time based on the aspect ordering.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgcYeU-ruZw3gobAeuLPN0tGq1_z5VDR_xYQl-VPCl1ySKED5slcCg3rXgnlk-ctNotSwtFMK4HdhnA49nweSmG3O3wH5KW8H0cCwtOSQRfCIFChSHrCjwh1lR74Bpai8WFgM5eqU89hsz/s1600/AOP3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgcYeU-ruZw3gobAeuLPN0tGq1_z5VDR_xYQl-VPCl1ySKED5slcCg3rXgnlk-ctNotSwtFMK4HdhnA49nweSmG3O3wH5KW8H0cCwtOSQRfCIFChSHrCjwh1lR74Bpai8WFgM5eqU89hsz/s1600/AOP3.png" height="166" width="640" /> </a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<br />
<br />
Advice chaining: As it happens with spring 2.0<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjcpCYiHZ5D61I9s8sNyEYmcxnnWe1FUvXIAst16642opPH4CUIiwps3aqFH5n0fmj5dAKIOXheuazg2uhfpLaWYoE37BdNRxowpqGk7L1wY4R8gdt5BT9IbL9Q_VKteso4tksgFGB-CKGZ/s1600/AOP2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjcpCYiHZ5D61I9s8sNyEYmcxnnWe1FUvXIAst16642opPH4CUIiwps3aqFH5n0fmj5dAKIOXheuazg2uhfpLaWYoE37BdNRxowpqGk7L1wY4R8gdt5BT9IbL9Q_VKteso4tksgFGB-CKGZ/s1600/AOP2.png" height="328" width="640" /></a></div>
<br />
<br />
AOP Concepts in Spring:<br />
<br />
In Spring AOP, aspects are
implemented using regular classes (the schema-based approach) or regular
classes annotated with the <tt class="interfacename">@Aspect</tt> annotation
(<tt class="interfacename">@AspectJ</tt> style).<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-CL5oZkrMjDs/Uz_O8M9MkMI/AAAAAAAAAjo/w0SmkLPWj2Q/s1600/aop5.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><br /></a></div>
<div class="itemizedlist">
<ul type="disc">
<li><span class="emphasis"><i>Join point</i></span>: A point during the execution of
a program, such as the execution of a method or the handling of
an exception. In Spring AOP, a join point <span class="emphasis"><i>always</i></span> represents
a method execution.<br />
</li>
<li><span class="emphasis"><i>Advice</i></span>: Action taken by an aspect
at a particular join point. Different types of advice include
"around," "before" and "after" advice.<br />
</li>
<li><span class="emphasis"><i>Pointcut</i></span>: A predicate that matches join points.
Advice is associated with a pointcut expression and runs at any join
point matched by the pointcut (for example, the execution of a method with
a certain name).<br />
</li>
<li><span class="emphasis"><i>Introduction</i></span>: (Also known as an
inter-type declaration). Declaring additional methods or fields on
behalf of a type. Spring AOP allows you to introduce new interfaces
(and a corresponding implementation) to
any proxied object. For example, you could use an introduction to
make a bean implement an <tt class="literal">IsModified</tt>
interface, to simplify caching.<br />
</li>
<li><span class="emphasis"><i>Target object</i></span>: Object being advised
by one or more aspects. Also referred to as the <span class="emphasis"><i>advised</i></span>
object. Since Spring AOP is implemented using runtime proxies, this object
will always be a <span class="emphasis"><i>proxied</i></span> object.<br />
</li>
<li><span class="emphasis"><i>AOP proxy</i></span>: An object created by the AOP
framework in order to implement the aspect contracts (advise method
executions and so on). In the Spring Framework, an AOP proxy will be a JDK
dynamic proxy or a CGLIB proxy. <span class="emphasis"><i>Proxy creation is
transparent to users of the schema-based and @AspectJ styles of
aspect declaration introduced in Spring 2.0.</i></span><br />
</li>
<li><span class="emphasis"><i>Weaving</i></span>: Linking aspects with other
application types or objects to create an advised object. This can be
done at compile time (using the AspectJ compiler, for example), load time,
or at runtime. Spring AOP, like other pure Java AOP frameworks, performs
weaving at runtime.<br />
</li>
</ul>
Types of Advices<br />
<br />
<ul style="text-align: left;">
<li>@Before : Execute before a join point</li>
<li>@After (finally) : Execute after join point regardless of sucessul or exception case</li>
<li>@AfterReturning : Execute after join point on successful method execution</li>
<li>@AfterThrowing : Execute after join point on execption</li>
<li>@Around : Surrounds a joinpoint. The aspect will have complete control before during and after method invocation </li>
</ul>
<u><b>Proxy: </b></u><br />
<br />
Spring using Java Dynamic proxies for AOP Proxies. CGLib is used when the objects do not implement an interfaces<br />
<br />
<u><b>How to Allow Spring to load @Aspect annotation</b></u><br />
<br />
<pre class="programlisting"><aop:aspectj-autoproxy/></pre>
<pre class="programlisting"> </pre>
<pre class="programlisting"> </pre>
<br />
<u><b>Pointcut Expression</b></u><br />
<u><b><br /></b></u>
This expression defines the matching patter, to which these advices should be applied.<br />
<br />
<u><i>Simple syntax is defined as follows</i></u><br />
<a href="http://4.bp.blogspot.com/-CL5oZkrMjDs/Uz_O8M9MkMI/AAAAAAAAAjo/w0SmkLPWj2Q/s1600/aop5.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://4.bp.blogspot.com/-CL5oZkrMjDs/Uz_O8M9MkMI/AAAAAAAAAjo/w0SmkLPWj2Q/s1600/aop5.png" height="104" width="640" /></a><br />
<pre class="programlisting"> </pre>
<pre class="programlisting"></pre>
<pre class="programlisting"><u><b>Simple example of defining aspect in Spring.</b></u></pre>
<pre class="programlisting"></pre>
<hr />
<pre class="programlisting"><b>Aspect</b></pre>
<hr />
<pre class="programlisting"></pre>
<pre class="programlisting"></pre>
<pre class="programlisting"> </pre>
<pre class="brush:java">package org.first.aspects;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
<span style="background-color: yellow;">@Aspect</span>
public class FirstAspect
{
<span style="background-color: yellow;">@Before("execution(* org.first.*.*(..))")
public void before()</span>
{
System.out.println("---Logging before --");
}
<span style="background-color: yellow;"> @After("execution(* org.first.*.*(..))")
public void after()</span>
{
System.out.println("---Logging After--");
}
}
</pre>
<pre class="programlisting"> </pre>
<pre class="programlisting"> </pre>
<hr />
<pre class="programlisting"><b>Bean Class</b></pre>
<hr />
<pre></pre>
<pre class="programlisting"></pre>
<pre class="brush:java"> </pre>
<pre class="brush:java">package org.first;
public class FirstServiceImpl //implements FirstService
{
public FirstServiceImpl()
{
}
public String printMessage()
{
final String s = "--printMessage()---";
System.out.println(s);
return s;
}
public String messagePrint()
{
final String s = "--messagePrint()---";
System.out.println(s);
return s;
}
}
<hr />
beans.xml
<hr />
<pre><?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"> </pre>
<pre> </pre>
<pre> <!--Aspect definitions are defined in the class --> </pre>
<pre> <span style="background-color: yellow;"><aop:aspectj-autoproxy /></span> </pre>
<pre> </pre>
<pre> <!-- Without this the aspects are not instantiated --> </pre>
<pre> <<span style="background-color: yellow;">bean </span>id="aspect" class="<span style="background-color: yellow;">org.first.aspects.FirstAspect</span>" />
</beans>
</pre>
</pre>
<hr />
<pre class="brush:java">Dependencies</pre>
<hr />
<pre class="brush:java"></pre>
<pre class="brush:java"> </pre>
<pre class="brush:java"><dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring-framework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId><span style="background-color: yellow;">spring-aop</span></artifactId>
<version>${spring-framework.version}</version>
</dependency>
<!-- @Aspect Annotation -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId><span style="background-color: yellow;">spring-aspects</span></artifactId>
<version>${spring-framework.version}</version>
</dependency>
<pre class="brush:java"></pre>
</pre>
<hr />
<pre class="brush:java">Test code</pre>
<hr />
<pre class="brush:java"> </pre>
<pre class="brush:java">import org.first.FirstService;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class AOPTest
{
ApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");
@Test
public void testContext()
{
final FirstService service = (FirstService) ctx.getBean("firstService");
<span style="background-color: yellow;"> service.printMessage();</span>
}
}
</pre>
<pre class="brush:java"></pre>
<hr />
Output
<br />
<hr />
<br />
<br />
<pre class="brush:java"><u><b>References :</b></u><b> </b>http://docs.spring.io/spring/docs/2.0.x/reference/aop.html</pre>
<pre class="brush:java"> </pre>
<pre class="brush:java"> </pre>
</div>
</div>
Anonymoushttp://www.blogger.com/profile/13196480231236274690noreply@blogger.com0tag:blogger.com,1999:blog-2002003343323875763.post-71350005830865703332015-01-30T06:58:00.000-08:002015-01-30T06:58:40.209-08:00HIbernate : How to get more details on "Errors in Named Queries"<div dir="ltr" style="text-align: left;" trbidi="on">
<b><u><br /></u></b>
<b><u>ERROR Seen when there is a problem in the named query </u></b><br />
<br />
<span style="font-family: Courier New, Courier, monospace;">org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'Dao': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'DaoImpl': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/spring/sessionfactory-cfg.xml]: Invocation of init method failed; nested exception is <span style="background-color: yellow;">org.hibernate.HibernateException: Errors in named queries: select_records_with_auth</span></span><br />
<div>
<br /></div>
<div>
<br /></div>
<div>
Just gives you a high level error.</div>
<div>
<br /></div>
<div>
To get more details change the loglevel. (Below example is of log4j)</div>
<div>
<br /></div>
<div>
<div>
<span style="font-family: Courier New, Courier, monospace;"><logger name='<b style="background-color: orange;">org.hibernate</b>' level='<span style="background-color: orange;">DEBUG</span>' additivity="false"></span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;"> <appender-ref ref='DebugLogFile'/></span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;"></logger></span></div>
</div>
<div>
<br /></div>
<div>
<b><u>you will get indepth details as shown below</u></b></div>
<div>
<br /></div>
<div>
<div>
<span style="font-family: Courier New, Courier, monospace;">2015-01-30 14:46:29.864 UTC,ERROR,***-web,,org.hibernate.hql.PARSER,null,RMI TCP Connection(3)-127.0.0.1,line 2:10: expecting IDENT, found '*'</span></div>
<div>
<span style="background-color: orange; font-family: Courier New, Courier, monospace;">2015-01-30 14:46:29.874 UTC,DEBUG,index-web,,org.hibernate.hql.ast.ErrorCounter,null,RMI TCP Connection(3)-127.0.0.1,line 2:10: expecting IDENT, found '*'</span></div>
<div>
<span style="background-color: orange; font-family: Courier New, Courier, monospace;">antlr.MismatchedTokenException: expecting IDENT, found '*'</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;"> at antlr.Parser.match(Parser.java:211) ~[antlr.jar:na]</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;"> at org.hibernate.hql.antlr.HqlBaseParser.identifier(HqlBaseParser.java:1612) [hibernate-core.jar:3.6.10.Final]</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;"> at org.hibernate.hql.antlr.HqlBaseParser.atom(HqlBaseParser.java:3691) [hibernate-core.jar:3.6.10.Final]</span></div>
</div>
<div>
<br /></div>
<div>
<br /></div>
</div>
Anonymoushttp://www.blogger.com/profile/13196480231236274690noreply@blogger.com2tag:blogger.com,1999:blog-2002003343323875763.post-46747698321526889182014-12-17T06:31:00.000-08:002014-12-17T06:31:34.187-08:00[Share Video] HDFS - Hadoop distributed file system, Introduction
<div dir="ltr" style="text-align: left;" trbidi="on">
I came across this simple and short video on HDFS a introduction<br />
<br />
<iframe allowfullscreen="" frameborder="0" height="360" src="http://www.youtube.com/embed/CMdVzhrW6NM" width="640"></iframe></div>Anonymoushttp://www.blogger.com/profile/13196480231236274690noreply@blogger.com1tag:blogger.com,1999:blog-2002003343323875763.post-60284657557878366022014-06-21T03:36:00.001-07:002014-06-21T03:36:11.670-07:00[Solution] .bat file don't proceed after mvn clean install<div dir="ltr" style="text-align: left;" trbidi="on">
Executing .bat does not proceed after mvn clean install.<br />
<br />
<span style="font-family: Courier New, Courier, monospace;">mvn -o clean install</span><br />
<span style="font-family: Courier New, Courier, monospace;">echo $classpath </span> -- This never executes<br />
<br />
<b>Solution :</b><br />
<br />
<span style="font-family: Courier New, Courier, monospace;"><b><i><span style="color: #6fa8dc; font-size: large;">call </span></i></b>mvn -o clean install </span><br />
<span style="font-family: Courier New, Courier, monospace;">echo $classpath </span><br />
<br />
<b>Reason: </b>.bat file, halts after calling another program. CALL command is invoke another program from the current and proceed further<br />
<br />
<b>Reference:</b> <a href="http://www.computerhope.com/call.htm">http://www.computerhope.com/call.htm</a><br />
<br /></div>
Anonymoushttp://www.blogger.com/profile/13196480231236274690noreply@blogger.com0tag:blogger.com,1999:blog-2002003343323875763.post-27836088261703931692014-04-05T07:55:00.003-07:002014-04-05T07:55:24.916-07:00Spring : context:component-scan vs context:annotation-config<div dir="ltr" style="text-align: left;" trbidi="on">
<h2 style="text-align: left;">
Whats the difference between component-scan and annotation-config</h2>
<ul>
<li><span style="background-color: yellow;"><context:annotation-config/> </span>-
Looks for @Autowired and JSR annotation, It does not identify the
@component, @configuration annotations. It just autowires existing
beans<br /> </li>
<li>whereas <span style="background-color: yellow;"><context:component-scan base-package="org.first" /></span> Does recoginize @Autowired, @component and other annotations also.<br /> </li>
<li><<span style="background-color: yellow;">context:component-scan> also does </span><span style="background-color: yellow;"><context:annotation-config/> and also scans packages to find registeredbeans</span></li>
</ul>
<hr />
<h3 style="text-align: left;">
Example 1 : Let's define the classes in beans.xml and also annotate with @Component and @Autowired</h3>
<pre class="brush:java">package org.first;</pre>
<pre class="brush:java">@<span style="background-color: yellow;">Component</span>
public class <span style="background-color: yellow;">FirstServiceImpl </span>implements FirstService{
</pre>
<pre class="brush:java"> public Name userName;</pre>
<pre class="brush:java">
</pre>
<pre class="brush:java"><pre class="brush:java"> public FirstServiceImpl(){</pre>
<pre class="brush:java"> System.out.println("<span style="background-color: yellow;">new FirstServiceImpl()</span>");
}
</pre>
<pre class="brush:java">
</pre>
<pre class="brush:java"> @<span style="background-color: yellow;">Autowired</span></pre>
<pre class="brush:java"> public void setUserName(final Name userName){
System.out.println("<span style="background-color: yellow;">setUserName(final Name userName)</span>");
this.userName = userName;
}</pre>
<div>
</div>
<div>
//getters, setters, other constructors</div>
</pre>
<pre class="brush:java">}
</pre>
<pre class="brush:java">
</pre>
<pre class="brush:java">package org.first;
</pre>
<pre class="brush:java">@<span style="background-color: yellow;">Component</span></pre>
<pre class="brush:java">public class Name{</pre>
<pre class="brush:java"> String name = "new";
public Name(){
super();</pre>
<pre class="brush:java"> System.out.println("<span style="background-color: yellow;">new Name()</span>");
}</pre>
<pre class="brush:java"> //getters, setters, other constructors
}
</pre>
<div>
<br /></div>
<div>
<b><u>beans.xml</u></b></div>
<b><u><br /></u></b>
<pre><beans><!-- Add Namesapece here --></pre>
<pre> <<span style="background-color: yellow;">bean </span>name="userName" class="org.first.Name">
<property name="name" value="Vidhya"></property>
</bean>
<<span style="background-color: yellow;">bean </span>name="firstService" class="org.first.FirstServiceImpl">
<property name="userName" ref="userName"></property>
</bean>
</beans></pre>
<pre>
</pre>
<pre><b style="font-family: 'Times New Roman'; white-space: normal;"><u>
</u></b></pre>
<pre><b style="font-family: 'Times New Roman'; white-space: normal;"><u>OUTPUT : </u></b>This will instantiate the userName and firstService classes, because both classes are defined in the xml</pre>
<pre>
</pre>
<pre>new Name()
new FirstServiceImpl()
setUserName(final Name userName)
</pre>
<div>
<br /></div>
<pre>
</pre>
<pre><pre class="brush:java"><pre><pre class="brush:java"><hr style="font-family: 'Times New Roman'; white-space: normal;" />
<h3 style="text-align: left;">
<span style="font-family: 'Times New Roman'; white-space: normal;">Example 2 : Lets try to use <context-annotation-config> : </span></h3>
</pre>
</pre>
</pre>
</pre>
<pre><pre class="brush:java"><pre class="brush:java">
</pre>
<pre class="brush:java">package org.first;</pre>
<pre class="brush:java">@<span style="background-color: yellow;">Component</span>
public class FirstServiceImpl implements FirstService{
</pre>
<pre class="brush:java"> public Name userName;
</pre>
<pre class="brush:java"><pre class="brush:java"> public FirstServiceImpl(){</pre>
<pre class="brush:java"> System.out.println("<span style="background-color: yellow;">new FirstServiceImpl()</span>");
}
</pre>
<pre class="brush:java">
</pre>
<pre class="brush:java"> @<span style="background-color: yellow;">Autowired</span></pre>
<pre class="brush:java"> public void setUserName(final Name userName){
System.out.println("<span style="background-color: yellow;">setUserName(final Name userName)</span>");
this.userName = userName;
}</pre>
<div>
</div>
<div>
//getters, setters, other constructors</div>
</pre>
<pre class="brush:java">}
</pre>
<pre class="brush:java">
</pre>
<pre class="brush:java">package org.first;
</pre>
<pre class="brush:java">public class Name{</pre>
<pre class="brush:java"> String name = "new";
public Name(){
super();</pre>
<pre class="brush:java"> System.out.println("<span style="background-color: yellow;">new Name()</span>");
}</pre>
<pre class="brush:java"> //getters, setters, other constructors
}
</pre>
<div style="font-family: 'Times New Roman'; white-space: normal;">
</div>
<div style="font-family: 'Times New Roman'; white-space: normal;">
<b><u>beans.xml</u></b></div>
<pre><pre class="brush:java"><pre><pre class="brush:java"><div style="font-family: 'Times New Roman'; white-space: normal;">
<beans><!-- Add Namesapece here --></div>
<pre><pre class="brush:java"><pre><span style="background-color: yellow;"> <context:annotation-config/></span></pre>
<pre></beans></pre>
<div>
</div>
</pre>
</pre>
</pre>
</pre>
</pre>
</pre>
<pre><b style="font-family: 'Times New Roman'; white-space: normal;"><u>
</u></b></pre>
<pre><b style="font-family: 'Times New Roman'; white-space: normal;"><u>OUTPUT : </u></b>This will NOT do anything. <b><i><u><span style="font-size: large;">NO OUTPUT</span></u></i></b>. Why? <i><b><span style="color: red;">The annotation-config cannot know about the beans unless defined. </span></b></i></pre>
<pre>
</pre>
<pre>How to fix this? We need to add bean definitions. <span style="color: #93c47d;"><b><i>Lets add the bean definitions in the beans.xml</i></b></span></pre>
<pre>
</pre>
<pre><span style="font-family: 'Times New Roman'; white-space: normal;">
</span></pre>
<hr style="font-family: 'Times New Roman'; white-space: normal;" />
<h3 style="text-align: left;">
<span style="font-family: 'Times New Roman'; white-space: normal;">Example 3 : Lets use <context-annotation-config> and bring back the bean definitions.</span></h3>
<pre>
</pre>
<div>
<pre class="brush:java"><div style="font-family: 'Times New Roman'; white-space: normal;">
<b><u>beans.xml</u></b></div>
<pre><pre class="brush:java"><pre><pre class="brush:java"><div style="font-family: 'Times New Roman'; white-space: normal;">
<beans><!-- Add Namesapece here --></div>
<pre><pre class="brush:java"><pre><span style="background-color: yellow;"> <context:annotation-config/></span></pre>
<pre><span style="background-color: white;">
</span></pre>
<pre><span style="background-color: white;"> <</span><span style="background-color: yellow;">bean </span><span style="background-color: white;">name="userName" class="org.first.Name"></span></pre>
<pre><span style="background-color: white;"> <property name="name" value="Vidhya"></property>
</bean>
<</span><span style="background-color: yellow;">bean </span><span style="background-color: white;">name="firstService" class="org.first.FirstServiceImpl">
<property name="userName" ref="userName"></property>
</bean></span></pre>
<pre></beans></pre>
</pre>
</pre>
</pre>
</pre>
</pre>
</pre>
</pre>
</div>
<pre class="brush:java"></pre>
<div style="font-family: 'Times New Roman'; white-space: normal;">
</div>
<div style="font-family: 'Times New Roman'; white-space: normal;">
</div>
<pre><b style="font-family: 'Times New Roman'; white-space: normal;"><u>OUTPUT : </u></b>This will instantiate the userName and firstService classes, <b><i><span style="color: #6aa84f;">because both classes are defined in the xml</span></i></b></pre>
<pre>
</pre>
<pre>new Name()
new FirstServiceImpl()
setUserName(final Name userName)
</pre>
<div>
</div>
<div>
</div>
<div>
<hr style="font-family: 'Times New Roman'; white-space: normal;" />
<h3 style="text-align: left;">
<span style="font-family: 'Times New Roman'; white-space: normal;">Example 4 : So, what's the use of annotation-config? We saw that annotation-config cannot load @component, Now lets see if it can autowire, with same class as in Example 2.</span></h3>
</div>
<div>
<pre class="brush:java"><pre>
</pre>
<pre><b style="font-family: 'Times New Roman'; white-space: normal;"><u>beans.xml</u></b></pre>
<div>
<pre class="brush:java"><pre><pre class="brush:java"><pre><pre class="brush:java"><div style="font-family: 'Times New Roman'; white-space: normal;">
<beans><!-- Add Namesapece here --></div>
<pre><pre class="brush:java"><pre><span style="background-color: yellow;"> <context:annotation-config/></span></pre>
<pre><span style="background-color: white;">
</span></pre>
<pre><span style="background-color: white;"> <</span><span style="background-color: yellow;">bean </span><span style="background-color: white;">name="userName" class="org.first.Name"></span></pre>
<pre><span style="background-color: white;"> <property name="name" value="Vidhya"></property>
</bean>
<</span><span style="background-color: yellow;">bean</span><span style="background-color: white;"> name="firstService" class="org.first.FirstServiceImpl">
<strike> <b><i><span style="color: red;"><property name="userName" ref="userName"></property></span></i></b></strike>
</bean></span></pre>
<pre></beans></pre>
</pre>
</pre>
</pre>
</pre>
</pre>
</pre>
</pre>
</div>
<pre class="brush:java"></pre>
</pre>
</div>
<pre>
</pre>
<h4 style="text-align: left;">
<pre style="font-weight: normal;"><b style="font-family: 'Times New Roman'; white-space: normal;"><u>OUTPUT : </u></b></pre>
</h4>
<div>
new Name()
new FirstServiceImpl()
setUserName(final Name userName)</div>
<div>
</div>
<div>
</div>
<div>
<span style="color: #38761d; font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><b>Looks like annotation-config can autowire, but cannot instantiate @Component</b></span></div>
<div>
</div>
</pre>
</pre>
<pre><span style="font-family: 'Times New Roman'; white-space: normal;">
</span></pre>
<pre><pre class="brush:java"><hr style="font-family: 'Times New Roman'; white-space: normal;" />
</pre>
</pre>
<h3>
<span style="font-family: 'Times New Roman'; white-space: normal;">Example 5 : Lets use </span><<span style="background-color: yellow;">context:component-scan</span>> now. As per definition, it can read all@component classes and also autowire. We will check that</h3>
<pre><pre class="brush:java"><div>
package org.first;</div>
<div>
<pre><pre class="brush:java"><pre class="brush:java"><span style="background-color: yellow;">@Component</span>
public class FirstServiceImpl implements FirstService{
public Name userName;
</pre>
<pre class="brush:java">
</pre>
<pre class="brush:java"><pre class="brush:java"> public FirstServiceImpl(){</pre>
<pre class="brush:java"> System.out.println("<span style="background-color: yellow;">new FirstServiceImpl()</span>");
}
</pre>
<pre class="brush:java">
</pre>
<pre class="brush:java"> @<span style="background-color: yellow;">Autowired</span></pre>
<pre class="brush:java"> public void setUserName(final Name userName){
System.out.println("<span style="background-color: yellow;">setUserName(final Name userName)</span>");
this.userName = userName;
}</pre>
<div>
</div>
<div>
//getters, setters, other constructors</div>
</pre>
<pre class="brush:java">}
</pre>
<pre class="brush:java">
</pre>
<pre class="brush:java">package org.first;</pre>
<pre class="brush:java">@<span style="background-color: yellow;">Component</span>
public class Name{
</pre>
<pre class="brush:java"> String name = "new";
public Name(){
super();</pre>
<pre class="brush:java"> System.out.println("<span style="background-color: yellow;">new Name()</span>");
}</pre>
<pre class="brush:java"> //getters, setters, other constructors
}
</pre>
<div style="font-family: 'Times New Roman'; white-space: normal;">
</div>
<div style="font-family: 'Times New Roman'; white-space: normal;">
<b><u>beans.xml</u></b></div>
<pre><pre class="brush:java"><pre><pre class="brush:java"><div style="font-family: 'Times New Roman'; white-space: normal;">
<beans><!-- Add Namespace here --></div>
<pre><pre class="brush:java"><pre> <<span style="background-color: yellow;">context:component-scan base-package="org.first" /></span></pre>
<pre></beans></pre>
<pre>
</pre>
<pre><pre class="brush:java"><pre><b style="font-family: 'Times New Roman'; white-space: normal;"><u>OUTPUT : </u></b>There you go<b><i>.. Now we achieve with single line in beans.xml, which all @Component and @Autowired annotations.</i></b></pre>
<div>
</div>
</pre>
</pre>
</pre>
</pre>
</pre>
</pre>
</pre>
</pre>
</pre>
</pre>
</div>
<span style="font-family: Times New Roman;"><span style="white-space: normal;">new FirstServiceImpl()</span></span><br />
<span style="font-family: Times New Roman;"><span style="white-space: normal;">new Name()</span></span><br />
<span style="font-family: Times New Roman;"><span style="white-space: normal;">setUserName(final Name userName)</span></span><br />
<span style="font-family: Times New Roman;"><span style="white-space: normal;">
</span></span>
<div>
<pre><span style="font-family: 'Times New Roman'; white-space: normal;">
</span></pre>
<h3 style="text-align: left;">
<span style="font-family: 'Times New Roman'; white-space: normal;"><b><u>SUMMARY:</u></b></span></h3>
<pre><span style="font-family: 'Times New Roman'; white-space: normal;">1. </span><context:component-scan> is one stop solution for @Autowired and @Component </pre>
<pre>2.<context:annotation-config> can only do @Autowired.</pre>
<pre>3. I am readying the annotation-config is very useful in the web context with DispatcherServlet. But need to try that. Probably will write about it later when I try it.</pre>
<pre><span style="font-family: 'Times New Roman'; white-space: normal;">
</span></pre>
<h3 style="text-align: left;">
<span style="font-family: 'Times New Roman'; white-space: normal;">References</span></h3>
<pre><span style="font-family: 'Times New Roman'; white-space: normal;">http://docs.spring.io/spring/docs/3.0.0.M3/reference/html/ch04s11.html</span></pre>
</div>
</pre>
<div style="font-family: 'Times New Roman'; white-space: normal;">
http://www.tutorialspoint.com/spring/spring_annotation_based_configuration.htm</div>
<span style="font-family: Times New Roman;"><span style="white-space: normal;">http://stackoverflow.com/questions/7414794/difference-between-contextannotation-config-vs-contextcomponent-scan</span></span><br />
<span style="font-family: Times New Roman;"><span style="white-space: normal;">
</span></span>
<div style="font-family: 'Times New Roman'; white-space: normal;">
</div>
</pre>
</div>
Anonymoushttp://www.blogger.com/profile/13196480231236274690noreply@blogger.com2tag:blogger.com,1999:blog-2002003343323875763.post-24799425438510591932014-04-05T03:56:00.000-07:002014-04-05T03:56:00.027-07:00Example: Spring configuration using AnnotationConfigApplicationContext without XML<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
Below is the example for Bean configuration using AnnotationConfigApplicationContext.<br />
<br />
AnnotationConfigApplicationContext(<span style="background-color: yellow;"><Package to scan></span>) or<br />
AnnotationConfigApplicationContext(<span style="background-color: yellow;">@Configuration class with @bean declaration</span>)<br />
<br />
We have to make sure that the same beans are not marked @component and also defined in @configuration class<br />
<br />
<hr />
<hr />
Class with @component annotation
<br />
<hr />
<pre class="brush:java">package org.first;
import org.springframework.stereotype.Component;
<span style="background-color: yellow;">@Component</span>
public class FirstServiceImpl implements FirstService
{
public FirstServiceImpl()
{
}
public String printMessage()
{
final String s = "--printMessage()---";
System.out.println(s);
return s;
}
public String messagePrint()
{
final String s = "--messagePrint()---";
System.out.println(s);
return s;
}
public FirstServiceImpl getfirstService()
{
return new FirstServiceImpl();
}
}
</pre>
<hr />
Test code
<br />
<hr />
<br />
<pre class="brush:java">import org.first.FirstService;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
public class AOPTest
{
ApplicationContext ctx = new <span style="background-color: yellow;">AnnotationConfigApplicationContext</span><span style="background-color: yellow;">("org.first");</span>
@Test
public void testContext()
{
final FirstService service = ctx.getBean(FirstService.class);
service.printMessage();
}
}
</pre>
<pre class="brush:java">
</pre>
</div>
Anonymoushttp://www.blogger.com/profile/13196480231236274690noreply@blogger.com0tag:blogger.com,1999:blog-2002003343323875763.post-16594824908473099042014-04-05T03:36:00.001-07:002014-04-05T03:48:42.470-07:00Example : Spring context:component-scan and @Component<div dir="ltr" style="text-align: left;" trbidi="on">
Automatic Component scanning is useful in defining beans and autowiring them without defining them in an .xml file<br />
<br />
<br />
Below is the example with xml and and beans annotated<br />
<hr />
beans.xml<br />
<hr />
<pre><?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<span style="background-color: yellow;"><context:component-scan base-package="org.first" /></span>
</beans></pre>
<br />
<hr />
Class with @component annotation
<br />
<hr />
<pre class="brush:java">package org.first;
import org.springframework.stereotype.Component;
<span style="background-color: yellow;">@Component</span>
public class FirstServiceImpl implements FirstService
{
public FirstServiceImpl()
{
}
public String printMessage()
{
final String s = "--printMessage()---";
System.out.println(s);
return s;
}
public String messagePrint()
{
final String s = "--messagePrint()---";
System.out.println(s);
return s;
}
public FirstServiceImpl getfirstService()
{
return new FirstServiceImpl();
}
}
</pre>
<hr />
Test code
<br />
<hr />
<br />
<pre class="brush:java">import org.first.FirstService;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class AOPTest
{
ApplicationContext ctx = new <span style="background-color: yellow;">ClassPathXmlApplicationContext("beans.xml");</span>
@Test
public void testContext()
{
final FirstService service = ctx.getBean(FirstService.class);
service.printMessage();
}
}
</pre>
<pre class="brush:java"></pre>
</div>
Anonymoushttp://www.blogger.com/profile/13196480231236274690noreply@blogger.com0tag:blogger.com,1999:blog-2002003343323875763.post-11263738524232328652014-04-04T01:50:00.001-07:002014-04-04T01:59:41.321-07:00Spring Controller with Hibernate using ContextLoaderListener<div dir="ltr" style="text-align: left;" trbidi="on">
<ul style="text-align: left;">
<li>Below is a simple example to show how to instantiate the spring context in ContextLoaderListener and use in a HTTPServlet.<br /> </li>
<li>There are other ways of directly using Dispatcher servlet, but the is the basic way for a beginner. </li>
<li>Eclipse project for this example can be found here: <a href="https://www.dropbox.com/s/v9ulf4i2zu2q2s9/spring-web-contextloader.zip" target="_blank">spring-web-contextloader.zip</a><br /> </li>
<li>The given codebase does not contain the database scripts. You may want to create ur own tables and change the hibernate.cfg.xml and beans.xml with the database connection details<br /> </li>
<li>This code has been tested in a jetty webserver. But should work in any webserver </li>
</ul>
<br />
<ul style="text-align: left;">
</ul>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhcG0_lqBISDug4FMAdjhmJMmn0dprLSyzT8GR88SXb6B7jSnR8Ri6OOWniuMiUYSgN9NbmTYVEwE0HJlYnVsCR_BgYtTuRGziDn9WU2EcNJYIgtde8nFknVi2B5MCn7l7mpJcKi_Jd_AoZ/s1600/spring-web.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhcG0_lqBISDug4FMAdjhmJMmn0dprLSyzT8GR88SXb6B7jSnR8Ri6OOWniuMiUYSgN9NbmTYVEwE0HJlYnVsCR_BgYtTuRGziDn9WU2EcNJYIgtde8nFknVi2B5MCn7l7mpJcKi_Jd_AoZ/s1600/spring-web.png" /></a></div>
<br />
<br />
<hr />
Web.xml - <br />
<hr />
<pre><?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<!-- Spring app context using a listener -->
<listener>
<listener-class>org.springframework.web.context.<span style="background-color: yellow;">ContextLoaderListener</span></listener-class>
</listener>
<context-param>
<param-name><span style="background-color: yellow;">contextConfigLocation</span></param-name>
<param-value><span style="background-color: yellow;">/WEB-INF/beans.xml</span></param-value>
</context-param>
<display-name>spring-web</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<!-- Trying the simple Servlet type -->
<servlet>
<description></description>
<display-name>EmployeeServlet</display-name>
<servlet-name>EmployeeServlet</servlet-name>
<servlet-class>org.controllers.EmployeeServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>EmployeeServlet</servlet-name>
<span style="background-color: yellow;"> <url-pattern>*.action</url-pattern></span>
</servlet-mapping>
</web-app> </pre>
<hr />
beans.xml
<br />
<hr />
<pre><?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<bean name="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.hsqldb.jdbc.JDBCDriver" />
<property name="url" value="jdbc:hsqldb:hsql://localhost/section1" />
<property name="username" value="sa" />
<property name="password" value="" />
</bean>
<bean name="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="packagesToScan" value="org.entity" />
<property name="configLocation" value="<span style="background-color: yellow;">classpath:hibernate.cfg.xml</span>" />
</bean>
<bean name="<span style="background-color: yellow;">employeeDAO</span>" class="org.dao.EmployeeDAO">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
</beans>
</pre>
<hr />
hibernate.cfg.xml<br />
<hr />
<pre><?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">org.hsqldb.jdbc.JDBCDriver</property>
<property name="hibernate.connection.url">jdbc:hsqldb:hsql://localhost/section1</property>
<property name="hibernate.connection.username">sa</property>
<property name="hibernate.connection.password"></property>
<property name="hibernate.hbm2ddl.auto">update</property>
<!-- property name="hibernate.connection.pool_size">1</property -->
<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">true</property>
<property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>
<!-- mapping class="org.entity.Product" / -->
<span style="background-color: yellow;"><mapping class="org.entity.Employee" /></span>
</session-factory>
</hibernate-configuration>
</pre>
<hr />
Servlet - Manual Controller
<br />
<hr />
<pre class="brush:java">package org.controllers;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.dao.EmployeeDAO;
import org.entity.Employee;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
public class <span style="background-color: yellow;">EmployeeServlet </span>extends HttpServlet
{
ApplicationContext ctx = null;
@Override
protected void service(final HttpServletRequest req, final HttpServletResponse resp)
throws ServletException, IOException
{
if (ctx == null)
{
<span style="background-color: yellow;"> ctx = WebApplicationContextUtils.getWebApplicationContext(getServletContext());</span>
}
final String uri = req.getRequestURI();
System.out.println("---------------" + uri);
if (uri.contains("employee.action"))
{
getEmployee(req, resp);
}
}
public void getEmployee(final HttpServletRequest req, final HttpServletResponse resp)
throws ServletException, IOException
{
try
{
final EmployeeDAO dao = <span style="background-color: yellow;">ctx.getBean("employeeDAO", EmployeeDAO.class);</span>
final Employee emp = dao.getEmployee(null);
req.setAttribute("emp", emp);
req.getRequestDispatcher("employee.jsp").forward(req, resp);
}
catch (final Exception e)
{
e.printStackTrace();
}
req.getRequestDispatcher("errors.jsp").forward(req, resp);
}
}
</pre>
<hr />
DAO
<br />
<hr />
<pre class="brush:java">package org.dao;
import org.entity.Employee;
import org.hibernate.SessionFactory;
public class EmployeeDAO
{
private SessionFactory sessionFactory;
public void setSessionFactory(final SessionFactory sessionFactory)
{
this.sessionFactory = sessionFactory;
}
public Employee getEmployee(Integer id)
throws Exception
{
try
{
if (id == null)
{
id = 1;
}
<span style="background-color: yellow;"> final Employee emp = (Employee) sessionFactory.openSession().get(Employee.class, id);</span>
System.out.println("--sessionFactory.get(Employee.class, " + id + ") ---> " + emp);
return emp;
}
catch (final Exception e)
{
e.printStackTrace();
throw e;
}
}
}
</pre>
<hr />
Entity
<br />
<hr />
<pre class="brush:java">package org.entity;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
<span style="background-color: yellow;">@Entity</span>
public class Employee {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer employeeId;
private String firstName;
private String lastName;
private String jobTitle;
private Double salary;
public Employee() {
}
public Employee(Integer employeeId, String firstName, String lastName,
String jobTitle, Double salary) {
this.employeeId = employeeId;
this.firstName = firstName;
this.lastName = lastName;
this.jobTitle = jobTitle;
this.salary = salary;
}
.....................
Please pick up the code from the zip file
}</pre>
<pre class="brush:java"> </pre>
<hr />
employee.jsp
<br />
<hr />
<pre><%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<span style="background-color: yellow;">Employee : <%=request.getAttribute("emp") %></span>
<br/>
Employee using taglig : <c:out value="${requestScope.emp}"></c:out>
</body>
</html></pre>
<hr />
pom.xml
<br />
<hr />
<pre><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>spring-web</groupId>
<artifactId>spring-web</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<!-- Spring -->
<spring-framework.version>3.2.3.RELEASE</spring-framework.version>
<!-- Hibernate / JPA -->
<hibernate.version>4.2.1.Final</hibernate.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>3.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>3.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>3.2.0.RELEASE</version>
</dependency>
<!-- Hibernate -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate.version}</version>
</dependency>
<!-- db -->
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.2.8</version>
</dependency>
</dependencies>
<build>
....................</pre>
<pre> <!-- Please see attached zip containing the code --> </pre>
<pre> </build>
</project></pre>
<pre> </pre>
<pre>OUTPUT</pre>
<pre> <div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjukcnqI30lt-NqS7hbliKJP8AruQptBrFEjNcdIweHZmik0bp1h4aGRHiF-KITkkf_GklRW-LhaUMRKiejBcDpP_pfENnSlSmG3Ya8Zow1QKm2A7pqOHhn9nwGMC1qDJ_9lxgpyinEVUUH/s1600/spring-web-output.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjukcnqI30lt-NqS7hbliKJP8AruQptBrFEjNcdIweHZmik0bp1h4aGRHiF-KITkkf_GklRW-LhaUMRKiejBcDpP_pfENnSlSmG3Ya8Zow1QKm2A7pqOHhn9nwGMC1qDJ_9lxgpyinEVUUH/s1600/spring-web-output.png" /></a></div>
</pre>
<pre> </pre>
</div>
Anonymoushttp://www.blogger.com/profile/13196480231236274690noreply@blogger.com0tag:blogger.com,1999:blog-2002003343323875763.post-81625835379422836752014-04-03T09:55:00.001-07:002014-04-03T10:38:10.090-07:00Elasticsearch shards and replicas<b>Shards and replicas</b> : Here is a good explanation on this topic <span style="-webkit-text-size-adjust: auto; background-color: rgba(255, 255, 255, 0);">http://stackoverflow.com/a/15705989</span><div><span style="-webkit-text-size-adjust: auto; background-color: rgba(255, 255, 255, 0);"><br></span></div><div><span style="-webkit-text-size-adjust: auto; background-color: rgba(255, 255, 255, 0);"><br></span></div><div><span style="-webkit-text-size-adjust: auto; background-color: rgba(255, 255, 255, 0);"><b>Routing clustering and index internals: </b></span><span style="-webkit-text-size-adjust: auto;">http://exploringelasticsearch.com/advanced_techniques.html#ch-advanced</span></div><div><span style="-webkit-text-size-adjust: auto;"><br></span></div><div><span style="-webkit-text-size-adjust: auto;"><br></span></div><div><span style="-webkit-text-size-adjust: auto;"><b>Cluster join example</b> : http://thediscoblog.com/blog/2013/09/03/effortless-elasticsearch-clustering/</span></div><div><span style="-webkit-text-size-adjust: auto;"><br></span></div>Anonymoushttp://www.blogger.com/profile/13196480231236274690noreply@blogger.com0tag:blogger.com,1999:blog-2002003343323875763.post-11118758470332649142014-04-03T04:04:00.001-07:002014-04-03T04:04:31.867-07:00HibernateTemplate not advised starting Hibernate 4<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
Here is the simple example for spring and hibernate integration<br />
<a href="https://www.dropbox.com/s/oavrdrjbvo2a3s6/spring_hibernate.zip" target="_blank">spring_hibernate.zip</a><br />
<br />
The sessionFactory is injected into the DAO with all definitions in the beans.xml with datasource wired.<br />
<br />
<hr />
<br />
<pre>beans.xml </pre>
<hr />
<pre><beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean name="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.hsqldb.jdbc.JDBCDriver" />
<property name="url" value="jdbc:hsqldb:hsql://localhost/section1" />
<property name="username" value="sa" />
<property name="password" value="" />
</bean>
<bean name="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="packagesToScan" value="org.entity"/>
</bean>
<bean name="EmployeeDAO" class="org.dao.EmployeeDAO">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
</beans>
</pre>
<hr />
<pre>org.entity.Employee</pre>
<hr />
<pre class="brush:java" pre="">package org.entity;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity
public class Employee {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer employeeId;
private String firstName;
private String lastName;
private String jobTitle;
private Double salary;</pre>
<pre></pre>
<pre>..............</pre>
<pre>..............</pre>
<pre>}</pre>
<br />
<hr />
<pre>DAO</pre>
<hr />
<pre> </pre>
<pre> </pre>
<pre></pre>
<pre class="brush:java">package org.dao;
import org.entity.Employee;
import org.hibernate.SessionFactory;
public class EmployeeDAO {
private SessionFactory sessionFactory;
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
public void getEmployee() throws Exception {
try {
Employee emp = (Employee) sessionFactory.openSession().get(Employee.class, 1);
System.out.println("--sessionFactory.get(Employee.class, 1) ---> " + emp);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
}</pre>
<br />
<hr />
Test Code
<br />
<hr />
<pre class="brush:java">package org;
import org.dao.EmployeeDAO;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class EmployeeDAOTest {
ApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");
@Test
public void testGetEmployeeWithHibernate() throws Exception{
EmployeeDAO dao = (EmployeeDAO) ctx.getBean("EmployeeDAO");
dao.getEmployee();
}
}
</pre>
</div>
Anonymoushttp://www.blogger.com/profile/13196480231236274690noreply@blogger.com1tag:blogger.com,1999:blog-2002003343323875763.post-77231913011236652342014-04-03T01:25:00.003-07:002014-04-03T01:27:57.004-07:00Spring Database connection with HSQLDB using datasource<div dir="ltr" style="text-align: left;" trbidi="on">
Below is a simple example to try JDBC connection in Spring. This example does not have the complete code<br />
<br />
<hr />
DAO
<br />
<hr />
<pre class="brush:java">import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.sql.DataSource;
public class EmployeeDAO {
private DataSource datasource;
public EmployeeDAO() {
}
public EmployeeDAO(DataSource datasource) {
super();
this.datasource = datasource;
}
public DataSource getDatasource() {
return datasource;
}
public void setDatasource(DataSource datasource) {
this.datasource = datasource;
}
public void countEmployee() throws Exception{
Connection con = null;
try {
con = datasource.getConnection();
PreparedStatement ps = con.prepareStatement("select count(*) from employeebimap");
ResultSet rs = ps.executeQuery();
if(rs.next())
{
System.out.println("select count(*) from employeebimap ---> "+ rs.getString(1));
}
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
if (con != null)
con.close();
}
}
}
</pre>
<br />
<br />
<hr />
database-beans.xml in classpath <br />
<hr />
<pre><beans br="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean br="" class="org.springframework.jdbc.datasource.DriverManagerDataSource" name="datasource">
<property name="driverClassName" value="org.hsqldb.jdbc.JDBCDriver">
<property name="url" value="jdbc:hsqldb:hsql://localhost/section1">
<property name="username" value="sa">
<property name="password" value="">
</property></property></property></property></bean>
<bean class="EmployeeDAO" name="EmployeeDAO">
<property name="datasource" ref="datasource">
</property></bean>
<bean autowire="constructor" br="" class="EmployeeDAO" name="EmployeeDAOAutowired">
</bean>
</beans>
</pre>
<br />
<br />
<hr />
EmployeeDAOTest <br />
<hr />
<pre class="brush:java">import EmployeeDAO;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class EmployeeDAOTest {
ApplicationContext ctx = new ClassPathXmlApplicationContext("database-beans.xml");
@Test
public void testEmployee() throws Exception{
EmployeeDAO dao = (EmployeeDAO) ctx.getBean("EmployeeDAO");
dao.countEmployee();
}
@Test
public void testEmployeeAutowiredConstructor() throws Exception{
EmployeeDAO dao = (EmployeeDAO) ctx.getBean("EmployeeDAOAutowired");
dao.countEmployee();
}
}
</pre>
<br />
OUTPUT:<br />
<br />
select count(*) from employeebimap ---> 2<br />
select count(*) from employeebimap ---> 2<br />
<br />
<br /></div>
Anonymoushttp://www.blogger.com/profile/13196480231236274690noreply@blogger.com0