TC65FM : TC65 Fast Manager

I did this program because I had to reprogram some chips without a working MES deployment environment. I could deploy the TC65 program on a server but not upload it on the chip. And then I thought it could do a nice application for all the people deploying TC65 programs in a production environment.

What this program basically does is to respond to “^SYSSTART” messages coming from the TC65 chip to launch an OTAP update and/or launch the program. But in the details it does a little bit more as it can auto-detect the port of the chip.

Some of the features might not be working great or even not working at all. The program will be improved with the time, my testings and your comments but it’s currently used for my own needs.

You can download it.

Here is the “-h” output :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
TC65FM 0.1 - Fast Manager - Copyright WebIngenia 2010
 
 -b  --behavior <behavior>     Behavior, can be : 
       i  / install              Install only
       r  / run                  Run only
       ri / run-and-install      Run and install
       n  / none                 Nothing
 -na --net-apn <apn>           Network APN
 -nu --net-user <user>         Network User
 -np --net-password <password> Network password
 -nd --net-dns <dns>           Network DNS
 -au --application-url <url>   Application url
 -sA --serial-autodetect       Serial auto-Detect
 -sp --serial-port <port>      Serial port (default: COM4)
 -ss --serial-speed <speed>    Serial speed (defau:t 9600)
 -tp --target-program          Target program
 -ni --no-ipr                  Desactivate IPR command (not recommended)
 -ae --autostart-enable        Enable autostart
 -ad --autostart-disable       Disable autostart
 -at --autostart-time          Time before autostart
 -pc --password-current        Current password
 -pn --password-next           Next password
 -h  --help                    This help

There’s also a “network autodetection” feature which is in a very early stage. So if you want to test it you can using the “-nA” option (but you shouldn’t).

Let’s say you want to automatically install the program each time a chip (configured with a serial baudrate of 9600) connects to the COM4 port :

1
tc65fm -sp COM4 -ss 9600 -na "m2minternet" -nu "http://webingenia.com/myPath/myApp.jad" -tg "a:/wim2msoft.jad"

The program creates two types of log files. One for the complete running time and one for each communication with the chip occuring after a restart (and the identification of the chip by its IMEI).

