c - C 中的简单压缩算法不起作用..有什么建议吗?

标签 c embedded compression nrf51

我正在 nordic Micro 中创建一个项目,该项目从模拟输入终端读取一个值并将其输出到 UART。我现在正尝试使用 GE Proficy Historian Compression 压缩数据,以便仅在 UART 中输出更改的数据。但是我的代码不起作用。输出的数据有时仍然是多余的。 该程序的思想是每隔一定时间产生一个中断,读取 adc 值,如果它与以前的值不同,则将其输出到 UART 端口。 该算法在这里解释 http://www.evsystems.net/files/GE_Historian_Compression_Overview.ppt 处理中断的主要代码部分如下所示

void ADC_IRQHandler(void)
{
    /* Clear dataready event */
  NRF_ADC->EVENTS_END = 0;   
    // write ADC value to UART port 

    // Compression Algorithm should occur here
    uint8_t current_Val= NRF_ADC->RESULT;
    //simple_uart_put(current_evaluation);


    // Construct error bands around the held point

    float U_tolerance = current_Val  + error_tolerance;
    float L_tolerance = current_Val - error_tolerance; // integer type is selected since lower tolerance could be negative

    if( first_Run == false)
    {
        float slope = ((current_Val - Archived_Val) / (held_Time - Archived_Time)) ;
        if (slope > U_Slope || slope > L_Slope)
        {
            Archived_Val = current_Val; // update the archived value
            held_Time = 1; // reset held time
            simple_uart_put(current_Val);
            first_Run = true;
            Archived_Val = current_Val;
        }
        else
        {
            float Upper_Slope = (U_tolerance - Archived_Val) /( held_Time - Archived_Time);
            float Lower_Slope  = (L_tolerance - Archived_Val)/(held_Time- Archived_Time);

            if(Upper_Slope < U_Slope) // lowest upper slope is always taken as a blanket boundry
            {
                U_Slope = Upper_Slope;
            }
            if(Lower_Slope < L_Slope)
            {
                L_Slope = Lower_Slope;
            }
            held_Time += time_increment;
        }
    }

    if (first_Run == true) // first held point always outputted
    {
            // calculate the slopes of the two lines 
    float Upper_Slope = (U_tolerance - Start_Up_Val) /( held_Time - Archived_Time);
    float Lower_Slope  = (L_tolerance - Start_Up_Val)/(held_Time- Archived_Time);

        // Update Max and Min slopes

    if(Upper_Slope < U_Slope) // lowest upper slope is always taken as a blanket boundry
    {
            U_Slope = Upper_Slope;
    }
    if(Lower_Slope < L_Slope)
    {
        L_Slope = Lower_Slope;
    }


    held_Time += time_increment;
    first_Run = false;
    Archived_Val = current_Val;
    }

}

变量定义如下

> uint32_t error_tolerance = 50; // error tolerance value for swining door algorithm
uint8_t Start_Up_Val = 100;
float held_Time = 1;
int Archived_Time = 0;
float U_Slope = 2500;
float L_Slope = 0;
//float slope;
uint8_t Archived_Val;
bool GE_Comp(uint8_t, uint8_t, uint8_t, int);
bool first_Run = true;
float time_increment = 0.1;

最佳答案

感谢大家的贡献,主要是对@Weather Vane 的贡献。正如您和其他人所建议的那样,中断处理程序正在执行过多的代码,这阻碍了它的正常运行。我现在通过按照建议将部分代码分散到主要功能来解决问题。 关注

关于c - C 中的简单压缩算法不起作用..有什么建议吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32028647/

相关文章:

c - 通过转换为 char* 并在 sprintf 中使用 "%s"来打印十六进制整数

android - 为什么用Bitmap.CompressFormat.JPEG压缩后图片颜色变了

android - 由于图像,应用程序体积较大。如何压缩 .PNG 图片?

c++ - 如何使用 fscanf 将任何字符读入字符串直到到达制表符?

c++ - 从 char 到 int 的转换做了一些奇怪的事情

c - BeagleBone Black UART 软件 FIFO 大小?

c - C启动代码是否改变数据地址

php - curl 命令返回 http/1.1 406 Not Acceptable 错误

c - 具有共享内存和信号量的多个灵活阵列成员或 VLA

c - 不被零除的浮点异常