Line No. | Rev | Author | Line |
---|---|---|---|
1 | 6 | kaklik | /*! \file edpdebug.c \brief Emerald Data Protocol Debug Functions. */ |
2 | //***************************************************************************** |
||
3 | // |
||
4 | // File Name : 'edpdebug.c' |
||
5 | // Title : Emerald Data Protocol Debug Functions |
||
6 | // Author : Pascal Stang - Copyright (C) 2003 |
||
7 | // Created : 2003.09.20 |
||
8 | // Revised : 2003.09.20 |
||
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 <avr/io.h> // include I/O definitions (port names, pin names, etc) |
||
20 | #include <avr/interrupt.h> // include interrupt support |
||
21 | #include <avr/pgmspace.h> // include program-space support |
||
22 | |||
23 | #include "global.h" // include our global settings |
||
24 | #include "rprintf.h" // include printf function library |
||
25 | #include "debug.h" // include debug helper library |
||
26 | #include "input.h" // include user-input functions |
||
27 | |||
28 | #include "edp.h" |
||
29 | #include "edpdebug.h" |
||
30 | |||
31 | // globals |
||
32 | |||
33 | // functions |
||
34 | |||
35 | void edpDisplayCommand(u08 length, EdpCommand* edpCommand) |
||
36 | { |
||
37 | // print source and command char |
||
38 | rprintf("EDP SrcAddr: 0x%x Cmd: 0x%x '%c'\r\n", |
||
39 | edpCommand->SrcAddr, |
||
40 | edpCommand->Command, edpCommand->Command); |
||
41 | if(length-2) |
||
42 | { |
||
43 | // print data |
||
44 | rprintf("Data:\r\n"); |
||
45 | debugPrintHexTable(length-2, edpCommand->Data); |
||
46 | } |
||
47 | } |
||
48 | |||
49 | void edpDisplayReply(u08 response, EdpReply* edpReply) |
||
50 | { |
||
51 | u08 i; |
||
52 | u08 checksum; |
||
53 | |||
54 | // display response |
||
55 | rprintf("EDP Response: 0x%x '%c'\r\n",response,response); |
||
56 | |||
57 | // if data was received |
||
58 | if(response==EDP_RESP_DATA_REPLY) |
||
59 | { |
||
60 | // do checksum on reply |
||
61 | checksum = edpReply->Length; |
||
62 | for(i=0; i<(edpReply->Length-1); i++) |
||
63 | { |
||
64 | checksum += edpReply->Data[i]; |
||
65 | } |
||
66 | checksum = ~checksum; |
||
67 | // print message |
||
68 | rprintf("EDP Reply: "); |
||
69 | // show data received |
||
70 | rprintf("Length: 0x%x ",edpReply->Length); |
||
71 | rprintf("RxChksum=0x%x MyChksum=0x%x",edpReply->Data[edpReply->Length-1], checksum); |
||
72 | rprintfCRLF(); |
||
73 | rprintf("Data:\r\n"); |
||
74 | debugPrintHexTable((edpReply->Length-1), edpReply->Data); |
||
75 | rprintfCRLF(); |
||
76 | } |
||
77 | } |
||
78 | /* |
||
79 | void edpDisplayReplyOld(u08 response, u08 replyLength, u08* replyData) |
||
80 | { |
||
81 | u08 i; |
||
82 | u08 checksum; |
||
83 | |||
84 | // display response |
||
85 | rprintf("EDP Response: 0x%x '%c'\r\n",response,response); |
||
86 | |||
87 | // if data was received |
||
88 | if(response==EDP_RESP_DATA_REPLY) |
||
89 | { |
||
90 | // do checksum on reply |
||
91 | checksum = replyLength; |
||
92 | for(i=0; i<(replyLength-1); i++) |
||
93 | { |
||
94 | checksum += replyData[i]; |
||
95 | } |
||
96 | checksum = ~checksum; |
||
97 | // print message |
||
98 | rprintf("EDP Reply: "); |
||
99 | // show data received |
||
100 | rprintf("Length: 0x%x ",replyLength); |
||
101 | rprintf("RxChksum=0x%x MyChksum=0x%x",replyData[replyLength-1], checksum); |
||
102 | rprintfCRLF(); |
||
103 | rprintf("Data:\r\n"); |
||
104 | debugPrintHexTable((replyLength-1), replyData); |
||
105 | rprintfCRLF(); |
||
106 | } |
||
107 | } |
||
108 | */ |
||
109 | |||
110 | u08 edpComposeCommand(u08 srcEdpAddr, u08* cmdBuffer) |
||
111 | { |
||
112 | u08 string[80]; |
||
113 | u08 len; |
||
114 | u08 i; |
||
115 | |||
116 | // instructions |
||
117 | rprintfProgStrM("Enter EDP Command, format [c][p1][p2][p3]...[pN]\r\n"); |
||
118 | rprintfProgStrM("[c] is command char, [px] parameters in 2-digit hex\r\n"); |
||
119 | |||
120 | // get user input |
||
121 | rprintfProgStrM("EDP Command>"); |
||
122 | len = inputString(0x0D, 80, string); |
||
123 | rprintfCRLF(); |
||
124 | |||
125 | // check for null user input |
||
126 | if(!len) |
||
127 | { |
||
128 | rprintfProgStrM("ERROR: No command\r\n"); |
||
129 | // return immediately with zero command length |
||
130 | return 0; |
||
131 | } |
||
132 | |||
133 | // prepare command |
||
134 | cmdBuffer[0] = srcEdpAddr; |
||
135 | cmdBuffer[1] = string[0]; |
||
136 | for(i=0; i<len/2; i++) |
||
137 | { |
||
138 | cmdBuffer[i+2] = asciiHexToByte(&string[1+(i*2)]); |
||
139 | } |
||
140 | |||
141 | // return command length |
||
142 | return 2+(len/2); |
||
143 | } |
||
144 | |||
145 | void edpRunCommand(u08 destEdpAddr, u08 cmdLength, u08* cmdBuffer) |
||
146 | { |
||
147 | u08 response; |
||
148 | EdpReply* edpReply; |
||
149 | |||
150 | u08 retval; |
||
151 | |||
152 | EdpCommand* edpCommand = (EdpCommand*)cmdBuffer; |
||
153 | |||
154 | // send command |
||
155 | rprintf("Sending Command: 0x%x '%c' ->",edpCommand->Command,edpCommand->Command); |
||
156 | retval = edpSendCommand(destEdpAddr, cmdLength, edpCommand); |
||
157 | // handle result values |
||
158 | if(retval == EDP_COMMAND_OK) |
||
159 | { |
||
160 | // command sent successfully |
||
161 | rprintfProgStrM("Send Success!\r\n"); |
||
162 | } |
||
163 | else if(retval == EDP_COMMAND_NODEV) |
||
164 | { |
||
165 | // device did not exist |
||
166 | rprintfProgStrM("Send Failed->NO DEVICE!\r\n"); |
||
167 | rprintf("No EDP device could be contacted at address 0x%x.\r\n", destEdpAddr); |
||
168 | rprintfProgStrM("The device may be busy or not responding.\r\n"); |
||
169 | rprintfProgStrM("Check target device and I2C bus cabling.\r\n"); |
||
170 | // return immediately |
||
171 | return; |
||
172 | } |
||
173 | else |
||
174 | { |
||
175 | // other error |
||
176 | rprintfProgStrM("Send Failed->Unspecified Error!\r\n"); |
||
177 | // return immediately |
||
178 | return; |
||
179 | } |
||
180 | |||
181 | // get the reply, if any, from the command |
||
182 | retval = edpGetCommandReply(&response, &edpReply); |
||
183 | // handle result values |
||
184 | if(retval == EDP_REPLY_BADCHKSUM) |
||
185 | { |
||
186 | rprintf("**** Reply has bad checksum ****\r\n"); |
||
187 | } |
||
188 | // display the reply |
||
189 | edpDisplayReply(response, edpReply); |
||
190 | } |
Powered by WebSVN v2.8.3