@@ -683,6 +683,27 @@ SCENARIO("Test the encoding of command messages") {
683
683
}
684
684
}
685
685
686
+
687
+ WHEN (" Encode the DeviceNetConfigCmdUp message with Wifi and buffer without enough space" )
688
+ {
689
+ DeviceNetConfigCmdUp command;
690
+ command.c .id = CommandId::DeviceNetConfigCmdUpId;
691
+
692
+ command.params .type = NetworkAdapter::WIFI;
693
+ String longSsid = " longSSID" ;
694
+ strcpy (command.params .wifi .ssid , longSsid.c_str ());
695
+
696
+ uint8_t buffer[7 ];
697
+ size_t bytes_encoded = sizeof (buffer);
698
+
699
+ CBORMessageEncoder encoder;
700
+ MessageEncoder::Status err = encoder.encode ((Message*)&command, buffer, bytes_encoded);
701
+
702
+ THEN (" The encoding fails" ) {
703
+ REQUIRE (err == MessageEncoder::Status::Error);
704
+ }
705
+ }
706
+
686
707
WHEN (" Encode the DeviceNetConfigCmdUp message with LoraWan" )
687
708
{
688
709
DeviceNetConfigCmdUp command;
@@ -718,6 +739,28 @@ SCENARIO("Test the encoding of command messages") {
718
739
}
719
740
}
720
741
742
+ WHEN (" Encode the DeviceNetConfigCmdUp message with LoRa buffer without enough space" )
743
+ {
744
+ DeviceNetConfigCmdUp command;
745
+ command.c .id = CommandId::DeviceNetConfigCmdUpId;
746
+
747
+ command.params .type = NetworkAdapter::LORA;
748
+
749
+ String app_eui = " APPEUI" ;
750
+ strcpy (command.params .lora .appeui , app_eui.c_str ());
751
+ String app_key = " APPKEY" ;
752
+ strcpy (command.params .lora .appkey , app_key.c_str ());
753
+ uint8_t buffer[7 ];
754
+ size_t bytes_encoded = sizeof (buffer);
755
+
756
+ CBORMessageEncoder encoder;
757
+ MessageEncoder::Status err = encoder.encode ((Message*)&command, buffer, bytes_encoded);
758
+
759
+ THEN (" The encoding fails" ) {
760
+ REQUIRE (err == MessageEncoder::Status::Error);
761
+ }
762
+ }
763
+
721
764
WHEN (" Encode the DeviceNetConfigCmdUp message with GSM" )
722
765
{
723
766
DeviceNetConfigCmdUp command;
@@ -760,18 +803,18 @@ SCENARIO("Test the encoding of command messages") {
760
803
}
761
804
}
762
805
763
- WHEN (" Encode the DeviceNetConfigCmdUp message with NB-IoT " )
806
+ WHEN (" Encode the DeviceNetConfigCmdUp message with GSM " )
764
807
{
765
808
DeviceNetConfigCmdUp command;
766
809
command.c .id = CommandId::DeviceNetConfigCmdUpId;
767
810
768
- command.params .type = NetworkAdapter::NB ;
811
+ command.params .type = NetworkAdapter::GSM ;
769
812
String apn = " apn.arduino.cc" ;
770
- strcpy (command.params .nb .apn , apn.c_str ());
813
+ strcpy (command.params .gsm .apn , apn.c_str ());
771
814
String user = " username" ;
772
- strcpy (command.params .nb .login , user.c_str ());
815
+ strcpy (command.params .gsm .login , user.c_str ());
773
816
String password = " PASSWORD" ;
774
- strcpy (command.params .nb .pass , password.c_str ());
817
+ strcpy (command.params .gsm .pass , password.c_str ());
775
818
uint8_t buffer[512 ];
776
819
size_t bytes_encoded = sizeof (buffer);
777
820
@@ -780,7 +823,7 @@ SCENARIO("Test the encoding of command messages") {
780
823
781
824
uint8_t expected_result[] = {
782
825
0xda , 0x00 , 0x01 , 0x11 , 0x00 , 0x83 ,
783
- 0x04 , 0x6e , 0x61 , 0x70 , 0x6e , 0x2e , 0x61 , 0x72 ,
826
+ 0x03 , 0x6e , 0x61 , 0x70 , 0x6e , 0x2e , 0x61 , 0x72 ,
784
827
0x64 , 0x75 , 0x69 , 0x6e , 0x6f , 0x2e , 0x63 , 0x63 ,
785
828
0x68 , 0x75 , 0x73 , 0x65 , 0x72 , 0x6e , 0x61 , 0x6d ,
786
829
0x65
@@ -789,7 +832,7 @@ SCENARIO("Test the encoding of command messages") {
789
832
// Test the encoding is
790
833
// DA 00011100 # tag(73728)
791
834
// 83 # array(3)
792
- // 04 # unsigned(4 )
835
+ // 03 # unsigned(3 )
793
836
// 6E # text(14)
794
837
// 61706E2E61726475696E6F2E6363 # "apn.arduino.cc"
795
838
// 68 # text(8)
@@ -802,6 +845,29 @@ SCENARIO("Test the encoding of command messages") {
802
845
}
803
846
}
804
847
848
+ WHEN (" Encode the DeviceNetConfigCmdUp message with NB-IoT buffer without enough space" )
849
+ {
850
+ DeviceNetConfigCmdUp command;
851
+ command.c .id = CommandId::DeviceNetConfigCmdUpId;
852
+
853
+ command.params .type = NetworkAdapter::NB;
854
+ String apn = " apn.arduino.cc" ;
855
+ strcpy (command.params .nb .apn , apn.c_str ());
856
+ String user = " username" ;
857
+ strcpy (command.params .nb .login , user.c_str ());
858
+ String password = " PASSWORD" ;
859
+ strcpy (command.params .nb .pass , password.c_str ());
860
+ uint8_t buffer[12 ];
861
+ size_t bytes_encoded = sizeof (buffer);
862
+
863
+ CBORMessageEncoder encoder;
864
+ MessageEncoder::Status err = encoder.encode ((Message*)&command, buffer, bytes_encoded);
865
+
866
+ THEN (" The encoding fails" ) {
867
+ REQUIRE (err == MessageEncoder::Status::Error);
868
+ }
869
+ }
870
+
805
871
WHEN (" Encode the DeviceNetConfigCmdUp message with CAT-M1" )
806
872
{
807
873
DeviceNetConfigCmdUp command;
@@ -844,6 +910,29 @@ SCENARIO("Test the encoding of command messages") {
844
910
}
845
911
}
846
912
913
+ WHEN (" Encode the DeviceNetConfigCmdUp message with CAT-M1 buffer without enough space" )
914
+ {
915
+ DeviceNetConfigCmdUp command;
916
+ command.c .id = CommandId::DeviceNetConfigCmdUpId;
917
+
918
+ command.params .type = NetworkAdapter::CATM1;
919
+ String apn = " apn.arduino.cc" ;
920
+ strcpy (command.params .nb .apn , apn.c_str ());
921
+ String user = " username" ;
922
+ strcpy (command.params .nb .login , user.c_str ());
923
+ String password = " PASSWORD" ;
924
+ strcpy (command.params .nb .pass , password.c_str ());
925
+ uint8_t buffer[12 ];
926
+ size_t bytes_encoded = sizeof (buffer);
927
+
928
+ CBORMessageEncoder encoder;
929
+ MessageEncoder::Status err = encoder.encode ((Message*)&command, buffer, bytes_encoded);
930
+
931
+ THEN (" The encoding fails" ) {
932
+ REQUIRE (err == MessageEncoder::Status::Error);
933
+ }
934
+ }
935
+
847
936
WHEN (" Encode the DeviceNetConfigCmdUp message with Ethernet" )
848
937
{
849
938
DeviceNetConfigCmdUp command;
@@ -896,6 +985,65 @@ SCENARIO("Test the encoding of command messages") {
896
985
}
897
986
}
898
987
988
+ WHEN (" Encode the DeviceNetConfigCmdUp message with Ethernet IPv6" )
989
+ {
990
+ DeviceNetConfigCmdUp command;
991
+ command.c .id = CommandId::DeviceNetConfigCmdUpId;
992
+
993
+ command.params .type = NetworkAdapter::ETHERNET;
994
+ uint8_t ip[] = {0x1a , 0x4f , 0xa7 , 0xa9 , 0x92 , 0x8f , 0x7b , 0x1c , 0xec , 0x3b , 0x1e , 0xcd , 0x88 , 0x58 , 0x0d , 0x1e };
995
+ command.params .eth .ip .type = IPType::IPv6;
996
+ memcpy (command.params .eth .ip .bytes , ip, sizeof (ip));
997
+ uint8_t dns[] = {0x21 , 0xf6 , 0x3b , 0x22 , 0x99 , 0x6f , 0x5b , 0x72 , 0x25 , 0xd9 , 0xe0 , 0x24 , 0xf0 , 0x36 , 0xb5 , 0xd2 };
998
+ command.params .eth .dns .type = IPType::IPv6;
999
+ memcpy (command.params .eth .dns .bytes , dns, sizeof (dns));
1000
+ uint8_t gateway[] = {0x2e , 0xc2 , 0x27 , 0xf1 , 0xf1 , 0x9a , 0x0c , 0x11 , 0x47 , 0x1b , 0x84 , 0xaf , 0x96 , 0x10 , 0xb0 , 0x17 };
1001
+ command.params .eth .gateway .type = IPType::IPv6;
1002
+ memcpy (command.params .eth .gateway .bytes , gateway, sizeof (gateway));
1003
+ uint8_t netmask[] = {0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 };
1004
+ command.params .eth .netmask .type = IPType::IPv6;
1005
+ memcpy (command.params .eth .netmask .bytes , netmask, sizeof (netmask));
1006
+
1007
+
1008
+ uint8_t buffer[512 ];
1009
+ size_t bytes_encoded = sizeof (buffer);
1010
+
1011
+ CBORMessageEncoder encoder;
1012
+ MessageEncoder::Status err = encoder.encode ((Message*)&command, buffer, bytes_encoded);
1013
+
1014
+ uint8_t expected_result[] = {
1015
+ 0xda , 0x00 , 0x01 , 0x11 , 0x00 , 0x85 ,
1016
+ 0x06 ,0x50 , 0x1A , 0x4F , 0xA7 , 0xA9 , 0x92 , 0x8F , 0x7B , 0x1C ,
1017
+ 0xEC , 0x3B , 0x1E , 0xCD , 0x88 , 0x58 , 0x0D , 0x1E ,
1018
+ 0x50 , 0x21 , 0xF6 , 0x3B , 0x22 , 0x99 , 0x6F ,
1019
+ 0x5B , 0x72 , 0x25 , 0xD9 , 0xE0 , 0x24 , 0xF0 , 0x36 ,
1020
+ 0xB5 , 0xD2 , 0x50 , 0x2E , 0xC2 , 0x27 , 0xF1 ,
1021
+ 0xF1 , 0x9A , 0x0C , 0x11 , 0x47 , 0x1B , 0x84 , 0xAF ,
1022
+ 0x96 , 0x10 , 0xB0 , 0x17 , 0x50 , 0xFF , 0xFF ,
1023
+ 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0x00 , 0x00 ,
1024
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00
1025
+ };
1026
+
1027
+ // Test the encoding is
1028
+ // DA 00011100 # tag(73728)
1029
+ // 85 # array(5)
1030
+ // 06 # unsigned(6)
1031
+ // 50 # bytes(16)
1032
+ // 1A4FA7A9928F7B1CEC3B1ECD88580D1E # "\u001AO\xA7\xA9\x92\x8F{\u001C\xEC;\u001E͈X\r\u001E"
1033
+ // 50 # bytes(16)
1034
+ // 21F63B22996F5B7225D9E024F036B5D2 # "!\xF6;\"\x99o[r%\xD9\xE0$\xF06\xB5\xD2"
1035
+ // 50 # bytes(16)
1036
+ // 2EC227F1F19A0C11471B84AF9610B017 # ".\xC2'\xF1\xF1\x9A\f\u0011G\e\x84\xAF\x96\u0010\xB0\u0017"
1037
+ // 50 # bytes(16)
1038
+ // FFFFFFFFFFFFFFFF0000000000000000 # "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000"
1039
+
1040
+ THEN (" The encoding is successful" ) {
1041
+ REQUIRE (err == MessageEncoder::Status::Complete);
1042
+ REQUIRE (bytes_encoded == sizeof (expected_result));
1043
+ REQUIRE (memcmp (buffer, expected_result, sizeof (expected_result)) == 0 );
1044
+ }
1045
+ }
1046
+
899
1047
WHEN (" Encode the DeviceNetConfigCmdUp message with Ethernet DHCP" )
900
1048
{
901
1049
DeviceNetConfigCmdUp command;
@@ -938,6 +1086,68 @@ SCENARIO("Test the encoding of command messages") {
938
1086
}
939
1087
}
940
1088
1089
+ WHEN (" Encode the DeviceNetConfigCmdUp message with Ethernet IPv6 not enough space" )
1090
+ {
1091
+ DeviceNetConfigCmdUp command;
1092
+ command.c .id = CommandId::DeviceNetConfigCmdUpId;
1093
+
1094
+ command.params .type = NetworkAdapter::ETHERNET;
1095
+ uint8_t ip[] = {0x1a , 0x4f , 0xa7 , 0xa9 , 0x92 , 0x8f , 0x7b , 0x1c , 0xec , 0x3b , 0x1e , 0xcd , 0x88 , 0x58 , 0x0d , 0x1e };
1096
+ command.params .eth .ip .type = IPType::IPv6;
1097
+ memcpy (command.params .eth .ip .bytes , ip, sizeof (ip));
1098
+ uint8_t dns[] = {0x21 , 0xf6 , 0x3b , 0x22 , 0x99 , 0x6f , 0x5b , 0x72 , 0x25 , 0xd9 , 0xe0 , 0x24 , 0xf0 , 0x36 , 0xb5 , 0xd2 };
1099
+ command.params .eth .dns .type = IPType::IPv6;
1100
+ memcpy (command.params .eth .dns .bytes , dns, sizeof (dns));
1101
+ uint8_t gateway[] = {0x2e , 0xc2 , 0x27 , 0xf1 , 0xf1 , 0x9a , 0x0c , 0x11 , 0x47 , 0x1b , 0x84 , 0xaf , 0x96 , 0x10 , 0xb0 , 0x17 };
1102
+ command.params .eth .gateway .type = IPType::IPv6;
1103
+ memcpy (command.params .eth .gateway .bytes , gateway, sizeof (gateway));
1104
+ uint8_t netmask[] = {0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 };
1105
+ command.params .eth .netmask .type = IPType::IPv6;
1106
+ memcpy (command.params .eth .netmask .bytes , netmask, sizeof (netmask));
1107
+
1108
+
1109
+ uint8_t buffer[35 ];
1110
+ size_t bytes_encoded = sizeof (buffer);
1111
+
1112
+ CBORMessageEncoder encoder;
1113
+ MessageEncoder::Status err = encoder.encode ((Message*)&command, buffer, bytes_encoded);
1114
+
1115
+ THEN (" The encoding fails" ) {
1116
+ REQUIRE (err == MessageEncoder::Status::Error);
1117
+ }
1118
+ }
1119
+
1120
+ WHEN (" Encode the DeviceNetConfigCmdUp message with Ethernet IPv6 not enough space for any" )
1121
+ {
1122
+ DeviceNetConfigCmdUp command;
1123
+ command.c .id = CommandId::DeviceNetConfigCmdUpId;
1124
+
1125
+ command.params .type = NetworkAdapter::ETHERNET;
1126
+ uint8_t ip[] = {0x1a , 0x4f , 0xa7 , 0xa9 , 0x92 , 0x8f , 0x7b , 0x1c , 0xec , 0x3b , 0x1e , 0xcd , 0x88 , 0x58 , 0x0d , 0x1e };
1127
+ command.params .eth .ip .type = IPType::IPv6;
1128
+ memcpy (command.params .eth .ip .bytes , ip, sizeof (ip));
1129
+ uint8_t dns[] = {0x21 , 0xf6 , 0x3b , 0x22 , 0x99 , 0x6f , 0x5b , 0x72 , 0x25 , 0xd9 , 0xe0 , 0x24 , 0xf0 , 0x36 , 0xb5 , 0xd2 };
1130
+ command.params .eth .dns .type = IPType::IPv6;
1131
+ memcpy (command.params .eth .dns .bytes , dns, sizeof (dns));
1132
+ uint8_t gateway[] = {0x2e , 0xc2 , 0x27 , 0xf1 , 0xf1 , 0x9a , 0x0c , 0x11 , 0x47 , 0x1b , 0x84 , 0xaf , 0x96 , 0x10 , 0xb0 , 0x17 };
1133
+ command.params .eth .gateway .type = IPType::IPv6;
1134
+ memcpy (command.params .eth .gateway .bytes , gateway, sizeof (gateway));
1135
+ uint8_t netmask[] = {0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 };
1136
+ command.params .eth .netmask .type = IPType::IPv6;
1137
+ memcpy (command.params .eth .netmask .bytes , netmask, sizeof (netmask));
1138
+
1139
+
1140
+ uint8_t buffer[12 ];
1141
+ size_t bytes_encoded = sizeof (buffer);
1142
+
1143
+ CBORMessageEncoder encoder;
1144
+ MessageEncoder::Status err = encoder.encode ((Message*)&command, buffer, bytes_encoded);
1145
+
1146
+ THEN (" The encoding fails" ) {
1147
+ REQUIRE (err == MessageEncoder::Status::Error);
1148
+ }
1149
+ }
1150
+
941
1151
WHEN (" Encode the DeviceNetConfigCmdUp message with Cellular" )
942
1152
{
943
1153
DeviceNetConfigCmdUp command;
@@ -979,4 +1189,81 @@ SCENARIO("Test the encoding of command messages") {
979
1189
REQUIRE (memcmp (buffer, expected_result, sizeof (expected_result)) == 0 );
980
1190
}
981
1191
}
1192
+
1193
+ WHEN (" Encode the DeviceNetConfigCmdUp message with Notecard" )
1194
+ {
1195
+ DeviceNetConfigCmdUp command;
1196
+ command.c .id = CommandId::DeviceNetConfigCmdUpId;
1197
+
1198
+ command.params .type = NetworkAdapter::NOTECARD;
1199
+
1200
+ uint8_t buffer[512 ];
1201
+ size_t bytes_encoded = sizeof (buffer);
1202
+
1203
+ CBORMessageEncoder encoder;
1204
+ MessageEncoder::Status err = encoder.encode ((Message*)&command, buffer, bytes_encoded);
1205
+
1206
+ uint8_t expected_result[] = {
1207
+ 0xda , 0x00 , 0x01 , 0x11 , 0x00 , 0x81 ,
1208
+ 0x08
1209
+ };
1210
+
1211
+ // Test the encoding is
1212
+ // DA 00011100 # tag(73728)
1213
+ // 81 # array(1)
1214
+ // 08 # unsigned(8)
1215
+
1216
+ THEN (" The encoding is successful" ) {
1217
+ REQUIRE (err == MessageEncoder::Status::Complete);
1218
+ REQUIRE (bytes_encoded == sizeof (expected_result));
1219
+ REQUIRE (memcmp (buffer, expected_result, sizeof (expected_result)) == 0 );
1220
+ }
1221
+ }
1222
+
1223
+ WHEN (" Encode the DeviceNetConfigCmdUp message with None" )
1224
+ {
1225
+ DeviceNetConfigCmdUp command;
1226
+ command.c .id = CommandId::DeviceNetConfigCmdUpId;
1227
+
1228
+ command.params .type = NetworkAdapter::NONE;
1229
+
1230
+ uint8_t buffer[512 ];
1231
+ size_t bytes_encoded = sizeof (buffer);
1232
+
1233
+ CBORMessageEncoder encoder;
1234
+ MessageEncoder::Status err = encoder.encode ((Message*)&command, buffer, bytes_encoded);
1235
+
1236
+ uint8_t expected_result[] = {
1237
+ 0xda , 0x00 , 0x01 , 0x11 , 0x00 , 0x81 , 0x00
1238
+ };
1239
+
1240
+ // Test the encoding is
1241
+ // DA 00011100 # tag(73728)
1242
+ // 80 # array(1)
1243
+
1244
+ THEN (" The encoding is successful" ) {
1245
+ REQUIRE (err == MessageEncoder::Status::Complete);
1246
+ REQUIRE (bytes_encoded == sizeof (expected_result));
1247
+ REQUIRE (memcmp (buffer, expected_result, sizeof (expected_result)) == 0 );
1248
+ }
1249
+ }
1250
+
1251
+ WHEN (" Encode the DeviceNetConfigCmdUp message buffer without enough space" )
1252
+ {
1253
+ DeviceNetConfigCmdUp command;
1254
+ command.c .id = CommandId::DeviceNetConfigCmdUpId;
1255
+
1256
+ command.params .type = NetworkAdapter::ETHERNET;
1257
+
1258
+
1259
+ uint8_t buffer[6 ];
1260
+ size_t bytes_encoded = sizeof (buffer);
1261
+
1262
+ CBORMessageEncoder encoder;
1263
+ MessageEncoder::Status err = encoder.encode ((Message*)&command, buffer, bytes_encoded);
1264
+
1265
+ THEN (" The encoding fails" ) {
1266
+ REQUIRE (err == MessageEncoder::Status::Error);
1267
+ }
1268
+ }
982
1269
}
0 commit comments