11#include <string.h>
2+ #include <time.h>
23
34#include "unity.h"
45
@@ -16,7 +17,7 @@ static DacState dacState = INITIAL;
1617static const uint8_t dacServiceAddress [] = {0xef , 0xef , 0x1f };
1718static const uint8_t dacClientAddress [] = {0xef , 0xee , 0x1f };
1819static const uint8_t configuredNodeAddress [] = {0x00 , 0x01 , 0x17 };
19- static const uint8_t gatewayUplinkAddress [] = {0x00 , 0xef , 0x17 };
20+ static const uint8_t gatewayUplinkAddress [] = {0x00 , 0x00 , 0x17 };
2021static uint8_t nodeAddress [] = {0x00 , 0x00 , 0x00 };
2122
2223static bool flashProcessed = false;
@@ -33,7 +34,7 @@ bool initializeRadioImpl(RadioAddress address) {
3334 return true;
3435}
3536
36- char * generateThingIdImpl () {
37+ char * loadThingIdImpl () {
3738 return "SL-LE01-C980AFE9" ;
3839}
3940
@@ -92,12 +93,13 @@ void sendToGatewayMock1(uint8_t address[], uint8_t data[], int dataSize) {
9293 if (dacState == INITIAL ) {
9394 TEST_ASSERT_EQUAL_UINT8_ARRAY (dacServiceAddress , address , 3 );
9495
95- TEST_ASSERT_EQUAL_INT (29 , dataSize );
96- uint8_t expectedIntroductionData [] = {
96+ TEST_ASSERT_EQUAL_INT (43 , dataSize );
97+ uint8_t expectedIntroductionData [] = {
9798 0xff ,
98- 0xf8 , 0x03 , 0x00 , 0x01 , 0x80 ,
99- 0x01 , 0xfb , 0xef , 0xee , 0x1f , 0xfe ,
100- 0x53 , 0x4c , 0x2d , 0x4c , 0x45 , 0x30 , 0x31 , 0x2d , 0x43 , 0x39 , 0x38 , 0x30 , 0x41 , 0x46 , 0x45 , 0x39 ,
99+ 0xf8 , 0x03 , 0x00 , 0x02 , 0x80 ,
100+ 0x01 , 0x53 , 0x4c , 0x2d , 0x4c , 0x45 , 0x30 , 0x31 , 0x2d , 0x43 , 0x39 , 0x38 , 0x30 , 0x41 , 0x46 , 0x45 , 0x39 , 0xfe ,
101+ 0x02 , 0xfb , 0xef , 0xee , 0x1f , 0xfe ,
102+ 0x61 , 0x62 , 0x63 , 0x64 , 0x65 , 0x66 , 0x67 , 0x68 , 0x69 , 0x6a , 0x6b , 0x6c ,
101103 0xff
102104 };
103105 TEST_ASSERT_EQUAL_UINT8_ARRAY (expectedIntroductionData , data , dataSize );
@@ -113,18 +115,25 @@ void sendToGatewayMock1(uint8_t address[], uint8_t data[], int dataSize) {
113115 TEST_ASSERT_EQUAL_UINT8 (0x03 , actualAddress [0 ]);
114116 TEST_ASSERT_EQUAL_UINT8_ARRAY (dacClientAddress , actualAddress + 1 , 3 );
115117
116- char * text = getText (& introduction );
117- TEST_ASSERT_EQUAL_CHAR_ARRAY (thingId , text , strlen (thingId ));
118+ char * thingIdFromIntroduction = getStringAttributeValue (& introduction , 0x01 );
119+ if (!thingIdFromIntroduction )
120+ TEST_FAIL_MESSAGE ("Failed to get thing ID from introduction." );
121+ TEST_ASSERT_EQUAL_CHAR_ARRAY (thingId , thingIdFromIntroduction , strlen (thingId ));
122+
123+ char * registrationCode = getText (& introduction );
124+ if (!registrationCode )
125+ TEST_FAIL_MESSAGE ("Failed to get registration code from introduction." );
126+ TEST_ASSERT_EQUAL_CHAR_ARRAY ("abcdefghijkl" , registrationCode , 12 );
118127
119128 Protocol allocation = createProtocol (NAME_TUXP_PROTOCOL_ALLOCATION );
120129
121- uint8_t gatewayUplinkAddress [] = {0x00 , 0xef , 0x17 };
122130 addIntAttribute (& allocation ,
123- NAME_ATTRIBUTE_UPLINK_CHANNEL_BEGIN_TUXP_PROTOCOL_ALLOCATION , 0 );
131+ NAME_ATTRIBUTE_UPLINK_CHANNEL_BEGIN_TUXP_PROTOCOL_ALLOCATION , 0x17 );
124132 addIntAttribute (& allocation ,
125- NAME_ATTRIBUTE_UPLINK_CHANNEL_END_TUXP_PROTOCOL_ALLOCATION , 0 );
126- addByteAttribute (& allocation , NAME_ATTRIBUTE_UPLINK_ADDRESS_HIGH_BYTE_TUXP_PROTOCOL_ALLOCATION , 0 );
127- addByteAttribute (& allocation ,NAME_ATTRIBUTE_UPLINK_ADDRESS_LOW_BYTE_TUXP_PROTOCOL_ALLOCATION , 0 );
133+ NAME_ATTRIBUTE_UPLINK_CHANNEL_END_TUXP_PROTOCOL_ALLOCATION , 0x17 );
134+ uint8_t uplinkAddress [] = {0x00 , 0x00 };
135+ addBytesAttribute (& allocation , NAME_ATTRIBUTE_UPLINK_ADDRESS_TUXP_PROTOCOL_ALLOCATION ,
136+ uplinkAddress , 2 );
128137
129138 uint8_t allocatedAddress [] = {0x00 , 0x01 , 0x17 };
130139 addBytesAttribute (& allocation ,
@@ -220,15 +229,23 @@ int receiveRadioDataImpl(uint8_t buffer[], int bufferSize) {
220229 return 0 ;
221230}
222231
232+ long getTimeImpl () {
233+ time_t current ;
234+ time (& current );
235+
236+ return current ;
237+ }
238+
223239void registerThingHooks () {
224240 registerRadioInitializer (initializeRadioImpl );
225- registerThingIdGenerator ( generateThingIdImpl );
226- registerThingIdGenerator (loadRegistrationCodeImpl );
241+ registerThingIdLoader ( loadThingIdImpl );
242+ registerRegistrationCodeLoader (loadRegistrationCodeImpl );
227243 registerRadioConfigurer (configureRadioImpl );
228244 registerRadioAddressChanger (changeRadioAddressImpl );
229245 registerThingInfoLoader (loadThingInfoImpl );
230246 registerThingInfoSaver (saveThingInfoImpl );
231247 registerResetter (resetImpl );
248+ registerTimer (getTimeImpl );
232249 registerRadioDataReceiver (receiveRadioDataImpl );
233250 registerThingProtocolsConfigurer (configureThingProtocolsImpl );
234251}
@@ -291,8 +308,8 @@ void testLoraDacAllocated() {
291308 loadThingInfoImpl (& thingInfo );
292309 TEST_ASSERT_EQUAL_INT (ALLOCATED , thingInfo .dacState );
293310
294- TEST_ASSERT_EQUAL_INT (0 , thingInfo .uplinkChannelBegin );
295- TEST_ASSERT_EQUAL_INT (0 , thingInfo .uplinkChannelEnd );
311+ TEST_ASSERT_EQUAL_INT (23 , thingInfo .uplinkChannelBegin );
312+ TEST_ASSERT_EQUAL_INT (23 , thingInfo .uplinkChannelEnd );
296313 TEST_ASSERT_EQUAL_UINT8 (0x00 , thingInfo .uplinkAddressHighByte );
297314 TEST_ASSERT_EQUAL_UINT8 (0x00 , thingInfo .uplinkAddressLowByte );
298315
0 commit comments