/* * Copyright (C) 2003 BLADOX, s.r.o. All rights reserved. * * This file is part of an example program for Turbo. This example * program may be used, distributed and modified without limitation. * */ #include <config.h> #include <turbo/turbo.h> u8 PROGMEM t_Foo_en[] = "Net example"; u8 PROGMEM t_NP_1[] = "Network problem: Cannot open channel\n"; u8 PROGMEM t_NP_2[] = "Network problem: Timeout - no response\n"; u8 PROGMEM rc_data[] = "Receiving data"; u8 PROGMEM t_r1[] = "Receved len: "; u8 PROGMEM test_data[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 }; void action_menu (void *data) { Sockaddr sk = { IPPROTO_UDP, // IPPROTO_TCP, 9201, {62, 24, 67, 189} }; u8 f; u8 *res; u8 j; u8 len; res = open_channel_raw (&sk, Q_OPEN_CHANNEL_ONDEMAND, 255); j = get_tag (res, T_CHANNEL_STATUS); if (j != 0) { j += 2; f = res[j] & 0x07; if (f != 0) { send_data_raw (f, test_data, sizeof (test_data), Q_SEND_DATA_IMMEDIATELY); res = wait_for_action (ACTION_EVENT_DATA_AVAILABLE, rc_data, 10); j = get_tag (res, T_CHANNEL_DATA_LEN); if (j != 0) { dbsp ("data received\n"); j++; //tag j++; //len len = res[j]; res = receive_data_raw (f, len); j = get_tag (res, T_CHANNEL_DATA); if (j != 0) { u8 *buf = buf_B (); u8 *r = buf; u8 i; r = sprints (r, t_r1); r = sprinti (r, len); r = sprintc (r, '\n'); for (i = 0; i < len && i < 10; i++) { r = sprintch (r, res[j + 2 + i]); r = sprintc (r, ' '); } r = sprintc (r, '\n'); r = sprintc (r, '\0'); display_text (buf, NULL); } } else { display_text_raw (t_NP_2, Q_DISPLAY_TEXT_HIGH_PRIORITY | Q_DISPLAY_TEXT_DELAY_CLEAR); } // get_channel_status(); close_channel (f); return; } } display_text_raw (t_NP_1, Q_DISPLAY_TEXT_HIGH_PRIORITY | Q_DISPLAY_TEXT_DELAY_CLEAR); } void turbo_handler (u8 action, void *data) { switch (action) { case ACTION_APP_INIT: reg_action (ACTION_EVENT_DATA_AVAILABLE); break; case ACTION_INSERT_MENU: insert_menu (t_Foo_en); break; case ACTION_MENU_SELECTION: stk_thread (action_menu, data); break; default: break; } }
Copyright © 2004-2006 BLADOX | Turbo version 1.2
|