예제 #1
0
int main(void) {
   char blah;
   
   //initialization
   gina_init();  // initialize hardware
   at_init();    // enable radio
   pwm_init();   // enable timers
   adc_init();   // init Analog-to-Digital (temp+xl)
   i2c_cfg();

   radio_cfg(); // init Radio
   imu_cfg();

   if(at_test()) {
      cmd_mode = CMD_MODE_ERROR;
   }

   cmd_mode = CMD_MODE_IMU_LOOP; //have the mote just blast data
   
   while(1) {
      //radio_cfg();
      //cmd_mode = CMD_MODE_IMU_LOOP; 
      cmd_loop();
      //Collect and send data 
      if (cmd_mode == CMD_MODE_IMU_LOOP) {
         imu_measure();
         imu_send();
         //blah=at_get_reg(RG_ANT_DIV);
         //blah+1;
      }

      //Clear out RX interrupts if we aren't expecting something
      if ((at_state!=AT_STATE_RX_READY && at_state!=AT_STATE_RX_WAITING)) { 
         at_rxmode(0);
         AT_CLR_IRQ;
      }
      PWM_WAIT;  //wait for the 3ms timer
         //Check RX
      if (at_state == AT_STATE_RX_WAITING) {
         at_read(&bytes, &len);
      }
   }
   return 0;
}
예제 #2
0
파일: test_audit.c 프로젝트: kkovaacs/zorp
void
testcase(int index)
{
  struct timeval start, end;
  gboolean success;

  audit_params.per_session = TRUE;
  gettimeofday(&start, NULL);
  success = at_test(index);
  gettimeofday(&end, NULL);
  fprintf(stdout, "%s: Testing audit=%d, encrypt=%d, compress=%d, sign=%d, timestamp: %d, ids: %d, time: %ld\n", success ? "PASS" : "FAIL", 
          TC_INDEX_AUDIT(index),
          TC_INDEX_ENCRYPT(index),
          TC_INDEX_COMPRESS(index),
          TC_INDEX_SIGN(index),
          0 && TC_INDEX_TIMESTAMP(index),
          TC_INDEX_IDS(index),
          diff_time(&start, &end));
  
  if (!success)
    exit_code = 1;
}
예제 #3
0
파일: ther_at.c 프로젝트: yzkqfll/ibaby
void ther_at_handle(char *cmd_buf, uint8 len, char *ret_buf, uint8 *ret_len)
{
	char *p;

	*ret_len = 0;

	/* check cmd end */
	if (cmd_buf[len - 1] != '\n') {
		print(LOG_DBG, "cmd end with %c, should be \\n \n", cmd_buf[len - 1]);
		return;
	}

	/* overwrite \n with \0 */
	cmd_buf[len - 1] = '\0';
	len--;
//	print(LOG_DBG, "get cmd <%s>, len %d\n", cmd_buf, len);

	if (strncmp(cmd_buf, AT_CMD, strlen(AT_CMD))) {
		at_help();
		return;
	}

	/* AT */
	if (strcmp(cmd_buf, AT_CMD) == 0) {
		*ret_len = sprintf((char *)ret_buf, "%s\n", "OK");

	} else if (strcmp(cmd_buf, AT_TEST) == 0) {
		*ret_len = at_test(ret_buf);

	} else if (strcmp(cmd_buf, AT_ALIVE) == 0) {


	/* AT+MODE=x */
	} else if (strncmp((char *)cmd_buf, AT_MODE, strlen(AT_MODE)) == 0) {
		p = cmd_buf + strlen(AT_MODE);
		if (*p == '1') {
			*ret_len = at_enter_cal_mode(ret_buf);
		} else if (*p == '0') {
			*ret_len = at_exit_cal_mode(ret_buf);
		} else {
			*ret_len = sprintf((char *)ret_buf, "%s\n", "+MODE:UNKNOWN");
		}

	/* AT+MODE */
	} else if (strcmp((char *)cmd_buf, AT_MODE_Q) == 0) {
		*ret_len = at_get_mode(ret_buf);

	/* AT+RESET */
	} else if (strcmp((char *)cmd_buf, AT_RESET) == 0) {
		*ret_len = at_reset(ret_buf);

	/* AT+MAC */
	} else if (strcmp((char *)cmd_buf, AT_MAC) == 0) {
		*ret_len = at_get_mac(ret_buf);

	/* AT+HTW=x,x */
	} else if (strncmp((char *)cmd_buf, AT_HIGH_TEMP_WARNING, strlen(AT_HIGH_TEMP_WARNING)) == 0) {
		uint8 warning_enabled;
		uint16 high_temp_threshold;

		p = cmd_buf + strlen(AT_HIGH_TEMP_WARNING);
		warning_enabled =  atoi(p);

		if (!warning_enabled) {
			/* disable high temp warning */
			*ret_len = at_set_htw(ret_buf, warning_enabled, 0);
		} else {
			/* enable high temp warning */
			p = strstr((const char *)cmd_buf, ",");
			if (p) {
				high_temp_threshold = atoi(p + 1);
				*ret_len = at_set_htw(ret_buf, warning_enabled, high_temp_threshold);
			} else {
				*ret_len = sprintf((char *)ret_buf, "%s\n", "+THRESHOLD:ERROR");
			}
		}

	/* AT+HTW */
	} else if (strcmp((char *)cmd_buf, AT_HIGH_TEMP_WARNING_Q) == 0) {
		*ret_len = at_get_htw(ret_buf);

	/* AT+LDO=x */
	} else if (strncmp((char *)cmd_buf, AT_LDO, strlen(AT_LDO)) == 0) {
		p = cmd_buf + strlen(AT_LDO);
		if (*p == '1') {
			*ret_len = at_set_ldo_on(ret_buf);
		} else if (*p == '0') {
			*ret_len = at_set_ldo_off(ret_buf);
		} else {
			*ret_len = sprintf((char *)ret_buf, "%s\n", "+LDO:UNKNOWN");
		}

	/* AT+ADC0 */
	} else if (strcmp((char *)cmd_buf, AT_ADC0) == 0) {
		*ret_len = at_get_adc(ret_buf, HAL_ADC_CHANNEL_0);

	/* AT+ADC1 */
	} else if (strcmp((char *)cmd_buf, AT_ADC1) == 0) {
		*ret_len = at_get_adc(ret_buf, HAL_ADC_CHANNEL_1);

	/* AT+HWADC0 */
	} else if (strcmp((char *)cmd_buf, AT_HWADC0) == 0) {
		*ret_len = at_get_hw_adc(ret_buf, HAL_ADC_CHANNEL_0);

	/* AT+HWADC1 */
	} else if (strcmp((char *)cmd_buf, AT_HWADC1) == 0) {
		*ret_len = at_get_hw_adc(ret_buf, HAL_ADC_CHANNEL_1);

	/* AT+CH0RT */
	} else if (strcmp((char *)cmd_buf, AT_CH0RT) == 0) {
		*ret_len = at_get_ch_Rt(ret_buf, HAL_ADC_CHANNEL_0);

	/* AT+CH1RT */
	} else if (strcmp((char *)cmd_buf, AT_CH1RT) == 0) {
		*ret_len = at_get_ch_Rt(ret_buf, HAL_ADC_CHANNEL_1);

	/* AT+TEMP0 */
	} else if (strcmp((char *)cmd_buf, AT_TEMP0) == 0) {
		*ret_len = at_get_ch_temp(ret_buf, HAL_ADC_CHANNEL_0);

	/* AT+TEMP1 */
	} else if (strcmp((char *)cmd_buf, AT_TEMP1) == 0) {
		*ret_len = at_get_ch_temp(ret_buf, HAL_ADC_CHANNEL_1);

	/* AT+ADC0DELTA=x */
	} else if (strncmp((char *)cmd_buf, AT_ADC0_DELTA, strlen(AT_ADC0_DELTA)) == 0) {
		short delta;

		p = cmd_buf + strlen(AT_ADC0_DELTA);
		delta =  atoi(p);

		*ret_len = at_set_adc0_delta(ret_buf, delta);

	/* AT+ADC0DELTA */
	} else if (strcmp((char *)cmd_buf, AT_ADC0_DELTA_Q) == 0) {
		*ret_len = at_get_adc0_delta(ret_buf);

	/* AT+ADC1K=x */
	} else if (strncmp((char *)cmd_buf, AT_ADC1_K, strlen(AT_ADC1_K)) == 0) {
		float k;

		p = cmd_buf + strlen(AT_ADC1_K);
		k =  atof(p);

		*ret_len = at_set_adc1_k(ret_buf, k);

	/* AT+ADC1K */
	} else if (strcmp((char *)cmd_buf, AT_ADC1_K_Q) == 0) {
		*ret_len = at_get_adc1_k(ret_buf);

	/* AT+LOWTEMPCAL=x,x */
	} else if (strncmp((char *)cmd_buf, AT_LOW_TEMP_CAL, strlen(AT_LOW_TEMP_CAL)) == 0) {
		float R_low, t_low;

		p = cmd_buf + strlen(AT_LOW_TEMP_CAL);
		R_low =  atof(p);

		p = strstr((const char *)cmd_buf, ",");
		if (p)
			t_low = atof(p + 1);
		else
			t_low = 0;

		*ret_len = at_set_low_temp_cal(ret_buf, R_low, t_low);

	/* AT+LOWTEMPCAL */
	} else if (strcmp((char *)cmd_buf, AT_LOW_TEMP_CAL_Q) == 0) {
		*ret_len = at_get_low_temp_cal(ret_buf);

	/* AT+HIGHTEMPCAL=x,x */
	} else if (strncmp((char *)cmd_buf, AT_HIGH_TEMP_CAL, strlen(AT_HIGH_TEMP_CAL)) == 0) {
		float R_high, t_high;

		p = cmd_buf + strlen(AT_HIGH_TEMP_CAL);
		R_high =  atof(p);

		p = strstr((const char *)cmd_buf, ",");
		if (p)
			t_high = atof(p + 1);
		else
			t_high = 0;

		*ret_len = at_set_high_temp_cal(ret_buf, R_high, t_high);

	/* AT+HIGHTEMPCAL */
	} else if (strcmp((char *)cmd_buf, AT_HIGH_TEMP_CAL_Q) == 0) {
		*ret_len = at_get_high_temp_cal(ret_buf);

	/* AT+TEMPCAL=x,y */
	} else if (strncmp((char *)cmd_buf, AT_TEMP_CAL, strlen(AT_TEMP_CAL)) == 0) {
		float B_delta, R25_delta;

		p = cmd_buf + strlen(AT_TEMP_CAL);
		B_delta =  atof(p);

		p = strstr(cmd_buf, ",");
		if (p)
			R25_delta = atof(p + 1);
		else
			R25_delta = 0;

		*ret_len = at_set_temp_cal(ret_buf, B_delta, R25_delta);

	/* AT+TEMPCAL */
	} else if (strcmp((char *)cmd_buf, AT_TEMP_CAL_Q) == 0) {
		*ret_len = at_get_temp_cal(ret_buf);

	/* AT+BATTADC */
	} else if (strcmp((char *)cmd_buf, AT_BATT_ADC) == 0) {
		*ret_len = at_get_batt_adc(ret_buf);

	/* AT+BATTV */
	} else if (strcmp((char *)cmd_buf, AT_BATT_VOLTAGE) == 0) {
		*ret_len = at_get_batt_voltage(ret_buf);

	/* AT+BATTP */
	} else if (strcmp((char *)cmd_buf, AT_BATT_PERCENTAGE) == 0) {
		*ret_len = at_get_batt_percentage(ret_buf);

	/* AT+CONTRAST=x */
	} else if (strncmp((char *)cmd_buf, AT_OLED_CONTRAST, strlen(AT_OLED_CONTRAST)) == 0) {
		uint8 contrast;

		p = cmd_buf + strlen(AT_OLED_CONTRAST);
		contrast =  atoi(p);

		*ret_len = at_set_oled9639_contrast(ret_buf, contrast);

	/* AT+SERASE */
	} else if (strcmp((char *)cmd_buf, AT_S_ERASE) == 0) {
		*ret_len = at_serase(ret_buf);

	/* AT+SRESET */
	} else if (strcmp((char *)cmd_buf, AT_S_RESET) == 0) {
		*ret_len = at_sreset(ret_buf);

	/* AT+SINFO */
	} else if (strcmp((char *)cmd_buf, AT_S_INFO) == 0) {
		*ret_len = at_sinfo(ret_buf);

	/* AT+SRESTORE */
	} else if (strcmp((char *)cmd_buf, AT_S_RESTORE) == 0) {
		*ret_len = at_srestore(ret_buf);

	/* AT+STEST */
	} else if (strcmp((char *)cmd_buf, AT_S_TEST) == 0) {
		*ret_len = at_stest(ret_buf);

	} else {
		at_help();
	}

	return;

}