Here is the logs of what you should get at each chip startup with this app :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
TC65FM v0.1 - Copyright Webingenia - www.webingenia.com
2010-07-17 09:43:25.682 | <-- AT
2010-07-17 09:43:25.733 | --> AT
2010-07-17 09:43:25.748 | --> OK
2010-07-17 09:43:25.766 | <-- AT+IPR=9600
2010-07-17 09:43:25.828 | --> AT+IPR=9600
2010-07-17 09:43:25.829 | --> OK
2010-07-17 09:43:25.847 | <-- AT+CFUN=1,1
2010-07-17 09:43:25.908 | --> AT+CFUN=1,1
2010-07-17 09:43:26.932 | --> OK
2010-07-17 09:43:30.164 | --> ^SYSSTART
2010-07-17 09:43:30.169 | <-- AT+CGSN
2010-07-17 09:43:30.228 | --> AT+CGSN
2010-07-17 09:43:30.292 | --> 353234023540741
2010-07-17 09:43:30.292 | --> OK
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
TC65FM v0.1 - Copyright Webingenia - www.webingenia.com
2010-07-17 09:43:31.174 | <-- ATE1
2010-07-17 09:43:31.236 | --> ATE1
2010-07-17 09:43:31.253 | --> OK
2010-07-17 09:43:31.256 | <-- AT^SJOTAP=,http://webingenia.com:8080/myPath/myApp.jad,a:,,,gprs,m2minternet,,,,,,
2010-07-17 09:43:31.413 | --> AT^SJOTAP=,http://webingenia.com:8080/myPath/myApp.jar,a:,,,gprs,m2minternet,,,,,,
2010-07-17 09:43:31.461 | --> OK
2010-07-17 09:43:31.477 | <-- AT^SJOTAP
2010-07-17 09:43:31.540 | --> AT^SJOTAP
2010-07-17 09:43:31.573 | --> OK
2010-07-17 09:43:31.578 | <-- AT^SCFG="Trace/Syslog/OTAP","1"
2010-07-17 09:43:31.668 | --> AT^SCFG="Trace/Syslog/OTAP","1"
2010-07-17 09:43:31.685 | --> SYSLOG ENABLED
2010-07-17 09:43:47.622 | --> [OTAP] GPRS connection established.
2010-07-17 09:43:47.702 | --> [OTAP] Try to get http://webingenia.com:8080/myPath/myApp.jad ...
2010-07-17 09:43:51.812 | --> [OTAP] Connected.
2010-07-17 09:43:51.861 | --> [OTAP] Transfer finished.
2010-07-17 09:43:51.941 | --> [OTAP] Try to get http://webingenia.com:8080/myPath/myApp.jar ...
2010-07-17 09:44:01.781 | --> [OTAP] Connected.
2010-07-17 09:44:02.340 | --> [OTAP] Transfer finished.
2010-07-17 09:44:05.541 | --> [OTAP] JAM status: 900 Success.
2010-07-17 09:44:11.524 | --> [OTAP] Reboot now.
2010-07-17 09:44:11.540 | --> ^SYSSTART
2010-07-17 09:44:11.544 | <-- AT+CGSN
2010-07-17 09:44:11.605 | --> AT+CGSN
2010-07-17 09:44:11.652 | --> 353234023540741
2010-07-17 09:44:11.668 | --> OK
1
2
3
4
5
6
7
8
9
10
11
12
13
14
TC65FM v0.1 - Copyright Webingenia - www.webingenia.com
2010-07-17 09:44:12.048 | <-- AT^SJRA=a:/secretApp.jad
2010-07-17 09:44:12.132 | --> AT^SJRA=a:/secretApp.jad
2010-07-17 09:44:12.389 | --> OK
2010-07-17 09:44:13.652 | --> WIM2MSoft
2010-07-17 09:44:14.036 | --> Thread-5 : [1/7] Initiating...
2010-07-17 09:44:14.534 | --> Thread-5 : [2/7] Loading settings...
2010-07-17 09:44:15.126 | --> Thread-5 : [3/7] main AT Command interface...
2010-07-17 09:44:15.222 | --> Thread-5 : [4/7] Loading SMS Management...
2010-07-17 09:44:15.510 | --> Thread-5 : [5/7] Checking SIM card...
2010-07-17 09:44:20.676 | --> Thread-5 : [6/7] Loading M2MP network communication...
2010-07-17 09:44:21.908 | --> Thread-5 : [7/7] Loading the main program...
2010-07-17 09:44:32.485 | --> nwr : NetworkLayer.Connect : Could not connect to 84.14.33.44:3000 ex : class javax.microedition.io.ConnectionNotFoundException :  Remote host has rejected the connection.
2010-07-17 09:44:53.845 | --> nwr : NetworkLayer.Connect : Could not connect to 84.14.33.44:3000 ex : class javax.microedition.io.ConnectionNotFoundException :  Remote host has rejected the connection.
GD Star Rating
loading...

Dear Google Analytics


Dear Google Analytics, or dear blog readers (if any). I just read the google analytics stats of a site and noticed a totally new source of traffic: “Other”. What do you think it could be ?

Somehow it reminded me this blog post of a graphic designer (who seems quite talented and very creative) :


GD Star Rating
loading...

Google Latitude History

I thought about this service as soon as Google released the Google Latitude service : “It would be great if they could save data so that we could see where we were at a specific time.” And I very quickly published some code to get my position (you could be tracking me right now with it). I thought they would never release the history saving feature as people would have feared for their privacy and things like that. But they did it.

http://www.google.com/latitude/apps/history

I don’t know if it’s just me but I find it somehow related to what does foursquare in the way that it both help you to connect to your friends and you become rich of the location data you give them. In foursquare you have the possibility to become the mayor of nearly anything. In Google Maps, well, you possess your own tracking data.
Which basically means that the more you track, the more you create content. Couldn’t it be one of the key motivational factors ?

Google knows my mails, my contacts, my web search history, my favorites (using chrome sync), my discussions (on google talk even though I’m progressively switching to Skype), my photos, my credit card number, some friends on orkut and now my position. If you think they’re an evil big brother, you should just create better products, I’ll switch to your instantly.

