Subversion Repositories HomeAutomation

Rev

Rev 2143 | Rev 2199 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 2143 Rev 2198
Line 971... Line 971...
971
 * @param proto
971
 * @param proto
972
 *      Pointer to protocol information
972
 *      Pointer to protocol information
973
 * @return
973
 * @return
974
 *      IR_OK if data parsed successfully, one of several errormessages if not
974
 *      IR_OK if data parsed successfully, one of several errormessages if not
975
 */
975
 */
-
 
976
 
976
int8_t parseNexa2(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
977
int8_t parseNexa2(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
977
    /* parse buf[], max is len */
-
 
978
   
-
 
979
    /* check if we have correct amount of data */
978
    /* check if we have correct amount of data */
980
    if (len != 148 && len != 132) {
979
    if (len < 132) {
981
        return IR_NOT_CORRECT_DATA;
980
        return IR_NOT_CORRECT_DATA;
982
    }
981
    }
983
 
982
 
984
    if (buf[0] < IR_NEXA2_START1 - IR_NEXA2_START1/IR_NEXA2_TOL_DIV && buf[0] > IR_NEXA2_START1 + IR_NEXA2_START1/IR_NEXA2_TOL_DIV) { //check start bit
983
    if ((buf[len-132] < IR_NEXA2_START1 - IR_NEXA2_START1/IR_NEXA2_TOL_DIV) || (buf[len-132] > IR_NEXA2_START1 + IR_NEXA2_START1/IR_NEXA2_TOL_DIV)) { //check start bit
985
        return IR_NOT_CORRECT_DATA;
984
        return IR_NOT_CORRECT_DATA;
986
    }
985
    }
987
    if (buf[1] < IR_NEXA2_HIGH - IR_NEXA2_HIGH/IR_NEXA2_TOL_DIV && buf[1] > IR_NEXA2_HIGH + IR_NEXA2_HIGH/IR_NEXA2_TOL_DIV) { //check start bit
986
    if ((buf[len-131] < IR_NEXA2_HIGH - IR_NEXA2_HIGH/IR_NEXA2_TOL_DIV) || (buf[len-131] > IR_NEXA2_HIGH + IR_NEXA2_HIGH/IR_NEXA2_TOL_DIV)) { //check start bit
988
        return IR_NOT_CORRECT_DATA;
987
        return IR_NOT_CORRECT_DATA;
989
    }
988
    }
990
    if (buf[2] < IR_NEXA2_START2 - IR_NEXA2_START2/IR_NEXA2_TOL_DIV && buf[2] > IR_NEXA2_START2 + IR_NEXA2_START2/IR_NEXA2_TOL_DIV) { //check start bit
989
    if ((buf[len-130] < IR_NEXA2_START2 - IR_NEXA2_START2/IR_NEXA2_TOL_DIV) || (buf[len-130] > IR_NEXA2_START2 + IR_NEXA2_START2/IR_NEXA2_TOL_DIV)) { //check start bit
991
        return IR_NOT_CORRECT_DATA;
990
        return IR_NOT_CORRECT_DATA;
992
    }
991
    }
993
 
992
 
994
    /* Incoming data could actually be longer than 32bits when a dimming command is received */
993
    /* Incoming data could actually be longer than 32bits when a dimming command is received */
995
    uint64_t rawbitsTemp = 0;
994
    uint64_t rawbitsTemp = 0;
996
    uint8_t bitCounter = 0;
995
    uint8_t bitCounter = 0;
997
    for (uint8_t i = 3; i < len; i++) {
996
    for (uint8_t i = len-129; i < len; i++) {
998
        if ((i&1) == 0) {       /* if even, data */
997
        if ((i&1) == 0) {       /* if even, data */
999
            /* check length of transmit pulse */
998
            /* check length of transmit pulse */
1000
            if (buf[i] > IR_NEXA2_LOW_ONE - IR_NEXA2_LOW_ONE/IR_NEXA2_TOL_DIV && buf[i] < IR_NEXA2_LOW_ONE + IR_NEXA2_LOW_ONE/IR_NEXA2_TOL_DIV) {
999
            if (buf[i] > IR_NEXA2_LOW_ONE - IR_NEXA2_LOW_ONE/IR_NEXA2_TOL_DIV && buf[i] < IR_NEXA2_LOW_ONE + IR_NEXA2_LOW_ONE/IR_NEXA2_TOL_DIV) {
1001
                /* write a one */
1000
                /* write a one */
1002
                rawbitsTemp |= (1UL)<<(bitCounter++);
1001
                rawbitsTemp |= (1UL)<<(bitCounter++);
Line 1015... Line 1014...
1015
    }
1014
    }
1016
   
1015
   
1017
    proto->protocol=IR_PROTO_NEXA2;
1016
    proto->protocol=IR_PROTO_NEXA2;
1018
    proto->timeout=IR_NEXA2_TIMEOUT;
1017
    proto->timeout=IR_NEXA2_TIMEOUT;
1019
    proto->data=rawbitsTemp;
1018
    proto->data=rawbitsTemp;
-
 
1019
 
1020
    return IR_OK;
1020
    return IR_OK;
1021
}
1021
}
1022
 
1022
 
1023
#endif
1023
#endif
1024
 
1024
 
Line 1097... Line 1097...
1097
 
1097
 
1098
    /* check if we have correct amount of data */
1098
    /* check if we have correct amount of data */
1099
    if (len != 50) {
1099
    if (len != 50) {
1100
        return IR_NOT_CORRECT_DATA;
1100
        return IR_NOT_CORRECT_DATA;
1101
    }
1101
    }
1102
    if (buf[0] < IR_NEXA1_START - IR_NEXA1_START/IR_NEXA1_TOL_DIV && buf[0] > IR_NEXA1_START + IR_NEXA1_START/IR_NEXA1_TOL_DIV) { //check start bit
1102
    if (buf[0] < IR_NEXA1_START - IR_NEXA1_START/IR_NEXA1_TOL_DIV || buf[0] > IR_NEXA1_START + IR_NEXA1_START/IR_NEXA1_TOL_DIV) { //check start bit
1103
        return IR_NOT_CORRECT_DATA;
1103
        return IR_NOT_CORRECT_DATA;
1104
    }
1104
    }
1105
 
1105
 
1106
    uint32_t rawbitsTemp = 0;
1106
    uint32_t rawbitsTemp = 0;
1107
    uint8_t bitCounter = 0;
1107
    uint8_t bitCounter = 0;