From 54e47c7eb5d2afdcf299f024e48b49c1b241018e Mon Sep 17 00:00:00 2001 From: Sangjung Woo Date: Tue, 11 Oct 2016 20:16:09 +0900 Subject: [PATCH] client: Add AMB objects for Vehicle Status This patch adds some AMB objects for Vehicle Status based on Demo CAN DB. Change-Id: I6d5dc446634574700e3d9d790993595df86be13f Signed-off-by: Sangjung Woo --- lib/client/libamb-objects.h | 78 +++++++++++++++++- lib/client/libamb-util.h | 1 + lib/client/test/test.c | 191 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 267 insertions(+), 3 deletions(-) diff --git a/lib/client/libamb-objects.h b/lib/client/libamb-objects.h index c6377ac..a56d6e7 100644 --- a/lib/client/libamb-objects.h +++ b/lib/client/libamb-objects.h @@ -25,16 +25,88 @@ extern "C" { #include "libamb-util.h" -enum GearboxPositionDisplay{ +enum GearboxPositionDisplay { PARKING = (1<<3) | (1<<1), // 10, 0x0A DRIVE, // 11, 0x0B NEUTRAL, REVERSE, }; -CAN_OBJECT(VehicleOdometer, guint32, NULL); -CAN_OBJECT(VehicleSpeed, guint16, Speed); +enum DriveMode { + NORMAL = (1<<3) | (1<<1), // 10, 0x0A + ECO = (1<<3) | (1<<2), // 12, 0x0C + SPORT, // 13, 0x0D +}; + +/** + * Gear Information + * CANID: 257 (0x101) + */ CAN_OBJECT(GearboxPositionDisplay, guchar, NULL); +CAN_OBJECT(GearboxPosition, guchar, NULL); +CAN_OBJECT(DriveMode, guchar, NULL); + +/** + * Vehicle Speed & Odometer + * CANID: 258 (0x102) + */ +CAN_OBJECT(VehicleOdometer, guint32, NULL); +CAN_OBJECT(VehicleSpeed, guint16, Speed); + +/** + * Engine Information + * CANID: 259 (0x103) + */ +CAN_OBJECT(EngineRPM, guint16, NULL); +CAN_OBJECT(WarterTemperature, guint16, NULL); +CAN_OBJECT(FuelGage, guchar, NULL); + +/** + * TPMS Tire Air pressure + * CANID: 260 (0x104) + */ +CAN_OBJECT(TPMS_FL, guchar, NULL); +CAN_OBJECT(TPMS_FR, guchar, NULL); +CAN_OBJECT(TPMS_RL, guchar, NULL); +CAN_OBJECT(TPMS_RR, guchar, NULL); + +/** + * Warning Message & Status + * CANID: 518 (0x206) + */ +CAN_OBJECT(WarningSafetybelts, gboolean, NULL); +CAN_OBJECT(WarningAirbag, gboolean, NULL); +CAN_OBJECT(CheckCharging, gboolean, NULL); +CAN_OBJECT(WarningLowOilLevel, gboolean, NULL); +CAN_OBJECT(CheckPowerSteering, gboolean, NULL); +CAN_OBJECT(WarningBrake, gboolean, NULL); +CAN_OBJECT(WarningEBD, gboolean, NULL); +CAN_OBJECT(CheckEnging, gboolean, NULL); +CAN_OBJECT(EmergencyFlasher, gboolean, NULL); +CAN_OBJECT(FuelLeveltooLow, gboolean, NULL); +CAN_OBJECT(WarningTPM, gboolean, NULL); +CAN_OBJECT(LowWasher, gboolean, NULL); +CAN_OBJECT(SystemESC, gboolean, NULL); +CAN_OBJECT(SystemESCOff, gboolean, NULL); +CAN_OBJECT(WarningABS, gboolean, NULL); +CAN_OBJECT(StsDoorOpen, gboolean, NULL); +CAN_OBJECT(StsTrunkOpen, gboolean, NULL); +CAN_OBJECT(WarningImmobilizer, gboolean, NULL); +CAN_OBJECT(LampRearFogLights, gboolean, NULL); +CAN_OBJECT(LampHazardLight, gboolean, NULL); +CAN_OBJECT(LampFrontFog, gboolean, NULL); +CAN_OBJECT(LampTailLight, gboolean, NULL); +CAN_OBJECT(LampHighBeamAuto, gboolean, NULL); +CAN_OBJECT(LampHighBeam, gboolean, NULL); +CAN_OBJECT(LampCruiseCnt, gboolean, NULL); +CAN_OBJECT(LampCruiseCntSet, gboolean, NULL); +CAN_OBJECT(LampDoorOpenF_L, gboolean, NULL); +CAN_OBJECT(LampDoorOpenF_R, gboolean, NULL); +CAN_OBJECT(LampDoorOpenR_R, gboolean, NULL); +CAN_OBJECT(LampDoorOpenR_L, gboolean, NULL); +CAN_OBJECT(LampDoorOpenBonnet, gboolean, NULL); +CAN_OBJECT(LampDoorOpenTrunk, gboolean, NULL); +CAN_OBJECT(WarningParkingBreak, gboolean, NULL); #ifdef __cplusplus } diff --git a/lib/client/libamb-util.h b/lib/client/libamb-util.h index 5d4844a..65772b7 100644 --- a/lib/client/libamb-util.h +++ b/lib/client/libamb-util.h @@ -31,6 +31,7 @@ extern "C" { #include "libamb-common.h" #include "libamb-client.h" +#define g_variant_get_gboolean g_variant_get_boolean #define g_variant_get_guchar g_variant_get_byte #define g_variant_get_gint16 g_variant_get_int16 #define g_variant_get_guint16 g_variant_get_uint16 diff --git a/lib/client/test/test.c b/lib/client/test/test.c index bce4a80..2c49a6a 100644 --- a/lib/client/test/test.c +++ b/lib/client/test/test.c @@ -237,6 +237,112 @@ static void test_samsungcan_VehicleSpeed() return ; } +static void test_LampHazardLight() +{ + struct LampHazardLightType *p; + int ret = amb_get_LampHazardLight_with_zone(&p, None); + if (ret != 0) { + fprintf(stderr, "Fail to %s\n", __func__); + return ; + } + fprintf(stderr, " == LampHazardLight ==\n"); + fprintf(stderr, " Zone: %d\n", p->Zone); + fprintf(stderr, " Value: %s\n", (p->Value) ? "Set" : "None"); + fprintf(stderr, " ValueSequence: %d\n", p->ValueSequence); + fprintf(stderr, " Time: %f\n", p->Time); + + amb_release_data(p); +} + +static void LampHazardLight_handler(const gchar *objname, gpointer data) +{ + struct LampHazardLightType retdata; + + if (!data) + return ; + + amb_convert_LampHazardLightType(data, &retdata); + + fprintf(stderr, " == LampHazardLight ==\n"); + fprintf(stderr, " Zone: %d\n", retdata.Zone); + fprintf(stderr, " Value: %s\n", (retdata.Value) ? "Set" : "None"); + fprintf(stderr, " ValueSequence: %d\n", retdata.ValueSequence); + fprintf(stderr, " Time: %f\n", retdata.Time); +} + +static void test_LampHazardLight_listen() +{ + GMainLoop *loop; + int rc; + + rc = amb_register_property_changed_handler("LampHazardLight", 0, + (AMB_PROPERTY_CHANGED_CALLBACK)LampHazardLight_handler); + if (rc != 0) { + fprintf(stderr, "Fail to amb_register_property_changed_handler(): %s\n", "LampHazardLight"); + return ; + } + + g_timeout_add_seconds(10, timer_callback, "LampHazardLight"); + + loop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(loop); + + g_main_loop_unref(loop); +} + +static void test_WarningSafetybelts() +{ + struct WarningSafetybeltsType *p; + int ret = amb_get_WarningSafetybelts_with_zone(&p, None); + if (ret != 0) { + fprintf(stderr, "Fail to %s\n", __func__); + return ; + } + fprintf(stderr, " == WarningSafetybelt ==\n"); + fprintf(stderr, " Zone: %d\n", p->Zone); + fprintf(stderr, " Value: %s\n", (p->Value) ? "Set" : "None"); + fprintf(stderr, " ValueSequence: %d\n", p->ValueSequence); + fprintf(stderr, " Time: %f\n", p->Time); + + amb_release_data(p); +} + +static void WarningSafetybelts_handler(const gchar *objname, gpointer data) +{ + struct WarningSafetybeltsType retdata; + + if (!data) + return ; + + amb_convert_WarningSafetybeltsType(data, &retdata); + + fprintf(stderr, " == WarningSafetybelts ==\n"); + fprintf(stderr, " Zone: %d\n", retdata.Zone); + fprintf(stderr, " Value: %s\n", (retdata.Value) ? "Set" : "None"); + fprintf(stderr, " ValueSequence: %d\n", retdata.ValueSequence); + fprintf(stderr, " Time: %f\n", retdata.Time); +} + +static void test_WarningSafetybelts_listen() +{ + GMainLoop *loop; + int rc; + + rc = amb_register_property_changed_handler("WarningSafetybelts", 0, + (AMB_PROPERTY_CHANGED_CALLBACK)WarningSafetybelts_handler); + if (rc != 0) { + fprintf(stderr, "Fail to amb_register_property_changed_handler(): %s\n", "WarningSafetybelts"); + return ; + } + + g_timeout_add_seconds(10, timer_callback, "WarningSafetybelts"); + + loop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(loop); + + g_main_loop_unref(loop); +} + static void test_samsungcan_VehicleOdometer() { struct VehicleOdometerType *p; @@ -255,10 +361,95 @@ static void test_samsungcan_VehicleOdometer() return ; } +static void test_TPMS_FL() +{ + struct TPMS_FLType *p; + int ret = amb_get_TPMS_FL_with_zone(&p, None); + if (ret != 0) { + fprintf(stderr, "Fail to %s\n", __func__); + return ; + } + fprintf(stderr, " == TPMS_FL ==\n"); + fprintf(stderr, " Zone: %d\n", p->Zone); + // fprintf(stderr, " Value: %u\n", (unsigned int)p->Value); + fprintf(stderr, " Value: %u\n", p->Value); + fprintf(stderr, " ValueSequence: %d\n", p->ValueSequence); + fprintf(stderr, " Time: %f\n", p->Time); + + amb_release_data(p); +} + +static void TPMS_FL_handler(const gchar *objname, gpointer data) +{ + struct TPMS_FLType retdata; + + if (!data) + return ; + + amb_convert_TPMS_FLType(data, &retdata); + + fprintf(stderr, " == TPMS_FL ==\n"); + fprintf(stderr, " Zone: %d\n", retdata.Zone); + fprintf(stderr, " Value: %u\n", retdata.Value); + fprintf(stderr, " ValueSequence: %d\n", retdata.ValueSequence); + fprintf(stderr, " Time: %f\n", retdata.Time); +} + +static void test_TPMS_FL_listen() +{ + GMainLoop *loop; + int rc; + + rc = amb_register_property_changed_handler("TPMS_FL", 0, + (AMB_PROPERTY_CHANGED_CALLBACK)TPMS_FL_handler); + if (rc != 0) { + fprintf(stderr, "Fail to amb_register_property_changed_handler(): %s\n", "WarningSafetybelts"); + return ; + } + + g_timeout_add_seconds(10, timer_callback, "TPMS_FL"); + + loop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(loop); + + g_main_loop_unref(loop); +} + +static void test_FuelGage() +{ + struct FuelGageType *p; + int ret = amb_get_FuelGage_with_zone(&p, None); + if (ret != 0) { + fprintf(stderr, "Fail to %s\n", __func__); + return ; + } + fprintf(stderr, " == FuelGage ==\n"); + fprintf(stderr, " Zone: %d\n", p->Zone); + fprintf(stderr, " Value: %u\n", p->Value); + fprintf(stderr, " ValueSequence: %d\n", p->ValueSequence); + fprintf(stderr, " Time: %f\n", p->Time); + + amb_release_data(p); +} + int main() { test_get_object_list(); + // cansend vcan0 104#3C.00.00.00.00.00.00.00 + test_FuelGage(); + + // cansend vcan0 104#3C.00.00.00.00.00.00.00 + test_TPMS_FL(); + test_TPMS_FL_listen(); + + // cansend vcan0 206#00.00.00.00.01.00.00.00 + test_LampHazardLight(); + test_LampHazardLight_listen(); + + // cansend vcan0 206#01.00.00.00.00.00.00.00 + test_WarningSafetybelts(); + test_WarningSafetybelts_listen(); test_samsungcan_VehicleOdometer(); test_samsungcan_VehicleSpeed(); test_samsungcan_GearboxPosition(); -- 2.7.4