Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Driver for Bigass Fan
#1
So I started to write a CML driver for my BAF Haiku fan, based on the unpublished protocol and CML drivers by others.

In short, any command sent to the device needs to be enclosed between < starting and > ending delimiters device replies or status updates are enclosed in between (...) round brackets.

I would like to check if for getting the messages from the devices I could use the helper function below and define the startbyte and endbyte to be the round brackets?



Code:
GetASCIIStartStopMsg2
(
   [InOut] MEng.Object SrcObj
   , [In]  MEng.Card8 EndTime
   , [In]  MEng.Card1 StartByte
   , [In]  MEng.Card1 EndByte
   , [Out] MEng.String ToFill
)   Returns MEng.Boolean;


I am sorry the noob questions here, but how would I handle multiple messages in short succession coming from the device?
As an example of messages coming from the device see below:

Code:
(Haiku;DEVICE;BEEPER;ON)(Haiku;DEVICE;INDICATORS;ON)(Haiku;DEVICE;LIGHT;NOT PRESENT)(Haiku;DEVICE;SERVER;PRODUCTION)(Haiku;ERRORLOG;ENTRIES;NUM;10)(Haiku;ERRORLOG;ENTRIES;MAX;10)(Haiku;FAN;AUTO;OFF)(Haiku;FAN;DIR;FWD)(Haiku;FAN;PWR;ON)(Haiku;FAN;SPD;ACTUAL;2)(Haiku;FAN;SPD;MAX;7)(Haiku;FAN;SPD;MIN;1)(Haiku;FAN;BOOKENDS;1;7)(Haiku;FAN;TIMER;CURR;0)(Haiku;FAN;TIMER;MAX;7)(Haiku;FAN;TIMER;MIN;1)(Haiku;FAN;WHOOSH;STATUS;OFF)(Haiku;FW;NAME;FW000003)(Haiku;FW;FW000003;2.5.0)(Haiku;GROUP;LIST;EMPTY)(Haiku;GROUP;ROOM;TYPE;0)(Haiku;LEARN;MAXSPEED;4)(Haiku;LEARN;MINSPEED;0)(Haiku;LEARN;ZEROTEMP;1664)(Haiku;DEVICE;LIGHT;NOT PRESENT)(Haiku;DEVICE;LIGHT;NOT PRESENT)(Haiku;LIGHT;BOOKENDS;1;16)(Haiku;DEVICE;LIGHT;NOT PRESENT)(Haiku;DEVICE;LIGHT;NOT PRESENT)(Haiku;DEVICE;LIGHT;NOT PRESENT)(Haiku;NAME;VALUE;Haiku)(Haiku;NW;AP;STATUS;OFF)(Haiku;NW;DHCP;OFF)(Haiku;NW;PARAMS;ACTUAL;192.168.0.16;255.255.255.0;192.168.0.1)(Haiku;NW;SSID;south)(Haiku;NW;TOKEN;14515df6-ed24-4963-a465-1b5f983c82fc)(Haiku;SCHEDULE;CAP;MAX EVENTS,29)(Haiku;SCHEDULE;EVENT;LIST;NONE)(Haiku;SLEEP;EVENT;OFF)(Haiku;SLEEP;EVENT;ON)(Haiku;SLEEP;STATE;OFF)(Haiku;SMARTMODE;ACTUAL;HEATING)(Haiku;SMARTMODE;STATE;HEATING)(Haiku;SMARTSLEEP;IDEALTEMP;2166)(Haiku;SMARTSLEEP;MAXSPEED;3)(Haiku;SMARTSLEEP;MINSPEED;1)(Haiku;SNSROCC;TIMEOUT;CURR;60000)(Haiku;SNSROCC;TIMEOUT;MAX;86400000)(Haiku;SNSROCC;TIMEOUT;MIN;60000)(Haiku;TIME;VALUE;2018-11-24T14:43:41Z)(Haiku;WINTERMODE;HEIGHT;365)(Haiku;WINTERMODE;STATE;ON)
Reply
#2
Do the messages actually have a start and stop byte? They look like they more likely to only have a line termination. If so, then GetASCIITermedMsg would be the more appropriate scheme.