GD Star Rating
loading...

Technology brotherhoods


I often hear people talking about which technology is better between C / C++ / C# .Net / java. Most of the time, it’s more a political/brotherhood/community thing (like football, even thought frenchies like me aren’t so proud of their team now) than a technical talk.
I find it absurd. Computer science is about efficiency and making more money. You can take into account the pleasure you have to work on a technology (as you will be more likely to be more efficient with it), but it should still remain about efficiency.

The following video is about java & C# .Net. I’ve done quite a lot of C# .Net, Java and C, and some ObjectiveC (while developing iPhone applications) and a little bit of C++. The only thing I feel is that Sun with java had the good ideas, Microsoft with .Net took them and finished the work. Still, I often code in java, mostly for the TC65 chip, it’s quite comfortable. But for instance, it was longer to implement the M2MP protocol on the TC65 chip than the C# .net server. Mostly because of the unsigned types I had to “emulate” and the lack of generics (which are not available on the TC65′s JVM).

By the way, I’m running .Net apps on Linux everyday using Mono.

Here is the best example of what I’m talking about :

For all these lame people who don’t have an HTML5 compatible browser, you can go to the original video. The reason I downloaded it here in my blog is that you are forced to register to YouTube to watch it.

GD Star Rating
loading...

Nao the robot

I’ve got a highschool friend whose father started a robot company. And this isn’t any robot company, they built the finest consumer product robot. And she’s now representing the company and leading the communication around the robot in Shanghaï. She and her 9 people team, spent 5 full-time working months to do this quite amazing show :

Edit :
I just remembered my friend Alice already has a blog where she speaks about this great robot. My excuse for not remembering it is that she doesn’t update it very often.

GD Star Rating
loading...

I’m starting to like Skype


I’ve “always” used IM clients. I started with ICQ, switched to AIM, then MSN, then Jabber, then Gtalk and more recently Skype. I have all of them open, mostly because I like to be able to talk to everyone without forcing them to switch to something to talk to me but the main client I use, is currently Skype.

Skype is the only one client that isn’t open in any way (application and every protocols). Well I must say, they’ve released their SDK (SkypeKit) very recently (the 22/06/10). People can now build softwares around Skype. But this is not what I want to talk about.

Why I am starting to like Skype ? It’s the best around multiple computers. I can open it on Windows host, a Mac Os X host, a Linux host, and iPhone and still follow the same chat conversation without losing any word of it. What you received is shared among all computers and what you send too. This might also be the biggest drawback for some people. You have to take care of closing your session at work before talking trash about your boss.

Why I’m still not loving it ?

  • The available / away state clearly doesn’t work well. It just fails to automatically detect the available / away state. It feels like it’s a totally broken feature (and I’m not the only one who feels that way).
  • Exchanged messages sometimes have pretty important delays (something like 5 to 30 seconds).
GD Star Rating
loading...

Recycling .net objects to improve performances

C# .Net allocation and freeing system is quite efficient but when you need to create a huge number of objects, it’s just not fast enough. So what you can do is try to recycle each object to avoid to recreate them. You will then just need to set their property.

In my tests, this class reduced the allocation time from 12 to 15 times:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public sealed class Heap<T> where T:class, new() {
	private readonly Stack<T> _stack = new Stack<T>();
 
	private int _count;
 
	public T Allocate() {
		var obj = _count != 0 ? _stack.Pop() : new T();
		return obj;
	}
 
	public void Free( T obj ) {
		++_count;
		_stack.Push( obj );
	}
}

You might think that this process is really painful as you have to manually free every single objects you use. But in fact you just have to recycle most of the objects. If you forget some, that’s not really important (they will just get garbage collected).

GD Star Rating
loading...

A little TC65 development document

During the last months I spent some time writing a document on the TC65 development. It is primary aimed at TC65 project managers and developers.

This document can be considered as a draft and I’m waiting for any of your comments to fix / improve / complete it. It’s currently 40 pages long.

Here is the document.

GD Star Rating
loading...
Posted in English. Tags: , . 11 Comments »

