Parsing code for Stoker telnet output?


 

Joe Keenan

TVWBB Fan
Any of the other Stoker coders care to share the code they're using to parse the telnet output?

I'll admit, I'm just being lazy. I hate writing parsing code.
icon_wink.gif


TIA!

joe
 
Meh. Wasn't all that bad, but I'm not pulling out any of the diagnostic type data yet either. If anyone cares, here's the parser code for Objective-C/Foundation on Mac OS X:

<pre class="ip-ubbcode-code-pre">
- (void) parseTelnetOutput: (NSString *) stokerOutput
{
if ([stokerOutput rangeOfString:mad:":"].location != NSNotFound) // must have : after device ID or it's garbage
{
NSString *deviceID = nil;
NSString *tempC = nil;
NSString *tempUser = nil;
NSString *tempTarget = nil;
NSString *blower = nil;

NSScanner *scanner = [NSScanner scannerWithString:stokerOutput];

// first string (up to colon) is the Device ID

[scanner scanUpToString:mad:":" intoString:&deviceID];

if ([deviceID length] != 16) // bad deviceID
return;

[scanner scanUpToString:mad:" " intoString:nil]; // skip past the colon

for (int i = 0; i < 7; i++) // skip past the v0-v6 debug variables
{
[scanner scanUpToString:mad:" " intoString:nil];
}

[scanner scanUpToString:mad:" " intoString:&tempC]; // get the two temp variables
[scanner scanUpToString:mad:" " intoString:&tempUser];

if ([stokerOutput rangeOfString:mad:"PID"].location != NSNotFound) // if there's a PID string, then there's blower data
{
[scanner scanUpToString:mad:"tgt:" intoString:nil]; // skip past the tgt:
[scanner scanString:mad:"tgt:" intoString:nil];
[scanner scanUpToString:mad:" " intoString:&tempTarget]; // get the value

[scanner scanUpToString:mad:"blwr:" intoString:nil]; // skip past the blwr:
[scanner scanString:mad:"blwr:" intoString:nil];
[scanner scanUpToString:mad:" " intoString:&blower]; // get the value
}

NSLog (@"Stoker: parseTelnetOutput, deviceID: %@, tempUser: %@, target: %@, blower: %@", deviceID, tempUser, tempTarget, blower);

}

}
</pre>

Hmm. This software doesn't do a very nice job with code posting.
icon_frown.gif


joe
 
Out of curiosity, have you considered the JSON output mechanism? Seems like a much easier method to parse all of the relevant data in one swell foop and you don't need to worry about corner cases like disconnects during the telnet session, but it does take a few seconds to get a poll.
 
<BLOCKQUOTE class="ip-ubbcode-quote"><div class="ip-ubbcode-quote-title">quote:</div><div class="ip-ubbcode-quote-content">Originally posted by Jeff Bower:
Out of curiosity, have you considered the JSON output mechanism? Seems like a much easier method to parse all of the relevant data in one swell foop and you don't need to worry about corner cases like disconnects during the telnet session, but it does take a few seconds to get a poll. </div></BLOCKQUOTE>

I have both the HTTP (JSON) method and the Telnet method implemented in StokerX. The Stoker really seems to struggle doing the HTTP queries, considering how long it takes to answer them. And I've had reports that the front panel UI becomes very slow to respond as well when doing regular HTTP queries. So I implemented the Telnet method as well. Amir's StokerLog also does both.

And yes, dealing with the JSON data is much easier, and the code is much cleaner. But operationally, it's pretty limited. I already had the telnet code I needed from another application I wrote that used a telnet session to control/query a device. So rolling that into StokerX wasn't a big deal.

I'm going to release another beta this weekend, I think. I just have two issues I need to resolve first. I'm still working out the last bugs in the code to shut down the telnet logging output, and I have a UI freeze during a synchronous HTTP call when using the StokerX UI to change the target temp for the Stoker.

joe
 

 

Back
Top