void javax_wukong_wkpf_WKPF_void_createWuObject_short_byte_javax_wukong_wkpf_VirtualWuObject()
{
	dj_object *java_instance_reference = REF_TO_VOIDP(dj_exec_stackPopRef());
	uint8_t port_number = (uint8_t)dj_exec_stackPopShort();
	uint16_t wuclass_id = (uint16_t)dj_exec_stackPopShort();
	DEBUG_LOG(DBG_WKPF, "WKPF: Creating wuobject for virtual wuclass with id %x at port %x (ref: %p)\n", wuclass_id, port_number, java_instance_reference);
	wkpf_error_code = wkpf_create_wuobject(wuclass_id, port_number, java_instance_reference, false);
}
void javax_wukong_wkpf_WKPF_void_setPropertyBoolean_javax_wukong_wkpf_VirtualWuObject_byte_boolean() {
	bool value = (int16_t)dj_exec_stackPopShort();
	uint8_t property_number = (uint8_t)dj_exec_stackPopShort();
	dj_object *java_instance_reference = REF_TO_VOIDP(dj_exec_stackPopRef());
	wuobject_t *wuobject;
	wkpf_error_code = wkpf_get_wuobject_by_java_instance_reference(java_instance_reference, &wuobject);
	if (wkpf_error_code == WKPF_OK) {
		wkpf_error_code = wkpf_internal_write_property_boolean(wuobject, property_number, value);
	}
}
// void javax.darjeeling.actuators.Leds.set(short, boolean)
void javax_darjeeling_actuators_Leds_void_set_short_boolean()
{
	uint16_t on = dj_exec_stackPopShort();
	uint16_t nr = dj_exec_stackPopShort();

	// Check for out-of-bounds
	if (nr>=0 && nr<NUM_VIRTUAL_LEDS)
		nesc_setLed(nr, on);
	else
		dj_exec_createAndThrow(BASE_CDEF_java_lang_IndexOutOfBoundsException);
}
// void javax.darjeeling.io.Serial.setBaudRate(byte, int)
void javax_darjeeling_io_Serial_void_setBaudRate_byte_int()
{
	dj_exec_stackPopInt();
	dj_exec_stackPopShort();

	// Do nothing.
}
void javax_wukong_wkpf_WKPF_boolean_isLocalComponent_short() {
	uint16_t component_id = (int16_t)dj_exec_stackPopShort();
	wkcomm_address_t node_id;
	uint8_t port_number;
	wkpf_error_code = wkpf_get_node_and_port_for_component(component_id, &node_id, &port_number);
	dj_exec_stackPushShort(wkpf_error_code == WKPF_OK && node_id == wkcomm_get_node_id());
}
void javax_wukong_wkpf_WKPF_byte_getPortNumberForComponent_short() {
	uint16_t component_id = (uint16_t)dj_exec_stackPopShort();
	wkcomm_address_t node_id;
	uint8_t port_number;
	wkpf_error_code = wkpf_get_node_and_port_for_component(component_id, &node_id, &port_number);
	dj_exec_stackPushShort(port_number);
}
// void javax.darjeeling.actuators.Leds.set(short, boolean)
void javax_darjeeling_actuators_Leds_void_set_short_boolean()
{
    uint16_t on = dj_exec_stackPopShort();

    // Discard the led index argument
    dj_exec_stackPopShort();

    // set port B pin 7 to output
    DDRB |= 128;

    // turn the led on/off
    if (on)
        PORTB |= 128;
    else
        PORTB &= ~128;
}
// int javax.darjeeling.sensors.ADC.read(short)
void javax_darjeeling_sensors_ADC_int_read_short()
{
	dj_exec_stackPopShort();

	// No ADCs.
	dj_exec_createAndThrow(BASE_CDEF_java_lang_IndexOutOfBoundsException);
}
// void javax.virtualsense.actuators.Leds.setLed(int, boolean)
void javax_virtualsense_actuators_Leds_void_setLed_int_boolean()
{
	int16_t on = dj_exec_stackPopShort();
	int32_t nr = dj_exec_stackPopInt();

	if (nr==0) if (on) leds_on(LEDS_1); else leds_off(LEDS_1);
	if (nr==1) if (on) leds_on(LEDS_2); else leds_off(LEDS_2);
	if (nr==2) if (on) leds_on(LEDS_3); else leds_off(LEDS_3);
}
void javax_wukong_wknode_WuNodeLeds_void__setLed_int_boolean()
{
	unsigned char on = dj_exec_stackPopShort();
	unsigned int nr = dj_exec_stackPopInt();

	if (on)
		output_low(PORTK, nr);
	else
		output_high(PORTK, nr);
}
// void javax.darjeeling.Darjeeling.assertTrue(int, boolean)
void javax_darjeeling_Darjeeling_void_assertTrue_int_boolean()
{
	// pop argument from the stack
	int32_t value = dj_exec_stackPopShort();
	int32_t id = dj_exec_stackPopInt();
	if (value==0)
		printf("%c[31mASSERT[%3d] FAILED%c[0m\n", 0x1b, (int)id, 0x1b);
	else
		printf("%c[32mASSERT[%3d] PASSED%c[0m\n", 0x1b, (int)id, 0x1b);
}
예제 #12
0
// void javax.fleck.Leds.setLed(int, boolean)
void javax_fleck_Leds_void_setLed_int_boolean()
{
	unsigned char on = dj_exec_stackPopShort();
	unsigned int nr = dj_exec_stackPopInt();
	char * tempStr = dj_mem_alloc(25, CHUNKID_REFARRAY);
	snprintf(tempStr, 25, on?"LED %d ON(on/off=%d)\n":"LED %d OFF(on/off=%d)\n", nr, on);
	tossim_printf(tempStr);
	dj_mem_free(tempStr);
	
}
void javax_wukong_wkpf_WKPF_void_registerWuClass_short_byte__()
{
	dj_int_array *byteArrayProperties = REF_TO_VOIDP(dj_exec_stackPopRef());
	// check null
	if (byteArrayProperties==nullref){
		dj_exec_createAndThrow(BASE_CDEF_java_lang_NullPointerException);
	}
	uint16_t wuclass_id = (uint16_t)dj_exec_stackPopShort();
	DEBUG_LOG(DBG_WKPF, "WKPF: Registering virtual wuclass with id %x\n", wuclass_id);
	wkpf_error_code = wkpf_register_virtual_wuclass(wuclass_id, NULL, byteArrayProperties->array.length, (uint8_t *)byteArrayProperties->data.bytes);
}
void javax_wukong_wkpf_WKPF_void_setPropertyRefreshRate_short_byte_short() {
	int16_t value = (int16_t)dj_exec_stackPopShort();
	uint8_t property_number = (uint8_t)dj_exec_stackPopShort();
	uint16_t component_id = (uint16_t)dj_exec_stackPopShort();
	address_t node_id;
	uint8_t port_number;
	wkpf_error_code = wkpf_get_node_and_port_for_component(component_id, &node_id, &port_number);
	if (wkpf_error_code == WKPF_OK) {
		if (node_id != wkcomm_get_node_id())
			wkpf_error_code = WKPF_ERR_REMOTE_PROPERTY_FROM_JAVASET_NOT_SUPPORTED;
		else {
			wuobject_t *wuobject;
			wkpf_error_code = wkpf_get_wuobject_by_port(port_number, &wuobject);
			if (wkpf_error_code == WKPF_OK) {
				DEBUG_LOG(DBG_WKPF, "WKPF: setPropertyRefreshRate (local). Port %x, property %x, value %x\n", port_number, property_number, value);
				wkpf_error_code = wkpf_external_write_property_refresh_rate(wuobject, property_number, value);
			}
		}
	}
}
void javax_wukong_wkpf_WKPF_short_getPropertyShort_javax_wukong_wkpf_VirtualWuObject_byte()
{
	uint8_t property_number = (uint8_t)dj_exec_stackPopShort();
	dj_object *java_instance_reference = REF_TO_VOIDP(dj_exec_stackPopRef());
	wuobject_t *wuobject;
	wkpf_error_code = wkpf_get_wuobject_by_java_instance_reference(java_instance_reference, &wuobject);
	if (wkpf_error_code == WKPF_OK) {
		int16_t value;
		wkpf_error_code = wkpf_internal_read_property_int16(wuobject, property_number, &value);
		dj_exec_stackPushShort(value);
	}
}
// void javax.ostfriesentee.Ostfriesentee.assertTrue(int, boolean)
void javax_ostfriesentee_Ostfriesentee_void_assertTrue_int_boolean()
{
	// pop argument from the stack
	int32_t value = dj_exec_stackPopShort();
	int32_t id = dj_exec_stackPopInt();
	tests_total++;
	if (value==0) {
		debug_printf("%c[31mASSERT[%3d] FAILED%c[0m\n", 0x1b, (int)id, 0x1b);
	} else {
		tests_passed++;
		debug_printf("%c[32mASSERT[%3d] PASSED%c[0m\n", 0x1b, (int)id, 0x1b);
	}
}
// java.lang.Thread javax.darjeeling.Darjeeling.getThread(short)
void javax_darjeeling_Darjeeling_java_lang_Thread_getThread_short()
{
	dj_thread *thread;
	int index = dj_exec_stackPopShort();

	// check for out of bounds
	if ( (index<0) || (index>=dj_vm_countThreads(dj_exec_getVM())) )
		dj_exec_throwHere(dj_vm_createSysLibObject(dj_exec_getVM(), BASE_CDEF_java_lang_IndexOutOfBoundsException));
	else
	{
		thread = dj_vm_getThread(dj_exec_getVM(), index);
		dj_exec_stackPushRef(VOIDP_TO_REF(thread));
	}
}
// void javax.darjeeling.Darjeeling.assertTrue(int, boolean)
void javax_darjeeling_Darjeeling_void_assertTrue_int_boolean()
{
    // pop argument from the stack
    int16_t value = dj_exec_stackPopShort();
    int32_t id = dj_exec_stackPopInt();

#warning FIX THIS :)

    if (value==0)
        DARJEELING_PRINTF("ASSERT[%3ld] FAILED\n", id);
    else
        DARJEELING_PRINTF("ASSERT[%3ld] passed\n", id);

//	if (nesc_printf(temp)==0)
//		blockThreadForPrintf();
}
// void javax.darjeeling.Darjeeling.assertTrue(int, boolean)
void javax_darjeeling_Darjeeling_void_assertTrue_int_boolean()
{
	// pop argument from the stack
	int32_t value = dj_exec_stackPopShort();
	int32_t id = dj_exec_stackPopInt();


	char tempStr[35];
	if (tempStr != NULL){
		if (value==0)
			snprintf(tempStr, 35, "%c[31mASSERT[%3d] FAILED%c[0m\n", 0x1b, (int)id, 0x1b);
		else
			snprintf(tempStr, 35, "%c[32mASSERT[%3d] PASSED%c[0m\n", 0x1b, (int)id, 0x1b);
		tossim_printf(tempStr);
		dj_mem_free (tempStr);
		if (value ==0)
			dj_panic(DJ_PANIC_ASSERTION_FAILURE);
	}
}
예제 #20
0
// boolean javax.radio.Radio._send(short, byte[])
void javax_radio_Radio_boolean__send_short_byte__()
{
	dj_thread * currentThread = dj_exec_getCurrentThread();

	// get byte array to send
	dj_int_array * arr = REF_TO_VOIDP(dj_exec_stackPopRef());
	int16_t id = dj_exec_stackPopShort();

	if (tossim_send((char*)arr->data.bytes, id, arr->array.length)==0)
	{
		// block the current thread for IO
		DEBUG_LOG(DBG_DARJEELING, DARJEELING, "send stops thread[%p]\n", currentThread);
		currentThread->status = THREADSTATUS_BLOCKED_FOR_IO;
		_global_radio_sendThreadId = currentThread->id;
		dj_exec_breakExecution();
	}

	dj_exec_stackPushShort(tossim_wasAcked());

}
// short javax.darjeeling.io.SerialInputStream._waitForByte(byte)
void javax_darjeeling_io_SerialInputStream_void__waitForByte_byte()
{
	dj_exec_stackPopShort();

	// Don't do anything, read is implemented blocking
}
예제 #22
0
// void javax.radio.Radio.setChannel(short)
void javax_radio_Radio_void_setChannel_short()
{
	/*int16_t channel = */dj_exec_stackPopShort();
	// not implemented
}
// int javax.darjeeling.io.Serial.getDefaultBaudRate(byte)
void javax_darjeeling_io_Serial_int_getDefaultBaudRate_byte()
{
	dj_exec_stackPopShort();
	dj_exec_stackPushInt(57600);
}
// byte javax.darjeeling.io.SerialInputStream._read(byte)
// NOTE: this implementation is blocking, meaning that the entire JVM is blocked when you
// read from the 'serial port'. Should be replaced by callback based method.
void javax_darjeeling_io_SerialInputStream_short__read_byte()
{
	dj_exec_stackPopShort();
	dj_exec_stackPushShort((uint16_t) getchar() );
}
void javax_wukong_wkpf_WKPF_void_destroyWuObject_byte()
{
	uint8_t port_number = (uint8_t)dj_exec_stackPopShort();
	DEBUG_LOG(DBG_WKPF, "WKPF: Removing wuobject at port %x\n", port_number);
	wkpf_error_code = wkpf_remove_wuobject(port_number);
}
// void javax.darjeeling.io.SerialOutputStream._write(byte, int)
void javax_darjeeling_io_SerialOutputStream_void__write_byte_int()
{
	int32_t b = dj_exec_stackPopShort();
	dj_exec_stackPopShort();
	printf("%c", b);
}