dispatch.h
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2017-2018, Dataspeed Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Dataspeed Inc. nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 #ifndef _DATASPEED_PDS_CAN_DISPATCH_H
36 #define _DATASPEED_PDS_CAN_DISPATCH_H
37 #include <stdint.h>
38 
40 {
41 
42 typedef struct {
43  // Master and slave status messages have the same structure.
44  // 4 Reserved/Unused bits.
45  uint8_t :4;
46  // Inverter Last Request (bool)
47  uint8_t inverter_request :1;
48  // Inverter Status (bool)
49  uint8_t inverter_status :1;
50  // Inverter Overloading (bool)
51  uint8_t inverter_overload :1;
52  // Inverter Over Temperature (bool)
53  uint8_t inverter_overtemp :1;
54  // Mode (enum)
55  // The current mode of the PDS.
56  uint8_t mode :4;
57  // Script (enum)
58  // The currently running script on the PDS, if any.
59  uint8_t script :4;
60  // Channel Status X (enum)
61  // The current status of channel X on the PDS.
62  // Union for master channels 1-12 and slave channels 13-24
63  union { struct {uint8_t status_01 :4; uint8_t status_02 :4;}; struct {uint8_t status_13 :4; uint8_t status_14 :4;}; };
64  union { struct {uint8_t status_03 :4; uint8_t status_04 :4;}; struct {uint8_t status_15 :4; uint8_t status_16 :4;}; };
65  union { struct {uint8_t status_05 :4; uint8_t status_06 :4;}; struct {uint8_t status_17 :4; uint8_t status_18 :4;}; };
66  union { struct {uint8_t status_07 :4; uint8_t status_08 :4;}; struct {uint8_t status_19 :4; uint8_t status_20 :4;}; };
67  union { struct {uint8_t status_09 :4; uint8_t status_10 :4;}; struct {uint8_t status_21 :4; uint8_t status_22 :4;}; };
68  union { struct {uint8_t status_11 :4; uint8_t status_12 :4;}; struct {uint8_t status_23 :4; uint8_t status_24 :4;}; };
69 } MsgStatus1;
70 
71 typedef struct {
72  // Master and slave status messages have the same structure.
73  // Board Temperature (float32)
74  // Internal board temperature, in Celsius.
75  int8_t board_temp;
76  // Thermocouple Temperature (float32)
77  // Thermocouple temperature, in Celsius.
79  // Voltage (float32)
80  // Voltage, in V.
81  uint16_t voltage :12;
82  // 4 Reserved/Unused bits.
83  uint8_t :4;
84 } MsgStatus2;
85 
86 typedef struct {
87  // Union for multiple messages with the same structure: Current1Master, Current2Master, Current3Master, Current1Slave, Current2Slave, Current3Slave
88  union { int16_t current_01; int16_t current_05; int16_t current_09; int16_t current_13; int16_t current_17; int16_t current_21; };
89  union { int16_t current_02; int16_t current_06; int16_t current_10; int16_t current_14; int16_t current_18; int16_t current_22; };
90  union { int16_t current_03; int16_t current_07; int16_t current_11; int16_t current_15; int16_t current_19; int16_t current_23; };
91  union { int16_t current_04; int16_t current_08; int16_t current_12; int16_t current_16; int16_t current_20; int16_t current_24; };
92 } MsgCurrent;
93 
94 typedef struct {
95  uint8_t channel;
96  uint8_t request;
97 } MsgRelay;
98 
99 typedef struct {
100  uint8_t mode;
101 } MsgMode;
102 
103 typedef struct {
104  uint8_t script;
105 } MsgScript;
106 
107 #define BUILD_ASSERT(cond) do { (void) sizeof(char [1 - 2*!(cond)]); } while(0)
108 static void dispatchAssertSizes() {
109  BUILD_ASSERT(8 == sizeof(MsgCurrent));
110  BUILD_ASSERT(8 == sizeof(MsgStatus1));
111  BUILD_ASSERT(4 == sizeof(MsgStatus2));
112  BUILD_ASSERT(2 == sizeof(MsgRelay));
113  BUILD_ASSERT(1 == sizeof(MsgMode));
114  BUILD_ASSERT(1 == sizeof(MsgScript));
115 }
116 #undef BUILD_ASSERT
117 
118 enum {
119  ID_REQUEST = 0x410,
120  ID_MODE = 0x411,
121  ID_SCRIPT = 0x412,
122  ID_RESERVED1 = 0x413,
123  ID_RESERVED2 = 0x430,
124  ID_RESERVED3 = 0x431,
125  ID_RESERVED4 = 0x432,
146 };
147 
148 } //namespace dataspeed_pds_can
149 
150 #endif // _DATASPEED_PDS_CAN_DISPATCH_H
#define BUILD_ASSERT(cond)
Definition: dispatch.h:107
static void dispatchAssertSizes()
Definition: dispatch.h:108


dataspeed_pds_can
Author(s): Kevin Hallenbeck , Eric Myllyoja
autogenerated on Sat Jul 11 2020 03:09:52