Google PowerMeter and sample C# .Net API usage

Google PowerMeter offers you to collect your home’s / enterprise’s / specific equipment’s power usage and have some basic analysis on it.

There’s also a Google PowerMeter API so that everyone can build devices able to report their consumption and applications.

I would say one cheap and evolutive way to implement this API would be to use a Z-Wave power meter and have a Z-Wave central controller sent the data to Google servers. It could quickly get interesting because this could make you know the exact consumption of all your lights by calculating the result of the light-on/light-off order on individual lights. And this could even lead to define some max energy consumption scenarios so that you don’t allow more than X watts for all the lights of your house (this is just a idea, I would never put this in my home).

I know this isn’t the next BIG thing. Because everyone knows it’s all about the social right-now. But still, I think this could be the most green project of all time. Because it clearly shows people (or enterprises) how they consume energy and gives the useful analysis to find solutions. And for once it doesn’t try to make you feel guilty about not being green enough, it just brings facts.

By the way, you can have a negative energy consumption (power meter counting backward) in Google PowerMeter. I don’t think this is a bug, it must be for people selling their energy for their solar or wind energy producer equipments. But unfortunately you set the estimated cost of energy but you can’t set its estimated revenue price.

Sample API call

Here is a sample Google PowerMeter API call in C# .Net :
I just changed a little bit of the authentication parameters so that you can’t actually upload data on my account.

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
using System;
using System.Globalization;
using System.IO;
using System.Net;
using System.Text;
using System.Threading;
 
/* Equipment was activated with this URL :
 * https://www.google.com/powermeter/device/activate?mfg=WebIngenia&model=TestEquipment1&did=100102030405&cvars=1&dvars=0&rurl=http://test.webingenia.com/powerMeter&snonce=123
 *
 * The resulting request was (available here : http://test.webingenia.com/read/powerMeter#id2473 ) :
 * $_POST = array(
 *		[snonce] => 123
 *		[hash] => _____6c2562aeb7bab4e24afc7beeb18c701c04ba,____8c9f62fa8a137eba7fa35b5f58802fca2e56,____f4db13304c49d36fb81b20cabbe147f8ce34
 *		[token] => ________FhCtzebg_P____8BGMWjtUs
 *		[path] => /user/____4578579014915368/____4578579014915368/variable/WebIngenia.TestEquipment1.100102030405
 * )
 *
 */
 
namespace test {
	class Program {
 
		private static readonly Random _random = new Random();
 
		public const String DeviceHash = // Useless
			"____bf8262aeb7bab4e24afc7beeb18c701c04ba,____8c9f62fa8a137eba7fa35b5f58802fca2e56,____f4db13304c49d36fb81b20cabbe147f8ce34";
 
		public const String DeviceToken = // Needed for authentication
			"________FhCtzebg_P____8BGMWjtUs";
 
		public const String DevicePath = // URL of the device
			"/user/____4578579014915368/_____4578579014915368/variable/WebIngenia.TestEquipment1.100102030405";
 
		public const String DeviceVar = "c1";
 
		public const String FeedUrl = // URL of the Google PowerMeter API
			"https://www.google.com/powermeter/feeds";
 
		public const String EventUrl = // URL where to send the data
			FeedUrl + "/event";
 
		public const int Period = 5000; // 5 to 10 seconds
 
 
		static double MeterValue {
			get {
				return Settings.Default.MeterValue;
			}
			set {
				Settings.Default.MeterValue = value;
				Settings.Default.Save();
			}
		}
 
