aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Embedded_SW/Embedded
diff options
context:
space:
mode:
authorAvi Levkovich <avi@twine-s.com>2020-08-31 18:30:24 +0300
committerAvi Levkovich <avi@twine-s.com>2020-08-31 18:30:24 +0300
commit636615fd69d4cb758fdf51d35baad73ed71d8236 (patch)
treec943b50d87c1cc9ea5afeb3c8f88e1021b96958c /Software/Embedded_SW/Embedded
parent5c19a9bef046ff080a9a7008bd4f39e2a13e4ccb (diff)
downloadTango-636615fd69d4cb758fdf51d35baad73ed71d8236.tar.gz
Tango-636615fd69d4cb758fdf51d35baad73ed71d8236.zip
Add functions to read and wrie the setup temperature in Shinko's controller
Diffstat (limited to 'Software/Embedded_SW/Embedded')
-rw-r--r--Software/Embedded_SW/Embedded/Common/Utilities/ASCII.c32
-rw-r--r--Software/Embedded_SW/Embedded/Common/Utilities/ASCII.h1
-rw-r--r--Software/Embedded_SW/Embedded/Drivers/Uart_Comm/WHS_Controller_Comm/Shinko/ACS-13AC5E3.c48
-rw-r--r--Software/Embedded_SW/Embedded/Drivers/Uart_Comm/WHS_Controller_Comm/Shinko/ACS-13AC5E3.h54
-rw-r--r--Software/Embedded_SW/Embedded/Drivers/Uart_Comm/WHS_Controller_Comm/WHS_UART/WHS_Uart.c18
5 files changed, 138 insertions, 15 deletions
diff --git a/Software/Embedded_SW/Embedded/Common/Utilities/ASCII.c b/Software/Embedded_SW/Embedded/Common/Utilities/ASCII.c
index 403db1460..80035b588 100644
--- a/Software/Embedded_SW/Embedded/Common/Utilities/ASCII.c
+++ b/Software/Embedded_SW/Embedded/Common/Utilities/ASCII.c
@@ -4,7 +4,10 @@
* Created on: 31 Aug 2020
* Author: avi
*/
-
+#include "include.h"
+#include <stdint.h>
+#include <stdbool.h>
+#include <DataDef.h>
// Convert ASCII HEX to decimal
int ASCII_Hex_To_Decimal(char hexVal[], int len)
@@ -45,4 +48,31 @@ int ASCII_Hex_To_Decimal(char hexVal[], int len)
return dec_val;
}
+// function to convert decimal to ASCII hexadecimal
+uint32_t Decimal_To_ASCII_Hex(int n)
+{
+ Word_to_Bytes Word2Bytes;
+
+ // counter for hexadecimal number array
+ int i = 0;
+ while (n != 0)
+ {
+ // temporary variable to store remainder
+ int temp = 0;
+
+ // storing remainder in temp variable.
+ temp = n % 16;
+
+ Word2Bytes.Byte[i] = temp + 0x30;
+ i++;
+
+ n = n / 16;
+ }
+
+ for( ;i<4 ;i++)
+ Word2Bytes.Byte[i] = 0x30;
+
+ return Word2Bytes.Word;
+}
+
diff --git a/Software/Embedded_SW/Embedded/Common/Utilities/ASCII.h b/Software/Embedded_SW/Embedded/Common/Utilities/ASCII.h
index 05bd967a3..2c3ad1a55 100644
--- a/Software/Embedded_SW/Embedded/Common/Utilities/ASCII.h
+++ b/Software/Embedded_SW/Embedded/Common/Utilities/ASCII.h
@@ -9,6 +9,7 @@
#define COMMON_UTILITIES_ASCII_H_
int ASCII_Hex_To_Decimal(char hexVal[], int len);
+uint32_t Decimal_To_ASCII_Hex(int n);
diff --git a/Software/Embedded_SW/Embedded/Drivers/Uart_Comm/WHS_Controller_Comm/Shinko/ACS-13AC5E3.c b/Software/Embedded_SW/Embedded/Drivers/Uart_Comm/WHS_Controller_Comm/Shinko/ACS-13AC5E3.c
index 467bf1b5b..e57e0a21d 100644
--- a/Software/Embedded_SW/Embedded/Drivers/Uart_Comm/WHS_Controller_Comm/Shinko/ACS-13AC5E3.c
+++ b/Software/Embedded_SW/Embedded/Drivers/Uart_Comm/WHS_Controller_Comm/Shinko/ACS-13AC5E3.c
@@ -10,7 +10,9 @@
#include "drivers/Uart_Comm/WHS_Controller_Comm/WHS_UART/WHS_Uart.h"
#include <Utilities/ASCII.h>
-uint32_t Shinko_Temperature = 0;
+
+Shinko_Temperature_Degrees_t ShinkoTempDeg;
+
/*
RTU_REQUEST RTU_Request;
@@ -139,14 +141,14 @@ uint8_t Reading_Shinko_Response_PV()
{
Word2Bytes.Word = Shinko_Response.Bytes.Data;
- Shinko_Temperature = ASCII_Hex_To_Decimal(Word2Bytes.Byte, sizeof(Word2Bytes));
+ ShinkoTempDeg.Read_value = ASCII_Hex_To_Decimal(Word2Bytes.Byte, sizeof(Word2Bytes));
return OK;
}
return ERROR;
}
-void Test_Reading_Shinko_Request_SV()
+void Reading_Shinko_Request_SV()
{
Shinko_Request.Bytes.Header = Shinko_Header_Asccii_STX;//0x02
Shinko_Request.Bytes.Address = Shinko_ddress_Asccii; //0x20
@@ -161,8 +163,10 @@ void Test_Reading_Shinko_Request_SV()
Uart3_Transmit(Shinko_Request.buf,Size_Shinko_Req);
}
-uint8_t Test_Reading_Shinko_Response_SV()
+uint8_t Reading_Shinko_Response_SV()
{
+ Word_to_Bytes Word2Bytes;
+
Uart3_Receive(Shinko_Response.buf, Size_Shinko_Res -1 );
if( (Shinko_Response.Bytes.Header == Shinko_Header_Asccii_ACK) && //0x06
@@ -171,11 +175,45 @@ uint8_t Test_Reading_Shinko_Response_SV()
(Shinko_Response.Bytes.Command_Type == Read_Single) && //0x20
(Shinko_Response.Bytes.Data_Item == 0x30303031) && //0x30303031
- (Shinko_Response.Bytes.Data == 0x30303041) && //0x30303041
(Shinko_Response.Bytes.Checksum == shinko_clac_checksum(Shinko_Response.buf, sizeof(Shinko_Response.buf))) && //0x3045
(Shinko_Response.Bytes.Delimiter == Shinko_Delimiter_Asccii_ETX) )
+ {
+ Word2Bytes.Word = Shinko_Response.Bytes.Data;
+
+ ShinkoTempDeg.Read_Setup = ASCII_Hex_To_Decimal(Word2Bytes.Byte, sizeof(Word2Bytes));
+
return OK;
+ }
+ return ERROR;
+}
+void Setting_Shinko_Request_SV()
+{
+ Shinko_Setting_Request.Bytes.Header = Shinko_Header_Asccii_STX;//0x02
+ Shinko_Setting_Request.Bytes.Address = Shinko_ddress_Asccii; //0x20
+ Shinko_Setting_Request.Bytes.Sub_Address = Shinko_SubAddress_Asccii;//0x20
+ Shinko_Setting_Request.Bytes.Command_Type = Write_Single;//0x50
+
+ Shinko_Setting_Request.Bytes.Data_Item = 0x30303031;//0x30303031
+ Shinko_Setting_Request.Bytes.Data = Decimal_To_ASCII_Hex(ShinkoTempDeg.Setup);//Setting SV temperature
+
+ Shinko_Setting_Request.Bytes.Checksum = shinko_clac_checksum(Shinko_Setting_Request.buf, sizeof(Shinko_Setting_Request.buf)); //0x4446
+ Shinko_Setting_Request.Bytes.Delimiter = Shinko_Delimiter_Asccii_ETX;//0x03
+
+ Uart3_Transmit(Shinko_Setting_Request.buf,Size_Shinko_SetReq);
+}
+
+uint8_t Setting_Shinko_Response_SV()
+{
+ Uart3_Receive(Shinko_Setting_Response.buf, Size_Shinko_Res -1 );
+
+ if( (Shinko_Setting_Response.Bytes.Header == Shinko_Header_Asccii_ACK) && //0x06
+ (Shinko_Setting_Response.Bytes.Address == Shinko_ddress_Asccii) && //0x20
+ (Shinko_Setting_Response.Bytes.Checksum == shinko_clac_checksum(Shinko_Setting_Response.buf, sizeof(Shinko_Setting_Response.buf))) && //0x3045
+ (Shinko_Setting_Response.Bytes.Delimiter == Shinko_Delimiter_Asccii_ETX) ) //0x03
+ {
+ return OK;
+ }
return ERROR;
}
diff --git a/Software/Embedded_SW/Embedded/Drivers/Uart_Comm/WHS_Controller_Comm/Shinko/ACS-13AC5E3.h b/Software/Embedded_SW/Embedded/Drivers/Uart_Comm/WHS_Controller_Comm/Shinko/ACS-13AC5E3.h
index 14ef20214..39bc88a90 100644
--- a/Software/Embedded_SW/Embedded/Drivers/Uart_Comm/WHS_Controller_Comm/Shinko/ACS-13AC5E3.h
+++ b/Software/Embedded_SW/Embedded/Drivers/Uart_Comm/WHS_Controller_Comm/Shinko/ACS-13AC5E3.h
@@ -130,17 +130,65 @@ typedef union
uint8_t buf[16];
}SHINKO_RESPONSE;
+//Shinko Setting Request
+typedef union
+{
+ struct
+ {
+ //swap the order to switch endianness - need to send the LSB first
+ uint8_t unsed_padding ; //must use n*32bit in this case (since we swap the struct) without it we will get auto padding between Delimiter to Checksum
+ uint8_t Delimiter ; //14
+ uint16_t Checksum ; //12-13
+ uint32_t Data ; //8-11
+ uint32_t Data_Item ; //4-7
+ uint8_t Command_Type ; //3
+ uint8_t Sub_Address ; //2
+ uint8_t Address ; //1
+ uint8_t Header ; //0
+ }Bytes;
+ uint8_t buf[16];
+}SHINKO_SETTING_REQUEST;
+
+//Shinko Setting Response
+typedef union
+{
+ struct
+ {
+ //swap the order to switch endianness - need to send the LSB first
+ uint8_t unsed_padding[3] ; //must use n*32bit in this case (since we swap the struct) without it we will get auto padding between Delimiter to Checksum
+ uint8_t Delimiter ; //4
+ uint16_t Checksum ; //2-3
+ uint8_t Address ; //1
+ uint8_t Header ; //0
+ }Bytes;
+ uint8_t buf[8];
+}SHINKO_SETTING_RESPONSE;
+
+SHINKO_SETTING_REQUEST Shinko_Setting_Request;
+SHINKO_SETTING_RESPONSE Shinko_Setting_Response;
SHINKO_REQUEST Shinko_Request;
SHINKO_RESPONSE Shinko_Response;
#define Size_Shinko_Req sizeof(Shinko_Request.buf)
#define Size_Shinko_Res sizeof(Shinko_Response.buf)
-extern uint32_t Shinko_Temperature;
+#define Size_Shinko_SetReq sizeof(Shinko_Request.buf)
+#define Size_Shinko_SetRes sizeof(Shinko_Response.buf)
+
+typedef struct
+{
+ uint32_t Setup;
+ uint32_t Read_Setup;
+ uint32_t Read_value;
+}Shinko_Temperature_Degrees_t;//
+
+extern Shinko_Temperature_Degrees_t ShinkoTempDeg;
void Reading_Shinko_Request_PV();
uint8_t Reading_Shinko_Response_PV();
-void Test_Reading_Shinko_Request_SV();
-uint8_t Test_Reading_Shinko_Response_SV();
+void Reading_Shinko_Request_SV();
+uint8_t Reading_Shinko_Response_SV();
+void Setting_Shinko_Request_SV();
+uint8_t Setting_Shinko_Response_SV();
#endif /* DRIVERS_UART_COMM_MODBUS_ACS_13AC5E3_H_ */
diff --git a/Software/Embedded_SW/Embedded/Drivers/Uart_Comm/WHS_Controller_Comm/WHS_UART/WHS_Uart.c b/Software/Embedded_SW/Embedded/Drivers/Uart_Comm/WHS_Controller_Comm/WHS_UART/WHS_Uart.c
index f60a2632f..22d3cf836 100644
--- a/Software/Embedded_SW/Embedded/Drivers/Uart_Comm/WHS_Controller_Comm/WHS_UART/WHS_Uart.c
+++ b/Software/Embedded_SW/Embedded/Drivers/Uart_Comm/WHS_Controller_Comm/WHS_UART/WHS_Uart.c
@@ -188,17 +188,23 @@ uint32_t Test_Uart3(uint8_t test_number)
RS485_Direction(TX);//done in MilisecTask
delayms(1);
- Test_Reading_Shinko_Request_SV();//done in MilisecTask
+ Reading_Shinko_Request_SV();//done in MilisecTask
delayms(15);
RS485_Direction(RX);//done in MilisecTask
delayms(5);
- RetVal|=Test_Reading_Shinko_Response_SV();//done in MilisecTask
+ RetVal|=Reading_Shinko_Response_SV();//done in MilisecTask
break;
case 3: //---------------------------------- test Shinko -----------------------
- RetVal = Shinko_Temperature;
+ RetVal = ShinkoTempDeg.Read_value;
+ break;
+ case 4: //---------------------------------- test Shinko -----------------------
+ RetVal = ShinkoTempDeg.Read_Setup;
+ break;
+ case 5: //---------------------------------- test Shinko -----------------------
+ //TBD
break;
/*
- case 4://---------------------------------- test modbus -----------------------
+ case 6://---------------------------------- test modbus -----------------------
RS485_Direction(TX);
Test_Reading_modbus_Request_PV();
delayUs(4);
@@ -206,7 +212,7 @@ uint32_t Test_Uart3(uint8_t test_number)
delayUs(1);
RetVal|=Test_Reading_modbus_Response_PV_SV();
break;
- case 5://---------------------------------- test modbus -----------------------
+ case 7://---------------------------------- test modbus -----------------------
RS485_Direction(TX);
Test_Reading_modbus_Request_SV();
delayUs(4);
@@ -214,7 +220,7 @@ uint32_t Test_Uart3(uint8_t test_number)
delayUs(1);
RetVal|=Test_Reading_modbus_Response_PV_SV();
break;
- case 6://---------------------------------- test modbus -----------------------
+ case 8://---------------------------------- test modbus -----------------------
RS485_Direction(TX);
Test_Reading_modbus_Request_SV();
delayUs(4);