Changeset 554601
- Timestamp:
- 12/28/11 15:45:07 (17 months ago)
- Branches:
- ('master', 'a231b56d57a69513303d0061f5fa3e3cd51c85c1')('controller-upgrade', '72b31cc86eeeef18f1371a3067b6e8a5ca21abfc')('windows_service_fixes', 'df6bd2788365991d36d5af2a75833b8de2a5860f')
- Children:
- 44e5b81a909587475868949602bb06e09d9354f1
- Parents:
- b6fb5ce106ed038b516319e81b7117b7a36ec8ac
- git-author:
- Stefan Persson <stefan.persson@telldus.se>2011-12-28 15:45:07+01:00
- git-committer:
- Stefan Persson <stefan.persson@telldus.se>2011-12-28 15:45:07+01:00
- Location:
- telldus-core
- Files:
-
- 2 edited
-
client/telldus-core.h (modified) (1 diff)
-
tdtool/main.cpp (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
telldus-core/client/telldus-core.h
r8eaaf6 r554601 116 116 #define TELLSTICK_ERROR_CONNECTING_SERVICE -6 117 117 #define TELLSTICK_ERROR_UNKNOWN_RESPONSE -7 118 #define TELLSTICK_ERROR_SYNTAX -8 118 119 #define TELLSTICK_ERROR_UNKNOWN -99 119 120 -
telldus-core/tdtool/main.cpp
rb6fb5ce r554601 79 79 80 80 void print_device( int index ) { 81 tdInit(); 81 82 int intId = tdGetDeviceId(index); 82 83 char *name = tdGetName(intId); … … 103 104 } 104 105 105 void list_devices() { 106 int list_devices() { 107 tdInit(); 106 108 int intNum = tdGetNumberOfDevices(); 107 109 if (intNum < 0) { … … 109 111 fprintf(stderr, "Error fetching devices: %s\n", errorString); 110 112 tdReleaseString(errorString); 111 return ;113 return intNum; 112 114 } 113 115 printf("Number of devices: %i\n", intNum); … … 155 157 fprintf(stderr, "Error fetching sensors: %s\n", errorString); 156 158 tdReleaseString(errorString); 157 return; 158 } 159 return sensorStatus; 160 } 161 return TELLSTICK_SUCCESS; 159 162 } 160 163 161 164 int find_device( char *device ) { 165 tdInit(); 162 166 int deviceId = atoi(device); 163 167 if (deviceId == 0) { //Try to find the id from the name … … 179 183 } 180 184 181 void switch_device( bool turnOn, char *device ) { 185 int switch_device( bool turnOn, char *device ) { 186 tdInit(); 182 187 int deviceId = find_device( device ); 183 188 if (deviceId == 0) { 184 189 printf("Device '%s', not found!\n", device); 185 return ;190 return TELLSTICK_ERROR_DEVICE_NOT_FOUND; 186 191 } 187 192 … … 200 205 printf(" - %s\n", errorString); 201 206 tdReleaseString(errorString); 202 } 203 204 void dim_device( char *device, int level ) { 207 return retval; 208 } 209 210 int dim_device( char *device, int level ) { 211 tdInit(); 205 212 int deviceId = find_device( device ); 206 213 if (deviceId == 0) { 207 214 printf("Device '%s', not found!\n", device); 208 return ;215 return TELLSTICK_ERROR_DEVICE_NOT_FOUND; 209 216 } 210 217 if (level < 0 || level > 255) { 211 218 printf("Level %i out of range!\n", level); 212 return ;219 return TELLSTICK_ERROR_SYNTAX; 213 220 } 214 221 … … 219 226 tdReleaseString(name); 220 227 tdReleaseString(errorString); 221 } 222 223 void bell_device( char *device ) { 228 return retval; 229 } 230 231 int bell_device( char *device ) { 232 tdInit(); 224 233 int deviceId = find_device( device ); 225 234 if (deviceId == 0) { 226 235 printf("Device '%s', not found!\n", device); 227 return ;236 return TELLSTICK_ERROR_DEVICE_NOT_FOUND; 228 237 } 229 238 … … 234 243 tdReleaseString(name); 235 244 tdReleaseString(errorString); 236 } 237 238 void learn_device( char *device ) { 245 return retval; 246 } 247 248 int learn_device( char *device ) { 249 tdInit(); 239 250 int deviceId = find_device( device ); 240 251 if (deviceId == 0) { 241 252 printf("Device '%s', not found!\n", device); 242 return ;253 return TELLSTICK_ERROR_DEVICE_NOT_FOUND; 243 254 } 244 255 … … 249 260 tdReleaseString(name); 250 261 tdReleaseString(errorString); 251 } 252 253 void send_raw_command( char *command ) { 262 return retval; 263 } 264 265 int send_raw_command( char *command ) { 266 tdInit(); 254 267 const int MAX_LENGTH = 100; 255 268 char msg[MAX_LENGTH]; … … 263 276 if (fd == NULL) { 264 277 printf("Error opening file %s\n", command); 265 return ;278 return TELLSTICK_ERROR_UNKNOWN; 266 279 } 267 280 fgets(msg, MAX_LENGTH, fd); … … 272 285 printf("Sending raw command: %s\n", errorString); 273 286 tdReleaseString(errorString); 287 return retval; 274 288 } 275 289 … … 295 309 if (argc < 2) { 296 310 print_usage( argv[0] ); 297 return -1; 298 } 299 300 while ( (optch = getopt_long(argc,argv,optstring,long_opts,&longindex)) != -1 ) 311 return -TELLSTICK_ERROR_SYNTAX; 312 } 313 314 int returnSuccess = 0; 315 while ( (optch = getopt_long(argc,argv,optstring,long_opts,&longindex)) != -1 ){ 316 int success = 0; 301 317 switch (optch) { 302 318 case 'b' : 303 bell_device( &optarg[0] );319 success = bell_device( &optarg[0] ); 304 320 break; 305 321 case 'd' : 306 322 if (level >= 0) { 307 dim_device( &optarg[0], level ); 323 success = dim_device( &optarg[0], level ); 324 break; 308 325 } 326 printf("Dim level missing or incorrect value.\n"); 327 success = TELLSTICK_ERROR_SYNTAX; 309 328 break; 310 329 case 'f' : 311 s witch_device(false, &optarg[0]);330 success = switch_device(false, &optarg[0]); 312 331 break; 313 332 case 'h' : 314 333 print_usage( argv[0] ); 315 break;334 success = TELLSTICK_SUCCESS; 316 335 case 'i' : 317 336 print_version( ); 318 break;337 success = TELLSTICK_SUCCESS; 319 338 case 'l' : 320 list_devices();339 success = list_devices(); 321 340 break; 322 341 case 'n' : 323 s witch_device(true, &optarg[0]);342 success = switch_device(true, &optarg[0]); 324 343 break; 325 344 case 'e' : 326 learn_device(&optarg[0]);345 success = learn_device(&optarg[0]); 327 346 break; 328 347 case 'r' : 329 s end_raw_command(&optarg[0]);348 success = send_raw_command(&optarg[0]); 330 349 break; 331 350 case 'v' : … … 334 353 default : 335 354 print_usage( argv[0] ); 336 return -1; 337 } 338 355 success = TELLSTICK_ERROR_SYNTAX; 356 } 357 if(success != TELLSTICK_SUCCESS){ 358 returnSuccess = success; //return last error message 359 } 360 } 339 361 tdClose(); //Cleaning up 340 return 0;341 } 362 return -returnSuccess; 363 }
Note: See TracChangeset
for help on using the changeset viewer.