Are the above unsolicited or in response to a query? If in response to a query, and you don't know how many there will be, sometimes it's best to just send the query and let your poll method pick them up. as they come in. Your poll method can do a fairly short poll timeout, then do a loop where it loops maybe 8 times, with a very short timeout, maybe 5ms. It will read until either it times out and doesn't get a msg or you hit the 8 msg limit. Then return. Next time you'll grab any more that have shown up.

If you do a query and you kjnow for sure that a particular set of msgs are coming back, then just read until you either hit an end time or you have gotten the last one you expect. The '2' versions of the msg reader method exist just for that. You can pre-calculate an end time, and just keep passing that back into the msg reader as you loop. It will read as long as you haven't hit that end time.
Dean Roddey
Explorans limites defectum
Reply
#3
Oh, I just noticed that those lines probably aren't single msgs, but you really want to pick out the stuff inside the () parens. If so, then you are correct, use the start/stop msg guy. If there are new lines in there somewhere, they should get ignored since they are outside of any parens it looks like.

Otherwise, the other strategy stuff above is still relevant.
Dean Roddey
Explorans limites defectum
Reply
#4
So the messages I added in the first post came indeed in response to a query.
But there are no new lines, it may just look like that in the forum post.
The protocol looks like this:

<command>LR
(msg1)(msg2)(msg3)<query>LR
(msg1)

The number of messages in reply is variable, and some are repeated..., that is where I am lost whether the the poll needs to be fast to get all of those, or how else ()()() messages would appear in GetASCIIStartStopMsg2 routine?
Reply
#5
If you set the start and stop chars to ( and ), then you will just get one of those at a time. You can make the poll fast, just don't stay in there very long. Do a read in a loop, as mentioned, with a very short timeout on the read. That way, you can pick up what is there and process them, and get out fast as soon as you have eaten anything that has arrived.

SO set the the poll timeout to 100ms, and loop maybe 8 to 16 times per round, with a timeout of 5ms on each round. That should let you quickly response to anything that comes in.

Of course you could do the same after a query as well. So you could just have a helper method that takes a count of times to loop and will loop that many times with the very short read timeout and break out when it doesn't see anything. You could call that both from your poll callback and after a query that you know is going to return some variable number of messages
Dean Roddey
Explorans limites defectum
Reply
#6
OK, so got the receiving of messages down and those now come in alright.
Have another theory question here:
 - What is the point of actively polling besides the initial query and setting of field values?

When the driver connects initially would query the status, say fan is on, spinning forward, speed is 3, etc. If there are changes in those parameters, the device would send updates..., processing those is not sufficient? Querying all fields especially like every second seems unnecessary.
Reply
#7
The documentation on the driver development very eloquently explains my questions - thanks for that.
Any basic tutorial on how (properly...) to use the debugger in the CML IDE?
Reply
#8
There isn't such a tutorial, at least not anymore in the 5.x video series. I need to do a driver for that. Maybe I can do that today. I haven't done any CQC videos in a while, so I need to get some more done.
Dean Roddey
Explorans limites defectum
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  JVC D-ILA Driver jokermac 16 123 Yesterday, 07:10 PM
Last Post: Mark Stega
  RunTimer2 driver rbroders 18 6,344 10-17-2019, 04:38 PM
Last Post: rbroders
  Writing Driver - Varying commands based on checksum gReatAutomation 3 405 07-22-2019, 01:08 PM
Last Post: Dean Roddey
  Samsung HLxxA750 DLP Beta Driver jrunde 37 19,949 07-19-2019, 01:24 PM
Last Post: gReatAutomation
  Amazon Echo Hue Simulator Driver wuench 123 53,938 07-08-2019, 09:53 AM
Last Post: Dean Roddey
  New Driver - How hard would this be? kblagron 4 933 05-20-2019, 11:28 AM
Last Post: zaccari
  Cytech Comfort Driver znelbok 6 858 04-10-2019, 05:39 PM
Last Post: znelbok
  OpenHAB Driver whozeawhat 6 2,703 01-16-2019, 06:45 AM
Last Post: greymatter
  LIFX Driver bobskie708 14 4,491 01-10-2019, 06:36 PM
Last Post: Dean Roddey
  XBMC Driver wuench 428 191,212 12-28-2018, 11:07 AM
Last Post: dogman

Forum Jump:


Users browsing this thread: 1 Guest(s)