• weeklog 10


    12.24~12.28

      周一。昨晚发现被窝里看手机,背光还是太亮,试着加一个level,当环境光线低于40,背光设为10。根据配置里的比例改kernel。其依据是配置里的config_autoBrightnessLevels发的身份,并将最亮背光的最低环境光要求设为40w,这是估算,今天线忘带,明天实际测下,看阳光下能到多少背光,再调整。

    配置有点怪异,第三级背光突然增加,外界环境光增速是2.5 4 2.5 3,对应背光增速是2.5 4 1.5 1.33 1.25

      //6 levels, depending on the config_autoBrightnessLcdBacklightValues in config.xml
        //and get 400000 as the minimum requirement of the max level
        if(lux >= 5334 && lux < 13333)
                lux = 8000;//1
            else if(lux >= 13333 && lux < 53333)
                lux = 16000;//2
            else if(lux >= 53333 && lux < 133333)
                lux = 30000;//3
            else if(lux >= 133333 && lux < 399999)
                lux = 100000;//12
                //<5334 -> 0; >=399999 -> lux/8000*100-20

    周二

    以下代码,若在//--------------------之后加上任何一个声明,如,char a;打印出的buffer立马出错!!

    原来是buffer需要初始化,把第19行改为char *buffer = malloc(1001);就好了。

    因为这个指针未初始化时,给它赋值,将把值赋给不确定的内存段

    #include <stdio.h>
    #include <fcntl.h>
    #include <locale.h>
    #include <string.h>
    #define FILE "shediao"

     
    int main(){
        setlocale(LC_ALL, "GBK");


        #ifdef FILE
            printf("defined, FILE = %s\n", FILE);
        #endif
        printf("over\n");
        //--------------------------------------------------------------
        int f1;
        int f2;
        char *buffer;
        f1 = open(FILE, O_RDONLY);
        if (f1<0)
            printf("open_error\n");
        read(f1, buffer, 1000);
        f2 = creat("shediao_fixed", 777);
        if(f2<0)
            printf("creat_error\n");
        write(f2, buffer, 1000);
     
        
        printf("%s, length:%ld\n", buffer, strlen(buffer));
        
        close(f2);
        close(f1);


        return 0;
    }

    GBK编码中一个汉字占3字节,而换行符等依然是1字节

    #include <stdio.h>
    #include <fcntl.h>
    #include <locale.h>
    #include <string.h>
    #include <stdlib.h>
    #define FILE "shediao"
    #define MYSIZE 1000
     
    int main(){
        setlocale(LC_ALL, "GBK");


        #ifdef FILE
            printf("defined, FILE = %s\n", FILE);
        #endif
        printf("over\n");
        //--------------------------------------------------------------
        int f1, f2, count = MYSIZE, presentence;
        char *pr1, *pr2;
        char *buffer = malloc(MYSIZE+1);
        f1 = open(FILE, O_RDONLY);
        if (f1<0){
            printf("open_error\n");
            return -1;
        }
        f2 = creat("shediao_fixed", 777);
        if(f2<0){
            printf("creat_error\n");
            return -1;
        }

        while(count == MYSIZE){
            char *temp = malloc(MYSIZE+1);
            count = read(f1, buffer, MYSIZE);
            if(count<0){
                printf("read error\n");
                return -1;
            }
            pr1 = buffer;
            pr2 = pr1;
            while(pr1 < buffer + MYSIZE){
                if(*pr1 == '\n'){
                    if(pr1 - pr2 >= 26*3){
                        strncat(temp, pr2, pr1-pr2);
                        //printf("\n26:%s,%ld,%ld,1-2=%d \n", temp, pr1,pr2,pr1-pr2);
                    }else if(pr1 - pr2 >= 24*3 && presentence <= 26){
                        strncat(temp, pr2, pr1-pr2);
                        //printf("\n24:%s,%ld,%ld,1-2=%d \n", temp, pr1,pr2,pr1-pr2);
                    }else{
                        strncat(temp, pr2, pr1-pr2+1);
                        //printf("\nelse:%s,%ld,%ld,1-2=%d \n", temp, pr1,pr2,pr1-pr2);
                    }
                    presentence = pr2 - pr1;
                    pr2 = pr1+1;
                }
                pr1++;
            }
            strncat(temp, pr2, pr1-pr2);
            //printf("all:1-2 =%d temp:%s,pr1:%ld, pr2:%ld, \n", pr1 - pr2, temp, pr1, pr2);
            if(write(f2, temp, count) < 0){
                printf("write error\n");
                return -1;
            }
            //printf("length = %ld, %s\n",strlen(temp), temp);
         }    
        
        
        close(f2);
        close(f1);


        return 0;
    }

    调试一下午,发现原因是write(f2, temp, count);count大于temp中含字符的大小,

    改为write(f2, temp, strlen(temp))。

    但这仍不是全部的错误!!

    41行,内层while的循环条件应该是pr1 < buffer + count,而不是MYMAX;

    因为count是read后的结果,将小于等于MYMAX,它的安全性更高。使用MYMAX的结果就是在最后一次外层循环中,读取的字节数将不足1000byte,此时若仍让pr1走1000次,将会在第58行strncat(temp, pr2, pr1-pr2);刷进未知的东西,然后导致最后文件读取不了,全是乱码。

    挖哈哈,哥的射雕英雄传格式终于正确,成就感油然而生,深藏功与名。

    最终版本:

    #include <stdio.h>
    #include <fcntl.h>
    #include <locale.h>
    #include <string.h>
    #include <stdlib.h>
    #define FILE "shediao"
    #define MYSIZE 1000
     
    int main(){
        setlocale(LC_ALL, "GBK");


        #ifdef FILE
            printf("defined, FILE = %s\n", FILE);
        #endif
        printf("over\n");
        //--------------------------------------------------------------
        int f1, f2, count = MYSIZE, presentence;
        char *pr1, *pr2;
        char *buffer = malloc(MYSIZE+1);
        f1 = open(FILE, O_RDONLY);
        if (f1<0){
            printf("open_error\n");
            return -1;
        }
        f2 = creat("shediao_fixed", 777);
        if(f2<0){
            printf("creat_error\n");
            return -1;
        }

        while(count == MYSIZE){
            char *temp = malloc(MYSIZE+1);
            count = read(f1, buffer, MYSIZE);
            if(count<0){
                printf("read error\n");
                return -1;
            }
            pr1 = buffer;
            pr2 = pr1;
            while(pr1 < buffer + count){
                if(*pr1 == '\n'){
                    if(pr1 - pr2 >= 26*3){
                        strncat(temp, pr2, pr1-pr2);
                        //printf("\n26:%s,%ld,%ld,1-2=%d \n", temp, pr1,pr2,pr1-pr2);
                    }else if(pr1 - pr2 >= 24*3 && presentence <= 26){
                        strncat(temp, pr2, pr1-pr2);
                        //printf("\n24:%s,%ld,%ld,1-2=%d \n", temp, pr1,pr2,pr1-pr2);
                    }else{
                        strncat(temp, pr2, pr1-pr2+1);
                        //printf("\nelse:%s,%ld,%ld,1-2=%d \n", temp, pr1,pr2,pr1-pr2);
                    }
                    presentence = pr2 - pr1;
                    pr2 = pr1+1;
                }
                pr1++;
            }
            strncat(temp, pr2, pr1-pr2);
            //printf("all:1-2 =%d temp:%s,pr1:%ld, pr2:%ld, \n", pr1 - pr2, temp, pr1, pr2);
            if(write(f2, temp, strlen(temp)) < 0){
                printf("write error\n");
                return -1;
            }
            //printf("length = %ld, %s\n",strlen(temp), temp);
         }    
        
        
        close(f2);
        close(f1);


        return 0;
    }

    更新了版本,新加入变量remain_buffer,即每次read后最后一行,这行的字节数将加入下一次read第一行是否要删‘\n’的判断条件。

    #include <stdio.h>
    #include <fcntl.h>
    #include <locale.h>
    #include <string.h>
    #include <stdlib.h>
    #define FILE "shediao"
    #define DEST_FILE "shediao_fixed"
    #define MYSIZE 1000
     
    int main(){
        setlocale(LC_ALL, "GBK");


        #ifdef FILE
            printf("defined, FILE = %s\n", FILE);
        #endif
        printf("over\n");
        //--------------------------------------------------------------
        int f1, f2, count = MYSIZE, presentence;
        char *pr1, *pr2;
        char *buffer = malloc(MYSIZE+1);
        signed int remain_buffer = 0;
        f1 = open(FILE, O_RDONLY);
        if (f1<0){
            printf("open_error\n");
            return -1;
        }
        f2 = creat(DEST_FILE, 777);
        if(f2<0){
            printf("creat_error\n");
            return -1;
        }

        while(count == MYSIZE){
            char *temp = malloc(MYSIZE+1);
            count = read(f1, buffer, MYSIZE);
            if(count<0){
                printf("read error\n");
                return -1;
            }
            pr1 = buffer;
            pr2 = pr1;
            while(pr1 < buffer + count){
                if(*pr1 == '\n'){
                    if(pr1 - pr2 >= 26*3 || (strlen(temp)==0 && pr1 - pr2 + remain_buffer >= 26*3) ){
                        strncat(temp, pr2, pr1-pr2);
                        //printf("\n26:%s,%ld,%ld,1-2=%d \n", temp, pr1,pr2,pr1-pr2);
                    }else if( (pr1 - pr2 >= 24*3 && presentence <= 26) || (strlen(temp)==0 && pr1 - pr2 + remain_buffer >= 24*3 && presentence <= 26 ) ){
                        strncat(temp, pr2, pr1-pr2);
                        //printf("\n24:%s,%ld,%ld,1-2=%d \n", temp, pr1,pr2,pr1-pr2);
                    }else{
                        strncat(temp, pr2, pr1-pr2+1);
                        //printf("\nelse:%s,%ld,%ld,1-2=%d \n", temp, pr1,pr2,pr1-pr2);
                    }
                    presentence = pr2 - pr1;
                    pr2 = pr1+1;
                }
                pr1++;
            }
            remain_buffer = pr1-pr2;
            strncat(temp, pr2, remain_buffer);
            //printf("all:1-2 =%d temp:%s,pr1:%ld, pr2:%ld, \n", pr1 - pr2, temp, pr1, pr2);
            if(write(f2, temp, strlen(temp)) < 0){
                printf("write error\n");
                return -1;
            }
            //printf("length = %ld, %s\n",strlen(temp), temp);
         }    
        
        
        close(f2);
        close(f1);


        return 0;
    }

    用抛异常的方法追踪调用者,提供者:Android驱动研究群,北京-Airk(qq:176951632)

    Log.d(LOG_TAG, "dyyr - print caller of updateProximitySensorMode");
            try {
                throw new Exception();
            } catch (Exception e) {
                e.printStackTrace();
            }//dyyr 出现的log头是System.err

    Psensor

    ailt,aiht,piht,pilt
    a:als a??? light sensor
    p:ps proximity sensor
    i:??
    h,l:high, low
    t:threshold

    编package/app的时候会出两个目标:

    Install: out/target/product/T20WG/system/app/Phone.apk

    Install: out/target/product/T20WG/data/app/PhoneAppTests.apk

    只用第一个就好,测试的那个没什么用

  • 相关阅读:
    java注解-笔记
    java重载与重写-笔记
    java中(equals与==)- 笔记
    Java迭代与递归-笔记
    C++指针悬挂-笔记
    极速倒入sql记录到excel表格,19个子段5万条记录只需30秒
    利用MCI的方法可以方便的实现光驱门的开关
    如何让你的程序在任务列表隐藏
    如何实现遍历文件夹中的所有文件
    识别操作系统版本
  • 原文地址:https://www.cnblogs.com/yiru/p/2830621.html
Copyright © 2020-2023  润新知