/*---------------------------------------------------------------------------*/ static PT_THREAD(handle_output(struct httpd_state *s)) { PT_BEGIN(&s->outputpt); char *ptr; if(!httpd_fs_open(s->filename, &s->file)) { httpd_fs_open(http_404_html, &s->file); strcpy_P(s->filename, http_404_html); PT_WAIT_THREAD(&s->outputpt, send_headers(s, http_header_404)); PT_WAIT_THREAD(&s->outputpt, send_file(s)); } else { snprintf(s->tmp_str, sizeof(s->tmp_str) -1, "%d", s->file.len); //snprintf(s->str_tmp, 8, "%d", s->len); PT_WAIT_THREAD(&s->outputpt, send_headers(s, http_header_200)); ptr = strchr(s->filename, ISO_period); if(ptr != NULL && strncmp_P(ptr, http_shtml, 6) == 0) { PT_INIT(&s->scriptpt); PT_WAIT_THREAD(&s->outputpt, handle_script(s)); } else { PT_WAIT_THREAD(&s->outputpt, send_file(s)); } } PSOCK_CLOSE(&s->sout); PT_END(&s->outputpt); }
static PT_THREAD(handle_output(struct httpd_state *s)) { char *ptr; PT_BEGIN(&s->outputpt); #if DEBUGLOGIC httpd_strcpy(s->filename,httpd_indexfn); #endif if(!httpd_fs_open(s->filename, &s->file)) { httpd_strcpy(s->filename, httpd_404fn); httpd_fs_open(s->filename, &s->file); PT_WAIT_THREAD(&s->outputpt, send_headers(s, httpd_404notf)); PT_WAIT_THREAD(&s->outputpt, send_file(s)); } else { PT_WAIT_THREAD(&s->outputpt, send_headers(s, httpd_200ok)); ptr = strchr(s->filename, ISO_period); if((ptr != NULL && httpd_strncmp(ptr, httpd_shtml, 6) == 0) || httpd_strcmp(s->filename,httpd_indexfn)==0) { PT_INIT(&s->scriptpt); PT_WAIT_THREAD(&s->outputpt, handle_script(s)); } else { PT_WAIT_THREAD(&s->outputpt, send_file(s)); } } PSOCK_CLOSE(&s->sout); PT_END(&s->outputpt); }
/*---------------------------------------------------------------------------*/ static PT_THREAD(handle_script(struct httpd_state *s)) { char *ptr; PT_BEGIN(&s->scriptpt); while(s->file.len > 0) { /* Check if we should start executing a script. */ if(*s->file.data == ISO_percent && *(s->file.data + 1) == ISO_bang) { s->scriptptr = s->file.data + 3; s->scriptlen = s->file.len - 3; if(*(s->scriptptr - 1) == ISO_colon) { httpd_fs_open(s->scriptptr + 1, &s->file); PT_WAIT_THREAD(&s->scriptpt, send_file(s)); } else { // Httpd_cgi is called here PT_WAIT_THREAD(&s->scriptpt, httpd_cgi(s->scriptptr)(s, s->scriptptr)); } next_scriptstate(s); /* The script is over, so we reset the pointers and continue sending the rest of the file. */ s->file.data = s->scriptptr; s->file.len = s->scriptlen; } else { /* See if we find the start of script marker in the block of HTML to be sent. */ if(s->file.len > uip_mss()) { s->len = uip_mss(); } else { s->len = s->file.len; } if(*s->file.data == ISO_percent) { ptr = strchr(s->file.data + 1, ISO_percent); } else { ptr = strchr(s->file.data, ISO_percent); } if(ptr != NULL && ptr != s->file.data) { s->len = (int)(ptr - s->file.data); if(s->len >= uip_mss()) { s->len = uip_mss(); } } PT_WAIT_THREAD(&s->scriptpt, send_part_of_file(s)); s->file.data += s->len; s->file.len -= s->len; } } PT_END(&s->scriptpt); }
int DLGSM::PT_SMS_send(struct pt *pt, char *ret, char *nr, char *text, int len) { static struct pt child_pt; uint8_t c = 0, r = 0; PT_BEGIN(pt); c = 0; while (c == 0) { get_from_flash(&(sms_string_table[0]), _gsm_buff); PT_WAIT_THREAD(pt, PT_send_recv_confirm(&child_pt, ret, _gsm_buff, "OK", 1000)); c = *ret; } get_from_flash(&(sms_string_table[1]), _gsm_buff); PT_WAIT_THREAD(pt, PT_send_recv_confirm(&child_pt, ret, _gsm_buff, "OK", 3000)); _gsm_wline = 1; c = 0; while (c != 1) { get_from_flash(&(sms_string_table[2]), _gsm_buff); strcat(_gsm_buff, nr); strcat(_gsm_buff, "\"\r\n"); PT_WAIT_THREAD(pt, PT_send_recv_confirm(&child_pt, ret, _gsm_buff, ">", 3000)); c = *ret; } _gsm_wline = 0; GSM_send(text, len); PT_WAIT_THREAD(pt, PT_SMS_send_end(&child_pt)); PT_END(pt); }
/*---------------------------------------------------------------------------*/ static PT_THREAD(handle_output(struct httpd_state *s)) { PT_BEGIN(&s->outputpt); petsciiconv_topetscii(s->filename, sizeof(s->filename)); s->fd = cfs_open(s->filename, CFS_READ); petsciiconv_toascii(s->filename, sizeof(s->filename)); if(s->fd < 0) { strcpy(s->filename, "notfound.html"); s->fd = cfs_open(s->filename, CFS_READ); petsciiconv_toascii(s->filename, sizeof(s->filename)); if(s->fd < 0) { PT_WAIT_THREAD(&s->outputpt, send_headers(s, http_header_404)); PT_WAIT_THREAD(&s->outputpt, send_string(s, "not found")); uip_close(); webserver_log_file(&uip_conn->ripaddr, "404 (no notfound.html)"); PT_EXIT(&s->outputpt); } PT_WAIT_THREAD(&s->outputpt, send_headers(s, http_header_404)); webserver_log_file(&uip_conn->ripaddr, "404 - notfound.html"); } else { PT_WAIT_THREAD(&s->outputpt, send_headers(s, http_header_200)); } PT_WAIT_THREAD(&s->outputpt, send_file(s)); cfs_close(s->fd); s->fd = -1; PSOCK_CLOSE(&s->sout); PT_END(&s->outputpt); }
/*---------------------------------------------------------------------------*/ static PT_THREAD(handle_output(struct httpd_state *s)) { PT_BEGIN(&s->outputpt); s->fd = cfs_open(s->filename, CFS_READ); if(s->fd < 0) { s->fd = cfs_open("404.html", CFS_READ); if(s->fd < 0) { uip_abort(); PT_EXIT(&s->outputpt); } PT_WAIT_THREAD(&s->outputpt, send_headers(s, "HTTP/1.0 404 Not found\r\n")); PT_WAIT_THREAD(&s->outputpt, send_file(s)); } else { PT_WAIT_THREAD(&s->outputpt, send_headers(s, "HTTP/1.0 200 OK\r\n")); PT_WAIT_THREAD(&s->outputpt, send_file(s)); cfs_close(s->fd); } PSOCK_CLOSE(&s->sout); PT_END(&s->outputpt); }
int DLGSM::PT_SMS_check(struct pt *pt, char *ret) { static struct pt child_pt; static uint32_t sms_count; static char iret; PT_BEGIN(pt); curr_sms.index = 0; curr_sms.got_message = 0; get_from_flash(&(sms_string_table[6]), _gsm_buff); GSM_set_callback(GSM_process_SMS_list); PT_WAIT_THREAD(pt, PT_send_recv_confirm(&child_pt, &iret, _gsm_buff, "OK", 5000)); iret = 0; GSM_set_callback(NULL); if (curr_sms.index) { PT_WAIT_THREAD(pt, PT_SMS_process(&child_pt, &iret, &curr_sms)); PT_WAIT_THREAD(pt, PT_SMS_delete(&child_pt, curr_sms.index)); } *ret = iret; PT_END(pt); }
int DLGSM::PT_GPRS_connect(struct pt *pt, char *ret, char *server, short port, bool proto) { char r = 0; char shortbuff[100]; static struct pt child_pt; PT_BEGIN(pt); if (CONN_get_flag(CONN_CONNECTED)) { if (CONN_get_flag(CONN_SENDING)) PT_WAIT_THREAD(pt, PT_GPRS_send_end(&child_pt, &r)); PT_WAIT_THREAD(pt, PT_GPRS_close(&child_pt, &r)); } if (proto) get_from_flash(&(gsm_string_table[1]), _gsm_buff); else get_from_flash(&(gsm_string_table[2]), _gsm_buff); sprintf(shortbuff, "%s\",\"%d\"\r\n", server, port); strcat(_gsm_buff, shortbuff); PT_WAIT_THREAD(pt, PT_send_recv_confirm(&child_pt, &r, _gsm_buff, "CONNECT", 30000)); if (r != 1) { PT_EXIT(pt); } PT_WAIT_THREAD(pt, PT_GPRS_check_conn_state(&child_pt, &r)); if (r == GPRSS_CONNECT_OK) *ret = 1; else *ret = 0; PT_END(pt); }
int DLGSM::PT_restart(struct pt *pt, char *ret) { static struct pt child_pt; static uint32_t timestamp; static char u; char iret; PT_BEGIN(pt); u = 0; while (u < 3) { _gsmserial.flush(); PT_WAIT_THREAD(pt, PT_send_recv_confirm(&child_pt, &iret, "AT\r\n", "OK", 1000)); if (iret > 0) { PT_WAIT_THREAD(pt, PT_pwr_off(&child_pt, 1)); u = 3; } else { PT_WAIT_UNTIL(pt, (millis() - timestamp > 1000)); timestamp = millis(); u++; if (_DEBUG) Serial.println(u, DEC); } } timestamp = millis(); if (iret == 1) PT_WAIT_THREAD(pt, PT_pwr_off(&child_pt, 0)); PT_WAIT_UNTIL(pt, (millis() - timestamp) > 6000); PT_WAIT_THREAD(pt, PT_pwr_on(&child_pt)); PT_WAIT_THREAD(pt, PT_GSM_init(&child_pt, ret)); _error_cnt = 0; _tout_cnt = 0; u = 0; *ret = 1; PT_END(pt); }
/*---------------------------------------------------------------------------*/ static PT_THREAD(handle_output(struct httpd_state *s)) { char *ptr; PT_BEGIN(&s->outputpt); if(!httpd_fs_open(s->filename, &s->file)) { httpd_fs_open(http_404_html, &s->file); strcpy(s->filename, http_404_html); PT_WAIT_THREAD(&s->outputpt, send_headers(s, http_header_404)); PT_WAIT_THREAD(&s->outputpt, send_file(s)); } else { PT_WAIT_THREAD(&s->outputpt, send_headers(s, http_header_200)); ptr = strchr(s->filename, ISO_period); if(ptr != NULL && strncmp(ptr, http_shtml, 6) == 0) { PT_INIT(&s->scriptpt); PT_WAIT_THREAD(&s->outputpt, handle_script(s)); } else { PT_WAIT_THREAD(&s->outputpt, send_file(s)); } } PSOCK_CLOSE(&s->sout); PT_END(&s->outputpt); }
int DLGSM::PT_GPRS_init(struct pt *pt, char *ret) { static uint8_t len; static struct pt child_pt; static char k; PT_BEGIN(pt); //if (!CONN_get_flag(CONN_NETWORK)) // len = GPRS_INIT_NONTWR_LEN; //else len = GPRS_INIT_LEN; k = 0; while (k < len) { if (k == GPRS_INIT_ATTACH_CMD) GSM_set_timeout(50); *ret = 0; get_from_flash(&(gprs_init_string_table[k]), _gsm_buff); if (k != (len-1)) { PT_WAIT_THREAD(pt, PT_send_recv_confirm(&child_pt, ret, _gsm_buff, "OK", 30000)); } else { PT_WAIT_THREAD(pt, PT_send_recv(&child_pt, ret, _gsm_buff, 10000)); } if (*ret > 0) k++; else { if (_tout_cnt > 10) { DEBUG_LOG("GPRS restart"); PT_WAIT_THREAD(pt, PT_restart(&child_pt, ret)); _tout_cnt = 0; } } if (k == GPRS_INIT_ATTACH_CMD) GSM_set_timeout(25); } GSM_set_timeout(10); PT_END(pt); }
static PT_THREAD(handle_output(struct httpd_state *s)) { PT_BEGIN(&s->outputpt); s->script = NULL; s->script = httpd_simple_get_script(&s->filename[1]); if(s->script == NULL) { strncpy(s->filename, "/notfound.html", sizeof(s->filename)); PT_WAIT_THREAD(&s->outputpt, send_headers(s, http_header_404)); PT_WAIT_THREAD(&s->outputpt, send_string(s, NOT_FOUND)); uip_close(); webserver_log_file(&uip_conn->ripaddr, "404 - not found"); PT_EXIT(&s->outputpt); } else { PT_WAIT_THREAD(&s->outputpt, send_headers(s, http_header_200)); PT_WAIT_THREAD(&s->outputpt, s->script(s)); } s->script = NULL; PSOCK_CLOSE(&s->sout); PT_END(&s->outputpt); }
static PT_THREAD(handle_output(struct httpd_state *s)) { PT_BEGIN(&s->outputpt); s->script = httpd_cgi(&s->filename[1]); if(!s->script) { httpd_cgi_command_t *cmd = httpd_cgi_command(&s->filename[1]); if(cmd) { s->script = cmd->function(s); } } if(s->script) { if((s->script->flags & HTTPD_CUSTOM_HEADER) == 0) { PT_WAIT_THREAD(&s->outputpt, send_headers(s, http_header_200)); } if((s->script->flags & HTTPD_CUSTOM_TOP) == 0) { PT_WAIT_THREAD(&s->outputpt, generate_top(s)); } PT_WAIT_THREAD(&s->outputpt, s->script->function(s)); if((s->script->flags & HTTPD_CUSTOM_BOTTOM) == 0) { PT_WAIT_THREAD(&s->outputpt, generate_bottom(s)); } #if CONTIKI_TARGET_NATIVE } else if (httpd_is_file(s->filename)){ PT_WAIT_THREAD(&s->outputpt, send_headers(s, http_header_200)); PT_WAIT_THREAD(&s->outputpt, send_file(s)); #endif } else { LOG6LBR_6ADDR(WARN, &uip_conn->ripaddr, "File '%s' not found, from ", s->filename); PT_WAIT_THREAD(&s->outputpt, send_headers(s, http_header_404)); PT_WAIT_THREAD(&s->outputpt, generate_404(s)); } PSOCK_CLOSE(&s->sout); PT_END(&s->outputpt); }
static PT_THREAD(handle_output(struct httpd_state *s)) { PT_BEGIN(&s->outputpt); #if DEBUGLOGIC strcpy_P(s->filename,PSTR("/x")); #endif #if FIND_THE_SCRIPT s->script = httpd_simple_get_script(&s->filename[1]); if(s->script == NULL) { printf_P(PSTR("not found!")); strcpy_P(s->filename, PSTR("/notfound.html")); PT_WAIT_THREAD(&s->outputpt, send_headers(s, http_header_404)); PT_WAIT_THREAD(&s->outputpt, send_string_P(s, NOT_FOUND)); uip_close(); PT_EXIT(&s->outputpt); } else { #else s->script = generate_routes; if (1) { #endif PT_WAIT_THREAD(&s->outputpt, send_headers(s, http_header_200)); PT_WAIT_THREAD(&s->outputpt, s->script(s)); } s->script = NULL; PSOCK_CLOSE(&s->sout); PT_END(&s->outputpt); } /*---------------------------------------------------------------------------*/ static void handle_connection(struct httpd_state *s) { #if DEBUGLOGIC handle_output(s); #else handle_input(s); if(s->state == STATE_OUTPUT) { handle_output(s); } #endif }
/*---------------------------------------------------------------------------*/ static PT_THREAD(handle_output(void)) { ctk_arch_key_t c; char *ptr; PT_BEGIN(&s.outpt); while(1) { PT_WAIT_UNTIL(&s.outpt, (ctk_mode_get() == CTK_MODE_EXTERNAL) && kbhit()); ptr = s.outputbuf; s.len = 0; while(kbhit() && s.len < sizeof(s.outputbuf)) { c = cgetc(); *ptr = c; ++ptr; ++s.len; } PT_WAIT_THREAD(&s.outpt, send()); } PT_END(&s.outpt); }
int DLGSM::PT_recv(struct pt *pt, char *ret, char *conf, int tout, char process) { static uint32_t ts, startts; static struct pt linerecv_pt; PT_BEGIN(pt); ts = millis(); *ret = 0; PT_WAIT_UNTIL(pt, _gsmserial.available() || (millis() - ts) > tout); ts = millis(); if (!_gsmserial.available()) { *ret = 0; PT_EXIT(pt); } startts = millis(); _gsm_wline = 1; while (_gsmserial.available() || (millis() - startts) < tout) { PT_WAIT_THREAD(pt, PT_recvline(&linerecv_pt, ret, _gsm_buff, _gsm_buffsize, tout, process)); if (conf != NULL && strstr(_gsm_buff, conf) != NULL) *ret = 1; else if (conf != NULL) *ret = 0; } _gsm_wline = 0; PT_END(pt); }
PROCESS_THREAD(test_pub_bind, ev, data) { // printf("> test_pub_bind %d, %d, %p\n", process_pt->lc, ev, data); // print_event_name(ev); // printf("\r\n"); PROCESS_BEGIN(); zmq_init(); zmq_socket_init(&my_sock, ZMQ_PUB); // zmq_bind("tcp://*:9999"); zmq_bind(&my_sock, 9999); while(1) { if(etimer_expired(&et)) etimer_set(&et, CLOCK_SECOND); PROCESS_WAIT_EVENT(); if(ev == PROCESS_EVENT_TIMER) { printf("Publishing 'Hi there!'\r\n"); static zmq_msg_t *msg = NULL; msg = zmq_msg_from_const_data(0, "Hi there!", 9); PT_WAIT_THREAD(process_pt, my_sock.send(&my_sock, msg)); zmq_msg_destroy(&msg); } } PROCESS_END(); }
int DLGSM::PT_send_recv_confirm(struct pt *pt, char *ret, char *cmd, char *conf, int tout) { static uint32_t ts,startts; static struct pt linerecv_pt; PT_BEGIN(pt); *ret = 0; ts = millis(); GSM_send(cmd); PT_WAIT_UNTIL(pt, _gsmserial.available() || (millis() - ts) > tout); if (!_gsmserial.available()) { *ret = 0; PT_EXIT(pt); } ts = millis(); startts = millis(); _gsm_wline = 1; while (_gsmserial.available() || (millis() - startts) < tout) { PT_WAIT_THREAD(pt, PT_recvline(&linerecv_pt, ret, _gsm_buff, _gsm_buffsize, tout, 1)); ts = millis(); if (*ret == 0) _tout_cnt++; if (conf != NULL && strstr(_gsm_buff, conf) != NULL) { *ret = 1; PT_EXIT(pt); } else if (conf != NULL && (strstr(_gsm_buff, "ERROR") != NULL || strstr(_gsm_buff, "FAIL") != NULL)) { *ret = 2; _error_cnt++; PT_EXIT(pt); } else if (conf != NULL) *ret = 0; } _gsm_wline = 0; PT_END(pt); }
int DLGSM::PT_pwr_off(struct pt *pt, uint8_t force) { static struct pt child_pt; static uint32_t ts; char ret; PT_BEGIN(pt); DEBUG_LOG("GSM power off"); pinMode(GSM_PWR, OUTPUT); if (CONN_get_flag(CONN_PWR) || force) { digitalWrite(GSM_PWR, LOW); PT_WAIT_UNTIL(pt, (millis() - ts) > 1000); ts = millis(); digitalWrite(GSM_PWR, HIGH); PT_WAIT_UNTIL(pt, (millis() - ts) > 2000); ts = millis(); digitalWrite(GSM_PWR, LOW); PT_WAIT_UNTIL(pt, (millis() - ts) > 3000); CONN_set_flag(CONN_PWR, 0); CONN_set_flag(CONN_NETWORK, 0); CONN_set_flag(CONN_SENDING, 0); CONN_set_flag(CONN_CONNECTED, 0); PT_WAIT_THREAD(pt, PT_recv(&child_pt, &ret, "DOWN", 15000, 1)); } _gsmserial.flush(); PT_END(pt); }
int DLGSM::PT_send_recv(struct pt *pt, char *ret, char *cmd, int tout) { static uint32_t ts, startts; static struct pt linerecv_pt; static char gotsmtg = 0; PT_BEGIN(pt); *ret = 0; gotsmtg = 0; ts = millis(); GSM_send(cmd); PT_WAIT_UNTIL(pt, _gsmserial.available() || (millis() - ts) > tout); ts = millis(); if (!_gsmserial.available()) { PT_RESTART(pt); } startts = millis(); _gsm_wline = 1; while (_gsmserial.available() || (millis() - startts) < tout) { PT_WAIT_THREAD(pt, PT_recvline(&linerecv_pt, ret, _gsm_buff, _gsm_buffsize, tout, 1)); if (*ret > gotsmtg) gotsmtg = *ret; else if (*ret == 0) _tout_cnt++; ts = millis(); } if (*ret == 0) *ret = gotsmtg; _gsm_wline = 0; PT_END(pt); }
int DLGSM::PT_GPRS_send_start(struct pt *pt, char *ret) { char r; static struct pt child_pt; PT_BEGIN(pt); get_from_flash(&(gsm_string_table[6]), _gsm_buff); // Send AT+CIPSEND? to get PT_WAIT_THREAD(pt, PT_send_recv_confirm(&child_pt, &r, _gsm_buff, "+", 3000)); get_from_flash(&(gsm_string_table[3]), _gsm_buff); // Send AT+CIPSEND _gsm_wline = 1; // Disable new line character expectancy PT_WAIT_THREAD(pt, PT_send_recv_confirm(&child_pt, &r, _gsm_buff, ">", 3000)); _gsm_wline = 0; // Enable new line expectancy if (r > 0) CONN_set_flag(CONN_SENDING, 1); *ret = r; PT_END(pt); }
int DLGSM::PT_GPRS_close(struct pt *pt, char *ret) { char r = 0; static struct pt child_pt; PT_BEGIN(pt); PT_WAIT_THREAD(pt, PT_GPRS_check_conn_state(&child_pt, &r)); if (r == GPRSS_CONNECT_OK) { get_from_flash(&(gsm_string_table[4]), _gsm_buff); // Send AT+CIPCLOSE PT_WAIT_THREAD(pt, PT_send_recv_confirm(&child_pt, &r, _gsm_buff, "OK", 3000)); if (*ret == 1) { CONN_set_flag(CONN_CONNECTED, 0); } *ret = r; } else *ret = 1; PT_END(pt); }
int DLGSM::PT_check_flag(struct pt *pt, char flag) { static struct pt child_pt; static uint32_t ts; char iret; PT_BEGIN(pt); ts = millis(); do { get_from_flash(&(gprs_init_string_table[0]), _gsm_buff); GSM_send(_gsm_buff); PT_WAIT_THREAD(pt, PT_GSM_event_handler(&child_pt, &iret)); get_from_flash(&(gsm_string_table[0]), _gsm_buff); GSM_send(_gsm_buff); PT_WAIT_THREAD(pt, PT_GSM_event_handler(&child_pt, &iret)); PT_WAIT_UNTIL(pt, (millis() - ts) > 1000); ts = millis(); } while (CONN_get_flag(flag) == 0); PT_END(pt); }
uint8_t DLGSM::wake_modem(struct pt *pt) { uint8_t s = 0; char ret = 0; static struct pt child_pt; PT_BEGIN(pt); while (s < GPRSS_IP_STATUS || s >= GPRSS_PDP_DEACT) { PT_WAIT_THREAD(pt, PT_GPRS_check_conn_state(&child_pt, &ret)); s = ret; } PT_END(pt); }
int DLGSM::PT_SMS_send_end(struct pt *pt) { static struct pt child_pt; uint8_t r = 0; char iret; PT_BEGIN(pt); _gsm_buff[0] = 0x1a; _gsm_buff[1] = '\0'; PT_WAIT_THREAD(pt, PT_send_recv_confirm(&child_pt, &iret, _gsm_buff, "OK", 3000)); PT_END(pt); }
int DLGSM::PT_GPRS_send_end(struct pt *pt, char *ret) { char r = 0; static struct pt child_pt; PT_BEGIN(pt); r = 0; if (CONN_get_flag(CONN_SENDING)) { _gsm_buff[0] = 0x1a; _gsm_buff[1] = '\0'; PT_WAIT_THREAD(pt, PT_send_recv_confirm(&child_pt, &r, _gsm_buff, "OK", 3000)); if (r) CONN_set_flag(CONN_SENDING, 0); } *ret = r; PT_END(pt); }
int DLGSM::PT_SMS_delete(struct pt *pt, int num) { static struct pt child_pt; char iret; char smallbuff[12]; PT_BEGIN(pt); get_from_flash(&(sms_string_table[4]), _gsm_buff); sprintf(smallbuff, "%d\r\n", num); strcat(_gsm_buff, smallbuff); PT_WAIT_THREAD(pt, PT_send_recv_confirm(&child_pt, &iret, _gsm_buff, "OK", 3000)); PT_END(pt); }
int DLGSM::PT_GSM_event_handler(struct pt *pt, char *ret) { char i = 0; static char iret; static struct pt child_pt; static int n = 0; PT_BEGIN(pt); PT_YIELD_UNTIL(pt, _gsmserial.available() > 1); // +CMTI: "SM",1 while (_gsmserial.available()) { PT_WAIT_THREAD(pt, PT_recvline(&child_pt, &iret, _gsm_buff, _gsm_buffsize, 1000, 1)); if (iret > 0) { // Call arriving, hang up? if (_gsm_buff[0] == 'R') { sprintf(_gsm_buff, "ATH\r\n"); PT_WAIT_THREAD(pt, PT_send_recv_confirm(&child_pt, &iret, _gsm_buff, "OK", 5000)); *ret = GSM_EVENT_STATUS_REQ; PT_EXIT(pt); } else if (_gsm_buff[0] == '+') { if (_gsm_buff[3] == 'T' && _gsm_buff[4] == 'I') { n = atoi((char *)(_gsm_buff+12)); PT_WAIT_THREAD(pt, PT_SMS_read(&child_pt,&iret,n)); iret = 0; PT_WAIT_THREAD(pt, PT_SMS_process(&child_pt, &iret, &curr_sms)); PT_WAIT_THREAD(pt, PT_SMS_delete(&child_pt, n)); *ret = iret; PT_EXIT(pt); } } else { GSM_process_line(NULL); } } } PT_END(pt); }
/*---------------------------------------------------------------------------*/ static PT_THREAD(handle_output(struct httpd_state *s)) { char *ptr; PT_BEGIN(&s->outputpt); if(!httpd_fs_open(s->filename, &s->file)) { httpd_fs_open(http_404_html, &s->file); strcpy(s->filename, http_404_html); PT_WAIT_THREAD(&s->outputpt, send_headers(s, http_header_404)); PT_WAIT_THREAD(&s->outputpt, send_file(s)); } else { PT_WAIT_THREAD(&s->outputpt, send_headers(s, http_header_200)); ptr = strchr(s->filename, ISO_period); if(ptr != NULL && (strncmp(ptr, http_shtml, 6) == 0 || strncmp(ptr, ".bin", 4) == 0)) { PT_INIT(&s->scriptpt); PT_WAIT_THREAD(&s->outputpt, handle_script(s)); } else { PT_WAIT_THREAD(&s->outputpt, send_file(s)); } } if (s->emumode) { // Just switched to emulator mode! Fix the state s->state = STATE_WAITING; } else { PSOCK_CLOSE(&s->sout); } PT_END(&s->outputpt); }
static PT_THREAD(driver_thread(struct pt *pt)) { static struct pt writePt, readPt, lpPt; PT_BEGIN(pt); PT_INIT(&writePt); PT_INIT(&readPt); PT_INIT(&lpPt); PT_WAIT_THREAD(pt, data_write_thread(&writePt) & data_read_thread(&readPt) & data_long_polling_thread(&lpPt)); PT_END(pt); }