void PLUGIN_CA_TEST_CMD(void) { printf_cmd_main(); while(1) { usleep(10); int c = getchar(); if(isdigit(c) || c=='\n') { printf("c=%c\n", c); } else continue; ca_menu: switch(c) { case '0' : { while(1) { int c1 = getchar(); ca_errorcode_menu: switch(c1) { case '0' : { display_errorcode_auto(); } break; case '1' : { char str[256] = {0}; while(1) { memset(str, 0, sizeof(str)); printf_cmd_errorcode_manul(); while(!fgets(str, sizeof(str)-1, stdin)) usleep(10); printf("str1=%s\n", str); char* tmp=strchr(str, '\n'); *tmp = '\0'; if(!strncmp(str, "exit", strlen("exit"))) { c1 = '\n'; goto ca_errorcode_menu; } else if(!strncmp(str, "display", strlen("dispaly"))) { char* msg = strchr(str, ':'); #if(test_debug) if(msg) printf("dis msg=%s\n", msg);//PLUGIN_CA_Event_Report(EVENT_PLUGIN_CA_BUYMESSGE_DISPLAY, msg, strlen(msg) + 1); #else msg++;//skip ':' if(msg) PLUGIN_CA_Event_Report(EVENT_PLUGIN_CA_BUYMESSGE_DISPLAY, msg, strlen(msg) + 1); #endif } else if(!strncmp(str, "hide", strlen("hide"))) { char* msg = strchr(str, ':'); #if(test_debug) if(msg) printf("hide msg=%s\n", msg);//PLUGIN_CA_Event_Report(EVENT_PLUGIN_CA_BUYMESSGE_HIDE, msg, strlen(msg) + 1); #else msg++;//skip ':' if(msg) PLUGIN_CA_Event_Report(EVENT_PLUGIN_CA_BUYMESSGE_HIDE, msg, strlen(msg) + 1); #endif } else { //do nothing } usleep(10); } } break; case '2' : { hide_errorcode_auto(); } break; case '3' : { c = '\n'; goto ca_menu; } break; case '\n' : { printf_cmd_errorcode(); } break; default : break; } usleep(10); } } break; case '1' : { while(1) { char str[1024] = {0}; while(1) { memset(str, 0, sizeof(str)); printf_cmd_osd(); while(!fgets(str, sizeof(str)-1, stdin)) usleep(10); printf("str=%s\n", str); char* tmp=strchr(str, '\n'); *tmp = '\0'; if(!strncmp(str, "exit", strlen("exit"))) { c = '\n'; goto ca_menu; } else if(!strncmp(str, "display", strlen("dispaly"))) { char* msg = strchr(str, ':'); #if(test_debug) if(msg) printf("dis msg=%s\n", msg);//PLUGIN_CA_Event_Report(EVENT_PLUGIN_CA_BUYMESSGE_DISPLAY, msg, strlen(msg) + 1); #else msg++;//skip ':' if(msg) PLUGIN_CA_Event_Report(EVENT_PLUGIN_CA_OSD_DISPLAY, msg, strlen(msg) + 1); #endif } else if(!strncmp(str, "hide", strlen("hide"))) { char* msg = strchr(str, ':'); #if(test_debug) if(msg) printf("hide msg=%s\n", msg);//PLUGIN_CA_Event_Report(EVENT_PLUGIN_CA_BUYMESSGE_HIDE, msg, strlen(msg) + 1); #else msg++;//skip ':' if(msg) PLUGIN_CA_Event_Report(EVENT_PLUGIN_CA_OSD_HIDE, msg, strlen(msg) + 1); #endif } else { //do nothing } usleep(10); } } } break; case '2' : { char str[1024] = {0}; while(1) { memset(str, 0, sizeof(str)); printf_cmd_finger(); while(!fgets(str, sizeof(str)-1, stdin)) usleep(10); printf("str=%s\n", str); char* tmp=strchr(str, '\n'); *tmp = '\0'; if(!strncmp(str, "exit", strlen("exit"))) { c = '\n'; goto ca_menu; } else if(!strncmp(str, "display", strlen("dispaly"))) { char* msg = strchr(str, ':'); #if(test_debug) if(msg) printf("dis msg=%s\n", msg);//PLUGIN_CA_Event_Report(EVENT_PLUGIN_CA_BUYMESSGE_DISPLAY, msg, strlen(msg) + 1); #else msg++;//skip ':' if(msg) PLUGIN_CA_Event_Report(EVENT_PLUGIN_CA_FINGER_DISPLAY, msg, strlen(msg) + 1); #endif } else if(!strncmp(str, "hide", strlen("hide"))) { char* msg = strchr(str, ':'); #if(test_debug) if(msg) printf("hide msg=%s\n", msg);//PLUGIN_CA_Event_Report(EVENT_PLUGIN_CA_BUYMESSGE_HIDE, msg, strlen(msg) + 1); #else msg++;//skip ':' if(msg) PLUGIN_CA_Event_Report(EVENT_PLUGIN_CA_FINGER_HIDE, msg, strlen(msg) + 1); #endif } else { //do nothing } usleep(10); } } break; case '3' : { while(1) { int c1 = getchar(); switch(c1) { case '0' : { sc_upgrade_receiving(); } break; case '1' : { sc_upgrade_patching(); } break; case '2' : { c = '\n'; goto ca_menu; } break; case '\n' : { printf_cmd_scupgrade(); } break; default : break; } usleep(10); } } break; case '4' : { while(1) { int c1 = getchar(); switch(c1) { case '0' : { email_process(0); } break; case '1' : { email_process(1); } break; case '2' : { email_process(2); } break; case '3' : { c = '\n'; goto ca_menu; } break; case '\n' : { printf_cmd_email(); } break; default : break; } usleep(10); } } break; case '5' : { while(1) { int c1 = getchar(); switch(c1) { case '0' : { action_process(0); } break; case '1' : { action_process(1); } break; case '2' : { action_process(2); } break; case '3' : { action_process(3); } break; case '4' : { action_process(4); } break; case '5' : { action_process(5); } break; case '6' : { action_process(6); } break; case '7' : { c = '\n'; goto ca_menu; } break; case '\n' : { printf_cmd_action(); } break; default : break; } usleep(10); } } break; case '6' : { while(1) { int c1 = getchar(); switch(c1) { case '0' : { curtain_process(0); } break; case '1' : { curtain_process(1); } break; case '2' : { curtain_process(2); } break; case '3' : { c = '\n'; goto ca_menu; } break; case '\n' : { printf_cmd_curtain(); } break; default : break; } usleep(10); } } break; case '7' : { char str[1024] = {0}; while(1) { memset(str, 0, sizeof(str)); printf_cmd_servicelock(); while(!fgets(str, sizeof(str)-1, stdin)) usleep(10); printf("str=%s\n", str); char* tmp=strchr(str, '\n'); *tmp = '\0'; if(!strncmp(str, "exit", strlen("exit"))) { c = '\n'; goto ca_menu; } else if(!strncmp(str, "lock", strlen("lock"))) { char* msg = strchr(str, ':'); #if(test_debug) if(msg) printf("lock msg=%s\n", msg);//PLUGIN_CA_Event_Report(EVENT_PLUGIN_CA_BUYMESSGE_DISPLAY, msg, strlen(msg) + 1); #else msg++;//skip ':' if(msg) iSTB_API_Event_Report(EVENT_PLUGIN_CA_SERVICE_LOCK, msg, strlen(msg) + 1); #endif } else if(!strncmp(str, "unlock", strlen("unlock"))) { char* msg = strchr(str, ':'); #if(test_debug) if(msg) printf("unlock msg=%s\n", msg);//PLUGIN_CA_Event_Report(EVENT_PLUGIN_CA_BUYMESSGE_HIDE, msg, strlen(msg) + 1); #else msg++;//skip ':' if(msg) iSTB_API_Event_Report(EVENT_PLUGIN_CA_SERVICE_UNLOCK, msg, strlen(msg) + 1); #endif } else { //do nothing } usleep(10); } } break; case '\n' : { printf_cmd_main(); } break; default : break; } } }
int main(void) { // Alles TriState DDRA = 0; DDRB = 0; DDRC = 0; DDRD = 0; PORTA = 0; PORTB = 0; PORTC = 0; PORTD = 0; // save power MCUCR |= _BV(JTD); PRR |= _BV(PRTWI) | _BV(PRSPI) | _BV(PRADC); //ADCSRA &= ~_BV(ADEN); //ACSR |=_BV(ACD); // Power Led DDRA|=_BV(7); PIN_SET(A,7); sei(); // Init: Subsysteme uart_init(UART_BAUD_SELECT(BAUD,F_CPU)); stella_init(); // curtain_init(); //sensors_init(); // Init: Variablen enum stateEnum { StateCommands, StateCurtainValue, StateLedChannel, StateLedValue } laststate, state = StateCommands; uint8_t slowdown_counter = 0; uint8_t slowdown_counter2 = 0; uint8_t panic_counter = 0; uint8_t panic_counter_led = 0; uint8_t panic_counter_brightness = 0; uint8_t stella_channel = 0; enum stella_set_function stella_fading = STELLA_SET_IMMEDIATELY; uint8_t packetPosition = 0; unsigned char lastChar, haslastChar = 0; slowdown_counter = 0; slowdown_counter2 = 0; stella_setValue(STELLA_SET_IMMEDIATELY, 0, 0); stella_process(); wdt_enable(WDTO_250MS); #define PANIC_THRESHOLD 150 // Hauptprogramm while (1) { wdt_reset(); stella_process(); curtain_process(); //sensors_process(); //panic counter if (++slowdown_counter == 0) { if (++slowdown_counter2==0) { if (panic_counter < PANIC_THRESHOLD) ++panic_counter; } if (panic_counter == PANIC_THRESHOLD) { panic_counter = PANIC_THRESHOLD+1; panic_counter_led = 0; panic_counter_brightness = 0; packetPosition = 0; storeValues(); PIN_SET(A,6); } if (panic_counter == PANIC_THRESHOLD+1) { if (panic_counter_brightness==255) { panic_counter=PANIC_THRESHOLD+2; continue; } stella_setValue(STELLA_SET_FADE, panic_counter_led, ++panic_counter_brightness); } if (panic_counter == PANIC_THRESHOLD+2) { if (panic_counter_brightness==0) { panic_counter=PANIC_THRESHOLD+1; if (++panic_counter_led >= STELLA_CHANNELS) panic_counter_led = 0; continue; } stella_setValue(STELLA_SET_FADE, panic_counter_led, --panic_counter_brightness); } } uint16_t r = uart_getc(); uint8_t info = r >> 8; if (r == UART_NO_DATA) continue; else if (info!=0) { PIN_SET(A,6); PIN_SET(A,7); packetPosition = 0; continue; } const unsigned char temp = haslastChar ? lastChar : 0; haslastChar = 1; lastChar = r & 0xff; if (lastChar == 0xff && temp == 0xff) { // two proceeding 255-values start a valid packet packetPosition = 1; state = StateCommands; continue; } if (!packetPosition) continue; // reset panic counter if (panic_counter) { if (panic_counter>=110) { restoreValues(); PIN_CLEAR(A,6); } panic_counter = 0; } laststate = state; switch (state) { case StateCommands: switch (lastChar) { case 0xef: // get values sendInit(); sendStella(); //sendSensor(); sendMotor(); break; case 0xdf: // prepare for a curtain value state = StateCurtainValue; break; case 0xcf: // prepare for a led channel and value (fade:immediately) state = StateLedChannel; stella_fading = STELLA_SET_IMMEDIATELY; break; case 0xbf: // prepare for a led channel and value (fade:fade) state = StateLedChannel; stella_fading = STELLA_SET_FADE; break; case 0xaf: // prepare for a led channel and value (fade:fade flashy) state = StateLedChannel; stella_fading = STELLA_SET_FLASHY; break; case 0x9f: // prepare for a led channel and value (fade:fade immediately+relative) state = StateLedChannel; stella_fading = STELLA_SET_IMMEDIATELY_RELATIVE; break; case 0x00: // reset panic counter and acknowdlegde sendAck(); break; } break; case StateCurtainValue: state = StateCommands; curtain_setPosition(lastChar); break; case StateLedChannel: state = StateLedValue; stella_channel = lastChar; break; case StateLedValue: state = StateCommands; stella_setValue(stella_fading, stella_channel, lastChar); break; } // the state has not changed -> a full packet has been received -> prepare for the next one if (laststate==state) { packetPosition=0; } } return 0; }