@@ -896,6 +896,65 @@ SCENARIO("Test the encoding of command messages") {
896
896
}
897
897
}
898
898
899
+ WHEN (" Encode the DeviceNetConfigCmdUp message with Ethernet IPv6" )
900
+ {
901
+ DeviceNetConfigCmdUp command;
902
+ command.c .id = CommandId::DeviceNetConfigCmdUpId;
903
+
904
+ command.params .type = NetworkAdapter::ETHERNET;
905
+ uint8_t ip[] = {0x1a , 0x4f , 0xa7 , 0xa9 , 0x92 , 0x8f , 0x7b , 0x1c , 0xec , 0x3b , 0x1e , 0xcd , 0x88 , 0x58 , 0x0d , 0x1e };
906
+ command.params .eth .ip .type = IPType::IPv6;
907
+ memcpy (command.params .eth .ip .bytes , ip, sizeof (ip));
908
+ uint8_t dns[] = {0x21 , 0xf6 , 0x3b , 0x22 , 0x99 , 0x6f , 0x5b , 0x72 , 0x25 , 0xd9 , 0xe0 , 0x24 , 0xf0 , 0x36 , 0xb5 , 0xd2 };
909
+ command.params .eth .dns .type = IPType::IPv6;
910
+ memcpy (command.params .eth .dns .bytes , dns, sizeof (dns));
911
+ uint8_t gateway[] = {0x2e , 0xc2 , 0x27 , 0xf1 , 0xf1 , 0x9a , 0x0c , 0x11 , 0x47 , 0x1b , 0x84 , 0xaf , 0x96 , 0x10 , 0xb0 , 0x17 };
912
+ command.params .eth .gateway .type = IPType::IPv6;
913
+ memcpy (command.params .eth .gateway .bytes , gateway, sizeof (gateway));
914
+ uint8_t netmask[] = {0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 };
915
+ command.params .eth .netmask .type = IPType::IPv6;
916
+ memcpy (command.params .eth .netmask .bytes , netmask, sizeof (netmask));
917
+
918
+
919
+ uint8_t buffer[512 ];
920
+ size_t bytes_encoded = sizeof (buffer);
921
+
922
+ CBORMessageEncoder encoder;
923
+ MessageEncoder::Status err = encoder.encode ((Message*)&command, buffer, bytes_encoded);
924
+
925
+ uint8_t expected_result[] = {
926
+ 0xda , 0x00 , 0x01 , 0x11 , 0x00 , 0x85 ,
927
+ 0x06 ,0x50 , 0x1A , 0x4F , 0xA7 , 0xA9 , 0x92 , 0x8F , 0x7B , 0x1C ,
928
+ 0xEC , 0x3B , 0x1E , 0xCD , 0x88 , 0x58 , 0x0D , 0x1E ,
929
+ 0x50 , 0x21 , 0xF6 , 0x3B , 0x22 , 0x99 , 0x6F ,
930
+ 0x5B , 0x72 , 0x25 , 0xD9 , 0xE0 , 0x24 , 0xF0 , 0x36 ,
931
+ 0xB5 , 0xD2 , 0x50 , 0x2E , 0xC2 , 0x27 , 0xF1 ,
932
+ 0xF1 , 0x9A , 0x0C , 0x11 , 0x47 , 0x1B , 0x84 , 0xAF ,
933
+ 0x96 , 0x10 , 0xB0 , 0x17 , 0x50 , 0xFF , 0xFF ,
934
+ 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0x00 , 0x00 ,
935
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00
936
+ };
937
+
938
+ // Test the encoding is
939
+ // DA 00011100 # tag(73728)
940
+ // 85 # array(5)
941
+ // 06 # unsigned(6)
942
+ // 50 # bytes(16)
943
+ // 1A4FA7A9928F7B1CEC3B1ECD88580D1E # "\u001AO\xA7\xA9\x92\x8F{\u001C\xEC;\u001E͈X\r\u001E"
944
+ // 50 # bytes(16)
945
+ // 21F63B22996F5B7225D9E024F036B5D2 # "!\xF6;\"\x99o[r%\xD9\xE0$\xF06\xB5\xD2"
946
+ // 50 # bytes(16)
947
+ // 2EC227F1F19A0C11471B84AF9610B017 # ".\xC2'\xF1\xF1\x9A\f\u0011G\e\x84\xAF\x96\u0010\xB0\u0017"
948
+ // 50 # bytes(16)
949
+ // FFFFFFFFFFFFFFFF0000000000000000 # "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000"
950
+
951
+ THEN (" The encoding is successful" ) {
952
+ REQUIRE (err == MessageEncoder::Status::Complete);
953
+ REQUIRE (bytes_encoded == sizeof (expected_result));
954
+ REQUIRE (memcmp (buffer, expected_result, sizeof (expected_result)) == 0 );
955
+ }
956
+ }
957
+
899
958
WHEN (" Encode the DeviceNetConfigCmdUp message with Ethernet DHCP" )
900
959
{
901
960
DeviceNetConfigCmdUp command;
@@ -938,6 +997,37 @@ SCENARIO("Test the encoding of command messages") {
938
997
}
939
998
}
940
999
1000
+ WHEN (" Encode the DeviceNetConfigCmdUp message with Ethernet IPv6 not enough space" )
1001
+ {
1002
+ DeviceNetConfigCmdUp command;
1003
+ command.c .id = CommandId::DeviceNetConfigCmdUpId;
1004
+
1005
+ command.params .type = NetworkAdapter::ETHERNET;
1006
+ uint8_t ip[] = {0x1a , 0x4f , 0xa7 , 0xa9 , 0x92 , 0x8f , 0x7b , 0x1c , 0xec , 0x3b , 0x1e , 0xcd , 0x88 , 0x58 , 0x0d , 0x1e };
1007
+ command.params .eth .ip .type = IPType::IPv6;
1008
+ memcpy (command.params .eth .ip .bytes , ip, sizeof (ip));
1009
+ uint8_t dns[] = {0x21 , 0xf6 , 0x3b , 0x22 , 0x99 , 0x6f , 0x5b , 0x72 , 0x25 , 0xd9 , 0xe0 , 0x24 , 0xf0 , 0x36 , 0xb5 , 0xd2 };
1010
+ command.params .eth .dns .type = IPType::IPv6;
1011
+ memcpy (command.params .eth .dns .bytes , dns, sizeof (dns));
1012
+ uint8_t gateway[] = {0x2e , 0xc2 , 0x27 , 0xf1 , 0xf1 , 0x9a , 0x0c , 0x11 , 0x47 , 0x1b , 0x84 , 0xaf , 0x96 , 0x10 , 0xb0 , 0x17 };
1013
+ command.params .eth .gateway .type = IPType::IPv6;
1014
+ memcpy (command.params .eth .gateway .bytes , gateway, sizeof (gateway));
1015
+ uint8_t netmask[] = {0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 };
1016
+ command.params .eth .netmask .type = IPType::IPv6;
1017
+ memcpy (command.params .eth .netmask .bytes , netmask, sizeof (netmask));
1018
+
1019
+
1020
+ uint8_t buffer[35 ];
1021
+ size_t bytes_encoded = sizeof (buffer);
1022
+
1023
+ CBORMessageEncoder encoder;
1024
+ MessageEncoder::Status err = encoder.encode ((Message*)&command, buffer, bytes_encoded);
1025
+
1026
+ THEN (" The encoding fails" ) {
1027
+ REQUIRE (err == MessageEncoder::Status::Error);
1028
+ }
1029
+ }
1030
+
941
1031
WHEN (" Encode the DeviceNetConfigCmdUp message with Cellular" )
942
1032
{
943
1033
DeviceNetConfigCmdUp command;
@@ -979,4 +1069,62 @@ SCENARIO("Test the encoding of command messages") {
979
1069
REQUIRE (memcmp (buffer, expected_result, sizeof (expected_result)) == 0 );
980
1070
}
981
1071
}
1072
+
1073
+ WHEN (" Encode the DeviceNetConfigCmdUp message with Notecard" )
1074
+ {
1075
+ DeviceNetConfigCmdUp command;
1076
+ command.c .id = CommandId::DeviceNetConfigCmdUpId;
1077
+
1078
+ command.params .type = NetworkAdapter::NOTECARD;
1079
+
1080
+ uint8_t buffer[512 ];
1081
+ size_t bytes_encoded = sizeof (buffer);
1082
+
1083
+ CBORMessageEncoder encoder;
1084
+ MessageEncoder::Status err = encoder.encode ((Message*)&command, buffer, bytes_encoded);
1085
+
1086
+ uint8_t expected_result[] = {
1087
+ 0xda , 0x00 , 0x01 , 0x11 , 0x00 , 0x81 ,
1088
+ 0x08
1089
+ };
1090
+
1091
+ // Test the encoding is
1092
+ // DA 00011100 # tag(73728)
1093
+ // 81 # array(1)
1094
+ // 08 # unsigned(8)
1095
+
1096
+ THEN (" The encoding is successful" ) {
1097
+ REQUIRE (err == MessageEncoder::Status::Complete);
1098
+ REQUIRE (bytes_encoded == sizeof (expected_result));
1099
+ REQUIRE (memcmp (buffer, expected_result, sizeof (expected_result)) == 0 );
1100
+ }
1101
+ }
1102
+
1103
+ WHEN (" Encode the DeviceNetConfigCmdUp message with None" )
1104
+ {
1105
+ DeviceNetConfigCmdUp command;
1106
+ command.c .id = CommandId::DeviceNetConfigCmdUpId;
1107
+
1108
+ command.params .type = NetworkAdapter::NONE;
1109
+
1110
+ uint8_t buffer[512 ];
1111
+ size_t bytes_encoded = sizeof (buffer);
1112
+
1113
+ CBORMessageEncoder encoder;
1114
+ MessageEncoder::Status err = encoder.encode ((Message*)&command, buffer, bytes_encoded);
1115
+
1116
+ uint8_t expected_result[] = {
1117
+ 0xda , 0x00 , 0x01 , 0x11 , 0x00 , 0x81 , 0x00
1118
+ };
1119
+
1120
+ // Test the encoding is
1121
+ // DA 00011100 # tag(73728)
1122
+ // 80 # array(1)
1123
+
1124
+ THEN (" The encoding is successful" ) {
1125
+ REQUIRE (err == MessageEncoder::Status::Complete);
1126
+ REQUIRE (bytes_encoded == sizeof (expected_result));
1127
+ REQUIRE (memcmp (buffer, expected_result, sizeof (expected_result)) == 0 );
1128
+ }
1129
+ }
982
1130
}
0 commit comments