|
@@ -36,7 +36,7 @@
|
|
|
|
|
|
/* USER CODE BEGIN Includes */
|
|
|
|
|
|
-#define NET_DATBUFSIZE (1<<4)
|
|
|
+#define NET_DATBUFSIZE (1<<6)
|
|
|
|
|
|
#define ETH_DISABLED 0
|
|
|
#define ENC28J60 1
|
|
@@ -93,6 +93,10 @@ static void MX_SPI1_Init(void);
|
|
|
#if ETH_MODULE == ETH_DISABLED
|
|
|
# error ETH_MODULE is required
|
|
|
#endif
|
|
|
+static uint8_t monitoring_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
|
|
|
+static uint8_t monitoring_ip[] = {10, 181, 239, 255};
|
|
|
+static uint8_t remote_mac_base[] = {0xf2, 0xff, 0x01, 0x00, 0x01, 0x00};
|
|
|
+static uint8_t remote_ip_base[] = {10, 181, 239, 128};
|
|
|
|
|
|
#if ETH_MODULE == ENC28J60
|
|
|
# define NET_HEADERS_LENGTH (ETH_HEADER_LEN + IP_HEADER_LEN + UDP_HEADER_LEN)
|
|
@@ -166,11 +170,22 @@ static void eth_init() {
|
|
|
|
|
|
return;
|
|
|
}
|
|
|
-/*
|
|
|
-static void send(int32_t port_id, int len) {
|
|
|
- ES_send_udp_data2(net_sendbuf, remote_mac, len, 26517+port_id, remote_ip, 36400);
|
|
|
+
|
|
|
+void x_memcpy(uint8_t *dst, uint8_t *src, int len) {
|
|
|
+ while(len--)
|
|
|
+ dst[len] = src[len];
|
|
|
}
|
|
|
-*/
|
|
|
+
|
|
|
+static void send(uint8_t sensor_id, int len) {
|
|
|
+ uint8_t remote_ip[sizeof(remote_ip_base)];
|
|
|
+ uint8_t remote_mac[sizeof(remote_mac_base)];
|
|
|
+ x_memcpy(remote_ip, remote_ip_base, sizeof(remote_ip));
|
|
|
+ x_memcpy(remote_mac, remote_mac_base, sizeof(remote_mac));
|
|
|
+ remote_ip[3] += sensor_id;
|
|
|
+ remote_mac[5] += sensor_id;
|
|
|
+ ES_send_udp_data2(net_sendbuf, remote_mac, len, 26517, remote_ip, 36400);
|
|
|
+}
|
|
|
+
|
|
|
#endif
|
|
|
#if ETH_MODULE == WIZNET
|
|
|
|
|
@@ -275,23 +290,23 @@ static void send(int32_t port_id, int len) {
|
|
|
|
|
|
#endif
|
|
|
|
|
|
-/*
|
|
|
-static void sendChar(char c) {
|
|
|
- net_senddatbuf[0] = 0xff;
|
|
|
+
|
|
|
+static void sendChar(uint8_t sensor_id, char c) {
|
|
|
+ net_senddatbuf[0] = 0xfe;
|
|
|
net_senddatbuf[1] = 0xfe;
|
|
|
- net_senddatbuf[2] = 0xfd;
|
|
|
- net_senddatbuf[3] = 0xfc;
|
|
|
+ net_senddatbuf[2] = 0xfe;
|
|
|
+ net_senddatbuf[3] = 0xfe;
|
|
|
net_senddatbuf[4] = c;
|
|
|
net_senddatbuf[5] = c;
|
|
|
net_senddatbuf[6] = c;
|
|
|
net_senddatbuf[7] = c;
|
|
|
- send(-1, 8);
|
|
|
+ send(sensor_id, 8);
|
|
|
}
|
|
|
|
|
|
-static inline void sendAliveChar() {
|
|
|
+/*static inline void sendAliveChar() {
|
|
|
sendChar(0xfe);
|
|
|
-}
|
|
|
-*/
|
|
|
+}*/
|
|
|
+
|
|
|
|
|
|
static uint8_t getChar(uint8_t *dat) {
|
|
|
uint8_t diff0 = dat[0] ^ dat[1];
|
|
@@ -341,6 +356,7 @@ int main(void)
|
|
|
|
|
|
/* USER CODE BEGIN 2 */
|
|
|
|
|
|
+ OUT_LED_ERR_GPIO_Port->BSRR = OUT_LED_ERR_Pin;
|
|
|
GPIOA->BSRR = LED_STATUS_Pin;
|
|
|
HAL_Delay(250);
|
|
|
GPIOA->BSRR = LED_STATUS_Pin << 16;
|
|
@@ -350,13 +366,37 @@ int main(void)
|
|
|
eth_init();
|
|
|
|
|
|
GPIOA->BSRR = LED_STATUS_Pin;
|
|
|
+ OUT_LED_ERR_GPIO_Port->BSRR = OUT_LED_ERR_Pin << 16;
|
|
|
|
|
|
/* USER CODE END 2 */
|
|
|
|
|
|
/* Infinite loop */
|
|
|
/* USER CODE BEGIN WHILE */
|
|
|
+ uint16_t notify_counter = 0;
|
|
|
while (1)
|
|
|
{
|
|
|
+ if (!(notify_counter++ % 1000))
|
|
|
+ ES_send_udp_data2(net_sendbuf, monitoring_mac, 0, 26517, monitoring_ip, 36400);
|
|
|
+
|
|
|
+ uint16_t counter=0;
|
|
|
+ while(!HAL_GPIO_ReadPin(BUTTON_GPIO_Port, BUTTON_Pin)) {
|
|
|
+ counter++;
|
|
|
+ HAL_Delay(1);
|
|
|
+ if (counter > 250) {
|
|
|
+ OUT_LED_ERR_GPIO_Port->BSRR = OUT_LED_ERR_Pin << 16;
|
|
|
+ OUT_LED_0_GPIO_Port->BSRR = OUT_LED_0_Pin << 16;
|
|
|
+ OUT_LED_1_GPIO_Port->BSRR = OUT_LED_1_Pin << 16;
|
|
|
+ OUT_LED_2_GPIO_Port->BSRR = OUT_LED_2_Pin << 16;
|
|
|
+ OUT_LED_3_GPIO_Port->BSRR = OUT_LED_3_Pin << 16;
|
|
|
+ sendChar(0, 0xfc);
|
|
|
+ sendChar(1, 0xfc);
|
|
|
+ sendChar(2, 0xfc);
|
|
|
+ sendChar(3, 0xfc);
|
|
|
+ while(!HAL_GPIO_ReadPin(BUTTON_GPIO_Port, BUTTON_Pin));
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
uint16_t dat_len;
|
|
|
uint16_t dat_offset;
|
|
|
dat_len = 0;
|
|
@@ -365,7 +405,7 @@ int main(void)
|
|
|
if (dat_offset == 0)
|
|
|
continue;
|
|
|
|
|
|
- if (dat_len == 8) {
|
|
|
+ if (dat_len != 8) {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
@@ -377,7 +417,7 @@ int main(void)
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- uint8_t value = getChar(data);
|
|
|
+ uint8_t value = getChar(&data[4]);
|
|
|
|
|
|
if (value == 0xff) {
|
|
|
OUT_LED_ERR_GPIO_Port->BSRR = OUT_LED_ERR_Pin;
|
|
@@ -415,7 +455,6 @@ int main(void)
|
|
|
OUT_LED_ERR_GPIO_Port->BSRR = OUT_LED_ERR_Pin;
|
|
|
break;
|
|
|
}
|
|
|
-
|
|
|
/* USER CODE END WHILE */
|
|
|
|
|
|
/* USER CODE BEGIN 3 */
|
|
@@ -516,15 +555,15 @@ static void MX_GPIO_Init(void)
|
|
|
|
|
|
/*Configure GPIO pin Output Level */
|
|
|
HAL_GPIO_WritePin(GPIOA, OUT_LED_0_Pin|OUT_LED_1_Pin|OUT_LED_2_Pin|OUT_LED_3_Pin
|
|
|
- |OUT_LED_ERR_Pin|LED_STATUS_Pin|LED_SUBSTATUS_Pin, GPIO_PIN_RESET);
|
|
|
+ |OUT_LED_ERR_Pin|LED_STATUS_Pin, GPIO_PIN_RESET);
|
|
|
|
|
|
/*Configure GPIO pin Output Level */
|
|
|
HAL_GPIO_WritePin(SPI1_NSS_GPIO_Port, SPI1_NSS_Pin, GPIO_PIN_RESET);
|
|
|
|
|
|
/*Configure GPIO pins : OUT_LED_0_Pin OUT_LED_1_Pin OUT_LED_2_Pin OUT_LED_3_Pin
|
|
|
- OUT_LED_ERR_Pin LED_STATUS_Pin LED_SUBSTATUS_Pin */
|
|
|
+ OUT_LED_ERR_Pin LED_STATUS_Pin */
|
|
|
GPIO_InitStruct.Pin = OUT_LED_0_Pin|OUT_LED_1_Pin|OUT_LED_2_Pin|OUT_LED_3_Pin
|
|
|
- |OUT_LED_ERR_Pin|LED_STATUS_Pin|LED_SUBSTATUS_Pin;
|
|
|
+ |OUT_LED_ERR_Pin|LED_STATUS_Pin;
|
|
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
@@ -537,6 +576,12 @@ static void MX_GPIO_Init(void)
|
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
|
|
HAL_GPIO_Init(SPI1_NSS_GPIO_Port, &GPIO_InitStruct);
|
|
|
|
|
|
+ /*Configure GPIO pin : BUTTON_Pin */
|
|
|
+ GPIO_InitStruct.Pin = BUTTON_Pin;
|
|
|
+ GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
|
|
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
|
+ HAL_GPIO_Init(BUTTON_GPIO_Port, &GPIO_InitStruct);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/* USER CODE BEGIN 4 */
|