You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
//
// ZigBeeÖ¸ Áî½âÎö
//
# include "CommandDecoder.h"
byte CommandDecoder : : _CheckSUM ( byte main , byte data1 , byte data2 , byte data3 )
{
return ( ( byte ) ( ( main + data1 + data2 + data3 ) % 256 ) ) ;
}
CommandDecoder : : CommandDecoder ( )
{
}
CommandDecoder : : CommandDecoder ( byte * arr )
{
cmd [ 0 ] = arr [ 0 ] ;
cmd [ 1 ] = arr [ 1 ] ;
cmd [ 2 ] = arr [ 2 ] ;
cmd [ 3 ] = arr [ 3 ] ;
cmd [ 4 ] = arr [ 4 ] ;
cmd [ 5 ] = arr [ 5 ] ;
cmd [ 6 ] = arr [ 6 ] ;
cmd [ 7 ] = arr [ 7 ] ;
}
bool CommandDecoder : : CommandValidate ( )
{
if ( ( cmd [ 0 ] ! = CommandData : : FrameHead ) | | ( cmd [ 7 ] ! = CommandData : : FrameEnd ) )
return false ;
byte checksum = _CheckSUM ( cmd [ 2 ] , cmd [ 3 ] , cmd [ 4 ] , cmd [ 5 ] ) ;
if ( cmd [ 6 ] ! = checksum )
return false ;
return true ;
}
byte CommandDecoder : : GetDevice ( )
{
return cmd [ 1 ] ;
}
byte CommandDecoder : : GetMainCommand ( )
{
return cmd [ 2 ] ;
}
byte CommandDecoder : : GetDataBit ( byte num )
{
if ( ( num < 1 ) | | ( num > 3 ) )
return - 1 ;
return cmd [ 2 + num ] ;
}