Rev 280 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 280 | Rev 281 | ||
|---|---|---|---|
| Line 45... | Line 45... | ||
| 45 | static uint8_t buf[BUFFER_SIZE+1]; |
45 | static uint8_t buf[BUFFER_SIZE+1]; |
| 46 | 46 | ||
| 47 | #define SEND_BUFFER_SIZE 20 |
47 | #define SEND_BUFFER_SIZE 20 |
| 48 | static char sendbuf[SEND_BUFFER_SIZE+1]; |
48 | static char sendbuf[SEND_BUFFER_SIZE+1]; |
| 49 | static uint8_t buffpoint; |
49 | static uint8_t buffpoint; |
| - | 50 | ||
| - | 51 | #define C2S_START_BYTE 253 |
|
| - | 52 | #define C2S_END_BYTE 250 |
|
| 50 | 53 | ||
| 51 | /*---------------------------------------------------------------------------- |
54 | /*---------------------------------------------------------------------------- |
| 52 | * Putchar for udp |
55 | * Putchar for udp |
| 53 | * Implements a small buffer, sends packet over udp if buffer is full or |
56 | * Implements a small buffer, sends packet over udp if buffer is full or |
| 54 | * \n-char is sent. |
57 | * \n-char is sent. |
| Line 56... | Line 59... | ||
| 56 | *--------------------------------------------------------------------------*/ |
59 | *--------------------------------------------------------------------------*/ |
| 57 | int udp_putchar(char c, FILE* stream) { |
60 | int udp_putchar(char c, FILE* stream) { |
| 58 | if (gotserver != 0) { |
61 | if (gotserver != 0) { |
| 59 | sendbuf[buffpoint] = c; |
62 | sendbuf[buffpoint] = c; |
| 60 | buffpoint++; |
63 | buffpoint++; |
| 61 | 64 | ||
| 62 | if (c == '\n' || buffpoint > SEND_BUFFER_SIZE) { |
65 | if (c == '\n' || buffpoint > SEND_BUFFER_SIZE) { |
| 63 | send_udp(buf, sendbuf, buffpoint, rmDumperPrt, remotemac, remoteip); |
66 | send_udp(buf, sendbuf, buffpoint, rmDumperPrt, remotemac, remoteip); |
| 64 | buffpoint = 0; |
67 | buffpoint = 0; |
| 65 | } |
68 | } |
| 66 | } |
69 | } |
| 67 | return 0; |
70 | return 0; |
| 68 | } |
71 | } |
| 69 | 72 | ||
| 70 | static FILE mystdout = FDEV_SETUP_STREAM(udp_putchar, NULL, _FDEV_SETUP_WRITE); |
73 | static FILE mystdout = FDEV_SETUP_STREAM(udp_putchar, NULL, _FDEV_SETUP_WRITE); |
| 71 | 74 | ||
| 72 | /*----------------------------------------------------------------------------- |
75 | /*----------------------------------------------------------------------------- |
| 73 | * Main Program |
76 | * Main Program |
| 74 | *---------------------------------------------------------------------------*/ |
77 | *---------------------------------------------------------------------------*/ |
| 75 | int main(void) { |
78 | int main(void) { |
| 76 | 79 | ||
| 77 | //ethernet vars |
80 | //ethernet vars |
| 78 | uint16_t plen = 0; |
81 | uint16_t plen = 0; |
| 79 | uint8_t ledi=0; |
82 | uint8_t ledi=0; |
| 80 | uint8_t payloadlen=0; |
83 | uint8_t payloadlen=0; |
| 81 | buffpoint = 0; |
84 | buffpoint = 0; |
| 82 | 85 | ||
| 83 | //can vars |
86 | //can vars |
| 84 | Can_Message_t txMsg; |
87 | Can_Message_t txMsg; |
| 85 | Can_Message_t rxMsg; |
88 | Can_Message_t rxMsg; |
| 86 | txMsg.Id = 3; |
89 | txMsg.Id = 3; |
| 87 | txMsg.DataLength = 0; |
90 | txMsg.DataLength = 0; |
| 88 | txMsg.RemoteFlag = 0; |
91 | txMsg.RemoteFlag = 0; |
| 89 | txMsg.ExtendedFlag = 1; //DataLength and the databytes are just what happens to be in the memory. They are never set. |
92 | txMsg.ExtendedFlag = 1; //DataLength and the databytes are just what happens to be in the memory. They are never set. |
| 90 | 93 | ||
| 91 | 94 | ||
| 92 | uint32_t timeStamp = 0; |
95 | uint32_t timeStamp = 0; |
| 93 | 96 | ||
| 94 | Mcu_Init(); |
97 | Mcu_Init(); |
| 95 | Timebase_Init(); |
98 | Timebase_Init(); |
| 96 | //Serial_Init(); |
99 | //Serial_Init(); |
| Line 157... | Line 160... | ||
| 157 | 160 | ||
| 158 | } |
161 | } |
| 159 | 162 | ||
| 160 | /* check if any messages have been received */ |
163 | /* check if any messages have been received */ |
| 161 | while (Can_Receive(&rxMsg) == CAN_OK) { |
164 | while (Can_Receive(&rxMsg) == CAN_OK) { |
| - | 165 | uint8_t i; |
|
| 162 | printf("MSG Received: ID=%lx, DLC=%u, EXT=%u, RTR=%u, ", rxMsg.Id, (uint16_t)(rxMsg.DataLength), (uint16_t)(rxMsg.ExtendedFlag), (uint16_t)(rxMsg.RemoteFlag)); |
166 | printf("MSG Received: ID=%lx, DLC=%u, EXT=%u, RTR=%u, ", rxMsg.Id, (uint16_t)(rxMsg.DataLength), (uint16_t)(rxMsg.ExtendedFlag), (uint16_t)(rxMsg.RemoteFlag)); |
| 163 | printf("data={ "); |
167 | printf("data={ "); |
| 164 | for ( |
168 | for (i=0; i<rxMsg.DataLength; i++) { |
| 165 | printf("%x ", rxMsg.Data.bytes[i]); |
169 | printf("%x ", rxMsg.Data.bytes[i]); |
| 166 | } |
170 | } |
| 167 | printf("}\n"); |
171 | printf("}\n"); |
| 168 | 172 | ||
| - | 173 | //skicka ocksÄ som udppaket till rmCan2SerPrt |
|
| - | 174 | char sendbuf2[17]; |
|
| - | 175 | sendbuf2[0] = C2S_START_BYTE; |
|
| - | 176 | sendbuf2[1] = (uint8_t)rxMsg.Id; |
|
| - | 177 | sendbuf2[2] = (uint8_t)(rxMsg.Id>>8); |
|
| - | 178 | sendbuf2[3] = (uint8_t)(rxMsg.Id>>16); |
|
| - | 179 | sendbuf2[4] = (uint8_t)(rxMsg.Id>>24); |
|
| - | 180 | sendbuf2[5] = rxMsg.ExtendedFlag; |
|
| - | 181 | sendbuf2[6] = rxMsg.RemoteFlag; |
|
| - | 182 | sendbuf2[7] = rxMsg.DataLength; |
|
| - | 183 | for (uint8_t i=0; i<8; i++) { |
|
| - | 184 | sendbuf2[8+i] = rxMsg.Data.bytes[i]; |
|
| - | 185 | } |
|
| - | 186 | sendbuf2[16] = C2S_END_BYTE; |
|
| - | 187 | send_udp(buf, sendbuf2, 17, rmCan2SerPrt, remotemac, remoteip); |
|
| 169 | } |
188 | } |
| 170 | 189 | ||
| 171 | //test-debug-kod |
190 | //test-debug-kod |
| 172 | if ((enc28j60Read(EIR) & EIR_TXERIF)) { |
191 | if ((enc28j60Read(EIR) & EIR_TXERIF)) { |
| 173 | //printf("EIR_TXERIF set!\n"); |
192 | //printf("EIR_TXERIF set!\n"); |
| Line 206... | Line 225... | ||
| 206 | //Can_Send(&txMsg); |
225 | //Can_Send(&txMsg); |
| 207 | 226 | ||
| 208 | } |
227 | } |
| 209 | if (buf[IP_PROTO_P]==IP_PROTO_UDP_V){ |
228 | if (buf[IP_PROTO_P]==IP_PROTO_UDP_V){ |
| 210 | payloadlen=buf[UDP_LEN_L_P]-UDP_HEADER_LEN; |
229 | payloadlen=buf[UDP_LEN_L_P]-UDP_HEADER_LEN; |
| 211 |
|
230 | //printf("hej %x %x\n", buf[UDP_DST_PORT_H_P], buf[UDP_DST_PORT_L_P]); |
| 212 | if ((buf[UDP_DST_PORT_H_P]==((locCan2SerPrt>>8) & 0xff)) && (buf[UDP_DST_PORT_L_P] == (locCan2SerPrt & 0xff))) { |
231 | if ((buf[UDP_DST_PORT_H_P]==((locCan2SerPrt>>8) & 0xff)) && (buf[UDP_DST_PORT_L_P] == (locCan2SerPrt & 0xff))) { |
| - | 232 | if (payloadlen==17) { //ifsats ska in i ovan eller nedan ifsats kanske? nedan |
|
| - | 233 | if (buf[UDP_DATA_P]==C2S_START_BYTE && buf[UDP_DATA_P+16]==C2S_END_BYTE) { |
|
| - | 234 | Can_Message_t cm; |
|
| - | 235 | //cm.Id = 0; |
|
| - | 236 | cm.DataLength = buf[UDP_DATA_P+7]; |
|
| - | 237 | cm.RemoteFlag = buf[UDP_DATA_P+6]; |
|
| - | 238 | cm.ExtendedFlag = buf[UDP_DATA_P+5]; |
|
| - | 239 | cm.Id = (uint32_t)buf[UDP_DATA_P+1] + ((uint32_t)buf[UDP_DATA_P+2] << 8) + ((uint32_t)buf[UDP_DATA_P+3] << 16) + ((uint32_t)buf[UDP_DATA_P+4] << 24); |
|
| - | 240 | uint8_t i; |
|
| - | 241 | for (i = 0; i < cm.DataLength; i++) { |
|
| - | 242 | cm.Data.bytes[i] = buf[UDP_DATA_P+8+i]; |
|
| - | 243 | } |
|
| - | 244 | Can_Send(&cm); |
|
| - | 245 | } |
|
| 213 | printf("hoj\n"); |
246 | printf("hoj\n"); |
| - | 247 | } |
|
| 214 | } else if (buf[UDP_DATA_P]=='t' && payloadlen==5){ |
248 | } else if (buf[UDP_DATA_P]=='t' && payloadlen==5){ |
| 215 | uint8_t i=0; |
249 | uint8_t i=0; |
| 216 | if (gotserver == 0) { |
250 | if (gotserver == 0) { |
| 217 | while(i<6){ |
251 | while(i<6){ |
| 218 | remotemac[i]=buf[ETH_SRC_MAC +i]; |
252 | remotemac[i]=buf[ETH_SRC_MAC +i]; |