Example #1
0
// Message handling. This function is called from the radio code (radio_zwave_poll or radio_xbee_poll), checks for replies we may be waiting for, or passes on the handling to one of the other libs.
void wkcomm_handle_message(wkcomm_address_t addr, uint8_t *payload, uint8_t length) {
#ifdef DARJEELING_DEBUG
	DEBUG_LOG(DBG_WKCOMM, "Handling command %d from %d, length %d:\n", payload[0], addr, length);
	for (int8_t i=0; i<length; ++i) {
		DEBUG_LOG(DBG_WKCOMM, " %d", payload[i]);
	}
	DEBUG_LOG(DBG_WKCOMM, "\n");
#endif // DARJEELING_DEBUG

	wkcomm_received_msg msg;
	msg.src = addr;
	msg.command = 	payload[0];
	msg.seqnr = payload[1] + (((uint16_t)payload[2]) << 8);
	msg.payload = payload+3;
	msg.length = length - 3;

	if (wkcomm_wait_reply_number_of_commands > 0) {
		// nvmcomm_wait is waiting for a particular type of message. probably a response to a message sent earlier.
		// if this message is of that type, store it in nvmcomm_wait_received_message so nvmcomm_wait can return it.
		// if not, handle it as a normal message
		if (wkcomm_wait_reply_number_of_commands != 0
				&& msg.seqnr == wkcomm_last_seqnr) {
			for (int i=0; i<wkcomm_wait_reply_number_of_commands; i++) {
				if (msg.command == wkcomm_wait_reply_commands[i]) {
					wkcomm_received_reply = msg; // Struct, so values are copied. Radio libs need to provide a pointer to a global payload buffer.
					wkcomm_wait_reply_number_of_commands = 0; // Signal we're no longer waiting for the reply.
				}
			}
		}
	}

	// Pass on to other libs. Could have a system here were libraries register for specific commands, but this seems simpler, and only a bit slower if handlers return quickly when the message isn't meant for them.
	dj_hook_call(wkcomm_handle_message_hook, &msg);
}
Example #2
0
int main()
{
	// Declared in djarchive.c so that the reprogramming code can find it.
	di_app_archive = (dj_di_pointer)di_app_infusion_archive_data;

	// initialise serial port
	avr_serialInit(115200);

	core_init(mem, HEAPSIZE);
	dj_vm_main((dj_di_pointer)di_lib_infusions_archive_data, (dj_di_pointer)di_app_infusion_archive_data, java_library_native_handlers, java_library_native_handlers_length);

	// Listen to the radio
	while(true)
		dj_hook_call(dj_core_pollingHook, NULL);

	return 0;
}
Example #3
0
int main()
{
	// Declared in djarchive.c so that the reprogramming code can find it.
	di_app_archive = (dj_di_pointer)di_app_infusion_archive_data;

	// initialise serial port
	avr_serialInit(115200);

	core_init(mem, HEAPSIZE);
	dj_exec_setRunlevel(RUNLEVEL_RUNNING);
	wkpf_picokong((dj_di_pointer)di_app_infusion_archive_data);

	// Listen to the radio
	while(true)
		dj_hook_call(dj_core_pollingHook, NULL);

	return 0;
}
Example #4
0
int main(int argc,char* argv[])
{
	posix_parse_command_line(argc, argv);

	// Read the lib and app infusion archives from file
	di_lib_archive = posix_load_infusion_archive("lib_infusions.dja");
	di_app_archive = posix_load_infusion_archive("app_infusion.dja");

	// initialise memory manager
	void *mem = malloc(HEAPSIZE);
	ref_t_base_address = (char*)mem - 42;

	core_init(mem, HEAPSIZE);
	dj_vm_main(di_lib_archive, di_app_archive, java_library_native_handlers, java_library_native_handlers_length);

	// Listen to the radio
	while(true)
		dj_hook_call(dj_core_pollingHook, NULL);

	return 0;
}
Example #5
0
void dj_panic(int32_t panictype)
{
    switch(panictype)
    {
        case DJ_PANIC_OUT_OF_MEMORY:
        	DEBUG_LOG(true, "PANIC: out of memory!\n");
            break;
        case DJ_PANIC_ILLEGAL_INTERNAL_STATE:
        	DEBUG_LOG(true, "PANIC: illegal internal state!\n");
            break;
        case DJ_PANIC_UNIMPLEMENTED_FEATURE:
        	DEBUG_LOG(true, "PANIC: unimplemented feature!\n");
            break;
        case DJ_PANIC_UNCAUGHT_EXCEPTION:
        	DEBUG_LOG(true, "PANIC: uncaught exception!\n");
            break;
        case DJ_PANIC_UNSATISFIED_LINK:
            DEBUG_LOG(true, "PANIC: unsatisfied link!\n");
            break;
        case DJ_PANIC_MALFORMED_INFUSION:
        	DEBUG_LOG(true, "PANIC: malformed infusion!\n");
            break;
        case DJ_PANIC_ASSERTION_FAILURE:
            DEBUG_LOG(true, "PANIC: assertion failed!\n");
            break;
        case DJ_PANIC_SAFE_POINTER_OVERFLOW:
            DEBUG_LOG(true, "PANIC: safe pointer overflow!\n");
            break;
        default:
            DEBUG_LOG(true, "PANIC: unknown panic type %d!\n", panictype);
            break;
    }
    if (dj_exec_getRunlevel() < RUNLEVEL_PANIC) {
        dj_exec_setRunlevel(panictype);
        while (true) // Still allow remote access through wkcomm when in panic state.
            dj_hook_call(dj_core_pollingHook, NULL);
    } else {
        exit(panictype); // To avoid getting into a recursive panic.
    }
}
void javax_wukong_wkpf_WKPF_javax_wukong_wkpf_VirtualWuObject_select() {
	wuobject_t *wuobject;
	while(true) {
		// Process any incoming messages
		dj_hook_call(dj_vm_pollingHook, NULL);
		// // TODONR: implement group stuff
		// #ifdef NVM_USE_GROUP
		// 	// Send out a heartbeat message if it's due, and check for failed nodes.
		// 	group_heartbeat();
		// #endif // NVM_USE_GROUP
		if (dj_exec_getRunlevel() == RUNLEVEL_RUNNING) {
			// Propagate any dirty properties
			wkpf_propagate_dirty_properties();
			// Check if any wuobjects need updates
			if(wkpf_get_next_wuobject_to_update(&wuobject)) { // Will call update() for native profiles directly, and return true for virtual profiles requiring an update.
				dj_exec_stackPushRef(VOIDP_TO_REF(wuobject->java_instance_reference));
				DEBUG_LOG(DBG_WKPF, "WKPF: WKPF.select returning wuclass at port %x.\n", wuobject->port_number);
				return;
			}
		}
	}
}
Example #7
0
int main()
{
	// TODONR How does this work on Taroko?
	// initialise serial port
	// avr_serialInit(115200);

	dj_named_native_handler handlers[] = {
			{ "base", &base_native_handler },
			{ "darjeeling3", &darjeeling3_native_handler },
			{ "uart", &uart_native_handler },
			{ "wkcomm", &wkcomm_native_handler },
			{ "wkpf", &wkpf_native_handler },
			{ "wkreprog", &wkreprog_native_handler },
		};
	uint16_t length = sizeof(handlers)/ sizeof(handlers[0]);

	dj_vm_main(mem, HEAPSIZE, (dj_di_pointer)di_lib_infusions_archive_data, (dj_di_pointer)di_app_infusion_data, handlers, length);

	// Listen to the radio
	while(true)
		dj_hook_call(dj_vm_pollingHook, NULL);

	return 0;
}