int impulsCreateCode(JsonNode *code) { int systemcode = -1; int programcode = -1; int state = -1; int tmp; json_find_number(code, "systemcode", &systemcode); json_find_number(code, "programcode", &programcode); if(json_find_number(code, "off", &tmp) == 0) state=0; else if(json_find_number(code, "on", &tmp) == 0) state=1; if(systemcode == -1 || programcode == -1 || state == -1) { logprintf(LOG_ERR, "impuls: insufficient number of arguments"); return EXIT_FAILURE; } else if(systemcode > 31 || systemcode < 0) { logprintf(LOG_ERR, "impuls: invalid systemcode range"); return EXIT_FAILURE; } else if(programcode > 31 || programcode < 0) { logprintf(LOG_ERR, "impuls: invalid programcode range"); return EXIT_FAILURE; } else { impulsCreateMessage(systemcode, programcode, state); impulsClearCode(); impulsCreateSystemCode(systemcode); impulsCreateProgramCode(programcode); impulsCreateState(state); impulsCreateFooter(); } return EXIT_SUCCESS; }
void impulsParseCode(void) { int x = 0; int systemcode = binToDec(impuls->binary, 0, 4); int programcode = binToDec(impuls->binary, 5, 9); int check = impuls->binary[10]; int state = impuls->binary[11]; /* Convert the one's and zero's into binary */ for(x=0; x<(int)(double)impuls->rawlen; x+=4) { if(impuls->code[x+3] == 1 || impuls->code[x+0] == 1) { impuls->binary[x/4]=1; } else { impuls->binary[x/4]=0; } } if(check != state) { impulsCreateMessage(systemcode, programcode, state); } }