Skip to content

Commit

Permalink
Merge pull request #235 from openwsn-berkeley/develop_FW-456
Browse files Browse the repository at this point in the history
FW-456. Fixed.
  • Loading branch information
changtengfei committed Jan 28, 2016
2 parents 4183abe + 13265e3 commit a3a0c1c
Show file tree
Hide file tree
Showing 24 changed files with 2,441 additions and 2,192 deletions.
65 changes: 60 additions & 5 deletions drivers/common/openserial.c
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ void openserial_stop() {
}

void openserial_goldenImageCommands(void){
uint8_t input_buffer[7];
uint8_t input_buffer[10];
uint8_t numDataBytes;
uint8_t version;
#ifndef GOLDEN_IMAGE_NONE
Expand All @@ -460,6 +460,13 @@ void openserial_goldenImageCommands(void){
uint8_t commandLen;
uint8_t comandParam_8;
uint16_t comandParam_16;
cellInfo_ht cellList[SCHEDULEIEMAXNUMCELLS];
uint8_t i;

open_addr_t neighbor;
bool foundNeighbor;

memset(cellList,0,sizeof(cellList));

numDataBytes = openserial_getNumDataBytes();
//copying the buffer
Expand Down Expand Up @@ -489,7 +496,7 @@ void openserial_goldenImageCommands(void){
commandId = openserial_vars.inputBuf[3];
commandLen = openserial_vars.inputBuf[4];

if (commandLen>2 || commandLen == 0) {
if (commandLen>3) {
// the max command Len is 2, except ping commands
return;
} else {
Expand Down Expand Up @@ -525,9 +532,6 @@ void openserial_goldenImageCommands(void){
case COMMAND_SET_DAOPERIOD: // two bytes, in mili-seconds
icmpv6rpl_setDAOPeriod(comandParam_16);
break;
case COMMAND_PING_MOTE:
// this should not happen
break;
case COMMAND_SET_DAGRANK: // two bytes
neighbors_setMyDAGrank(comandParam_16);
break;
Expand Down Expand Up @@ -558,6 +562,57 @@ void openserial_goldenImageCommands(void){
}
}
break;
case COMMAND_SET_6P_ADD:
case COMMAND_SET_6P_DELETE:
case COMMAND_SET_6P_COUNT:
case COMMAND_SET_6P_LIST:
case COMMAND_SET_6P_CLEAR:
// get preferred parent
foundNeighbor = neighbors_getPreferredParentEui64(&neighbor);
if (foundNeighbor==FALSE) {
break;
}

sixtop_setHandler(SIX_HANDLER_OTF);
if (
(
commandId != COMMAND_SET_6P_ADD &&
commandId != COMMAND_SET_6P_DELETE
) ||
(
(
commandId == COMMAND_SET_6P_ADD ||
commandId == COMMAND_SET_6P_DELETE
) &&
commandLen == 0
)
){
// randommly select cell
sixtop_request(commandId-8,&neighbor,1);
} else {
for (i=0;i<commandLen;i++){
cellList[i].tsNum = openserial_vars.inputBuf[5+i];
cellList[i].choffset = 0;
cellList[i].linkoptions = CELLTYPE_TX;
}
sixtop_addORremoveCellByInfo(commandId-8,&neighbor,cellList);
}
break;
case COMMAND_SET_SLOTDURATION:
ieee154e_setSlotDuration(comandParam_16);
break;
case COMMAND_SET_6PRESPONSE_STATUS:
if (comandParam_8 ==1) {
sixtop_setIsResponseEnabled(TRUE);
} else {
if (comandParam_8 == 0) {
sixtop_setIsResponseEnabled(FALSE);
} else {
// security only can be 1 or 0
break;
}
}
break;
default:
// wrong command ID
break;
Expand Down
18 changes: 12 additions & 6 deletions drivers/common/openserial.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,18 @@ enum {
COMMAND_SET_KAPERIOD = 2,
COMMAND_SET_DIOPERIOD = 3,
COMMAND_SET_DAOPERIOD = 4,
COMMAND_PING_MOTE = 5,
COMMAND_SET_DAGRANK = 6,
COMMAND_SET_SECURITY_STATUS = 7,
COMMAND_SET_FRAMELENGTH = 8,
COMMAND_SET_ACK_STATUS = 9,
COMMAND_MAX = 10,
COMMAND_SET_DAGRANK = 5,
COMMAND_SET_SECURITY_STATUS = 6,
COMMAND_SET_FRAMELENGTH = 7,
COMMAND_SET_ACK_STATUS = 8,
COMMAND_SET_6P_ADD = 9,
COMMAND_SET_6P_DELETE = 10,
COMMAND_SET_6P_COUNT = 11,
COMMAND_SET_6P_LIST = 12,
COMMAND_SET_6P_CLEAR = 13,
COMMAND_SET_SLOTDURATION = 14,
COMMAND_SET_6PRESPONSE_STATUS = 15,
COMMAND_MAX = 16,
};

//=========================== module variables ================================
Expand Down
13 changes: 9 additions & 4 deletions inc/opendefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ static const uint8_t infoStackName[] = "OpenWSN ";
#define OPENWSN_VERSION_PATCH 0

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

//=========================== typedef =========================================
Expand Down Expand Up @@ -301,9 +304,11 @@ typedef struct {
uint8_t l2_numTxAttempts; // number Tx attempts
asn_t l2_asn; // at what ASN the packet was Tx'ed or Rx'ed
uint8_t* l2_payload; // pointer to the start of the payload of l2 (used for MAC to fill in ASN in ADV)
uint8_t* l2_scheduleIE_cellObjects; // pointer to the start of cell Objects in scheduleIE
uint8_t l2_scheduleIE_numOfCells; // number of cells were going to be scheduled or removed.
uint8_t l2_scheduleIE_frameID; // frameID in scheduleIE
uint8_t* l2_sixtop_cellObjects; // pointer to the start of cell Objects in 6P
uint8_t l2_sixtop_numOfCells; // number of cells were going to be scheduled or removed.
uint8_t l2_sixtop_frameID; // frameID in 6P
uint8_t l2_sixtop_requestCommand; // request Command in 6P
uint8_t l2_sixtop_returnCode; // return code in 6P
uint8_t* l2_ASNpayload; // pointer to the ASN in EB
uint8_t l2_joinPriority; // the join priority received in EB
bool l2_IEListPresent; //did have IE field?
Expand Down
9 changes: 6 additions & 3 deletions openapps/c6t/c6t.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ owerror_t c6t_receive(

sixtop_setHandler(SIX_HANDLER_OTF);
// call sixtop
sixtop_addCells(
sixtop_request(
IANA_6TOP_CMD_ADD,
&neighbor,
1
);
Expand Down Expand Up @@ -119,8 +120,10 @@ owerror_t c6t_receive(

sixtop_setHandler(SIX_HANDLER_OTF);
// call sixtop
sixtop_removeCell(
&neighbor
sixtop_request(
IANA_6TOP_CMD_DELETE,
&neighbor,
1
);

// set the CoAP header
Expand Down
31 changes: 23 additions & 8 deletions openstack/02a-MAClow/IEEE802154E.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ void ieee154e_init() {
ieee154e_vars.singleChannel = SYNCHRONIZING_CHANNEL;
ieee154e_vars.isAckEnabled = TRUE;
ieee154e_vars.isSecurityEnabled = FALSE;
ieee154e_vars.slotDuration = TsSlotDuration;
// default hopping template
memcpy(
&(ieee154e_vars.chTemplate[0]),
Expand All @@ -140,7 +141,7 @@ void ieee154e_init() {
radio_setStartFrameCb(ieee154e_startOfFrame);
radio_setEndFrameCb(ieee154e_endOfFrame);
// have the radio start its timer
radio_startTimer(TsSlotDuration);
radio_startTimer(ieee154e_vars.slotDuration);
}

//=========================== public ==========================================
Expand Down Expand Up @@ -184,7 +185,7 @@ PORT_RADIOTIMER_WIDTH ieee154e_asnDiff(asn_t* someASN) {
This function executes in ISR mode, when the new slot timer fires.
*/
void isr_ieee154e_newSlot() {
radio_setTimerPeriod(TsSlotDuration);
radio_setTimerPeriod(ieee154e_vars.slotDuration);
if (ieee154e_vars.isSync==FALSE) {
if (idmanager_getIsDAGroot()==TRUE) {
changeIsSync(TRUE);
Expand Down Expand Up @@ -761,6 +762,12 @@ port_INLINE bool ieee154e_processIEs(OpenQueueEntry_t* pkt, uint16_t* lenIE) {
// timelsot template ID
timeslotTemplateIDStoreFromEB(*((uint8_t*)(pkt->payload)+ptr));
ptr = ptr + 1;
if (ieee154e_vars.tsTemplateId != TIMESLOT_TEMPLATE_ID){
ieee154e_vars.slotDuration = *((uint8_t*)(pkt->payload)+ptr);
ptr = ptr + 1;
ieee154e_vars.slotDuration |= ((*((uint8_t*)(pkt->payload)+ptr))<<8) & 0xff00;
ptr = ptr + 1;
}
}
break;

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

radio_setTimerPeriod(TsSlotDuration*(NUMSERIALRX));
radio_setTimerPeriod(ieee154e_vars.slotDuration*(NUMSERIALRX));

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

void ieee154e_setSlotDuration(uint16_t duration){
ieee154e_vars.slotDuration = duration;
}

uint16_t ieee154e_getSlotDuration(){
return ieee154e_vars.slotDuration;
}

// timeslot template handling
port_INLINE void timeslotTemplateIDStoreFromEB(uint8_t id){
ieee154e_vars.tsTemplateId = id;
Expand All @@ -1936,12 +1951,12 @@ void synchronizePacket(PORT_RADIOTIMER_WIDTH timeReceived) {
// calculate new period
timeCorrection = (PORT_SIGNED_INT_WIDTH)((PORT_SIGNED_INT_WIDTH)timeReceived-(PORT_SIGNED_INT_WIDTH)TsTxOffset);

newPeriod = TsSlotDuration;
newPeriod = ieee154e_vars.slotDuration;

// detect whether I'm too close to the edge of the slot, in that case,
// skip a slot and increase the temporary slot length to be 2 slots long
if (currentValue<timeReceived || currentPeriod-currentValue<RESYNCHRONIZATIONGUARD) {
newPeriod += TsSlotDuration;
newPeriod += ieee154e_vars.slotDuration;
incrementAsnOffset();
}
newPeriod = (PORT_RADIOTIMER_WIDTH)((PORT_SIGNED_INT_WIDTH)newPeriod+timeCorrection);
Expand Down Expand Up @@ -2055,9 +2070,9 @@ void notif_receive(OpenQueueEntry_t* packetReceived) {
// COMPONENT_IEEE802154E_TO_SIXTOP so sixtop can knows it's for it
packetReceived->owner = COMPONENT_IEEE802154E_TO_SIXTOP;
#ifdef GOLDEN_IMAGE_ROOT
openserial_printInfo(COMPONENT_IEEE802154E,ERR_PACKET_SYNC,
(errorparameter_t)packetReceived->l2_asn.bytes0and1,
(errorparameter_t)packetReceived->l2_timeCorrection);
// openserial_printInfo(COMPONENT_IEEE802154E,ERR_PACKET_SYNC,
// (errorparameter_t)packetReceived->l2_asn.bytes0and1,
// (errorparameter_t)packetReceived->l2_timeCorrection);
#endif
// post RES's Receive task
scheduler_push_task(task_sixtopNotifReceive,TASKPRIO_SIXTOP_NOTIF_RX);
Expand Down
9 changes: 8 additions & 1 deletion openstack/02a-MAClow/IEEE802154E.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ static const uint8_t chTemplate_default[] = {
#define IEEE802154E_DESC_TYPE_LONG (1<<15)
#define IEEE802154E_DESC_TYPE_SHORT (0<<15)

#define IANA_6TOP_IE_GROUP_ID (2<<11)
#define IANA_6TOP_IE_GROUP_ID_TYPE (1<<15)

#define IEEE802154E_DESC_TYPE_HEADER_IE 0x0000
#define IEEE802154E_DESC_TYPE_PAYLOAD_IE 0x8000
//len field on PAYLOAD/HEADER DESC
Expand Down Expand Up @@ -142,7 +145,7 @@ enum ieee154e_atomicdurations_enum {
TsTxOffset = 70, // 2120us
TsLongGT = 36, // 1100us
TsTxAckDelay = 33, // 1000us
TsShortGT = 7, // 500us
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.
#else
TsTxOffset = 131, // 4000us
TsLongGT = 43, // 1300us
Expand Down Expand Up @@ -247,6 +250,8 @@ typedef struct {
bool isSecurityEnabled; // whether security is applied
// time correction
int16_t timeCorrection; // store the timeCorrection, prepend and retrieve it inside of frame header

uint16_t slotDuration; //
} ieee154e_vars_t;

BEGIN_PACK
Expand Down Expand Up @@ -279,6 +284,8 @@ void ieee154e_getAsn(uint8_t* array);
void ieee154e_setIsAckEnabled(bool isEnabled);
void ieee154e_setSingleChannel(uint8_t channel);
void ieee154e_setIsSecurityEnabled(bool isEnabled);
void ieee154e_setSlotDuration(uint16_t duration);
uint16_t ieee154e_getSlotDuration();

uint16_t ieee154e_getTimeCorrection(void);
// events
Expand Down
4 changes: 2 additions & 2 deletions openstack/02a-MAClow/adaptive_sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ Once compensationTimeout == 0, extend or shorten current slot length for one tic
void adaptive_sync_countCompensationTimeout() {
uint16_t newSlotDuration;

newSlotDuration = TsSlotDuration;
newSlotDuration = ieee154e_getSlotDuration();

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

newSlotDuration = TsSlotDuration*(compoundSlots+1);
newSlotDuration = ieee154e_getSlotDuration()*(compoundSlots+1);

// if clockState is not set yet, don't compensate.
if(adaptive_sync_vars.clockState == S_NONE) {
Expand Down
Loading

0 comments on commit a3a0c1c

Please sign in to comment.