<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Florent Clairambault &#187; Protocol</title>
	<atom:link href="http://florent.clairambault.fr/tag/protocol/feed" rel="self" type="application/rss+xml" />
	<link>http://florent.clairambault.fr</link>
	<description></description>
	<lastBuildDate>Sat, 04 Feb 2012 19:56:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4-alpha-19719</generator>
		<item>
		<title>The M2MP protocol</title>
		<link>http://florent.clairambault.fr/the-m2mp-protocol?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=the-m2mp-protocol</link>
		<comments>http://florent.clairambault.fr/the-m2mp-protocol#comments</comments>
		<pubDate>Sat, 12 Dec 2009 20:00:10 +0000</pubDate>
		<dc:creator>Florent Clairambault</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[M2M]]></category>
		<category><![CDATA[M2MP]]></category>
		<category><![CDATA[Protocol]]></category>
		<category><![CDATA[TC65]]></category>
		<category><![CDATA[TCP]]></category>

		<guid isPermaLink="false">http://florent.clairambault.fr/?p=2165</guid>
		<description><![CDATA[Today, I&#8217;m going to talk about a little protocol that I&#8217;ve implemented in few softwares (on TC65, .Net client and .Net server). It won&#8217;t be very interesting for most of you (99.99%). But still, I wanted to write it because it has been very useful and it might prevent you from writing the next stupid [...]]]></description>
			<content:encoded><![CDATA[<p>Today, I&#8217;m going to talk about a little protocol that I&#8217;ve implemented in few softwares (on TC65, .Net client and .Net server). It won&#8217;t be very interesting for most of you (99.99%). But still, I wanted to write it because it has been very useful and it might prevent you from writing the next <a href="#stupid">stupid M2M protocol specifications</a>.</p>
<h2>Motivations</h2>
<p>I made this simple protocol to solve very simple and common problems on M2M equipments, we want to :</p>
<ul>
<li>Transmit and receive in real-time</li>
<li>Transmit as few data as possible</li>
<li>Send and receive any kind of data</li>
</ul>
<p>So the basic ideas are to :</p>
<ul>
<li>Keep a TCP connection open all the time by sending regular keep-alive frames.</li>
<li>Define named channels that are only transmitted once</li>
<li>Send byte array, and two-dimensionnal byte arrays on these channels</li>
</ul>
<p>We rely on the TCP protocol for packet checksuming, packet ordering and every little things it does very well.</p>
<p>Basically, we send these kind of frames :</p>
<ul>
<li>Identification frames</li>
<li>Channel name to id definition</li>
<li>Data transmission of single byte arrays (Byte[]).</li>
<li>Data transmission of two-dimentionnal byte arrays (Byte[][]).</li>
</ul>
<h2>The protocol</h2>
<p><b>Identification</b><br />
The client ask for authentication :</p>

<div class="wp_codebox"><table><tr id="p216536"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p2165code36"><pre class="java" style="font-family:monospace;"><span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x01 <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// Identification header</span>
<span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x05 <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// Size of the identification</span>
<span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">5</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> <span style="color: #0000ff;">'h'</span>, <span style="color: #0000ff;">'e'</span>, <span style="color: #0000ff;">'l'</span>, <span style="color: #0000ff;">'l'</span>, <span style="color: #0000ff;">'o'</span> <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// Identifier</span></pre></td></tr></table></div>

<p>The server replies &#8220;ok&#8221; or &#8220;not ok&#8221;</p>

<div class="wp_codebox"><table><tr id="p216537"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p2165code37"><pre class="java" style="font-family:monospace;"><span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x01 <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// Identification request</span>
<span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x01 <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// OK, 0x00 for not ok</span></pre></td></tr></table></div>

<p><strong>Ping / Keep alives</strong><br />
Client sends a ping request :</p>

<div class="wp_codebox"><table><tr id="p216538"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p2165code38"><pre class="java" style="font-family:monospace;"><span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x02 <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// client ping request header</span>
<span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x15 <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// the number (here 0x15) can be incremented or random</span></pre></td></tr></table></div>

<p>Server answers the ping request :</p>

<div class="wp_codebox"><table><tr id="p216539"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p2165code39"><pre class="java" style="font-family:monospace;"><span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x02 <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// client ping server response header</span>
<span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x15 <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// where 0x15 is the number of the ping request</span></pre></td></tr></table></div>

<p>Server sends a ping request :</p>

<div class="wp_codebox"><table><tr id="p216540"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p2165code40"><pre class="java" style="font-family:monospace;"><span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x03 <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// server ping request header</span>
<span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x16 <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// the number (here 0x16) can be incremented or random</span></pre></td></tr></table></div>

<p>Client answers the ping request :</p>

<div class="wp_codebox"><table><tr id="p216541"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p2165code41"><pre class="java" style="font-family:monospace;"><span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x03 <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// server ping client response header</span>
<span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x16 <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// where 0x16 is the 0x16 number of the ping request</span></pre></td></tr></table></div>

<p><strong>Defining a named channel</strong><br />
<em>This applies to both client to server and server to client communcation.</em></p>

<div class="wp_codebox"><table><tr id="p216542"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p2165code42"><pre class="java" style="font-family:monospace;"><span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x20 <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// channel definition frame header</span>
<span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x0D <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// where 13 is the size of the following message</span>
<span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x03 <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// where 3 is the id of the channel</span>
<span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">12</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> <span style="color: #0000ff;">'c'</span>, <span style="color: #0000ff;">'h'</span>, <span style="color: #0000ff;">'a'</span>, <span style="color: #0000ff;">'n'</span>, <span style="color: #0000ff;">'n'</span>, <span style="color: #0000ff;">'e'</span>, <span style="color: #0000ff;">'l'</span>, <span style="color: #0000ff;">' '</span>, <span style="color: #0000ff;">'n'</span>, <span style="color: #0000ff;">'a'</span>, <span style="color: #0000ff;">'m'</span>, <span style="color: #0000ff;">'e'</span> <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// the name of the channel : &quot;channel name&quot;</span></pre></td></tr></table></div>

<p><strong>Sending some data</strong><br />
<em>This applies to both client to server and server to client communcation.</em></p>
<p>For 0 to 254 sized messages :</p>

<div class="wp_codebox"><table><tr id="p216543"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p2165code43"><pre class="java" style="font-family:monospace;"><span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x21 <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// one byte sized data transmission frame header</span>
<span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x06 <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// size of the data</span>
<span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x03 <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// where 3 is the id of the channel</span>
<span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">5</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x01, 0x02, 0x03, 0x04, 0x05 <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// data transmitted on the channel</span></pre></td></tr></table></div>

<p>For 255 to 65534 sized data messages :</p>

<div class="wp_codebox"><table><tr id="p216544"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p2165code44"><pre class="java" style="font-family:monospace;"><span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x41 <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// two bytes sized data transmission frame header</span>
<span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">2</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x00, 0x06 <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// size of the data</span>
<span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x03 <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// where 3 is the id of the channel</span>
<span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">5</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x01, 0x02, 0x03, 0x04, 0x05 <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// data transmitted on the channel</span></pre></td></tr></table></div>

<p>For 65 535 octets to 4 294 967 294 sized data messages :</p>

<div class="wp_codebox"><table><tr id="p216545"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p2165code45"><pre class="java" style="font-family:monospace;"><span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x61 <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// two bytes sized data transmission frame header</span>
<span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">4</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x00, 0x00, 0x00, 0x06 <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// size of the data</span>
<span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x03 <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// where 3 is the id of the channel</span>
<span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">5</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x01, 0x02, 0x03, 0x04, 0x05 <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// data transmitted on the channel</span></pre></td></tr></table></div>

<p>For data arrray transmission, it&#8217;s the same except frame header are 0&#215;22, 0&#215;42, 0&#215;62 instead of 0&#215;21, 0&#215;41, 0&#215;61. If you transmit data array like this one Byte[][] data = { { 0&#215;01, 0&#215;02 }, { 0&#215;03, 0&#215;04, 0&#215;05 }, { 0&#215;06, 0&#215;07, 0&#215;08, 0&#215;09 } } :</p>

<div class="wp_codebox"><table><tr id="p216546"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code" id="p2165code46"><pre class="java" style="font-family:monospace;"><span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x22 <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// one byte sized data transmission frame header</span>
<span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x0D <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// size of the data</span>
<span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x03 <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// where 3 is the id of the channel</span>
<span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x02 <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// size of the first array</span>
<span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">2</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x01, 0x02 <span style="color: #009900;">&#125;</span> 
<span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x03 <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// size of the second array</span>
<span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">3</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x03, 0x04, 0x05 <span style="color: #009900;">&#125;</span> 
<span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x04 <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// size of the third array</span>
<span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">4</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x06, 0x07, 0x08, 0x09 <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>For bigger arrays, you need to define :</p>

<div class="wp_codebox"><table><tr id="p216547"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code" id="p2165code47"><pre class="java" style="font-family:monospace;"><span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x42 <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// one byte sized data transmission frame header</span>
<span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x10 <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// size of the data (16)</span>
<span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x03 <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// where 3 is the id of the channel</span>
<span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">2</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x00, 0x02 <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// size of the first array</span>
<span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">2</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x01, 0x02 <span style="color: #009900;">&#125;</span> 
<span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">2</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x00, 0x03 <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// size of the second array</span>
<span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">3</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x03, 0x04, 0x05 <span style="color: #009900;">&#125;</span> 
<span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">2</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x00, 0x04 <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// size of the third array</span>
<span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">4</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x06, 0x07, 0x08, 0x09 <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>and so on :</p>

<div class="wp_codebox"><table><tr id="p216548"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code" id="p2165code48"><pre class="java" style="font-family:monospace;"><span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x62 <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// one byte sized data transmission frame header</span>
<span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x16 <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// size of the data (22)</span>
<span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x03 <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// where 3 is the id of the channel</span>
<span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">4</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x00, 0x00, 0x00, 0x02 <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// size of the first array</span>
<span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">2</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x01, 0x02 <span style="color: #009900;">&#125;</span> 
<span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">4</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x00, 0x00, 0x00, 0x03 <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// size of the second array</span>
<span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">3</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x03, 0x04, 0x05 <span style="color: #009900;">&#125;</span> 
<span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">4</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x00, 0x00, 0x00, 0x04 <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// size of the third array</span>
<span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">4</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x06, 0x07, 0x08, 0x09 <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h2>Sample data types transmitted</h2>
<p><strong>Strings</strong><br />
Easy&#8230; Just the bytes value of the string</p>
<p><strong>Position</strong><br />
when moving :</p>

<div class="wp_codebox"><table><tr id="p216549"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p2165code49"><pre class="java" style="font-family:monospace;"><span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">4</span> <span style="color: #009900;">&#93;</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Atimestamp+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Timestamp</span></a> <span style="color: #339933;">:</span> UInt32 <span style="color: #009900;">&#40;</span>since <span style="color: #cc66cc;">1970</span> or <span style="color: #cc66cc;">2009</span> <span style="color: #000000; font-weight: bold;">if</span> you wish<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">4</span> <span style="color: #009900;">&#93;</span> Longitude <span style="color: #339933;">:</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Afloat+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Float</span></a>
<span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">4</span> <span style="color: #009900;">&#93;</span> Latitude <span style="color: #339933;">:</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Afloat+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Float</span></a>
<span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">2</span> <span style="color: #009900;">&#93;</span> Speed <span style="color: #339933;">:</span> UInt16
<span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">2</span> <span style="color: #009900;">&#93;</span> Altitude <span style="color: #339933;">:</span> UInt16</pre></td></tr></table></div>

<p>= 16 bytes</p>
<p>when stopped :</p>

<div class="wp_codebox"><table><tr id="p216550"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p2165code50"><pre class="java" style="font-family:monospace;"><span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">4</span> <span style="color: #009900;">&#93;</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Atimestamp+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Timestamp</span></a> <span style="color: #339933;">:</span> UInt32 <span style="color: #009900;">&#40;</span>since <span style="color: #cc66cc;">1970</span> or <span style="color: #cc66cc;">2009</span> <span style="color: #000000; font-weight: bold;">if</span> you wish<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">4</span> <span style="color: #009900;">&#93;</span> Longitude <span style="color: #339933;">:</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Afloat+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Float</span></a>
<span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">4</span> <span style="color: #009900;">&#93;</span> Latitude <span style="color: #339933;">:</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Afloat+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Float</span></a></pre></td></tr></table></div>

<p>= 12 bytes</p>
<p><strong>Battery</strong><br />
Percentage :</p>

<div class="wp_codebox"><table><tr id="p216551"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p2165code51"><pre class="java" style="font-family:monospace;"><span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#93;</span> Percentage <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Abyte+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Byte</span></a><span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

<p>Voltage :</p>

<div class="wp_codebox"><table><tr id="p216552"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p2165code52"><pre class="java" style="font-family:monospace;"><span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">2</span> <span style="color: #009900;">&#93;</span> Voltage in mV <span style="color: #009900;">&#40;</span>UInt16<span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

<h2>Sample communication</h2>
<p>This is just to show how is working a sample communication</p>

<div class="wp_codebox"><table><tr id="p216553"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p2165code53"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">--&gt;</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x01, 0x04, 0x01, 0x02, 0x03, 0x04 <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// identification frame</span>
<span style="color: #339933;">&lt;--</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x01, 0x01 <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// identification accepted</span>
<span style="color: #339933;">--&gt;</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x20, 0x08, 0x00, <span style="color: #0000ff;">'b'</span>, <span style="color: #0000ff;">'a'</span>, <span style="color: #0000ff;">'t'</span>, <span style="color: #0000ff;">'t'</span>, <span style="color: #0000ff;">'e'</span>, <span style="color: #0000ff;">'r'</span>, <span style="color: #0000ff;">'y'</span> <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// We define the channel &quot;battery&quot; with id 0x00</span>
<span style="color: #339933;">--&gt;</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> 0x21, 0x02, 0x00, <span style="color: #cc66cc;">70</span> <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// We send 70 (meaning 70%) on the &quot;battery&quot; channel.</span></pre></td></tr></table></div>

<h2>On top of that</h2>
<p>On top of that, I added some settings management and status specifications.</p>
<p><strong>Settings management</strong><br />
The server can get and set some settings on the &#8220;_set&#8221; channel.<br />
If it&#8217;s a two-dimentionnal array and the first element is &#8220;s&#8221; (like &#8220;set&#8221;) it means that it sets some settings, the next elements will be &#8220;setting1=value1&#8243;, &#8220;setting2=value2&#8243;, etc.<br />
If it&#8217;s a two-dimentionnal array and the first element is &#8220;g&#8221; (like &#8220;get&#8221;) it means that it needs the client to report the value of some settings, like &#8220;setting1&#8243;, &#8220;setting2&#8243;<br />
If it&#8217;s a single dimentionnal array that contains &#8220;ga&#8221; (like &#8220;get all&#8221;) it means that the server wants the client to report the value of every settings.<br />
The client can also send &#8220;c&#8221;  (in the same format as the get) if a setting changed on the client side.</p>
<p>Sample transmission:<br />
Setting values:</p>

<div class="wp_codebox"><table><tr id="p216554"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p2165code54"><pre class="c" style="font-family:monospace;"> <span style="color: #339933;">--</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;_set&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">--&gt;</span> <span style="color: #009900;">&#123;</span> <span style="color: #ff0000;">&quot;s&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;setting1=value1&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;setting2=value2&quot;</span> <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>It&#8217;s the responsibility of the server to send an acknowledge request to know that the client has actually successfully received this settings.</p>
<p>Getting values:</p>

<div class="wp_codebox"><table><tr id="p216555"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p2165code55"><pre class="c" style="font-family:monospace;"> <span style="color: #339933;">--</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;_set&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">--&gt;</span> <span style="color: #009900;">&#123;</span> <span style="color: #ff0000;">&quot;g&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;setting1&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;setting2&quot;</span> <span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;--</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;_set&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">--</span>  <span style="color: #009900;">&#123;</span> <span style="color: #ff0000;">&quot;g&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;setting1=value1&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;setting2=value2&quot;</span> <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Setting and gettings value :</p>

<div class="wp_codebox"><table><tr id="p216556"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p2165code56"><pre class="c" style="font-family:monospace;"> <span style="color: #339933;">--</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;_set&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">--&gt;</span> <span style="color: #009900;">&#123;</span> <span style="color: #ff0000;">&quot;sg&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;setting1=value1&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;setting2=value2&quot;</span> <span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;--</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;_set&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">--</span>  <span style="color: #009900;">&#123;</span> <span style="color: #ff0000;">&quot;g&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;setting1=value1&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;setting2=value2&quot;</span> <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Gettings all the values :</p>

<div class="wp_codebox"><table><tr id="p216557"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p2165code57"><pre class="c" style="font-family:monospace;"> <span style="color: #339933;">--</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;_set&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">--&gt;</span> <span style="color: #ff0000;">&quot;ga&quot;</span>
<span style="color: #339933;">&lt;--</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;_set&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">--</span>   <span style="color: #009900;">&#123;</span> <span style="color: #ff0000;">&quot;g&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;setting1=value1&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;setting2=value2&quot;</span> <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><strong>Status parameters management</strong><br />
The server can get some status parameters on the &#8220;_sta&#8221; channel. Status are pretty much like settings except that they describe parameters that cannot be changed from the server.</p>
<p>Getting a parameter:</p>

<div class="wp_codebox"><table><tr id="p216558"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p2165code58"><pre class="c" style="font-family:monospace;"> <span style="color: #339933;">--</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;_sta&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">--&gt;</span> <span style="color: #009900;">&#123;</span> <span style="color: #ff0000;">&quot;g&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;version&quot;</span> <span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;--</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;_sta&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">--</span>  <span style="color: #009900;">&#123;</span> <span style="color: #ff0000;">&quot;g&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;version=0.0.1&quot;</span> <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Getting all parameters:</p>

<div class="wp_codebox"><table><tr id="p216559"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p2165code59"><pre class="c" style="font-family:monospace;"> <span style="color: #339933;">--</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;_sta&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">--&gt;</span> <span style="color: #009900;">&#123;</span> <span style="color: #ff0000;">&quot;ga&quot;</span> <span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;--</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;_sta&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">--</span>  <span style="color: #009900;">&#123;</span> <span style="color: #ff0000;">&quot;g&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;hw=tc65i/1.1&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;sw=sampleprogram/0.0.1&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;cap=sms,applicationA/1.0&quot;</span> <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Value changed on the client side</p>

<div class="wp_codebox"><table><tr id="p216560"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p2165code60"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">&lt;--</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;_set&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">--</span> <span style="color: #009900;">&#123;</span> <span style="color: #ff0000;">&quot;c&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;setting1=value1&quot;</span> <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><strong>Capacities</strong><br />
Previously, capacities where requested by server with the &#8220;?&#8221; message on the &#8220;_cap&#8221; channel but they are now handled through the standard status message and the &#8220;cap&#8221; parameter.</p>

<div class="wp_codebox"><table><tr id="p216561"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p2165code61"><pre class="c" style="font-family:monospace;"> <span style="color: #339933;">--</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;_sta&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">--&gt;</span> <span style="color: #009900;">&#123;</span> <span style="color: #ff0000;">&quot;g&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;cap&quot;</span> <span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;--</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;_sta&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">--</span>  <span style="color: #009900;">&#123;</span> <span style="color: #ff0000;">&quot;g&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;cap=sms_relay_send_1,gpio_1&quot;</span> <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><strong>Command execution</strong></p>

<div class="wp_codebox"><table><tr id="p216562"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p2165code62"><pre class="c" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// To send a command</span>
 <span style="color: #339933;">--</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;_cmd&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">--&gt;</span> <span style="color: #009900;">&#123;</span> <span style="color: #ff0000;">&quot;e&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;&lt;commandId&gt;&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;command&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;arg1&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;arg2&quot;</span> <span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">// To acknowledge the command</span>
<span style="color: #339933;">&lt;--</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;_cmd&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">--</span>  <span style="color: #009900;">&#123;</span> <span style="color: #ff0000;">&quot;a&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;&lt;commandId&gt;&quot;</span> <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><em>In the future commands could algo be acknowledge as a group by sending an acknowledge request.</em></p>
<p><strong>Files transmission</strong><br />
The server sends:</p>

<div class="wp_codebox"><table><tr id="p216563"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p2165code63"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">&lt;--</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;_fi:u&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">--</span> <span style="color: #009900;">&#123;</span> byte<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">5</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;file1&quot;</span><span style="color: #339933;">,</span> byte<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">4</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>uint32_t<span style="color: #009900;">&#41;</span> file1Size<span style="color: #339933;">,</span> byte<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">16</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> file1Hash<span style="color: #339933;">,</span> byte<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">5</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;file2&quot;</span><span style="color: #339933;">,</span> byte<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">4</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>uint32_t<span style="color: #009900;">&#41;</span> file2Size<span style="color: #339933;">,</span> byte<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">16</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> file2Hash <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>If the client wants to get the detailed subhashes:</p>

<div class="wp_codebox"><table><tr id="p216564"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p2165code64"><pre class="c" style="font-family:monospace;"> <span style="color: #339933;">--</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;_fi:h&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">--&gt;</span> <span style="color: #009900;">&#123;</span> byte<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">5</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;file1&quot;</span><span style="color: #339933;">,</span> byte<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">4</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>uint32_t<span style="color: #009900;">&#41;</span> size<span style="color: #339933;">,</span> byte<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">4</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>uint32_t<span style="color: #009900;">&#41;</span> offset1<span style="color: #339933;">,</span> byte<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">4</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>uint32_t<span style="color: #009900;">&#41;</span> offset2 <span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;--</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;_fi:h&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">--</span>  <span style="color: #009900;">&#123;</span> byte<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">5</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;file1&quot;</span><span style="color: #339933;">,</span> byte<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">4</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>uint32_t<span style="color: #009900;">&#41;</span> size<span style="color: #339933;">,</span> byte<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">4</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>uint32_t<span style="color: #009900;">&#41;</span> offset1<span style="color: #339933;">,</span> byte<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">16</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> hash<span style="color: #339933;">,</span> byte<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">4</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>uint32_t<span style="color: #009900;">&#41;</span> size<span style="color: #339933;">,</span> byte<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">16</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> hash <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Then if the client has a different value of the files:</p>

<div class="wp_codebox"><table><tr id="p216565"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p2165code65"><pre class="c" style="font-family:monospace;"> <span style="color: #339933;">--</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;_fi:g:file1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">--&gt;</span> <span style="color: #009900;">&#123;</span> byte<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">4</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>uint32_t<span style="color: #009900;">&#41;</span> offset<span style="color: #339933;">,</span> byte<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">4</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>uint32_t<span style="color: #009900;">&#41;</span> size <span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;--</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;_fi:g:file1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">--</span>  <span style="color: #009900;">&#123;</span> byte<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">4</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>uint32_t<span style="color: #009900;">&#41;</span> offset<span style="color: #339933;">,</span> byte<span style="color: #009900;">&#91;</span> x <span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> data<span style="color: #339933;">,</span> byte<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">16</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> file1Hash <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><strong>Publish/Subscribe (MQTT like)</strong><br />
You could subscribe to a channel &#8220;toto&#8221; using:</p>

<div class="wp_codebox"><table><tr id="p216566"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p2165code66"><pre class="c" style="font-family:monospace;"> <span style="color: #339933;">--</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;_pubsub&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">--&gt;</span> <span style="color: #009900;">&#123;</span> <span style="color: #ff0000;">&quot;s&quot;</span> <span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;toto&quot;</span> <span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;--</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;_pubsub&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">--</span>  <span style="color: #009900;">&#123;</span> <span style="color: #ff0000;">&quot;sa&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;toto&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#91;</span> <span style="color: #208080;">0x01</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>You could unsubscribe to a channel &#8220;toto&#8221; using:</p>

<div class="wp_codebox"><table><tr id="p216567"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p2165code67"><pre class="c" style="font-family:monospace;"> <span style="color: #339933;">--</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;_pubsub&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">--&gt;</span> <span style="color: #009900;">&#123;</span> <span style="color: #ff0000;">&quot;u&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;toto&quot;</span> <span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;--</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;_pubsub&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">--</span>  <span style="color: #009900;">&#123;</span> <span style="color: #ff0000;">&quot;ua&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;toto&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#91;</span> <span style="color: #208080;">0x01</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>And the rest is left like this.</p>
<p><strong>Gateway acting and sub equipements</strong><br />
Any equipment can act as a gateway by encapsulating data of an sub-equipment in a channel name like this &#8220;_eq/[sub equipment identifier]&#8221; but this has never been used for the moment.</p>
<p>Every packet coming from the sub-equipment is relayed to the server as a data packet.<br />
If the equipment, identified locally by &#8220;mac:112233445566&#8243; sends an identification to the server, this will work like this :<br />
Subequipment to Equipment:</p>

<div class="wp_codebox"><table><tr id="p216568"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p2165code68"><pre class="c" style="font-family:monospace;"><span style="color: #009900;">&#91;</span> <span style="color: #208080;">0x01</span> <span style="color: #208080;">0x04</span> <span style="color: #ff0000;">'t'</span> <span style="color: #ff0000;">'o'</span> <span style="color: #ff0000;">'t'</span> <span style="color: #ff0000;">'o'</span> <span style="color: #009900;">&#93;</span></pre></td></tr></table></div>

<p>This will be relayed to the server as data message like this :</p>

<div class="wp_codebox"><table><tr id="p216569"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p2165code69"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">--</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;_eq/mac:112233445566&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">--&gt;</span> <span style="color: #009900;">&#91;</span> <span style="color: #208080;">0x01</span><span style="color: #339933;">,</span> <span style="color: #208080;">0x04</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'t'</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'o'</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'t'</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'o'</span> <span style="color: #009900;">&#93;</span></pre></td></tr></table></div>

<p>Meaning in raw data :</p>

<div class="wp_codebox"><table><tr id="p216570"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p2165code70"><pre class="c" style="font-family:monospace;"><span style="color: #009900;">&#91;</span><span style="color: #208080;">0x21</span> <span style="color: #208080;">0x07</span> <span style="color: #208080;">0x03</span> <span style="color: #208080;">0x01</span> <span style="color: #208080;">0x04</span> <span style="color: #ff0000;">'t'</span> <span style="color: #ff0000;">'o'</span> <span style="color: #ff0000;">'t'</span> <span style="color: #ff0000;">'o'</span> <span style="color: #009900;">&#93;</span></pre></td></tr></table></div>

<p>(where 0&#215;03 is the generated channel id)</p>
<h2>Stupid protocols</h2>
<p>I&#8217;ve seen a lot of protocols from big companies doing some really stupid things like <a name="stupid">:</a></p>
<ul>
<li>Fixed size frames for not fixed size data.</li>
<li>4 zero filled bytes preamble. Why the hell would we need preamble in a TCP connection ?</li>
<li>8 bytes timestamp in millisecond when data has a 1 second precision.</li>
<li>4 bytes integer for specifying some number that never exceed 32.</li>
<li>Checksums on top of the TCP checksumming mechanism.</li>
<li>Redundant data at the beginning and the end.</li>
<li>Disconnecting very frequently (TCP establishment + identification costs a lot).</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://florent.clairambault.fr/the-m2mp-protocol/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>TC65 : Settings management</title>
		<link>http://florent.clairambault.fr/tc65-settings-management?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=tc65-settings-management</link>
		<comments>http://florent.clairambault.fr/tc65-settings-management#comments</comments>
		<pubDate>Fri, 11 Dec 2009 20:00:03 +0000</pubDate>
		<dc:creator>Florent Clairambault</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[M2M]]></category>
		<category><![CDATA[M2MP]]></category>
		<category><![CDATA[Protocol]]></category>
		<category><![CDATA[TC65]]></category>
		<category><![CDATA[TCP]]></category>

		<guid isPermaLink="false">http://florent.clairambault.fr/?p=2146</guid>
		<description><![CDATA[Someone recently asked me and the javacint group how we should handle settings. So I&#8217;ll give you two answers : ejw&#8217;s reply : You should use some simple DataInputStream and DataOutputStream objects. Mine : If you only store simple values (numbers and text), you should use a simple text file. It enables you to easily [...]]]></description>
			<content:encoded><![CDATA[<p>Someone recently asked me and the javacint group <a href="http://groups.google.com/group/javacint/browse_thread/thread/4cfb9c3754334291">how we should handle settings</a>. So I&#8217;ll give you two answers :</p>
<ul>
<li><a href="http://groups.google.com/group/javacint/msg/f226ea32c02d6d68">ejw&#8217;s reply</a> : You should use some simple DataInputStream and DataOutputStream objects.</li>
<li>Mine : If you only store simple values (numbers and text), you should use a simple text file. It enables you to easily see and modify settings outside the TC65.</li>
</ul>
<p>So, my little gift of today will be a simple settings management class. The idea is that this file is in a very simple format (that can be read in any PC) and it only stores settings that have changed. This is very important, it allows you to change the default behavior at next software update but also enable you to override some of the settings for each chip (like the last IMSI identifier of the SIM card). </p>
<p><em>I did something wrong in this example by writing all the methods with a starting Uppercase letter. The reason is that I do like a it a lot better like that (this is the C# style) but style, the good thing to do is to stick to each language&#8217;s coding conventions. I can&#8217;t really update this code as I have modified this class to a more complex version where other class register to this one to receive settings change event.</em></p>

<div class="wp_codebox"><table><tr id="p214672"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
</pre></td><td class="code" id="p2146code72"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">Common</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.microedition.io.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.siemens.icm.io.file.*</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * Settings management class
 * @author Florent Clairambault
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Settings <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// The cached settings</span>
	<span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ahashtable+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Hashtable</span></a> _settings<span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// File of the settings</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> _fileName <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;a:/settings.txt&quot;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// Singleton instance of the settings</span>
        <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> Settings _instance<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * Get Default instance of the Settings class
	 * @return The default instance of the Settings class
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">synchronized</span> Settings getInstance<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> _instance <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #009900;">&#41;</span>
			_instance <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Settings<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">return</span> _instance<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * Free the singleton instance
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">synchronized</span> <span style="color: #000066; font-weight: bold;">void</span> freeInstance<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		_instance <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * Load settings
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">synchronized</span> <span style="color: #000066; font-weight: bold;">void</span> load<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astringbuffer+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">StringBuffer</span></a> buffer <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astringbuffer+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">StringBuffer</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ahashtable+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Hashtable</span></a> settings <span style="color: #339933;">=</span> getDefaultSettings<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
&nbsp;
&nbsp;
			FileConnection fc <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>FileConnection<span style="color: #009900;">&#41;</span> Connector.<span style="color: #006633;">open</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;file:///&quot;</span> <span style="color: #339933;">+</span> _fileName, Connector.<span style="color: #006633;">READ</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainputstream+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">InputStream</span></a> is <span style="color: #339933;">=</span> fc.<span style="color: #006633;">openInputStream</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span> is.<span style="color: #006633;">available</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000066; font-weight: bold;">int</span> c <span style="color: #339933;">=</span> is.<span style="color: #006633;">read</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> c <span style="color: #339933;">==</span> <span style="color: #0000ff;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					loadTreatLine<span style="color: #009900;">&#40;</span> settings, buffer.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					buffer <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astringbuffer+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">StringBuffer</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span>
					buffer.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">char</span><span style="color: #009900;">&#41;</span> c <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			is.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			fc.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aioexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">IOException</span></a> ex <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">// The exception we shoud have is at first launch : </span>
			<span style="color: #666666; font-style: italic;">// There shouldn't be any file to read from</span>
&nbsp;
			<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> Logger.<span style="color: #006633;">E_CRITICAL</span> <span style="color: #009900;">&#41;</span>
				Logger.<span style="color: #006633;">Log</span><span style="color: #009900;">&#40;</span> <span style="color: #cc66cc;">19</span>, <span style="color: #0000ff;">&quot;Settings.Load&quot;</span>, ex <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		_settings <span style="color: #339933;">=</span> settings<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * Treat each line of the file
	 * @param def Default settings
	 * @param line Line to parse
	 */</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> loadTreatLine<span style="color: #009900;">&#40;</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ahashtable+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Hashtable</span></a> settings, <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> line <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> Logger.<span style="color: #006633;">E_VERBOSE</span> <span style="color: #009900;">&#41;</span>
			Logger.<span style="color: #006633;">Log</span><span style="color: #009900;">&#40;</span> <span style="color: #cc66cc;">78</span>, <span style="color: #0000ff;">&quot;loadTreatLine( [...], <span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span> <span style="color: #339933;">+</span> line <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span> );&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> spl <span style="color: #339933;">=</span> Common.<span style="color: #006633;">strSplit</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'='</span>, line <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> key <span style="color: #339933;">=</span> spl<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> value <span style="color: #339933;">=</span> spl<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// If default settings hashTable contains this key</span>
		<span style="color: #666666; font-style: italic;">// we can use this value</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> settings.<span style="color: #006633;">containsKey</span><span style="color: #009900;">&#40;</span> key <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			settings.<span style="color: #006633;">remove</span><span style="color: #009900;">&#40;</span> key <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			settings.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span> key, value <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * Get default settings
	 * @return Default settings Hashtable
	 */</span>
	<span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ahashtable+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Hashtable</span></a> getDefaultSettings<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ahashtable+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Hashtable</span></a> defaultSettings <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ahashtable+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Hashtable</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// General M2MSoft settings :</span>
		defaultSettings.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;code&quot;</span>, <span style="color: #0000ff;">&quot;8888&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		defaultSettings.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;servers&quot;</span>, <span style="color: #0000ff;">&quot;87.106.206.30:3000&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		defaultSettings.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;apn&quot;</span>, <span style="color: #0000ff;">&quot;gprs,m2minternet,<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #000099; font-weight: bold;">\&quot;</span>,<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #000099; font-weight: bold;">\&quot;</span>,,0&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		defaultSettings.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;imsi&quot;</span>, <span style="color: #0000ff;">&quot;0000&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		defaultSettings.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;watchdogtimer&quot;</span>, <span style="color: #0000ff;">&quot;20&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		defaultSettings.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;version&quot;</span>, <span style="color: #0000ff;">&quot;0&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		defaultSettings.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;phoneManager&quot;</span>, <span style="color: #0000ff;">&quot;+33686955405&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">return</span> defaultSettings<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * Reset everything
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">synchronized</span> <span style="color: #000066; font-weight: bold;">void</span> resetEverything<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			FileConnection fc <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>FileConnection<span style="color: #009900;">&#41;</span> Connector.<span style="color: #006633;">open</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;file:///&quot;</span> <span style="color: #339933;">+</span> _fileName, Connector.<span style="color: #006633;">READ_WRITE</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> fc.<span style="color: #006633;">exists</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
				fc.<span style="color: #006633;">delete</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        _settings <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ahashtable+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Hashtable</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Exception</span></a> ex <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> Logger.<span style="color: #006633;">E_CRITICAL</span> <span style="color: #009900;">&#41;</span>
				Logger.<span style="color: #006633;">Log</span><span style="color: #009900;">&#40;</span> <span style="color: #cc66cc;">16725</span>, <span style="color: #0000ff;">&quot;Settings.ResetEverything&quot;</span>, ex <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/** 
	 * save setttings
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">synchronized</span> <span style="color: #000066; font-weight: bold;">void</span> save<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// If there's no settings, we shouldn't have to save anything</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> _settings <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #009900;">&#41;</span>
			<span style="color: #000000; font-weight: bold;">return</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ahashtable+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Hashtable</span></a> defSettings <span style="color: #339933;">=</span> getDefaultSettings<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aenumeration+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Enumeration</span></a> e <span style="color: #339933;">=</span> defSettings.<span style="color: #006633;">keys</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			FileConnection fc <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>FileConnection<span style="color: #009900;">&#41;</span> Connector.<span style="color: #006633;">open</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;file:///&quot;</span> <span style="color: #339933;">+</span> _fileName, Connector.<span style="color: #006633;">READ_WRITE</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> fc.<span style="color: #006633;">exists</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
				fc.<span style="color: #006633;">delete</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #666666; font-style: italic;">//fc = (FileConnection) Connector.open(&quot;file:///&quot; + _fileName, Connector.READ_WRITE);</span>
			fc.<span style="color: #006633;">create</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aoutputstream+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">OutputStream</span></a> os <span style="color: #339933;">=</span> fc.<span style="color: #006633;">openOutputStream</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span> e.<span style="color: #006633;">hasMoreElements</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> key <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a><span style="color: #009900;">&#41;</span> e.<span style="color: #006633;">nextElement</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> value <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a><span style="color: #009900;">&#41;</span> _settings.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span> key <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> defValue <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a><span style="color: #009900;">&#41;</span> defSettings.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span> key <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #666666; font-style: italic;">// if there is a default value</span>
					defValue <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #666666; font-style: italic;">// and</span>
					<span style="color: #666666; font-style: italic;">// the value isn't the same as the default value</span>
					defValue.<span style="color: #006633;">compareTo</span><span style="color: #009900;">&#40;</span> value <span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #cc66cc;">0</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> line <span style="color: #339933;">=</span> key <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;=&quot;</span> <span style="color: #339933;">+</span> value <span style="color: #339933;">+</span> <span style="color: #0000ff;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: #339933;">;</span>
&nbsp;
					<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> Logger.<span style="color: #006633;">E_DEBUG</span> <span style="color: #009900;">&#41;</span>
						Logger.<span style="color: #006633;">Log</span><span style="color: #009900;">&#40;</span> <span style="color: #cc66cc;">131</span>, <span style="color: #0000ff;">&quot;Settings.save.line = <span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span> <span style="color: #339933;">+</span> line <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
					os.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span> line.<span style="color: #006633;">getBytes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
&nbsp;
			<span style="color: #009900;">&#125;</span>
			os.<span style="color: #006633;">flush</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			os.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			fc.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Exception</span></a> ex <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> Logger.<span style="color: #006633;">E_CRITICAL</span> <span style="color: #009900;">&#41;</span>
				Logger.<span style="color: #006633;">Log</span><span style="color: #009900;">&#40;</span> <span style="color: #cc66cc;">131</span>, <span style="color: #0000ff;">&quot;Settings.save&quot;</span>, ex <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * Init (and ReInit) method
	 */</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> checkLoad<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> _settings <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #009900;">&#41;</span>
			load<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * Get a setting's value as a String
	 * @param key Key Name of the setting
	 * @return String value of the setting
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">synchronized</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> getSetting<span style="color: #009900;">&#40;</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> key <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		checkLoad<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> _settings.<span style="color: #006633;">containsKey</span><span style="color: #009900;">&#40;</span> key <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
			<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a><span style="color: #009900;">&#41;</span> _settings.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span> key <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">else</span>
			<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * Sets a setting
	 * @param key Setting to set
	 * @param value Value of the setting
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">synchronized</span> <span style="color: #000066; font-weight: bold;">void</span> setSetting<span style="color: #009900;">&#40;</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> key, <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> value <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		checkLoad<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> _settings.<span style="color: #006633;">containsKey</span><span style="color: #009900;">&#40;</span> key <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
			_settings.<span style="color: #006633;">remove</span><span style="color: #009900;">&#40;</span> key <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		_settings.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span> key, value <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		OnSettingChanged<span style="color: #009900;">&#40;</span> key <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * Get a setting's value as an int
	 * @param key Key Name of setting
	 * @return Integer value of the setting
	 * @throws java.lang.NumberFormatException When the int cannot be parsed
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> getSettingInt<span style="color: #009900;">&#40;</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> key <span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Anumberformatexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">NumberFormatException</span></a> <span style="color: #009900;">&#123;</span>
		<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> value <span style="color: #339933;">=</span> getSetting<span style="color: #009900;">&#40;</span> key <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> value <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #009900;">&#41;</span>
			<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">return</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainteger+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Integer</span></a>.<span style="color: #006633;">parseInt</span><span style="color: #009900;">&#40;</span> value <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Latter on, I added some settings consumer capacities. It allows to use this class in some sort of &#8220;third party&#8221; developed components. Each component had to register itself to the settings management class, the settings management class could then request the default value settings it will provide, and it could set/get settings. The settings event class also launched an event when a setting was changed.</p>
]]></content:encoded>
			<wfw:commentRss>http://florent.clairambault.fr/tc65-settings-management/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Database Caching 1/23 queries in 0.010 seconds using disk: basic
Object Caching 1682/1727 objects using disk: basic

Served from: florent.clairambault.fr @ 2012-02-07 11:01:12 -->
