Files
bacnet_stack/bacnet-stack/npdu.c
T
2005-03-13 12:08:27 +00:00

122 lines
3.6 KiB
C

/*####COPYRIGHTBEGIN####
-------------------------------------------
Copyright (C) 2005 Steve Karg
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to:
The Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA.
As a special exception, if other files instantiate templates or
use macros or inline functions from this file, or you compile
this file and link it with other works to produce a work based
on this file, this file does not by itself cause the resulting
work to be covered by the GNU General Public License. However
the source code for this file must still be made available in
accordance with section (3) of the GNU General Public License.
This exception does not invalidate any other reasons why a work
based on this file might be covered by the GNU General Public
License.
-------------------------------------------
####COPYRIGHTEND####*/
#include <stdbool.h>
#include <stdint.h>
#include <assert.h>
#include "bacdef.h"
#include "bacenum.h"
/* max-segments-accepted
B'000' Unspecified number of segments accepted.
B'001' 2 segments accepted.
B'010' 4 segments accepted.
B'011' 8 segments accepted.
B'100' 16 segments accepted.
B'101' 32 segments accepted.
B'110' 64 segments accepted.
B'111' Greater than 64 segments accepted.
*/
/* max-APDU-length-accepted
B'0000' Up to MinimumMessageSize (50 octets)
B'0001' Up to 128 octets
B'0010' Up to 206 octets (fits in a LonTalk frame)
B'0011' Up to 480 octets (fits in an ARCNET frame)
B'0100' Up to 1024 octets
B'0101' Up to 1476 octets (fits in an ISO 8802-3 frame)
B'0110' reserved by ASHRAE
B'0111' reserved by ASHRAE
B'1000' reserved by ASHRAE
B'1001' reserved by ASHRAE
B'1010' reserved by ASHRAE
B'1011' reserved by ASHRAE
B'1100' reserved by ASHRAE
B'1101' reserved by ASHRAE
B'1110' reserved by ASHRAE
B'1111' reserved by ASHRAE
*/
uint8_t npdu_encode_max_seg_max_apdu(int max_segs, int max_apdu)
{
uint8_t octet = 0;
if (max_segs < 2)
octet = 0;
else if (max_segs < 4)
octet = 0x10;
else if (max_segs < 8)
octet = 0x20;
else if (max_segs < 16)
octet = 0x30;
else if (max_segs < 32)
octet = 0x40;
else if (max_segs < 64)
octet = 0x50;
else if (max_segs == 64)
octet = 0x60;
else
octet = 0x70;
// max_apdu must be 50 octets minimum
assert(max_apdu >= 50);
if (max_apdu == 50)
octet |= 0x00;
else if (max_apdu <= 128)
octet |= 0x01;
//fits in a LonTalk frame
else if (max_apdu <= 206)
octet |= 0x02;
//fits in an ARCNET or MS/TP frame
else if (max_apdu <= 480)
octet |= 0x03;
else if (max_apdu <= 1024)
octet |= 0x04;
// fits in an ISO 8802-3 frame
else if (max_apdu <= 1476)
octet |= 0x05;
return octet;
}
int npdu_encode(
uint8_t *buf,
BACNET_ADDRESS *dest,
BACNET_ADDRESS *src,
bool data_expecting_reply,
uint8_t invoke_id)
{
int len = 0;
return len;
}