Esempio n. 1
0
/* read powered flag */
static ZERO_OR_ERROR FS_r_power(struct one_wire_query *owq)
{
	BYTE p;
	RETURN_ERROR_IF_BAD( OW_r_mem(&p, 1, _ADDRESS_POWERED, PN(owq)) ) ;
	OWQ_Y(owq) = (p == _1W_2450_POWERED);
	Cache_Add_SlaveSpecific(&OWQ_Y(owq), sizeof(int), SlaveSpecificTag(POW), PN(owq));
	return 0;
}
Esempio n. 2
0
/* write powered flag */
static ZERO_OR_ERROR FS_w_power(struct one_wire_query *owq)
{
	BYTE p = _1W_2450_POWERED;	/* powered */
	BYTE q = _1W_2450_UNPOWERED;	/* parasitic */
	if (OW_w_mem(OWQ_Y(owq) ? &p : &q, 1, _ADDRESS_POWERED, PN(owq))) {
		return -EINVAL;
	}
	Cache_Add_SlaveSpecific(&OWQ_Y(owq), sizeof(int), SlaveSpecificTag(POW), PN(owq));
	return 0;
}
Esempio n. 3
0
static ZERO_OR_ERROR FS_Mclear(struct one_wire_query *owq)
{
	struct parsedname *pn = PN(owq);
	int init = 1;

	if ( BAD( Cache_Get_SlaveSpecific(&init, sizeof(init), SlaveSpecificTag(INI), pn)) ) {
		OWQ_Y(owq) = 1;
		if ( FS_r_strobe(owq) != 0 ) {	// set reset pin to strobe mode
			return -EINVAL;
		}
		RETURN_ERROR_IF_BAD( OW_w_pio(0x30, pn) );

		UT_delay(100);
		// init
		RETURN_ERROR_IF_BAD( OW_w_pio(0x38, pn) ) ;
		UT_delay(10);
		// Enable Display, Cursor, and Blinking
		// Entry-mode: auto-increment, no shift
		RETURN_ERROR_IF_BAD( OW_w_pio(0x0F, pn) ) ;
		RETURN_ERROR_IF_BAD( OW_w_pio(0x06, pn) ) ;
		Cache_Add_SlaveSpecific(&init, sizeof(init), SlaveSpecificTag(INI), pn);
	}
	// clear
	RETURN_ERROR_IF_BAD( OW_w_pio(0x01, pn) );
	UT_delay(2);
	return FS_Mhome(owq);
}
Esempio n. 4
0
/* write flag */
static ZERO_OR_ERROR FS_w_flag(struct one_wire_query *owq)
{
	struct parsedname *pn = PN(owq);
	BYTE cr;
	BYTE fl = pn->selected_filetype->data.c;
	OWQ_allocate_struct_and_pointer(owq_flag);
	
	OWQ_create_temporary(owq_flag, (char *) &cr, 1, 0x0201, pn);
	if (COMMON_read_memory_F0(owq_flag, 0, 0)) {
		return -EINVAL;
	}
	if (OWQ_Y(owq)) {
		if (cr & fl) {
			return 0;
		}
	} else {
		if ((cr & fl) == 0) {
			return 0;
		}
	}
	cr ^= fl;					/* flip the bit */
	if (OW_w_mem(&cr, 1, 0x0201, pn)) {
		return -EINVAL;
	}
	return 0;
}
Esempio n. 5
0
/* LCD */
static ZERO_OR_ERROR FS_simple_command(struct one_wire_query *owq)
{
	struct parsedname *pn = PN(owq);
	UINT lcd_command_pair = (UINT) pn->selected_filetype->data.u;
	BYTE lcd_command_code = OWQ_Y(owq) ? UNPACK_ON(lcd_command_pair) : UNPACK_OFF(lcd_command_pair);
	return GB_to_Z_OR_E(OW_simple_command(lcd_command_code, pn)) ;
}
Esempio n. 6
0
static ZERO_OR_ERROR FS_r_por(struct one_wire_query *owq)
{
	BYTE data[6];
	RETURN_ERROR_IF_BAD( OW_r_reg(data, PN(owq)) );
	OWQ_Y(owq) = UT_getbit(&data[5], 3);
	return 0;
}
Esempio n. 7
0
static ZERO_OR_ERROR FS_out_of_testmode(struct one_wire_query *owq)
{
	if ( OWQ_Y(owq) ) {
		RETURN_ERROR_IF_BAD( OW_out_of_test_mode(PN(owq) ) );
	}
	return 0;
}
Esempio n. 8
0
static ZERO_OR_ERROR FS_w_por(struct one_wire_query *owq)
{
	struct parsedname *pn = PN(owq);
	BYTE data[6];
	RETURN_ERROR_IF_BAD( OW_r_reg(data, pn) );
	UT_setbit(&data[5], 3, OWQ_Y(owq));
	return GB_to_Z_OR_E( OW_w_control(data[5], pn) ) ;
}
Esempio n. 9
0
static SIZE_OR_ERROR OWQ_parse_output_yesno(struct one_wire_query *owq)
{
	if (OWQ_size(owq) < PROPERTY_LENGTH_YESNO) {
		return -EMSGSIZE;
	}
	OWQ_buffer(owq)[0] = ((OWQ_Y(owq) & 0x1) == 0) ? '0' : '1';
	return ShouldTrim(PN(owq))? 1 : PROPERTY_LENGTH_YESNO;
}
Esempio n. 10
0
static ZERO_OR_ERROR FS_CO2_status( struct one_wire_query *owq)
{
	_FLOAT V = 0.;
	ZERO_OR_ERROR z_or_e = FS_r_sibling_F(&V,"volt.B",owq) ;

	OWQ_Y(owq) = (V>3.0) && (V<3.4) ;
	return z_or_e ;
}
Esempio n. 11
0
static ZERO_OR_ERROR FS_increment(struct one_wire_query *owq)
{
	if ( OWQ_Y(owq) == 0 ) {
		return 0 ;
	}
	FS_del_sibling( "counter/cycles", owq ) ;
	return GB_to_Z_OR_E (OW_increment( PN(owq) )) ;
}
Esempio n. 12
0
ZERO_OR_ERROR FS_present(struct one_wire_query *owq)
{
	struct parsedname *pn = PN(owq);

	if (NotRealDir(pn) || pn->selected_device == DeviceSimultaneous || pn->selected_device == DeviceThermostat) {
		OWQ_Y(owq) = 1;
	} else if ( pn->selected_connection->iroutines.flags & ADAP_FLAG_presence_from_dirblob ) {
		OWQ_Y(owq) = GOOD( PresenceFromDirblob(pn) ) ;
	} else if ( pn->selected_connection->iroutines.flags & ADAP_FLAG_sham ) {
		OWQ_Y(owq) = 0 ;
	} else {
		struct transaction_log t[] = {
			TRXN_NVERIFY,
			TRXN_END,
		};
		OWQ_Y(owq) = BAD(BUS_transaction(t, pn)) ? 0 : 1;
	}
	return 0;
}
Esempio n. 13
0
/* Sparse numeric indexes */
static ZERO_OR_ERROR FS_r_is_index_prime(struct one_wire_query *owq)
{
	struct parsedname * pn = PN(owq) ; // Get the parsename reference
	int array_index ; // array index
	
	// Here we'll use the index as a number (integer) and test whether the number is prime
	// The index is not an array index.
	// There is no pre-defined number of elements
	// There is no ".ALL" function available
	
	// The index string was parsed and converted to a number, but
	// no bounds checking was done (unlike a normal array).
	
	array_index = pn->extension ;
	
	// Prime number test
	// pick off negatives, 0, 1, 2, evens
	// Then test by dividing by odds up to square root
	if ( array_index < 1 ) {
		return -EINVAL ;
	} else if ( array_index == 1 ) {
		OWQ_Y(owq) = 1 ; // 1 is prime
	} else if ( array_index == 2 ) {
		OWQ_Y(owq) = 1 ; // 2 is prime
	} else if ( array_index % 2 == 0 ) {
		OWQ_Y(owq) = 0 ; // even is not prime
	} else {
		int idiv = 1 ; // test devisor 
		
		OWQ_Y(owq) = 1 ; // assume prime
		
		do {
			idiv += 2 ; // still odd
			if ( array_index % idiv == 0 ) {
				OWQ_Y(owq) = 0 ; // non-prime
				break ;
			}
		} while ( idiv < (array_index/idiv) ) ;
	}

	return 0;
}
Esempio n. 14
0
static ZERO_OR_ERROR FS_r_APU(struct one_wire_query *owq)
{
	struct parsedname *pn = PN(owq);
	switch ( get_busmode(pn->selected_connection) ) {
		case bus_i2c:
			OWQ_Y(owq) = ( (pn->selected_connection->master.i2c.configreg & DS2482_REG_CFG_APU) != 0x00 ) ;
			return 0;
		default:
			return -ENOTSUP ;
	}
}
Esempio n. 15
0
static ZERO_OR_ERROR FS_r_PPM(struct one_wire_query *owq)
{
	struct connection_in * in = PN(owq)->selected_connection ;
	switch ( get_busmode(in) ) {
		case bus_i2c:
			OWQ_Y(owq) = ( (in->master.i2c.configreg & DS2482_REG_CFG_PPM) != 0x00 ) ;
			return 0;
		default:
			return -ENOTSUP ;
	}
}
Esempio n. 16
0
ZERO_OR_ERROR FS_r_sibling_Y(INT *Y, const char * sibling, struct one_wire_query *owq)
{
	struct one_wire_query * owq_sibling  = OWQ_create_sibling( sibling, owq ) ;
	SIZE_OR_ERROR sib_status ;

	if ( owq_sibling == NO_ONE_WIRE_QUERY ) {
		return -EINVAL ;
	}
	sib_status = FS_read_local(owq_sibling) ;
	Y[0] = OWQ_Y(owq_sibling) ;
	OWQ_destroy(owq_sibling) ;
	return sib_status >= 0 ? 0 : -EINVAL ;
}
Esempio n. 17
0
ZERO_OR_ERROR FS_w_sibling_Y(INT Y, const char * sibling, struct one_wire_query *owq)
{
	ZERO_OR_ERROR write_error;
	struct one_wire_query * owq_sibling  = OWQ_create_sibling( sibling, owq ) ;

	if ( owq_sibling == NO_ONE_WIRE_QUERY ) {
		return -EINVAL ;
	}
	OWQ_Y(owq_sibling) = Y ;
	write_error = FS_write_local(owq_sibling) ;
	OWQ_destroy(owq_sibling) ;
	return write_error ;
}
Esempio n. 18
0
// Handles: .n
static ZERO_OR_ERROR FS_write_a_bit(struct one_wire_query *owq_bit)
{
	struct one_wire_query * owq_byte = OWQ_create_separate( EXTENSION_BYTE, owq_bit ) ;
	ZERO_OR_ERROR z_or_e = -ENOENT ;
	
	if ( owq_byte != NO_ONE_WIRE_QUERY ) {
		if ( FS_read_local( owq_byte ) >= 0 ) {
			UT_setbit( (BYTE *) &OWQ_U( owq_byte ), OWQ_pn(owq_bit).extension, OWQ_Y(owq_bit) ) ;
			z_or_e = FS_write_owq( owq_byte ) ;
		}
		OWQ_destroy( owq_byte ) ;
	}
	return z_or_e ;
}
Esempio n. 19
0
/* read flag */
static ZERO_OR_ERROR FS_r_flag(struct one_wire_query *owq)
{
	struct parsedname *pn = PN(owq);
	BYTE cr;
	BYTE fl = pn->selected_filetype->data.c;
	OWQ_allocate_struct_and_pointer(owq_flag);

	OWQ_create_temporary(owq_flag, (char *) &cr, 1, 0x0201, pn);
	if (COMMON_read_memory_F0(owq_flag, 0, 0)) {
		return -EINVAL;
	}
	OWQ_Y(owq) = (cr & fl) ? 1 : 0;
	return 0;
}
Esempio n. 20
0
static ZERO_OR_ERROR FS_w_APU(struct one_wire_query *owq)
{
	struct parsedname *pn = PN(owq);
	switch ( get_busmode(pn->selected_connection) ) {
		case bus_i2c:
			if ( OWQ_Y(owq) ) {
				pn->selected_connection->master.i2c.configreg |= DS2482_REG_CFG_APU ;
			} else {
				pn->selected_connection->master.i2c.configreg &= ~DS2482_REG_CFG_APU ;
			}
			break ;
		default:
			break ;
	}
	return 0 ;
}
Esempio n. 21
0
static ZERO_OR_ERROR FS_w_PPM(struct one_wire_query *owq)
{
	struct connection_in * in = PN(owq)->selected_connection ;
	switch ( get_busmode(in) ) {
		case bus_i2c:
			if ( OWQ_Y(owq) ) {
				in->master.i2c.configreg |= DS2482_REG_CFG_PPM ;
			} else {
				in->master.i2c.configreg &= ~DS2482_REG_CFG_PPM ;
			}
			break ;
		default:
			break ;
	}
	return 0 ;
}
Esempio n. 22
0
/* read a bit from BYTE */
static ZERO_OR_ERROR FS_read_a_bit( struct one_wire_query *owq_bit )
{
	// Bus and device already locked
	struct one_wire_query * owq_byte = OWQ_create_separate( EXTENSION_BYTE, owq_bit ) ;
	struct parsedname *pn = PN(owq_bit);
	ZERO_OR_ERROR z_or_e = -ENOENT ;
	
	if ( owq_byte == NO_ONE_WIRE_QUERY ) {
		return -ENOENT ;
	}

	/* read the UINT */
	if ( FS_read_owq(owq_byte) >= 0) {
		OWQ_Y(owq_bit) = UT_getbit_U( OWQ_U(owq_byte), pn->extension) ;
		z_or_e = 0 ;
	}

	OWQ_destroy(owq_byte);
	return z_or_e;
}
Esempio n. 23
0
static ZERO_OR_ERROR FS_r_yesno( struct one_wire_query * owq )
{
	struct parsedname * pn = PN(owq) ;
	struct connection_in * in = pn->selected_connection ;
	struct filetype * ft = pn->selected_filetype ;
	size_t struct_offset = ft->data.s ;
	char * in_loc = (void *) in ;
	int * p_yes_no = (int *)(in_loc + struct_offset) ;

	switch( (ft->visible)(pn) ) {
		case visible_not_now:
		case visible_never:
			return -ENOTSUP ;
		default:
			break ;
	}

	OWQ_Y(owq) = p_yes_no[0] ;
	return 0 ;
}
Esempio n. 24
0
// Handles: BYTE
static ZERO_OR_ERROR FS_read_all_bits(struct one_wire_query *owq_byte)
{
	struct one_wire_query * owq_bit = OWQ_create_separate( 0, owq_byte ) ;
	struct parsedname *pn = PN(owq_byte);
	size_t elements = pn->selected_filetype->ag->elements;
	size_t extension;
	
	if ( owq_bit == NO_ONE_WIRE_QUERY ) {
		return -ENOENT ;
	}

	/* Loop through F_r_single, just to get data */
	for (extension = 0; extension < elements; ++extension) {
		OWQ_pn(owq_bit).extension = extension ;
		if ( FS_read_owq(owq_bit) < 0 ) {
			OWQ_destroy(owq_bit);
			return -EINVAL;
		}
		UT_setbit_U( &OWQ_U(owq_byte), extension, OWQ_Y(owq_bit) ) ;
	}

	OWQ_destroy(owq_bit);
	return 0;
}
Esempio n. 25
0
// handles: BYTE
static ZERO_OR_ERROR FS_write_as_bits( struct one_wire_query *owq_byte )
{
	struct one_wire_query * owq_bit = OWQ_create_separate( 0, owq_byte ) ;
	size_t elements = OWQ_pn(owq_byte).selected_filetype->ag->elements;
	size_t extension ;
	ZERO_OR_ERROR z_or_e = 0 ;
	
	if ( owq_bit == NO_ONE_WIRE_QUERY ) {
		return -ENOENT ;
	}

	for ( extension = 0 ; extension < elements ; ++extension ) {
		ZERO_OR_ERROR z ;
		OWQ_pn(owq_bit).extension = extension ;
		OWQ_Y(owq_bit) = UT_getbit( (BYTE *) &OWQ_U(owq_byte), extension ) ;
		z = FS_write_owq( owq_bit ) ;
		if ( z != 0 ) {
			z_or_e = z ;
		}
	}
	OWQ_destroy( owq_bit ) ;

	return z_or_e ;
}
Esempio n. 26
0
/* 2450 A/D */
static ZERO_OR_ERROR FS_w_PIO(struct one_wire_query *owq)
{
	return GB_to_Z_OR_E( OW_w_pio( OWQ_Y(owq), PN(owq)) ) ;
}
Esempio n. 27
0
/* write high/low voltage triggered state alarm flags */
static ZERO_OR_ERROR FS_w_flag(struct one_wire_query *owq)
{
	struct parsedname *pn = PN(owq);
	return GB_to_Z_OR_E(OW_w_flag( OWQ_Y(owq), pn->selected_filetype->data.i, pn)) ;
}
Esempio n. 28
0
void _print_owq(struct one_wire_query *owq)
{
	char c[32];
	fprintf(stderr,"OWQ OneWireQuery structure of %s\n", PN(owq)->path);
	fprintf(stderr,"    OneWireQuery size=%lu offset=%lu, extension=%d\n",
		   (unsigned long) OWQ_size(owq), (unsigned long) OWQ_offset(owq), (int) OWQ_pn(owq).extension);
	if ( OWQ_buffer(owq) != NULL ) {
		Debug_Bytes("OneWireQuery buffer", (BYTE *) OWQ_buffer(owq), OWQ_size(owq));
	}
	fprintf(stderr,"    Cleanup = %.4X",OWQ_cleanup(owq));
	fprintf(stderr,"    OneWireQuery I=%d U=%u F=%G Y=%d D=%s\n", OWQ_I(owq), OWQ_U(owq), OWQ_F(owq), OWQ_Y(owq), SAFESTRING(ctime_r(&OWQ_D(owq), c)));
	fprintf(stderr,"--- OneWireQuery done\n");
}
Esempio n. 29
0
/* Just some tests to support reconnection */
static ZERO_OR_ERROR FS_w_reconnect(struct one_wire_query *owq)
{
	struct parsedname *pn = PN(owq);
	pn->selected_connection->reconnect_state = OWQ_Y(owq) ? reconnect_error : reconnect_ok ;
	return 0;
}
Esempio n. 30
0
/* Just some tests to support reconnection */
static ZERO_OR_ERROR FS_r_reconnect(struct one_wire_query *owq)
{
	struct parsedname *pn = PN(owq);
	OWQ_Y(owq) = (pn->selected_connection->reconnect_state == reconnect_error);
	return 0;
}