Skip to content

Commit a3a0c1c

Browse files
committed
Merge pull request #235 from openwsn-berkeley/develop_FW-456
FW-456. Fixed.
2 parents 4183abe + 13265e3 commit a3a0c1c

File tree

24 files changed

+2441
-2192
lines changed

24 files changed

+2441
-2192
lines changed

drivers/common/openserial.c

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ void openserial_stop() {
450450
}
451451

452452
void openserial_goldenImageCommands(void){
453-
uint8_t input_buffer[7];
453+
uint8_t input_buffer[10];
454454
uint8_t numDataBytes;
455455
uint8_t version;
456456
#ifndef GOLDEN_IMAGE_NONE
@@ -460,6 +460,13 @@ void openserial_goldenImageCommands(void){
460460
uint8_t commandLen;
461461
uint8_t comandParam_8;
462462
uint16_t comandParam_16;
463+
cellInfo_ht cellList[SCHEDULEIEMAXNUMCELLS];
464+
uint8_t i;
465+
466+
open_addr_t neighbor;
467+
bool foundNeighbor;
468+
469+
memset(cellList,0,sizeof(cellList));
463470

464471
numDataBytes = openserial_getNumDataBytes();
465472
//copying the buffer
@@ -489,7 +496,7 @@ void openserial_goldenImageCommands(void){
489496
commandId = openserial_vars.inputBuf[3];
490497
commandLen = openserial_vars.inputBuf[4];
491498

492-
if (commandLen>2 || commandLen == 0) {
499+
if (commandLen>3) {
493500
// the max command Len is 2, except ping commands
494501
return;
495502
} else {
@@ -525,9 +532,6 @@ void openserial_goldenImageCommands(void){
525532
case COMMAND_SET_DAOPERIOD: // two bytes, in mili-seconds
526533
icmpv6rpl_setDAOPeriod(comandParam_16);
527534
break;
528-
case COMMAND_PING_MOTE:
529-
// this should not happen
530-
break;
531535
case COMMAND_SET_DAGRANK: // two bytes
532536
neighbors_setMyDAGrank(comandParam_16);
533537
break;
@@ -558,6 +562,57 @@ void openserial_goldenImageCommands(void){
558562
}
559563
}
560564
break;
565+
case COMMAND_SET_6P_ADD:
566+
case COMMAND_SET_6P_DELETE:
567+
case COMMAND_SET_6P_COUNT:
568+
case COMMAND_SET_6P_LIST:
569+
case COMMAND_SET_6P_CLEAR:
570+
// get preferred parent
571+
foundNeighbor = neighbors_getPreferredParentEui64(&neighbor);
572+
if (foundNeighbor==FALSE) {
573+
break;
574+
}
575+
576+
sixtop_setHandler(SIX_HANDLER_OTF);
577+
if (
578+
(
579+
commandId != COMMAND_SET_6P_ADD &&
580+
commandId != COMMAND_SET_6P_DELETE
581+
) ||
582+
(
583+
(
584+
commandId == COMMAND_SET_6P_ADD ||
585+
commandId == COMMAND_SET_6P_DELETE
586+
) &&
587+
commandLen == 0
588+
)
589+
){
590+
// randommly select cell
591+
sixtop_request(commandId-8,&neighbor,1);
592+
} else {
593+
for (i=0;i<commandLen;i++){
594+
cellList[i].tsNum = openserial_vars.inputBuf[5+i];
595+
cellList[i].choffset = 0;
596+
cellList[i].linkoptions = CELLTYPE_TX;
597+
}
598+
sixtop_addORremoveCellByInfo(commandId-8,&neighbor,cellList);
599+
}
600+
break;
601+
case COMMAND_SET_SLOTDURATION:
602+
ieee154e_setSlotDuration(comandParam_16);
603+
break;
604+
case COMMAND_SET_6PRESPONSE_STATUS:
605+
if (comandParam_8 ==1) {
606+
sixtop_setIsResponseEnabled(TRUE);
607+
} else {
608+
if (comandParam_8 == 0) {
609+
sixtop_setIsResponseEnabled(FALSE);
610+
} else {
611+
// security only can be 1 or 0
612+
break;
613+
}
614+
}
615+
break;
561616
default:
562617
// wrong command ID
563618
break;

drivers/common/openserial.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,18 @@ enum {
6464
COMMAND_SET_KAPERIOD = 2,
6565
COMMAND_SET_DIOPERIOD = 3,
6666
COMMAND_SET_DAOPERIOD = 4,
67-
COMMAND_PING_MOTE = 5,
68-
COMMAND_SET_DAGRANK = 6,
69-
COMMAND_SET_SECURITY_STATUS = 7,
70-
COMMAND_SET_FRAMELENGTH = 8,
71-
COMMAND_SET_ACK_STATUS = 9,
72-
COMMAND_MAX = 10,
67+
COMMAND_SET_DAGRANK = 5,
68+
COMMAND_SET_SECURITY_STATUS = 6,
69+
COMMAND_SET_FRAMELENGTH = 7,
70+
COMMAND_SET_ACK_STATUS = 8,
71+
COMMAND_SET_6P_ADD = 9,
72+
COMMAND_SET_6P_DELETE = 10,
73+
COMMAND_SET_6P_COUNT = 11,
74+
COMMAND_SET_6P_LIST = 12,
75+
COMMAND_SET_6P_CLEAR = 13,
76+
COMMAND_SET_SLOTDURATION = 14,
77+
COMMAND_SET_6PRESPONSE_STATUS = 15,
78+
COMMAND_MAX = 16,
7379
};
7480

7581
//=========================== module variables ================================

inc/opendefs.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ static const uint8_t infoStackName[] = "OpenWSN ";
2525
#define OPENWSN_VERSION_PATCH 0
2626

2727
// golden image version and type
28-
#define GOLDEN_IMAGE_VERSION 1
28+
#define GOLDEN_IMAGE_VERSION 2
2929
// define golden image type: only one can be used
3030
#define GD_TYPE_ROOT 1 // dagroot
3131
#define GD_TYPE_SNIFFER 2 // sniffer
@@ -244,6 +244,9 @@ enum {
244244
ERR_WRONG_CRC_INPUT = 0x39, // wrong CRC in input Buffer (input length {0})
245245
ERR_PACKET_SYNC = 0x3a, // synchronized when received a packet
246246
ERR_SECURITY = 0x3b, // security error on frameType {0}, code location {1}
247+
ERR_SIXTOP_RETURNCODE = 0x3c, // sixtop return code {0} at sixtop state {1}
248+
ERR_SIXTOP_COUNT = 0x3d, // there are {0} cells to request mote
249+
ERR_SIXTOP_LIST = 0x3e, // the cells reserved to request mote contains slot {0} and slot {1}
247250
};
248251

249252
//=========================== typedef =========================================
@@ -301,9 +304,11 @@ typedef struct {
301304
uint8_t l2_numTxAttempts; // number Tx attempts
302305
asn_t l2_asn; // at what ASN the packet was Tx'ed or Rx'ed
303306
uint8_t* l2_payload; // pointer to the start of the payload of l2 (used for MAC to fill in ASN in ADV)
304-
uint8_t* l2_scheduleIE_cellObjects; // pointer to the start of cell Objects in scheduleIE
305-
uint8_t l2_scheduleIE_numOfCells; // number of cells were going to be scheduled or removed.
306-
uint8_t l2_scheduleIE_frameID; // frameID in scheduleIE
307+
uint8_t* l2_sixtop_cellObjects; // pointer to the start of cell Objects in 6P
308+
uint8_t l2_sixtop_numOfCells; // number of cells were going to be scheduled or removed.
309+
uint8_t l2_sixtop_frameID; // frameID in 6P
310+
uint8_t l2_sixtop_requestCommand; // request Command in 6P
311+
uint8_t l2_sixtop_returnCode; // return code in 6P
307312
uint8_t* l2_ASNpayload; // pointer to the ASN in EB
308313
uint8_t l2_joinPriority; // the join priority received in EB
309314
bool l2_IEListPresent; //did have IE field?

openapps/c6t/c6t.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ owerror_t c6t_receive(
9191

9292
sixtop_setHandler(SIX_HANDLER_OTF);
9393
// call sixtop
94-
sixtop_addCells(
94+
sixtop_request(
95+
IANA_6TOP_CMD_ADD,
9596
&neighbor,
9697
1
9798
);
@@ -119,8 +120,10 @@ owerror_t c6t_receive(
119120

120121
sixtop_setHandler(SIX_HANDLER_OTF);
121122
// call sixtop
122-
sixtop_removeCell(
123-
&neighbor
123+
sixtop_request(
124+
IANA_6TOP_CMD_DELETE,
125+
&neighbor,
126+
1
124127
);
125128

126129
// set the CoAP header

openstack/02a-MAClow/IEEE802154E.c

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ void ieee154e_init() {
115115
ieee154e_vars.singleChannel = SYNCHRONIZING_CHANNEL;
116116
ieee154e_vars.isAckEnabled = TRUE;
117117
ieee154e_vars.isSecurityEnabled = FALSE;
118+
ieee154e_vars.slotDuration = TsSlotDuration;
118119
// default hopping template
119120
memcpy(
120121
&(ieee154e_vars.chTemplate[0]),
@@ -140,7 +141,7 @@ void ieee154e_init() {
140141
radio_setStartFrameCb(ieee154e_startOfFrame);
141142
radio_setEndFrameCb(ieee154e_endOfFrame);
142143
// have the radio start its timer
143-
radio_startTimer(TsSlotDuration);
144+
radio_startTimer(ieee154e_vars.slotDuration);
144145
}
145146

146147
//=========================== public ==========================================
@@ -184,7 +185,7 @@ PORT_RADIOTIMER_WIDTH ieee154e_asnDiff(asn_t* someASN) {
184185
This function executes in ISR mode, when the new slot timer fires.
185186
*/
186187
void isr_ieee154e_newSlot() {
187-
radio_setTimerPeriod(TsSlotDuration);
188+
radio_setTimerPeriod(ieee154e_vars.slotDuration);
188189
if (ieee154e_vars.isSync==FALSE) {
189190
if (idmanager_getIsDAGroot()==TRUE) {
190191
changeIsSync(TRUE);
@@ -761,6 +762,12 @@ port_INLINE bool ieee154e_processIEs(OpenQueueEntry_t* pkt, uint16_t* lenIE) {
761762
// timelsot template ID
762763
timeslotTemplateIDStoreFromEB(*((uint8_t*)(pkt->payload)+ptr));
763764
ptr = ptr + 1;
765+
if (ieee154e_vars.tsTemplateId != TIMESLOT_TEMPLATE_ID){
766+
ieee154e_vars.slotDuration = *((uint8_t*)(pkt->payload)+ptr);
767+
ptr = ptr + 1;
768+
ieee154e_vars.slotDuration |= ((*((uint8_t*)(pkt->payload)+ptr))<<8) & 0xff00;
769+
ptr = ptr + 1;
770+
}
764771
}
765772
break;
766773

@@ -948,7 +955,7 @@ port_INLINE void activity_ti1ORri1() {
948955
openserial_startInput();
949956
//this is to emulate a set of serial input slots without having the slotted structure.
950957

951-
radio_setTimerPeriod(TsSlotDuration*(NUMSERIALRX));
958+
radio_setTimerPeriod(ieee154e_vars.slotDuration*(NUMSERIALRX));
952959

953960
//increase ASN by NUMSERIALRX-1 slots as at this slot is already incremented by 1
954961
for (i=0;i<NUMSERIALRX-1;i++){
@@ -1912,6 +1919,14 @@ void ieee154e_setIsSecurityEnabled(bool isEnabled){
19121919
ieee154e_vars.isSecurityEnabled = isEnabled;
19131920
}
19141921

1922+
void ieee154e_setSlotDuration(uint16_t duration){
1923+
ieee154e_vars.slotDuration = duration;
1924+
}
1925+
1926+
uint16_t ieee154e_getSlotDuration(){
1927+
return ieee154e_vars.slotDuration;
1928+
}
1929+
19151930
// timeslot template handling
19161931
port_INLINE void timeslotTemplateIDStoreFromEB(uint8_t id){
19171932
ieee154e_vars.tsTemplateId = id;
@@ -1936,12 +1951,12 @@ void synchronizePacket(PORT_RADIOTIMER_WIDTH timeReceived) {
19361951
// calculate new period
19371952
timeCorrection = (PORT_SIGNED_INT_WIDTH)((PORT_SIGNED_INT_WIDTH)timeReceived-(PORT_SIGNED_INT_WIDTH)TsTxOffset);
19381953

1939-
newPeriod = TsSlotDuration;
1954+
newPeriod = ieee154e_vars.slotDuration;
19401955

19411956
// detect whether I'm too close to the edge of the slot, in that case,
19421957
// skip a slot and increase the temporary slot length to be 2 slots long
19431958
if (currentValue<timeReceived || currentPeriod-currentValue<RESYNCHRONIZATIONGUARD) {
1944-
newPeriod += TsSlotDuration;
1959+
newPeriod += ieee154e_vars.slotDuration;
19451960
incrementAsnOffset();
19461961
}
19471962
newPeriod = (PORT_RADIOTIMER_WIDTH)((PORT_SIGNED_INT_WIDTH)newPeriod+timeCorrection);
@@ -2055,9 +2070,9 @@ void notif_receive(OpenQueueEntry_t* packetReceived) {
20552070
// COMPONENT_IEEE802154E_TO_SIXTOP so sixtop can knows it's for it
20562071
packetReceived->owner = COMPONENT_IEEE802154E_TO_SIXTOP;
20572072
#ifdef GOLDEN_IMAGE_ROOT
2058-
openserial_printInfo(COMPONENT_IEEE802154E,ERR_PACKET_SYNC,
2059-
(errorparameter_t)packetReceived->l2_asn.bytes0and1,
2060-
(errorparameter_t)packetReceived->l2_timeCorrection);
2073+
// openserial_printInfo(COMPONENT_IEEE802154E,ERR_PACKET_SYNC,
2074+
// (errorparameter_t)packetReceived->l2_asn.bytes0and1,
2075+
// (errorparameter_t)packetReceived->l2_timeCorrection);
20612076
#endif
20622077
// post RES's Receive task
20632078
scheduler_push_task(task_sixtopNotifReceive,TASKPRIO_SIXTOP_NOTIF_RX);

openstack/02a-MAClow/IEEE802154E.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ static const uint8_t chTemplate_default[] = {
4141
#define IEEE802154E_DESC_TYPE_LONG (1<<15)
4242
#define IEEE802154E_DESC_TYPE_SHORT (0<<15)
4343

44+
#define IANA_6TOP_IE_GROUP_ID (2<<11)
45+
#define IANA_6TOP_IE_GROUP_ID_TYPE (1<<15)
46+
4447
#define IEEE802154E_DESC_TYPE_HEADER_IE 0x0000
4548
#define IEEE802154E_DESC_TYPE_PAYLOAD_IE 0x8000
4649
//len field on PAYLOAD/HEADER DESC
@@ -142,7 +145,7 @@ enum ieee154e_atomicdurations_enum {
142145
TsTxOffset = 70, // 2120us
143146
TsLongGT = 36, // 1100us
144147
TsTxAckDelay = 33, // 1000us
145-
TsShortGT = 7, // 500us
148+
TsShortGT = 9, // 500us, The standardlized value for this is 400/2=200us(7ticks). Currectly 7 doesn't work for short packet, change it back to 7 when found the problem.
146149
#else
147150
TsTxOffset = 131, // 4000us
148151
TsLongGT = 43, // 1300us
@@ -247,6 +250,8 @@ typedef struct {
247250
bool isSecurityEnabled; // whether security is applied
248251
// time correction
249252
int16_t timeCorrection; // store the timeCorrection, prepend and retrieve it inside of frame header
253+
254+
uint16_t slotDuration; //
250255
} ieee154e_vars_t;
251256

252257
BEGIN_PACK
@@ -279,6 +284,8 @@ void ieee154e_getAsn(uint8_t* array);
279284
void ieee154e_setIsAckEnabled(bool isEnabled);
280285
void ieee154e_setSingleChannel(uint8_t channel);
281286
void ieee154e_setIsSecurityEnabled(bool isEnabled);
287+
void ieee154e_setSlotDuration(uint16_t duration);
288+
uint16_t ieee154e_getSlotDuration();
282289

283290
uint16_t ieee154e_getTimeCorrection(void);
284291
// events

openstack/02a-MAClow/adaptive_sync.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ Once compensationTimeout == 0, extend or shorten current slot length for one tic
173173
void adaptive_sync_countCompensationTimeout() {
174174
uint16_t newSlotDuration;
175175

176-
newSlotDuration = TsSlotDuration;
176+
newSlotDuration = ieee154e_getSlotDuration();
177177

178178
// if clockState is not set yet, don't compensate.
179179
if (adaptive_sync_vars.clockState == S_NONE) {
@@ -215,7 +215,7 @@ void adaptive_sync_countCompensationTimeout_compoundSlots(uint16_t compoundSlots
215215
uint8_t compensateTicks;
216216
uint16_t newSlotDuration;
217217

218-
newSlotDuration = TsSlotDuration*(compoundSlots+1);
218+
newSlotDuration = ieee154e_getSlotDuration()*(compoundSlots+1);
219219

220220
// if clockState is not set yet, don't compensate.
221221
if(adaptive_sync_vars.clockState == S_NONE) {

0 commit comments

Comments
 (0)