Pentru a putea realiza o analiză de film cât mai precisă și suficient de rapidă, ne-am gandit să implementăm un sistem format din mai multe dispozitive electronice și un server, legate într-o rețea wireless, care să funcționeze într-o sală de cinema.
Mai precis, fiecare scaun din sală va avea un astfel de dispozitiv – format dintr-o mini-tastatură, un transmițător/receptor wireless și (opțional) un display – care se va sincroniza cu serverul atunci când pornește filmul și va porni un ceas. Atunci când utilizatorul vrea să-și spună părerea despre momentul curent din film, apasă pe un buton – fiecare buton are o semnificație configurabilă. Atunci, dispozitivul formează un pachet cu codul de timp al filmului, codul butoului și codul dispozitivului și îl trimite la server.
Serverul receptionează pachetele primite de la dispozitivele din sală și are un soft care sintetizează informațiile.
Name | Sincronizare |
---|---|
Actors | Administratorul sistemului |
Trigger | 1. Actorul da semnalul (prin apasarea unui buton) de incepere a sincronizarii retelei. 2. Acest proces se reia la fiecare minut dupa prima executie pentru mentinerea sincronizarii retelei.. |
Preconditions | 0. Alimentarea componentelor. 1. Existenta cel putin a unui dispozitiv in retea. 2. Existenta placutei de receptie si conexiunea acesteia la server 3. Existenta si rularea unei aplicatii software (care sa preia pachetele si sa le prelucreze) pe o masina Linux si a unui server IPv6 |
Main Scenario | 1. Serverul trimite un mesaj broadcast de sincronizare (inceperea unui timer) 2. Dispozitivele receptioneaza semanlul si raspund cu ACK. |
Alternative Scenarios | 1.a. Clientul nu primeste pachetul de la server. 1.a.1. Clientul nu face nimic, iar serverul va retrimite dupa timeout-ul de la ACK. 2.a.1. ACK-ul se pierde. 2.a.2. La fel ca mai sus. |
Post Conditions | 1. Clientul si serverul au un ceas de timp real sincronizat. |
Name | Transmiterea semnificatiei butoanelor |
---|---|
Actors | Administratorul sistemului |
Trigger | Actorul trimte un mesaj broadcast cu semnificatia fiecarui buton (in software-ul care ruleaza pe server se va completa un tabel) |
Preconditions | 1. Use case-ul de sincronizare sa se fi executat cu succes. |
Main Scenario | 1. Serverul trimite un mesaj cu date 2. Dispozitivele receptioneaza semanlul si raspund cu ACK. |
Alternative Scenarios | 1.a. Clientul nu primeste pachetul de la server. 1.a.1. Clientul nu face nimic, iar serverul va retrimite dupa timeout-ul de la ACK. 2.a.1. ACK-ul se pierde. 2.a.2. La fel ca mai sus. |
Post Conditions | 1. Clientul afiseaza intr-un ciclu pe display semnificatia butoanelor. |
Name | Transmiterea datelor statistice |
---|---|
Actors | Utilizatorul |
Trigger | Actorul apasa pe un buton de la tastatura dispozitivului |
Preconditions | 1. Use case-ul de sincronizare sa se fi executat cu succes. 2. Use case-ul de transmitere a semnificatiei butoanelor sa se fi executat cu succes. |
Main Scenario | 1. Clientul creaza un pachet care contine numarul butonului, codul de timp curent, id-ul propriu. 2. Clientul depune pachetul intr-o coada de asteptare. 3. (cat timp coada nu e goala) Clientul ia pachetul din capul cozii, il trimite si asteapta ACK pentru el. |
Alternative Scenarios | 3.a. Clientul nu primeste ACK de la server. 3.a.1. Clientul retransmite pachetul. |
Post Conditions | 1. Serveul prelucreaza datele. |
Componentele alese initial au fost:
Update
Principala problema cu aceste componente a fost ca RF Tranceiverul din interiorul Zigbit-ului e foarte sensibil si se poate arde foarte usor daca nu e protejat (ceea ce s-a si intamplat). Pentru schema finala vom folosi un tranceiver care este separat de ATmega 1281.
Am folosit 2 modalitati (platforme de delvoltare a codului pentru Zigbit)
/* * This is a small example of how to write a TCP server using * Contiki's protosockets. It is a simple server that accepts one line * of text from the TCP connection, and echoes back the first 10 bytes * of the string, and then closes the connection. * * The server only handles one connection at a time. * */ #include <string.h> #include <stdio.h> /* * We include "contiki-net.h" to get all network definitions and * declarations. */ #include "contiki-net.h" #include "webserver-nogui.h" /* * We define one protosocket since we've decided to only handle one * connection at a time. If we want to be able to handle more than one * connection at a time, each parallell connection needs its own * protosocket. */ static struct psock ps; /* * We must have somewhere to put incoming data, and we use a 10 byte * buffer for this purpose. */ static char buffer[10]; static double value; static uint8_t unit, zeci, sute; void ADC_init(void) { ADMUX |= _BV(REFS1)|_BV(REFS0); ADCSRA |= _BV(ADEN); } uint16_t ADC_get(void) { uint8_t i; uint16_t val=0; ADMUX = _BV(REFS1)|_BV(REFS0); for(i = 0; i < 20; i++) { ADCSRA |= _BV(ADSC); loop_until_bit_is_set(ADCSRA, ADIF); val+= ADC; } val = val / 20; return val; } uint16_t ADC_getTemp(void) { uint8_t i; uint16_t val=0; ADMUX = _BV(REFS1)|_BV(REFS0)|_BV(MUX0); for(i = 0; i < 20; i++) { ADCSRA |= _BV(ADSC); loop_until_bit_is_set(ADCSRA, ADIF); val+= ADC; } val = (val / 20) - 9; return val; } /*---------------------------------------------------------------------------*/ /* * A protosocket always requires a protothread. The protothread * contains the code that uses the protosocket. We define the * protothread here. */ static PT_THREAD(handle_connection(struct psock *p)) { /* * A protosocket's protothread must start with a PSOCK_BEGIN(), with * the protosocket as argument. * * Remember that the same rules as for protothreads apply: do NOT * use local variables unless you are very sure what you are doing! * Local (stack) variables are not preserved when the protothread * blocks. */ PSOCK_BEGIN(p); /* * We start by sending out a welcoming message. The message is sent * using the PSOCK_SEND_STR() function that sends a null-terminated * string. */ PSOCK_SEND_STR(p, "Sparrow node online.\n"); /* * Next, we use the PSOCK_READTO() function to read incoming data * from the TCP connection until we get a newline character. The * number of bytes that we actually keep is dependant of the length * of the input buffer that we use. Since we only have a 10 byte * buffer here (the buffer[] array), we can only remember the first * 10 bytes received. The rest of the line up to the newline simply * is discarded. */ // PSOCK_READTO(p, '\n'); /* * And we send back the contents of the buffer. The PSOCK_DATALEN() * function provides us with the length of the data that we've * received. Note that this length will not be longer than the input * buffer we're using. */ PSOCK_SEND_STR(p, "Voltage: "); //PSOCK_SEND(p, buffer, PSOCK_DATALEN(p)); value = ADC_get() / 200.0; unit = (uint8_t)value%10; zeci = (uint8_t)(value * 10)%10; sute = (uint8_t)(value * 100)%10; sprintf(buffer,"%d.%d%dV\n",unit,zeci,sute); PSOCK_SEND_STR(p, buffer); PSOCK_SEND_STR(p, "Temperatura la babanu: "); value = ADC_getTemp() / 8.0; unit = ((uint8_t)value/10)%10; zeci = (uint8_t)value%10; sute = (uint8_t)(value * 10)%10; //PSOCK_SEND(p, buffer, PSOCK_DATALEN(p)); sprintf(buffer,"%d%d.%dC\n",unit,zeci,sute); PSOCK_SEND_STR(p, buffer); /* * We close the protosocket. */ PSOCK_CLOSE(p); /* * And end the protosocket's protothread. */ PSOCK_END(p); } /*---------------------------------------------------------------------------*/ /* * We declare the process. */ PROCESS(example_psock_server_process, "Example protosocket server"); /*---------------------------------------------------------------------------*/ /* * The definition of the process. */ PROCESS_THREAD(example_psock_server_process, ev, data) { /* * The process begins here. */ PROCESS_BEGIN(); /* * We start with setting up a listening TCP port. Note how we're * using the HTONS() macro to convert the port number (1010) to * network byte order as required by the tcp_listen() function. */ tcp_listen(HTONS(1010)); ADC_init(); /* * We loop for ever, accepting new connections. */ while(1) { /* * We wait until we get the first TCP/IP event, which probably * comes because someone connected to us. */ PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event); /* * If a peer connected with us, we'll initialize the protosocket * with PSOCK_INIT(). */ if(uip_connected()) { /* * The PSOCK_INIT() function initializes the protosocket and * binds the input buffer to the protosocket. */ PSOCK_INIT(&ps, buffer, sizeof(buffer)); /* * We loop until the connection is aborted, closed, or times out. */ while(!(uip_aborted() || uip_closed() || uip_timedout())) { /* * We wait until we get a TCP/IP event. Remember that we * always need to wait for events inside a process, to let * other processes run while we are waiting. */ PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event); /* * Here is where the real work is taking place: we call the * handle_connection() protothread that we defined above. This * protothread uses the protosocket to receive the data that * we want it to. */ handle_connection(&ps); } } } /* * We must always declare the end of a process. */ PROCESS_END(); } /*---------------------------------------------------------------------------*/ AUTOSTART_PROCESSES(&webserver_nogui_process,&example_psock_server_process);
/**************************************************************************//** \file Peer2Peer.c \brief Peer-2-peer sample application. \author Atmel Corporation: http://www.atmel.com \n Support email: avr@atmel.com Copyright (c) 2008 , Atmel Corporation. All rights reserved. Licensed under Atmel's Limited License Agreement (BitCloudTM). \internal History: 14.10.09 A. Taradov - Added FIFO for received packets ******************************************************************************/ /****************************************************************************** Includes section ******************************************************************************/ #include <types.h> #include <configServer.h> #include <appTimer.h> #include <zdo.h> #include <peer2peer.h> #include <serialInterface.h> /****************************************************************************** Define(s) section ******************************************************************************/ /****************************************************************************** Variables section ******************************************************************************/ // Network related variables static uint16_t nwkAddr; // Own NWK address static AppMessageBuffer_t appMessageBuffer; // Application message buffer static uint8_t messageIdTx = 0; // Application transmitted message ID static uint8_t messageIdRx = 0; // Next expected ID of received message static uint16_t actualDataLength = 0; // Actual data length to be transmitted via network // Data indications FIFO related variables static uint8_t apsDataIndFifo[APP_DATA_IND_BUFFER_SIZE]; static uint16_t apsDataIndFifoStart = 0; static uint16_t apsDataIndFifoEnd = 0; // USART related variables static HAL_UsartDescriptor_t appUsartDescriptor; // USART descriptor (required by stack) static bool usartTxBusy = false; // USART transmission transaction status static uint8_t usartTxBuffer[APP_USART_TX_BUFFER_SIZE]; // USART Tx buffer static uint8_t usartRxBuffer[APP_USART_RX_BUFFER_SIZE]; // USART Rx buffer // Application related parameters static AppState_t appState = APP_INITIAL_STATE; // application state static AppDataTransmissionState_t appDataTransmissionState = APP_DATA_TRANSMISSION_READY_STATE; static ZDO_StartNetworkReq_t networkParams; // request params for ZDO_StartNetworkReq static APS_DataReq_t apsDataReq; // Endpoint parameters static SimpleDescriptor_t simpleDescriptor = { APP_ENDPOINT, APP_PROFILE_ID, 1, 1, 0, 0 , NULL, 0, NULL }; static APS_RegisterEndpointReq_t endpointParams; static bool noIndications = false; // Timer indicating starting network during network joining. // Also used as delay timer between APS_DataConf and APS_DataReq. static HAL_AppTimer_t delayTimer; /*********************************************************************************** Static functions declarations section ***********************************************************************************/ static void APS_DataIndication(APS_DataInd_t* dataInd); static void APS_DataConf(APS_DataConf_t* confInfo); static void ZDO_StartNetworkConf(ZDO_StartNetworkConf_t* confirmInfo); static void initNetwork(void); static void startNetwork(void); static void networkSendData(bool newTransmission); static void startBlinkTimer(void); static void startingNetworkTimerFired(void); static void delayTimerFired(void); static void initSerialInterface(void); static void usartStartSending(void); static void usartBytesReceived(uint16_t readBytesLen); static void usartWriteConf(void); static uint16_t fifoFreeSpace(void); static void fifoWriteData(uint8_t *data, uint16_t size); static uint16_t fifoReadData(uint8_t *data, uint16_t size); static void buttonReleased(uint8_t buttons); /*********************************************************************************** Implementation section ***********************************************************************************/
Produsul are un potential mare de piata, putand fi utilizat in foarte multe domenii care presupun feedback live din partea clientilor.
Universitatea de Arta Teatrala si Cinematografica “I.L.Caragiale” - Bucuresti www.unatc.ro