| Line No. | Rev | Author | Line |
|---|---|---|---|
| 1 | 6 | kaklik | /*! \file erp.c \brief Emerald Radio Protocol System. */ |
| 2 | //***************************************************************************** |
||
| 3 | // |
||
| 4 | // File Name : 'erp.c' |
||
| 5 | // Title : Emerald Radio Protocol System |
||
| 6 | // Author : Pascal Stang - Copyright (C) 2003 |
||
| 7 | // Created : 2003.09.10 |
||
| 8 | // Revised : 2003.09.10 |
||
| 9 | // Version : 0.1 |
||
| 10 | // Target MCU : Atmel AVR series |
||
| 11 | // Editor Tabs : 4 |
||
| 12 | // |
||
| 13 | // This code is distributed under the GNU Public License |
||
| 14 | // which can be found at http://www.gnu.org/licenses/gpl.txt |
||
| 15 | // |
||
| 16 | //***************************************************************************** |
||
| 17 | |||
| 18 | //----- Include Files --------------------------------------------------------- |
||
| 19 | #include "global.h" // include our global settings |
||
| 20 | #include "debug.h" // include debug function library |
||
| 21 | #include "rprintf.h" // include printf function library |
||
| 22 | |||
| 23 | #include "erp.h" |
||
| 24 | #include "edpdebug.h" |
||
| 25 | |||
| 26 | // globals |
||
| 27 | |||
| 28 | // functions |
||
| 29 | void erpDisplayHeader(ErpPacket* erpPacket) |
||
| 30 | { |
||
| 31 | // show ERP packet header |
||
| 32 | rprintf("ERP Header: Callsign="); |
||
| 33 | rprintfStrLen(erpPacket->CallSign,0,CALLSIGN_FIELD_LEN); |
||
| 34 | rprintf(", Trg=0x%x, Src=0x%x, Seq#=%d, Type=", |
||
| 35 | erpPacket->ToAddress, |
||
| 36 | erpPacket->FromAddress, |
||
| 37 | erpPacket->SequenceNum); |
||
| 38 | // try to decode packet type |
||
| 39 | switch(erpPacket->Type) |
||
| 40 | { |
||
| 41 | case ERP_ECHO: rprintf("ECHO"); break; |
||
| 42 | case ERP_ECHOREPLY: rprintf("ECHOREPLY"); break; |
||
| 43 | case ERP_TEST: rprintf("TEST"); break; |
||
| 44 | case ERP_EDPCOMMAND: rprintf("EDPCOMMAND"); break; |
||
| 45 | case ERP_EDPREPLY: rprintf("EDPREPLY"); break; |
||
| 46 | case ERP_EDPREPLYNODEV: rprintf("EDPREPLYNODEV"); break; |
||
| 47 | default: rprintf("0x%x", erpPacket->Type); break; |
||
| 48 | } |
||
| 49 | rprintfCRLF(); |
||
| 50 | } |
||
| 51 | |||
| 52 | void erpDisplayPacket(ErpPacket* erpPacket, u08 pktLength) |
||
| 53 | { |
||
| 54 | u08 i; |
||
| 55 | u08 flag; |
||
| 56 | |||
| 57 | // show ERP packet header |
||
| 58 | erpDisplayHeader(erpPacket); |
||
| 59 | |||
| 60 | // dump complete raw packet data |
||
| 61 | if(pktLength) |
||
| 62 | { |
||
| 63 | // check if all characters are printable |
||
| 64 | flag = TRUE; |
||
| 65 | for(i=0; i<pktLength; i++) |
||
| 66 | { |
||
| 67 | if( ((u08*)erpPacket)[i] < 0x20 ) flag = FALSE; |
||
| 68 | } |
||
| 69 | |||
| 70 | // print packet data |
||
| 71 | rprintf("Data:\r\n"); |
||
| 72 | if(flag) |
||
| 73 | { |
||
| 74 | // print as string |
||
| 75 | rprintfStrLen(((u08*)erpPacket), 0, pktLength); |
||
| 76 | } |
||
| 77 | else |
||
| 78 | { |
||
| 79 | // print as hex |
||
| 80 | debugPrintHexTable(pktLength, ((u08*)erpPacket)); |
||
| 81 | } |
||
| 82 | rprintfCRLF(); |
||
| 83 | } |
||
| 84 | } |
||
| 85 | |||
| 86 | void erpDisplayEdpCommand(u08 length, ErpEdpCommand* erpEdpCommand) |
||
| 87 | { |
||
| 88 | // print ERP-specific fields |
||
| 89 | rprintf("EDP DestAddr: 0x%x\r\n", erpEdpCommand->EdpDestAddr); |
||
| 90 | // print embedded EDP command |
||
| 91 | edpDisplayCommand(length-1, &erpEdpCommand->EdpCommand); |
||
| 92 | } |
||
| 93 | |||
| 94 | void erpDisplayEdpReply(u08 length, ErpEdpReply* erpEdpReply) |
||
| 95 | { |
||
| 96 | // print embedded EDP reply |
||
| 97 | edpDisplayReply(erpEdpReply->EdpResponse, &erpEdpReply->EdpReply); |
||
| 98 | } |
||
| 99 | |||
| 100 | |||
| 101 | /* |
||
| 102 | void ErpPacketCreate(u08 targetI2cAddr, u08 pktType, u08 datalength, u08* data) |
||
| 103 | { |
||
| 104 | // make packet structure in TxPacket memory |
||
| 105 | struct ErpPacket* erpPacket |
||
| 106 | = (struct ErpPacket*)TxPacket; |
||
| 107 | |||
| 108 | // prepare Emerald packet header |
||
| 109 | memcpy(erpPacket->CallSign, MYCALLSIGN, CALLSIGN_FIELD_LEN); |
||
| 110 | erpPacket->ToAddress = targetI2cAddr; |
||
| 111 | erpPacket->FromAddress = LocalI2cAddr; |
||
| 112 | erpPacket->SequenceNum = SequenceNum++; |
||
| 113 | erpPacket->Type = pktType; |
||
| 114 | // copy data |
||
| 115 | for(i=0; i<datalength; i++) |
||
| 116 | { |
||
| 117 | erpPacket->Data[i] = *data++; |
||
| 118 | } |
||
| 119 | } |
||
| 120 | |||
| 121 | void ErpPacketTx(void) |
||
| 122 | { |
||
| 123 | // STX/ETX header |
||
| 124 | u08 stxetxStatus = 0x5A; |
||
| 125 | u08 stxetxType = 0xA5; |
||
| 126 | rprintf("Sending Packet: Status: 0x%x Type: 0x%x\r\n", stxetxStatus, stxetxType); |
||
| 127 | radioSend(stxetxStatus, stxetxType, EMRADIOHEADER_LEN+(len/2), packet); |
||
| 128 | } |
||
| 129 | */ |
Powered by WebSVN v2.8.3