Get the parameters from the command line and check the code first:
Static void address_parse (
Bacnet_address * DST,
Int argc,
Char * argv [])
{
Unsigned Mac [6];
Unsigned port;
Int COUNT = 0;
Int Index = 0;
If (argc> 0 ){
Count =
Sscanf (argv [0], "% u. % u. % u. % u: % u ", & Mac [0], & Mac [1], & Mac [2],
& Mac [3], & Port );
If (COUNT = 5 ){
DST-> mac_len = 6;
For (Index = 0; index <4; index ++ ){
DST-> Mac [Index] = Mac [Index];
}
Encode_unsigned16 (& DST-> Mac [4], Port );
} Else {
Count =
Sscanf (argv [0], "% x: % x", & Mac [0], & Mac [1], & Mac [2],
& Mac [3], & Mac [4], & Mac [5]);
DST-> mac_len = count;
For (Index = 0; index <max_mac_len; index ++ ){
If (index <count ){
DST-> Mac [Index] = Mac [Index];
} Else {
DST-> Mac [Index] = 0;
}
}
}
}
DST-> net = 0;
DST-> Len = 0;
For (Index = 0; index <max_mac_len; index ++ ){
DST-> ADR [Index] = 0;
}
} Here, encode_unsigned16 is the number of unsigned codes. If the input address is 19.168.1.100 and the port number is 47808, it is converted to 0xbac0, And the array stores 192.168.1.100: 47808.
Int encode_unsigned16 (
Uint8_t * APDU,
Uint16_t value)
{
APDU [0] = (uint8_t) (Value & 0xff00)> 8 );
APDU [1] = (uint8_t) (Value & 0x00ff );
Return 2;
}