Skip to content

Commit

Permalink
Add ParseDutyCycleRate 1, 15, 30, 60, 90 min.
Browse files Browse the repository at this point in the history
  • Loading branch information
Anol Paisal committed May 31, 2019
1 parent 66dac51 commit f444be4
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 17 deletions.
23 changes: 20 additions & 3 deletions src/apps/LoRaMac/encoder/SKiM980A/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,6 @@ static void OnTxNextPacketTimerEvent( void* context )
LoRaMacStatus_t status;

TimerStop( &TxNextPacketTimer );
// TimerStop( &passive_sleep_timer );

mibReq.Type = MIB_NETWORK_ACTIVATION;
status = LoRaMacMibGetRequestConfirm( &mibReq );
Expand Down Expand Up @@ -1123,6 +1122,25 @@ void RestoreUserSetting( void )
}

}

uint32_t ParseDutyCycleRate(uint8_t rate)
{
switch (rate)
{
case RATE_15_MIN: // 15 min
return 15 * APP_TX_DUTYCYCLE;
case RATE_30_MIN: // 30 min
return 30 * APP_TX_DUTYCYCLE;
case RATE_60_MIN: // 60 min
return 60 * APP_TX_DUTYCYCLE;
case RATE_90_MIN: // 90 min
return 90 * APP_TX_DUTYCYCLE;
case RATE_01_MIN: // 1 min
default:
return APP_TX_DUTYCYCLE;
}
}

/**
* Main application entry point.
*/
Expand Down Expand Up @@ -1385,8 +1403,7 @@ int main( void )
Encoder.ConfigData->isActiveMode = 0;
printf( "\r\n###### ===== Passive mode ==== ######\r\n\r\n" );
} else {
TxDutyCycleTime = (config.sampling == 0) ? (uint32_t)(APP_TX_DUTYCYCLE) :
((uint32_t)config.sampling * (uint32_t) APP_TX_DUTYCYCLE); //Duty cycle 1 ~ 15 min.
TxDutyCycleTime = ParseDutyCycleRate(config.sampling);
Encoder.ConfigData->isActiveMode = 1;
last_flow = flow;
printf( "\r\n###### ===== Active mode ==== ######\r\n\r\n" );
Expand Down
20 changes: 6 additions & 14 deletions src/boards/SKiM980A/encoder-board.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,16 @@ void OnTamperingIrq( void* context )
CRITICAL_SECTION_BEGIN();
// Encoder_t *obj = (Encoder_t *) context;
if (GpioRead(&Encoder.Tampering) == GPIO_PIN_RESET) {
if (!(flow.status && TAMPER_FLAG)) {
flow.status |= TAMPER_FLAG;
printf( "\r\n###### ===== Tampering attached ==== ######\r\n\r\n" );
#ifndef USE_GPIO
HAL_TIM_Encoder_Start_IT(&TimHandle, TIM_CHANNEL_1);
}
#endif
} else {
if ((flow.status && TAMPER_FLAG))
{
flow.status &= ~TAMPER_FLAG;
printf( "\r\n###### ===== Tampering released ==== ######\r\n\r\n" );
// HAL_TIM_Encoder_Stop_IT(&TimHandle, TIM_CHANNEL_1);
}

}
CRITICAL_SECTION_END();
if (Encoder.OnSendOneshot != NULL)
Expand All @@ -149,17 +147,11 @@ void OnAlarmIrq( void* context )
CRITICAL_SECTION_BEGIN();
// Encoder_t *obj = (Encoder_t *) context;
if (GpioRead(&Encoder.Alarm) == GPIO_PIN_RESET) {
if (!(flow.status && ALARM_FLAG))
{
flow.status |= ALARM_FLAG;
printf( "\r\n###### ===== Alarm ==== ######\r\n\r\n" );
}
} else {
if ((flow.status && ALARM_FLAG))
{
flow.status &= ~ALARM_FLAG;
printf( "\r\n###### ===== Silent ==== ######\r\n\r\n" );
}
}
CRITICAL_SECTION_END();
if (Encoder.OnSendOneshot != NULL && config.digital_alarm > 0)
Expand Down Expand Up @@ -191,15 +183,15 @@ void OnPulseDetected( void* context )
Encoder.OnShowPulseDetect();
}

CRITICAL_SECTION_END();

if(Encoder.ConfigData->isActiveMode == 0) {
Encoder.ConfigData->isActiveMode = 1;
if (Encoder.OnSendOneshot != NULL)
{
Encoder.OnSendOneshot( );
}
}

CRITICAL_SECTION_END();
}
}

#else
Expand Down
8 changes: 8 additions & 0 deletions src/boards/encoder-board.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@

#include "encoder.h"

typedef enum {
RATE_01_MIN = 0,
RATE_15_MIN,
RATE_30_MIN,
RATE_60_MIN,
RATE_90_MIN
} DUTYCYCLE_RATE ;

// An encoder.c file has to be implmented under system directory.
void OnTamperingIrq( void* context );
void OnAlarmIrq( void* context );
Expand Down

0 comments on commit f444be4

Please sign in to comment.