Beispiel #1
0
int DLGSM::PT_GPRS_check_conn_state(struct pt *pt, char *ret) {
	static struct pt child_pt;
        static uint8_t k;
	char iret;
        char d[15];

	PT_BEGIN(pt);
        get_from_flash(&(gsm_string_table[5]), _gsm_buff);
	*ret = 0;
	k = 0;
        PT_WAIT_THREAD(pt, PT_send_recv_confirm(&child_pt, ret, _gsm_buff, "STATE:", 20000));

        if (strcmp_P(_gsm_buff, PSTR("STATE:")) >= 0) {
		while (k < GPRSS_LEN) {
                        if (strcmp_flash(_gsm_buff+7, &(gprs_state_table[k]), d) == 0) {
				*ret = k;
                                if (k == GPRSS_IP_INITIAL ||
                                    k == GPRSS_IP_START ||
                                    k == GPRSS_IP_CONFIG) { // Reinitialize GPRS
						PT_WAIT_WHILE(pt, CONN_get_flag(CONN_NETWORK) == 0);
						PT_WAIT_THREAD(pt, PT_GSM_init(&child_pt, &iret));
						PT_WAIT_WHILE(pt, CONN_get_flag(CONN_GPRS_NET) == 0);
						PT_WAIT_THREAD(pt, PT_GPRS_init(&child_pt, &iret));              
                                } else if (k == GPRSS_IP_GPRSACT) { // Just need to query the local IP...
                                	get_from_flash(&(gprs_init_string_table[9]), _gsm_buff);
                                      	PT_WAIT_THREAD(pt, PT_send_recv(&child_pt, &iret, _gsm_buff, 1000));
                                } else if (k == GPRSS_CONNECT_OK) {
                                	CONN_set_flag(CONN_CONNECTED, 1);
                                } else if (k == GPRSS_TCP_CLOSED ||
                                           k == GPRSS_UDP_CLOSED) {
                                	CONN_set_flag(CONN_CONNECTED, 0);
                                } else if (k == GPRSS_PDP_DEACT) { // Reinitialize GPRS
                                	PT_WAIT_WHILE(pt, CONN_get_flag(CONN_NETWORK) == 0);
					PT_WAIT_THREAD(pt, PT_GSM_init(&child_pt, &iret));
					PT_WAIT_WHILE(pt, CONN_get_flag(CONN_GPRS_NET) == 0);
					PT_WAIT_THREAD(pt, PT_GPRS_init(&child_pt, &iret));
				}
                                *ret = k;
				PT_EXIT(pt);
                        }
			k++;
                }
        } else {
		PT_RESTART(pt);
	}
        *ret = -1;
	PT_END(pt);
}
Beispiel #2
0
Datei: log.c Projekt: nnayo/scalp
static PT_THREAD( LOG_log(pt_t* pt) )
{
	u32 time;
	u8 is_filtered;
	u8 i;

	PT_BEGIN(pt);

	// systematically unlock the channel
	// because most of time no response is sent
	// when a response is needed, the channel will be locked
	DPT_unlock(&LOG.interf);

	switch ( LOG.state ) {
		case LOG_OFF:
		default:
			// empty the log fifo
			(void)FIFO_get(&LOG.in_fifo, &LOG.fr);

			// loop back for next frame
			PT_RESTART(pt);
			break;

		case LOG_RAM:
#ifdef SAVE_IN_RAM_ENABLED
#endif
			break;

		case LOG_EEPROM:
			// if address is out of range
			if ( LOG.eeprom_addr >= EEPROM_END_ADDR ) {
				// logging is no more possible
				// so quit
				PT_EXIT(pt);
			}
			break;

		case LOG_SDCARD:
			// if address is out of range
			if ( LOG.sdcard_addr >= SDCARD_END_ADDR ) {
				// logging is no more possible
				// so quit
				PT_EXIT(pt);
			}
			break;
	}

	// wait while no frame is present in the fifo
	PT_WAIT_WHILE(pt, KO == FIFO_get(&LOG.in_fifo, &LOG.fr));

	// if it is a log command
	if ( (LOG.fr.cmde == FR_LOG_CMD) && (!LOG.fr.resp) ) {
		// treat it
		LOG_command(&LOG.fr);

		// send the response
		DPT_lock(&LOG.interf);
		PT_WAIT_UNTIL(pt, OK == DPT_tx(&LOG.interf, &LOG.fr));
		DPT_unlock(&LOG.interf);


		// and wait till the next frame
		PT_RESTART(pt);
	}

	// filter the frame according to its origin
	is_filtered = OK;	// by default, every frame is filtered
	for ( i = 0; i < sizeof(LOG.orig_filter); i++ ) {
		// passthrough or frame origin and filter acceptance match
		if ( (LOG.orig_filter[i] == 0x00) || (LOG.orig_filter[i] == LOG.fr.orig) ){
			is_filtered = KO;
			break;
		}
	}

	// if frame is filtered away
	if ( is_filtered ) {
		// lop back for next frame
		PT_RESTART(pt);
	}

	// build the log packet
	LOG.block.index = LOG.index;
	time = TIME_get();
	LOG.block.time[0] = (u8)(time >> 16);
	LOG.block.time[1] = (u8)(time >>  8);
	LOG.block.fr = LOG.fr;

	switch ( LOG.state ) {
		case LOG_OFF:
		default:
			// shall never happen but just in case
			// loop back for next frame
			PT_RESTART(pt);
			break;

		case LOG_RAM:
#ifdef SAVE_IN_RAM_ENABLED
			LOG.ram_buffer[LOG.ram_index] = LOG.block;
			if ( LOG.ram_index < (RAM_BUFFER_SIZE - 1) ) {
				LOG.ram_index++;
			}
#endif
			break;

		case LOG_EEPROM:
			// save it to eeprom
			PT_WAIT_UNTIL(pt, EEP_write(LOG.eeprom_addr, (u8*)&LOG.block, sizeof(log_t)));

			// wait until saving is done
			PT_WAIT_UNTIL(pt, EEP_is_fini());
			break;

		case LOG_SDCARD:
			// save it to sdcard (fill the write buffer)
			PT_WAIT_UNTIL(pt, SD_write(LOG.sdcard_addr, (u8*)&LOG.block, sizeof(log_t)));

			// wait until saving is done

			break;
	}

	// loop back to treat the next frame to log
	PT_RESTART(pt);

	PT_END(pt);
}