int __init emxx_pm_init(void) { int ret; printk(KERN_INFO "Power Management for EMXX.\n"); /* initialize static variable */ variable_init(); pm_idle = emxx_pm_idle; suspend_set_ops(&emxx_pm_ops); pm_loops_per_jiffy = loops_per_jiffy; ret = sysfs_create_file(power_kobj, &sleep_while_idle_attr.attr); if (ret) printk(KERN_ERR "subsys_create_file failed: %d\n", ret); #ifdef CONFIG_PROC_FS { struct proc_dir_entry *entry; entry = create_proc_read_entry("pm", S_IWUSR | S_IRUGO, NULL, emxx_pm_read_proc, 0); if (entry == NULL) return -ENOENT; entry->write_proc = (write_proc_t *)emxx_pm_write_proc; } #endif pm_power_off = emxx_pm_power_off; return 0; }
int main(int argc __attribute__((unused)), char *argv[]) { char *b; Prototype *pt; FuncRef fr; unitype_init(); UConvLoadDatabase("UniConvert"); variable_init(); pt=define_prototype(tlist[0], 1, 0, call_intref); define_function("UpdateVar", "", pt, (Function) updatevar); define_function("UpdateEdit", "", pt, (Function) updateedit); pt=define_prototype(tlist[1], 2, 0, call_strint); define_function("PrintInt", "", pt, (Function) printint); pt=define_prototype(tlist[0], 2, 0, call_intintref); fr = define_function("Assign", "", pt, (Function) assign); define_operator(OPASSIGN, fr); pt=define_prototype(tlist[2], 2, IntType, call_intintresint); fr = define_function("IntAdd", "", pt, (Function) intadd); define_operator(OPADD, fr); fr = define_function("IntMin", "", pt, (Function) intminus); define_operator(OPSUB, fr); fr = define_function("IntGreater", "", pt, (Function) intgreater); define_operator(OPGREATER, fr); fr = define_function("IntLess", "", pt, (Function) intless); define_operator(OPLESS, fr); pt=define_prototype(tlist[4], 1, 0, call_lazy); fr = define_function("LazyEval", "", pt, (Function) calculate_lazy_expression); pt=define_prototype(tlist[5], 2, 0, call_lazylazyref); fr = define_function("AssignLazyEval", "", pt, (Function) assign_lazy); define_operator(OPASSIGN, fr); b=malloc(sizeof(char)*(strlen(argv[1])+1)); strcpy(b,argv[1]); lex_open_file(b); parse_input(); return 0; }
int main (void) { set_micro(); NRF_init(); MS5611_reset(); MS5611_read_PROM(); SHT11_softreset(); variable_init(); TCD0_CNT=0; while (1) { while (TCD0_CNT!=0xF9FF); //10 ms timer lock. SHT11_measure(); MS5611_measure(); if (MS5611_dataflag) { NRF_Transmit(); MS5611_dataflag=0; } if (nrf_flag) //doroste inja? { PTX_IRQ(); nrf_flag=0; } //if (twi_flag) nashod //{ //TWI_MasterInterruptHandler(&twiMaster); //twi_flag=0; //} } }
//-------------------------------------------- int parse_json_file(void) { cJSON *root; cJSON *item; cJSON *node; cJSON *id; cJSON *type; cJSON *topic; cJSON *cond; cJSON *value; cJSON *nextid; cJSON *nextid_true; cJSON *nextid_false; cJSON *retain; cJSON *variable; int cnt; FILE *fp = NULL; long fsize; char *str; rf_type_t rf_type; fp = fopen(RULES_FILE, "rb"); if (fp == NULL) { dprintf("can't open %s file: %s\n", RULES_FILE, strerror(errno)); return -1; } fseek(fp, 0, SEEK_END); fsize = ftell(fp); str = malloc(fsize + 1); memset(str, 0, fsize); fseek(fp, 0, SEEK_SET); fread(str, fsize, 1, fp); str[fsize] = '\0'; fclose(fp); thread_mqtt_set_rules_topic_data(str, fsize); root = cJSON_Parse(str); free(str); if (root == NULL) { dprintf("wrong %s file\n", RULES_FILE); return -1; } item = cJSON_GetObjectItem(root, "version"); if (item == NULL || item->type != cJSON_String) goto error; if (check_version(item->valuestring) < 0) { dprintf("Rules file version is %s, must be less or equal %s\n", item->valuestring, RULES_VERSION); goto error; } item = cJSON_GetObjectItem(root, "nodes"); if (item == NULL) goto error; rf_type = RF_NONE; for (cnt = 0 ; cnt < cJSON_GetArraySize(item); cnt++) { node = cJSON_GetArrayItem(item, cnt); if (node == NULL) goto error; type = cJSON_GetObjectItem(node, "type"); if (type == NULL) goto error; if (strncmp(type->valuestring, RT_TRIGGER_CRON, sizeof(RT_TRIGGER_CRON) - 1) == 0) { value = cJSON_GetObjectItem(node, "value"); if (value == NULL || value->type != cJSON_String) goto error; nextid = cJSON_GetObjectItem(node, "nextid"); if (nextid == NULL || nextid->type != cJSON_Number) goto error; thread_cron_trigger_add(value->valuestring, (size_t)nextid->valueint); continue; } if (strncmp(type->valuestring, RT_TRIGGER_TOPIC, sizeof(RT_TRIGGER_TOPIC) - 1) == 0) { topic = cJSON_GetObjectItem(node, "topic"); if (topic == NULL || topic->type != cJSON_String) goto error; nextid = cJSON_GetObjectItem(node, "nextid"); if (nextid == NULL || nextid->type != cJSON_Number) goto error; thread_mqtt_trigger_add(topic->valuestring, (size_t)nextid->valueint); continue; } if (strncmp(type->valuestring, RT_VARIABLE_INIT, sizeof(RT_VARIABLE_INIT) - 1) == 0) { variable = cJSON_GetObjectItem(node, "variable"); if (variable == NULL || variable->type != cJSON_String) goto error; value = cJSON_GetObjectItem(node, "value"); if (value == NULL || value->type != cJSON_String) goto error; retain = cJSON_GetObjectItem(node, "retain"); if (retain == NULL || retain->type != cJSON_Number) goto error; variable_init(variable->valuestring, strlen(variable->valuestring), value->valuestring, strlen(value->valuestring), retain->valueint); continue; } if (strncmp(type->valuestring, RT_CONDITION_TOPIC_VALUE, sizeof(RT_CONDITION_TOPIC_VALUE) - 1) == 0) rf_type = RF_CONDITION_TOPIC_VALUE; else if (strncmp(type->valuestring, RT_CONDITION_TOPIC_TOPIC, sizeof(RT_CONDITION_TOPIC_TOPIC) - 1) == 0) rf_type = RF_CONDITION_TOPIC_TOPIC; else if (strncmp(type->valuestring, RT_CONDITION_TOPIC_VARIABLE, sizeof(RT_CONDITION_TOPIC_VARIABLE) - 1) == 0) rf_type = RF_CONDITION_TOPIC_VARIABLE; else if (strncmp(type->valuestring, RT_CONDITION_VARIABLE_VALUE, sizeof(RT_CONDITION_VARIABLE_VALUE) - 1) == 0) rf_type = RF_CONDITION_VARIABLE_VALUE; else if (strncmp(type->valuestring, RT_CONDITION_VARIABLE_VARIABLE, sizeof(RT_CONDITION_VARIABLE_VARIABLE) - 1) == 0) rf_type = RF_CONDITION_VARIABLE_VARIABLE; else if (strncmp(type->valuestring, RT_ACTION_VALUE, sizeof(RT_ACTION_VALUE) - 1) == 0) rf_type = RF_ACTION_VALUE; else if (strncmp(type->valuestring, RT_ACTION_TOPIC, sizeof(RT_ACTION_TOPIC) - 1) == 0) rf_type = RF_ACTION_TOPIC; else if (strncmp(type->valuestring, RT_ACTION_VARIABLE, sizeof(RT_ACTION_VARIABLE) - 1) == 0) rf_type = RF_ACTION_VARIABLE; else if (strncmp(type->valuestring, RT_VARIABLE_SET, sizeof(RT_VARIABLE_SET) - 1) == 0) rf_type = RF_VARIABLE_SET; else if (strncmp(type->valuestring, RT_VARIABLE_INCREMENT, sizeof(RT_VARIABLE_INCREMENT) - 1) == 0) rf_type = RF_VARIABLE_INCREMENT; else if (strncmp(type->valuestring, RT_VARIABLE_DECREMENT, sizeof(RT_VARIABLE_DECREMENT) - 1) == 0) rf_type = RF_VARIABLE_DECREMENT; if (rf_type == RF_CONDITION_TOPIC_VALUE || rf_type == RF_CONDITION_TOPIC_TOPIC || rf_type == RF_CONDITION_TOPIC_VARIABLE || rf_type == RF_CONDITION_VARIABLE_VALUE || rf_type == RF_CONDITION_VARIABLE_VARIABLE) { rf_condition_param_t *rfp; id = cJSON_GetObjectItem(node, "id"); if (id == NULL || id->type != cJSON_Number) goto error; if (rf_type == RF_CONDITION_TOPIC_VALUE || rf_type == RF_CONDITION_TOPIC_TOPIC || rf_type == RF_CONDITION_TOPIC_VARIABLE) topic = cJSON_GetObjectItem(node, "topic"); else if (rf_type == RF_CONDITION_VARIABLE_VALUE || rf_type == RF_CONDITION_VARIABLE_VARIABLE) topic = cJSON_GetObjectItem(node, "variable"); if (topic == NULL || topic->type != cJSON_String) goto error; cond = cJSON_GetObjectItem(node, "condition"); if (cond == NULL || cond->type != cJSON_String) goto error; if (rf_type == RF_CONDITION_TOPIC_VALUE || rf_type == RF_CONDITION_VARIABLE_VALUE) value = cJSON_GetObjectItem(node, "value"); else if (rf_type == RF_CONDITION_TOPIC_TOPIC) value = cJSON_GetObjectItem(node, "value-topic"); else if (rf_type == RF_CONDITION_TOPIC_VARIABLE || rf_type == RF_CONDITION_VARIABLE_VARIABLE) value = cJSON_GetObjectItem(node, "value-variable"); if (value == NULL || topic->type != cJSON_String) goto error; nextid_true = cJSON_GetObjectItem(node, "nextid-true"); if (nextid_true == NULL || nextid->type != cJSON_Number) goto error; nextid_false = cJSON_GetObjectItem(node, "nextid-false"); if (nextid_false == NULL || nextid->type != cJSON_Number) goto error; rfp = (rf_condition_param_t *)malloc(sizeof(rf_condition_param_t)); memset(rfp, 0, sizeof(rf_condition_param_t)); rfp->nextid_true = nextid_true->valueint; rfp->nextid_false = nextid_false->valueint; rfp->condition = (char *)malloc(strlen(cond->valuestring) + 1); strcpy(rfp->condition, cond->valuestring); if (rf_type == RF_CONDITION_TOPIC_VARIABLE || rf_type == RF_CONDITION_VARIABLE_VARIABLE) get_variable_topic(value->valuestring, strlen(value->valuestring), &rfp->str, &rfp->str_len); else { rfp->str_len = (uint16_t)strlen(value->valuestring); rfp->str = (uint8_t *)malloc(rfp->str_len); memcpy(rfp->str, value->valuestring, rfp->str_len); } if (rf_type == RF_CONDITION_VARIABLE_VALUE || rf_type == RF_CONDITION_VARIABLE_VARIABLE) get_variable_topic(topic->valuestring, strlen(topic->valuestring), &rfp->name, &rfp->name_len); else { rfp->name_len = (uint16_t)strlen(topic->valuestring); rfp->name = (uint8_t *)malloc(rfp->name_len); memcpy(rfp->name, topic->valuestring, rfp->name_len); } thread_rules_add_node(id->valueint, rf_type, (void *)rfp); continue; } if (rf_type == RF_ACTION_VALUE || rf_type == RF_ACTION_TOPIC || rf_type == RF_ACTION_VARIABLE) { rf_action_param_t *rfp; id = cJSON_GetObjectItem(node, "id"); if (id == NULL || id->type != cJSON_Number) goto error; topic = cJSON_GetObjectItem(node, "topic"); if (topic == NULL || topic->type != cJSON_String) goto error; if (rf_type == RF_ACTION_VALUE) value = cJSON_GetObjectItem(node, "value"); else if (rf_type == RF_ACTION_TOPIC) value = cJSON_GetObjectItem(node, "value-topic"); else if (rf_type == RF_ACTION_VARIABLE) value = cJSON_GetObjectItem(node, "value-variable"); if (value == NULL || value->type != cJSON_String) goto error; nextid = cJSON_GetObjectItem(node, "nextid"); if (nextid == NULL || nextid->type != cJSON_Number) goto error; retain = cJSON_GetObjectItem(node, "retain"); if (retain == NULL || retain->type != cJSON_Number) goto error; rfp = (rf_action_param_t *)malloc(sizeof(rf_action_param_t)); memset(rfp, 0, sizeof(rf_action_param_t)); rfp->nextid = nextid->valueint; rfp->retain = retain->valueint; if (rf_type == RF_ACTION_VARIABLE) get_variable_topic(value->valuestring, strlen(value->valuestring), &rfp->str, &rfp->str_len); else { rfp->str_len = (uint16_t)strlen(value->valuestring); rfp->str = (uint8_t *)malloc(rfp->str_len); memcpy(rfp->str, value->valuestring, rfp->str_len); } rfp->name_len = (uint16_t)strlen(topic->valuestring); rfp->name = (uint8_t *)malloc(rfp->name_len); memcpy(rfp->name, topic->valuestring, rfp->name_len); thread_rules_add_node(id->valueint, rf_type, (void *)rfp); continue; } if (rf_type == RF_VARIABLE_SET || rf_type == RF_VARIABLE_INCREMENT || rf_type == RF_VARIABLE_DECREMENT) { rf_variable_param_t *rfp; id = cJSON_GetObjectItem(node, "id"); if (id == NULL || id->type != cJSON_Number) goto error; variable = cJSON_GetObjectItem(node, "variable"); if (variable == NULL || variable->type != cJSON_String) goto error; if (rf_type == RF_VARIABLE_SET) { value = cJSON_GetObjectItem(node, "value"); if (value == NULL || value->type != cJSON_String) goto error; } nextid = cJSON_GetObjectItem(node, "nextid"); if (nextid == NULL || nextid->type != cJSON_Number) goto error; retain = cJSON_GetObjectItem(node, "retain"); if (retain == NULL || retain->type != cJSON_Number) goto error; rfp = (rf_variable_param_t *)malloc(sizeof(rf_variable_param_t)); memset(rfp, 0, sizeof(rf_variable_param_t)); get_variable_topic(variable->valuestring, strlen(variable->valuestring), &rfp->name, &rfp->name_len); rfp->nextid = nextid->valueint; rfp->retain = retain->valueint; if (rf_type == RF_VARIABLE_SET) { rfp->str_len = (uint16_t)strlen(value->valuestring); rfp->str = (uint8_t *)malloc(rfp->str_len); memcpy(rfp->str, value->valuestring, rfp->str_len); } thread_rules_add_node(id->valueint, rf_type, (void *)rfp); continue; } } cJSON_Delete(root); return 0; error: cJSON_Delete(root); thread_cron_remove_all(); thread_mqtt_trigger_remove_all(); thread_rules_remove_all(); dprintf("Corrupted or wrong %s rules file\n", RULES_FILE); return -1; }