		static void Send() {
 
			// We increment the counter (by 0 to 1 kWh)
			MeterValue += _random.NextDouble();
 
			Console.WriteLine( "MeterValue : {0}", MeterValue );
 
			// This is what we are going to send
			var strContent = String.Format(
			@"
<feed xmlns=""http://www.w3.org/2005/Atom"" xmlns:meter=""http://schemas.google.com/meter/2008"">
	<entry>
      <category scheme=""http://schemas.google.com/g/2005#kind"" term=""http://schemas.google.com/meter/2008#instMeasurement"" />
      <meter:subject>{0}</meter:subject>
      <meter:occurTime meter:uncertainty=""1.0"">{1}</meter:occurTime>
      <meter:quantity meter:uncertainty=""0.001"" meter:unit=""kW h"">{2}</meter:quantity>
    </entry>
</feed>",
				FeedUrl + DevicePath + "." + DeviceVar,						// Device URL
				DateTime.UtcNow.ToString( "yyyy-MM-dd'T'HH:mm:ss.fffK" ),	// Current UTC date
				MeterValue.ToString( CultureInfo.InvariantCulture )			// Meter value
			);
 
			// We convert it into raw content
			var content = Encoding.UTF8.GetBytes( strContent );
 
			// We create the POST request
			var req = WebRequest.Create( EventUrl );
			req.Headers.Add( "Authorization", "AuthSub token=\"" + DeviceToken + "\"" );
			req.Method = "POST";
			req.ContentLength = content.Length;
			req.ContentType = "application/atom+xml";
 
			try {
				// Opening the request stream means starting the request
				Console.Write( "Requesting..." );
				using ( var requestStream = req.GetRequestStream() ) {
 
					// We send the content
					requestStream.Write( content, 0, content.Length );
 
					// And we end the request by getting the response
					using ( var streamReader = new StreamReader( req.GetResponse().GetResponseStream() ) ) {
						Console.WriteLine( "Result : " + streamReader.ReadToEnd() );
					}
				}
			}
			catch ( WebException e ) { // If a webException occurs (should be 400)
				// We display the error
				var response = e.Response as HttpWebResponse;
				if ( response == null ) // This is not the exception that we want
					throw;
				using ( response ) {
					using ( var responseStream = response.GetResponseStream() ) {
						Console.WriteLine(
							"Error {0} : {1} ",
							response.StatusCode,
							new StreamReader( responseStream ).ReadToEnd()
						);
					}
				}
			}
		}
 
		static void Main() {
			while ( true ) {
				try {
					Send();
				}
				catch ( Exception ex ) {
					Console.WriteLine( "Exception : " + ex );
				}
				Thread.Sleep( Period + _random.Next( Period ) );
			}
		}
 
		// This code was generated by Visual Studio (but I prefer to put it here rather than having to publish the VS project)
		#region Auto-generated
		[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
		[System.CodeDom.Compiler.GeneratedCodeAttribute( "Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "9.0.0.0" )]
		internal sealed class Settings:System.Configuration.ApplicationSettingsBase {
 
			private static Settings defaultInstance = ( (Settings) ( Synchronized( new Settings() ) ) );
 
			public static Settings Default {
				get {
					return defaultInstance;
				}
			}
 
			[System.Configuration.UserScopedSettingAttribute()]
			[System.Diagnostics.DebuggerNonUserCodeAttribute()]
			[System.Configuration.DefaultSettingValueAttribute( "3000" )]
			public double MeterValue {
				get {
					return ( (double) ( this[ "MeterValue" ] ) );
				}
				set {
					this[ "MeterValue" ] = value;
				}
			}
		}
		#endregion
	}
}

I didn’t let it running too much time but still you can see that it works :

GD Star Rating
loading...

WP-Codebox fix so that it doesn’t prevent posts export

If you have a PHP configured with some open_basedir restriction (which is recommended), the WP-Codebox plugin will prevent you from exporting the posts of your blog.

Go to your blog, go in the “wp-content/plugins/wp-codebox” dir and edit the “wp-codebox.php” file :
On line 27, you should have :

1
2
include_once "../../../wp-config.php";
include_once "../../../wp-settings.php";

Well, it fails because the plugin doesn’t use the good practices, so it’s pretty easy to fix :

1
2
require_once( ABSPATH.'/wp-config.php' );
require_once( ABSPATH.'/wp-settings.php' );

I’d like to thank the developer of this plugin for doing such a great job. It brings the power of geshi (not the latest version by the way) into wordpress.

BTW, why change :
* include_once to require_once : Why should we accept that a file couldn’t be included on go on ?
* double quote to simple quote : php reads it faster because it doesn’t parse vars (“$” starting words).
* no parenthesis to parenthesis : Well, it’s a method isn’t it ?
GD Star Rating
loading...