Stefan Schuermans commited on 2012-05-06 17:54:55
Showing 5 changed files, with 56 additions and 1 deletions.
... | ... |
@@ -233,7 +233,7 @@ static void AppBbmProcFrame(AppBbmState *state) |
233 | 233 |
if (state->haveAddr) { |
234 | 234 |
memcpy(pack.udp.IpHdr.Dest, state->addr, sizeof(pack.udp.IpHdr.Dest)); |
235 | 235 |
pack.udp.UdpHdr.SrcPort = htons(2323); |
236 |
- pack.udp.UdpHdr.DestPort = htons(2323); |
|
236 |
+ pack.udp.UdpHdr.DestPort = htons(state->port); |
|
237 | 237 |
UdpSend((unsigned char *)&pack, sizeof(pack)); |
238 | 238 |
} |
239 | 239 |
|
... | ... |
@@ -266,6 +266,16 @@ void AppBbmInit(AppBbmState *state) // (extern) |
266 | 266 |
debug_app_bbm_printf("%hhu: no address", state->no); |
267 | 267 |
} |
268 | 268 |
|
269 |
+ // get destination port for MCUF frames |
|
270 |
+ if (state->haveAddr) { |
|
271 |
+ char filename[12]; |
|
272 |
+ sprintf(filename, "bbm%hhu/port", state->no); |
|
273 |
+ if (AppsToolsReadPort(*state->sectorBuf, state->vi, |
|
274 |
+ filename, &state->port) != 0) |
|
275 |
+ state->port = 2323; // default MCUF destination port |
|
276 |
+ debug_app_bbm_printf("%hhu: port %hu", state->no, state->port); |
|
277 |
+ } |
|
278 |
+ |
|
269 | 279 |
// initialize internal state |
270 | 280 |
state->idxFile = 0; |
271 | 281 |
state->haveFile = 0; |
... | ... |
@@ -19,6 +19,7 @@ typedef struct app_bbm_state { |
19 | 19 |
unsigned long nextActMs; ///< when to do next action |
20 | 20 |
char haveAddr; ///< if destination address for MCUF is known |
21 | 21 |
unsigned char addr[4]; ///< destination address for MCUF packets |
22 |
+ unsigned short port; ///< destination port for MCUF packets |
|
22 | 23 |
unsigned int idxFile; ///< index of file to open next |
23 | 24 |
char haveFile; ///< if a file is open |
24 | 25 |
FILEINFO fi; ///< information about open file |
... | ... |
@@ -112,11 +112,14 @@ void AppsRun(void) // (extern) |
112 | 112 |
|
113 | 113 |
// initialize applications |
114 | 114 |
AppBbmState bbm0 = { .sectorBuf = §orBuf, .vi = &vi, .no = 0 }; |
115 |
+ AppBbmState bbm1 = { .sectorBuf = §orBuf, .vi = &vi, .no = 1 }; |
|
115 | 116 |
AppBbmInit(&bbm0); |
117 |
+ AppBbmInit(&bbm1); |
|
116 | 118 |
|
117 | 119 |
// run applications |
118 | 120 |
while (CfIsPresent()) { |
119 | 121 |
AppBbmRun(&bbm0); |
122 |
+ AppBbmRun(&bbm1); |
|
120 | 123 |
Tasks(); |
121 | 124 |
} |
122 | 125 |
} |
... | ... |
@@ -108,3 +108,33 @@ char AppsToolsReadIp(uint8_t sectorBuf[SECTOR_SIZE], VOLINFO *vi, |
108 | 108 |
return 0; |
109 | 109 |
} |
110 | 110 |
|
111 |
+/** |
|
112 |
+ * @brief read network port from file |
|
113 |
+ * @param[in] sectorBuf scratch buffer to store a sector |
|
114 |
+ * @param[in] vi volume information structure |
|
115 |
+ * @param[in] filename name of file to read |
|
116 |
+ * @param[out] port network port read |
|
117 |
+ * @return 0 on success, -1 on error |
|
118 |
+ */ |
|
119 |
+char AppsToolsReadPort(uint8_t sectorBuf[SECTOR_SIZE], VOLINFO *vi, |
|
120 |
+ const char *filename, unsigned short *port) // (extern) |
|
121 |
+{ |
|
122 |
+ char bufStr[16]; |
|
123 |
+ unsigned short tmpPort; |
|
124 |
+ |
|
125 |
+ // get string from file |
|
126 |
+ if (AppsToolsReadStr(sectorBuf, vi, filename, bufStr, sizeof(bufStr)) != 0) |
|
127 |
+ return -1; |
|
128 |
+ |
|
129 |
+ // parse string |
|
130 |
+ if (sscanf(bufStr, "%hu", &tmpPort) != 1 || tmpPort == 0) { |
|
131 |
+ debug_apps_tools_printf("port parse error"); |
|
132 |
+ return -1; |
|
133 |
+ } |
|
134 |
+ |
|
135 |
+ // port to output |
|
136 |
+ debug_apps_tools_printf("port read: %hu", tmpPort); |
|
137 |
+ *port = tmpPort; |
|
138 |
+ return 0; |
|
139 |
+} |
|
140 |
+ |
... | ... |
@@ -42,5 +42,16 @@ extern char AppsToolsReadMac(uint8_t sectorBuf[SECTOR_SIZE], VOLINFO *vi, |
42 | 42 |
extern char AppsToolsReadIp(uint8_t sectorBuf[SECTOR_SIZE], VOLINFO *vi, |
43 | 43 |
const char *filename, unsigned char ip[4]); |
44 | 44 |
|
45 |
+/** |
|
46 |
+ * @brief read network port from file |
|
47 |
+ * @param[in] sectorBuf scratch buffer to store a sector |
|
48 |
+ * @param[in] vi volume information structure |
|
49 |
+ * @param[in] filename name of file to read |
|
50 |
+ * @param[out] port network port read |
|
51 |
+ * @return 0 on success, -1 on error |
|
52 |
+ */ |
|
53 |
+extern char AppsToolsReadPort(uint8_t sectorBuf[SECTOR_SIZE], VOLINFO *vi, |
|
54 |
+ const char *filename, unsigned short *port); |
|
55 |
+ |
|
45 | 56 |
#endif // #ifndef INC_apps_tools |
46 | 57 |
|
47 | 58 |