Just started programming in c# to receive events from push buttons.
I tried to understand the bits with the protocol explanation. I got the most important, but some help will always be welcome.
Receive:
I pressed on button 3 on kit VMB8PB
This is what I received : :15:248:1:4:0:4:0:0:240:4:
15 : ?
248 : ?
1 : Address
4: ?
0 : ?
4 : ButtonPress ( 4 = button 3)
0 : BottonRelease (will be 4 if released)
0 : BottonLongPress (will be 4 if longpress)
240: ?
4:?
Send
I tried to get the name of the button (addres 01). ‘Push button name request’
Tried with the packet creator , but no idea what i’ve got to send
11 01 00 ?? EF 00 00 01 00
RTR?
Is it the same packet I have got to send via TCP/IP ?
You received COMMAND_PUSH_BUTTON_STATUS - Page 3 of the protocol for the VMBxPB.
The bytes indicate the following:
0x0F: Start of packet (STX)
0xF8: High priority + Rtr Off
0x01: Address
0x04: 4 Data bytes
0x00: Data byte [1] = COMMAND_PUSH_BUTTON_STATUS
0x04: Data byte [2] = Bitmask for Button Pressed (btn 3 is pressed 00000100)
0x00: Data byte [3] = Bitmask for Button Released (none)
0x00: Data byte [4] = Bitmask for Button LongPressed (none)
0xF0: Checksum (2’s complement starting from STX to data byte [3])
0x04: End of packet (ETX)
Example for COMMAND_PUSH_BUTTON_NAME_REQUEST - Page 6 of the protocol for the VMBxPB:
0x0F: Start of packet (STX)
0xFB: Low priority + Rtr Off
0x01: Address
0x02: 2 Data bytes
0xEF: Data byte [1] = COMMAND_PUSH_BUTTON_NAME_REQUEST
0x01: Data byte [2] = Request name for pushbutton 1 (00000001)
0x03: Checksum (2’s complement starting from STX to data byte [2])
0x04: End of packet (ETX)
hi , after searching a lot on the web, I almost get the protocol send packets working. The only one I don’t know: how to generate " 0xFB: Low priority + Rtr Off "
Pdf says : SID10 & SID9 : Priority (00:hightes… 11 : lowest priority)
is this ‘11’ binary or Hex? and do i just need to add 0x01 when RTR is true?
-> priority_rtr (in code)
can someone help me?
thxx
Manu
[code]public class VelbusProtocol
{
public static byte GetCheckSum(List _bytes)
{
int checksum = _bytes[0];
for (int i = 1; i < _bytes.Count - 1; i++)
{
checksum += _bytes*;
}
checksum &= 0xff;
checksum ^= 0xff;
byte checksumb = byte.Parse(checksum.ToString());
return checksumb;
}
public static byte] GeneratePackage(byte address, byte] parameters, byte priority, bool rtr)
{
// how to calulate this one?
byte priority_rtr = 0xFB;
List<byte> _datas = new List<byte>();
_datas.Add(0x0F); // SOF
_datas.Add(priority_rtr); // add priority
_datas.Add(address); // address
_datas.Add(byte.Parse(parameters.Length.ToString())); // add params count
for (int i = 0; i < parameters.Length; i++) { _datas.Add(parameters*); }; // add params
_datas.Add(GetCheckSum(_datas)); // add Checksum
_datas.Add(0x04); // EOF
return _datas.ToArray();
}
public static string test()
{
// Set led 1 on of kit VMB8PB on address 01
byte] package = VelbusProtocol.GeneratePackage(0x01, new byte] { 0xF6, 0x01 }, 0x00, false);
string temp = "";
for (int i = 0; i < package.Length; i++)
{
temp += package*.ToString("X2") + " ";
}
return temp;
//returns "0F FB 01 02 F6 01 FC 04 "
}[/code]***
My mistake, the rtr flag is in the data size byte, not in the priority byte.
Recap:
is always FB or F8
if you want on then add 0x40 to the
Without rtr on:
0x0F: Start of packet (STX)
0xF8: High priority
0x01: Address
0x04: 4 Data bytes and rtr off
…
With rtr on:
0x0F: Start of packet (STX)
0xF8: High priority
0x01: Address
0x44: 4 Data bytes and rtr on
…
Sample code for Delphi
procedure TPacket.SetPriority(const Value: TPriority);
begin
if Value = vpLow then
FPackedData[1] := $FB
else
FPackedData[1] := $F8;
end;
function TPacket.GetRtr: Boolean;
begin
Result := ((FPackedData[3] and $40) = $40);
end;
procedure TPacket.SetRtr(const Value: Boolean);
begin
if Value then
FPackedData[3] := FPackedData[3] or $40 { set flag }
else
FPackedData[3] := FPackedData[3] and $0F; { clear flag }
end;
So basically the low order-nibble is the number of data bytes. And the high-order nibble contains a flag for rtr.