Open yzliao opened 11 years ago
sample code
#if DATA_COMPRESSION_ENABLED
compress_data(samples_sorted_bytes, uncomp_data_len, comp_samples_sorted_bytes,&comp_data_len);
if(comp_data_len==0){
sf_tdma_disable_tx(); //should we access this via app_connection?
leds_off(LEDS_GREEN);
}
else{
leds_on(LEDS_GREEN);
sf_tdma_enable_tx();
app_conn_send(comp_samples_sorted_bytes,sizeof(uint8_t)*comp_data_len);
}
void compress_data(const uint8_t *uncomp_data, uint8_t data_len, const uint8_t *comp_data, uint8_t *comp_data_len)
{
#ifdef I2C_SENSOR
int acc_y, acc_z;
acc_y = (uncomp_data[2]<<8)+uncomp_data[3];
acc_z = (uncomp_data[4]<<8)+uncomp_data[5];
if(abs_value(acc_y)>=abs_value(acc_z)){
*comp_data_len= data_len;
copy_byte_array(uncomp_data,comp_data,data_len);
}
else{
*comp_data_len = 0;
}
#endif
#ifdef ADC_SENSOR
*comp_data_len= data_len;
copy_byte_array(uncomp_data,comp_data,data_len);
#endif
}
void copy_byte_array(uint8_t * from, uint8_t * to, const uint8_t len)
{
int i;
for(i=0;i<len;i++)
*(to+i)=*(from+i);
}
two methods: